cortex-agents 2.3.1 → 4.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.
Files changed (70) hide show
  1. package/.opencode/agents/{plan.md → architect.md} +104 -58
  2. package/.opencode/agents/audit.md +183 -0
  3. package/.opencode/agents/{fullstack.md → coder.md} +10 -54
  4. package/.opencode/agents/debug.md +76 -201
  5. package/.opencode/agents/devops.md +16 -123
  6. package/.opencode/agents/docs-writer.md +195 -0
  7. package/.opencode/agents/fix.md +207 -0
  8. package/.opencode/agents/implement.md +433 -0
  9. package/.opencode/agents/perf.md +151 -0
  10. package/.opencode/agents/refactor.md +163 -0
  11. package/.opencode/agents/security.md +20 -85
  12. package/.opencode/agents/testing.md +1 -151
  13. package/.opencode/skills/data-engineering/SKILL.md +221 -0
  14. package/.opencode/skills/monitoring-observability/SKILL.md +251 -0
  15. package/README.md +315 -224
  16. package/dist/cli.js +85 -17
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +60 -22
  19. package/dist/registry.d.ts +8 -3
  20. package/dist/registry.d.ts.map +1 -1
  21. package/dist/registry.js +16 -2
  22. package/dist/tools/branch.d.ts +2 -2
  23. package/dist/tools/cortex.d.ts +2 -2
  24. package/dist/tools/cortex.js +7 -7
  25. package/dist/tools/docs.d.ts +2 -2
  26. package/dist/tools/environment.d.ts +31 -0
  27. package/dist/tools/environment.d.ts.map +1 -0
  28. package/dist/tools/environment.js +93 -0
  29. package/dist/tools/github.d.ts +42 -0
  30. package/dist/tools/github.d.ts.map +1 -0
  31. package/dist/tools/github.js +200 -0
  32. package/dist/tools/plan.d.ts +28 -4
  33. package/dist/tools/plan.d.ts.map +1 -1
  34. package/dist/tools/plan.js +232 -4
  35. package/dist/tools/quality-gate.d.ts +28 -0
  36. package/dist/tools/quality-gate.d.ts.map +1 -0
  37. package/dist/tools/quality-gate.js +233 -0
  38. package/dist/tools/repl.d.ts +55 -0
  39. package/dist/tools/repl.d.ts.map +1 -0
  40. package/dist/tools/repl.js +291 -0
  41. package/dist/tools/task.d.ts +2 -0
  42. package/dist/tools/task.d.ts.map +1 -1
  43. package/dist/tools/task.js +25 -30
  44. package/dist/tools/worktree.d.ts +5 -32
  45. package/dist/tools/worktree.d.ts.map +1 -1
  46. package/dist/tools/worktree.js +75 -447
  47. package/dist/utils/change-scope.d.ts +33 -0
  48. package/dist/utils/change-scope.d.ts.map +1 -0
  49. package/dist/utils/change-scope.js +198 -0
  50. package/dist/utils/github.d.ts +104 -0
  51. package/dist/utils/github.d.ts.map +1 -0
  52. package/dist/utils/github.js +243 -0
  53. package/dist/utils/ide.d.ts +76 -0
  54. package/dist/utils/ide.d.ts.map +1 -0
  55. package/dist/utils/ide.js +307 -0
  56. package/dist/utils/plan-extract.d.ts +28 -0
  57. package/dist/utils/plan-extract.d.ts.map +1 -1
  58. package/dist/utils/plan-extract.js +90 -1
  59. package/dist/utils/repl.d.ts +145 -0
  60. package/dist/utils/repl.d.ts.map +1 -0
  61. package/dist/utils/repl.js +547 -0
  62. package/dist/utils/terminal.d.ts +53 -1
  63. package/dist/utils/terminal.d.ts.map +1 -1
  64. package/dist/utils/terminal.js +642 -5
  65. package/package.json +1 -1
  66. package/.opencode/agents/build.md +0 -294
  67. package/.opencode/agents/review.md +0 -314
  68. package/dist/plugin.d.ts +0 -1
  69. package/dist/plugin.d.ts.map +0 -1
  70. package/dist/plugin.js +0 -4
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Change Scope Detection
3
+ *
4
+ * Categorizes changed files by risk level to determine which sub-agents
5
+ * should be triggered during the quality gate. Avoids wasting tokens on
6
+ * trivial changes while ensuring high-risk changes get full coverage.
7
+ */
8
+ // ─── File Pattern Matchers ───────────────────────────────────────────────────
9
+ /** Patterns that indicate trivial changes — docs, comments, formatting only */
10
+ const TRIVIAL_PATTERNS = [
11
+ /\.md$/i,
12
+ /\.txt$/i,
13
+ /\.mdx$/i,
14
+ /LICENSE/i,
15
+ /CHANGELOG/i,
16
+ /\.prettierrc/,
17
+ /\.editorconfig/,
18
+ /\.vscode\//,
19
+ /\.idea\//,
20
+ ];
21
+ /** Patterns that indicate test/config-only changes — low risk */
22
+ const LOW_RISK_PATTERNS = [
23
+ /\.test\.[jt]sx?$/,
24
+ /\.spec\.[jt]sx?$/,
25
+ /__tests__\//,
26
+ /test\//,
27
+ /tests\//,
28
+ /\.eslintrc/,
29
+ /\.prettierrc/,
30
+ /tsconfig.*\.json$/,
31
+ /jest\.config/,
32
+ /vitest\.config/,
33
+ /\.gitignore$/,
34
+ ];
35
+ /** Patterns that indicate high-risk changes — auth, payments, infra, security */
36
+ const HIGH_RISK_PATTERNS = [
37
+ // Auth & security
38
+ /auth/i,
39
+ /login/i,
40
+ /session/i,
41
+ /password/i,
42
+ /token/i,
43
+ /crypto/i,
44
+ /encrypt/i,
45
+ /permission/i,
46
+ /rbac/i,
47
+ /oauth/i,
48
+ /jwt/i,
49
+ /middleware\/auth/i,
50
+ // Payment & sensitive data
51
+ /payment/i,
52
+ /billing/i,
53
+ /stripe/i,
54
+ /checkout/i,
55
+ // Infrastructure & deployment
56
+ /Dockerfile/i,
57
+ /docker-compose/i,
58
+ /\.github\/workflows\//,
59
+ /\.gitlab-ci/,
60
+ /Jenkinsfile/i,
61
+ /\.circleci\//,
62
+ /terraform\//,
63
+ /pulumi\//,
64
+ /k8s\//,
65
+ /deploy\//,
66
+ /infra\//,
67
+ /nginx\.conf/i,
68
+ /Caddyfile/i,
69
+ /Procfile/i,
70
+ /fly\.toml/i,
71
+ ];
72
+ /** Patterns that indicate DevOps file changes */
73
+ const DEVOPS_PATTERNS = [
74
+ /Dockerfile/i,
75
+ /docker-compose/i,
76
+ /\.dockerignore/i,
77
+ /\.github\/workflows\//,
78
+ /\.gitlab-ci/,
79
+ /Jenkinsfile/i,
80
+ /\.circleci\//,
81
+ /terraform\//,
82
+ /pulumi\//,
83
+ /cdk\//,
84
+ /k8s\//,
85
+ /deploy\//,
86
+ /infra\//,
87
+ /nginx\.conf/i,
88
+ /Caddyfile/i,
89
+ /Procfile/i,
90
+ /fly\.toml/i,
91
+ /railway\.json/i,
92
+ /render\.yaml/i,
93
+ ];
94
+ /** Patterns that indicate performance-sensitive changes */
95
+ const PERF_PATTERNS = [
96
+ /query/i,
97
+ /database/i,
98
+ /migration/i,
99
+ /\.sql$/i,
100
+ /prisma/i,
101
+ /drizzle/i,
102
+ /repository/i,
103
+ /cache/i,
104
+ /render/i,
105
+ /component/i,
106
+ /hook/i,
107
+ /algorithm/i,
108
+ /sort/i,
109
+ /search/i,
110
+ /index/i,
111
+ /worker/i,
112
+ /stream/i,
113
+ /batch/i,
114
+ /queue/i,
115
+ ];
116
+ // ─── Classification ──────────────────────────────────────────────────────────
117
+ /**
118
+ * Classify a set of changed files into a risk scope and determine
119
+ * which sub-agents should be triggered.
120
+ *
121
+ * @param changedFiles - Array of file paths that were created or modified
122
+ * @returns Classification result with scope, rationale, and agent triggers
123
+ */
124
+ export function classifyChangeScope(changedFiles) {
125
+ if (changedFiles.length === 0) {
126
+ return {
127
+ scope: "trivial",
128
+ rationale: "No files changed",
129
+ agents: noAgents(),
130
+ };
131
+ }
132
+ const hasHighRisk = changedFiles.some((f) => HIGH_RISK_PATTERNS.some((p) => p.test(f)));
133
+ const hasDevOps = changedFiles.some((f) => DEVOPS_PATTERNS.some((p) => p.test(f)));
134
+ const hasPerf = changedFiles.some((f) => PERF_PATTERNS.some((p) => p.test(f)));
135
+ const allTrivial = changedFiles.every((f) => TRIVIAL_PATTERNS.some((p) => p.test(f)));
136
+ const allLowRisk = changedFiles.every((f) => LOW_RISK_PATTERNS.some((p) => p.test(f)) || TRIVIAL_PATTERNS.some((p) => p.test(f)));
137
+ // Trivial — docs/comments only
138
+ if (allTrivial) {
139
+ return {
140
+ scope: "trivial",
141
+ rationale: "Documentation/formatting changes only — no quality gate needed",
142
+ agents: {
143
+ ...noAgents(),
144
+ docsWriter: true,
145
+ },
146
+ };
147
+ }
148
+ // Low risk — tests/config only
149
+ if (allLowRisk) {
150
+ return {
151
+ scope: "low",
152
+ rationale: "Test/config changes only — minimal quality gate",
153
+ agents: {
154
+ ...noAgents(),
155
+ testing: true,
156
+ },
157
+ };
158
+ }
159
+ // High risk — auth, payments, infra
160
+ if (hasHighRisk) {
161
+ return {
162
+ scope: "high",
163
+ rationale: "High-risk changes detected (auth/security/payments/infra) — full quality gate",
164
+ agents: {
165
+ testing: true,
166
+ security: true,
167
+ audit: true,
168
+ devops: hasDevOps,
169
+ perf: hasPerf,
170
+ docsWriter: true,
171
+ },
172
+ };
173
+ }
174
+ // Standard — everything else
175
+ return {
176
+ scope: "standard",
177
+ rationale: "Standard code changes — normal quality gate",
178
+ agents: {
179
+ testing: true,
180
+ security: true,
181
+ audit: true,
182
+ devops: hasDevOps,
183
+ perf: hasPerf,
184
+ docsWriter: true,
185
+ },
186
+ };
187
+ }
188
+ /** Helper: no agents triggered */
189
+ function noAgents() {
190
+ return {
191
+ testing: false,
192
+ security: false,
193
+ audit: false,
194
+ devops: false,
195
+ perf: false,
196
+ docsWriter: false,
197
+ };
198
+ }
@@ -0,0 +1,104 @@
1
+ export interface GhStatus {
2
+ installed: boolean;
3
+ authenticated: boolean;
4
+ hasRemote: boolean;
5
+ repoOwner?: string;
6
+ repoName?: string;
7
+ projects: {
8
+ id: string;
9
+ number: number;
10
+ title: string;
11
+ }[];
12
+ }
13
+ export interface GitHubIssue {
14
+ number: number;
15
+ title: string;
16
+ state: string;
17
+ labels: string[];
18
+ assignees: string[];
19
+ milestone?: string;
20
+ body: string;
21
+ url: string;
22
+ createdAt: string;
23
+ updatedAt: string;
24
+ }
25
+ export interface GitHubProjectItem {
26
+ id: string;
27
+ title: string;
28
+ type: "ISSUE" | "PULL_REQUEST" | "DRAFT_ISSUE";
29
+ status?: string;
30
+ assignees: string[];
31
+ labels: string[];
32
+ issueNumber?: number;
33
+ url?: string;
34
+ body?: string;
35
+ }
36
+ /**
37
+ * Check full GitHub CLI availability and repo context.
38
+ * Returns a status object with installation, authentication, and repo info.
39
+ */
40
+ export declare function checkGhAvailability(cwd: string): Promise<GhStatus>;
41
+ /**
42
+ * Parse a git remote URL to extract owner and repo name.
43
+ * Handles HTTPS, SSH, and GitHub CLI formats.
44
+ * Supports both github.com and GitHub Enterprise Server URLs (e.g., github.mycompany.com).
45
+ *
46
+ * The regex requires "github" to appear at a hostname boundary (after `//` or `@`)
47
+ * to prevent false positives like "notgithub.com" or "fakegithub.evil.com".
48
+ */
49
+ export declare function parseRepoUrl(url: string): {
50
+ owner: string;
51
+ name: string;
52
+ } | null;
53
+ /**
54
+ * Truncate a string to the given length, appending "..." if truncated.
55
+ */
56
+ export declare function truncate(str: string, maxLen: number): string;
57
+ /**
58
+ * Format a single GitHub issue into a compact list entry.
59
+ * Used when presenting multiple issues for selection.
60
+ */
61
+ export declare function formatIssueListEntry(issue: GitHubIssue): string;
62
+ /**
63
+ * Format multiple issues into a numbered selection list.
64
+ */
65
+ export declare function formatIssueList(issues: GitHubIssue[]): string;
66
+ /**
67
+ * Format a GitHub issue into a planning-friendly markdown block.
68
+ * Used by the architect agent to seed plan content from selected issues.
69
+ */
70
+ export declare function formatIssueForPlan(issue: GitHubIssue): string;
71
+ /**
72
+ * Format a single GitHub Project item into a compact list entry.
73
+ */
74
+ export declare function formatProjectItemEntry(item: GitHubProjectItem): string;
75
+ /**
76
+ * Format multiple project items into a list.
77
+ */
78
+ export declare function formatProjectItemList(items: GitHubProjectItem[]): string;
79
+ /**
80
+ * Fetch GitHub projects associated with the repo owner.
81
+ */
82
+ export declare function fetchProjects(cwd: string, owner: string): Promise<{
83
+ id: string;
84
+ number: number;
85
+ title: string;
86
+ }[]>;
87
+ /**
88
+ * Fetch issues from the current repository using gh CLI.
89
+ */
90
+ export declare function fetchIssues(cwd: string, options?: {
91
+ state?: string;
92
+ labels?: string;
93
+ milestone?: string;
94
+ assignee?: string;
95
+ limit?: number;
96
+ }): Promise<GitHubIssue[]>;
97
+ /**
98
+ * Fetch project items from a specific GitHub Project.
99
+ */
100
+ export declare function fetchProjectItems(cwd: string, owner: string, projectNumber: number, options?: {
101
+ status?: string;
102
+ limit?: number;
103
+ }): Promise<GitHubProjectItem[]>;
104
+ //# sourceMappingURL=github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/utils/github.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,243 @@
1
+ import { gh, which, git } from "./shell.js";
2
+ // ─── Constants ───────────────────────────────────────────────────────────────
3
+ /** Maximum character length for issue body in list views to avoid overwhelming context. */
4
+ const BODY_TRUNCATE_LENGTH = 200;
5
+ /** Maximum character length for issue body in detail views (plan formatting). */
6
+ const BODY_DETAIL_LENGTH = 2000;
7
+ // ─── GitHub CLI Availability ─────────────────────────────────────────────────
8
+ /**
9
+ * Check full GitHub CLI availability and repo context.
10
+ * Returns a status object with installation, authentication, and repo info.
11
+ */
12
+ export async function checkGhAvailability(cwd) {
13
+ const status = {
14
+ installed: false,
15
+ authenticated: false,
16
+ hasRemote: false,
17
+ projects: [],
18
+ };
19
+ // 1. Check if gh is installed
20
+ const ghPath = await which("gh");
21
+ if (!ghPath)
22
+ return status;
23
+ status.installed = true;
24
+ // 2. Check if authenticated
25
+ try {
26
+ await gh(cwd, "auth", "status");
27
+ status.authenticated = true;
28
+ }
29
+ catch {
30
+ return status;
31
+ }
32
+ // 3. Extract repo owner/name from remote
33
+ try {
34
+ const { stdout } = await git(cwd, "remote", "get-url", "origin");
35
+ const parsed = parseRepoUrl(stdout.trim());
36
+ if (parsed) {
37
+ status.hasRemote = true;
38
+ status.repoOwner = parsed.owner;
39
+ status.repoName = parsed.name;
40
+ }
41
+ }
42
+ catch {
43
+ // No remote configured — hasRemote stays false
44
+ }
45
+ return status;
46
+ }
47
+ /**
48
+ * Parse a git remote URL to extract owner and repo name.
49
+ * Handles HTTPS, SSH, and GitHub CLI formats.
50
+ * Supports both github.com and GitHub Enterprise Server URLs (e.g., github.mycompany.com).
51
+ *
52
+ * The regex requires "github" to appear at a hostname boundary (after `//` or `@`)
53
+ * to prevent false positives like "notgithub.com" or "fakegithub.evil.com".
54
+ */
55
+ export function parseRepoUrl(url) {
56
+ // HTTPS: https://github.com/owner/repo.git OR https://github.mycompany.com/owner/repo.git
57
+ // The `//` anchor ensures "github" is at the start of the hostname, not mid-word.
58
+ const httpsMatch = url.match(/\/\/github[^/]*\/([^/]+)\/([^/.]+?)(?:\.git)?$/);
59
+ if (httpsMatch) {
60
+ return { owner: httpsMatch[1], name: httpsMatch[2] };
61
+ }
62
+ // SSH: git@github.com:owner/repo.git OR git@github.mycompany.com:owner/repo.git
63
+ // The `git@` prefix already anchors to the hostname start.
64
+ const sshMatch = url.match(/git@github[^:]*:([^/]+)\/([^/.]+?)(?:\.git)?$/);
65
+ if (sshMatch) {
66
+ return { owner: sshMatch[1], name: sshMatch[2] };
67
+ }
68
+ return null;
69
+ }
70
+ // ─── Issue Formatting ────────────────────────────────────────────────────────
71
+ /**
72
+ * Truncate a string to the given length, appending "..." if truncated.
73
+ */
74
+ export function truncate(str, maxLen) {
75
+ if (!str)
76
+ return "";
77
+ if (str.length <= maxLen)
78
+ return str;
79
+ return str.substring(0, maxLen).trimEnd() + "...";
80
+ }
81
+ /**
82
+ * Format a single GitHub issue into a compact list entry.
83
+ * Used when presenting multiple issues for selection.
84
+ */
85
+ export function formatIssueListEntry(issue) {
86
+ const labels = issue.labels.length > 0 ? ` [${issue.labels.join(", ")}]` : "";
87
+ const assignees = issue.assignees.length > 0 ? ` → ${issue.assignees.join(", ")}` : "";
88
+ const body = issue.body ? `\n ${truncate(issue.body.replace(/\n/g, " "), BODY_TRUNCATE_LENGTH)}` : "";
89
+ return `#${issue.number}: ${issue.title}${labels}${assignees}${body}`;
90
+ }
91
+ /**
92
+ * Format multiple issues into a numbered selection list.
93
+ */
94
+ export function formatIssueList(issues) {
95
+ if (issues.length === 0)
96
+ return "No issues found.";
97
+ return issues.map((issue) => formatIssueListEntry(issue)).join("\n\n");
98
+ }
99
+ /**
100
+ * Format a GitHub issue into a planning-friendly markdown block.
101
+ * Used by the architect agent to seed plan content from selected issues.
102
+ */
103
+ export function formatIssueForPlan(issue) {
104
+ const parts = [];
105
+ parts.push(`### Issue #${issue.number}: ${issue.title}`);
106
+ parts.push("");
107
+ if (issue.labels.length > 0) {
108
+ parts.push(`**Labels:** ${issue.labels.join(", ")}`);
109
+ }
110
+ if (issue.assignees.length > 0) {
111
+ parts.push(`**Assignees:** ${issue.assignees.join(", ")}`);
112
+ }
113
+ if (issue.milestone) {
114
+ parts.push(`**Milestone:** ${issue.milestone}`);
115
+ }
116
+ parts.push(`**URL:** ${issue.url}`);
117
+ parts.push("");
118
+ if (issue.body) {
119
+ parts.push("**Description:**");
120
+ parts.push("");
121
+ parts.push(truncate(issue.body, BODY_DETAIL_LENGTH));
122
+ }
123
+ return parts.join("\n");
124
+ }
125
+ // ─── Project Item Formatting ─────────────────────────────────────────────────
126
+ /**
127
+ * Format a single GitHub Project item into a compact list entry.
128
+ */
129
+ export function formatProjectItemEntry(item) {
130
+ const status = item.status ? ` (${item.status})` : "";
131
+ const type = item.type === "DRAFT_ISSUE" ? " [Draft]" : item.type === "PULL_REQUEST" ? " [PR]" : "";
132
+ const labels = item.labels.length > 0 ? ` [${item.labels.join(", ")}]` : "";
133
+ const assignees = item.assignees.length > 0 ? ` → ${item.assignees.join(", ")}` : "";
134
+ const ref = item.issueNumber ? `#${item.issueNumber}: ` : "";
135
+ return `${ref}${item.title}${type}${status}${labels}${assignees}`;
136
+ }
137
+ /**
138
+ * Format multiple project items into a list.
139
+ */
140
+ export function formatProjectItemList(items) {
141
+ if (items.length === 0)
142
+ return "No project items found.";
143
+ return items.map((item) => formatProjectItemEntry(item)).join("\n");
144
+ }
145
+ // ─── GitHub CLI Data Fetching ────────────────────────────────────────────────
146
+ /**
147
+ * Fetch GitHub projects associated with the repo owner.
148
+ */
149
+ export async function fetchProjects(cwd, owner) {
150
+ try {
151
+ const { stdout } = await gh(cwd, "project", "list", "--owner", owner, "--format", "json");
152
+ const parsed = JSON.parse(stdout);
153
+ // gh project list --format json returns { projects: [...] }
154
+ const projects = parsed.projects ?? parsed ?? [];
155
+ return projects.map((p) => ({
156
+ id: String(p.id ?? ""),
157
+ number: Number(p.number ?? 0),
158
+ title: String(p.title ?? "Untitled"),
159
+ }));
160
+ }
161
+ catch (error) {
162
+ // Surface auth errors — these are actionable for the user.
163
+ // Other errors (no projects, API format changes) are non-critical.
164
+ const msg = error?.message ?? String(error);
165
+ if (msg.includes("auth") || msg.includes("401") || msg.includes("403")) {
166
+ throw new Error(`GitHub authentication error while fetching projects: ${msg}`);
167
+ }
168
+ return [];
169
+ }
170
+ }
171
+ /**
172
+ * Fetch issues from the current repository using gh CLI.
173
+ */
174
+ export async function fetchIssues(cwd, options = {}) {
175
+ const args = [
176
+ "issue", "list",
177
+ "--json", "number,title,state,labels,assignees,milestone,body,url,createdAt,updatedAt",
178
+ "--limit", String(options.limit ?? 20),
179
+ ];
180
+ if (options.state)
181
+ args.push("--state", options.state);
182
+ if (options.labels)
183
+ args.push("--label", options.labels);
184
+ if (options.milestone)
185
+ args.push("--milestone", options.milestone);
186
+ if (options.assignee)
187
+ args.push("--assignee", options.assignee);
188
+ const { stdout } = await gh(cwd, ...args);
189
+ const raw = JSON.parse(stdout);
190
+ return raw.map((item) => ({
191
+ number: item.number,
192
+ title: item.title ?? "",
193
+ state: item.state ?? "open",
194
+ labels: (item.labels ?? []).map((l) => (typeof l === "string" ? l : l.name ?? "")),
195
+ assignees: (item.assignees ?? []).map((a) => (typeof a === "string" ? a : a.login ?? "")),
196
+ milestone: item.milestone?.title ?? undefined,
197
+ body: item.body ?? "",
198
+ url: item.url ?? "",
199
+ createdAt: item.createdAt ?? "",
200
+ updatedAt: item.updatedAt ?? "",
201
+ }));
202
+ }
203
+ /**
204
+ * Fetch project items from a specific GitHub Project.
205
+ */
206
+ export async function fetchProjectItems(cwd, owner, projectNumber, options = {}) {
207
+ const { stdout } = await gh(cwd, "project", "item-list", String(projectNumber), "--owner", owner, "--format", "json", "--limit", String(options.limit ?? 30));
208
+ const parsed = JSON.parse(stdout);
209
+ // gh project item-list --format json returns { items: [...] }
210
+ const raw = parsed.items ?? parsed ?? [];
211
+ const items = raw.map((item) => ({
212
+ id: String(item.id ?? ""),
213
+ title: item.title ?? "",
214
+ type: normalizeItemType(item.type),
215
+ status: item.status ?? undefined,
216
+ assignees: Array.isArray(item.assignees)
217
+ ? item.assignees.map((a) => (typeof a === "string" ? a : a.login ?? ""))
218
+ : [],
219
+ labels: Array.isArray(item.labels)
220
+ ? item.labels.map((l) => (typeof l === "string" ? l : l.name ?? ""))
221
+ : [],
222
+ issueNumber: item.content?.number ?? undefined,
223
+ url: item.content?.url ?? undefined,
224
+ body: item.content?.body ?? undefined,
225
+ }));
226
+ // Apply status filter client-side if provided
227
+ if (options.status) {
228
+ const filterStatus = options.status.toLowerCase();
229
+ return items.filter((item) => item.status?.toLowerCase().includes(filterStatus));
230
+ }
231
+ return items;
232
+ }
233
+ /**
234
+ * Normalize the item type string from GitHub's API into our union type.
235
+ */
236
+ function normalizeItemType(type) {
237
+ const t = String(type ?? "").toUpperCase();
238
+ if (t.includes("PULL") || t === "PULL_REQUEST")
239
+ return "PULL_REQUEST";
240
+ if (t.includes("DRAFT") || t === "DRAFT_ISSUE")
241
+ return "DRAFT_ISSUE";
242
+ return "ISSUE";
243
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * IDE Detection System
3
+ *
4
+ * Detects the current Integrated Development Environment or editor context.
5
+ * This is used to offer appropriate worktree launch options that match
6
+ * the user's current workflow.
7
+ *
8
+ * Detection is based on environment variables set by various IDEs when
9
+ * running terminal sessions within them.
10
+ */
11
+ export type IDEType = "vscode" | "cursor" | "windsurf" | "jetbrains" | "zed" | "terminal" | "unknown";
12
+ export interface IDEDetection {
13
+ type: IDEType;
14
+ name: string;
15
+ version?: string;
16
+ hasIntegratedTerminal: boolean;
17
+ canOpenInTerminal: boolean;
18
+ canOpenInWindow: boolean;
19
+ cliAvailable?: boolean;
20
+ cliBinary?: string;
21
+ cliInstallHint?: string;
22
+ detectionSource: string;
23
+ }
24
+ export interface EnvironmentRecommendation {
25
+ option: string;
26
+ priority: "high" | "medium" | "low";
27
+ reason: string;
28
+ mode?: "ide" | "terminal" | "pty" | "background" | "stay";
29
+ }
30
+ /**
31
+ * Detect the current IDE/editor environment.
32
+ * Checks environment variables, process hierarchy, and context clues.
33
+ */
34
+ export declare function detectIDE(): IDEDetection;
35
+ /**
36
+ * Get the command to open a worktree in the IDE's integrated terminal.
37
+ * Returns null if the IDE doesn't support CLI-based opening.
38
+ *
39
+ * Note: This function is currently unused but kept for future use.
40
+ * All inputs are escaped to prevent command injection.
41
+ */
42
+ export declare function getIDEOpenCommand(ide: IDEDetection, worktreePath: string): string | null;
43
+ /**
44
+ * Get the name of the CLI binary for the detected IDE.
45
+ * Returns null if no CLI is available or known.
46
+ */
47
+ export declare function getIDECliBinary(ide: IDEDetection): string | null;
48
+ /**
49
+ * Get a human-readable hint for installing an IDE's CLI binary.
50
+ * Each IDE has a different installation method.
51
+ */
52
+ export declare function getInstallHint(type: IDEType, binary: string): string;
53
+ /**
54
+ * Async version of detectIDE() that also checks whether the IDE's CLI binary
55
+ * is actually available in PATH. Use this in tools where you need to verify
56
+ * runtime availability before offering IDE launch options.
57
+ *
58
+ * The sync detectIDE() is preserved for non-async contexts.
59
+ */
60
+ export declare function detectIDEWithCLICheck(): Promise<IDEDetection>;
61
+ /**
62
+ * Check if we're already inside an IDE terminal.
63
+ * This helps determine if we should offer "stay here" as primary option.
64
+ */
65
+ export declare function isInIDETerminal(): boolean;
66
+ /**
67
+ * Generate contextual recommendations based on detected environment.
68
+ * Used by agents to offer appropriate launch options to users.
69
+ */
70
+ export declare function generateEnvironmentRecommendations(ide: IDEDetection): EnvironmentRecommendation[];
71
+ /**
72
+ * Format environment detection as a human-readable report.
73
+ * Used by the detect_environment tool.
74
+ */
75
+ export declare function formatEnvironmentReport(ide: IDEDetection, terminalName: string): string;
76
+ //# sourceMappingURL=ide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ide.d.ts","sourceRoot":"","sources":["../../src/utils/ide.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,MAAM,OAAO,GACf,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,WAAW,GACX,KAAK,GACL,UAAU,GACV,SAAS,CAAC;AAEd,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,CAAC;CAC3D;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,YAAY,CAoGxC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA6BxF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAahE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAapE;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,YAAY,CAAC,CAgBnE;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAGzC;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,YAAY,GAAG,yBAAyB,EAAE,CAkDjG;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAgDvF"}