@swarmclawai/swarmclaw 1.2.6 → 1.2.9
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/README.md +54 -23
- package/next.config.ts +1 -0
- package/package.json +4 -3
- package/scripts/easy-setup.mjs +1 -1
- package/scripts/postinstall.mjs +1 -1
- package/skills/swarmclaw.md +115 -0
- package/skills/tools/browser.md +131 -0
- package/skills/tools/execute.md +98 -0
- package/skills/tools/files.md +98 -0
- package/skills/tools/memory.md +104 -0
- package/skills/tools/platform.md +144 -0
- package/skills/tools/skills.md +83 -0
- package/src/app/agents/[id]/page.tsx +1 -18
- package/src/app/api/agents/thread-route.test.ts +0 -1
- package/src/app/api/approvals/route.test.ts +6 -22
- package/src/app/api/chats/[id]/messages/route.ts +23 -19
- package/src/app/api/chats/messages-route.test.ts +105 -51
- package/src/app/api/connectors/route.ts +2 -2
- package/src/app/api/mcp-servers/[id]/test/route.ts +3 -2
- package/src/app/api/openclaw/deploy/route.ts +2 -0
- package/src/app/api/portability/export/route.ts +8 -0
- package/src/app/api/portability/import/route.test.ts +80 -0
- package/src/app/api/portability/import/route.ts +28 -0
- package/src/app/api/settings/route.ts +0 -2
- package/src/app/api/setup/doctor/route.ts +4 -4
- package/src/app/api/wallets/[id]/route.ts +15 -157
- package/src/app/api/wallets/generate/route.ts +22 -0
- package/src/app/api/wallets/route.test.ts +147 -0
- package/src/app/api/wallets/route.ts +13 -95
- package/src/app/autonomy/page.tsx +2 -57
- package/src/app/protocols/page.tsx +2 -21
- package/src/app/settings/page.tsx +0 -9
- package/src/app/wallets/page.tsx +105 -5
- package/src/cli/index.js +21 -33
- package/src/cli/spec.js +19 -30
- package/src/components/agents/agent-chat-list.tsx +23 -1
- package/src/components/agents/agent-sheet.tsx +2 -40
- package/src/components/agents/inspector-panel.tsx +165 -131
- package/src/components/chat/chat-area.tsx +38 -9
- package/src/components/chat/chat-card.tsx +0 -31
- package/src/components/chat/message-bubble.tsx +1 -108
- package/src/components/chat/message-list.tsx +33 -19
- package/src/components/connectors/connector-sheet.tsx +25 -1
- package/src/components/gateways/gateway-sheet.tsx +5 -2
- package/src/components/layout/sidebar-rail.tsx +6 -10
- package/src/components/projects/project-detail.tsx +3 -35
- package/src/components/projects/tabs/overview-tab.tsx +3 -59
- package/src/components/projects/tabs/work-tab.tsx +7 -77
- package/src/components/protocols/structured-session-launcher.tsx +1 -22
- package/src/components/shared/connector-platform-icon.tsx +1 -0
- package/src/components/tasks/task-card.tsx +4 -34
- package/src/components/tasks/task-sheet.tsx +6 -36
- package/src/components/wallets/wallet-list.tsx +150 -0
- package/src/lib/agent-execute-defaults.test.ts +24 -0
- package/src/lib/agent-execute-defaults.ts +62 -0
- package/src/lib/app/navigation.test.ts +0 -13
- package/src/lib/app/navigation.ts +2 -7
- package/src/lib/app/view-constants.ts +14 -19
- package/src/lib/chat/queued-message-queue.test.ts +134 -1
- package/src/lib/chat/queued-message-queue.ts +77 -2
- package/src/lib/server/agents/agent-service.ts +5 -0
- package/src/lib/server/agents/agent-thread-session.ts +0 -1
- package/src/lib/server/agents/delegation-advisory.test.ts +0 -1
- package/src/lib/server/agents/delegation-jobs.test.ts +0 -69
- package/src/lib/server/agents/delegation-jobs.ts +0 -25
- package/src/lib/server/agents/main-agent-loop.ts +1 -49
- package/src/lib/server/agents/subagent-runtime.ts +0 -1
- package/src/lib/server/approval-match.ts +0 -85
- package/src/lib/server/approvals.test.ts +6 -6
- package/src/lib/server/approvals.ts +0 -6
- package/src/lib/server/autonomy/supervisor-reflection.test.ts +0 -1
- package/src/lib/server/builtin-extensions.ts +1 -2
- package/src/lib/server/capability-router.test.ts +0 -2
- package/src/lib/server/chat-execution/chat-execution-advanced.test.ts +1 -1
- package/src/lib/server/chat-execution/chat-execution-tool-events.test.ts +15 -14
- package/src/lib/server/chat-execution/chat-execution-types.ts +0 -2
- package/src/lib/server/chat-execution/chat-execution-utils.ts +2 -4
- package/src/lib/server/chat-execution/chat-streaming-utils.ts +2 -30
- package/src/lib/server/chat-execution/chat-turn-finalization.ts +1 -36
- package/src/lib/server/chat-execution/chat-turn-preparation.ts +81 -64
- package/src/lib/server/chat-execution/chat-turn-stream-execution.ts +4 -0
- package/src/lib/server/chat-execution/continuation-evaluator.ts +8 -0
- package/src/lib/server/chat-execution/iteration-event-handler.ts +0 -24
- package/src/lib/server/chat-execution/memory-mutation-tools.ts +1 -1
- package/src/lib/server/chat-execution/message-classifier.test.ts +0 -45
- package/src/lib/server/chat-execution/message-classifier.ts +11 -16
- package/src/lib/server/chat-execution/prompt-builder.test.ts +27 -0
- package/src/lib/server/chat-execution/prompt-builder.ts +14 -31
- package/src/lib/server/chat-execution/prompt-mode.test.ts +24 -0
- package/src/lib/server/chat-execution/prompt-mode.ts +5 -1
- package/src/lib/server/chat-execution/prompt-sections.ts +0 -1
- package/src/lib/server/chat-execution/situational-awareness.test.ts +2 -73
- package/src/lib/server/chat-execution/situational-awareness.ts +4 -38
- package/src/lib/server/chat-execution/stream-agent-chat.test.ts +13 -126
- package/src/lib/server/chat-execution/stream-agent-chat.ts +46 -21
- package/src/lib/server/chat-execution/stream-continuation.test.ts +4 -52
- package/src/lib/server/chat-execution/stream-continuation.ts +6 -48
- package/src/lib/server/chatrooms/chatroom-routing.test.ts +4 -0
- package/src/lib/server/chatrooms/session-mailbox.ts +0 -10
- package/src/lib/server/chats/chat-session-service.ts +3 -5
- package/src/lib/server/connectors/connector-inbound.ts +0 -1
- package/src/lib/server/connectors/connector-lifecycle.ts +19 -3
- package/src/lib/server/connectors/connector-service.ts +39 -9
- package/src/lib/server/connectors/discord.ts +2 -2
- package/src/lib/server/connectors/matrix.ts +3 -2
- package/src/lib/server/connectors/signal.ts +5 -4
- package/src/lib/server/connectors/slack.ts +10 -9
- package/src/lib/server/connectors/swarmdock-bidding.ts +74 -0
- package/src/lib/server/connectors/swarmdock-payloads.test.ts +85 -0
- package/src/lib/server/connectors/swarmdock-secret.test.ts +128 -0
- package/src/lib/server/connectors/swarmdock-secret.ts +152 -0
- package/src/lib/server/connectors/swarmdock-tasks.ts +119 -0
- package/src/lib/server/connectors/swarmdock.ts +255 -0
- package/src/lib/server/connectors/teams.ts +3 -2
- package/src/lib/server/connectors/telegram.ts +4 -4
- package/src/lib/server/connectors/whatsapp.ts +2 -2
- package/src/lib/server/daemon/controller.ts +7 -0
- package/src/lib/server/execution-brief.test.ts +2 -25
- package/src/lib/server/execution-brief.ts +12 -35
- package/src/lib/server/execution-engine/task-attempt.ts +0 -1
- package/src/lib/server/gateways/gateway-profile-service.ts +19 -1
- package/src/lib/server/messages/message-repository.test.ts +70 -0
- package/src/lib/server/messages/message-repository.ts +11 -6
- package/src/lib/server/openclaw/deploy.ts +32 -2
- package/src/lib/server/persistence/storage-context.ts +0 -5
- package/src/lib/server/plugins-advanced.test.ts +1 -2
- package/src/lib/server/portability/export.ts +109 -0
- package/src/lib/server/portability/import.ts +159 -0
- package/src/lib/server/protocols/protocol-normalization.ts +0 -4
- package/src/lib/server/protocols/protocol-queries.ts +0 -6
- package/src/lib/server/protocols/protocol-run-lifecycle.ts +4 -32
- package/src/lib/server/protocols/protocol-service.ts +0 -1
- package/src/lib/server/protocols/protocol-step-helpers.ts +0 -4
- package/src/lib/server/protocols/protocol-step-processors.ts +0 -6
- package/src/lib/server/protocols/protocol-swarm.ts +0 -2
- package/src/lib/server/protocols/protocol-types.ts +0 -2
- package/src/lib/server/provider-health.ts +1 -10
- package/src/lib/server/runtime/daemon-state/core.ts +0 -9
- package/src/lib/server/runtime/daemon-state.test.ts +0 -35
- package/src/lib/server/runtime/heartbeat-service.ts +3 -23
- package/src/lib/server/runtime/process-manager.ts +13 -9
- package/src/lib/server/runtime/queue/core.ts +11 -33
- package/src/lib/server/runtime/runtime-storage-write-paths.test.ts +6 -6
- package/src/lib/server/runtime/scheduler.ts +0 -13
- package/src/lib/server/runtime/session-run-manager/drain.ts +0 -24
- package/src/lib/server/runtime/session-run-manager/enqueue.ts +0 -1
- package/src/lib/server/runtime/session-run-manager/queries.ts +15 -1
- package/src/lib/server/runtime/session-run-manager/recovery.ts +0 -1
- package/src/lib/server/runtime/session-run-manager.test.ts +58 -28
- package/src/lib/server/sandbox/session-runtime.test.ts +18 -1
- package/src/lib/server/sandbox/session-runtime.ts +40 -28
- package/src/lib/server/session-tools/autonomy-tools.test.ts +7 -9
- package/src/lib/server/session-tools/context.ts +1 -1
- package/src/lib/server/session-tools/credential-env.ts +109 -0
- package/src/lib/server/session-tools/crud.ts +3 -17
- package/src/lib/server/session-tools/delegate.ts +0 -4
- package/src/lib/server/session-tools/edit_file.ts +3 -2
- package/src/lib/server/session-tools/execute.test.ts +58 -0
- package/src/lib/server/session-tools/execute.ts +334 -0
- package/src/lib/server/session-tools/files-tool.ts +635 -0
- package/src/lib/server/session-tools/index.ts +14 -8
- package/src/lib/server/session-tools/memory-tool.ts +242 -0
- package/src/lib/server/session-tools/memory.ts +1 -1
- package/src/lib/server/session-tools/openclaw-nodes.ts +3 -2
- package/src/lib/server/session-tools/openclaw-workspace.ts +3 -2
- package/src/lib/server/session-tools/platform-tool.ts +617 -0
- package/src/lib/server/session-tools/session-info.ts +3 -2
- package/src/lib/server/session-tools/session-tools-wiring.test.ts +3 -4
- package/src/lib/server/session-tools/shell.ts +7 -122
- package/src/lib/server/session-tools/skills-tool.ts +396 -0
- package/src/lib/server/session-tools/team-context.ts +0 -3
- package/src/lib/server/session-tools/web.ts +2 -2
- package/src/lib/server/storage-normalization.ts +10 -0
- package/src/lib/server/storage.ts +18 -45
- package/src/lib/server/tasks/task-checkout.ts +59 -0
- package/src/lib/server/tasks/task-lifecycle.ts +2 -0
- package/src/lib/server/tasks/task-route-service.ts +4 -26
- package/src/lib/server/tasks/task-service.ts +0 -7
- package/src/lib/server/tool-aliases.ts +2 -2
- package/src/lib/server/tool-capability-policy-advanced.test.ts +13 -6
- package/src/lib/server/tool-capability-policy.test.ts +2 -1
- package/src/lib/server/tool-capability-policy.ts +60 -35
- package/src/lib/server/tool-planning.ts +11 -12
- package/src/lib/server/universal-tool-access.ts +0 -1
- package/src/lib/server/wallets/wallet-crypto.ts +33 -0
- package/src/lib/server/wallets/wallet-repository.ts +24 -0
- package/src/lib/server/wallets/wallet-service.ts +119 -0
- package/src/lib/server/working-state/extraction.ts +8 -42
- package/src/lib/server/working-state/normalization.ts +10 -103
- package/src/lib/server/working-state/service.ts +12 -21
- package/src/lib/setup-defaults.ts +5 -0
- package/src/lib/strip-internal-metadata.test.ts +1 -1
- package/src/lib/strip-internal-metadata.ts +1 -1
- package/src/lib/tool-definitions.ts +1 -1
- package/src/lib/validation/schemas.test.ts +16 -0
- package/src/lib/validation/schemas.ts +49 -2
- package/src/stores/slices/data-slice.ts +5 -1
- package/src/stores/slices/ui-slice.ts +0 -4
- package/src/stores/use-chat-store.test.ts +231 -0
- package/src/stores/use-chat-store.ts +62 -13
- package/src/types/agent.ts +264 -0
- package/src/types/app-settings.ts +173 -0
- package/src/types/approval.ts +25 -0
- package/src/types/connector.ts +188 -0
- package/src/types/extension.ts +386 -0
- package/src/types/index.ts +16 -3555
- package/src/types/message.ts +56 -0
- package/src/types/misc.ts +737 -0
- package/src/types/protocol.ts +420 -0
- package/src/types/provider.ts +52 -0
- package/src/types/run.ts +180 -0
- package/src/types/schedule.ts +59 -0
- package/src/types/session.ts +215 -0
- package/src/types/skill.ts +157 -0
- package/src/types/swarmdock.ts +29 -0
- package/src/types/task.ts +144 -0
- package/src/types/working-state.ts +204 -0
- package/src/views/settings/section-heartbeat.tsx +2 -2
- package/src/views/settings/section-runtime-loop.tsx +0 -14
- package/src/app/api/canvas/[sessionId]/route.ts +0 -35
- package/src/app/api/missions/[id]/actions/route.ts +0 -31
- package/src/app/api/missions/[id]/events/route.ts +0 -14
- package/src/app/api/missions/[id]/route.ts +0 -10
- package/src/app/api/missions/route.test.ts +0 -244
- package/src/app/api/missions/route.ts +0 -57
- package/src/app/api/wallets/[id]/approve/route.ts +0 -79
- package/src/app/api/wallets/[id]/balance-history/route.ts +0 -18
- package/src/app/api/wallets/[id]/send/route.ts +0 -113
- package/src/app/api/wallets/[id]/transactions/route.ts +0 -18
- package/src/app/missions/[id]/page.tsx +0 -3
- package/src/app/missions/page.tsx +0 -685
- package/src/components/canvas/canvas-panel.tsx +0 -267
- package/src/components/wallets/wallet-approval-dialog.tsx +0 -107
- package/src/components/wallets/wallet-panel.tsx +0 -1010
- package/src/components/wallets/wallet-section.tsx +0 -260
- package/src/features/missions/queries.ts +0 -23
- package/src/lib/canvas-content.test.ts +0 -360
- package/src/lib/canvas-content.ts +0 -198
- package/src/lib/server/canvas-content.test.ts +0 -32
- package/src/lib/server/canvas-content.ts +0 -6
- package/src/lib/server/ethereum.ts +0 -591
- package/src/lib/server/evm-swap.ts +0 -476
- package/src/lib/server/missions/mission-intent.test.ts +0 -63
- package/src/lib/server/missions/mission-intent.ts +0 -569
- package/src/lib/server/missions/mission-repository.ts +0 -74
- package/src/lib/server/missions/mission-service/actions.ts +0 -6
- package/src/lib/server/missions/mission-service/bindings.ts +0 -9
- package/src/lib/server/missions/mission-service/context.ts +0 -4
- package/src/lib/server/missions/mission-service/core.ts +0 -2271
- package/src/lib/server/missions/mission-service/queries.ts +0 -12
- package/src/lib/server/missions/mission-service/recovery.ts +0 -5
- package/src/lib/server/missions/mission-service/ticks.ts +0 -9
- package/src/lib/server/missions/mission-service.test.ts +0 -888
- package/src/lib/server/missions/mission-service.ts +0 -6
- package/src/lib/server/session-tools/canvas.ts +0 -105
- package/src/lib/server/session-tools/sandbox.ts +0 -281
- package/src/lib/server/session-tools/wallet-tool.test.ts +0 -150
- package/src/lib/server/session-tools/wallet.ts +0 -1287
- package/src/lib/server/solana.ts +0 -327
- package/src/lib/server/wallet/wallet-execution.test.ts +0 -198
- package/src/lib/server/wallet/wallet-portfolio.test.ts +0 -98
- package/src/lib/server/wallet/wallet-portfolio.ts +0 -772
- package/src/lib/server/wallet/wallet-service.test.ts +0 -81
- package/src/lib/server/wallet/wallet-service.ts +0 -225
- package/src/lib/wallet/wallet-transactions.test.ts +0 -75
- package/src/lib/wallet/wallet-transactions.ts +0 -43
- package/src/lib/wallet/wallet.test.ts +0 -333
- package/src/lib/wallet/wallet.ts +0 -183
- package/src/views/settings/section-wallets.tsx +0 -35
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory — Consolidated memory tool with action-based dispatch.
|
|
3
|
+
*
|
|
4
|
+
* Single tool surface that replaces the five separate memory_* tools.
|
|
5
|
+
* Actions:
|
|
6
|
+
* read — Read a specific memory entry by id or key (maps to "get")
|
|
7
|
+
* write — Store or update a durable memory (TERMINAL — memory_write boundary)
|
|
8
|
+
* search — Semantic search across memory
|
|
9
|
+
* list — List memory entries
|
|
10
|
+
*
|
|
11
|
+
* Legacy action names (store, update, get, delete, link, unlink, doctor) are
|
|
12
|
+
* also accepted and routed directly to executeMemoryAction for full backward
|
|
13
|
+
* compatibility.
|
|
14
|
+
*
|
|
15
|
+
* Memory is agent-level: it stores what the agent has learned about users,
|
|
16
|
+
* projects, decisions, and its environment — not platform configuration.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { z } from 'zod'
|
|
20
|
+
import { tool } from '@langchain/core/tools'
|
|
21
|
+
import type { Extension, ExtensionHooks } from '@/types'
|
|
22
|
+
import { registerNativeCapability } from '../native-capabilities'
|
|
23
|
+
import { errorMessage } from '@/lib/shared-utils'
|
|
24
|
+
import { log } from '../logger'
|
|
25
|
+
import { normalizeToolInputArgs } from './normalize-tool-args'
|
|
26
|
+
import type { ToolBuildContext } from './context'
|
|
27
|
+
import { executeMemoryAction, MemoryExtension as OriginalMemoryExtension } from './memory'
|
|
28
|
+
|
|
29
|
+
const TAG = 'memory-tool'
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Action mapping: new consolidated names → legacy action names
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
/** Maps consolidated action names to the legacy names used by executeMemoryAction */
|
|
36
|
+
const ACTION_MAP: Record<string, string> = {
|
|
37
|
+
read: 'get',
|
|
38
|
+
write: 'store',
|
|
39
|
+
search: 'search',
|
|
40
|
+
list: 'list',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Actions that are passed through directly (legacy action names) */
|
|
44
|
+
const PASSTHROUGH_ACTIONS = new Set([
|
|
45
|
+
'store', 'update', 'get', 'search', 'list', 'delete', 'link', 'unlink', 'doctor',
|
|
46
|
+
])
|
|
47
|
+
|
|
48
|
+
/** Actions that are write mutations and should trigger the memory_write terminal boundary */
|
|
49
|
+
const WRITE_ACTIONS = new Set(['write', 'store', 'update'])
|
|
50
|
+
|
|
51
|
+
function resolveAction(raw: string): string {
|
|
52
|
+
const trimmed = raw.trim().toLowerCase()
|
|
53
|
+
if (ACTION_MAP[trimmed]) return ACTION_MAP[trimmed]
|
|
54
|
+
if (PASSTHROUGH_ACTIONS.has(trimmed)) return trimmed
|
|
55
|
+
return trimmed
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// File-content guard (prevents models from confusing memory with file writes)
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
function looksLikeFileContent(args: Record<string, unknown>): boolean {
|
|
63
|
+
const value = typeof args.value === 'string' ? args.value : ''
|
|
64
|
+
const title = typeof args.title === 'string' ? args.title : ''
|
|
65
|
+
const key = typeof args.key === 'string' ? args.key : ''
|
|
66
|
+
const category = typeof args.category === 'string' ? args.category : ''
|
|
67
|
+
const allText = `${title} ${key} ${category} ${value}`
|
|
68
|
+
|
|
69
|
+
const hasFileExtension = /\.\w{1,5}$/.test(title || key)
|
|
70
|
+
const hasFilePath = /(?:^|[\s"'/])(?:\/[\w.-]+){2,}\.[\w]{1,5}\b/.test(allText)
|
|
71
|
+
const mentionsFileOp = /\b(?:csv|file|refactor|code|script|document|spreadsheet|inventory)\b/i.test(allText)
|
|
72
|
+
const lineCount = (value.match(/\n/g) || []).length + 1
|
|
73
|
+
const looksLikeCode = /^(import |export |function |const |let |var |class |interface |type |def |from |#include|package |using )/m.test(value)
|
|
74
|
+
const looksLikeCsv = lineCount >= 3 && (value.match(/,/g) || []).length >= lineCount * 2
|
|
75
|
+
const looksLikeStructuredData = lineCount >= 5 && (/^\s*[\[{]/m.test(value) || looksLikeCsv)
|
|
76
|
+
|
|
77
|
+
if (hasFileExtension || hasFilePath || (mentionsFileOp && (!value || value.length > 200))) {
|
|
78
|
+
return true
|
|
79
|
+
}
|
|
80
|
+
if (value.length > 500 && (looksLikeCode || looksLikeStructuredData || looksLikeCsv)) {
|
|
81
|
+
return true
|
|
82
|
+
}
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const FILE_REDIRECT_MSG =
|
|
87
|
+
'Error: memory write is only for remembering facts, preferences, and decisions — NOT for creating files, CSV data, code, or documents. ' +
|
|
88
|
+
'To write a file, use the `files` tool: files({action:"write", files:[{path:"path/to/file", content:"..."}]})'
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Unified action dispatch
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
async function memoryAction(
|
|
95
|
+
args: Record<string, unknown>,
|
|
96
|
+
ctx: Parameters<typeof executeMemoryAction>[1],
|
|
97
|
+
): Promise<string> {
|
|
98
|
+
const normalized = normalizeToolInputArgs(args)
|
|
99
|
+
const rawAction = typeof normalized.action === 'string' ? normalized.action : ''
|
|
100
|
+
|
|
101
|
+
if (!rawAction) {
|
|
102
|
+
return 'Error: `action` parameter is required. Valid actions: read, write, search, list (also: store, update, get, delete, link, unlink, doctor).'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const resolvedAction = resolveAction(rawAction)
|
|
106
|
+
|
|
107
|
+
log.info(TAG, `memory action=${rawAction} (resolved=${resolvedAction})`, {
|
|
108
|
+
agentId: typeof ctx?.agentId === 'string' ? ctx.agentId : undefined,
|
|
109
|
+
sessionId: typeof ctx?.sessionId === 'string' ? ctx.sessionId : undefined,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
// File-content guard for write mutations (same guard as the old memory_store tool)
|
|
113
|
+
if (WRITE_ACTIONS.has(rawAction.trim().toLowerCase()) && looksLikeFileContent(normalized)) {
|
|
114
|
+
return FILE_REDIRECT_MSG
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
// Map to executeMemoryAction with the resolved legacy action name
|
|
119
|
+
return await executeMemoryAction(
|
|
120
|
+
{ ...normalized, action: resolvedAction },
|
|
121
|
+
ctx,
|
|
122
|
+
)
|
|
123
|
+
} catch (err: unknown) {
|
|
124
|
+
return `Error: ${errorMessage(err)}`
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Extension registration
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
const MemoryToolExtension: Extension = {
|
|
133
|
+
name: 'Core Memory',
|
|
134
|
+
description:
|
|
135
|
+
'Agent-level long-term memory system. Memory stores what this agent has learned — ' +
|
|
136
|
+
'user preferences, decisions, project context, relationships, and environment details. ' +
|
|
137
|
+
'Not for platform configuration or system settings.',
|
|
138
|
+
hooks: {
|
|
139
|
+
// Reuse all hooks from the original memory extension
|
|
140
|
+
...OriginalMemoryExtension.hooks,
|
|
141
|
+
getCapabilityDescription: () =>
|
|
142
|
+
'I have long-term memory (`memory` tool) that persists across conversations. ' +
|
|
143
|
+
'Working memory is session-scoped and ephemeral — good for scratch notes and in-progress work. ' +
|
|
144
|
+
'Durable memory persists across sessions — for stable facts, preferences, decisions, and learned knowledge. ' +
|
|
145
|
+
'I can search, read, write, and list memories.',
|
|
146
|
+
getOperatingGuidance: () => [
|
|
147
|
+
'Memory: use the `memory` tool with an action parameter. For past-conversation recall, use action "search" then "read". For storing facts or corrections, use action "write". For listing all memories, use action "list".',
|
|
148
|
+
'For info already in the current conversation, respond directly without calling the memory tool.',
|
|
149
|
+
'For questions about prior work, decisions, dates, people, preferences, or todos from earlier conversations: start with one durable memory search, then use read only if you need a more targeted entry. Only use archive/session history when the user explicitly needs transcript-level detail or the durable search is insufficient.',
|
|
150
|
+
'When the user directly says to remember, store, or correct a fact, do one write call immediately. Treat the newest direct user statement as authoritative.',
|
|
151
|
+
'When one user message contains multiple related facts to remember, prefer one canonical write that captures the full set instead of many near-duplicate calls.',
|
|
152
|
+
'If someone says "remember this", write it down; do not rely on RAM alone.',
|
|
153
|
+
'Memory writes merge canonical memories and retire superseded variants. After a successful write, do not keep re-searching unless the user explicitly asked you to verify.',
|
|
154
|
+
'By default, memory searches focus on durable memories. Only include archives or working execution notes when you explicitly need transcript or run-history context.',
|
|
155
|
+
'For open goals, form a hypothesis and execute — do not keep re-asking broad questions.',
|
|
156
|
+
'NEVER use the memory tool to create files, CSV data, code, or documents — always use the `files` tool for those.',
|
|
157
|
+
],
|
|
158
|
+
} as ExtensionHooks,
|
|
159
|
+
tools: [
|
|
160
|
+
{
|
|
161
|
+
name: 'memory',
|
|
162
|
+
description:
|
|
163
|
+
'Agent-level long-term memory. Store and recall facts, preferences, decisions, and knowledge across conversations. ' +
|
|
164
|
+
'Write actions merge matching canonical memories and retire superseded variants. ' +
|
|
165
|
+
'Search defaults to durable memories unless sources explicitly include archive or working.',
|
|
166
|
+
parameters: {
|
|
167
|
+
type: 'object',
|
|
168
|
+
properties: {
|
|
169
|
+
action: {
|
|
170
|
+
type: 'string',
|
|
171
|
+
enum: ['read', 'write', 'search', 'list', 'store', 'update', 'get', 'delete', 'link', 'unlink', 'doctor'],
|
|
172
|
+
description: 'The memory operation to perform',
|
|
173
|
+
},
|
|
174
|
+
id: { type: 'string', description: 'Memory entry ID (for read, write/update, delete, link, unlink)' },
|
|
175
|
+
key: { type: 'string', description: 'Memory key or lookup name' },
|
|
176
|
+
title: { type: 'string', description: 'Human-readable title for the memory entry' },
|
|
177
|
+
value: { type: 'string', description: 'Memory content to store or update' },
|
|
178
|
+
category: {
|
|
179
|
+
type: 'string',
|
|
180
|
+
description: 'Category (e.g., identity/preferences, knowledge/facts, projects/decisions, working/scratch)',
|
|
181
|
+
},
|
|
182
|
+
query: { type: 'string', description: 'Search query for semantic memory lookup' },
|
|
183
|
+
sources: {
|
|
184
|
+
type: 'array',
|
|
185
|
+
items: { type: 'string', enum: ['durable', 'working', 'archive', 'all'] },
|
|
186
|
+
description: 'Which memory tiers to search (default: durable)',
|
|
187
|
+
},
|
|
188
|
+
scope: {
|
|
189
|
+
type: 'string',
|
|
190
|
+
enum: ['auto', 'all', 'global', 'shared', 'agent', 'session', 'project'],
|
|
191
|
+
description: 'Memory scope filter',
|
|
192
|
+
},
|
|
193
|
+
rerank: {
|
|
194
|
+
type: 'string',
|
|
195
|
+
enum: ['balanced', 'semantic', 'lexical'],
|
|
196
|
+
description: 'Search reranking strategy',
|
|
197
|
+
},
|
|
198
|
+
targetIds: { type: 'array', items: { type: 'string' }, description: 'Target memory IDs for link/unlink' },
|
|
199
|
+
pinned: { type: 'boolean', description: 'Pin this memory so it always loads in context' },
|
|
200
|
+
sharedWith: { type: 'array', items: { type: 'string' }, description: 'Agent IDs to share this memory with' },
|
|
201
|
+
references: { type: 'array', description: 'Reference objects to attach to the memory' },
|
|
202
|
+
filePaths: { type: 'array', description: 'File references to attach to the memory' },
|
|
203
|
+
linkedMemoryIds: { type: 'array', items: { type: 'string' }, description: 'IDs of related memories to link' },
|
|
204
|
+
metadata: { type: 'object', description: 'Arbitrary metadata to attach to the memory entry' },
|
|
205
|
+
},
|
|
206
|
+
required: ['action'],
|
|
207
|
+
},
|
|
208
|
+
execute: async (args, context) =>
|
|
209
|
+
memoryAction(args as Record<string, unknown>, context.session),
|
|
210
|
+
planning: {
|
|
211
|
+
capabilities: ['memory.search', 'memory.write'],
|
|
212
|
+
disciplineGuidance: [
|
|
213
|
+
'Use the `memory` tool for all memory operations: read, write, search, list.',
|
|
214
|
+
'For past-conversation recall, start with action "search". Use "read" only for targeted entry lookup.',
|
|
215
|
+
'For storing facts or corrections, use action "write" immediately.',
|
|
216
|
+
'NEVER use the memory tool to create files, documents, or data exports.',
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
registerNativeCapability('memory', MemoryToolExtension)
|
|
224
|
+
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
// Tool builder (called from session-tools/index.ts)
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
|
|
229
|
+
export function buildMemoryTool(bctx: ToolBuildContext) {
|
|
230
|
+
if (!bctx.hasExtension('memory')) return []
|
|
231
|
+
|
|
232
|
+
return [
|
|
233
|
+
tool(
|
|
234
|
+
async (args) => memoryAction(args, bctx.ctx),
|
|
235
|
+
{
|
|
236
|
+
name: 'memory',
|
|
237
|
+
description: MemoryToolExtension.tools![0].description,
|
|
238
|
+
schema: z.object({}).passthrough(),
|
|
239
|
+
},
|
|
240
|
+
),
|
|
241
|
+
]
|
|
242
|
+
}
|
|
@@ -684,7 +684,7 @@ export async function executeMemoryAction(input: unknown, ctx: MemoryActionConte
|
|
|
684
684
|
/**
|
|
685
685
|
* Register as a Built-in Extension
|
|
686
686
|
*/
|
|
687
|
-
const MemoryExtension: Extension = {
|
|
687
|
+
export const MemoryExtension: Extension = {
|
|
688
688
|
name: 'Core Memory',
|
|
689
689
|
description: 'Advanced database-backed long-term memory with semantic search and graph linking.',
|
|
690
690
|
hooks: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errorMessage } from '@/lib/shared-utils'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
import { randomUUID } from 'crypto'
|
|
3
4
|
import { tool, type StructuredToolInterface } from '@langchain/core/tools'
|
|
@@ -103,8 +104,8 @@ export async function executeNodesAction(args: any, deps: OpenClawNodesDeps = {}
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
return JSON.stringify({ status: 'error', error: `Unknown nodes action "${action}".` })
|
|
106
|
-
} catch (err:
|
|
107
|
-
return JSON.stringify({ error: err
|
|
107
|
+
} catch (err: unknown) {
|
|
108
|
+
return JSON.stringify({ error: errorMessage(err) })
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errorMessage } from '@/lib/shared-utils'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
import { tool, type StructuredToolInterface } from '@langchain/core/tools'
|
|
3
4
|
import { execFile } from 'child_process'
|
|
@@ -91,8 +92,8 @@ async function executeWorkspaceAction(args: any) {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
return `Unknown action "${action}".`
|
|
94
|
-
} catch (err:
|
|
95
|
-
return JSON.stringify({ ok: false, error: err
|
|
95
|
+
} catch (err: unknown) {
|
|
96
|
+
return JSON.stringify({ ok: false, error: (err instanceof Error && 'stderr' in err) ? (err as { stderr: string }).stderr : errorMessage(err) })
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
|