@2en/clawly-plugins 1.8.0 → 1.10.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 +45 -11
  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}`)
@@ -99,10 +118,19 @@ export function registerMemoryBrowser(api: PluginApi) {
99
118
  api.registerGatewayMethod('memory-browser.list', async ({params, respond}) => {
100
119
  try {
101
120
  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()
121
+ const scope = readString(params, 'scope') ?? 'memory'
122
+
123
+ let files: string[]
124
+ if (scope === 'root') {
125
+ const wsRoot = resolveWorkspaceRoot(api, profile)
126
+ files = await listRootMdFiles(wsRoot)
127
+ api.logger.info(`memory-browser.list (root): ${files.length} files found in ${wsRoot}`)
128
+ } else {
129
+ const dir = profile ? resolveMemoryDir(api, profile) : memoryDir
130
+ files = await collectMdFiles(dir, dir)
131
+ files.sort()
132
+ api.logger.info(`memory-browser.list: ${files.length} files found`)
133
+ }
106
134
  respond(true, {files})
107
135
  } catch (err) {
108
136
  api.logger.error(
@@ -121,7 +149,13 @@ export function registerMemoryBrowser(api: PluginApi) {
121
149
  api.registerGatewayMethod('memory-browser.get', async ({params, respond}) => {
122
150
  const relativePath = readString(params, 'path')
123
151
  const profile = readString(params, 'profile')
124
- const dir = profile ? resolveMemoryDir(api, profile) : memoryDir
152
+ const scope = readString(params, 'scope') ?? 'memory'
153
+ const dir =
154
+ scope === 'root'
155
+ ? resolveWorkspaceRoot(api, profile)
156
+ : profile
157
+ ? resolveMemoryDir(api, profile)
158
+ : memoryDir
125
159
  if (!relativePath) {
126
160
  respond(false, undefined, {
127
161
  code: 'invalid_params',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {