@sashabogi/foundation 0.1.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 +21 -0
- package/README.md +341 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +308 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/services/config.service.d.ts +92 -0
- package/dist/services/config.service.d.ts.map +1 -0
- package/dist/services/config.service.js +284 -0
- package/dist/services/config.service.js.map +1 -0
- package/dist/services/git.service.d.ts +175 -0
- package/dist/services/git.service.d.ts.map +1 -0
- package/dist/services/git.service.js +395 -0
- package/dist/services/git.service.js.map +1 -0
- package/dist/services/provider.service.d.ts +74 -0
- package/dist/services/provider.service.d.ts.map +1 -0
- package/dist/services/provider.service.js +182 -0
- package/dist/services/provider.service.js.map +1 -0
- package/dist/services/storage.service.d.ts +84 -0
- package/dist/services/storage.service.d.ts.map +1 -0
- package/dist/services/storage.service.js +320 -0
- package/dist/services/storage.service.js.map +1 -0
- package/dist/tools/demerzel/index.d.ts +21 -0
- package/dist/tools/demerzel/index.d.ts.map +1 -0
- package/dist/tools/demerzel/index.js +166 -0
- package/dist/tools/demerzel/index.js.map +1 -0
- package/dist/tools/gaia/index.d.ts +27 -0
- package/dist/tools/gaia/index.d.ts.map +1 -0
- package/dist/tools/gaia/index.js +466 -0
- package/dist/tools/gaia/index.js.map +1 -0
- package/dist/tools/seldon/index.d.ts +43 -0
- package/dist/tools/seldon/index.d.ts.map +1 -0
- package/dist/tools/seldon/index.js +886 -0
- package/dist/tools/seldon/index.js.map +1 -0
- package/dist/types/index.d.ts +392 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitService - Unified git operations
|
|
3
|
+
*
|
|
4
|
+
* Provides git functionality for all Foundation modules:
|
|
5
|
+
* - Worktree management (create, list, remove)
|
|
6
|
+
* - Branch operations (create, switch, merge)
|
|
7
|
+
* - Status, diff, log queries
|
|
8
|
+
* - CLAUDE.md file operations
|
|
9
|
+
*/
|
|
10
|
+
export interface GitStatus {
|
|
11
|
+
branch: string;
|
|
12
|
+
ahead: number;
|
|
13
|
+
behind: number;
|
|
14
|
+
staged: string[];
|
|
15
|
+
modified: string[];
|
|
16
|
+
untracked: string[];
|
|
17
|
+
conflicts: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface GitLogEntry {
|
|
20
|
+
hash: string;
|
|
21
|
+
shortHash: string;
|
|
22
|
+
author: string;
|
|
23
|
+
date: string;
|
|
24
|
+
message: string;
|
|
25
|
+
}
|
|
26
|
+
export interface GitWorktreeInfo {
|
|
27
|
+
path: string;
|
|
28
|
+
branch: string;
|
|
29
|
+
head: string;
|
|
30
|
+
bare: boolean;
|
|
31
|
+
detached: boolean;
|
|
32
|
+
locked: boolean;
|
|
33
|
+
prunable: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare class GitService {
|
|
36
|
+
private static instance;
|
|
37
|
+
private constructor();
|
|
38
|
+
static getInstance(): GitService;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a directory is inside a git repository
|
|
41
|
+
*/
|
|
42
|
+
isGitRepo(cwd?: string): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the root directory of the git repository
|
|
45
|
+
*/
|
|
46
|
+
getRepoRoot(cwd?: string): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the current branch name
|
|
49
|
+
*/
|
|
50
|
+
getCurrentBranch(cwd?: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Create a new git worktree
|
|
53
|
+
*/
|
|
54
|
+
createWorktree(path: string, branch: string, options?: {
|
|
55
|
+
baseBranch?: string;
|
|
56
|
+
cwd?: string;
|
|
57
|
+
createBranch?: boolean;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* List all worktrees
|
|
61
|
+
*/
|
|
62
|
+
listWorktrees(cwd?: string): Promise<GitWorktreeInfo[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Remove a worktree
|
|
65
|
+
*/
|
|
66
|
+
removeWorktree(path: string, options?: {
|
|
67
|
+
force?: boolean;
|
|
68
|
+
cwd?: string;
|
|
69
|
+
}): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Prune stale worktree references
|
|
72
|
+
*/
|
|
73
|
+
pruneWorktrees(cwd?: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Create a new branch
|
|
76
|
+
*/
|
|
77
|
+
createBranch(name: string, options?: {
|
|
78
|
+
baseBranch?: string;
|
|
79
|
+
cwd?: string;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Delete a branch
|
|
83
|
+
*/
|
|
84
|
+
deleteBranch(name: string, options?: {
|
|
85
|
+
force?: boolean;
|
|
86
|
+
cwd?: string;
|
|
87
|
+
}): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Check if a branch exists
|
|
90
|
+
*/
|
|
91
|
+
branchExists(name: string, cwd?: string): Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* List all branches
|
|
94
|
+
*/
|
|
95
|
+
listBranches(cwd?: string): Promise<string[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Switch to a branch
|
|
98
|
+
*/
|
|
99
|
+
switchBranch(name: string, cwd?: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Merge a branch into the current branch
|
|
102
|
+
*/
|
|
103
|
+
mergeBranch(name: string, options?: {
|
|
104
|
+
noFf?: boolean;
|
|
105
|
+
message?: string;
|
|
106
|
+
cwd?: string;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
success: boolean;
|
|
109
|
+
conflicts: string[];
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Get detailed git status
|
|
113
|
+
*/
|
|
114
|
+
getStatus(cwd?: string): Promise<GitStatus>;
|
|
115
|
+
/**
|
|
116
|
+
* Get list of conflicted files
|
|
117
|
+
*/
|
|
118
|
+
getConflictedFiles(cwd?: string): Promise<string[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Get diff for a file or all changes
|
|
121
|
+
*/
|
|
122
|
+
getDiff(options?: {
|
|
123
|
+
file?: string;
|
|
124
|
+
staged?: boolean;
|
|
125
|
+
cwd?: string;
|
|
126
|
+
}): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Get git log
|
|
129
|
+
*/
|
|
130
|
+
getLog(options?: {
|
|
131
|
+
count?: number;
|
|
132
|
+
format?: string;
|
|
133
|
+
cwd?: string;
|
|
134
|
+
}): Promise<GitLogEntry[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Get path to CLAUDE.md in repo root
|
|
137
|
+
*/
|
|
138
|
+
getClaudeMdPath(cwd?: string): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Read CLAUDE.md content
|
|
141
|
+
*/
|
|
142
|
+
readClaudeMd(cwd?: string): Promise<string | null>;
|
|
143
|
+
/**
|
|
144
|
+
* Write CLAUDE.md content
|
|
145
|
+
*/
|
|
146
|
+
writeClaudeMd(content: string, cwd?: string): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Append to a section in CLAUDE.md
|
|
149
|
+
*/
|
|
150
|
+
appendToClaudeMdSection(section: string, content: string, cwd?: string): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Stage files
|
|
153
|
+
*/
|
|
154
|
+
stageFiles(files: string[] | 'all', cwd?: string): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Commit staged changes
|
|
157
|
+
*/
|
|
158
|
+
commit(message: string, cwd?: string): Promise<string>;
|
|
159
|
+
/**
|
|
160
|
+
* Abort a merge in progress
|
|
161
|
+
*/
|
|
162
|
+
abortMerge(cwd?: string): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Reset to a specific commit
|
|
165
|
+
*/
|
|
166
|
+
reset(target?: string, options?: {
|
|
167
|
+
hard?: boolean;
|
|
168
|
+
cwd?: string;
|
|
169
|
+
}): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Check if there are uncommitted changes
|
|
172
|
+
*/
|
|
173
|
+
hasUncommittedChanges(cwd?: string): Promise<boolean>;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=git.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.service.d.ts","sourceRoot":"","sources":["../../src/services/git.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAa;IAEpC,OAAO;IAEP,MAAM,CAAC,WA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C,MAAM,GAAG,IAAI,CAAC;IAMvE;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhF;;OAEG;IACG,uBAAuB,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,IAAI,CAAC;IAmChB;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrF;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAO3E;;OAEG;IACG,UAAU,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;OAEG;IACG,KAAK,CACT,MAAM,GAAE,MAAe,EACvB,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAO,GAC7C,OAAO,CAAC,IAAI,CAAC;IAMhB;;OAEG;IACG,qBAAqB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;CAI3E"}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitService - Unified git operations
|
|
3
|
+
*
|
|
4
|
+
* Provides git functionality for all Foundation modules:
|
|
5
|
+
* - Worktree management (create, list, remove)
|
|
6
|
+
* - Branch operations (create, switch, merge)
|
|
7
|
+
* - Status, diff, log queries
|
|
8
|
+
* - CLAUDE.md file operations
|
|
9
|
+
*/
|
|
10
|
+
import { exec } from 'child_process';
|
|
11
|
+
import { promisify } from 'util';
|
|
12
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
13
|
+
import { join, dirname } from 'path';
|
|
14
|
+
const execAsync = promisify(exec);
|
|
15
|
+
export class GitService {
|
|
16
|
+
static instance;
|
|
17
|
+
constructor() { }
|
|
18
|
+
static getInstance() {
|
|
19
|
+
if (!GitService.instance) {
|
|
20
|
+
GitService.instance = new GitService();
|
|
21
|
+
}
|
|
22
|
+
return GitService.instance;
|
|
23
|
+
}
|
|
24
|
+
// ===========================================================================
|
|
25
|
+
// Repository Detection
|
|
26
|
+
// ===========================================================================
|
|
27
|
+
/**
|
|
28
|
+
* Check if a directory is inside a git repository
|
|
29
|
+
*/
|
|
30
|
+
async isGitRepo(cwd = process.cwd()) {
|
|
31
|
+
try {
|
|
32
|
+
await execAsync('git rev-parse --git-dir', { cwd });
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the root directory of the git repository
|
|
41
|
+
*/
|
|
42
|
+
async getRepoRoot(cwd = process.cwd()) {
|
|
43
|
+
const { stdout } = await execAsync('git rev-parse --show-toplevel', { cwd });
|
|
44
|
+
return stdout.trim();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the current branch name
|
|
48
|
+
*/
|
|
49
|
+
async getCurrentBranch(cwd = process.cwd()) {
|
|
50
|
+
const { stdout } = await execAsync('git branch --show-current', { cwd });
|
|
51
|
+
return stdout.trim();
|
|
52
|
+
}
|
|
53
|
+
// ===========================================================================
|
|
54
|
+
// Worktree Operations
|
|
55
|
+
// ===========================================================================
|
|
56
|
+
/**
|
|
57
|
+
* Create a new git worktree
|
|
58
|
+
*/
|
|
59
|
+
async createWorktree(path, branch, options = {}) {
|
|
60
|
+
const { baseBranch = 'main', cwd = process.cwd(), createBranch = true } = options;
|
|
61
|
+
// Ensure parent directory exists
|
|
62
|
+
const parentDir = dirname(path);
|
|
63
|
+
if (!existsSync(parentDir)) {
|
|
64
|
+
mkdirSync(parentDir, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
if (createBranch) {
|
|
67
|
+
// Create worktree with new branch based on baseBranch
|
|
68
|
+
await execAsync(`git worktree add -b "${branch}" "${path}" "${baseBranch}"`, { cwd });
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// Create worktree for existing branch
|
|
72
|
+
await execAsync(`git worktree add "${path}" "${branch}"`, { cwd });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* List all worktrees
|
|
77
|
+
*/
|
|
78
|
+
async listWorktrees(cwd = process.cwd()) {
|
|
79
|
+
const { stdout } = await execAsync('git worktree list --porcelain', { cwd });
|
|
80
|
+
const worktrees = [];
|
|
81
|
+
let current = {};
|
|
82
|
+
for (const line of stdout.split('\n')) {
|
|
83
|
+
if (line.startsWith('worktree ')) {
|
|
84
|
+
if (current.path) {
|
|
85
|
+
worktrees.push(current);
|
|
86
|
+
}
|
|
87
|
+
current = {
|
|
88
|
+
path: line.slice(9),
|
|
89
|
+
bare: false,
|
|
90
|
+
detached: false,
|
|
91
|
+
locked: false,
|
|
92
|
+
prunable: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
else if (line.startsWith('HEAD ')) {
|
|
96
|
+
current.head = line.slice(5);
|
|
97
|
+
}
|
|
98
|
+
else if (line.startsWith('branch ')) {
|
|
99
|
+
current.branch = line.slice(7).replace('refs/heads/', '');
|
|
100
|
+
}
|
|
101
|
+
else if (line === 'bare') {
|
|
102
|
+
current.bare = true;
|
|
103
|
+
}
|
|
104
|
+
else if (line === 'detached') {
|
|
105
|
+
current.detached = true;
|
|
106
|
+
}
|
|
107
|
+
else if (line === 'locked') {
|
|
108
|
+
current.locked = true;
|
|
109
|
+
}
|
|
110
|
+
else if (line === 'prunable') {
|
|
111
|
+
current.prunable = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Don't forget the last worktree
|
|
115
|
+
if (current.path) {
|
|
116
|
+
worktrees.push(current);
|
|
117
|
+
}
|
|
118
|
+
return worktrees;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Remove a worktree
|
|
122
|
+
*/
|
|
123
|
+
async removeWorktree(path, options = {}) {
|
|
124
|
+
const { force = false, cwd = process.cwd() } = options;
|
|
125
|
+
const forceFlag = force ? '--force' : '';
|
|
126
|
+
await execAsync(`git worktree remove ${forceFlag} "${path}"`, { cwd });
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Prune stale worktree references
|
|
130
|
+
*/
|
|
131
|
+
async pruneWorktrees(cwd = process.cwd()) {
|
|
132
|
+
await execAsync('git worktree prune', { cwd });
|
|
133
|
+
}
|
|
134
|
+
// ===========================================================================
|
|
135
|
+
// Branch Operations
|
|
136
|
+
// ===========================================================================
|
|
137
|
+
/**
|
|
138
|
+
* Create a new branch
|
|
139
|
+
*/
|
|
140
|
+
async createBranch(name, options = {}) {
|
|
141
|
+
const { baseBranch = 'HEAD', cwd = process.cwd() } = options;
|
|
142
|
+
await execAsync(`git branch "${name}" "${baseBranch}"`, { cwd });
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Delete a branch
|
|
146
|
+
*/
|
|
147
|
+
async deleteBranch(name, options = {}) {
|
|
148
|
+
const { force = false, cwd = process.cwd() } = options;
|
|
149
|
+
const flag = force ? '-D' : '-d';
|
|
150
|
+
await execAsync(`git branch ${flag} "${name}"`, { cwd });
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check if a branch exists
|
|
154
|
+
*/
|
|
155
|
+
async branchExists(name, cwd = process.cwd()) {
|
|
156
|
+
try {
|
|
157
|
+
await execAsync(`git show-ref --verify --quiet refs/heads/${name}`, { cwd });
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* List all branches
|
|
166
|
+
*/
|
|
167
|
+
async listBranches(cwd = process.cwd()) {
|
|
168
|
+
const { stdout } = await execAsync('git branch --list --format="%(refname:short)"', { cwd });
|
|
169
|
+
return stdout.trim().split('\n').filter(Boolean);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Switch to a branch
|
|
173
|
+
*/
|
|
174
|
+
async switchBranch(name, cwd = process.cwd()) {
|
|
175
|
+
await execAsync(`git switch "${name}"`, { cwd });
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Merge a branch into the current branch
|
|
179
|
+
*/
|
|
180
|
+
async mergeBranch(name, options = {}) {
|
|
181
|
+
const { noFf = false, message, cwd = process.cwd() } = options;
|
|
182
|
+
let cmd = `git merge "${name}"`;
|
|
183
|
+
if (noFf)
|
|
184
|
+
cmd += ' --no-ff';
|
|
185
|
+
if (message)
|
|
186
|
+
cmd += ` -m "${message}"`;
|
|
187
|
+
try {
|
|
188
|
+
await execAsync(cmd, { cwd });
|
|
189
|
+
return { success: true, conflicts: [] };
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
// Check for merge conflicts
|
|
193
|
+
if (error.message?.includes('CONFLICT')) {
|
|
194
|
+
const conflicts = await this.getConflictedFiles(cwd);
|
|
195
|
+
return { success: false, conflicts };
|
|
196
|
+
}
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// ===========================================================================
|
|
201
|
+
// Status & Diff Operations
|
|
202
|
+
// ===========================================================================
|
|
203
|
+
/**
|
|
204
|
+
* Get detailed git status
|
|
205
|
+
*/
|
|
206
|
+
async getStatus(cwd = process.cwd()) {
|
|
207
|
+
const { stdout: branchOutput } = await execAsync('git branch --show-current', { cwd });
|
|
208
|
+
const { stdout: statusOutput } = await execAsync('git status --porcelain=v1', { cwd });
|
|
209
|
+
// Get ahead/behind counts
|
|
210
|
+
let ahead = 0;
|
|
211
|
+
let behind = 0;
|
|
212
|
+
try {
|
|
213
|
+
const { stdout: trackOutput } = await execAsync('git rev-list --left-right --count HEAD...@{upstream}', { cwd });
|
|
214
|
+
const [a, b] = trackOutput.trim().split('\t');
|
|
215
|
+
ahead = parseInt(a || '0', 10);
|
|
216
|
+
behind = parseInt(b || '0', 10);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// No upstream configured
|
|
220
|
+
}
|
|
221
|
+
const staged = [];
|
|
222
|
+
const modified = [];
|
|
223
|
+
const untracked = [];
|
|
224
|
+
const conflicts = [];
|
|
225
|
+
for (const line of statusOutput.split('\n')) {
|
|
226
|
+
if (!line)
|
|
227
|
+
continue;
|
|
228
|
+
const index = line[0];
|
|
229
|
+
const worktree = line[1];
|
|
230
|
+
const file = line.slice(3);
|
|
231
|
+
// Conflicts (both modified)
|
|
232
|
+
if (index === 'U' || worktree === 'U' || (index === 'A' && worktree === 'A')) {
|
|
233
|
+
conflicts.push(file);
|
|
234
|
+
}
|
|
235
|
+
// Staged changes
|
|
236
|
+
else if (index !== ' ' && index !== '?') {
|
|
237
|
+
staged.push(file);
|
|
238
|
+
}
|
|
239
|
+
// Unstaged modifications
|
|
240
|
+
if (worktree === 'M') {
|
|
241
|
+
modified.push(file);
|
|
242
|
+
}
|
|
243
|
+
// Untracked
|
|
244
|
+
if (index === '?') {
|
|
245
|
+
untracked.push(file);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
branch: branchOutput.trim(),
|
|
250
|
+
ahead,
|
|
251
|
+
behind,
|
|
252
|
+
staged,
|
|
253
|
+
modified,
|
|
254
|
+
untracked,
|
|
255
|
+
conflicts,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get list of conflicted files
|
|
260
|
+
*/
|
|
261
|
+
async getConflictedFiles(cwd = process.cwd()) {
|
|
262
|
+
const { stdout } = await execAsync('git diff --name-only --diff-filter=U', { cwd });
|
|
263
|
+
return stdout.trim().split('\n').filter(Boolean);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get diff for a file or all changes
|
|
267
|
+
*/
|
|
268
|
+
async getDiff(options = {}) {
|
|
269
|
+
const { file, staged = false, cwd = process.cwd() } = options;
|
|
270
|
+
let cmd = 'git diff';
|
|
271
|
+
if (staged)
|
|
272
|
+
cmd += ' --staged';
|
|
273
|
+
if (file)
|
|
274
|
+
cmd += ` -- "${file}"`;
|
|
275
|
+
const { stdout } = await execAsync(cmd, { cwd });
|
|
276
|
+
return stdout;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get git log
|
|
280
|
+
*/
|
|
281
|
+
async getLog(options = {}) {
|
|
282
|
+
const { count = 10, cwd = process.cwd() } = options;
|
|
283
|
+
const format = '%H|%h|%an|%ar|%s';
|
|
284
|
+
const { stdout } = await execAsync(`git log -${count} --format="${format}"`, { cwd });
|
|
285
|
+
return stdout
|
|
286
|
+
.trim()
|
|
287
|
+
.split('\n')
|
|
288
|
+
.filter(Boolean)
|
|
289
|
+
.map((line) => {
|
|
290
|
+
const [hash, shortHash, author, date, message] = line.split('|');
|
|
291
|
+
return { hash, shortHash, author, date, message };
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
// ===========================================================================
|
|
295
|
+
// CLAUDE.md Operations
|
|
296
|
+
// ===========================================================================
|
|
297
|
+
/**
|
|
298
|
+
* Get path to CLAUDE.md in repo root
|
|
299
|
+
*/
|
|
300
|
+
async getClaudeMdPath(cwd = process.cwd()) {
|
|
301
|
+
const root = await this.getRepoRoot(cwd);
|
|
302
|
+
return join(root, 'CLAUDE.md');
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Read CLAUDE.md content
|
|
306
|
+
*/
|
|
307
|
+
async readClaudeMd(cwd = process.cwd()) {
|
|
308
|
+
const path = await this.getClaudeMdPath(cwd);
|
|
309
|
+
if (!existsSync(path))
|
|
310
|
+
return null;
|
|
311
|
+
return readFileSync(path, 'utf-8');
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Write CLAUDE.md content
|
|
315
|
+
*/
|
|
316
|
+
async writeClaudeMd(content, cwd = process.cwd()) {
|
|
317
|
+
const path = await this.getClaudeMdPath(cwd);
|
|
318
|
+
writeFileSync(path, content, 'utf-8');
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Append to a section in CLAUDE.md
|
|
322
|
+
*/
|
|
323
|
+
async appendToClaudeMdSection(section, content, cwd = process.cwd()) {
|
|
324
|
+
const path = await this.getClaudeMdPath(cwd);
|
|
325
|
+
let existing = '';
|
|
326
|
+
if (existsSync(path)) {
|
|
327
|
+
existing = readFileSync(path, 'utf-8');
|
|
328
|
+
}
|
|
329
|
+
// Find or create section
|
|
330
|
+
const sectionHeader = `## ${section}`;
|
|
331
|
+
if (existing.includes(sectionHeader)) {
|
|
332
|
+
// Find the section and append after it
|
|
333
|
+
const sectionIndex = existing.indexOf(sectionHeader);
|
|
334
|
+
const nextSectionMatch = existing.slice(sectionIndex + sectionHeader.length).match(/\n## /);
|
|
335
|
+
const insertIndex = nextSectionMatch
|
|
336
|
+
? sectionIndex + sectionHeader.length + nextSectionMatch.index
|
|
337
|
+
: existing.length;
|
|
338
|
+
const before = existing.slice(0, insertIndex);
|
|
339
|
+
const after = existing.slice(insertIndex);
|
|
340
|
+
// Ensure proper spacing
|
|
341
|
+
const newContent = `${before.trimEnd()}\n${content}\n${after.trimStart()}`;
|
|
342
|
+
writeFileSync(path, newContent, 'utf-8');
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
// Append new section
|
|
346
|
+
const newContent = `${existing.trimEnd()}\n\n${sectionHeader}\n\n${content}\n`;
|
|
347
|
+
writeFileSync(path, newContent, 'utf-8');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
// ===========================================================================
|
|
351
|
+
// Utility Operations
|
|
352
|
+
// ===========================================================================
|
|
353
|
+
/**
|
|
354
|
+
* Stage files
|
|
355
|
+
*/
|
|
356
|
+
async stageFiles(files, cwd = process.cwd()) {
|
|
357
|
+
if (files === 'all') {
|
|
358
|
+
await execAsync('git add -A', { cwd });
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
await execAsync(`git add ${files.map((f) => `"${f}"`).join(' ')}`, { cwd });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Commit staged changes
|
|
366
|
+
*/
|
|
367
|
+
async commit(message, cwd = process.cwd()) {
|
|
368
|
+
const { stdout } = await execAsync(`git commit -m "${message}"`, { cwd });
|
|
369
|
+
// Extract commit hash from output
|
|
370
|
+
const match = stdout.match(/\[[\w-]+ ([a-f0-9]+)\]/);
|
|
371
|
+
return match ? match[1] : '';
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Abort a merge in progress
|
|
375
|
+
*/
|
|
376
|
+
async abortMerge(cwd = process.cwd()) {
|
|
377
|
+
await execAsync('git merge --abort', { cwd });
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Reset to a specific commit
|
|
381
|
+
*/
|
|
382
|
+
async reset(target = 'HEAD', options = {}) {
|
|
383
|
+
const { hard = false, cwd = process.cwd() } = options;
|
|
384
|
+
const flag = hard ? '--hard' : '';
|
|
385
|
+
await execAsync(`git reset ${flag} ${target}`, { cwd });
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Check if there are uncommitted changes
|
|
389
|
+
*/
|
|
390
|
+
async hasUncommittedChanges(cwd = process.cwd()) {
|
|
391
|
+
const { stdout } = await execAsync('git status --porcelain', { cwd });
|
|
392
|
+
return stdout.trim().length > 0;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
//# sourceMappingURL=git.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.service.js","sourceRoot":"","sources":["../../src/services/git.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE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1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProviderService - Multi-provider AI routing with failover
|
|
3
|
+
*
|
|
4
|
+
* Supports 13+ AI providers:
|
|
5
|
+
* - Anthropic (Claude)
|
|
6
|
+
* - OpenAI (GPT-4o, o1, o3)
|
|
7
|
+
* - Google (Gemini)
|
|
8
|
+
* - DeepSeek
|
|
9
|
+
* - Groq
|
|
10
|
+
* - Together
|
|
11
|
+
* - Fireworks
|
|
12
|
+
* - OpenRouter
|
|
13
|
+
* - Z.AI (GLM)
|
|
14
|
+
* - Kimi
|
|
15
|
+
* - Ollama (local)
|
|
16
|
+
* - Perplexity
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Automatic retry with exponential backoff
|
|
20
|
+
* - Health tracking per provider
|
|
21
|
+
* - Circuit breakers
|
|
22
|
+
* - Cost-aware routing
|
|
23
|
+
* - Session delegation for Anthropic
|
|
24
|
+
*/
|
|
25
|
+
import type { FoundationConfig, ProviderName, AgentRole, ProviderHealth, ProviderInvokeResult } from '../types/index.js';
|
|
26
|
+
export interface InvokeOptions {
|
|
27
|
+
role: AgentRole;
|
|
28
|
+
task: string;
|
|
29
|
+
context?: string;
|
|
30
|
+
systemPrompt?: string;
|
|
31
|
+
temperature?: number;
|
|
32
|
+
maxTokens?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare class ProviderService {
|
|
35
|
+
private static instance;
|
|
36
|
+
private config;
|
|
37
|
+
private storage;
|
|
38
|
+
private initialized;
|
|
39
|
+
private constructor();
|
|
40
|
+
static getInstance(): ProviderService;
|
|
41
|
+
/**
|
|
42
|
+
* Initialize with configuration
|
|
43
|
+
*/
|
|
44
|
+
init(config: FoundationConfig): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Invoke an agent role with a task
|
|
47
|
+
*/
|
|
48
|
+
invoke(options: InvokeOptions): Promise<ProviderInvokeResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Invoke with fallback chain
|
|
51
|
+
*/
|
|
52
|
+
private invokeWithFallback;
|
|
53
|
+
/**
|
|
54
|
+
* Invoke a specific provider
|
|
55
|
+
*/
|
|
56
|
+
private invokeProvider;
|
|
57
|
+
/**
|
|
58
|
+
* List available providers
|
|
59
|
+
*/
|
|
60
|
+
listProviders(): ProviderName[];
|
|
61
|
+
/**
|
|
62
|
+
* Get health status for all providers
|
|
63
|
+
*/
|
|
64
|
+
getProviderHealth(): ProviderHealth[];
|
|
65
|
+
/**
|
|
66
|
+
* Test a specific provider's connectivity
|
|
67
|
+
*/
|
|
68
|
+
testProvider(provider: ProviderName): Promise<{
|
|
69
|
+
success: boolean;
|
|
70
|
+
latencyMs: number;
|
|
71
|
+
error?: string;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=provider.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.service.d.ts","sourceRoot":"","sources":["../../src/services/provider.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,oBAAoB,EAErB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkB;IACzC,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAIP,MAAM,CAAC,WAAW,IAAI,eAAe;IAOrC;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnD;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAsDnE;;OAEG;YACW,kBAAkB;IAyChC;;OAEG;YACW,cAAc;IAkB5B;;OAEG;IACH,aAAa,IAAI,YAAY,EAAE;IAK/B;;OAEG;IACH,iBAAiB,IAAI,cAAc,EAAE;IAIrC;;OAEG;IACG,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAmB7G"}
|