carmoji 0.3.0 → 0.3.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/carmoji.js +13 -33
- package/package.json +1 -1
package/carmoji.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
copyFileSync, existsSync, readdirSync, unlinkSync,
|
|
23
23
|
} from 'node:fs';
|
|
24
24
|
import { spawn } from 'node:child_process';
|
|
25
|
-
import { homedir } from 'node:os';
|
|
25
|
+
import { homedir, hostname } from 'node:os';
|
|
26
26
|
import { join, dirname, basename } from 'node:path';
|
|
27
27
|
import { fileURLToPath } from 'node:url';
|
|
28
28
|
|
|
@@ -763,37 +763,14 @@ function uninstallTool(key) {
|
|
|
763
763
|
console.log(`Removed CarMoji hooks for ${tool.name} from ${path}`);
|
|
764
764
|
}
|
|
765
765
|
|
|
766
|
-
/**
|
|
766
|
+
/**
|
|
767
|
+
* Merge the CarMoji hooks into ~/.claude/settings.json, keeping a backup.
|
|
768
|
+
* Existing carmoji entries are replaced, not skipped, so switching between
|
|
769
|
+
* a repo clone (`node …/carmoji.js`) and the npm package (`npx carmoji`)
|
|
770
|
+
* always leaves the config pointing at whichever one ran the install.
|
|
771
|
+
*/
|
|
767
772
|
function installClaude() {
|
|
768
|
-
|
|
769
|
-
let settings = {};
|
|
770
|
-
if (existsSync(path)) {
|
|
771
|
-
try {
|
|
772
|
-
settings = JSON.parse(readFileSync(path, 'utf8'));
|
|
773
|
-
} catch {
|
|
774
|
-
console.error(`${path} is not valid JSON — fix it first (nothing was changed).`);
|
|
775
|
-
process.exit(1);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
if (typeof settings.hooks !== 'object' || settings.hooks === null) settings.hooks = {};
|
|
779
|
-
|
|
780
|
-
let added = 0;
|
|
781
|
-
for (const name of CLAUDE_HOOK_EVENTS) {
|
|
782
|
-
const entries = Array.isArray(settings.hooks[name]) ? settings.hooks[name]
|
|
783
|
-
: (settings.hooks[name] = []);
|
|
784
|
-
if (JSON.stringify(entries).includes('carmoji')) continue; // already ours
|
|
785
|
-
entries.push({ hooks: [{ type: 'command', command: HOOK_COMMAND, timeout: 5 }] });
|
|
786
|
-
added++;
|
|
787
|
-
}
|
|
788
|
-
if (added === 0) {
|
|
789
|
-
console.log(`CarMoji hooks already installed in ${path}`);
|
|
790
|
-
return;
|
|
791
|
-
}
|
|
792
|
-
const bak = existsSync(path) ? backupFile(path) : null;
|
|
793
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
794
|
-
writeFileSync(path, JSON.stringify(settings, null, 2) + '\n');
|
|
795
|
-
console.log(`Added CarMoji hooks to ${added} event(s) in ${path}`);
|
|
796
|
-
if (bak) console.log(`Backup saved to ${bak}`);
|
|
773
|
+
installJsonHooks('claude', TOOLS.claude);
|
|
797
774
|
console.log('New Claude Code sessions will pick them up.');
|
|
798
775
|
}
|
|
799
776
|
|
|
@@ -922,7 +899,10 @@ async function main() {
|
|
|
922
899
|
|
|
923
900
|
const event = eventFromHook(payload);
|
|
924
901
|
if (!event) break;
|
|
925
|
-
|
|
902
|
+
// host lets the phone attribute plan-window usage per machine and
|
|
903
|
+
// sum across them instead of showing whichever reported last.
|
|
904
|
+
const message = { source, session: payload.session_id,
|
|
905
|
+
host: hostname(), ...event };
|
|
926
906
|
// Claude-format transcripts power the tok/s readout; the forks share
|
|
927
907
|
// the format, and sessionTokens quietly no-ops for everyone else.
|
|
928
908
|
const tokens = sessionTokens(payload);
|
|
@@ -982,7 +962,7 @@ async function main() {
|
|
|
982
962
|
process.exit(1);
|
|
983
963
|
}
|
|
984
964
|
const [session, tokens, project] = rest;
|
|
985
|
-
const message = { source: 'test', session, ...event };
|
|
965
|
+
const message = { source: 'test', session, host: hostname(), ...event };
|
|
986
966
|
if (tokens !== undefined) message.tokens = Number(tokens);
|
|
987
967
|
if (project) message.project = project;
|
|
988
968
|
const usage = claudeUsage(true);
|