andy-stack_vaultkeeper-ai/Services/WorkSpaceService.ts
Andrew Beal f1e6619923 feat: add memory system for cross-session context retention
Add memories feature allowing AI to retain vault conventions, user preferences, and established workflows across conversation sessions. Include read-only mode option, validation requiring read-before-write, and settings UI with toggle controls.
Adjusted default search and snippet size values in plugin settings.
2026-04-04 20:04:41 +01:00

42 lines
No EOL
1.5 KiB
TypeScript

import type VaultkeeperAIPlugin from "main";
import { Resolve } from "./DependencyService";
import { Services } from "./Services";
import { Notice, TFile, type WorkspaceLeaf } from "obsidian";
import type { VaultService } from "./VaultService";
export class WorkSpaceService {
private readonly plugin: VaultkeeperAIPlugin = Resolve<VaultkeeperAIPlugin>(Services.VaultkeeperAIPlugin);
private readonly vaultService: VaultService = Resolve<VaultService>(Services.VaultService);
public async openNote(noteName: string) {
const file: TFile | null = this.plugin.app.metadataCache.getFirstLinkpathDest(noteName, "");
const leaf: WorkspaceLeaf = this.plugin.app.workspace.getLeaf(false);
if (file) {
await leaf.openFile(file);
} else {
new Notice(`Failed to open note: "${noteName}"`);
}
}
public async openNoteByPath(path: string) {
const file = this.plugin.app.vault.getAbstractFileByPath(path);
if (file instanceof TFile) {
const leaf: WorkspaceLeaf = this.plugin.app.workspace.getLeaf(false);
await leaf.openFile(file);
} else {
new Notice(`Failed to open note: "${path}"`);
}
}
public getActiveFile(allowAccessToPluginRoot: boolean = false): TFile | null {
const activeFile = this.plugin.app.workspace.getActiveFile();
if (!activeFile || this.vaultService.isExclusion(activeFile.path, allowAccessToPluginRoot)) {
return null;
}
return activeFile;
}
}