@2en/clawly-plugins 1.8.0 → 1.11.0

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.
Files changed (2) hide show
  1. package/gateway/memory.ts +47 -12
  2. package/package.json +1 -1
package/gateway/memory.ts CHANGED
@@ -37,21 +37,25 @@ function coercePluginConfig(api: PluginApi): Record<string, unknown> {
37
37
  return isRecord(api.pluginConfig) ? api.pluginConfig : {}
38
38
  }
39
39
 
40
- /** Resolve the memory directory path. Memory lives under workspace (agents.defaults.workspace). */
41
- function resolveMemoryDir(api: PluginApi, profile?: string): string {
40
+ /** Resolve the workspace root directory (without /memory suffix). */
41
+ function resolveWorkspaceRoot(api: PluginApi, profile?: string): string {
42
42
  const cfg = coercePluginConfig(api)
43
43
  const configPath = configString(cfg, 'memoryDir')
44
- if (configPath) return configPath
44
+ if (configPath) return path.dirname(configPath) // strip /memory if configured
45
45
 
46
46
  const baseDir =
47
47
  process.env.OPENCLAW_WORKSPACE ?? path.join(os.homedir(), '.openclaw', 'workspace')
48
- // Profile-aware: "main" or empty → default workspace, otherwise workspace-<profile>
49
48
  if (profile && profile !== 'main') {
50
49
  const parentDir = path.dirname(baseDir)
51
50
  const baseName = path.basename(baseDir)
52
- return path.join(parentDir, `${baseName}-${profile}`, 'memory')
51
+ return path.join(parentDir, `${baseName}-${profile}`)
53
52
  }
54
- return path.join(baseDir, 'memory')
53
+ return baseDir
54
+ }
55
+
56
+ /** Resolve the memory directory path. Memory lives under workspace (agents.defaults.workspace). */
57
+ function resolveMemoryDir(api: PluginApi, profile?: string): string {
58
+ return path.join(resolveWorkspaceRoot(api, profile), 'memory')
55
59
  }
56
60
 
57
61
  /** Check that a relative path is safe (no directory traversal). */
@@ -89,6 +93,21 @@ async function collectMdFiles(dir: string, baseDir: string, acc: string[] = []):
89
93
  return acc
90
94
  }
91
95
 
96
+ /** List only root-level .md files in a directory (non-recursive). */
97
+ async function listRootMdFiles(dir: string): Promise<string[]> {
98
+ let entries: fs.Dirent[]
99
+ try {
100
+ entries = await fs.readdir(dir, {withFileTypes: true})
101
+ } catch (err) {
102
+ if ((err as NodeJS.ErrnoException).code === 'ENOENT') return []
103
+ throw err
104
+ }
105
+ return entries
106
+ .filter((e) => e.isFile() && e.name.toLowerCase().endsWith('.md'))
107
+ .map((e) => e.name)
108
+ .sort()
109
+ }
110
+
92
111
  export function registerMemoryBrowser(api: PluginApi) {
93
112
  const memoryDir = resolveMemoryDir(api)
94
113
  api.logger.info(`memory-browser: memory directory: ${memoryDir}`)
@@ -98,11 +117,21 @@ export function registerMemoryBrowser(api: PluginApi) {
98
117
  // -----------------------------
99
118
  api.registerGatewayMethod('memory-browser.list', async ({params, respond}) => {
100
119
  try {
120
+ api.logger.info(`memory-browser.list params: ${JSON.stringify(params)}`)
101
121
  const profile = readString(params, 'profile')
102
- const dir = profile ? resolveMemoryDir(api, profile) : memoryDir
103
- const files = await collectMdFiles(dir, dir)
104
- api.logger.info(`memory-browser.list: ${files.length} files found`)
105
- files.sort()
122
+ const scope = readString(params, 'scope') ?? 'memory'
123
+
124
+ let files: string[]
125
+ if (scope === 'root') {
126
+ const wsRoot = resolveWorkspaceRoot(api, profile)
127
+ files = await listRootMdFiles(wsRoot)
128
+ api.logger.info(`memory-browser.list (root): ${files.length} files found in ${wsRoot}`)
129
+ } else {
130
+ const dir = profile ? resolveMemoryDir(api, profile) : memoryDir
131
+ files = await collectMdFiles(dir, dir)
132
+ files.sort()
133
+ api.logger.info(`memory-browser.list: ${files.length} files found`)
134
+ }
106
135
  respond(true, {files})
107
136
  } catch (err) {
108
137
  api.logger.error(
@@ -121,7 +150,13 @@ export function registerMemoryBrowser(api: PluginApi) {
121
150
  api.registerGatewayMethod('memory-browser.get', async ({params, respond}) => {
122
151
  const relativePath = readString(params, 'path')
123
152
  const profile = readString(params, 'profile')
124
- const dir = profile ? resolveMemoryDir(api, profile) : memoryDir
153
+ const scope = readString(params, 'scope') ?? 'memory'
154
+ const dir =
155
+ scope === 'root'
156
+ ? resolveWorkspaceRoot(api, profile)
157
+ : profile
158
+ ? resolveMemoryDir(api, profile)
159
+ : memoryDir
125
160
  if (!relativePath) {
126
161
  respond(false, undefined, {
127
162
  code: 'invalid_params',
@@ -183,5 +218,5 @@ export function registerMemoryBrowser(api: PluginApi) {
183
218
  }
184
219
  })
185
220
 
186
- api.logger.info(`memory-browser: registered (dir: ${memoryDir})`)
221
+ api.logger.info(`memory-browser: registered v1.11.0 (dir: ${memoryDir})`)
187
222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.8.0",
3
+ "version": "1.11.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {