threadlines 0.1.12 → 0.1.14

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.
@@ -47,6 +47,36 @@ const config_1 = require("../utils/config");
47
47
  const fs = __importStar(require("fs"));
48
48
  const path = __importStar(require("path"));
49
49
  const chalk_1 = __importDefault(require("chalk"));
50
+ /**
51
+ * Detect the environment where the check is being run
52
+ * Returns: 'vercel', 'github', 'gitlab', or 'local'
53
+ */
54
+ function detectEnvironment() {
55
+ console.log(chalk_1.default.gray(' [DEBUG] detectEnvironment: Starting detection...'));
56
+ console.log(chalk_1.default.gray(` [DEBUG] detectEnvironment: VERCEL = "${process.env.VERCEL || 'NOT SET'}"`));
57
+ console.log(chalk_1.default.gray(` [DEBUG] detectEnvironment: GITHUB_ACTIONS = "${process.env.GITHUB_ACTIONS || 'NOT SET'}"`));
58
+ console.log(chalk_1.default.gray(` [DEBUG] detectEnvironment: GITLAB_CI = "${process.env.GITLAB_CI || 'NOT SET'}"`));
59
+ console.log(chalk_1.default.gray(` [DEBUG] detectEnvironment: CI = "${process.env.CI || 'NOT SET'}"`));
60
+ console.log(chalk_1.default.gray(` [DEBUG] detectEnvironment: CI_COMMIT_SHA = "${process.env.CI_COMMIT_SHA || 'NOT SET'}"`));
61
+ // Vercel: VERCEL env var is always set in Vercel builds
62
+ if (process.env.VERCEL) {
63
+ console.log(chalk_1.default.green(' [DEBUG] detectEnvironment: Detected VERCEL'));
64
+ return 'vercel';
65
+ }
66
+ // GitHub Actions: GITHUB_ACTIONS env var is always set
67
+ if (process.env.GITHUB_ACTIONS) {
68
+ console.log(chalk_1.default.green(' [DEBUG] detectEnvironment: Detected GITHUB_ACTIONS'));
69
+ return 'github';
70
+ }
71
+ // GitLab CI: GITLAB_CI env var is always set, or CI is set with GitLab-specific vars
72
+ if (process.env.GITLAB_CI || (process.env.CI && process.env.CI_COMMIT_SHA)) {
73
+ console.log(chalk_1.default.green(' [DEBUG] detectEnvironment: Detected GITLAB_CI'));
74
+ return 'gitlab';
75
+ }
76
+ // Local development: none of the above
77
+ console.log(chalk_1.default.yellow(' [DEBUG] detectEnvironment: No CI env vars detected - returning "local"'));
78
+ return 'local';
79
+ }
50
80
  async function checkCommand(options) {
51
81
  const repoRoot = process.cwd();
52
82
  console.log(chalk_1.default.blue('šŸ” Threadline: Checking code against your threadlines...\n'));
@@ -212,15 +242,36 @@ async function checkCommand(options) {
212
242
  };
213
243
  });
214
244
  // 4. Get repo name and branch name
245
+ console.log(chalk_1.default.gray('\nšŸ“” Detecting repository and branch information...'));
246
+ // Log Vercel-specific env vars that might help with repo detection
247
+ if (process.env.VERCEL) {
248
+ console.log(chalk_1.default.gray(' [DEBUG] Vercel environment variables:'));
249
+ console.log(chalk_1.default.gray(` [DEBUG] VERCEL_GIT_REPO_OWNER = "${process.env.VERCEL_GIT_REPO_OWNER || 'NOT SET'}"`));
250
+ console.log(chalk_1.default.gray(` [DEBUG] VERCEL_GIT_REPO_SLUG = "${process.env.VERCEL_GIT_REPO_SLUG || 'NOT SET'}"`));
251
+ console.log(chalk_1.default.gray(` [DEBUG] VERCEL_GIT_REPO_ID = "${process.env.VERCEL_GIT_REPO_ID || 'NOT SET'}"`));
252
+ console.log(chalk_1.default.gray(` [DEBUG] VERCEL_GIT_COMMIT_REF = "${process.env.VERCEL_GIT_COMMIT_REF || 'NOT SET'}"`));
253
+ console.log(chalk_1.default.gray(` [DEBUG] VERCEL_GIT_COMMIT_SHA = "${process.env.VERCEL_GIT_COMMIT_SHA || 'NOT SET'}"`));
254
+ }
215
255
  const repoName = await (0, repo_1.getRepoName)(repoRoot);
216
256
  const branchName = await (0, repo_1.getBranchName)(repoRoot);
217
- // 5. Get API URL (auto-detect Vercel if available)
257
+ // 5. Get API URL
218
258
  const apiUrl = options.apiUrl ||
219
259
  process.env.THREADLINE_API_URL ||
220
- (process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : null) ||
221
- 'http://localhost:3000';
222
- // 6. Call review API
223
- console.log(chalk_1.default.gray('šŸ¤– Running threadline checks...'));
260
+ 'https://devthreadline.com';
261
+ // 6. Detect environment
262
+ console.log(chalk_1.default.gray('\nšŸŒ Detecting environment...'));
263
+ const environment = detectEnvironment();
264
+ // 7. Log final values being sent to API
265
+ console.log(chalk_1.default.gray('\nšŸ“¤ Final values being sent to API:'));
266
+ console.log(chalk_1.default.gray(` repoName: ${repoName ? `"${repoName}"` : 'null/undefined'}`));
267
+ console.log(chalk_1.default.gray(` branchName: ${branchName ? `"${branchName}"` : 'null/undefined'}`));
268
+ console.log(chalk_1.default.gray(` commitSha: ${commitSha ? `"${commitSha}"` : 'null/undefined'}`));
269
+ console.log(chalk_1.default.gray(` commitMessage: ${commitMessage ? `"${commitMessage.substring(0, 50)}..."` : 'null/undefined'}`));
270
+ console.log(chalk_1.default.gray(` prTitle: ${prTitle ? `"${prTitle}"` : 'null/undefined'}`));
271
+ console.log(chalk_1.default.gray(` environment: "${environment}"`));
272
+ console.log(chalk_1.default.gray(` reviewContext: ${JSON.stringify(reviewContext)}`));
273
+ // 8. Call review API
274
+ console.log(chalk_1.default.gray('\nšŸ¤– Running threadline checks...'));
224
275
  const client = new client_1.ReviewAPIClient(apiUrl);
225
276
  const response = await client.review({
226
277
  threadlines: threadlinesWithContext,
@@ -232,7 +283,8 @@ async function checkCommand(options) {
232
283
  branchName: branchName || undefined,
233
284
  commitSha: commitSha,
234
285
  commitMessage: commitMessage,
235
- prTitle: prTitle
286
+ prTitle: prTitle,
287
+ environment: environment
236
288
  });
237
289
  // 7. Display results (with filtering if --full not specified)
238
290
  displayResults(response, options.full || false);
package/dist/git/repo.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getRepoName = getRepoName;
7
7
  exports.getBranchName = getBranchName;
8
8
  const simple_git_1 = __importDefault(require("simple-git"));
9
+ const chalk_1 = __importDefault(require("chalk"));
9
10
  /**
10
11
  * Gets the raw git remote URL from origin.
11
12
  * Returns the URL exactly as Git provides it - no parsing or normalization.
@@ -13,16 +14,38 @@ const simple_git_1 = __importDefault(require("simple-git"));
13
14
  */
14
15
  async function getRepoName(repoRoot) {
15
16
  const git = (0, simple_git_1.default)(repoRoot);
17
+ console.log(chalk_1.default.gray(' [DEBUG] getRepoName: Starting...'));
18
+ console.log(chalk_1.default.gray(` [DEBUG] getRepoName: repoRoot = ${repoRoot}`));
16
19
  try {
17
20
  const remotes = await git.getRemotes(true);
21
+ console.log(chalk_1.default.gray(` [DEBUG] getRepoName: Found ${remotes.length} remote(s)`));
22
+ if (remotes.length > 0) {
23
+ remotes.forEach((remote, idx) => {
24
+ console.log(chalk_1.default.gray(` [DEBUG] getRepoName: Remote[${idx}] name="${remote.name}", fetch="${remote.refs?.fetch || 'N/A'}", push="${remote.refs?.push || 'N/A'}"`));
25
+ });
26
+ }
27
+ else {
28
+ console.log(chalk_1.default.yellow(' [DEBUG] getRepoName: No remotes found'));
29
+ }
18
30
  const origin = remotes.find(r => r.name === 'origin');
19
- if (!origin || !origin.refs?.fetch) {
31
+ if (!origin) {
32
+ console.log(chalk_1.default.yellow(' [DEBUG] getRepoName: No "origin" remote found'));
33
+ return null;
34
+ }
35
+ console.log(chalk_1.default.gray(` [DEBUG] getRepoName: Found origin remote: fetch="${origin.refs?.fetch || 'N/A'}"`));
36
+ if (!origin.refs?.fetch) {
37
+ console.log(chalk_1.default.yellow(' [DEBUG] getRepoName: Origin remote found but no fetch URL'));
20
38
  return null;
21
39
  }
40
+ console.log(chalk_1.default.green(` [DEBUG] getRepoName: Success - returning "${origin.refs.fetch}"`));
22
41
  // Return raw URL - let server handle normalization if needed
23
42
  return origin.refs.fetch;
24
43
  }
25
44
  catch (error) {
45
+ console.log(chalk_1.default.red(` [DEBUG] getRepoName: Error occurred: ${error.message || error}`));
46
+ if (error.stack) {
47
+ console.log(chalk_1.default.gray(` [DEBUG] getRepoName: Stack: ${error.stack}`));
48
+ }
26
49
  return null;
27
50
  }
28
51
  }
@@ -32,11 +55,23 @@ async function getRepoName(repoRoot) {
32
55
  */
33
56
  async function getBranchName(repoRoot) {
34
57
  const git = (0, simple_git_1.default)(repoRoot);
58
+ console.log(chalk_1.default.gray(' [DEBUG] getBranchName: Starting...'));
59
+ console.log(chalk_1.default.gray(` [DEBUG] getBranchName: repoRoot = ${repoRoot}`));
35
60
  try {
36
61
  const branch = await git.revparse(['--abbrev-ref', 'HEAD']);
37
- return branch || null;
62
+ console.log(chalk_1.default.gray(` [DEBUG] getBranchName: git revparse --abbrev-ref HEAD returned: "${branch || '(empty)'}"`));
63
+ if (!branch) {
64
+ console.log(chalk_1.default.yellow(' [DEBUG] getBranchName: Git command returned empty string'));
65
+ return null;
66
+ }
67
+ console.log(chalk_1.default.green(` [DEBUG] getBranchName: Success - returning "${branch}"`));
68
+ return branch;
38
69
  }
39
70
  catch (error) {
71
+ console.log(chalk_1.default.red(` [DEBUG] getBranchName: Error occurred: ${error.message || error}`));
72
+ if (error.stack) {
73
+ console.log(chalk_1.default.gray(` [DEBUG] getBranchName: Stack: ${error.stack}`));
74
+ }
40
75
  return null;
41
76
  }
42
77
  }
package/dist/index.js CHANGED
@@ -61,7 +61,7 @@ program
61
61
  program
62
62
  .command('check')
63
63
  .description('Check code against your threadlines')
64
- .option('--api-url <url>', 'Threadline server URL', process.env.THREADLINE_API_URL || (process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'http://localhost:3000'))
64
+ .option('--api-url <url>', 'Threadline server URL', process.env.THREADLINE_API_URL || 'https://devthreadline.com')
65
65
  .option('--full', 'Show all results (compliant, attention, not_relevant). Default: only attention items')
66
66
  .option('--branch <name>', 'Review all commits in branch vs base (e.g., --branch feature/new-feature)')
67
67
  .option('--commit <ref>', 'Review specific commit. Accepts commit SHA or git reference (e.g., HEAD, HEAD~1, abc123). Example: --commit HEAD')
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getAutoReviewTarget = getAutoReviewTarget;
7
+ const chalk_1 = __importDefault(require("chalk"));
4
8
  function getAutoReviewTarget() {
9
+ console.log(chalk_1.default.gray(' [DEBUG] getAutoReviewTarget: Starting detection...'));
5
10
  // 1. Check for PR/MR context (most authoritative)
6
11
  // GitHub Actions PR
12
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: Checking GitHub Actions PR...`));
13
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: GITHUB_EVENT_NAME = "${process.env.GITHUB_EVENT_NAME || 'NOT SET'}"`));
7
14
  if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
8
15
  const targetBranch = process.env.GITHUB_BASE_REF;
9
16
  const sourceBranch = process.env.GITHUB_HEAD_REF;
10
17
  const prNumber = process.env.GITHUB_EVENT_PULL_REQUEST_NUMBER;
18
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: GITHUB_BASE_REF = "${targetBranch || 'NOT SET'}"`));
19
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: GITHUB_HEAD_REF = "${sourceBranch || 'NOT SET'}"`));
20
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: GITHUB_EVENT_PULL_REQUEST_NUMBER = "${prNumber || 'NOT SET'}"`));
11
21
  if (targetBranch && sourceBranch && prNumber) {
22
+ console.log(chalk_1.default.green(` [DEBUG] getAutoReviewTarget: Detected GitHub PR #${prNumber}`));
12
23
  return {
13
24
  type: 'pr',
14
25
  value: prNumber,
@@ -16,14 +27,23 @@ function getAutoReviewTarget() {
16
27
  targetBranch
17
28
  };
18
29
  }
30
+ else {
31
+ console.log(chalk_1.default.yellow(' [DEBUG] getAutoReviewTarget: GitHub PR env vars incomplete'));
32
+ }
19
33
  }
20
34
  // GitLab CI MR
35
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: Checking GitLab CI MR...`));
36
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: CI_MERGE_REQUEST_IID = "${process.env.CI_MERGE_REQUEST_IID || 'NOT SET'}"`));
21
37
  if (process.env.CI_MERGE_REQUEST_IID) {
22
38
  const targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;
23
39
  const sourceBranch = process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME;
24
40
  const mrNumber = process.env.CI_MERGE_REQUEST_IID;
25
41
  const mrTitle = process.env.CI_MERGE_REQUEST_TITLE; // Reliable GitLab CI env var
42
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: CI_MERGE_REQUEST_TARGET_BRANCH_NAME = "${targetBranch || 'NOT SET'}"`));
43
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: CI_MERGE_REQUEST_SOURCE_BRANCH_NAME = "${sourceBranch || 'NOT SET'}"`));
44
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: CI_MERGE_REQUEST_TITLE = "${mrTitle || 'NOT SET'}"`));
26
45
  if (targetBranch && sourceBranch && mrNumber) {
46
+ console.log(chalk_1.default.green(` [DEBUG] getAutoReviewTarget: Detected GitLab MR #${mrNumber}`));
27
47
  return {
28
48
  type: 'mr',
29
49
  value: mrNumber,
@@ -32,27 +52,41 @@ function getAutoReviewTarget() {
32
52
  prTitle: mrTitle || undefined // Only include if present
33
53
  };
34
54
  }
55
+ else {
56
+ console.log(chalk_1.default.yellow(' [DEBUG] getAutoReviewTarget: GitLab MR env vars incomplete'));
57
+ }
35
58
  }
36
59
  // 2. Check for branch name (CI with branch)
60
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: Checking branch env vars...`));
61
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: GITHUB_REF_NAME = "${process.env.GITHUB_REF_NAME || 'NOT SET'}"`));
62
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: CI_COMMIT_REF_NAME = "${process.env.CI_COMMIT_REF_NAME || 'NOT SET'}"`));
63
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: VERCEL_GIT_COMMIT_REF = "${process.env.VERCEL_GIT_COMMIT_REF || 'NOT SET'}"`));
37
64
  const branch = process.env.GITHUB_REF_NAME || // GitHub Actions
38
65
  process.env.CI_COMMIT_REF_NAME || // GitLab CI
39
66
  process.env.VERCEL_GIT_COMMIT_REF; // Vercel
40
67
  if (branch) {
68
+ console.log(chalk_1.default.green(` [DEBUG] getAutoReviewTarget: Detected branch "${branch}"`));
41
69
  return {
42
70
  type: 'branch',
43
71
  value: branch
44
72
  };
45
73
  }
46
74
  // 3. Check for commit SHA (CI without branch)
75
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: Checking commit SHA env vars...`));
76
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: GITHUB_SHA = "${process.env.GITHUB_SHA || 'NOT SET'}"`));
77
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: CI_COMMIT_SHA = "${process.env.CI_COMMIT_SHA || 'NOT SET'}"`));
78
+ console.log(chalk_1.default.gray(` [DEBUG] getAutoReviewTarget: VERCEL_GIT_COMMIT_SHA = "${process.env.VERCEL_GIT_COMMIT_SHA || 'NOT SET'}"`));
47
79
  const commit = process.env.GITHUB_SHA || // GitHub Actions
48
80
  process.env.CI_COMMIT_SHA || // GitLab CI
49
81
  process.env.VERCEL_GIT_COMMIT_SHA; // Vercel
50
82
  if (commit) {
83
+ console.log(chalk_1.default.green(` [DEBUG] getAutoReviewTarget: Detected commit "${commit}"`));
51
84
  return {
52
85
  type: 'commit',
53
86
  value: commit
54
87
  };
55
88
  }
56
89
  // 4. Local development (no CI env vars)
90
+ console.log(chalk_1.default.yellow(' [DEBUG] getAutoReviewTarget: No CI env vars detected - returning null (local mode)'));
57
91
  return null;
58
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threadlines",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Threadline CLI - AI-powered linter based on your natural language documentation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {