@greenarmor/ges-core 1.2.0 → 1.2.2
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/fix-history/index.d.ts +38 -0
- package/dist/fix-history/index.js +75 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/index.d.ts +36 -0
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FixHistoryEntry, ControlStatus, SeverityLevel } from "../types/index.js";
|
|
2
|
+
export declare function loadFixHistory(projectPath: string): FixHistoryEntry[];
|
|
3
|
+
export declare function appendFixHistory(projectPath: string, entries: FixHistoryEntry[]): void;
|
|
4
|
+
export declare function clearFixHistory(projectPath: string): void;
|
|
5
|
+
export interface FindingLike {
|
|
6
|
+
ruleId: string;
|
|
7
|
+
severity: SeverityLevel | string;
|
|
8
|
+
category: string;
|
|
9
|
+
title: string;
|
|
10
|
+
file: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
evidence: string;
|
|
13
|
+
description: string;
|
|
14
|
+
controlIds: string[];
|
|
15
|
+
fix: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ControlLike {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
framework: string;
|
|
21
|
+
article?: string;
|
|
22
|
+
status: ControlStatus | string;
|
|
23
|
+
}
|
|
24
|
+
export interface FixActionLike {
|
|
25
|
+
type: "create" | "modify" | "append" | "npm-install";
|
|
26
|
+
filePath: string;
|
|
27
|
+
description: string;
|
|
28
|
+
ruleId: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function createFixHistoryEntry(opts: {
|
|
31
|
+
source: "cli" | "mcp";
|
|
32
|
+
dry_run: boolean;
|
|
33
|
+
finding: FindingLike;
|
|
34
|
+
action: FixActionLike;
|
|
35
|
+
controls: ControlLike[];
|
|
36
|
+
applied: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
}): FixHistoryEntry;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
export function loadFixHistory(projectPath) {
|
|
4
|
+
const histPath = path.join(projectPath, ".ges", "fix-history.json");
|
|
5
|
+
try {
|
|
6
|
+
const raw = fs.readFileSync(histPath, "utf-8");
|
|
7
|
+
const data = JSON.parse(raw);
|
|
8
|
+
return Array.isArray(data) ? data : [];
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function appendFixHistory(projectPath, entries) {
|
|
15
|
+
if (entries.length === 0)
|
|
16
|
+
return;
|
|
17
|
+
const gesDir = path.join(projectPath, ".ges");
|
|
18
|
+
if (!fs.existsSync(gesDir)) {
|
|
19
|
+
fs.mkdirSync(gesDir, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
const histPath = path.join(gesDir, "fix-history.json");
|
|
22
|
+
const existing = loadFixHistory(projectPath);
|
|
23
|
+
const updated = existing.concat(entries);
|
|
24
|
+
fs.writeFileSync(histPath, JSON.stringify(updated, null, 2), "utf-8");
|
|
25
|
+
}
|
|
26
|
+
export function clearFixHistory(projectPath) {
|
|
27
|
+
const histPath = path.join(projectPath, ".ges", "fix-history.json");
|
|
28
|
+
try {
|
|
29
|
+
fs.unlinkSync(histPath);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// ignore
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let entryCounter = 0;
|
|
36
|
+
export function createFixHistoryEntry(opts) {
|
|
37
|
+
entryCounter++;
|
|
38
|
+
const frameworksAffected = [...new Set(opts.controls.map(c => c.framework))];
|
|
39
|
+
return {
|
|
40
|
+
id: `fix-${Date.now()}-${entryCounter}`,
|
|
41
|
+
timestamp: new Date().toISOString(),
|
|
42
|
+
source: opts.source,
|
|
43
|
+
dry_run: opts.dry_run,
|
|
44
|
+
finding: {
|
|
45
|
+
rule_id: opts.finding.ruleId,
|
|
46
|
+
severity: opts.finding.severity,
|
|
47
|
+
category: opts.finding.category,
|
|
48
|
+
title: opts.finding.title,
|
|
49
|
+
file: opts.finding.file,
|
|
50
|
+
line: opts.finding.line,
|
|
51
|
+
evidence: opts.finding.evidence,
|
|
52
|
+
description: opts.finding.description,
|
|
53
|
+
},
|
|
54
|
+
controls: opts.controls.map(c => ({
|
|
55
|
+
id: c.id,
|
|
56
|
+
name: c.name,
|
|
57
|
+
framework: c.framework,
|
|
58
|
+
article: c.article,
|
|
59
|
+
status: c.status,
|
|
60
|
+
})),
|
|
61
|
+
fix: {
|
|
62
|
+
action_type: opts.action.type,
|
|
63
|
+
file_path: opts.action.filePath,
|
|
64
|
+
description: opts.action.description,
|
|
65
|
+
guidance: opts.finding.fix,
|
|
66
|
+
applied: opts.applied,
|
|
67
|
+
error: opts.error,
|
|
68
|
+
},
|
|
69
|
+
compliance_impact: {
|
|
70
|
+
frameworks_affected: frameworksAffected,
|
|
71
|
+
controls_addressed: opts.controls.length,
|
|
72
|
+
severity_resolved: opts.finding.severity,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -154,3 +154,39 @@ export interface ControlOverride {
|
|
|
154
154
|
status: ControlStatus;
|
|
155
155
|
reason: string;
|
|
156
156
|
}
|
|
157
|
+
export interface FixHistoryEntry {
|
|
158
|
+
id: string;
|
|
159
|
+
timestamp: string;
|
|
160
|
+
source: "cli" | "mcp";
|
|
161
|
+
dry_run: boolean;
|
|
162
|
+
finding: {
|
|
163
|
+
rule_id: string;
|
|
164
|
+
severity: SeverityLevel;
|
|
165
|
+
category: string;
|
|
166
|
+
title: string;
|
|
167
|
+
file: string;
|
|
168
|
+
line?: number;
|
|
169
|
+
evidence: string;
|
|
170
|
+
description: string;
|
|
171
|
+
};
|
|
172
|
+
controls: {
|
|
173
|
+
id: string;
|
|
174
|
+
name: string;
|
|
175
|
+
framework: string;
|
|
176
|
+
article?: string;
|
|
177
|
+
status: ControlStatus;
|
|
178
|
+
}[];
|
|
179
|
+
fix: {
|
|
180
|
+
action_type: "create" | "modify" | "append" | "npm-install";
|
|
181
|
+
file_path: string;
|
|
182
|
+
description: string;
|
|
183
|
+
guidance: string;
|
|
184
|
+
applied: boolean;
|
|
185
|
+
error?: string;
|
|
186
|
+
};
|
|
187
|
+
compliance_impact: {
|
|
188
|
+
frameworks_affected: string[];
|
|
189
|
+
controls_addressed: number;
|
|
190
|
+
severity_resolved: SeverityLevel;
|
|
191
|
+
};
|
|
192
|
+
}
|