@2en/clawly-plugins 1.17.4 → 1.17.5

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 +30 -11
  2. package/package.json +1 -1
package/gateway/memory.ts CHANGED
@@ -44,39 +44,57 @@ function resolveStateDir(api: PluginApi): string {
44
44
  return api.runtime.state?.resolveStateDir?.(process.env) ?? process.env.OPENCLAW_STATE_DIR ?? ''
45
45
  }
46
46
 
47
- /** Read the default agent's workspace path from openclaw.json (cached). */
48
- let _cachedAgentWorkspace: string | null | undefined
49
- function readAgentWorkspace(api: PluginApi): string | null {
50
- if (_cachedAgentWorkspace !== undefined) return _cachedAgentWorkspace
47
+ /** Read agents list from openclaw.json (cached). */
48
+ let _cachedAgentsList: Array<{id?: string; default?: boolean; workspace?: string}> | null | undefined
49
+ function readAgentsList(api: PluginApi): Array<{id?: string; default?: boolean; workspace?: string}> | null {
50
+ if (_cachedAgentsList !== undefined) return _cachedAgentsList
51
51
  try {
52
52
  const stateDir = resolveStateDir(api)
53
53
  if (!stateDir) {
54
- _cachedAgentWorkspace = null
54
+ _cachedAgentsList = null
55
55
  return null
56
56
  }
57
57
  const raw = fsSync.readFileSync(path.join(stateDir, 'openclaw.json'), 'utf-8')
58
58
  const config = JSON.parse(raw)
59
59
  const agents = config?.agents?.list
60
60
  if (!Array.isArray(agents)) {
61
- _cachedAgentWorkspace = null
61
+ _cachedAgentsList = null
62
62
  return null
63
63
  }
64
- const defaultAgent = agents.find((a: any) => a.default) ?? agents[0]
65
- const ws = typeof defaultAgent?.workspace === 'string' ? defaultAgent.workspace : null
66
- _cachedAgentWorkspace = ws
67
- return ws
64
+ _cachedAgentsList = agents
65
+ return agents
68
66
  } catch {
69
- _cachedAgentWorkspace = null
67
+ _cachedAgentsList = null
70
68
  return null
71
69
  }
72
70
  }
73
71
 
72
+ /** Read workspace path for a specific agent (by id) or the default agent. */
73
+ function readAgentWorkspace(api: PluginApi, agentId?: string): string | null {
74
+ const agents = readAgentsList(api)
75
+ if (!agents) return null
76
+ let agent: (typeof agents)[number] | undefined
77
+ if (agentId) {
78
+ agent = agents.find((a) => a.id === agentId)
79
+ }
80
+ if (!agent) {
81
+ agent = agents.find((a) => a.default) ?? agents[0]
82
+ }
83
+ return typeof agent?.workspace === 'string' ? agent.workspace : null
84
+ }
85
+
74
86
  /** Resolve the workspace root directory (without /memory suffix). */
75
87
  function resolveWorkspaceRoot(api: PluginApi, profile?: string): string {
76
88
  const cfg = coercePluginConfig(api)
77
89
  const configPath = configString(cfg, 'memoryDir')
78
90
  if (configPath) return path.dirname(configPath) // strip /memory if configured
79
91
 
92
+ // If profile is an agent id, look up that agent's workspace directly
93
+ if (profile && profile !== 'main') {
94
+ const agentWs = readAgentWorkspace(api, profile)
95
+ if (agentWs) return agentWs
96
+ }
97
+
80
98
  const stateDir = resolveStateDir(api)
81
99
  const baseDir =
82
100
  process.env.OPENCLAW_WORKSPACE ??
@@ -85,6 +103,7 @@ function resolveWorkspaceRoot(api: PluginApi, profile?: string): string {
85
103
  ? path.join(stateDir, 'workspace')
86
104
  : path.join(os.homedir(), '.openclaw', 'workspace'))
87
105
  if (profile && profile !== 'main') {
106
+ // Fallback: append profile suffix when agent not found in config
88
107
  const parentDir = path.dirname(baseDir)
89
108
  const baseName = path.basename(baseDir)
90
109
  return path.join(parentDir, `${baseName}-${profile}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.17.4",
3
+ "version": "1.17.5",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {