@@ -56,11 +56,22 @@ export function obsidianSettingsPage(editor, window) {
|
||||
const inspect = new Adw.ActionRow({ title: 'Vault contents', subtitle: 'Read displays text files. Use the agent to create, edit, organize, or restore notes.' });
|
||||
const view = new Gtk.TextView({ editable: false, cursor_visible: true, wrap_mode: Gtk.WrapMode.WORD_CHAR, left_margin: 12, right_margin: 12, top_margin: 8, bottom_margin: 8 });
|
||||
const scroll = new Gtk.ScrolledWindow({ min_content_height: 220, max_content_height: 360, propagate_natural_height: true, has_frame: true }); scroll.set_child(view);
|
||||
const show = value => view.buffer.set_text(String(value).slice(0, 64000), -1);
|
||||
action(inspect, 'Files', async () => { const result = await run({ action: 'list' }); show(result.entries.map(e => `${e.type === 'folder' ? '[folder]' : `${e.bytes} B`} ${e.path}`).join('\n') + (result.truncated ? '\nMore entries omitted.' : '')); });
|
||||
action(inspect, 'Search', async () => { const result = await run({ action: 'search', query: input.text }); show(result.matches.map(e => `${e.path}\n${e.snippet}`).join('\n\n') || 'No matching notes.'); });
|
||||
action(inspect, 'Memory', async () => { const result = await run({ action: 'memory_search', query: input.text }); show(result.matches.map(e => `${e.path}\n${e.snippet}`).join('\n\n') || 'No matching memories.'); });
|
||||
action(inspect, 'Read', async () => { if (!input.text.toLowerCase().endsWith('.md')) throw new Error('Enter a Markdown file path, such as memory/preferences.md'); const note = await run({ action: 'read', path: input.text }); show(`${note.path}\n\n${note.content}`); });
|
||||
const show = value => view.buffer.set_text(String(value), -1);
|
||||
let continuation = null;
|
||||
const inspectPage = async args => {
|
||||
const result = await run(args);
|
||||
continuation = result.nextOffset != null ? { ...args, offset: result.nextOffset, ...(result.revision ? { revision: result.revision } : {}) } : null;
|
||||
let text;
|
||||
if (args.action === 'read') text = `${result.path} (byte ${result.offset})\n\n${result.content}`;
|
||||
else if (args.action === 'list') text = result.entries.map(e => `${e.type === 'folder' ? '[folder]' : `${e.bytes} B`} ${e.path}`).join('\n');
|
||||
else text = result.matches.map(e => `${e.path}\n${e.snippet}`).join('\n\n') || 'No matches on this page.';
|
||||
show(text + (continuation ? '\n\nMore content available — press Next page.' : '\n\nEnd of results.'));
|
||||
};
|
||||
action(inspect, 'Files', async () => inspectPage({ action: 'list' }));
|
||||
action(inspect, 'Search', async () => inspectPage({ action: 'search', query: input.text }));
|
||||
action(inspect, 'Memory', async () => inspectPage({ action: 'memory_search', query: input.text }));
|
||||
action(inspect, 'Read', async () => { if (!input.text.toLowerCase().endsWith('.md')) throw new Error('Enter a Markdown file path, such as memory/preferences.md'); await inspectPage({ action: 'read', path: input.text }); });
|
||||
action(inspect, 'Next page', async () => { if (continuation) await inspectPage(continuation); });
|
||||
memory.add(inspect); memory.add(scroll); page.add(memory);
|
||||
return page;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user