@vibecontrols/vibe-plugin-storage-postgres 2026.509.2 → 2026.509.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -21,15 +21,8 @@
21
21
  * The schema is created on first connection (`CREATE TABLE IF NOT EXISTS
22
22
  * documents`). No manual migrations needed.
23
23
  */
24
- import { type VibePlugin, type VibePluginFactory } from "@vibecontrols/plugin-sdk/contract";
24
+ import { type VibePluginFactory } from "@vibecontrols/plugin-sdk/contract";
25
25
  import "./postgres.adapter.js";
26
26
  export { createPostgresAgentDatabase } from "./postgres.adapter.js";
27
27
  export declare const createPlugin: VibePluginFactory;
28
- /**
29
- * Static manifest export — kept for the agent's defensive plugin loader
30
- * that reads `vibePlugin` directly without invoking the factory.
31
- * Lifecycle hooks here are no-ops; real registration happens via the
32
- * factory above.
33
- */
34
- export declare const vibePlugin: VibePlugin;
35
28
  export default createPlugin;
package/dist/index.js CHANGED
@@ -23,4 +23,4 @@ See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode de
23
23
  CREATE INDEX IF NOT EXISTS idx_doc_updated_at ON documents (updated_at);
24
24
  `)}async putDoc(collection,id,value,options){let json=JSON.stringify(value),blob=encrypt(json,this.key);if(options?.keepCreatedAt)await this.pool.query(`INSERT INTO documents (collection, id, ciphertext, iv, tag) VALUES ($1, $2, $3, $4, $5)
25
25
  ON CONFLICT (collection, id) DO UPDATE SET ciphertext = EXCLUDED.ciphertext, iv = EXCLUDED.iv, tag = EXCLUDED.tag, updated_at = now()`,[collection,id,blob.ciphertext,blob.iv,blob.tag]);else await this.pool.query(`INSERT INTO documents (collection, id, ciphertext, iv, tag) VALUES ($1, $2, $3, $4, $5)
26
- ON CONFLICT (collection, id) DO UPDATE SET ciphertext = EXCLUDED.ciphertext, iv = EXCLUDED.iv, tag = EXCLUDED.tag, updated_at = now()`,[collection,id,blob.ciphertext,blob.iv,blob.tag])}async getDoc(collection,id){let row=(await this.pool.query("SELECT id, ciphertext, iv, tag, created_at, updated_at FROM documents WHERE collection = $1 AND id = $2",[collection,id])).rows[0];if(!row)return null;let json=decrypt({ciphertext:row.ciphertext,iv:row.iv,tag:row.tag},this.key);return{collection,id:row.id,value:JSON.parse(json),createdAt:row.created_at.toISOString(),updatedAt:row.updated_at.toISOString()}}async listDocs(collection){return(await this.pool.query("SELECT id, ciphertext, iv, tag, created_at, updated_at FROM documents WHERE collection = $1 ORDER BY created_at DESC",[collection])).rows.map((row)=>{let r2=row,json=decrypt({ciphertext:r2.ciphertext,iv:r2.iv,tag:r2.tag},this.key);return{collection,id:r2.id,value:JSON.parse(json),createdAt:r2.created_at.toISOString(),updatedAt:r2.updated_at.toISOString()}})}async deleteDoc(collection,id){return((await this.pool.query("DELETE FROM documents WHERE collection = $1 AND id = $2",[collection,id])).rowCount??0)>0}async close(){await this.pool.end()}getDbPath(){return this.connStr}async createTask(task){let now=nowIso(),value={...task,createdAt:now,updatedAt:now};return await this.putDoc(COLLECTIONS.tasks,task.id,value),value}async getTask(id){return(await this.getDoc(COLLECTIONS.tasks,id))?.value}async getAllTasks(){return(await this.listDocs(COLLECTIONS.tasks)).map((d)=>d.value)}async getPendingTasks(){return(await this.getAllTasks()).filter((t)=>t.status==="pending")}async updateTask(id,updates){let existing=await this.getDoc(COLLECTIONS.tasks,id);if(!existing)return;let next={...existing.value,...updates,updatedAt:nowIso()};await this.putDoc(COLLECTIONS.tasks,id,next,{keepCreatedAt:!0})}async cancelTask(id){let existing=await this.getDoc(COLLECTIONS.tasks,id);if(!existing)return!1;if(existing.value.status==="completed"||existing.value.status==="failed")return!1;let next={...existing.value,status:"failed",error:"Cancelled by user",updatedAt:nowIso()};return await this.putDoc(COLLECTIONS.tasks,id,next,{keepCreatedAt:!0}),!0}async getConfig(key){return(await this.getDoc(COLLECTIONS.config,key))?.value.value}async setConfig(key,value){await this.putDoc(COLLECTIONS.config,key,{key,value})}async deleteConfig(key){return this.deleteDoc(COLLECTIONS.config,key)}async getAllConfig(){let docs=await this.listDocs(COLLECTIONS.config),out={};for(let d of docs)out[d.value.key]=d.value.value;return out}async bulkSetConfig(entries){for(let[k,v]of Object.entries(entries))await this.setConfig(k,v)}async getConfigStatus(){let row=(await this.pool.query("SELECT COUNT(*)::int AS n, MAX(updated_at) AS last_updated FROM documents WHERE collection = $1",[COLLECTIONS.config])).rows[0];return{totalKeys:row.n,lastUpdated:row.last_updated?row.last_updated.toISOString():null}}async createGitRepository(repo){let now=nowIso(),value={...repo,createdAt:now,lastScanned:now};return await this.putDoc(COLLECTIONS.gitRepos,repo.id,value),value}async getGitRepository(id){return(await this.getDoc(COLLECTIONS.gitRepos,id))?.value}async getGitRepositoryByPath(path){return(await this.listDocs(COLLECTIONS.gitRepos)).find((d)=>d.value.path===path)?.value}async getAllGitRepositories(){return(await this.listDocs(COLLECTIONS.gitRepos)).map((d)=>d.value)}async updateGitRepository(id,updates){let existing=await this.getDoc(COLLECTIONS.gitRepos,id);if(!existing)return;let next={...existing.value,...updates,lastScanned:nowIso()};await this.putDoc(COLLECTIONS.gitRepos,id,next,{keepCreatedAt:!0})}async deleteGitRepository(id){return this.deleteDoc(COLLECTIONS.gitRepos,id)}async fixGitHierarchy(){let all=await this.getAllGitRepositories(),byPath=new Map(all.map((r)=>[r.path,r])),fixed=0;for(let repo of all){let segments=repo.path.split("/").filter(Boolean),parent;for(let i=segments.length-1;i>0;i--){let candidate="/"+segments.slice(0,i).join("/");if(byPath.has(candidate)&&candidate!==repo.path){parent=candidate;break}}if(parent!==repo.parentPath)await this.updateGitRepository(repo.id,{parentPath:parent}),fixed+=1}return{fixed}}async createBookmarkedCommand(cmd){let value={...cmd,createdAt:nowIso()};return await this.putDoc(COLLECTIONS.bookmarks,cmd.id,value),value}async getBookmarkedCommand(id){return(await this.getDoc(COLLECTIONS.bookmarks,id))?.value}async getAllBookmarkedCommands(){return(await this.listDocs(COLLECTIONS.bookmarks)).map((d)=>d.value)}async getBookmarkedCommandsByProject(projectId){return(await this.getAllBookmarkedCommands()).filter((c)=>projectId===null?c.projectId===void 0||c.projectId===null:c.projectId===projectId)}async getBookmarkedCommandsByCategory(category){return(await this.getAllBookmarkedCommands()).filter((c)=>c.category===category)}async updateBookmarkedCommand(id,updates){let existing=await this.getDoc(COLLECTIONS.bookmarks,id);if(!existing)return;let next={...existing.value,...updates};await this.putDoc(COLLECTIONS.bookmarks,id,next,{keepCreatedAt:!0})}async deleteBookmarkedCommand(id){return this.deleteDoc(COLLECTIONS.bookmarks,id)}async executeBookmarkedCommand(id){return this.getBookmarkedCommand(id)}async createNotification(notification){let value={...notification,createdAt:nowIso()};return await this.putDoc(COLLECTIONS.notifications,notification.id,value),value}async getNotification(id){return(await this.getDoc(COLLECTIONS.notifications,id))?.value}async getAllNotifications(){return(await this.listDocs(COLLECTIONS.notifications)).map((d)=>d.value)}async getNotificationsByProject(projectId){return(await this.getAllNotifications()).filter((n)=>projectId===null?n.projectId===void 0||n.projectId===null:n.projectId===projectId)}async getGlobalNotifications(){return(await this.getAllNotifications()).filter((n)=>!n.projectId)}async getUnreadNotifications(){return(await this.getAllNotifications()).filter((n)=>n.status==="unread")}async updateNotificationStatus(id,status){let existing=await this.getDoc(COLLECTIONS.notifications,id);if(!existing)return;let next={...existing.value,status};await this.putDoc(COLLECTIONS.notifications,id,next,{keepCreatedAt:!0})}async markAllNotificationsRead(){let all=await this.getAllNotifications(),count=0;for(let n of all)if(n.status==="unread")await this.updateNotificationStatus(n.id,"read"),count+=1;return count}async deleteNotification(id){return this.deleteDoc(COLLECTIONS.notifications,id)}async clearOldNotifications(olderThanDays=30){let cutoff=Date.now()-olderThanDays*86400000,all=await this.getAllNotifications(),count=0;for(let n of all)if(Date.parse(n.createdAt)<cutoff)await this.deleteDoc(COLLECTIONS.notifications,n.id),count+=1;return count}async getPluginState(pluginName,key){return(await this.getDoc(COLLECTIONS.pluginState,pluginStateId(pluginName,key)))?.value.value}async setPluginState(pluginName,key,value){await this.putDoc(COLLECTIONS.pluginState,pluginStateId(pluginName,key),{pluginName,key,value})}async deletePluginState(pluginName,key){return this.deleteDoc(COLLECTIONS.pluginState,pluginStateId(pluginName,key))}async getAllPluginState(pluginName){return(await this.listDocs(COLLECTIONS.pluginState)).filter((d)=>d.value.pluginName===pluginName).map((d)=>({key:d.value.key,value:d.value.value,updatedAt:d.updatedAt}))}async deleteAllPluginState(pluginName){return(await this.pool.query("DELETE FROM documents WHERE collection = $1 AND id LIKE $2",[COLLECTIONS.pluginState,`${pluginName}::%`])).rowCount??0}}var createPostgresAgentDatabase=async(opts)=>{let connStr,fromOptions=opts.adapterOptions?.connectionString;if(fromOptions)connStr=fromOptions;else if(opts.dataDir&&/^(postgres|postgresql):\/\//.test(opts.dataDir))connStr=opts.dataDir;else if(process.env.VIBE_POSTGRES_URL)connStr=process.env.VIBE_POSTGRES_URL;if(!connStr)throw Error("vibe-plugin-storage-postgres: connection string required. Pass via adapterOptions.connectionString (preferred), set VIBE_POSTGRES_URL, or pass a postgres:// URL as dbPath.");let key=deriveKey(opts.encryptionKey),pgModule=await Promise.resolve().then(() => (init_esm(),exports_esm)),PoolCtor=pgModule.Pool??pgModule.default?.Pool;if(!PoolCtor)throw Error("vibe-plugin-storage-postgres: failed to load 'pg' module");let pool=new PoolCtor({connectionString:connStr}),adapter=new PostgresAgentDatabase(pool,key,connStr);return await adapter.init(),adapter};registerAdapter("postgres",createPostgresAgentDatabase);var PLUGIN_NAME="storage-postgres",PLUGIN_VERSION="2026.509.2",createPlugin=(ctx)=>{let log=new BoundLogger(ctx.logger,PLUGIN_NAME),lifecycle=createLifecycleHooks({name:PLUGIN_NAME,telemetryEventName:"storage-postgres.ready",onInit:(hostServices)=>{new ProviderRegistry(hostServices).registerProvider("storage","postgres",createPostgresAgentDatabase),new TelemetryEmitter(PLUGIN_NAME,PLUGIN_VERSION,hostServices).emit("storage-postgres.registered",{adapter:"postgres"}),log.info("postgres storage adapter registered with host ProviderRegistry")}});return{name:PLUGIN_NAME,version:PLUGIN_VERSION,description:"PostgreSQL encrypted storage adapter (registers via side-effect import).",tags:["backend","adapter","provider"],capabilities:{storage:"rw",secrets:"read"},onServerStart:lifecycle.onServerStart,onServerStop:lifecycle.onServerStop}},vibePlugin={name:PLUGIN_NAME,version:PLUGIN_VERSION,description:"PostgreSQL encrypted storage adapter (registers via side-effect import).",tags:["backend","adapter","provider"],capabilities:{storage:"rw",secrets:"read"}},src_default=createPlugin;export{vibePlugin,src_default as default,createPostgresAgentDatabase,createPlugin};
26
+ ON CONFLICT (collection, id) DO UPDATE SET ciphertext = EXCLUDED.ciphertext, iv = EXCLUDED.iv, tag = EXCLUDED.tag, updated_at = now()`,[collection,id,blob.ciphertext,blob.iv,blob.tag])}async getDoc(collection,id){let row=(await this.pool.query("SELECT id, ciphertext, iv, tag, created_at, updated_at FROM documents WHERE collection = $1 AND id = $2",[collection,id])).rows[0];if(!row)return null;let json=decrypt({ciphertext:row.ciphertext,iv:row.iv,tag:row.tag},this.key);return{collection,id:row.id,value:JSON.parse(json),createdAt:row.created_at.toISOString(),updatedAt:row.updated_at.toISOString()}}async listDocs(collection){return(await this.pool.query("SELECT id, ciphertext, iv, tag, created_at, updated_at FROM documents WHERE collection = $1 ORDER BY created_at DESC",[collection])).rows.map((row)=>{let r2=row,json=decrypt({ciphertext:r2.ciphertext,iv:r2.iv,tag:r2.tag},this.key);return{collection,id:r2.id,value:JSON.parse(json),createdAt:r2.created_at.toISOString(),updatedAt:r2.updated_at.toISOString()}})}async deleteDoc(collection,id){return((await this.pool.query("DELETE FROM documents WHERE collection = $1 AND id = $2",[collection,id])).rowCount??0)>0}async close(){await this.pool.end()}getDbPath(){return this.connStr}async createTask(task){let now=nowIso(),value={...task,createdAt:now,updatedAt:now};return await this.putDoc(COLLECTIONS.tasks,task.id,value),value}async getTask(id){return(await this.getDoc(COLLECTIONS.tasks,id))?.value}async getAllTasks(){return(await this.listDocs(COLLECTIONS.tasks)).map((d)=>d.value)}async getPendingTasks(){return(await this.getAllTasks()).filter((t)=>t.status==="pending")}async updateTask(id,updates){let existing=await this.getDoc(COLLECTIONS.tasks,id);if(!existing)return;let next={...existing.value,...updates,updatedAt:nowIso()};await this.putDoc(COLLECTIONS.tasks,id,next,{keepCreatedAt:!0})}async cancelTask(id){let existing=await this.getDoc(COLLECTIONS.tasks,id);if(!existing)return!1;if(existing.value.status==="completed"||existing.value.status==="failed")return!1;let next={...existing.value,status:"failed",error:"Cancelled by user",updatedAt:nowIso()};return await this.putDoc(COLLECTIONS.tasks,id,next,{keepCreatedAt:!0}),!0}async getConfig(key){return(await this.getDoc(COLLECTIONS.config,key))?.value.value}async setConfig(key,value){await this.putDoc(COLLECTIONS.config,key,{key,value})}async deleteConfig(key){return this.deleteDoc(COLLECTIONS.config,key)}async getAllConfig(){let docs=await this.listDocs(COLLECTIONS.config),out={};for(let d of docs)out[d.value.key]=d.value.value;return out}async bulkSetConfig(entries){for(let[k,v]of Object.entries(entries))await this.setConfig(k,v)}async getConfigStatus(){let row=(await this.pool.query("SELECT COUNT(*)::int AS n, MAX(updated_at) AS last_updated FROM documents WHERE collection = $1",[COLLECTIONS.config])).rows[0];return{totalKeys:row.n,lastUpdated:row.last_updated?row.last_updated.toISOString():null}}async createGitRepository(repo){let now=nowIso(),value={...repo,createdAt:now,lastScanned:now};return await this.putDoc(COLLECTIONS.gitRepos,repo.id,value),value}async getGitRepository(id){return(await this.getDoc(COLLECTIONS.gitRepos,id))?.value}async getGitRepositoryByPath(path){return(await this.listDocs(COLLECTIONS.gitRepos)).find((d)=>d.value.path===path)?.value}async getAllGitRepositories(){return(await this.listDocs(COLLECTIONS.gitRepos)).map((d)=>d.value)}async updateGitRepository(id,updates){let existing=await this.getDoc(COLLECTIONS.gitRepos,id);if(!existing)return;let next={...existing.value,...updates,lastScanned:nowIso()};await this.putDoc(COLLECTIONS.gitRepos,id,next,{keepCreatedAt:!0})}async deleteGitRepository(id){return this.deleteDoc(COLLECTIONS.gitRepos,id)}async fixGitHierarchy(){let all=await this.getAllGitRepositories(),byPath=new Map(all.map((r)=>[r.path,r])),fixed=0;for(let repo of all){let segments=repo.path.split("/").filter(Boolean),parent;for(let i=segments.length-1;i>0;i--){let candidate="/"+segments.slice(0,i).join("/");if(byPath.has(candidate)&&candidate!==repo.path){parent=candidate;break}}if(parent!==repo.parentPath)await this.updateGitRepository(repo.id,{parentPath:parent}),fixed+=1}return{fixed}}async createBookmarkedCommand(cmd){let value={...cmd,createdAt:nowIso()};return await this.putDoc(COLLECTIONS.bookmarks,cmd.id,value),value}async getBookmarkedCommand(id){return(await this.getDoc(COLLECTIONS.bookmarks,id))?.value}async getAllBookmarkedCommands(){return(await this.listDocs(COLLECTIONS.bookmarks)).map((d)=>d.value)}async getBookmarkedCommandsByProject(projectId){return(await this.getAllBookmarkedCommands()).filter((c)=>projectId===null?c.projectId===void 0||c.projectId===null:c.projectId===projectId)}async getBookmarkedCommandsByCategory(category){return(await this.getAllBookmarkedCommands()).filter((c)=>c.category===category)}async updateBookmarkedCommand(id,updates){let existing=await this.getDoc(COLLECTIONS.bookmarks,id);if(!existing)return;let next={...existing.value,...updates};await this.putDoc(COLLECTIONS.bookmarks,id,next,{keepCreatedAt:!0})}async deleteBookmarkedCommand(id){return this.deleteDoc(COLLECTIONS.bookmarks,id)}async executeBookmarkedCommand(id){return this.getBookmarkedCommand(id)}async createNotification(notification){let value={...notification,createdAt:nowIso()};return await this.putDoc(COLLECTIONS.notifications,notification.id,value),value}async getNotification(id){return(await this.getDoc(COLLECTIONS.notifications,id))?.value}async getAllNotifications(){return(await this.listDocs(COLLECTIONS.notifications)).map((d)=>d.value)}async getNotificationsByProject(projectId){return(await this.getAllNotifications()).filter((n)=>projectId===null?n.projectId===void 0||n.projectId===null:n.projectId===projectId)}async getGlobalNotifications(){return(await this.getAllNotifications()).filter((n)=>!n.projectId)}async getUnreadNotifications(){return(await this.getAllNotifications()).filter((n)=>n.status==="unread")}async updateNotificationStatus(id,status){let existing=await this.getDoc(COLLECTIONS.notifications,id);if(!existing)return;let next={...existing.value,status};await this.putDoc(COLLECTIONS.notifications,id,next,{keepCreatedAt:!0})}async markAllNotificationsRead(){let all=await this.getAllNotifications(),count=0;for(let n of all)if(n.status==="unread")await this.updateNotificationStatus(n.id,"read"),count+=1;return count}async deleteNotification(id){return this.deleteDoc(COLLECTIONS.notifications,id)}async clearOldNotifications(olderThanDays=30){let cutoff=Date.now()-olderThanDays*86400000,all=await this.getAllNotifications(),count=0;for(let n of all)if(Date.parse(n.createdAt)<cutoff)await this.deleteDoc(COLLECTIONS.notifications,n.id),count+=1;return count}async getPluginState(pluginName,key){return(await this.getDoc(COLLECTIONS.pluginState,pluginStateId(pluginName,key)))?.value.value}async setPluginState(pluginName,key,value){await this.putDoc(COLLECTIONS.pluginState,pluginStateId(pluginName,key),{pluginName,key,value})}async deletePluginState(pluginName,key){return this.deleteDoc(COLLECTIONS.pluginState,pluginStateId(pluginName,key))}async getAllPluginState(pluginName){return(await this.listDocs(COLLECTIONS.pluginState)).filter((d)=>d.value.pluginName===pluginName).map((d)=>({key:d.value.key,value:d.value.value,updatedAt:d.updatedAt}))}async deleteAllPluginState(pluginName){return(await this.pool.query("DELETE FROM documents WHERE collection = $1 AND id LIKE $2",[COLLECTIONS.pluginState,`${pluginName}::%`])).rowCount??0}}var createPostgresAgentDatabase=async(opts)=>{let connStr,fromOptions=opts.adapterOptions?.connectionString;if(fromOptions)connStr=fromOptions;else if(opts.dataDir&&/^(postgres|postgresql):\/\//.test(opts.dataDir))connStr=opts.dataDir;else if(process.env.VIBE_POSTGRES_URL)connStr=process.env.VIBE_POSTGRES_URL;if(!connStr)throw Error("vibe-plugin-storage-postgres: connection string required. Pass via adapterOptions.connectionString (preferred), set VIBE_POSTGRES_URL, or pass a postgres:// URL as dbPath.");let key=deriveKey(opts.encryptionKey),pgModule=await Promise.resolve().then(() => (init_esm(),exports_esm)),PoolCtor=pgModule.Pool??pgModule.default?.Pool;if(!PoolCtor)throw Error("vibe-plugin-storage-postgres: failed to load 'pg' module");let pool=new PoolCtor({connectionString:connStr}),adapter=new PostgresAgentDatabase(pool,key,connStr);return await adapter.init(),adapter};registerAdapter("postgres",createPostgresAgentDatabase);var PLUGIN_NAME="storage-postgres",PLUGIN_VERSION="2026.509.4",createPlugin=(ctx)=>{let log=new BoundLogger(ctx.logger,PLUGIN_NAME),lifecycle=createLifecycleHooks({name:PLUGIN_NAME,telemetryEventName:"storage-postgres.ready",onInit:(hostServices)=>{new ProviderRegistry(hostServices).registerProvider("storage","postgres",createPostgresAgentDatabase),new TelemetryEmitter(PLUGIN_NAME,PLUGIN_VERSION,hostServices).emit("storage-postgres.registered",{adapter:"postgres"}),log.info("postgres storage adapter registered with host ProviderRegistry")}});return{name:PLUGIN_NAME,version:PLUGIN_VERSION,description:"PostgreSQL encrypted storage adapter (registers via side-effect import).",tags:["backend","adapter","provider"],capabilities:{storage:"rw",secrets:"read"},onServerStart:lifecycle.onServerStart,onServerStop:lifecycle.onServerStop}},src_default=createPlugin;export{src_default as default,createPostgresAgentDatabase,createPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibecontrols/vibe-plugin-storage-postgres",
3
- "version": "2026.509.2",
3
+ "version": "2026.509.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",