@2en/clawly-plugins 1.17.4 → 1.17.6

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