-
Notifications
You must be signed in to change notification settings - Fork 2
fix: support fs.watch on non-recursive platforms and make better-sqlite3 optional #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,12 +33,18 @@ export function createProviderWatch( | |
| ): { close(): void } { | ||
| let watcher: FSWatcher; | ||
| try { | ||
| watcher = fsWatch(watchPath, { recursive: true }, (_event, filename) => { | ||
| if (shouldEmit && typeof filename === "string" && !shouldEmit(filename)) { | ||
| return; | ||
| } | ||
| onEvent(); | ||
| }); | ||
| const isRecursiveSupported = process.platform === "darwin" || process.platform === "win32"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Platform allowlist incorrectly disables recursive fs.watch on Linux runtimes that support it, causing potential missed nested file change events. Prompt for AI agents |
||
|
|
||
| watcher = fsWatch( | ||
| watchPath, | ||
| isRecursiveSupported ? { recursive: true } : {}, | ||
| (_event, filename) => { | ||
| if (shouldEmit && typeof filename === "string" && !shouldEmit(filename)) { | ||
| return; | ||
| } | ||
| onEvent(); | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| throw toError(error); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| /** Shared test fixtures for OpenCode provider tests. */ | ||
| import Database from "better-sqlite3"; | ||
| let Database: any; | ||
|
|
||
| try { | ||
| Database = require("better-sqlite3"); | ||
| } catch { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Catching all errors when requiring Prompt for AI agents |
||
| // optional dependency not available | ||
| } | ||
|
|
||
| export const hasSqlite = !!Database; | ||
|
|
||
| const OPENCODE_SCHEMA = ` | ||
| CREATE TABLE project ( | ||
|
|
@@ -39,20 +47,20 @@ const OPENCODE_SCHEMA = ` | |
| ); | ||
| `; | ||
|
|
||
| export function createTestDb(): Database.Database { | ||
| export function createTestDb(): any { | ||
| const db = new Database(":memory:"); | ||
| db.exec(OPENCODE_SCHEMA); | ||
| return db; | ||
| } | ||
|
|
||
| export function seedProject(db: Database.Database, id: string, worktree: string): void { | ||
| export function seedProject(db: any, id: string, worktree: string): void { | ||
| db.prepare( | ||
| "INSERT INTO project (id, worktree, time_created, time_updated) VALUES (?, ?, ?, ?)", | ||
| ).run(id, worktree, Date.now(), Date.now()); | ||
| } | ||
|
|
||
| export function seedSession( | ||
| db: Database.Database, | ||
| db: any, | ||
| id: string, | ||
| projectId: string, | ||
| opts: { parentId?: string; title?: string; directory?: string; timeUpdated?: number } = {}, | ||
|
|
@@ -73,7 +81,7 @@ export function seedSession( | |
| } | ||
|
|
||
| export function seedMessage( | ||
| db: Database.Database, | ||
| db: any, | ||
| id: string, | ||
| sessionId: string, | ||
| data: Record<string, unknown>, | ||
|
|
@@ -86,7 +94,7 @@ export function seedMessage( | |
| } | ||
|
|
||
| export function seedPart( | ||
| db: Database.Database, | ||
| db: any, | ||
| id: string, | ||
| messageId: string, | ||
| sessionId: string, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Using top-level CommonJS
require("better-sqlite3")in an ESM-distributed package can fail in ESM runtime paths and silently disable the OpenCode provider.Prompt for AI agents