@lonely9206/cc-hooks 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/.claude/settings.json +26 -0
- package/README.md +29 -0
- package/bin/cli.js +89 -0
- package/bin/install.js +64 -0
- package/dist/index.js +10805 -0
- package/package.json +21 -0
- package/src/api.js +33 -0
- package/src/fileTracker.js +219 -0
- package/src/git.js +12 -0
- package/src/index.js +4 -0
- package/track_logs/.current_entry +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"UserPromptSubmit": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "cc-hooks prompt"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"PostToolBatch": [
|
|
15
|
+
{
|
|
16
|
+
"matcher": "",
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "cc-hooks changes"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# cc-hooks
|
|
2
|
+
|
|
3
|
+
Claude Code hooks for logging prompts and file changes to cloud MySQL.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g cc-hooks
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or use directly with npx:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx cc-hooks prompt "your prompt"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
Hooks are automatically configured on install via postinstall script.
|
|
20
|
+
|
|
21
|
+
## API URL
|
|
22
|
+
|
|
23
|
+
Set environment variable to override default API URL:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
CC_HOOKS_API_URL=http://your-api-server:8000 npx cc-hooks prompt "test"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Default: http://localhost:8000 (dev) / http://192.168.1.224:8000 (production)
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { FileTracker } = require('../src/fileTracker');
|
|
3
|
+
const { logPrompt, logChanges } = require('../src/api');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const LOG_DIR = path.join(process.cwd(), 'track_logs');
|
|
8
|
+
const ENTRY_FILE = path.join(LOG_DIR, '.current_entry');
|
|
9
|
+
|
|
10
|
+
function ensureDir() {
|
|
11
|
+
if (!fs.existsSync(LOG_DIR)) {
|
|
12
|
+
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
const command = process.argv[2];
|
|
18
|
+
|
|
19
|
+
if (command === 'prompt') {
|
|
20
|
+
// Get prompt from args or stdin
|
|
21
|
+
let prompt = process.argv[3] || '';
|
|
22
|
+
|
|
23
|
+
if (!prompt) {
|
|
24
|
+
try {
|
|
25
|
+
prompt = await new Promise((resolve, reject) => {
|
|
26
|
+
const chunks = [];
|
|
27
|
+
process.stdin.on('data', chunk => chunks.push(chunk));
|
|
28
|
+
process.stdin.on('end', () => resolve(chunks.join('')));
|
|
29
|
+
process.stdin.on('error', reject);
|
|
30
|
+
});
|
|
31
|
+
prompt = prompt.trim();
|
|
32
|
+
} catch (e) {
|
|
33
|
+
// No stdin available
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!prompt) {
|
|
38
|
+
console.log('Usage: cc-hooks prompt "prompt text"');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Try to parse as JSON if it looks like JSON
|
|
43
|
+
let cleanPrompt = prompt;
|
|
44
|
+
try {
|
|
45
|
+
const parsed = JSON.parse(prompt);
|
|
46
|
+
if (parsed && typeof parsed === 'object') {
|
|
47
|
+
cleanPrompt = parsed.prompt || parsed.text || prompt;
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// Not JSON, use as-is
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ensureDir();
|
|
54
|
+
const result = await logPrompt(cleanPrompt);
|
|
55
|
+
if (result.id) {
|
|
56
|
+
fs.writeFileSync(ENTRY_FILE, result.id);
|
|
57
|
+
}
|
|
58
|
+
console.log('OK:', result.id);
|
|
59
|
+
} else if (command === 'changes') {
|
|
60
|
+
// Parse args
|
|
61
|
+
const args = process.argv.slice(3);
|
|
62
|
+
let watchDir = '.';
|
|
63
|
+
let since = 60;
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < args.length; i++) {
|
|
66
|
+
if (args[i] === '-w' || args[i] === '--watch-dir') {
|
|
67
|
+
watchDir = args[i + 1] || '.';
|
|
68
|
+
i++;
|
|
69
|
+
} else if (args[i] === '-s' || args[i] === '--since') {
|
|
70
|
+
since = parseInt(args[i + 1]) || 60;
|
|
71
|
+
i++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const tracker = new FileTracker(watchDir);
|
|
76
|
+
const filesChanged = tracker.detectChanges(since);
|
|
77
|
+
await logChanges(filesChanged);
|
|
78
|
+
console.log('OK:', filesChanged.length, 'changes detected');
|
|
79
|
+
} else {
|
|
80
|
+
console.log('Usage:');
|
|
81
|
+
console.log(' cc-hooks prompt "prompt text" - Record a prompt');
|
|
82
|
+
console.log(' cc-hooks changes [-w <dir>] [-s <minutes>] - Detect file changes');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
main().catch(err => {
|
|
87
|
+
console.error('Error:', err.message);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
});
|
package/bin/install.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
|
|
6
|
+
const HOOKS_DIR = path.join(process.cwd(), '.claude');
|
|
7
|
+
const SETTINGS_FILE = path.join(HOOKS_DIR, 'settings.json');
|
|
8
|
+
|
|
9
|
+
function ensureDir(dir) {
|
|
10
|
+
if (!fs.existsSync(dir)) {
|
|
11
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function configureHooks() {
|
|
16
|
+
ensureDir(HOOKS_DIR);
|
|
17
|
+
|
|
18
|
+
const hooksConfig = {
|
|
19
|
+
hooks: {
|
|
20
|
+
UserPromptSubmit: [
|
|
21
|
+
{
|
|
22
|
+
matcher: "",
|
|
23
|
+
hooks: [
|
|
24
|
+
{
|
|
25
|
+
type: "command",
|
|
26
|
+
command: "cc-hooks prompt"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
PostToolBatch: [
|
|
32
|
+
{
|
|
33
|
+
matcher: "",
|
|
34
|
+
hooks: [
|
|
35
|
+
{
|
|
36
|
+
type: "command",
|
|
37
|
+
command: "cc-hooks changes"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let existingConfig = {};
|
|
46
|
+
if (fs.existsSync(SETTINGS_FILE)) {
|
|
47
|
+
try {
|
|
48
|
+
existingConfig = JSON.parse(fs.readFileSync(SETTINGS_FILE, 'utf8'));
|
|
49
|
+
} catch (e) {}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const newConfig = {
|
|
53
|
+
...existingConfig,
|
|
54
|
+
hooks: {
|
|
55
|
+
...(existingConfig.hooks || {}),
|
|
56
|
+
...hooksConfig.hooks
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
fs.writeFileSync(SETTINGS_FILE, JSON.stringify(newConfig, null, 2));
|
|
61
|
+
console.log('Claude Code hooks configured successfully!');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
configureHooks();
|