phewsh 0.6.0 → 0.7.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/bin/phewsh.js +21 -13
- package/lib/supabase.js +5 -1
- package/package.json +1 -1
package/bin/phewsh.js
CHANGED
|
@@ -79,10 +79,11 @@ function showHelp() {
|
|
|
79
79
|
console.log('');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// Non-blocking update check
|
|
82
|
+
// Non-blocking update check — resolves true if update found
|
|
83
|
+
let _updateDone = false;
|
|
83
84
|
function checkForUpdates() {
|
|
84
85
|
const pkg = require('../package.json');
|
|
85
|
-
fetch(`https://registry.npmjs.org/${pkg.name}/latest`, { signal: AbortSignal.timeout(3000) })
|
|
86
|
+
return fetch(`https://registry.npmjs.org/${pkg.name}/latest`, { signal: AbortSignal.timeout(3000) })
|
|
86
87
|
.then(r => r.json())
|
|
87
88
|
.then(data => {
|
|
88
89
|
if (data.version && data.version !== pkg.version) {
|
|
@@ -91,25 +92,32 @@ function checkForUpdates() {
|
|
|
91
92
|
const isNewer = newer[0] > current[0] || newer[1] > current[1] || newer[2] > current[2];
|
|
92
93
|
if (isNewer) {
|
|
93
94
|
console.log(g(`\n Update available: ${pkg.version} → ${data.version}`));
|
|
94
|
-
console.log(g(` npm install -g phewsh\n`));
|
|
95
|
+
console.log(g(` Run: npm install -g phewsh\n`));
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
})
|
|
98
|
-
.catch(() => {})
|
|
99
|
+
.catch(() => {})
|
|
100
|
+
.finally(() => { _updateDone = true; });
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
process.exit(0);
|
|
104
|
-
}
|
|
103
|
+
// Always check for updates (non-blocking)
|
|
104
|
+
const updatePromise = checkForUpdates();
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
process.exit(
|
|
106
|
+
function exitAfterUpdate(code = 0) {
|
|
107
|
+
// If update check already resolved, exit now
|
|
108
|
+
if (_updateDone) return process.exit(code);
|
|
109
|
+
// Otherwise wait up to 2s for it to finish
|
|
110
|
+
updatePromise.then(() => process.exit(code));
|
|
111
|
+
setTimeout(() => process.exit(code), 2000);
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
if (
|
|
112
|
-
|
|
114
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
115
|
+
showHelp();
|
|
116
|
+
exitAfterUpdate(0);
|
|
117
|
+
} else if (command === 'version' || command === '--version' || command === '-v') {
|
|
118
|
+
showVersion();
|
|
119
|
+
exitAfterUpdate(0);
|
|
120
|
+
} else if (COMMANDS[command]) {
|
|
113
121
|
COMMANDS[command]();
|
|
114
122
|
} else {
|
|
115
123
|
console.error(`\n Unknown command: ${command}\n Run 'phewsh help' for available commands.\n`);
|
package/lib/supabase.js
CHANGED
|
@@ -78,6 +78,10 @@ async function upsert(table, data, accessToken) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// SAP: fire-and-forget per-inference tracking
|
|
81
|
+
// Session ID — unique per CLI invocation, enables multi-prompt correlation
|
|
82
|
+
const { randomUUID } = require('crypto');
|
|
83
|
+
const CLI_SESSION_ID = randomUUID();
|
|
84
|
+
|
|
81
85
|
// kWh estimates by model family (conservative)
|
|
82
86
|
const MODEL_KWH = {
|
|
83
87
|
'claude-haiku': 0.00025,
|
|
@@ -110,7 +114,7 @@ function trackSap({ userId, source = 'cli', model, promptTokens, completionToken
|
|
|
110
114
|
method: 'POST',
|
|
111
115
|
body: JSON.stringify({
|
|
112
116
|
p_user_id: userId || null,
|
|
113
|
-
p_session_id:
|
|
117
|
+
p_session_id: CLI_SESSION_ID,
|
|
114
118
|
p_source: source,
|
|
115
119
|
p_model: model || null,
|
|
116
120
|
p_prompt_tokens: promptTokens || null,
|