mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
Checkpoint: File edits
Automatic checkpoint created by Claude Code - Branch: v3 - Timestamp: 2026-01-07T21:00:34Z - Changes: 6 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
227e53282e
commit
203d62bb2b
6 files changed
+254
-5
No files matched your search
@@ -8,4 +8,4 @@ capabilities:
|
||||
optimizations:
|
||||
- context-caching
|
||||
- memory-persistence
|
||||
createdAt: "2026-01-07T16:48:49.140Z"
|
||||
createdAt: "2026-01-07T20:59:19.495Z"
|
||||
@@ -8,4 +8,4 @@ capabilities:
|
||||
optimizations:
|
||||
- flash-attention
|
||||
- token-reduction
|
||||
createdAt: "2026-01-07T16:48:49.140Z"
|
||||
createdAt: "2026-01-07T20:59:19.495Z"
|
||||
@@ -7,4 +7,4 @@ capabilities:
|
||||
- best-practices
|
||||
optimizations:
|
||||
- incremental-analysis
|
||||
createdAt: "2026-01-07T16:48:49.140Z"
|
||||
createdAt: "2026-01-07T20:59:19.495Z"
|
||||
@@ -7,4 +7,4 @@ capabilities:
|
||||
- security-review
|
||||
optimizations:
|
||||
- pattern-matching
|
||||
createdAt: "2026-01-07T16:48:49.140Z"
|
||||
createdAt: "2026-01-07T20:59:19.495Z"
|
||||
@@ -7,4 +7,4 @@ capabilities:
|
||||
- coverage
|
||||
optimizations:
|
||||
- parallel-execution
|
||||
createdAt: "2026-01-07T16:48:49.140Z"
|
||||
createdAt: "2026-01-07T20:59:19.495Z"
|
||||
@@ -741,6 +741,248 @@ export class ClaimService extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// GitHub Sync Implementation
|
||||
// ============================================================================
|
||||
|
||||
const DEFAULT_GITHUB_CONFIG: GitHubSyncConfig = {
|
||||
enabled: false,
|
||||
syncLabels: true,
|
||||
claimLabel: 'claimed',
|
||||
autoAssign: true,
|
||||
commentOnClaim: true,
|
||||
commentOnRelease: true,
|
||||
};
|
||||
|
||||
export class GitHubSync {
|
||||
private config: GitHubSyncConfig;
|
||||
private claimService: ClaimService;
|
||||
|
||||
constructor(claimService: ClaimService, config?: Partial<GitHubSyncConfig>) {
|
||||
this.claimService = claimService;
|
||||
this.config = { ...DEFAULT_GITHUB_CONFIG, ...config };
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if GitHub CLI is available
|
||||
*/
|
||||
isGhAvailable(): boolean {
|
||||
try {
|
||||
execSync('gh --version', { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current repository from git remote
|
||||
*/
|
||||
getRepo(): string | null {
|
||||
if (this.config.repo) return this.config.repo;
|
||||
try {
|
||||
const remote = execSync('git remote get-url origin', { encoding: 'utf-8' }).trim();
|
||||
const match = remote.match(/github\.com[/:]([\w-]+\/[\w-]+)/);
|
||||
return match ? match[1].replace('.git', '') : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync issues from GitHub
|
||||
*/
|
||||
async syncIssues(state: 'open' | 'closed' | 'all' = 'open'): Promise<GitHubSyncResult> {
|
||||
const errors: string[] = [];
|
||||
const issues: GitHubIssue[] = [];
|
||||
|
||||
if (!this.isGhAvailable()) {
|
||||
return { success: false, synced: 0, errors: ['GitHub CLI (gh) not installed'] };
|
||||
}
|
||||
|
||||
const repo = this.getRepo();
|
||||
if (!repo) {
|
||||
return { success: false, synced: 0, errors: ['Could not determine GitHub repository'] };
|
||||
}
|
||||
|
||||
try {
|
||||
const issuesJson = execSync(
|
||||
`gh issue list --repo ${repo} --state ${state} --json number,title,body,state,labels,assignees,url,createdAt,updatedAt --limit 100`,
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
const rawIssues = JSON.parse(issuesJson);
|
||||
|
||||
for (const raw of rawIssues) {
|
||||
issues.push({
|
||||
number: raw.number,
|
||||
title: raw.title,
|
||||
body: raw.body || '',
|
||||
state: raw.state === 'OPEN' ? 'open' : 'closed',
|
||||
labels: raw.labels?.map((l: { name: string }) => l.name) || [],
|
||||
assignees: raw.assignees?.map((a: { login: string }) => a.login) || [],
|
||||
url: raw.url,
|
||||
createdAt: new Date(raw.createdAt),
|
||||
updatedAt: new Date(raw.updatedAt),
|
||||
});
|
||||
}
|
||||
|
||||
return { success: true, synced: issues.length, errors, issues };
|
||||
} catch (error) {
|
||||
errors.push(`Failed to fetch issues: ${(error as Error).message}`);
|
||||
return { success: false, synced: 0, errors };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync a local claim to GitHub (add label/assignee/comment)
|
||||
*/
|
||||
async claimOnGitHub(issueNumber: number, claimant: Claimant): Promise<GitHubSyncResult> {
|
||||
const errors: string[] = [];
|
||||
|
||||
if (!this.config.enabled) {
|
||||
return { success: true, synced: 0, errors: ['GitHub sync not enabled'] };
|
||||
}
|
||||
|
||||
if (!this.isGhAvailable()) {
|
||||
return { success: false, synced: 0, errors: ['GitHub CLI (gh) not installed'] };
|
||||
}
|
||||
|
||||
const repo = this.getRepo();
|
||||
if (!repo) {
|
||||
return { success: false, synced: 0, errors: ['Could not determine repository'] };
|
||||
}
|
||||
|
||||
try {
|
||||
// Add claim label
|
||||
if (this.config.syncLabels) {
|
||||
try {
|
||||
execSync(`gh issue edit ${issueNumber} --repo ${repo} --add-label "${this.config.claimLabel}"`, { stdio: 'ignore' });
|
||||
} catch {
|
||||
errors.push('Failed to add claim label (label may not exist)');
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-assign if human claimant
|
||||
if (this.config.autoAssign && claimant.type === 'human') {
|
||||
try {
|
||||
execSync(`gh issue edit ${issueNumber} --repo ${repo} --add-assignee "${claimant.name}"`, { stdio: 'ignore' });
|
||||
} catch {
|
||||
errors.push('Failed to assign issue');
|
||||
}
|
||||
}
|
||||
|
||||
// Add comment
|
||||
if (this.config.commentOnClaim) {
|
||||
const claimantStr = claimant.type === 'human' ? `@${claimant.name}` : `Agent: ${claimant.agentType}`;
|
||||
const comment = `🤖 **Issue claimed** by ${claimantStr}\n\n_Coordinated by Claude Flow V3_`;
|
||||
try {
|
||||
execSync(`gh issue comment ${issueNumber} --repo ${repo} --body "${comment.replace(/"/g, '\\"')}"`, { stdio: 'ignore' });
|
||||
} catch {
|
||||
errors.push('Failed to add comment');
|
||||
}
|
||||
}
|
||||
|
||||
return { success: errors.length === 0, synced: 1, errors };
|
||||
} catch (error) {
|
||||
errors.push(`GitHub sync failed: ${(error as Error).message}`);
|
||||
return { success: false, synced: 0, errors };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release claim on GitHub (remove label/assignee/comment)
|
||||
*/
|
||||
async releaseOnGitHub(issueNumber: number, claimant: Claimant): Promise<GitHubSyncResult> {
|
||||
const errors: string[] = [];
|
||||
|
||||
if (!this.config.enabled) {
|
||||
return { success: true, synced: 0, errors: ['GitHub sync not enabled'] };
|
||||
}
|
||||
|
||||
if (!this.isGhAvailable()) {
|
||||
return { success: false, synced: 0, errors: ['GitHub CLI (gh) not installed'] };
|
||||
}
|
||||
|
||||
const repo = this.getRepo();
|
||||
if (!repo) {
|
||||
return { success: false, synced: 0, errors: ['Could not determine repository'] };
|
||||
}
|
||||
|
||||
try {
|
||||
// Remove claim label
|
||||
if (this.config.syncLabels) {
|
||||
try {
|
||||
execSync(`gh issue edit ${issueNumber} --repo ${repo} --remove-label "${this.config.claimLabel}"`, { stdio: 'ignore' });
|
||||
} catch {
|
||||
// Label might not exist
|
||||
}
|
||||
}
|
||||
|
||||
// Remove assignee if human claimant
|
||||
if (this.config.autoAssign && claimant.type === 'human') {
|
||||
try {
|
||||
execSync(`gh issue edit ${issueNumber} --repo ${repo} --remove-assignee "${claimant.name}"`, { stdio: 'ignore' });
|
||||
} catch {
|
||||
errors.push('Failed to remove assignee');
|
||||
}
|
||||
}
|
||||
|
||||
// Add release comment
|
||||
if (this.config.commentOnRelease) {
|
||||
const claimantStr = claimant.type === 'human' ? `@${claimant.name}` : `Agent: ${claimant.agentType}`;
|
||||
const comment = `🔓 **Issue released** by ${claimantStr}\n\n_This issue is now available for others to claim._`;
|
||||
try {
|
||||
execSync(`gh issue comment ${issueNumber} --repo ${repo} --body "${comment.replace(/"/g, '\\"')}"`, { stdio: 'ignore' });
|
||||
} catch {
|
||||
errors.push('Failed to add release comment');
|
||||
}
|
||||
}
|
||||
|
||||
return { success: errors.length === 0, synced: 1, errors };
|
||||
} catch (error) {
|
||||
errors.push(`GitHub release sync failed: ${(error as Error).message}`);
|
||||
return { success: false, synced: 0, errors };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk sync all local claims to GitHub
|
||||
*/
|
||||
async syncAllClaimsToGitHub(): Promise<GitHubSyncResult> {
|
||||
const errors: string[] = [];
|
||||
let synced = 0;
|
||||
|
||||
const claims = await this.claimService.getAllClaims();
|
||||
for (const claim of claims) {
|
||||
// Extract issue number from issueId (assumes format like "123" or "issue-123")
|
||||
const issueMatch = claim.issueId.match(/(\d+)/);
|
||||
if (issueMatch) {
|
||||
const result = await this.claimOnGitHub(parseInt(issueMatch[1], 10), claim.claimant);
|
||||
if (result.success) synced++;
|
||||
else errors.push(...result.errors);
|
||||
}
|
||||
}
|
||||
|
||||
return { success: errors.length === 0, synced, errors };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GitHub issues that are claimed locally
|
||||
*/
|
||||
async getClaimedGitHubIssues(): Promise<GitHubIssue[]> {
|
||||
const syncResult = await this.syncIssues('open');
|
||||
if (!syncResult.success || !syncResult.issues) return [];
|
||||
|
||||
const localClaims = await this.claimService.getAllClaims();
|
||||
const claimedIds = new Set(localClaims.map(c => {
|
||||
const match = c.issueId.match(/(\d+)/);
|
||||
return match ? parseInt(match[1], 10) : null;
|
||||
}).filter(Boolean));
|
||||
|
||||
return syncResult.issues.filter(issue => claimedIds.has(issue.number));
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Factory
|
||||
// ============================================================================
|
||||
@@ -752,4 +994,11 @@ export function createClaimService(
|
||||
return new ClaimService(projectRoot, config);
|
||||
}
|
||||
|
||||
export function createGitHubSync(
|
||||
claimService: ClaimService,
|
||||
config?: Partial<GitHubSyncConfig>
|
||||
): GitHubSync {
|
||||
return new GitHubSync(claimService, config);
|
||||
}
|
||||
|
||||
export default ClaimService;
|
||||
Reference in new issue
Block a user