The open source coding agent.
TypeScript
Add automatic CONTEXT.md loading and improve share sync reliability
Dax Raad754cc667411c
diff --git a/js/CONTEXT.md b/js/CONTEXT.mdindex 6c95218572b..53a9fd46d92 100644--- a/js/CONTEXT.md+++ b/js/CONTEXT.md@@ -1,6 +1,7 @@# OpenCode Context## Build/Test Commands+- `bun install` - Install dependencies- `bun run index.ts` - Run the application- `bun build src/index.ts --compile --outfile ./dist/opencode` - Build executable@@ -9,6 +10,7 @@- `bun test --test-name-pattern <regex>` - Run tests matching pattern## Code Style & Conventions+- TypeScript with Bun runtime- ES modules (`"type": "module"`)- Namespace-based organization (e.g., `Tool.define`, `App.provide`)@@ -21,4 +23,5 @@- Error handling: try/catch with structured logging- File organization: group by feature in `src/` with index files for exports- Test files: co-located in `test/` directory, use Bun's built-in test runner-- Naming: camelCase for variables/functions, PascalCase for namespaces/types\ No newline at end of file+- Naming: camelCase for variables/functions, PascalCase for namespaces/types+diff --git a/js/src/session/session.ts b/js/src/session/session.tsindex d911270a799..cbe6cd89c47 100644--- a/js/src/session/session.ts+++ b/js/src/session/session.ts@@ -141,6 +141,7 @@ export namespace Session {msg,);}+ const app = await App.use();if (msgs.length === 0) {const system: Message = {id: Identifier.ascending("message"),@@ -159,6 +160,14 @@ export namespace Session {tool: {},},};+ const contextFile = Bun.file(path.join(app.root, "CONTEXT.md"));+ if (await contextFile.exists()) {+ const context = await contextFile.text();+ system.parts.push({+ type: "text",+ text: context,+ });+ }msgs.push(system);state().messages.set(sessionID, msgs);generateText({diff --git a/js/src/share/share.ts b/js/src/share/share.tsindex a9b5ed8fdf9..db204ab9792 100644--- a/js/src/share/share.ts+++ b/js/src/share/share.ts@@ -8,6 +8,7 @@ export namespace Share {const log = Log.create({ service: "share" });let queue: Promise<void> = Promise.resolve();+ const pending = new Map<string, any>();const state = App.state("share", async () => {Bus.subscribe(Storage.Event.Write, async (payload) => {@@ -17,23 +18,32 @@ export namespace Share {const session = await Session.get(sessionID);if (!session.shareID) return;+ const key = payload.properties.key;+ pending.set(key, payload.properties.content);+queue = queue- .then(() =>- fetch(`${URL}/share_sync`, {+ .then(async () => {+ const content = pending.get(key);+ if (content === undefined) return;+ pending.delete(key);++ return fetch(`${URL}/share_sync`, {method: "POST",body: JSON.stringify({sessionID: sessionID,shareID: session.shareID,- key: payload.properties.key,- content: JSON.stringify(payload.properties.content),+ key: key,+ content: JSON.stringify(content),}),- }),- )- .then((x) => {- log.info("synced", {- key: payload.properties.key,- status: x.status,});+ })+ .then((x) => {+ if (x) {+ log.info("synced", {+ key: key,+ status: x.status,+ });+ }});});});