release-cherry-pick 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Diovi Robinet Morales
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,187 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # release-cherry-pick
4
+
5
+ **Automates release cherry-picking and GitLab merge-request creation from the command line.**
6
+
7
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D18-339933?logo=node.js&logoColor=white)](https://nodejs.org)
8
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
9
+ [![GitLab API](https://img.shields.io/badge/GitLab-REST%20API%20%2B%20PAT-FC6D26?logo=gitlab&logoColor=white)](https://docs.gitlab.com/api/rest/)
10
+ [![AI](https://img.shields.io/badge/AI-Anthropic%20Claude-D97757)](https://docs.anthropic.com)
11
+ [![CLI](https://img.shields.io/badge/type-CLI-informational)](#)
12
+
13
+ </div>
14
+
15
+ ## What it does
16
+
17
+ Shipping a release by hand — creating a release branch, cherry-picking each fix onto it, writing an MR title/description, picking a reviewer, checking the right MR checkboxes — is repetitive and error-prone, especially when releasing several unrelated tasks at once. `release-cherry-pick` is run **from inside the project being released** and automates that whole sequence for a list of tasks.
18
+
19
+ ## What it solves
20
+
21
+ Given a list of task IDs (from a file, a `-b` flag, or interactive branch selection), for each one it:
22
+
23
+ 1. **Creates a release branch off `staging`**, named after the original branch (prefix stripped): `feature/PB-123-list-user` → `release/PB-123-list-user`.
24
+ 2. **Authenticates to GitLab** with a personal access token (`gitlab.token` in config, or the `GITLAB_TOKEN` env var), prompting for one if missing and validating it against `GET /user`.
25
+ 3. **Cherry-picks only that task's own commits** onto the release branch — matched by the team's `[TASK-ID] description` commit message convention (not a naive branch diff, which breaks when a branch wasn't cut from a recent `staging`).
26
+ 4. **Drafts the MR title and description with Anthropic Claude** from the picked commits, falling back to a static template if AI is disabled or fails.
27
+ 5. **Lists real GitLab project members** for the reviewer prompt, pre-selecting your configured default reviewers.
28
+ 6. **Creates the MR** with squash-commits and delete-source-branch checked by default, assigned to your configured default assignees.
29
+ 7. **Never auto-resolves problems for you**: if cherry-picking conflicts, or the release branch already exists remotely, it stops touching that branch immediately and reports it — you decide manually. Branches whose changes are already present get reported as `SKIPPED`, not silently pushed.
30
+ 8. **Produces a final report** (console + `release-summary.md`) showing exactly which branches shipped, which need manual conflict resolution, which were skipped, and the MR link for each.
31
+
32
+ ## Requirements
33
+
34
+ - Node.js >= 18
35
+ - A GitLab personal access token with the `api` scope (set as `gitlab.token` in config, or export `GITLAB_TOKEN`)
36
+ - Run from inside the git repository you're releasing (it needs an `origin` remote pointing at GitLab)
37
+ - (Optional) an Anthropic API key, for AI-generated MR titles/descriptions
38
+
39
+ ## Installation
40
+
41
+ Install it globally with npm or pnpm:
42
+
43
+ ```bash
44
+ npm install -g release-cherry-pick
45
+ # or
46
+ pnpm add -g release-cherry-pick
47
+ ```
48
+
49
+ Or run it without installing anything:
50
+
51
+ ```bash
52
+ npx release-cherry-pick release
53
+ # or
54
+ pnpm dlx release-cherry-pick release
55
+ ```
56
+
57
+ Both expose the `release-cherry-pick` command. The tool needs to run **inside the git repository being released**, so a global install is the most practical option.
58
+
59
+ ## Usage
60
+
61
+ ### Run a release
62
+
63
+ ```bash
64
+ # Interactive — pick branches from the repo
65
+ release-cherry-pick release
66
+
67
+ # From a branch-list file
68
+ release-cherry-pick release --file branches.txt
69
+
70
+ # Direct — comma-separated task IDs and/or full branch names
71
+ release-cherry-pick release --branches PB-123,PB-124
72
+ release-cherry-pick release --branches feature/PB-123-list-user,hotfix/PB-124-fix-favicon
73
+ ```
74
+
75
+ A bare task ID is resolved to its real remote branch (same as the file input); for a full branch name, the task ID is extracted from it. Branches whose name doesn't start with a task ID are skipped with a warning.
76
+
77
+ ### Configure
78
+
79
+ ```bash
80
+ # Initialize/update configuration
81
+ release-cherry-pick config --init
82
+
83
+ # Show current configuration
84
+ release-cherry-pick config --show
85
+ ```
86
+
87
+ ### Branch list file format
88
+
89
+ ```
90
+ *PB-I3217*: Al gestionar autos de una póliza y al renovar una póliza de auto, el campo Endoso no está listando los posibles valores a seleccionar.
91
+ *PB-I3218*: Error al listar "Coberturas afectadas" (Configuraciones / Reclamos / Coberturas afectadas).
92
+ ```
93
+
94
+ The tool resolves each task ID to its real remote branch automatically (asking you to disambiguate if more than one branch matches).
95
+
96
+ ### Configuration file
97
+
98
+ Since it can hold secrets (`gitlab.token`, `ai.apiKey`), the configuration is **never stored inside the project**. It lives in your home directory, one file per project: `~/.release-cherry-pick/<project>.json` (e.g. `C:\Users\<you>\.release-cherry-pick\gitlab.example.com_group_project.json`). The file name comes from the `origin` remote (host + project path), so it's the same whether you cloned over SSH or HTTPS and doesn't change if you move the folder; repos without a remote use the folder name plus a short hash of its path. `config --show` prints the file's location. On Linux/macOS the file is created readable by your user only. Set `RELEASE_CHERRY_PICK_CONFIG_DIR` to use another directory.
99
+
100
+ ```json
101
+ {
102
+ "git": {
103
+ "stagingBranch": "staging",
104
+ "branchPrefix": {
105
+ "feature": "feature/",
106
+ "hotfix": "hotfix/",
107
+ "release": "release/"
108
+ }
109
+ },
110
+ "gitlab": {
111
+ "host": "",
112
+ "token": ""
113
+ },
114
+ "ai": {
115
+ "enabled": true,
116
+ "provider": "",
117
+ "apiKey": "",
118
+ "model": "",
119
+ "baseURL": ""
120
+ },
121
+ "release": {
122
+ "autoCreateMR": true,
123
+ "mrTitleFormat": "[{taskId}] {description}",
124
+ "defaultReviewers": [],
125
+ "defaultAssignees": [],
126
+ "mrSquash": true,
127
+ "mrRemoveSourceBranch": true,
128
+ "branches": []
129
+ }
130
+ }
131
+ ```
132
+
133
+ `ai.provider`/`ai.model` are empty by default: with AI enabled and no model saved, `release` asks you to pick a provider and model once and saves them. `ai.baseURL` is empty too, so each provider uses its own API endpoint unless you override it. `config --show` masks `gitlab.token` and `ai.apiKey` (e.g. `glpat-****WxYz`, `sk-ant-****9z8y`), and the wizard hides both while you type them.
134
+
135
+ Any option missing from the file is filled in from these defaults when it's loaded, so config files written by older versions keep working; the merged result is validated up front, and every problem (wrong type, invalid value) is reported in a single clear error.
136
+
137
+ `config --init` asks for every option above. When `autoCreateMR` is on, it uses the GitLab token (the one just entered, or `GITLAB_TOKEN`) to list the **real GitLab project members** so you pick `defaultReviewers` (preselected in each MR's reviewer prompt, still editable per MR) and `defaultAssignees` (assigned automatically to every MR) from them. If there's no token yet or the API call fails, it falls back to typing comma-separated usernames. Older configs with `release.defaultReviewerPattern` (a regex over usernames) still work — it's used when `defaultReviewers` is empty — and running the wizard migrates it into the explicit list.
138
+
139
+ GitLab authentication uses a personal access token stored in `gitlab.token` (or the `GITLAB_TOKEN` environment variable, which takes effect when the config value is empty). The GitLab host and project path are both resolved from the `origin` remote URL (SSH `git@host:group/proj.git`, `ssh://…`, or HTTPS, with or without credentials) — no `projectId` is stored. Set `gitlab.host` only when the remote's host isn't the GitLab web host, e.g. an SSH alias from `~/.ssh/config`. The Anthropic API key can also be supplied via the `ANTHROPIC_API_KEY` environment variable instead of the config file.
140
+
141
+ ## Testing in development
142
+
143
+ There's no automated test suite yet (`npm test` is a placeholder). To validate a change:
144
+
145
+ 1. **Run the smoke script**, which exercises branch parsing, config defaults, status tracking, and report/doc generation:
146
+ ```bash
147
+ node test-e2e.js
148
+ ```
149
+ 2. **Syntax-check everything** after editing:
150
+ ```bash
151
+ find src -name "*.js" -exec node --check {} \;
152
+ ```
153
+ 3. **Run the full release flow against the synthetic sandbox** — a throwaway local `origin` (bare repo) plus a clone with prepared branches covering each scenario (normal feature/hotfix, untagged commit that must not be picked, real conflict, already-applied change → `SKIPPED`, two branches with the same task ID, branch with no task ID). Its config has `autoCreateMR: false`, so nothing is pushed and the GitLab API is never called:
154
+ ```bash
155
+ npm run sandbox:create # (re)creates it in $TMPDIR/release-cherry-pick-sandbox
156
+ npm run sandbox:run -- -b "PB-100,hotfix/PB-I200-favicon,PB-300,PB-400,PB-500,feature/refactor"
157
+ npm run sandbox:run -- -f tasks.txt # --file path (tasks.txt lives in the sandbox)
158
+ npm run sandbox:run # interactive-selection path
159
+ ```
160
+ `sandbox:run` auto-answers every prompt (list → first choice, checkbox → the checked choices or all if none are, confirm → no), so it runs unattended. Re-run `sandbox:create` before each run to start from a clean state.
161
+
162
+ Two more flags work with both `sandbox:run` and `sandbox:config` (the setup wizard, whose prompts default to their current values):
163
+ - `--fake-gitlab` intercepts `fetch()` calls to the GitLab REST API (`/user`, project members, `POST merge_requests` — which prints the request body it received and returns a fake URL) and sets a fake `GITLAB_TOKEN`, so the real client, member-selection and MR-creation code run end to end with no GitLab. Release branches are pushed to the sandbox's local `origin` only.
164
+ - `--answer name=value` forces the answer of a prompt by name (value parsed as JSON when possible).
165
+ ```bash
166
+ npm run sandbox:config -- --fake-gitlab --answer autoCreateMR=true --answer 'defaultAssignees=["abel"]'
167
+ npm run sandbox:run -- --fake-gitlab -b "PB-100,PB-300" # shows the MR request body, incl. reviewer_ids/assignee_ids
168
+ ```
169
+ 4. **Exercise the real git flow against an isolated, disposable mirror** — never test branch creation, cherry-picking, or pushes directly against a real project. Clone a mirror of the target repo so pushes/branch deletes only touch your local disk:
170
+ ```bash
171
+ git clone --mirror <path-or-url-to-target-repo> /tmp/rcp-test/mirror.git
172
+ git clone /tmp/rcp-test/mirror.git /tmp/rcp-test/work
173
+ cd /tmp/rcp-test/work
174
+ # run release-cherry-pick's functions/CLI here — origin points only at the local mirror
175
+ ```
176
+ This gives you real branches, real commit history, and real conflict scenarios with zero risk to the actual GitLab project.
177
+ 5. **GitLab API behavior** (token validation, listing reviewers, MR creation) and **AI generation** need a real token (PAT with `api` scope) and a real Anthropic key respectively to exercise end-to-end — verify these manually against a test GitLab project before relying on them in production.
178
+
179
+ ## Developers
180
+
181
+ - lleraabi@gmail.com
182
+ - ariel@ingeniuscuba.com
183
+ - drobinetm@outlook.com
184
+
185
+ ## License
186
+
187
+ MIT
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "release-cherry-pick",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "CLI tool for automating release cherry-pick and GitLab MR creation",
5
+ "bin": {
6
+ "release-cherry-pick": "src/index.js"
7
+ },
8
+ "files": [
9
+ "src/"
10
+ ],
11
+ "scripts": {
12
+ "start": "node src/index.js",
13
+ "lint": "eslint .",
14
+ "lint:fix": "eslint . --fix",
15
+ "sandbox:create": "bash scripts/sandbox/make-sandbox.sh",
16
+ "sandbox:run": "node scripts/sandbox/run-release.js",
17
+ "sandbox:config": "node scripts/sandbox/run-config.js",
18
+ "prepublishOnly": "npm run lint",
19
+ "prepare": "husky || true"
20
+ },
21
+ "lint-staged": {
22
+ "*.js": "eslint --fix"
23
+ },
24
+ "keywords": [
25
+ "cli",
26
+ "git",
27
+ "cherry-pick",
28
+ "gitlab",
29
+ "release",
30
+ "merge-request",
31
+ "automation",
32
+ "npx"
33
+ ],
34
+ "author": "Diovi Robinet Morales",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/drobinetm/release-cherry-pick.git"
39
+ },
40
+ "homepage": "https://github.com/drobinetm/release-cherry-pick#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/drobinetm/release-cherry-pick/issues"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "type": "commonjs",
48
+ "engines": {
49
+ "node": ">=18"
50
+ },
51
+ "dependencies": {
52
+ "@anthropic-ai/sdk": "^0.32.0",
53
+ "chalk": "^4.1.2",
54
+ "commander": "^15.0.0",
55
+ "inquirer": "^8.2.7",
56
+ "inquirer-autocomplete-prompt": "^2.0.0",
57
+ "inquirer-checkbox-plus-prompt": "^1.4.2",
58
+ "simple-git": "^3.36.0"
59
+ },
60
+ "devDependencies": {
61
+ "@eslint/js": "^10.0.1",
62
+ "eslint": "^10.11.0",
63
+ "husky": "^9.1.7",
64
+ "lint-staged": "^17.5.1"
65
+ }
66
+ }
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const { program } = require('commander');
4
+ const pkg = require('../../package.json');
5
+
6
+ function createProgram() {
7
+ return program
8
+ .name('release-cherry-pick')
9
+ .description('CLI tool for automating release cherry-pick and GitLab MR creation')
10
+ .version(pkg.version);
11
+ }
12
+
13
+ module.exports = { createProgram };
@@ -0,0 +1,285 @@
1
+ 'use strict';
2
+
3
+ const logger = require('../utils/logger');
4
+
5
+ const DEFAULT_PROVIDER = 'anthropic';
6
+ const MODELS_DEV_URL = 'https://models.dev/api.json';
7
+ const CATALOG_TIMEOUT_MS = 8000;
8
+ const LIVE_TIMEOUT_MS = 10000;
9
+
10
+ // Used when models.dev is unreachable, or when a popular provider has no `api` field in the catalog.
11
+ const KNOWN_BASE_URLS = {
12
+ anthropic: 'https://api.anthropic.com/v1',
13
+ openai: 'https://api.openai.com/v1',
14
+ google: null,
15
+ groq: 'https://api.groq.com/openai/v1',
16
+ mistral: 'https://api.mistral.ai/v1',
17
+ xai: 'https://api.x.ai/v1',
18
+ cerebras: 'https://api.cerebras.ai/v1',
19
+ togetherai: 'https://api.together.xyz/v1',
20
+ fireworksai: 'https://api.fireworks.ai/inference/v1',
21
+ perplexity: 'https://api.perplexity.ai',
22
+ deepseek: 'https://api.deepseek.com',
23
+ openrouter: 'https://openrouter.ai/api/v1',
24
+ 'github-copilot': 'https://api.githubcopilot.com',
25
+ lmstudio: 'http://127.0.0.1:1234/v1',
26
+ alibaba: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
27
+ moonshotai: 'https://api.moonshot.ai/v1',
28
+ nvidia: 'https://integrate.api.nvidia.com/v1'
29
+ };
30
+
31
+ // Minimal offline fallback so the wizard still works without network access.
32
+ const FALLBACK_CATALOG = {
33
+ anthropic: {
34
+ id: 'anthropic',
35
+ name: 'Anthropic',
36
+ env: 'ANTHROPIC_API_KEY',
37
+ api: KNOWN_BASE_URLS.anthropic,
38
+ models: {
39
+ 'claude-haiku-4-5': { id: 'claude-haiku-4-5', tool_call: true },
40
+ 'claude-sonnet-4-5': { id: 'claude-sonnet-4-5', tool_call: true },
41
+ 'claude-opus-4-5': { id: 'claude-opus-4-5', tool_call: true }
42
+ }
43
+ },
44
+ openai: {
45
+ id: 'openai',
46
+ name: 'OpenAI',
47
+ env: 'OPENAI_API_KEY',
48
+ api: KNOWN_BASE_URLS.openai,
49
+ models: {
50
+ 'gpt-4o-mini': { id: 'gpt-4o-mini', tool_call: true },
51
+ 'gpt-4o': { id: 'gpt-4o', tool_call: true },
52
+ 'gpt-4.1-mini': { id: 'gpt-4.1-mini', tool_call: true },
53
+ 'gpt-4.1': { id: 'gpt-4.1', tool_call: true }
54
+ }
55
+ },
56
+ google: {
57
+ id: 'google',
58
+ name: 'Google',
59
+ env: 'GOOGLE_API_KEY,GEMINI_API_KEY',
60
+ api: null,
61
+ models: {
62
+ 'gemini-2.5-flash': { id: 'gemini-2.5-flash', tool_call: true },
63
+ 'gemini-2.5-pro': { id: 'gemini-2.5-pro', tool_call: true }
64
+ }
65
+ },
66
+ groq: {
67
+ id: 'groq',
68
+ name: 'Groq',
69
+ env: 'GROQ_API_KEY',
70
+ api: KNOWN_BASE_URLS.groq,
71
+ models: {
72
+ 'llama-3.3-70b-versatile': { id: 'llama-3.3-70b-versatile', tool_call: true }
73
+ }
74
+ },
75
+ deepseek: {
76
+ id: 'deepseek',
77
+ name: 'DeepSeek',
78
+ env: 'DEEPSEEK_API_KEY',
79
+ api: KNOWN_BASE_URLS.deepseek,
80
+ models: {
81
+ 'deepseek-chat': { id: 'deepseek-chat', tool_call: true },
82
+ 'deepseek-reasoner': { id: 'deepseek-reasoner', tool_call: true }
83
+ }
84
+ },
85
+ openrouter: {
86
+ id: 'openrouter',
87
+ name: 'OpenRouter',
88
+ env: 'OPENROUTER_API_KEY',
89
+ api: KNOWN_BASE_URLS.openrouter,
90
+ models: {
91
+ 'openai/gpt-4o-mini': { id: 'openai/gpt-4o-mini', tool_call: true },
92
+ 'anthropic/claude-sonnet-4.5': { id: 'anthropic/claude-sonnet-4.5', tool_call: true }
93
+ }
94
+ }
95
+ };
96
+
97
+ let catalogCache = null;
98
+ let catalogCacheAt = 0;
99
+
100
+ function normalizeEnvKeys(env) {
101
+ if (!env) return [];
102
+ if (Array.isArray(env)) return env.filter(Boolean);
103
+ return String(env).split(',').map((key) => key.trim()).filter(Boolean);
104
+ }
105
+
106
+ function getEnvKeyNames(provider) {
107
+ if (!provider) return [];
108
+ return normalizeEnvKeys(provider.env);
109
+ }
110
+
111
+ function findEnvValue(envKeyNames) {
112
+ for (const key of envKeyNames) {
113
+ if (process.env[key]) return process.env[key];
114
+ }
115
+ return '';
116
+ }
117
+
118
+ async function fetchWithTimeout(url, options = {}, timeoutMs = CATALOG_TIMEOUT_MS) {
119
+ const controller = new globalThis.AbortController();
120
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
121
+ try {
122
+ return await globalThis.fetch(url, { ...options, signal: controller.signal });
123
+ } finally {
124
+ clearTimeout(timer);
125
+ }
126
+ }
127
+
128
+ // Loads the full provider catalog (200+ providers) from models.dev — same source OpenCode uses.
129
+ async function loadProviderCatalog({ force = false } = {}) {
130
+ const now = Date.now();
131
+ if (!force && catalogCache && now - catalogCacheAt < 5 * 60 * 1000) {
132
+ return catalogCache;
133
+ }
134
+
135
+ try {
136
+ const response = await fetchWithTimeout(MODELS_DEV_URL);
137
+ if (!response.ok) {
138
+ throw new Error(`models.dev HTTP ${response.status}`);
139
+ }
140
+ const data = await response.json();
141
+ if (!data || typeof data !== 'object' || Object.keys(data).length === 0) {
142
+ throw new Error('models.dev returned an empty catalog');
143
+ }
144
+ catalogCache = data;
145
+ catalogCacheAt = Date.now();
146
+ return data;
147
+ } catch (error) {
148
+ logger.warn(`Could not load provider catalog from models.dev (${error.message}); using built-in fallback list`);
149
+ catalogCache = FALLBACK_CATALOG;
150
+ catalogCacheAt = Date.now();
151
+ return catalogCache;
152
+ }
153
+ }
154
+
155
+ function isChatModel(model) {
156
+ if (!model) return false;
157
+ if (model.tool_call) return true;
158
+ const output = model.modalities && model.modalities.output;
159
+ return Array.isArray(output) && output.includes('text');
160
+ }
161
+
162
+ function catalogModelIds(provider) {
163
+ if (!provider || !provider.models) return [];
164
+ return Object.keys(provider.models)
165
+ .filter((id) => isChatModel(provider.models[id]))
166
+ .sort((a, b) => a.localeCompare(b));
167
+ }
168
+
169
+ function getProviderChoices(catalog) {
170
+ return Object.values(catalog)
171
+ .map((provider) => ({
172
+ name: provider.name || provider.id,
173
+ value: provider.id
174
+ }))
175
+ .sort((a, b) => a.name.localeCompare(b.name));
176
+ }
177
+
178
+ function resolveApiKey(config, providerId, providerEntry) {
179
+ if (config && config.ai && config.ai.apiKey) {
180
+ return config.ai.apiKey;
181
+ }
182
+ const envValue = findEnvValue(getEnvKeyNames(providerEntry));
183
+ if (envValue) return envValue;
184
+ // Legacy single-key configs from earlier releases
185
+ const legacyEnv = providerId === 'anthropic' ? 'ANTHROPIC_API_KEY'
186
+ : providerId === 'openai' ? 'OPENAI_API_KEY' : '';
187
+ return legacyEnv && process.env[legacyEnv] ? process.env[legacyEnv] : '';
188
+ }
189
+
190
+ function resolveBaseURL(providerId, providerEntry, config) {
191
+ if (config && config.ai && config.ai.baseURL) return config.ai.baseURL;
192
+ if (providerEntry && providerEntry.api) return providerEntry.api;
193
+ return KNOWN_BASE_URLS[providerId] || null;
194
+ }
195
+
196
+ function joinUrl(base, path) {
197
+ return `${String(base).replace(/\/+$/, '')}${path}`;
198
+ }
199
+
200
+ async function listModelsLive(providerId, provider, apiKey, baseURL) {
201
+ if (!apiKey) return null;
202
+
203
+ try {
204
+ if (providerId === 'anthropic') {
205
+ const response = await fetchWithTimeout(joinUrl(baseURL || KNOWN_BASE_URLS.anthropic, '/models?limit=1000'), {
206
+ headers: {
207
+ 'x-api-key': apiKey,
208
+ 'anthropic-version': '2023-06-01'
209
+ }
210
+ }, LIVE_TIMEOUT_MS);
211
+ if (!response.ok) return null;
212
+ const data = await response.json();
213
+ const models = (data.data || []).map((m) => m.id).filter(Boolean);
214
+ return models.length ? models.sort((a, b) => a.localeCompare(b)) : null;
215
+ }
216
+
217
+ if (providerId === 'google') {
218
+ const response = await fetchWithTimeout(
219
+ `https://generativelanguage.googleapis.com/v1beta/models?key=${encodeURIComponent(apiKey)}&pageSize=200`,
220
+ {},
221
+ LIVE_TIMEOUT_MS
222
+ );
223
+ if (!response.ok) return null;
224
+ const data = await response.json();
225
+ const models = (data.models || [])
226
+ .map((m) => (m.name || '').replace(/^models\//, ''))
227
+ .filter(Boolean);
228
+ return models.length ? models.sort((a, b) => a.localeCompare(b)) : null;
229
+ }
230
+
231
+ if (baseURL) {
232
+ const response = await fetchWithTimeout(joinUrl(baseURL, '/models'), {
233
+ headers: { Authorization: `Bearer ${apiKey}` }
234
+ }, LIVE_TIMEOUT_MS);
235
+ if (!response.ok) return null;
236
+ const data = await response.json();
237
+ const raw = Array.isArray(data.data) ? data.data : Array.isArray(data.models) ? data.models : [];
238
+ const models = raw
239
+ .map((m) => m.id || m.name || (typeof m === 'string' ? m : null))
240
+ .filter(Boolean);
241
+ return models.length ? models.sort((a, b) => a.localeCompare(b)) : null;
242
+ }
243
+ } catch (error) {
244
+ logger.warn(`Live model list from provider failed: ${error.message}`);
245
+ }
246
+
247
+ return null;
248
+ }
249
+
250
+ // Connects to the provider and lists its models; falls back to the models.dev catalog.
251
+ async function listModelsForProvider(providerId, provider, apiKey, baseURL) {
252
+ const live = await listModelsLive(providerId, provider, apiKey, baseURL);
253
+ if (live && live.length > 0) {
254
+ return { models: live, source: 'live' };
255
+ }
256
+
257
+ const fromCatalog = catalogModelIds(provider);
258
+ if (fromCatalog.length > 0) {
259
+ return { models: fromCatalog, source: 'catalog' };
260
+ }
261
+
262
+ if (provider && provider.models) {
263
+ const all = Object.keys(provider.models).sort((a, b) => a.localeCompare(b));
264
+ if (all.length > 0) {
265
+ return { models: all, source: 'catalog' };
266
+ }
267
+ }
268
+
269
+ return { models: [], source: 'none' };
270
+ }
271
+
272
+ module.exports = {
273
+ DEFAULT_PROVIDER,
274
+ KNOWN_BASE_URLS,
275
+ FALLBACK_CATALOG,
276
+ loadProviderCatalog,
277
+ getProviderChoices,
278
+ getEnvKeyNames,
279
+ findEnvValue,
280
+ catalogModelIds,
281
+ resolveApiKey,
282
+ resolveBaseURL,
283
+ listModelsForProvider,
284
+ normalizeEnvKeys
285
+ };
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ const defaultConfig = {
4
+ git: {
5
+ stagingBranch: 'staging',
6
+ branchPrefix: {
7
+ feature: 'feature/',
8
+ hotfix: 'hotfix/',
9
+ release: 'release/'
10
+ }
11
+ },
12
+ gitlab: {
13
+ host: '',
14
+ token: ''
15
+ },
16
+ ai: {
17
+ enabled: true,
18
+ // Left empty on purpose: when AI is enabled and no provider/model is saved, ensureAiSettings
19
+ // asks for them at release time. baseURL stays empty too, so each provider resolves its own
20
+ // endpoint (resolveBaseURL prefers config.ai.baseURL, which would otherwise win for any provider).
21
+ provider: '',
22
+ apiKey: '',
23
+ model: '',
24
+ baseURL: ''
25
+ },
26
+ release: {
27
+ autoCreateMR: true,
28
+ mrTitleFormat: '[{taskId}] {description}',
29
+ // GitLab usernames, picked from the real project members in the setup wizard
30
+ defaultReviewers: [],
31
+ defaultAssignees: [],
32
+ mrSquash: true,
33
+ mrRemoveSourceBranch: true,
34
+ branches: []
35
+ }
36
+ };
37
+
38
+ function getDefaultConfig() {
39
+ return JSON.parse(JSON.stringify(defaultConfig));
40
+ }
41
+
42
+ module.exports = {
43
+ getDefaultConfig,
44
+ defaultConfig
45
+ };