@fractary/faber-cli 1.1.0 → 1.3.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/dist/commands/plan/index.d.ts +11 -0
- package/dist/commands/plan/index.d.ts.map +1 -0
- package/dist/commands/plan/index.js +383 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/lib/anthropic-client.d.ts +69 -0
- package/dist/lib/anthropic-client.d.ts.map +1 -0
- package/dist/lib/anthropic-client.js +225 -0
- package/dist/lib/config.d.ts +30 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +127 -0
- package/dist/lib/repo-client.d.ts +78 -0
- package/dist/lib/repo-client.d.ts.map +1 -0
- package/dist/lib/repo-client.js +151 -0
- package/dist/lib/sdk-config-adapter.d.ts +24 -0
- package/dist/lib/sdk-config-adapter.d.ts.map +1 -0
- package/dist/lib/sdk-config-adapter.js +50 -0
- package/dist/lib/sdk-type-adapter.d.ts +43 -0
- package/dist/lib/sdk-type-adapter.d.ts.map +1 -0
- package/dist/lib/sdk-type-adapter.js +42 -0
- package/dist/types/config.d.ts +34 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +6 -0
- package/dist/utils/prompt.d.ts +8 -0
- package/dist/utils/prompt.d.ts.map +1 -0
- package/dist/utils/prompt.js +19 -0
- package/dist/utils/validation.d.ts +71 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +157 -0
- package/package.json +2 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic API Client
|
|
3
|
+
*
|
|
4
|
+
* Generates workflow plans via Claude API
|
|
5
|
+
*/
|
|
6
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
7
|
+
import Ajv from 'ajv';
|
|
8
|
+
import fs from 'fs/promises';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import { Git } from '@fractary/faber';
|
|
12
|
+
import { validateJsonSize } from '../utils/validation.js';
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = path.dirname(__filename);
|
|
15
|
+
/**
|
|
16
|
+
* Anthropic API Client
|
|
17
|
+
*/
|
|
18
|
+
export class AnthropicClient {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.git = new Git();
|
|
22
|
+
this.ajv = new Ajv({ strict: false }); // Allow additional properties
|
|
23
|
+
const apiKey = config.anthropic?.api_key;
|
|
24
|
+
if (!apiKey) {
|
|
25
|
+
throw new Error('Anthropic API key not found. Set ANTHROPIC_API_KEY environment variable.');
|
|
26
|
+
}
|
|
27
|
+
this.client = new Anthropic({
|
|
28
|
+
apiKey,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Load plan JSON schema for validation
|
|
33
|
+
*/
|
|
34
|
+
async loadPlanSchema() {
|
|
35
|
+
if (this.planSchema) {
|
|
36
|
+
return; // Already loaded
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
// Schema path relative to this file
|
|
40
|
+
const schemaPath = path.resolve(__dirname, '../../../plugins/faber/config/schemas/plan.schema.json');
|
|
41
|
+
const schemaContent = await fs.readFile(schemaPath, 'utf8');
|
|
42
|
+
this.planSchema = JSON.parse(schemaContent);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
// Schema not found or invalid - log warning but don't fail
|
|
46
|
+
console.warn('Warning: Could not load plan schema for validation:', error instanceof Error ? error.message : 'Unknown error');
|
|
47
|
+
this.planSchema = null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate plan JSON against schema
|
|
52
|
+
*/
|
|
53
|
+
validatePlan(plan) {
|
|
54
|
+
if (!this.planSchema) {
|
|
55
|
+
// Schema not loaded - skip validation
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const validate = this.ajv.compile(this.planSchema);
|
|
59
|
+
const valid = validate(plan);
|
|
60
|
+
if (!valid) {
|
|
61
|
+
const errors = validate.errors?.map(e => `${e.instancePath} ${e.message}`).join(', ') || 'Unknown validation errors';
|
|
62
|
+
throw new Error(`Plan JSON validation failed: ${errors}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Generate workflow plan via Claude API
|
|
67
|
+
*/
|
|
68
|
+
async generatePlan(input) {
|
|
69
|
+
// Load plan schema for validation
|
|
70
|
+
await this.loadPlanSchema();
|
|
71
|
+
// Load workflow configuration
|
|
72
|
+
const workflowConfig = await this.loadWorkflowConfig(input.workflow);
|
|
73
|
+
// Generate plan ID
|
|
74
|
+
const timestamp = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d+Z/, '').replace('T', '-');
|
|
75
|
+
const planId = `fractary-faber-${input.issueNumber}-${timestamp}`;
|
|
76
|
+
// Construct prompt for Claude
|
|
77
|
+
const prompt = this.constructPlanningPrompt(input, workflowConfig);
|
|
78
|
+
// Call Claude API
|
|
79
|
+
const response = await this.client.messages.create({
|
|
80
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
81
|
+
max_tokens: 8192,
|
|
82
|
+
messages: [
|
|
83
|
+
{
|
|
84
|
+
role: 'user',
|
|
85
|
+
content: prompt,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
// Extract plan JSON from response
|
|
90
|
+
const content = response.content[0];
|
|
91
|
+
if (content.type !== 'text') {
|
|
92
|
+
throw new Error('Unexpected response type from Claude API');
|
|
93
|
+
}
|
|
94
|
+
// Validate response size (prevent DoS)
|
|
95
|
+
validateJsonSize(content.text, 1024 * 1024); // 1MB limit
|
|
96
|
+
const planJson = this.extractJsonFromResponse(content.text);
|
|
97
|
+
// Add metadata
|
|
98
|
+
const { organization, project } = await this.extractRepoInfo();
|
|
99
|
+
const plan = {
|
|
100
|
+
...planJson,
|
|
101
|
+
plan_id: planId,
|
|
102
|
+
created_by: 'cli',
|
|
103
|
+
cli_version: '1.0.0',
|
|
104
|
+
created_at: new Date().toISOString(),
|
|
105
|
+
issue: {
|
|
106
|
+
source: 'github',
|
|
107
|
+
id: input.issueNumber.toString(),
|
|
108
|
+
url: `https://github.com/${organization}/${project}/issues/${input.issueNumber}`,
|
|
109
|
+
},
|
|
110
|
+
branch: `feature/${input.issueNumber}`,
|
|
111
|
+
worktree: `~/.claude-worktrees/${organization}-${project}-${input.issueNumber}`,
|
|
112
|
+
workflow: input.workflow,
|
|
113
|
+
};
|
|
114
|
+
// Validate plan against schema
|
|
115
|
+
this.validatePlan(plan);
|
|
116
|
+
return plan;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Load workflow configuration
|
|
120
|
+
*/
|
|
121
|
+
async loadWorkflowConfig(workflow) {
|
|
122
|
+
const workflowPath = path.join(this.config.workflow?.config_path || './plugins/faber/config/workflows', `${workflow}.json`);
|
|
123
|
+
try {
|
|
124
|
+
const content = await fs.readFile(workflowPath, 'utf-8');
|
|
125
|
+
return JSON.parse(content);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new Error(`Failed to load workflow config: ${workflow} (${workflowPath})`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Construct planning prompt for Claude
|
|
133
|
+
*/
|
|
134
|
+
constructPlanningPrompt(input, workflowConfig) {
|
|
135
|
+
return `You are a workflow planning assistant for the FABER system. Your task is to generate a structured workflow plan based on the provided issue and workflow configuration.
|
|
136
|
+
|
|
137
|
+
**Issue Information:**
|
|
138
|
+
- Number: #${input.issueNumber}
|
|
139
|
+
- Title: ${input.issueTitle}
|
|
140
|
+
- Description: ${input.issueDescription}
|
|
141
|
+
|
|
142
|
+
**Workflow Type:** ${input.workflow}
|
|
143
|
+
|
|
144
|
+
**Workflow Configuration:**
|
|
145
|
+
${JSON.stringify(workflowConfig, null, 2)}
|
|
146
|
+
|
|
147
|
+
**Your Task:**
|
|
148
|
+
Generate a complete workflow plan that includes:
|
|
149
|
+
1. All phases from the workflow configuration
|
|
150
|
+
2. Specific steps for each phase based on the issue requirements
|
|
151
|
+
3. Success criteria for each phase
|
|
152
|
+
4. Estimated complexity
|
|
153
|
+
|
|
154
|
+
**Output Format:**
|
|
155
|
+
Return ONLY a valid JSON object with the following structure:
|
|
156
|
+
|
|
157
|
+
\`\`\`json
|
|
158
|
+
{
|
|
159
|
+
"phases": [
|
|
160
|
+
{
|
|
161
|
+
"phase": "phase_name",
|
|
162
|
+
"description": "What this phase accomplishes",
|
|
163
|
+
"steps": [
|
|
164
|
+
{
|
|
165
|
+
"action": "specific action to take",
|
|
166
|
+
"details": "additional context or requirements"
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
"success_criteria": [
|
|
170
|
+
"criterion 1",
|
|
171
|
+
"criterion 2"
|
|
172
|
+
],
|
|
173
|
+
"complexity": "low|medium|high"
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"overall_complexity": "low|medium|high",
|
|
177
|
+
"estimated_phases": 4,
|
|
178
|
+
"special_considerations": [
|
|
179
|
+
"Any special notes or warnings"
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
\`\`\`
|
|
183
|
+
|
|
184
|
+
Generate the plan now:`;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Extract JSON from Claude response
|
|
188
|
+
*/
|
|
189
|
+
extractJsonFromResponse(text) {
|
|
190
|
+
// Try to find JSON in code blocks
|
|
191
|
+
const jsonBlockMatch = text.match(/```json\s*\n([\s\S]*?)\n```/);
|
|
192
|
+
if (jsonBlockMatch) {
|
|
193
|
+
return JSON.parse(jsonBlockMatch[1]);
|
|
194
|
+
}
|
|
195
|
+
// Try to find JSON in the text
|
|
196
|
+
const jsonMatch = text.match(/\{[\s\S]*\}/);
|
|
197
|
+
if (jsonMatch) {
|
|
198
|
+
return JSON.parse(jsonMatch[0]);
|
|
199
|
+
}
|
|
200
|
+
throw new Error('Could not extract JSON from Claude response');
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Extract repository organization and project name using SDK Git class
|
|
204
|
+
*/
|
|
205
|
+
async extractRepoInfo() {
|
|
206
|
+
try {
|
|
207
|
+
const remoteUrl = this.git.exec('remote get-url origin');
|
|
208
|
+
// Parse git@github.com:organization/project.git or https://github.com/organization/project.git
|
|
209
|
+
const match = remoteUrl.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
210
|
+
if (match) {
|
|
211
|
+
return {
|
|
212
|
+
organization: match[1],
|
|
213
|
+
project: match[2],
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
// Fall back to config or defaults
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
organization: this.config.github?.organization || 'unknown',
|
|
222
|
+
project: this.config.github?.project || 'unknown',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Manager
|
|
3
|
+
*
|
|
4
|
+
* Loads FABER CLI configuration and respects Claude Code settings
|
|
5
|
+
*/
|
|
6
|
+
import type { FaberConfig } from '../types/config.js';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration Manager
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConfigManager {
|
|
11
|
+
private config;
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Load configuration
|
|
15
|
+
*/
|
|
16
|
+
static load(): Promise<FaberConfig>;
|
|
17
|
+
/**
|
|
18
|
+
* Read Claude Code configuration for worktree location
|
|
19
|
+
*/
|
|
20
|
+
private static readClaudeCodeWorktreeLocation;
|
|
21
|
+
/**
|
|
22
|
+
* Get Claude Code configuration paths by platform
|
|
23
|
+
*/
|
|
24
|
+
private static getClaudeConfigPaths;
|
|
25
|
+
/**
|
|
26
|
+
* Get configuration value
|
|
27
|
+
*/
|
|
28
|
+
get(key: keyof FaberConfig): any;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,oBAAoB,CAAC;AAEpE;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAc;IAE5B,OAAO;IAIP;;OAEG;WACU,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC;IAgEzC;;OAEG;mBACkB,8BAA8B;IAoBnD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAyBnC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,WAAW,GAAG,GAAG;CAGjC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Manager
|
|
3
|
+
*
|
|
4
|
+
* Loads FABER CLI configuration and respects Claude Code settings
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs/promises';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import os from 'os';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration Manager
|
|
11
|
+
*/
|
|
12
|
+
export class ConfigManager {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Load configuration
|
|
18
|
+
*/
|
|
19
|
+
static async load() {
|
|
20
|
+
const config = {};
|
|
21
|
+
// Load from environment variables
|
|
22
|
+
config.anthropic = {
|
|
23
|
+
api_key: process.env.ANTHROPIC_API_KEY,
|
|
24
|
+
};
|
|
25
|
+
config.github = {
|
|
26
|
+
token: process.env.GITHUB_TOKEN,
|
|
27
|
+
};
|
|
28
|
+
// Load from FABER config file
|
|
29
|
+
try {
|
|
30
|
+
const faberConfigPath = path.join(process.cwd(), '.fractary', 'settings.json');
|
|
31
|
+
const faberConfigContent = await fs.readFile(faberConfigPath, 'utf-8');
|
|
32
|
+
const faberConfig = JSON.parse(faberConfigContent);
|
|
33
|
+
// Merge with config
|
|
34
|
+
if (faberConfig.anthropic) {
|
|
35
|
+
config.anthropic = { ...config.anthropic, ...faberConfig.anthropic };
|
|
36
|
+
}
|
|
37
|
+
if (faberConfig.github) {
|
|
38
|
+
config.github = { ...config.github, ...faberConfig.github };
|
|
39
|
+
}
|
|
40
|
+
if (faberConfig.worktree) {
|
|
41
|
+
config.worktree = { ...config.worktree, ...faberConfig.worktree };
|
|
42
|
+
}
|
|
43
|
+
if (faberConfig.workflow) {
|
|
44
|
+
config.workflow = { ...config.workflow, ...faberConfig.workflow };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
// FABER config not found, use defaults
|
|
49
|
+
}
|
|
50
|
+
// Read Claude Code configuration for worktree location
|
|
51
|
+
if (!config.worktree?.location || config.worktree?.inherit_from_claude !== false) {
|
|
52
|
+
const claudeWorktreeLocation = await ConfigManager.readClaudeCodeWorktreeLocation();
|
|
53
|
+
if (claudeWorktreeLocation) {
|
|
54
|
+
if (!config.worktree) {
|
|
55
|
+
config.worktree = {};
|
|
56
|
+
}
|
|
57
|
+
config.worktree.location = claudeWorktreeLocation;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Set defaults
|
|
61
|
+
if (!config.worktree?.location) {
|
|
62
|
+
config.worktree = {
|
|
63
|
+
...config.worktree,
|
|
64
|
+
location: path.join(os.homedir(), '.claude-worktrees'),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (!config.workflow?.config_path) {
|
|
68
|
+
config.workflow = {
|
|
69
|
+
...config.workflow,
|
|
70
|
+
config_path: path.join(process.cwd(), 'plugins', 'faber', 'config', 'workflows'),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return config;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Read Claude Code configuration for worktree location
|
|
77
|
+
*/
|
|
78
|
+
static async readClaudeCodeWorktreeLocation() {
|
|
79
|
+
const configPaths = ConfigManager.getClaudeConfigPaths();
|
|
80
|
+
for (const configPath of configPaths) {
|
|
81
|
+
try {
|
|
82
|
+
const content = await fs.readFile(configPath, 'utf-8');
|
|
83
|
+
const config = JSON.parse(content);
|
|
84
|
+
if (config.worktree?.directory) {
|
|
85
|
+
return config.worktree.directory;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
// Config file not found or not readable, try next
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get Claude Code configuration paths by platform
|
|
97
|
+
*/
|
|
98
|
+
static getClaudeConfigPaths() {
|
|
99
|
+
const homeDir = os.homedir();
|
|
100
|
+
const platform = os.platform();
|
|
101
|
+
switch (platform) {
|
|
102
|
+
case 'linux':
|
|
103
|
+
return [
|
|
104
|
+
path.join(homeDir, '.config', 'claude', 'config.json'),
|
|
105
|
+
path.join(homeDir, '.claude', 'config.json'),
|
|
106
|
+
];
|
|
107
|
+
case 'darwin': // macOS
|
|
108
|
+
return [
|
|
109
|
+
path.join(homeDir, 'Library', 'Application Support', 'Claude', 'config.json'),
|
|
110
|
+
path.join(homeDir, '.config', 'claude', 'config.json'),
|
|
111
|
+
];
|
|
112
|
+
case 'win32': // Windows
|
|
113
|
+
return [
|
|
114
|
+
path.join(process.env.APPDATA || path.join(homeDir, 'AppData', 'Roaming'), 'Claude', 'config.json'),
|
|
115
|
+
path.join(homeDir, '.claude', 'config.json'),
|
|
116
|
+
];
|
|
117
|
+
default:
|
|
118
|
+
return [path.join(homeDir, '.claude', 'config.json')];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get configuration value
|
|
123
|
+
*/
|
|
124
|
+
get(key) {
|
|
125
|
+
return this.config[key];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repo Client
|
|
3
|
+
*
|
|
4
|
+
* Integrates with @fractary/core SDK for repository and work tracking operations
|
|
5
|
+
*/
|
|
6
|
+
interface Issue {
|
|
7
|
+
id: string;
|
|
8
|
+
number: number;
|
|
9
|
+
title: string;
|
|
10
|
+
description: string;
|
|
11
|
+
labels: string[];
|
|
12
|
+
url: string;
|
|
13
|
+
state: string;
|
|
14
|
+
}
|
|
15
|
+
interface WorktreeResult {
|
|
16
|
+
path: string;
|
|
17
|
+
absolute_path: string;
|
|
18
|
+
branch: string;
|
|
19
|
+
created_at: string;
|
|
20
|
+
organization: string;
|
|
21
|
+
project: string;
|
|
22
|
+
work_id: string;
|
|
23
|
+
}
|
|
24
|
+
interface IssueUpdateOptions {
|
|
25
|
+
id: string;
|
|
26
|
+
comment?: string;
|
|
27
|
+
addLabel?: string;
|
|
28
|
+
removeLabel?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Repo Client - integrates with @fractary/core SDK
|
|
32
|
+
*
|
|
33
|
+
* Provides repository and work tracking operations using WorkManager and RepoManager
|
|
34
|
+
* from the @fractary/core SDK. Replaces the previous CLI-based approach.
|
|
35
|
+
*/
|
|
36
|
+
export declare class RepoClient {
|
|
37
|
+
private config;
|
|
38
|
+
private workManager;
|
|
39
|
+
private repoManager;
|
|
40
|
+
private organization;
|
|
41
|
+
private project;
|
|
42
|
+
constructor(config: any);
|
|
43
|
+
/**
|
|
44
|
+
* Fetch specific issues by ID
|
|
45
|
+
*
|
|
46
|
+
* Uses WorkManager from @fractary/core SDK
|
|
47
|
+
*/
|
|
48
|
+
fetchIssues(ids: string[]): Promise<Issue[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Search issues by labels
|
|
51
|
+
*
|
|
52
|
+
* Uses WorkManager from @fractary/core SDK
|
|
53
|
+
*/
|
|
54
|
+
searchIssues(labels: string[]): Promise<Issue[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Create a git branch
|
|
57
|
+
*
|
|
58
|
+
* Uses RepoManager from @fractary/core SDK
|
|
59
|
+
*/
|
|
60
|
+
createBranch(branchName: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Create a git worktree
|
|
63
|
+
*
|
|
64
|
+
* Uses RepoManager from @fractary/core SDK
|
|
65
|
+
*/
|
|
66
|
+
createWorktree(options: {
|
|
67
|
+
workId: string;
|
|
68
|
+
path?: string;
|
|
69
|
+
}): Promise<WorktreeResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Update GitHub issue
|
|
72
|
+
*
|
|
73
|
+
* Uses WorkManager from @fractary/core SDK
|
|
74
|
+
*/
|
|
75
|
+
updateIssue(options: IssueUpdateOptions): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=repo-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-client.d.ts","sourceRoot":"","sources":["../../src/lib/repo-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,UAAU,KAAK;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,kBAAkB;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,GAAG;IA6BvB;;;;OAIG;IACG,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAclD;;;;OAIG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAetD;;;;OAIG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrD;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IA+BzF;;;;OAIG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CA0B9D"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repo Client
|
|
3
|
+
*
|
|
4
|
+
* Integrates with @fractary/core SDK for repository and work tracking operations
|
|
5
|
+
*/
|
|
6
|
+
import { WorkManager, RepoManager } from '@fractary/core';
|
|
7
|
+
import { createWorkConfig, createRepoConfig } from './sdk-config-adapter.js';
|
|
8
|
+
import { sdkIssueToCLIIssue, sdkWorktreeToCLIWorktreeResult } from './sdk-type-adapter.js';
|
|
9
|
+
import os from 'os';
|
|
10
|
+
/**
|
|
11
|
+
* Repo Client - integrates with @fractary/core SDK
|
|
12
|
+
*
|
|
13
|
+
* Provides repository and work tracking operations using WorkManager and RepoManager
|
|
14
|
+
* from the @fractary/core SDK. Replaces the previous CLI-based approach.
|
|
15
|
+
*/
|
|
16
|
+
export class RepoClient {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
// Validate GitHub token
|
|
20
|
+
const token = config.github?.token;
|
|
21
|
+
if (!token) {
|
|
22
|
+
throw new Error('GitHub token not found. Set GITHUB_TOKEN environment variable.');
|
|
23
|
+
}
|
|
24
|
+
// Extract organization and project
|
|
25
|
+
this.organization = config.github?.organization || 'unknown';
|
|
26
|
+
this.project = config.github?.project || 'unknown';
|
|
27
|
+
// Create SDK configurations
|
|
28
|
+
const workConfig = createWorkConfig(config);
|
|
29
|
+
const repoConfig = createRepoConfig(config);
|
|
30
|
+
// Initialize SDK managers
|
|
31
|
+
try {
|
|
32
|
+
this.workManager = new WorkManager(workConfig);
|
|
33
|
+
this.repoManager = new RepoManager(repoConfig);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
throw new Error(`Failed to initialize SDK managers: ${error.message}`);
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Fetch specific issues by ID
|
|
44
|
+
*
|
|
45
|
+
* Uses WorkManager from @fractary/core SDK
|
|
46
|
+
*/
|
|
47
|
+
async fetchIssues(ids) {
|
|
48
|
+
try {
|
|
49
|
+
const issues = await Promise.all(ids.map(id => this.workManager.fetchIssue(id)));
|
|
50
|
+
return issues.map(sdkIssueToCLIIssue);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof Error) {
|
|
54
|
+
throw new Error(`Failed to fetch issues: ${error.message}`);
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Search issues by labels
|
|
61
|
+
*
|
|
62
|
+
* Uses WorkManager from @fractary/core SDK
|
|
63
|
+
*/
|
|
64
|
+
async searchIssues(labels) {
|
|
65
|
+
try {
|
|
66
|
+
const issues = await this.workManager.searchIssues('', {
|
|
67
|
+
state: 'open',
|
|
68
|
+
labels: labels,
|
|
69
|
+
});
|
|
70
|
+
return issues.map(sdkIssueToCLIIssue);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof Error) {
|
|
74
|
+
throw new Error(`Failed to search issues: ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a git branch
|
|
81
|
+
*
|
|
82
|
+
* Uses RepoManager from @fractary/core SDK
|
|
83
|
+
*/
|
|
84
|
+
async createBranch(branchName) {
|
|
85
|
+
try {
|
|
86
|
+
await this.repoManager.createBranch(branchName);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (error instanceof Error) {
|
|
90
|
+
throw new Error(`Failed to create branch: ${error.message}`);
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a git worktree
|
|
97
|
+
*
|
|
98
|
+
* Uses RepoManager from @fractary/core SDK
|
|
99
|
+
*/
|
|
100
|
+
async createWorktree(options) {
|
|
101
|
+
try {
|
|
102
|
+
const branch = `feature/${options.workId}`;
|
|
103
|
+
const path = options.path ||
|
|
104
|
+
`~/.claude-worktrees/${this.organization}-${this.project}-${options.workId}`;
|
|
105
|
+
// Expand ~ to home directory
|
|
106
|
+
const expandedPath = path.startsWith('~')
|
|
107
|
+
? path.replace('~', os.homedir())
|
|
108
|
+
: path;
|
|
109
|
+
const worktree = this.repoManager.createWorktree({
|
|
110
|
+
path: expandedPath,
|
|
111
|
+
branch,
|
|
112
|
+
workId: options.workId,
|
|
113
|
+
});
|
|
114
|
+
return sdkWorktreeToCLIWorktreeResult(worktree, this.organization, this.project, options.workId);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error instanceof Error) {
|
|
118
|
+
throw new Error(`Failed to create worktree: ${error.message}`);
|
|
119
|
+
}
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Update GitHub issue
|
|
125
|
+
*
|
|
126
|
+
* Uses WorkManager from @fractary/core SDK
|
|
127
|
+
*/
|
|
128
|
+
async updateIssue(options) {
|
|
129
|
+
try {
|
|
130
|
+
const issueId = parseInt(options.id, 10);
|
|
131
|
+
// Create comment if provided
|
|
132
|
+
if (options.comment) {
|
|
133
|
+
await this.workManager.createComment(issueId, options.comment);
|
|
134
|
+
}
|
|
135
|
+
// Add label if provided
|
|
136
|
+
if (options.addLabel) {
|
|
137
|
+
await this.workManager.addLabels(issueId, [options.addLabel]);
|
|
138
|
+
}
|
|
139
|
+
// Remove label if provided
|
|
140
|
+
if (options.removeLabel) {
|
|
141
|
+
await this.workManager.removeLabels(issueId, [options.removeLabel]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (error instanceof Error) {
|
|
146
|
+
throw new Error(`Failed to update issue: ${error.message}`);
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Configuration Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts FABER CLI configuration to @fractary/core SDK configuration format
|
|
5
|
+
*/
|
|
6
|
+
import type { FaberConfig } from '../types/config.js';
|
|
7
|
+
import type { WorkConfig, RepoConfig } from '@fractary/core';
|
|
8
|
+
/**
|
|
9
|
+
* Create WorkConfig for WorkManager from FaberConfig
|
|
10
|
+
*
|
|
11
|
+
* @param faberConfig - FABER CLI configuration
|
|
12
|
+
* @returns WorkConfig for @fractary/core WorkManager
|
|
13
|
+
* @throws Error if required fields are missing
|
|
14
|
+
*/
|
|
15
|
+
export declare function createWorkConfig(faberConfig: FaberConfig): WorkConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Create RepoConfig for RepoManager from FaberConfig
|
|
18
|
+
*
|
|
19
|
+
* @param faberConfig - FABER CLI configuration
|
|
20
|
+
* @returns RepoConfig for @fractary/core RepoManager
|
|
21
|
+
* @throws Error if required fields are missing
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRepoConfig(faberConfig: FaberConfig): RepoConfig;
|
|
24
|
+
//# sourceMappingURL=sdk-config-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-config-adapter.d.ts","sourceRoot":"","sources":["../../src/lib/sdk-config-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE7D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAuBrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAiBrE"}
|