skilltally 0.0.0-stage → 1.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/.agents/plugins/marketplace.json +21 -0
- package/.claude-plugin/marketplace.json +18 -0
- package/.claude-plugin/plugin.json +13 -0
- package/.codex-plugin/plugin.json +39 -0
- package/CHANGELOG.md +40 -0
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/bin/cli.mjs +321 -0
- package/bin/track.mjs +331 -0
- package/gemini-extension.json +5 -0
- package/hooks/agy-fast-track.sh +28 -0
- package/hooks/claude-codex-hooks.json +18 -0
- package/hooks.json +16 -0
- package/package.json +53 -4
- package/plugin.json +17 -0
- package/skills/skilltally/SKILL.md +59 -0
- package/src/backfill/antigravity.mjs +150 -0
- package/src/backfill/claude.mjs +129 -0
- package/src/backfill/codex.mjs +200 -0
- package/src/backfill/gemini.mjs +152 -0
- package/src/backfill/index.mjs +83 -0
- package/src/core/config.mjs +33 -0
- package/src/core/debug.mjs +58 -0
- package/src/core/detect.mjs +9 -0
- package/src/core/normalize.mjs +78 -0
- package/src/core/store.mjs +99 -0
- package/src/install/antigravity.mjs +135 -0
- package/src/install/claude.mjs +116 -0
- package/src/install/codex.mjs +171 -0
- package/src/install/doctor.mjs +261 -0
- package/src/install/gemini.mjs +93 -0
- package/src/install/index.mjs +110 -0
- package/src/install/runtime.mjs +210 -0
- package/src/inventory/scan.mjs +397 -0
- package/src/report/aggregate.mjs +217 -0
- package/src/report/export.mjs +93 -0
- package/src/report/format.mjs +271 -0
- package/src/report/timeline.mjs +117 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, lstatSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { homedir, tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import zlib from 'node:zlib';
|
|
6
|
+
import { getHomeDir } from '../core/config.mjs';
|
|
7
|
+
import { readAllEvents } from '../core/store.mjs';
|
|
8
|
+
import { detectAntigravity, getAntigravityPluginTarget } from './antigravity.mjs';
|
|
9
|
+
import { detectClaude, hasClaudePluginInstalled } from './claude.mjs';
|
|
10
|
+
import { checkCodexHookTrust, detectCodex, hasCodexPluginInstalled } from './codex.mjs';
|
|
11
|
+
import { detectGemini } from './gemini.mjs';
|
|
12
|
+
import { extractHookCommandPath, getPackageRoot, isSkilltallyHandler, readJsonObject } from './runtime.mjs';
|
|
13
|
+
|
|
14
|
+
function collectSkilltallyHookCommands(hooksJsonObj) {
|
|
15
|
+
const commands = [];
|
|
16
|
+
if (!hooksJsonObj || typeof hooksJsonObj !== 'object') return commands;
|
|
17
|
+
|
|
18
|
+
// Antigravity root hooks.json style: { "<name>": { PostToolUse: [...] } }
|
|
19
|
+
for (const val of Object.values(hooksJsonObj)) {
|
|
20
|
+
if (val && typeof val === 'object' && Array.isArray(val.PostToolUse)) {
|
|
21
|
+
for (const group of val.PostToolUse) {
|
|
22
|
+
for (const h of group?.hooks || []) {
|
|
23
|
+
if (typeof h?.command === 'string') commands.push(h.command);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Claude / Codex / Gemini style: { hooks: { PostToolUse: [...], AfterTool: [...] } }
|
|
30
|
+
for (const eventName of ['PostToolUse', 'AfterTool']) {
|
|
31
|
+
if (Array.isArray(hooksJsonObj?.hooks?.[eventName])) {
|
|
32
|
+
for (const group of hooksJsonObj.hooks[eventName]) {
|
|
33
|
+
for (const h of group?.hooks || []) {
|
|
34
|
+
if (isSkilltallyHandler(h) && typeof h.command === 'string') {
|
|
35
|
+
commands.push(h.command);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return commands;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function checkCommandPathsExist(commands, baseDir) {
|
|
46
|
+
if (commands.length === 0) return null;
|
|
47
|
+
for (const cmd of commands) {
|
|
48
|
+
const rawPath = extractHookCommandPath(cmd);
|
|
49
|
+
if (!rawPath) return false;
|
|
50
|
+
const resolved = isAbsolute(rawPath) ? rawPath : resolve(baseDir, rawPath);
|
|
51
|
+
if (!existsSync(resolved)) return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function runSelfTest(pkgRoot) {
|
|
57
|
+
const trackScript = join(pkgRoot, 'bin', 'track.mjs');
|
|
58
|
+
if (!existsSync(trackScript)) {
|
|
59
|
+
return { ok: false, error: `Missing ${trackScript}` };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const tmp = mkdtempSync(join(tmpdir(), 'skilltally-doctor-'));
|
|
63
|
+
try {
|
|
64
|
+
const payload = JSON.stringify({
|
|
65
|
+
toolCall: {
|
|
66
|
+
id: 'doctor_self_test',
|
|
67
|
+
name: 'view_file',
|
|
68
|
+
args: { Path: '/Users/tester/.gemini/config/skills/self-test/SKILL.md' },
|
|
69
|
+
},
|
|
70
|
+
conversationId: 'doctor-conv',
|
|
71
|
+
cwd: '/tmp/doctor-check',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const res = spawnSync(process.execPath, [trackScript, '--host', 'antigravity'], {
|
|
75
|
+
input: payload,
|
|
76
|
+
encoding: 'utf8',
|
|
77
|
+
env: { ...process.env, SKILLTALLY_HOME: tmp },
|
|
78
|
+
});
|
|
79
|
+
if (res.status !== 0 || res.stdout !== '{}') {
|
|
80
|
+
return { ok: false, error: `Unexpected exit=${res.status}, stdout=${JSON.stringify(res.stdout)}` };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const evFile = join(tmp, 'events.jsonl');
|
|
84
|
+
if (!existsSync(evFile)) {
|
|
85
|
+
return { ok: false, error: 'Self-test did not write events.jsonl' };
|
|
86
|
+
}
|
|
87
|
+
const ev = JSON.parse(readFileSync(evFile, 'utf8').trim());
|
|
88
|
+
if (ev.skill !== 'self-test' || ev.origin !== 'hook') {
|
|
89
|
+
return { ok: false, error: 'Self-test wrote unexpected event payload' };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { ok: true };
|
|
93
|
+
} catch (err) {
|
|
94
|
+
return { ok: false, error: err.message };
|
|
95
|
+
} finally {
|
|
96
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function runDoctor({
|
|
101
|
+
homeDir = homedir(),
|
|
102
|
+
dataHome = getHomeDir(),
|
|
103
|
+
pkgRoot = getPackageRoot(),
|
|
104
|
+
} = {}) {
|
|
105
|
+
const nodeMajor = Number(process.versions.node.split('.')[0]);
|
|
106
|
+
const nodeOk = Number.isFinite(nodeMajor) && nodeMajor >= 18;
|
|
107
|
+
const zstdNative = typeof zlib.zstdDecompressSync === 'function';
|
|
108
|
+
|
|
109
|
+
// Store & events check
|
|
110
|
+
const { events, corruptLines } = readAllEvents(dataHome);
|
|
111
|
+
let hookEvents = 0;
|
|
112
|
+
let backfillEvents = 0;
|
|
113
|
+
let latestTs = null;
|
|
114
|
+
for (const ev of events) {
|
|
115
|
+
if (ev.origin === 'hook') hookEvents += 1;
|
|
116
|
+
else backfillEvents += 1;
|
|
117
|
+
if (ev.ts && (!latestTs || ev.ts > latestTs)) latestTs = ev.ts;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Host 1: Antigravity
|
|
121
|
+
const agyDetected = detectAntigravity(homeDir);
|
|
122
|
+
const agyPluginDir = getAntigravityPluginTarget(homeDir);
|
|
123
|
+
let agyPluginExists = false;
|
|
124
|
+
let agyIsSymlink = false;
|
|
125
|
+
try {
|
|
126
|
+
const st = lstatSync(agyPluginDir);
|
|
127
|
+
agyPluginExists = st.isDirectory() || st.isSymbolicLink();
|
|
128
|
+
agyIsSymlink = st.isSymbolicLink();
|
|
129
|
+
} catch {}
|
|
130
|
+
|
|
131
|
+
let agyDisabled = false;
|
|
132
|
+
if (agyPluginExists) {
|
|
133
|
+
try {
|
|
134
|
+
const cfg = readJsonObject(join(homeDir, '.gemini', 'config', 'config.json'));
|
|
135
|
+
if (cfg?.plugins?.skilltally?.enabled === false) agyDisabled = true;
|
|
136
|
+
} catch {}
|
|
137
|
+
try {
|
|
138
|
+
const manifest = readJsonObject(join(agyPluginDir, 'plugin.json'));
|
|
139
|
+
if (manifest?.disabled === true && !agyDisabled) {
|
|
140
|
+
const cfg = readJsonObject(join(homeDir, '.gemini', 'config', 'config.json'));
|
|
141
|
+
if (cfg?.plugins?.skilltally?.enabled !== true) agyDisabled = true;
|
|
142
|
+
}
|
|
143
|
+
} catch {}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let agyPluginCmds = [];
|
|
147
|
+
if (agyPluginExists && existsSync(join(agyPluginDir, 'hooks.json'))) {
|
|
148
|
+
try {
|
|
149
|
+
agyPluginCmds = collectSkilltallyHookCommands(readJsonObject(join(agyPluginDir, 'hooks.json')));
|
|
150
|
+
} catch {}
|
|
151
|
+
}
|
|
152
|
+
let agyGlobalCmds = [];
|
|
153
|
+
const agyGlobalHooksPath = join(homeDir, '.gemini', 'config', 'hooks.json');
|
|
154
|
+
if (existsSync(agyGlobalHooksPath)) {
|
|
155
|
+
try {
|
|
156
|
+
agyGlobalCmds = collectSkilltallyHookCommands(readJsonObject(agyGlobalHooksPath));
|
|
157
|
+
} catch {}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const agyPluginPathValid = checkCommandPathsExist(agyPluginCmds, agyPluginDir);
|
|
161
|
+
const agyGlobalPathValid = checkCommandPathsExist(agyGlobalCmds, dirname(agyGlobalHooksPath));
|
|
162
|
+
const agyHookPathValid =
|
|
163
|
+
agyPluginPathValid === false || agyGlobalPathValid === false
|
|
164
|
+
? false
|
|
165
|
+
: agyPluginPathValid === true || agyGlobalPathValid === true
|
|
166
|
+
? true
|
|
167
|
+
: null;
|
|
168
|
+
|
|
169
|
+
const antigravity = {
|
|
170
|
+
detected: agyDetected,
|
|
171
|
+
installed: (agyPluginExists && agyPluginCmds.length > 0) || agyGlobalCmds.length > 0,
|
|
172
|
+
mode: agyPluginExists ? (agyIsSymlink ? 'symlink' : 'plugin') : agyGlobalCmds.length > 0 ? 'global_hooks' : 'none',
|
|
173
|
+
disabled: agyDisabled,
|
|
174
|
+
duplicateHook: agyPluginCmds.length > 0 && agyGlobalCmds.length > 0,
|
|
175
|
+
hookPathValid: agyHookPathValid,
|
|
176
|
+
target: agyPluginExists ? agyPluginDir : agyGlobalHooksPath,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Host 2: Claude Code
|
|
180
|
+
const claudeDetected = detectClaude(homeDir);
|
|
181
|
+
const claudePlugin = hasClaudePluginInstalled(homeDir);
|
|
182
|
+
const claudeSettingsPath = join(homeDir, '.claude', 'settings.json');
|
|
183
|
+
let claudeCmds = [];
|
|
184
|
+
if (existsSync(claudeSettingsPath)) {
|
|
185
|
+
try {
|
|
186
|
+
claudeCmds = collectSkilltallyHookCommands(readJsonObject(claudeSettingsPath));
|
|
187
|
+
} catch {}
|
|
188
|
+
}
|
|
189
|
+
const claudeSettingsInstalled = claudeCmds.length > 0;
|
|
190
|
+
const claude = {
|
|
191
|
+
detected: claudeDetected,
|
|
192
|
+
installed: claudePlugin || claudeSettingsInstalled,
|
|
193
|
+
pluginInstalled: claudePlugin,
|
|
194
|
+
settingsInstalled: claudeSettingsInstalled,
|
|
195
|
+
duplicateHook: claudePlugin && claudeSettingsInstalled,
|
|
196
|
+
hookPathValid: checkCommandPathsExist(claudeCmds, dirname(claudeSettingsPath)),
|
|
197
|
+
target: claudeSettingsPath,
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// Host 3: Codex
|
|
201
|
+
const codexDetected = detectCodex(homeDir);
|
|
202
|
+
const codexPlugin = hasCodexPluginInstalled(homeDir);
|
|
203
|
+
const codexHooksPath = join(homeDir, '.codex', 'hooks.json');
|
|
204
|
+
let codexCmds = [];
|
|
205
|
+
if (existsSync(codexHooksPath)) {
|
|
206
|
+
try {
|
|
207
|
+
codexCmds = collectSkilltallyHookCommands(readJsonObject(codexHooksPath));
|
|
208
|
+
} catch {}
|
|
209
|
+
}
|
|
210
|
+
const codexHooksInstalled = codexCmds.length > 0;
|
|
211
|
+
const codex = {
|
|
212
|
+
detected: codexDetected,
|
|
213
|
+
installed: codexPlugin || codexHooksInstalled,
|
|
214
|
+
pluginInstalled: codexPlugin,
|
|
215
|
+
hooksJsonInstalled: codexHooksInstalled,
|
|
216
|
+
duplicateHook: codexPlugin && codexHooksInstalled,
|
|
217
|
+
hookPathValid: checkCommandPathsExist(codexCmds, dirname(codexHooksPath)),
|
|
218
|
+
trustStatus: checkCodexHookTrust(homeDir),
|
|
219
|
+
target: codexHooksPath,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// Host 4: Gemini CLI
|
|
223
|
+
const geminiDetected = detectGemini(homeDir);
|
|
224
|
+
const geminiSettingsPath = join(homeDir, '.gemini', 'settings.json');
|
|
225
|
+
let geminiCmds = [];
|
|
226
|
+
let geminiHooksDisabled = false;
|
|
227
|
+
if (existsSync(geminiSettingsPath)) {
|
|
228
|
+
try {
|
|
229
|
+
const geminiDoc = readJsonObject(geminiSettingsPath);
|
|
230
|
+
geminiCmds = collectSkilltallyHookCommands(geminiDoc);
|
|
231
|
+
geminiHooksDisabled = geminiDoc?.hooksConfig?.enabled === false;
|
|
232
|
+
} catch {}
|
|
233
|
+
}
|
|
234
|
+
const gemini = {
|
|
235
|
+
detected: geminiDetected,
|
|
236
|
+
installed: geminiCmds.length > 0,
|
|
237
|
+
hookPathValid: checkCommandPathsExist(geminiCmds, dirname(geminiSettingsPath)),
|
|
238
|
+
hooksConfigDisabled: geminiHooksDisabled,
|
|
239
|
+
target: geminiSettingsPath,
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const selfTest = runSelfTest(pkgRoot);
|
|
243
|
+
const hosts = { antigravity, claude, codex, gemini };
|
|
244
|
+
const brokenPaths = Object.values(hosts).some((h) => h.hookPathValid === false);
|
|
245
|
+
const ok = nodeOk && selfTest.ok && !brokenPaths;
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
ok,
|
|
249
|
+
node: { version: process.versions.node, ok: nodeOk, zstdNative },
|
|
250
|
+
dataHome,
|
|
251
|
+
events: {
|
|
252
|
+
total: events.length,
|
|
253
|
+
hook: hookEvents,
|
|
254
|
+
backfill: backfillEvents,
|
|
255
|
+
corruptLines,
|
|
256
|
+
latestTs,
|
|
257
|
+
},
|
|
258
|
+
hosts,
|
|
259
|
+
selfTest,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { getHomeDir } from '../core/config.mjs';
|
|
5
|
+
import {
|
|
6
|
+
backupFile,
|
|
7
|
+
getPackageRoot,
|
|
8
|
+
mergeEventHook,
|
|
9
|
+
readJsonObject,
|
|
10
|
+
removeSkilltallyHooksForEvent,
|
|
11
|
+
syncRuntime,
|
|
12
|
+
writeJsonAtomic,
|
|
13
|
+
} from './runtime.mjs';
|
|
14
|
+
|
|
15
|
+
export function detectGemini(homeDir = homedir()) {
|
|
16
|
+
return (
|
|
17
|
+
existsSync(join(homeDir, '.gemini', 'settings.json')) ||
|
|
18
|
+
existsSync(join(homeDir, '.gemini', 'skills')) ||
|
|
19
|
+
existsSync(join(homeDir, '.gemini', 'extensions'))
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function installGemini({
|
|
24
|
+
homeDir = homedir(),
|
|
25
|
+
dataHome = getHomeDir(),
|
|
26
|
+
pkgRoot = getPackageRoot(),
|
|
27
|
+
dryRun = false,
|
|
28
|
+
} = {}) {
|
|
29
|
+
const runtime = syncRuntime({ pkgRoot, dataHome, dryRun });
|
|
30
|
+
const command = `node "${runtime.target.replace(/\\/g, '/')}" --host gemini`;
|
|
31
|
+
const settingsPath = join(homeDir, '.gemini', 'settings.json');
|
|
32
|
+
const doc = readJsonObject(settingsPath);
|
|
33
|
+
|
|
34
|
+
const { nextDoc, changed, action } = mergeEventHook(doc, 'AfterTool', {
|
|
35
|
+
matcher: 'activate_skill',
|
|
36
|
+
handler: {
|
|
37
|
+
name: 'skilltally',
|
|
38
|
+
type: 'command',
|
|
39
|
+
command,
|
|
40
|
+
description: 'Track skill activations locally',
|
|
41
|
+
timeout: 5000,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
let backup = null;
|
|
46
|
+
if (changed) {
|
|
47
|
+
backup = backupFile(settingsPath, dataHome, 'gemini-settings', dryRun);
|
|
48
|
+
if (!dryRun) {
|
|
49
|
+
writeJsonAtomic(settingsPath, nextDoc, 0o600);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const hooksDisabled = doc?.hooksConfig?.enabled === false;
|
|
54
|
+
return {
|
|
55
|
+
host: 'gemini',
|
|
56
|
+
status: changed ? (action === 'added' ? 'installed' : 'updated') : 'unchanged',
|
|
57
|
+
target: settingsPath,
|
|
58
|
+
backup,
|
|
59
|
+
...(hooksDisabled
|
|
60
|
+
? { note: 'hooksConfig.enabled is false in ~/.gemini/settings.json; enable hooks to record events.' }
|
|
61
|
+
: {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function uninstallGemini({
|
|
66
|
+
homeDir = homedir(),
|
|
67
|
+
dataHome = getHomeDir(),
|
|
68
|
+
dryRun = false,
|
|
69
|
+
} = {}) {
|
|
70
|
+
const settingsPath = join(homeDir, '.gemini', 'settings.json');
|
|
71
|
+
if (!existsSync(settingsPath)) {
|
|
72
|
+
return { host: 'gemini', status: 'not_installed', target: settingsPath };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const doc = readJsonObject(settingsPath);
|
|
76
|
+
const { nextDoc, changed, removedCount } = removeSkilltallyHooksForEvent(doc, 'AfterTool');
|
|
77
|
+
if (!changed) {
|
|
78
|
+
return { host: 'gemini', status: 'not_installed', target: settingsPath };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const backup = backupFile(settingsPath, dataHome, 'gemini-settings', dryRun);
|
|
82
|
+
if (!dryRun) {
|
|
83
|
+
writeJsonAtomic(settingsPath, nextDoc, 0o600);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
host: 'gemini',
|
|
88
|
+
status: 'uninstalled',
|
|
89
|
+
removedCount,
|
|
90
|
+
target: settingsPath,
|
|
91
|
+
backup,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { existsSync, rmSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { getHomeDir } from '../core/config.mjs';
|
|
4
|
+
import { detectAntigravity, installAntigravity, uninstallAntigravity } from './antigravity.mjs';
|
|
5
|
+
import { detectClaude, installClaude, uninstallClaude } from './claude.mjs';
|
|
6
|
+
import { detectCodex, installCodex, uninstallCodex } from './codex.mjs';
|
|
7
|
+
import { detectGemini, installGemini, uninstallGemini } from './gemini.mjs';
|
|
8
|
+
import { getPackageRoot } from './runtime.mjs';
|
|
9
|
+
|
|
10
|
+
const HOSTS = {
|
|
11
|
+
antigravity: {
|
|
12
|
+
detect: detectAntigravity,
|
|
13
|
+
install: installAntigravity,
|
|
14
|
+
uninstall: uninstallAntigravity,
|
|
15
|
+
},
|
|
16
|
+
claude: {
|
|
17
|
+
detect: detectClaude,
|
|
18
|
+
install: installClaude,
|
|
19
|
+
uninstall: uninstallClaude,
|
|
20
|
+
},
|
|
21
|
+
codex: {
|
|
22
|
+
detect: detectCodex,
|
|
23
|
+
install: installCodex,
|
|
24
|
+
uninstall: uninstallCodex,
|
|
25
|
+
},
|
|
26
|
+
gemini: {
|
|
27
|
+
detect: detectGemini,
|
|
28
|
+
install: installGemini,
|
|
29
|
+
uninstall: uninstallGemini,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function runInstall({
|
|
34
|
+
homeDir = homedir(),
|
|
35
|
+
dataHome = getHomeDir(),
|
|
36
|
+
pkgRoot = getPackageRoot(),
|
|
37
|
+
host = 'all',
|
|
38
|
+
dryRun = false,
|
|
39
|
+
force = false,
|
|
40
|
+
} = {}) {
|
|
41
|
+
const normalizedHost = String(host || 'all').toLowerCase();
|
|
42
|
+
if (normalizedHost !== 'all' && !Object.prototype.hasOwnProperty.call(HOSTS, normalizedHost)) {
|
|
43
|
+
throw new Error(`Unsupported host "${host}" (expected: all, antigravity, claude, codex, gemini)`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const targets = normalizedHost === 'all' ? Object.keys(HOSTS) : [normalizedHost];
|
|
47
|
+
const results = [];
|
|
48
|
+
let exitCode = 0;
|
|
49
|
+
|
|
50
|
+
for (const h of targets) {
|
|
51
|
+
const adapter = HOSTS[h];
|
|
52
|
+
const detected = adapter.detect(homeDir);
|
|
53
|
+
if (!detected && !force) {
|
|
54
|
+
results.push({
|
|
55
|
+
host: h,
|
|
56
|
+
status: 'not_detected',
|
|
57
|
+
...(normalizedHost !== 'all'
|
|
58
|
+
? { reason: `${h} config directory not found (use --force to create it)` }
|
|
59
|
+
: {}),
|
|
60
|
+
});
|
|
61
|
+
if (normalizedHost !== 'all') exitCode = 2;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const res = adapter.install({ homeDir, dataHome, pkgRoot, dryRun, force });
|
|
66
|
+
results.push(res);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
dryRun,
|
|
71
|
+
exitCode,
|
|
72
|
+
results,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function runUninstall({
|
|
77
|
+
homeDir = homedir(),
|
|
78
|
+
dataHome = getHomeDir(),
|
|
79
|
+
host = 'all',
|
|
80
|
+
purge = false,
|
|
81
|
+
dryRun = false,
|
|
82
|
+
} = {}) {
|
|
83
|
+
const normalizedHost = String(host || 'all').toLowerCase();
|
|
84
|
+
if (normalizedHost !== 'all' && !Object.prototype.hasOwnProperty.call(HOSTS, normalizedHost)) {
|
|
85
|
+
throw new Error(`Unsupported host "${host}" (expected: all, antigravity, claude, codex, gemini)`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const targets = normalizedHost === 'all' ? Object.keys(HOSTS) : [normalizedHost];
|
|
89
|
+
const results = [];
|
|
90
|
+
|
|
91
|
+
for (const h of targets) {
|
|
92
|
+
results.push(HOSTS[h].uninstall({ homeDir, dataHome, dryRun }));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let purged = false;
|
|
96
|
+
if (purge && existsSync(dataHome)) {
|
|
97
|
+
if (!dryRun) {
|
|
98
|
+
rmSync(dataHome, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
purged = true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
dryRun,
|
|
105
|
+
purgeRequested: Boolean(purge),
|
|
106
|
+
purged,
|
|
107
|
+
dataHome,
|
|
108
|
+
results,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chmodSync,
|
|
3
|
+
copyFileSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
renameSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from 'node:fs';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
|
|
13
|
+
export function getPackageRoot() {
|
|
14
|
+
return dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getRuntimeTrackPath(dataHome) {
|
|
18
|
+
return join(dataHome, 'runtime', 'track.mjs');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function syncRuntime({ pkgRoot = getPackageRoot(), dataHome, dryRun = false }) {
|
|
22
|
+
const src = join(pkgRoot, 'bin', 'track.mjs');
|
|
23
|
+
if (!existsSync(src)) {
|
|
24
|
+
throw new Error(`Missing tracker entry at ${src}`);
|
|
25
|
+
}
|
|
26
|
+
const target = getRuntimeTrackPath(dataHome);
|
|
27
|
+
if (!dryRun) {
|
|
28
|
+
mkdirSync(dirname(target), { recursive: true, mode: 0o700 });
|
|
29
|
+
copyFileSync(src, target);
|
|
30
|
+
chmodSync(target, 0o755);
|
|
31
|
+
}
|
|
32
|
+
return { target, synced: !dryRun };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function backupFile(filePath, dataHome, label, dryRun = false) {
|
|
36
|
+
if (!existsSync(filePath)) return null;
|
|
37
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
38
|
+
const backupPath = join(dataHome, 'backups', `${label}-${stamp}.bak`);
|
|
39
|
+
if (!dryRun) {
|
|
40
|
+
mkdirSync(dirname(backupPath), { recursive: true, mode: 0o700 });
|
|
41
|
+
copyFileSync(filePath, backupPath);
|
|
42
|
+
chmodSync(backupPath, 0o600);
|
|
43
|
+
}
|
|
44
|
+
return backupPath;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function readJsonObject(filePath) {
|
|
48
|
+
if (!existsSync(filePath)) return {};
|
|
49
|
+
const raw = readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '');
|
|
50
|
+
if (!raw.trim()) return {};
|
|
51
|
+
let parsed;
|
|
52
|
+
try {
|
|
53
|
+
parsed = JSON.parse(raw);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
throw new Error(`Invalid JSON in ${filePath}: ${err.message}`);
|
|
56
|
+
}
|
|
57
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
58
|
+
throw new Error(`Expected JSON object in ${filePath}`);
|
|
59
|
+
}
|
|
60
|
+
return parsed;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function writeJsonAtomic(filePath, obj, mode = 0o600) {
|
|
64
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
65
|
+
const tmp = `${filePath}.tmp.${process.pid}`;
|
|
66
|
+
writeFileSync(tmp, JSON.stringify(obj, null, 2) + '\n', { mode });
|
|
67
|
+
chmodSync(tmp, mode);
|
|
68
|
+
renameSync(tmp, filePath);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isSkilltallyHandler(h) {
|
|
72
|
+
if (!h || typeof h !== 'object') return false;
|
|
73
|
+
if (h.statusMessage === 'skilltally' || h.name === 'skilltally') return true;
|
|
74
|
+
if (
|
|
75
|
+
typeof h.command === 'string' &&
|
|
76
|
+
h.command.includes('skilltally') &&
|
|
77
|
+
(h.command.includes('track.mjs') || h.command.includes('agy-fast-track.sh'))
|
|
78
|
+
) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function extractHookCommandPath(command) {
|
|
85
|
+
if (typeof command !== 'string') return null;
|
|
86
|
+
const match = command.match(/["']([^"']*(?:track\.mjs|agy-fast-track\.sh))["']/) ||
|
|
87
|
+
command.match(/(\S*(?:track\.mjs|agy-fast-track\.sh))/);
|
|
88
|
+
return match ? match[1] : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function handlersEqual(a, b) {
|
|
92
|
+
return (
|
|
93
|
+
a?.type === b?.type &&
|
|
94
|
+
a?.command === b?.command &&
|
|
95
|
+
Boolean(a?.async) === Boolean(b?.async) &&
|
|
96
|
+
a?.timeout === b?.timeout &&
|
|
97
|
+
a?.statusMessage === b?.statusMessage &&
|
|
98
|
+
a?.name === b?.name &&
|
|
99
|
+
a?.description === b?.description
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function mergeEventHook(doc, eventName, { matcher, handler }) {
|
|
104
|
+
const nextDoc = structuredClone(doc && typeof doc === 'object' ? doc : {});
|
|
105
|
+
const desired = { ...handler };
|
|
106
|
+
|
|
107
|
+
if (!nextDoc.hooks || typeof nextDoc.hooks !== 'object' || Array.isArray(nextDoc.hooks)) {
|
|
108
|
+
nextDoc.hooks = {};
|
|
109
|
+
}
|
|
110
|
+
const list = Array.isArray(nextDoc.hooks[eventName]) ? nextDoc.hooks[eventName] : [];
|
|
111
|
+
|
|
112
|
+
let existingCount = 0;
|
|
113
|
+
let exactMatch = false;
|
|
114
|
+
for (const group of list) {
|
|
115
|
+
if (!group || !Array.isArray(group.hooks)) continue;
|
|
116
|
+
for (const h of group.hooks) {
|
|
117
|
+
if (isSkilltallyHandler(h)) {
|
|
118
|
+
existingCount += 1;
|
|
119
|
+
if (group.matcher === matcher && handlersEqual(h, desired)) {
|
|
120
|
+
exactMatch = true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (existingCount === 1 && exactMatch) {
|
|
127
|
+
return { nextDoc, changed: false, action: 'unchanged' };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const cleaned = [];
|
|
131
|
+
for (const group of list) {
|
|
132
|
+
if (!group || typeof group !== 'object') continue;
|
|
133
|
+
const hooks = Array.isArray(group.hooks) ? group.hooks.filter((h) => !isSkilltallyHandler(h)) : [];
|
|
134
|
+
if (hooks.length > 0) {
|
|
135
|
+
cleaned.push({ ...group, hooks });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
cleaned.push({
|
|
140
|
+
matcher,
|
|
141
|
+
hooks: [desired],
|
|
142
|
+
});
|
|
143
|
+
nextDoc.hooks[eventName] = cleaned;
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
nextDoc,
|
|
147
|
+
changed: true,
|
|
148
|
+
action: existingCount > 0 ? 'updated' : 'added',
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function mergePostToolUseHook(
|
|
153
|
+
doc,
|
|
154
|
+
{ matcher, command, async = true, timeout = 5, statusMessage = 'skilltally' }
|
|
155
|
+
) {
|
|
156
|
+
return mergeEventHook(doc, 'PostToolUse', {
|
|
157
|
+
matcher,
|
|
158
|
+
handler: {
|
|
159
|
+
type: 'command',
|
|
160
|
+
command,
|
|
161
|
+
...(async ? { async: true } : {}),
|
|
162
|
+
timeout,
|
|
163
|
+
statusMessage,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function removeSkilltallyHooksForEvent(doc, eventName) {
|
|
169
|
+
const nextDoc = structuredClone(doc && typeof doc === 'object' ? doc : {});
|
|
170
|
+
const list = nextDoc?.hooks?.[eventName];
|
|
171
|
+
if (!Array.isArray(list)) {
|
|
172
|
+
return { nextDoc, changed: false, removedCount: 0 };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
let removedCount = 0;
|
|
176
|
+
const cleaned = [];
|
|
177
|
+
for (const group of list) {
|
|
178
|
+
if (!group || typeof group !== 'object') continue;
|
|
179
|
+
const hooks = Array.isArray(group.hooks) ? group.hooks : [];
|
|
180
|
+
const kept = hooks.filter((h) => {
|
|
181
|
+
if (isSkilltallyHandler(h)) {
|
|
182
|
+
removedCount += 1;
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
});
|
|
187
|
+
if (kept.length > 0) {
|
|
188
|
+
cleaned.push({ ...group, hooks: kept });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (removedCount === 0) {
|
|
193
|
+
return { nextDoc, changed: false, removedCount: 0 };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (cleaned.length > 0) {
|
|
197
|
+
nextDoc.hooks[eventName] = cleaned;
|
|
198
|
+
} else {
|
|
199
|
+
delete nextDoc.hooks[eventName];
|
|
200
|
+
if (Object.keys(nextDoc.hooks).length === 0) {
|
|
201
|
+
delete nextDoc.hooks;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return { nextDoc, changed: true, removedCount };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function removeSkilltallyHooks(doc) {
|
|
209
|
+
return removeSkilltallyHooksForEvent(doc, 'PostToolUse');
|
|
210
|
+
}
|