diff --git a/.clinerules b/.clinerules new file mode 100644 index 00000000..ae6689f0 --- /dev/null +++ b/.clinerules @@ -0,0 +1 @@ +Read DEVELOPMENT.md carefully. \ No newline at end of file diff --git a/CLAUDE.md b/DEVELOPMENT.md similarity index 86% rename from CLAUDE.md rename to DEVELOPMENT.md index 81adaafa..44fa9703 100644 --- a/CLAUDE.md +++ b/DEVELOPMENT.md @@ -25,15 +25,10 @@ - Comments: Focus on "why" not "what", especially for complex logic - Prefer const over let when variable won't be reassigned - In Lua: use camelCase for variables and functions +- Tests end with .test.ts ## Architecture Overview -### Server and Client Architecture -- **ServerSystem**: Manages server-side operations, file system, and plugin management -- **ClientSystem**: Handles client UI, editor interactions, and supports both online and offline-synced modes -- **Space**: Core abstraction for document storage, reading/writing pages and managing metadata -- **SpacePrimitives**: Storage backend interface supporting multiple implementations (disk, HTTP, S3) - ### Plugin System (Plugs) - **PlugOS**: Extension framework with System, Plug, Sandbox, and Syscalls components - **Hooks**: Extension points (commands, events, slash commands, widgets) @@ -56,6 +51,7 @@ ## Directory Structure ### Top-level Directories +- `/Library`: Standard library shipped with SilverBullet - `/cmd`: Command-line interfaces and entry points - `/common`: Shared core functionality for both server and client - `/lib`: Utility libraries and internal modules @@ -68,7 +64,6 @@ ### Key Areas - `/common/spaces`: Space implementation with different backend primitives - `/common/space_lua`: Lua scripting implementation with parsers and runtime -- `/common/template`: Template language implementation - `/lib/plugos`: Plugin system core functionality - `/plugs`: Plugs for core functionality (editor, indexing, etc) distributed with the system - `/web`: Client implementation diff --git a/plugs/core/Library/Std/Config.md b/Library/Std/Config.md similarity index 100% rename from plugs/core/Library/Std/Config.md rename to Library/Std/Config.md diff --git a/plugs/core/Library/Std/Date.md b/Library/Std/Date.md similarity index 100% rename from plugs/core/Library/Std/Date.md rename to Library/Std/Date.md diff --git a/plugs/core/Library/Std/Embed.md b/Library/Std/Embed.md similarity index 100% rename from plugs/core/Library/Std/Embed.md rename to Library/Std/Embed.md diff --git a/plugs/core/Library/Std/Lua.md b/Library/Std/Lua.md similarity index 100% rename from plugs/core/Library/Std/Lua.md rename to Library/Std/Lua.md diff --git a/plugs/core/Library/Std/Query Templates.md b/Library/Std/Query Templates.md similarity index 100% rename from plugs/core/Library/Std/Query Templates.md rename to Library/Std/Query Templates.md diff --git a/plugs/core/Library/Std/Slash.md b/Library/Std/Slash.md similarity index 100% rename from plugs/core/Library/Std/Slash.md rename to Library/Std/Slash.md diff --git a/plugs/core/Library/Std/Space Overview.md b/Library/Std/Space Overview.md similarity index 100% rename from plugs/core/Library/Std/Space Overview.md rename to Library/Std/Space Overview.md diff --git a/plugs/core/Library/Std/Table.md b/Library/Std/Table.md similarity index 100% rename from plugs/core/Library/Std/Table.md rename to Library/Std/Table.md diff --git a/plugs/core/Library/Std/Tag.md b/Library/Std/Tag.md similarity index 100% rename from plugs/core/Library/Std/Tag.md rename to Library/Std/Tag.md diff --git a/plugs/core/Library/Std/Template.md b/Library/Std/Template.md similarity index 100% rename from plugs/core/Library/Std/Template.md rename to Library/Std/Template.md diff --git a/plugs/core/Library/Std/Widget.md b/Library/Std/Widget.md similarity index 100% rename from plugs/core/Library/Std/Widget.md rename to Library/Std/Widget.md diff --git a/plugs/core/Library/Std/Widgets.md b/Library/Std/Widgets.md similarity index 100% rename from plugs/core/Library/Std/Widgets.md rename to Library/Std/Widgets.md diff --git a/build_plugs.ts b/build_plugs.ts index 889bac72..80fbc124 100644 --- a/build_plugs.ts +++ b/build_plugs.ts @@ -15,7 +15,8 @@ if (import.meta.main) { `./plugs/${name}/${name}.plug.yaml` ); - const targetDir = path.join("dist_plug_bundle", "_plug"); + const plugBundlePath = "dist_plug_bundle"; + const targetDir = path.join(plugBundlePath, "_plug"); Deno.mkdirSync(targetDir, { recursive: true }); Deno.mkdirSync("dist", { recursive: true }); diff --git a/build_web.ts b/build_web.ts index ebc13abb..96778f67 100644 --- a/build_web.ts +++ b/build_web.ts @@ -16,7 +16,12 @@ export async function bundleAll( await buildCopyBundleAssets(); let timer; if (watch) { - const watcher = Deno.watchFs(["web", "common", "dist_plug_bundle"]); + const watcher = Deno.watchFs([ + "web", + "common", + "dist_plug_bundle/_plug", + "Library", + ]); for await (const _event of watcher) { if (timer) { clearTimeout(timer); @@ -76,6 +81,11 @@ async function buildCopyBundleAssets() { await Deno.mkdir("dist_client_bundle", { recursive: true }); await Deno.mkdir("dist_plug_bundle", { recursive: true }); + // Copy Library files + await copy("Library", "dist_plug_bundle/Library", { + overwrite: true, + }); + await bundleFolder( "dist_plug_bundle", "dist/plug_asset_bundle.json", @@ -121,6 +131,7 @@ async function buildCopyBundleAssets() { await Deno.writeTextFile("dist_client_bundle/service_worker.js", swCode); await copyAssets("dist_client_bundle/.client"); + await bundleFolder("dist_client_bundle", "dist/client_asset_bundle.json"); console.log("Built!"); diff --git a/plugs/core/core.plug.yaml b/plugs/core/core.plug.yaml index de49cece..5dc67287 100644 --- a/plugs/core/core.plug.yaml +++ b/plugs/core/core.plug.yaml @@ -1,37 +1,5 @@ name: core -assets: - - "Library/Std/*" -functions: - init: - path: ./std.ts:init - env: server - events: - - system:ready - readFile: - path: ./std.ts:readFile - pageNamespace: - pattern: "^Library/Std/.+" - operation: readFile - writeFile: - path: ./std.ts:writeFile - pageNamespace: - pattern: "^Library/Std/.+" - operation: writeFile - deleteFile: - path: ./std.ts:deleteFile - pageNamespace: - pattern: "^Library/Std/.+" - operation: deleteFile - getFileMeta: - path: ./std.ts:getFileMeta - pageNamespace: - pattern: "^Library/Std/.+" - operation: getFileMeta - listFiles: - path: ./std.ts:listFiles - pageNamespace: - pattern: "^Library/Std/.+" - operation: listFiles + config: # Built-in schemas schema.tag: diff --git a/plugs/core/std.ts b/plugs/core/std.ts deleted file mode 100644 index 14a170e4..00000000 --- a/plugs/core/std.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { - asset, - codeWidget, - datastore, - editor, - mq, - system, -} from "@silverbulletmd/silverbullet/syscalls"; -import type { FileMeta } from "@silverbulletmd/silverbullet/types"; -import { sleep } from "$lib/async.ts"; - -export async function listFiles(): Promise { - return await asset.listFiles("core"); -} - -export async function readFile( - name: string, -): Promise<{ data: Uint8Array; meta: FileMeta }> { - const text = await asset.readAsset("core", name, "utf8"); - return { - data: new TextEncoder().encode(text), - meta: await asset.getFileMeta("core", name), - }; -} - -export function writeFile(): Promise { - throw new Error("Writing std files not supported"); -} - -export function deleteFile(): Promise { - throw new Error("Deleting std files not supported"); -} - -export function getFileMeta(name: string): Promise { - return asset.getFileMeta("core", name); -} - -const stdLibCacheKey = ["stdLibCache"]; - -type StdLibCache = Record; // page name -> last modified time - -/** - * Ensure indexing all Library/Std files - * @param initialSync set to true when this is triggered after the initial sync - * @returns - */ -export async function init(initialSync = false) { - // Check if in read-only mode - if (await system.getMode() === "ro") { - return; - } - - console.log("Doing stdlib init"); - - let stdLibCache: StdLibCache | undefined = await datastore.get( - stdLibCacheKey, - ); - if (!stdLibCache || initialSync) { - stdLibCache = {}; - } - // Iterate over the current file listing, check if any new files have been added, removed or modified - const newListing = await listFiles(); - let anythingChanged = false; - // First check for files that were removed - for (const cachedFile of Object.keys(stdLibCache)) { - if (!newListing.find((f) => f.name === cachedFile)) { - anythingChanged = true; - console.log(`Clearing index for removed file ${cachedFile}`); - await system.invokeFunction("index.clearDSIndex", cachedFile); - delete stdLibCache[cachedFile]; - } - } - - // Then check for new/modified files - for (const file of newListing) { - const lastModified = file.lastModified; - - // Check if file is new or modified compared to cache - if (!stdLibCache[file.name] || stdLibCache[file.name] !== lastModified) { - anythingChanged = true; - await system.invokeFunction("index.clearDSIndex", file.name); - await mq.send("indexQueue", file.name); - stdLibCache[file.name] = lastModified; - } - } - - // Save updated cache - await datastore.set(stdLibCacheKey, stdLibCache); - - if (anythingChanged) { - console.log("Waiting for index queue to be processed"); - let queueProcessed = false; - while (!queueProcessed) { - const stats = await mq.getQueueStats("indexQueue"); - if (stats.queued === 0 && stats.processing === 0) { - queueProcessed = true; - } - await sleep(100); - } - if (!initialSync) { - // If this is not a - console.log("Index queue processed, reloading system"); - await editor.reloadConfigAndCommands(); - await codeWidget.refreshAll(); - } - } -} diff --git a/web/client.ts b/web/client.ts index fb56ccfc..dcf88f22 100644 --- a/web/client.ts +++ b/web/client.ts @@ -184,8 +184,7 @@ export class Client { this.eventHook, (path) => { // isSyncCandidate // Exclude all plug space primitives paths - return !this.plugSpaceRemotePrimitives.isLikelyHandled(path) && - !path.startsWith("Library/Std/"); + return !this.plugSpaceRemotePrimitives.isLikelyHandled(path); }, ); @@ -511,7 +510,7 @@ export class Client { ), this.eventHook, // Don't trigger events for these paths, they're handled in a custom way - ["Library/Std/"], + // ["Library/Std/"], ); this.spaceKV = spaceKvPrimitives; diff --git a/web/client_system.ts b/web/client_system.ts index 77bd313b..4d5a9c3e 100644 --- a/web/client_system.ts +++ b/web/client_system.ts @@ -318,7 +318,6 @@ export class ClientSystem { // await this.client.space.fetchPageList(); this.indexOngoing = true; await this.system.invokeFunction("index.reindexSpace", []); - await this.system.invokeFunction("core.init", [true]); // initialSync = true console.info("Full space index complete."); await this.markFullSpaceIndexComplete(this.ds); this.indexOngoing = false;