feat: add vault refresh after each response + /refresh local command
This commit is contained in:
parent
f5fc5048dd
commit
a07bc0f48c
2 changed files with 30 additions and 3 deletions
6
main.js
6
main.js
File diff suppressed because one or more lines are too long
|
|
@ -322,6 +322,18 @@ export class ChatView extends ItemView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Force Obsidian to re-index the vault file tree.
|
||||||
|
* Necessary because SMB shares don't propagate file change events,
|
||||||
|
* so Obsidian doesn't know when Hermes creates/modifies files on Helm. */
|
||||||
|
private refreshVault(): void {
|
||||||
|
try {
|
||||||
|
this.app.vault.trigger("resolved");
|
||||||
|
console.log("[Hermes] Vault refresh triggered");
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[Hermes] Vault refresh failed:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Slash command autocomplete
|
// Slash command autocomplete
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
@ -461,6 +473,17 @@ export class ChatView extends ItemView {
|
||||||
if (!rawInput) return;
|
if (!rawInput) return;
|
||||||
this.textarea.value = "";
|
this.textarea.value = "";
|
||||||
|
|
||||||
|
// Handle local-only commands (no API call)
|
||||||
|
if (rawInput === "/refresh") {
|
||||||
|
this.refreshVault();
|
||||||
|
await this.appendMessage("user", "/refresh");
|
||||||
|
await this.appendMessage(
|
||||||
|
"assistant",
|
||||||
|
"Vault refreshed. File explorer should now reflect all changes."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve slash commands to full prompts before sending
|
// Resolve slash commands to full prompts before sending
|
||||||
const userInput = this.resolveSlashCommand(rawInput);
|
const userInput = this.resolveSlashCommand(rawInput);
|
||||||
|
|
||||||
|
|
@ -552,6 +575,10 @@ export class ChatView extends ItemView {
|
||||||
|
|
||||||
// Single persistence call: messages + sessionId (if set above) in one write
|
// Single persistence call: messages + sessionId (if set above) in one write
|
||||||
await this.persistence?.saveMessages(this.chatState.messages);
|
await this.persistence?.saveMessages(this.chatState.messages);
|
||||||
|
|
||||||
|
// Force vault re-index — SMB shares don't propagate file change events,
|
||||||
|
// so Obsidian won't know about files created/modified by Hermes on Helm.
|
||||||
|
this.refreshVault();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (contentDiv) {
|
if (contentDiv) {
|
||||||
contentDiv.setText(`Error: ${error.message || "Unknown error"}`);
|
contentDiv.setText(`Error: ${error.message || "Unknown error"}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue