mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: remove thinking state tracking from local launcher
This commit is contained in:
@@ -1,73 +1,7 @@
|
||||
const fs = require('fs');
|
||||
|
||||
// Disable autoupdater (never works really)
|
||||
// Disable autoupdater
|
||||
process.env.DISABLE_AUTOUPDATER = '1';
|
||||
|
||||
// Helper to write JSON messages to fd 3
|
||||
function writeMessage(message) {
|
||||
try {
|
||||
fs.writeSync(3, JSON.stringify(message) + '\n');
|
||||
} catch (err) {
|
||||
// fd 3 not available, ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Intercept fetch to track thinking state
|
||||
const originalFetch = global.fetch;
|
||||
let fetchCounter = 0;
|
||||
|
||||
global.fetch = function(...args) {
|
||||
const id = ++fetchCounter;
|
||||
const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || '';
|
||||
const method = args[1]?.method || 'GET';
|
||||
|
||||
// Parse URL for privacy
|
||||
let hostname = '';
|
||||
let path = '';
|
||||
try {
|
||||
const urlObj = new URL(url, 'http://localhost');
|
||||
hostname = urlObj.hostname;
|
||||
path = urlObj.pathname;
|
||||
} catch (e) {
|
||||
// If URL parsing fails, use defaults
|
||||
hostname = 'unknown';
|
||||
path = url;
|
||||
}
|
||||
|
||||
// Send fetch start event
|
||||
writeMessage({
|
||||
type: 'fetch-start',
|
||||
id,
|
||||
hostname,
|
||||
path,
|
||||
method,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
|
||||
// Execute the original fetch immediately
|
||||
const fetchPromise = originalFetch(...args);
|
||||
|
||||
// Attach handlers to send fetch end event
|
||||
const sendEnd = () => {
|
||||
writeMessage({
|
||||
type: 'fetch-end',
|
||||
id,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
};
|
||||
|
||||
// Send end event on both success and failure
|
||||
fetchPromise.then(sendEnd, sendEnd);
|
||||
|
||||
// Return the original promise unchanged
|
||||
return fetchPromise;
|
||||
};
|
||||
|
||||
// Preserve fetch properties
|
||||
Object.defineProperty(global.fetch, 'name', { value: 'fetch' });
|
||||
Object.defineProperty(global.fetch, 'length', { value: originalFetch.length });
|
||||
|
||||
// Import global Claude Code CLI
|
||||
const { getClaudeCliPath, runClaudeCli } = require('./claude_version_utils.cjs');
|
||||
|
||||
runClaudeCli(getClaudeCliPath());
|
||||
runClaudeCli(getClaudeCliPath());
|
||||
|
||||
Reference in New Issue
Block a user