@soufienne/mcp-server-driftguard 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.
- package/LICENSE +21 -0
- package/README.md +129 -0
- package/build/git.d.ts +68 -0
- package/build/git.d.ts.map +1 -0
- package/build/git.js +249 -0
- package/build/git.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +589 -0
- package/build/index.js.map +1 -0
- package/build/risk.d.ts +19 -0
- package/build/risk.d.ts.map +1 -0
- package/build/risk.js +59 -0
- package/build/risk.js.map +1 -0
- package/build/scope.d.ts +38 -0
- package/build/scope.d.ts.map +1 -0
- package/build/scope.js +105 -0
- package/build/scope.js.map +1 -0
- package/build/state.d.ts +181 -0
- package/build/state.d.ts.map +1 -0
- package/build/state.js +844 -0
- package/build/state.js.map +1 -0
- package/build/types.d.ts +178 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +56 -0
- package/build/types.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Soufienne <ramailorakou@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🛡️ DriftGuard
|
|
4
|
+
### A Firewall for Intelligence
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@soufienne/mcp-server-driftguard)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://modelcontextprotocol.io)
|
|
9
|
+
|
|
10
|
+
**Strict State Machine • Zero-Loss Continuity • L3 Integrity**
|
|
11
|
+
|
|
12
|
+
[Getting Started](#-getting-started) •
|
|
13
|
+
[The Manifesto](#-the-manifesto) •
|
|
14
|
+
[Documentation](#-documentation)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 🧐 What is DriftGuard?
|
|
21
|
+
|
|
22
|
+
**DriftGuard** is an implementing server for the **Model Context Protocol (MCP)** that acts as a "Traffic Controller" for AI Agents.
|
|
23
|
+
|
|
24
|
+
Most agents suffer from **"Code Drift"**: they edit random files, lose context, and hallucinate checkpoints. DriftGuard solves this by enforcing a **Strict Recursive State Machine**. An agent *cannot* touch code until it has:
|
|
25
|
+
1. **Proposed** a task.
|
|
26
|
+
2. **Claimed** a scope (locking files).
|
|
27
|
+
3. **Declared** intent.
|
|
28
|
+
|
|
29
|
+
It is not just a tool; it is an **Agreement Architecture**.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🚀 Getting Started
|
|
34
|
+
|
|
35
|
+
You can run DriftGuard instantly using `npx`. No configuration required.
|
|
36
|
+
|
|
37
|
+
### One-Command Install
|
|
38
|
+
```bash
|
|
39
|
+
npx @modelcontextprotocol/inspector npx @soufienne/mcp-server-driftguard
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Manual Installation (For Development)
|
|
43
|
+
```bash
|
|
44
|
+
# 1. Clone the repository
|
|
45
|
+
git clone https://github.com/ramailo1/mcp-server-driftguard.git
|
|
46
|
+
cd mcp-server-driftguard
|
|
47
|
+
|
|
48
|
+
# 2. Install dependencies & Build
|
|
49
|
+
npm install
|
|
50
|
+
npm run build
|
|
51
|
+
|
|
52
|
+
# 3. Launch the Inspector
|
|
53
|
+
npm run inspect
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 📜 The Manifesto (Workflow)
|
|
59
|
+
|
|
60
|
+
DriftGuard enforces a linear, verifiable cycle.
|
|
61
|
+
|
|
62
|
+
```mermaid
|
|
63
|
+
graph LR
|
|
64
|
+
A[Start] --> B(dg_propose_task)
|
|
65
|
+
B --> C{dg_claim_scope}
|
|
66
|
+
C -->|Locked| D(dg_report_intent)
|
|
67
|
+
D -->|Exec| E[Edit Files]
|
|
68
|
+
E --> F(dg_verify)
|
|
69
|
+
F -->|Pass| G(dg_checkpoint)
|
|
70
|
+
G --> A
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 1. 📝 Propose & Plan
|
|
74
|
+
Define your objective. DriftGuard creates a structured `ACTIVE_PLAN.md` and tracks progress.
|
|
75
|
+
- `dg_propose_task`: Start a new mission.
|
|
76
|
+
|
|
77
|
+
### 2. 🔒 Scope Claiming
|
|
78
|
+
Prevent agents from stepping on each other's toes.
|
|
79
|
+
- `dg_claim_scope`: Lock file paths (e.g., `src/**/*.ts`).
|
|
80
|
+
- **Integrity**: Automatically snapshots file hashes (MD5) to detect "Time-Travel" hacks.
|
|
81
|
+
|
|
82
|
+
### 3. ⚡ Intent & Action
|
|
83
|
+
Never act without declaring *why*.
|
|
84
|
+
- `dg_report_intent`: "I am identifying the bug in user.ts"
|
|
85
|
+
- `dg_verify`: Run your test command. *Proves* the code works.
|
|
86
|
+
|
|
87
|
+
### 4. 💾 Checkpoint & Continuity
|
|
88
|
+
Save your game.
|
|
89
|
+
- `dg_checkpoint`: Commits L3 Git Notes.
|
|
90
|
+
- `dg_generate_handoff`: **Resume Packet**. Serializes the entire session state for the next agent.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 🛠️ The Toolkit
|
|
95
|
+
|
|
96
|
+
| Tool | Purpose | Phase |
|
|
97
|
+
| :--- | :--- | :--- |
|
|
98
|
+
| `dg_init` | Initialize DriftGuard in a repo | Core |
|
|
99
|
+
| `dg_status` | Get current tasks & state | Core |
|
|
100
|
+
| `dg_claim_scope` | **Lock** files for exclusive editing | Traffic |
|
|
101
|
+
| `dg_report_intent` | Declare next move (Required before checkpt) | Action |
|
|
102
|
+
| `dg_verify` | Run verification command | Action |
|
|
103
|
+
| `dg_health_check` | Detect manual file tampering | Integrity |
|
|
104
|
+
| `dg_generate_handoff` | Create resume packet for next session | Continuity |
|
|
105
|
+
| `dg_reset` | **Hard Reset** (Safety Valve) | Safety |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 🤝 Contributing
|
|
110
|
+
|
|
111
|
+
We welcome contributions "at the speed of thought."
|
|
112
|
+
1. Fork the repo (`ramailo1/mcp-server-driftguard`).
|
|
113
|
+
2. Create your feature branch.
|
|
114
|
+
3. Commit your changes.
|
|
115
|
+
4. Push to the branch.
|
|
116
|
+
5. Open a Pull Request.
|
|
117
|
+
|
|
118
|
+
## 📄 License
|
|
119
|
+
|
|
120
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
<div align="center">
|
|
125
|
+
|
|
126
|
+
**Built with ❤️ for the Age of Agents.**
|
|
127
|
+
*@soufienne*
|
|
128
|
+
|
|
129
|
+
</div>
|
package/build/git.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DriftGuard Git Manager
|
|
3
|
+
* Handles L3 (Git Notes) persistence for audit trails
|
|
4
|
+
*/
|
|
5
|
+
import { GitNoteMetadata } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* GitManager handles all Git operations for L3 storage
|
|
8
|
+
*/
|
|
9
|
+
export declare class GitManager {
|
|
10
|
+
private static instance;
|
|
11
|
+
private git;
|
|
12
|
+
private projectPath;
|
|
13
|
+
private _isRepo;
|
|
14
|
+
private constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Get the singleton instance
|
|
17
|
+
*/
|
|
18
|
+
static getInstance(projectPath?: string): GitManager;
|
|
19
|
+
/**
|
|
20
|
+
* Check if current directory is a Git repository
|
|
21
|
+
*/
|
|
22
|
+
isGitRepo(): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the current HEAD commit hash
|
|
25
|
+
*/
|
|
26
|
+
getHeadHash(): Promise<string | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Get git diff stat output (summary of changes)
|
|
29
|
+
*/
|
|
30
|
+
getDiffStat(): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Get detailed git diff output
|
|
33
|
+
*/
|
|
34
|
+
getDiffDetailed(): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Get list of changed files
|
|
37
|
+
*/
|
|
38
|
+
getChangedFiles(): Promise<string[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Write a Git Note to the current HEAD commit
|
|
41
|
+
* Uses refs/notes/driftguard namespace to avoid conflicts
|
|
42
|
+
*/
|
|
43
|
+
writeNote(metadata: GitNoteMetadata): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Read Git Note from a specific commit
|
|
46
|
+
*/
|
|
47
|
+
readNote(commitHash?: string): Promise<GitNoteMetadata | null>;
|
|
48
|
+
/**
|
|
49
|
+
* List all commits with DriftGuard notes
|
|
50
|
+
* Returns an array of commit hashes
|
|
51
|
+
*/
|
|
52
|
+
listNotedCommits(): Promise<string[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Reconstruct task history from Git Notes
|
|
55
|
+
* Useful if .driftguard/ is deleted
|
|
56
|
+
*/
|
|
57
|
+
reconstructHistory(): Promise<GitNoteMetadata[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Update the project path
|
|
60
|
+
*/
|
|
61
|
+
setProjectPath(path: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* List files matching patterns
|
|
64
|
+
*/
|
|
65
|
+
listFiles(patterns: string[]): Promise<string[]>;
|
|
66
|
+
}
|
|
67
|
+
export declare const gitManager: GitManager;
|
|
68
|
+
//# sourceMappingURL=git.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7C;;GAEG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAa;IACpC,OAAO,CAAC,GAAG,CAAY;IACvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAwB;IAEvC,OAAO;IAUP;;OAEG;WACW,WAAW,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU;IAU3D;;OAEG;IACU,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAc1C;;OAEG;IACU,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYlD;;OAEG;IACU,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAY3C;;OAEG;IACU,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAY/C;;OAEG;IACU,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAkBjD;;;OAGG;IACU,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IA8BnE;;OAEG;IACU,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAyB3E;;;OAGG;IACU,gBAAgB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAuBlD;;;OAGG;IACU,kBAAkB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAmB7D;;OAEG;IACI,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAUzC;;OAEG;IACU,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAYhE;AAGD,eAAO,MAAM,UAAU,YAA2B,CAAC"}
|
package/build/git.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DriftGuard Git Manager
|
|
3
|
+
* Handles L3 (Git Notes) persistence for audit trails
|
|
4
|
+
*/
|
|
5
|
+
import { simpleGit } from 'simple-git';
|
|
6
|
+
const DRIFTGUARD_NOTE_REF = 'refs/notes/driftguard';
|
|
7
|
+
/**
|
|
8
|
+
* GitManager handles all Git operations for L3 storage
|
|
9
|
+
*/
|
|
10
|
+
export class GitManager {
|
|
11
|
+
static instance;
|
|
12
|
+
git;
|
|
13
|
+
projectPath;
|
|
14
|
+
_isRepo = null;
|
|
15
|
+
constructor(projectPath) {
|
|
16
|
+
this.projectPath = projectPath;
|
|
17
|
+
const options = {
|
|
18
|
+
baseDir: projectPath,
|
|
19
|
+
binary: 'git',
|
|
20
|
+
maxConcurrentProcesses: 1,
|
|
21
|
+
};
|
|
22
|
+
this.git = simpleGit(options);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the singleton instance
|
|
26
|
+
*/
|
|
27
|
+
static getInstance(projectPath) {
|
|
28
|
+
if (!GitManager.instance) {
|
|
29
|
+
GitManager.instance = new GitManager(projectPath || process.cwd());
|
|
30
|
+
}
|
|
31
|
+
else if (projectPath && projectPath !== GitManager.instance.projectPath) {
|
|
32
|
+
// Update path if different
|
|
33
|
+
GitManager.instance = new GitManager(projectPath);
|
|
34
|
+
}
|
|
35
|
+
return GitManager.instance;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if current directory is a Git repository
|
|
39
|
+
*/
|
|
40
|
+
async isGitRepo() {
|
|
41
|
+
if (this._isRepo !== null) {
|
|
42
|
+
return this._isRepo;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
await this.git.revparse(['--git-dir']);
|
|
46
|
+
this._isRepo = true;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
this._isRepo = false;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the current HEAD commit hash
|
|
56
|
+
*/
|
|
57
|
+
async getHeadHash() {
|
|
58
|
+
if (!(await this.isGitRepo())) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const hash = await this.git.revparse(['HEAD']);
|
|
63
|
+
return hash.trim();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get git diff stat output (summary of changes)
|
|
71
|
+
*/
|
|
72
|
+
async getDiffStat() {
|
|
73
|
+
if (!(await this.isGitRepo())) {
|
|
74
|
+
return 'Not a git repository';
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const diff = await this.git.diff(['--stat']);
|
|
78
|
+
return diff || 'No changes detected';
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return `Error getting diff: ${error}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get detailed git diff output
|
|
86
|
+
*/
|
|
87
|
+
async getDiffDetailed() {
|
|
88
|
+
if (!(await this.isGitRepo())) {
|
|
89
|
+
return 'Not a git repository';
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const diff = await this.git.diff();
|
|
93
|
+
return diff || 'No changes detected';
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return `Error getting diff: ${error}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get list of changed files
|
|
101
|
+
*/
|
|
102
|
+
async getChangedFiles() {
|
|
103
|
+
if (!(await this.isGitRepo())) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const status = await this.git.status();
|
|
108
|
+
const files = [
|
|
109
|
+
...status.modified,
|
|
110
|
+
...status.created,
|
|
111
|
+
...status.deleted,
|
|
112
|
+
...status.renamed.map(r => r.to),
|
|
113
|
+
];
|
|
114
|
+
return [...new Set(files)]; // Deduplicate
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Write a Git Note to the current HEAD commit
|
|
122
|
+
* Uses refs/notes/driftguard namespace to avoid conflicts
|
|
123
|
+
*/
|
|
124
|
+
async writeNote(metadata) {
|
|
125
|
+
if (!(await this.isGitRepo())) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const headHash = await this.getHeadHash();
|
|
129
|
+
if (!headHash) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const noteContent = JSON.stringify(metadata, null, 2);
|
|
134
|
+
// Write note with --force to allow overwriting
|
|
135
|
+
await this.git.raw([
|
|
136
|
+
'notes',
|
|
137
|
+
'--ref', DRIFTGUARD_NOTE_REF,
|
|
138
|
+
'add',
|
|
139
|
+
'-f', // Force overwrite if exists
|
|
140
|
+
'-m', noteContent,
|
|
141
|
+
headHash
|
|
142
|
+
]);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('Failed to write Git Note:', error);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Read Git Note from a specific commit
|
|
152
|
+
*/
|
|
153
|
+
async readNote(commitHash) {
|
|
154
|
+
if (!(await this.isGitRepo())) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
const hash = commitHash || await this.getHeadHash();
|
|
158
|
+
if (!hash) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
const noteContent = await this.git.raw([
|
|
163
|
+
'notes',
|
|
164
|
+
'--ref', DRIFTGUARD_NOTE_REF,
|
|
165
|
+
'show',
|
|
166
|
+
hash
|
|
167
|
+
]);
|
|
168
|
+
return JSON.parse(noteContent.trim());
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// Note doesn't exist or parse error
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* List all commits with DriftGuard notes
|
|
177
|
+
* Returns an array of commit hashes
|
|
178
|
+
*/
|
|
179
|
+
async listNotedCommits() {
|
|
180
|
+
if (!(await this.isGitRepo())) {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const output = await this.git.raw([
|
|
185
|
+
'notes',
|
|
186
|
+
'--ref', DRIFTGUARD_NOTE_REF,
|
|
187
|
+
'list'
|
|
188
|
+
]);
|
|
189
|
+
// Format: <note-object-hash> <commit-hash>
|
|
190
|
+
const lines = output.trim().split('\n').filter(l => l);
|
|
191
|
+
return lines.map(line => {
|
|
192
|
+
const parts = line.split(' ');
|
|
193
|
+
return parts[1] || parts[0]; // Get commit hash
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Reconstruct task history from Git Notes
|
|
202
|
+
* Useful if .driftguard/ is deleted
|
|
203
|
+
*/
|
|
204
|
+
async reconstructHistory() {
|
|
205
|
+
const commits = await this.listNotedCommits();
|
|
206
|
+
const history = [];
|
|
207
|
+
for (const hash of commits) {
|
|
208
|
+
const note = await this.readNote(hash);
|
|
209
|
+
if (note) {
|
|
210
|
+
history.push(note);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Sort by timestamp descending (newest first)
|
|
214
|
+
history.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
215
|
+
return history;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Update the project path
|
|
219
|
+
*/
|
|
220
|
+
setProjectPath(path) {
|
|
221
|
+
this.projectPath = path;
|
|
222
|
+
const options = {
|
|
223
|
+
baseDir: path,
|
|
224
|
+
binary: 'git',
|
|
225
|
+
maxConcurrentProcesses: 1,
|
|
226
|
+
};
|
|
227
|
+
this.git = simpleGit(options);
|
|
228
|
+
this._isRepo = null; // Reset cache
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* List files matching patterns
|
|
232
|
+
*/
|
|
233
|
+
async listFiles(patterns) {
|
|
234
|
+
if (!(await this.isGitRepo())) {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
// git ls-files -c -o --exclude-standard -- pathspec...
|
|
239
|
+
const output = await this.git.raw(['ls-files', '-c', '-o', '--exclude-standard', '--', ...patterns]);
|
|
240
|
+
return output.split('\n').filter(s => s.trim().length > 0);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Export singleton instance
|
|
248
|
+
export const gitManager = GitManager.getInstance();
|
|
249
|
+
//# sourceMappingURL=git.js.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