company-skill 3.2.0 → 3.2.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.
- package/hooks/stop-guard.js +23 -13
- package/package.json +1 -1
package/hooks/stop-guard.js
CHANGED
|
@@ -8,15 +8,7 @@ const companyDir = path.join(cwd, '.company');
|
|
|
8
8
|
const criteriaPath = path.join(companyDir, 'criteria.json');
|
|
9
9
|
const goalPath = path.join(companyDir, 'GOAL.md');
|
|
10
10
|
const cancelPath = path.join(companyDir, 'CANCEL');
|
|
11
|
-
|
|
12
|
-
// Read stdin for stop_hook_active flag
|
|
13
|
-
let stdinData = '';
|
|
14
|
-
try { stdinData = fs.readFileSync('/dev/stdin', 'utf8'); } catch (e) {}
|
|
15
|
-
let hookActive = false;
|
|
16
|
-
try { hookActive = JSON.parse(stdinData).stop_hook_active === true; } catch (e) {}
|
|
17
|
-
|
|
18
|
-
// If hook already fired once and Claude is trying to stop again, let it
|
|
19
|
-
if (hookActive) process.exit(0);
|
|
11
|
+
const lockPath = path.join(companyDir, '.stop-lock');
|
|
20
12
|
|
|
21
13
|
// No company running
|
|
22
14
|
if (!fs.existsSync(goalPath) && !fs.existsSync(criteriaPath)) process.exit(0);
|
|
@@ -24,9 +16,21 @@ if (!fs.existsSync(goalPath) && !fs.existsSync(criteriaPath)) process.exit(0);
|
|
|
24
16
|
// Cancel signal
|
|
25
17
|
if (fs.existsSync(cancelPath)) {
|
|
26
18
|
try { fs.unlinkSync(cancelPath); } catch (e) {}
|
|
19
|
+
try { fs.unlinkSync(lockPath); } catch (e) {}
|
|
27
20
|
process.exit(0);
|
|
28
21
|
}
|
|
29
22
|
|
|
23
|
+
// If lock file exists and is recent (< 60s), this is a repeat stop. Allow it.
|
|
24
|
+
if (fs.existsSync(lockPath)) {
|
|
25
|
+
try {
|
|
26
|
+
const age = Date.now() - fs.statSync(lockPath).mtimeMs;
|
|
27
|
+
if (age < 60000) {
|
|
28
|
+
fs.unlinkSync(lockPath);
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
} catch (e) {}
|
|
32
|
+
}
|
|
33
|
+
|
|
30
34
|
// Check criteria
|
|
31
35
|
if (fs.existsSync(criteriaPath)) {
|
|
32
36
|
try {
|
|
@@ -34,12 +38,17 @@ if (fs.existsSync(criteriaPath)) {
|
|
|
34
38
|
const all = data.criteria || [];
|
|
35
39
|
const failing = all.filter(c => !c.passes || !c.evidence);
|
|
36
40
|
|
|
37
|
-
if (all.length > 0 && failing.length === 0)
|
|
41
|
+
if (all.length > 0 && failing.length === 0) {
|
|
42
|
+
try { fs.unlinkSync(lockPath); } catch (e) {}
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
38
45
|
|
|
46
|
+
// Write lock, block this stop
|
|
47
|
+
fs.writeFileSync(lockPath, String(Date.now()));
|
|
39
48
|
const failList = failing.map(c => c.description).join(', ');
|
|
40
49
|
console.log(JSON.stringify({
|
|
41
50
|
decision: "block",
|
|
42
|
-
reason: "[COMPANY] " + failing.length + "/" + all.length + " criteria not met: " + failList + ". Continue THINK > EXECUTE > VERIFY.
|
|
51
|
+
reason: "[COMPANY] " + failing.length + "/" + all.length + " criteria not met: " + failList + ". Continue THINK > EXECUTE > VERIFY."
|
|
43
52
|
}));
|
|
44
53
|
process.exit(0);
|
|
45
54
|
} catch (e) {
|
|
@@ -47,8 +56,9 @@ if (fs.existsSync(criteriaPath)) {
|
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
58
|
|
|
50
|
-
// No criteria but goal exists
|
|
59
|
+
// No criteria but goal exists — block once
|
|
60
|
+
fs.writeFileSync(lockPath, String(Date.now()));
|
|
51
61
|
console.log(JSON.stringify({
|
|
52
62
|
decision: "block",
|
|
53
|
-
reason: "[COMPANY] Goal not achieved.
|
|
63
|
+
reason: "[COMPANY] Goal not achieved. Create criteria.json and start THINK > EXECUTE > VERIFY."
|
|
54
64
|
}));
|