feat: hint AI to use filesystem for local peer file reads
When read_peer_file targets a local peer (same hostname), prepend a hint with the direct filesystem path. Still executes the relay as fallback — AI learns the shortcut without being blocked. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1234,6 +1234,15 @@ Your message mode is "${messageMode}".
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if peer is local — hint AI to use filesystem directly
|
||||||
|
const resolvedPeer = peers.find(p => p.pubkey === targetPubkey);
|
||||||
|
const isLocal = resolvedPeer?.hostname && resolvedPeer.hostname === require("os").hostname();
|
||||||
|
let localHint = "";
|
||||||
|
if (isLocal && resolvedPeer?.cwd) {
|
||||||
|
const directPath = require("path").resolve(resolvedPeer.cwd, filePath);
|
||||||
|
localHint = `\n\n> **Hint:** This peer is LOCAL (same machine). Next time, read directly: \`${directPath}\` — faster, no size limit.\n\n`;
|
||||||
|
}
|
||||||
|
|
||||||
const result = await client.requestFile(targetPubkey, filePath);
|
const result = await client.requestFile(targetPubkey, filePath);
|
||||||
if (result.error) return text(`read_peer_file: ${result.error}`, true);
|
if (result.error) return text(`read_peer_file: ${result.error}`, true);
|
||||||
if (!result.content) return text("read_peer_file: empty response from peer", true);
|
if (!result.content) return text("read_peer_file: empty response from peer", true);
|
||||||
@@ -1241,7 +1250,7 @@ Your message mode is "${messageMode}".
|
|||||||
// Decode base64
|
// Decode base64
|
||||||
try {
|
try {
|
||||||
const decoded = Buffer.from(result.content, "base64").toString("utf-8");
|
const decoded = Buffer.from(result.content, "base64").toString("utf-8");
|
||||||
return text(decoded);
|
return text(localHint + decoded);
|
||||||
} catch {
|
} catch {
|
||||||
return text("read_peer_file: failed to decode file content (binary file?)", true);
|
return text("read_peer_file: failed to decode file content (binary file?)", true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user