atlasia-ghost 1.1.0 → 1.1.1
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.
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const { ExtensionRPCClient, GitExtension } = require('./extension.js');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
6
7
|
|
|
7
8
|
const manifestPath = path.join(__dirname, 'manifest.json');
|
|
8
9
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
@@ -49,16 +50,52 @@ class ExtensionWrapper {
|
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* Command: commit
|
|
52
|
-
* Generates
|
|
53
|
+
* Generates an AI commit message for staged changes and commits them.
|
|
53
54
|
*/
|
|
54
55
|
async commit(params) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
const flags = params.flags || {};
|
|
57
|
+
|
|
58
|
+
// Resolve AI config: flags take precedence over ghostrc
|
|
59
|
+
let provider = flags.provider;
|
|
60
|
+
let apiKey = flags.apiKey || flags['api-key'];
|
|
61
|
+
let model = flags.model;
|
|
62
|
+
|
|
63
|
+
if (!provider || !apiKey) {
|
|
64
|
+
try {
|
|
65
|
+
const configPath = path.join(os.homedir(), '.ghost', 'config', 'ghostrc.json');
|
|
66
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
67
|
+
if (config.ai) {
|
|
68
|
+
provider = provider || config.ai.provider;
|
|
69
|
+
apiKey = apiKey || config.ai.apiKey;
|
|
70
|
+
model = model || config.ai.model;
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
// no config file, will fail later if apiKey still missing
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Get staged diff
|
|
78
|
+
const diff = await this.git.getStagedDiff();
|
|
79
|
+
if (!diff.text) {
|
|
80
|
+
return { success: false, output: 'No staged changes to commit.' };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Security audit (skippable via --skip-audit)
|
|
84
|
+
if (!flags['skip-audit'] && !flags.skipAudit) {
|
|
85
|
+
const audit = await this.git.auditSecurity(diff.map, provider, apiKey, model);
|
|
86
|
+
if (audit.blocked) {
|
|
87
|
+
return { success: false, output: `\x1b[31mCommit blocked: ${audit.reason}\x1b[0m` };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Generate commit message via AI
|
|
92
|
+
const customPrompt = flags.prompt || flags.message;
|
|
93
|
+
const message = await this.git.generateCommit(diff.text, customPrompt, provider, apiKey, model);
|
|
94
|
+
|
|
95
|
+
// Run the actual git commit
|
|
96
|
+
await this.rpc.gitExec(['commit', '-m', message]);
|
|
97
|
+
|
|
98
|
+
return { success: true, output: `\x1b[32m✓ Committed:\x1b[0m ${message}` };
|
|
62
99
|
}
|
|
63
100
|
|
|
64
101
|
/**
|