opcode-pg-memory 2.2.2 → 2.2.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/cli.js CHANGED
@@ -4956,6 +4956,7 @@ import { join } from "node:path";
4956
4956
  import { homedir } from "node:os";
4957
4957
  var OPENCODE_CONFIG_DIR = join(homedir(), ".config", "opencode");
4958
4958
  var OPENCODE_COMMAND_DIR = join(OPENCODE_CONFIG_DIR, "command");
4959
+ var OPENCODE_SKILLS_DIR = join(homedir(), ".config", "opencode", "skills");
4959
4960
  var PLUGIN_NAME = "opcode-pg-memory";
4960
4961
  var REPO_URL = "https://github.com/Vbs313/opcode-pg-memory";
4961
4962
  var PG_MEMORY_INIT_COMMAND = `---
@@ -5058,12 +5059,80 @@ function createInitCommand() {
5058
5059
  console.log("Created /pg-memory-init command");
5059
5060
  return true;
5060
5061
  }
5062
+ var PG_MEMORY_SYNC_COMMAND = `---
5063
+ description: Sync OpenCode sessions from SQLite to PostgreSQL
5064
+ ---
5065
+
5066
+ # PG Memory Sync
5067
+
5068
+ Run this command to sync historical OpenCode sessions into the pg-memory database:
5069
+
5070
+ \`\`\`bash
5071
+ bunx opcode-pg-memory sync
5072
+ \`\`\`
5073
+
5074
+ This imports all historical OpenCode sessions into the pg-memory PostgreSQL database for future retrieval.
5075
+ `;
5076
+ function createSyncCommand() {
5077
+ mkdirSync(OPENCODE_COMMAND_DIR, { recursive: true });
5078
+ const syncPath = join(OPENCODE_COMMAND_DIR, "pg-memory-sync.md");
5079
+ writeFileSync(syncPath, PG_MEMORY_SYNC_COMMAND);
5080
+ console.log("Created /pg-memory-sync command");
5081
+ return true;
5082
+ }
5083
+ var PG_MEMORY_REFLECT_COMMAND = `---
5084
+ description: Reflect on current session to extract patterns and insights
5085
+ ---
5086
+
5087
+ # PG Memory Reflect
5088
+
5089
+ Summarize and reflect on the current session to extract reusable patterns, lessons, and insights.
5090
+
5091
+ ## Instructions
5092
+
5093
+ 1. Determine the current session ID
5094
+ 2. Call the \`hindsight_reflect\` MCP tool with the session ID
5095
+ 3. Present the results in a clear format: error patterns, tool usage, success patterns, recommendations
5096
+ `;
5097
+ function createReflectCommand() {
5098
+ mkdirSync(OPENCODE_COMMAND_DIR, { recursive: true });
5099
+ const reflectPath = join(OPENCODE_COMMAND_DIR, "pg-memory-reflect.md");
5100
+ writeFileSync(reflectPath, PG_MEMORY_REFLECT_COMMAND);
5101
+ console.log("Created /pg-memory-reflect command");
5102
+ return true;
5103
+ }
5104
+ var PG_MEMORY_SKILL = `# pg-memory — Long-term Memory for OpenCode
5105
+
5106
+ You have access to persistent long-term memory via the pg-memory plugin. Use it to search historical knowledge and reflect on completed work.
5107
+
5108
+ ## Available Tools
5109
+
5110
+ ### recall_memory — Search Historical Memories
5111
+ Search for relevant entities, observations, and reflections from past sessions.
5112
+ Call BEFORE starting any new task.
5113
+ - recall_memory({ query: "your task goal" })
5114
+
5115
+ ### hindsight_reflect — Summarize Session
5116
+ Extract reusable patterns and lessons.
5117
+ Call AFTER completing significant work.
5118
+ - hindsight_reflect({ trigger_type: "manual" })
5119
+
5120
+ ## Best Practice
5121
+ Always call recall_memory(query=<current task goal>) before working on a new problem.
5122
+ `;
5123
+ function createSkill() {
5124
+ mkdirSync(OPENCODE_SKILLS_DIR, { recursive: true });
5125
+ const skillPath = join(OPENCODE_SKILLS_DIR, "pg-memory.md");
5126
+ writeFileSync(skillPath, PG_MEMORY_SKILL);
5127
+ console.log("Created pg-memory skill");
5128
+ return true;
5129
+ }
5061
5130
  function printHelp() {
5062
5131
  console.log(`
5063
5132
  pg-memory - PostgreSQL-backed long-term memory for OpenCode
5064
5133
 
5065
5134
  Commands:
5066
- install Register plugin and create /pg-memory-init command
5135
+ install Register plugin and create commands
5067
5136
  sync Sync OpenCode sessions from SQLite to PostgreSQL
5068
5137
 
5069
5138
  Examples:
@@ -5101,6 +5170,9 @@ OpenCode PG Memory installer
5101
5170
  createNewConfig();
5102
5171
  }
5103
5172
  createInitCommand();
5173
+ createSyncCommand();
5174
+ createReflectCommand();
5175
+ createSkill();
5104
5176
  console.log(`
5105
5177
  Setup complete!`);
5106
5178
  console.log(`
package/dist/index.js CHANGED
@@ -20463,6 +20463,7 @@ var OpenCodePGMemory = async (ctx) => {
20463
20463
  const cacheManager = plugin.getCacheManager();
20464
20464
  const logger = createLogger("plugin");
20465
20465
  const injectedSessions = new Set;
20466
+ const injectedSystemPrompt = new Set;
20466
20467
  return {
20467
20468
  event: async (input) => {
20468
20469
  const { type, properties } = input.event;
@@ -20675,6 +20676,36 @@ var OpenCodePGMemory = async (ctx) => {
20675
20676
  console.error("[PG Memory] Error in tool.execute.after:", error);
20676
20677
  }
20677
20678
  },
20679
+ "experimental.chat.system.transform": async (input, output) => {
20680
+ try {
20681
+ const sessionId = input.sessionID || "default";
20682
+ if (injectedSystemPrompt.has(sessionId))
20683
+ return;
20684
+ injectedSystemPrompt.add(sessionId);
20685
+ output.system = output.system || [];
20686
+ output.system.push(`## PG Memory Tools Available
20687
+
20688
+ You have access to long-term memory via the pg-memory plugin. These tools help you reuse knowledge across sessions:
20689
+
20690
+ ### recall_memory — search historical memories
20691
+ Call this BEFORE starting any new task. It retrieves relevant entities, observations, and reflections from past sessions.
20692
+ - Example: recall_memory({ query: "database connection pool tuning" })
20693
+ - Best practice: always pass your current task goal as the query
20694
+
20695
+ ### hindsight_reflect — reflect on session
20696
+ Call this AFTER completing significant work to extract reusable patterns.
20697
+ - Example: hindsight_reflect({ trigger_type: "manual" })
20698
+ - Reflexions are automatically available in future sessions
20699
+
20700
+ ### When to use
20701
+ - Before diving into a new problem → recall_memory(query=<your goal>)
20702
+ - After completing a major task → hindsight_reflect()
20703
+ - When you need historical context about a specific topic → recall_memory(topic_segment_id=<id>)
20704
+ `);
20705
+ } catch (error) {
20706
+ console.error("[PG Memory] Error in system.transform:", error);
20707
+ }
20708
+ },
20678
20709
  "experimental.session.compacting": async (input, output) => {
20679
20710
  try {
20680
20711
  if (ctx.client?.tui?.showToast) {
@@ -20879,6 +20910,7 @@ function formatMemoryContext(facts) {
20879
20910
  const score = f2.relevanceScore ? ` (${(f2.relevanceScore * 100).toFixed(0)}%)` : "";
20880
20911
  lines.push(`- [${typeLabel}${tierLabel}] ${f2.content.substring(0, 200)}${score}`);
20881
20912
  }
20913
+ lines.push("", 'Tip: Use recall_memory(query="...") to search more specific memories, or /pg-memory-reflect to summarize this session.');
20882
20914
  return lines.join(`
20883
20915
  `);
20884
20916
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAoBA,UAAU,aAAa;IACrB,0BAA0B;IAC1B,MAAM,EAAE,GAAG,CAAC;IACZ,uBAAuB;IACvB,OAAO,EAAE,GAAG,CAAC;IACb,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uCAAuC;AACvC,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAE3D,UAAU,WAAW;IACnB,mDAAmD;IACnD,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;SAAE,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/F,0CAA0C;IAC1C,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,EAAE;QAAE,IAAI,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7H,iDAAiD;IACjD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM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KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpI,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,UAAU;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACpF;AAwJD,eAAO,MAAM,gBAAgB,EAAE,MAiiB9B,CAAC;AA+JF,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opcode-pg-memory",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "OpenCode plugin for persistent memory using PostgreSQL + pgvector — four-layer memory architecture with topic segmentation",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",