@tonyclaw/agent-inspector 4.0.1 → 4.0.2
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/.output/backend/nitro.json +1 -1
- package/.output/cli.js +192 -109
- package/.output/server/_ssr/index.mjs +1 -1
- package/.output/server/_ssr/{router-CTHqmroT.mjs → router-BBY_zWRK.mjs} +91 -3
- package/.output/server/index.mjs +1 -1
- package/.output/ui/assets/{CompareDrawer-L3n4J-Or.js → CompareDrawer-rtNElN-B.js} +1 -1
- package/.output/ui/assets/{InspectorPet-D5o_3OZS.js → InspectorPet-QaAiuF3d.js} +1 -1
- package/.output/ui/assets/{ProxyViewerContainer-Ocagx75S.js → ProxyViewerContainer-6twNZHwl.js} +4 -4
- package/.output/ui/assets/{ReplayDialog-Bk7x1h-y.js → ReplayDialog-B7KlziO2.js} +1 -1
- package/.output/ui/assets/{RequestAnatomy-U4lzL7Sc.js → RequestAnatomy-2XVFBrW4.js} +1 -1
- package/.output/ui/assets/{ResponseView-LOWfvBLK.js → ResponseView-BULgzLVB.js} +1 -1
- package/.output/ui/assets/{StreamingChunkSequence-DPfsrrXQ.js → StreamingChunkSequence-DSkvkbns.js} +1 -1
- package/.output/ui/assets/{_sessionId-OdX2Jvt1.js → _sessionId-D2dmJi3G.js} +1 -1
- package/.output/ui/assets/{_sessionId-0MlWS-CO.js → _sessionId-DcS0s1Mr.js} +1 -1
- package/.output/ui/assets/{index-Du4qNOOt.js → index-B0TN1KKO.js} +2 -2
- package/.output/ui/assets/{index-gvFj_9K6.js → index-Bva1zHEs.js} +1 -1
- package/.output/ui/assets/{index-Ea-c8hPg.js → index-BzBExOxu.js} +1 -1
- package/.output/ui/assets/{index-zVVS53Hd.js → index-k6sRQz55.js} +1 -1
- package/.output/ui/assets/{json-viewer-C1WAMzg3.js → json-viewer-CWM4tY-j.js} +1 -1
- package/.output/ui/assets/{jszip.min-B8AKu2zm.js → jszip.min-BkWvRFlo.js} +1 -1
- package/.output/ui/index.html +1 -1
- package/package.json +5 -10
- package/src/assets/IDE/claudecode-color.svg +0 -1
- package/src/assets/IDE/codex-color.svg +0 -1
- package/src/assets/IDE/opencode.svg +0 -1
- package/src/assets/IDE/xiaomimimo.svg +0 -1
- package/src/assets/favicon.svg +0 -21
- package/src/assets/logos/alibaba.svg +0 -1
- package/src/assets/logos/anthropic.svg +0 -1
- package/src/assets/logos/claude-code.svg +0 -4
- package/src/assets/logos/deepseek.svg +0 -1
- package/src/assets/logos/minimax.jpeg +0 -0
- package/src/assets/logos/openai.svg +0 -1
- package/src/assets/logos/opencode.svg +0 -4
- package/src/assets/logos/qwen.webp +0 -0
- package/src/assets/logos/zhipuai.svg +0 -219
- package/src/backend/router.tsx +0 -36
- package/src/backend/routes/$.ts +0 -26
- package/src/backend/routes/__root.ts +0 -4
- package/src/backend/routes/api/-instances.ts +0 -7
- package/src/backend/routes/api/alerts.summary.ts +0 -28
- package/src/backend/routes/api/alerts.ts +0 -70
- package/src/backend/routes/api/config.paths.ts +0 -14
- package/src/backend/routes/api/config.ts +0 -73
- package/src/backend/routes/api/ecosystem.packages.$packageId.help.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.install.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.runner-presets.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.upgrade.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.ts +0 -21
- package/src/backend/routes/api/ecosystem.recipes.$recipeId.run.ts +0 -11
- package/src/backend/routes/api/ecosystem.tasks.$taskId.ts +0 -16
- package/src/backend/routes/api/ecosystem.tasks.ts +0 -12
- package/src/backend/routes/api/groups.$groupId.evidence.ts +0 -55
- package/src/backend/routes/api/groups.$groupId.sessions.ts +0 -50
- package/src/backend/routes/api/groups.$groupId.ts +0 -93
- package/src/backend/routes/api/groups.ts +0 -79
- package/src/backend/routes/api/health.ts +0 -22
- package/src/backend/routes/api/instances.$name.connection.ts +0 -12
- package/src/backend/routes/api/instances.$name.restart.ts +0 -23
- package/src/backend/routes/api/instances.$name.start.ts +0 -18
- package/src/backend/routes/api/instances.$name.stop.ts +0 -23
- package/src/backend/routes/api/instances.$name.ts +0 -12
- package/src/backend/routes/api/instances.ts +0 -16
- package/src/backend/routes/api/knowledge.candidates.$candidateId.promote.ts +0 -32
- package/src/backend/routes/api/knowledge.candidates.$candidateId.ts +0 -50
- package/src/backend/routes/api/knowledge.candidates.ts +0 -10
- package/src/backend/routes/api/knowledge.project-context.ts +0 -29
- package/src/backend/routes/api/knowledge.search.ts +0 -62
- package/src/backend/routes/api/knowledge.sessions.$sessionId.candidates.ts +0 -26
- package/src/backend/routes/api/logs.$id.body.ts +0 -58
- package/src/backend/routes/api/logs.$id.chunks.ts +0 -37
- package/src/backend/routes/api/logs.$id.replay.ts +0 -297
- package/src/backend/routes/api/logs.$id.ts +0 -23
- package/src/backend/routes/api/logs.import.ts +0 -39
- package/src/backend/routes/api/logs.stream.ts +0 -174
- package/src/backend/routes/api/logs.ts +0 -214
- package/src/backend/routes/api/mcp.ts +0 -25
- package/src/backend/routes/api/models.ts +0 -10
- package/src/backend/routes/api/pi-agent.ts +0 -29
- package/src/backend/routes/api/providers.$providerId.model-metadata.ts +0 -173
- package/src/backend/routes/api/providers.$providerId.test.log.ts +0 -342
- package/src/backend/routes/api/providers.$providerId.ts +0 -111
- package/src/backend/routes/api/providers.export.ts +0 -44
- package/src/backend/routes/api/providers.import.ts +0 -81
- package/src/backend/routes/api/providers.scan.ts +0 -28
- package/src/backend/routes/api/providers.ts +0 -102
- package/src/backend/routes/api/runs.$runId.evidence.ts +0 -55
- package/src/backend/routes/api/runs.$runId.ts +0 -50
- package/src/backend/routes/api/runs.ts +0 -62
- package/src/backend/routes/api/runtime.ts +0 -46
- package/src/backend/routes/api/sessions.ts +0 -51
- package/src/backend/routes/api/storage.ts +0 -56
- package/src/backend/routes/livez.ts +0 -13
- package/src/backend/routes/metrics.ts +0 -14
- package/src/backend/routes/proxy/$.ts +0 -15
- package/src/backend/routes/readyz.ts +0 -18
- package/src/backend/start.ts +0 -10
- package/src/cli/alias.ts +0 -431
- package/src/cli/detect-tools.ts +0 -123
- package/src/cli/doctor.ts +0 -836
- package/src/cli/instance.ts +0 -1071
- package/src/cli/instanceApi.ts +0 -213
- package/src/cli/instanceArgs.ts +0 -301
- package/src/cli/instanceControl.ts +0 -191
- package/src/cli/instanceModel.ts +0 -276
- package/src/cli/instanceRegistry.ts +0 -731
- package/src/cli/networkHints.ts +0 -170
- package/src/cli/onboard.ts +0 -1668
- package/src/cli/onboardTarget.ts +0 -228
- package/src/cli/rustBackendPackage.ts +0 -458
- package/src/cli/startupOutput.ts +0 -16
- package/src/cli/templates/codex-skill-onboard.ts +0 -320
- package/src/cli/templates/command-onboard.ts +0 -25
- package/src/cli/templates/skill-onboard.ts +0 -625
- package/src/cli.ts +0 -1433
- package/src/components/OnboardingBanner.tsx +0 -115
- package/src/components/ProxyViewer.tsx +0 -2259
- package/src/components/ProxyViewerContainer.tsx +0 -1076
- package/src/components/alerts/AlertsDialog.tsx +0 -615
- package/src/components/clients/ClientLogo.tsx +0 -175
- package/src/components/ecosystem/AgentLabDialog.tsx +0 -947
- package/src/components/errors/SafeErrorBoundary.tsx +0 -201
- package/src/components/groups/GroupsDialog.tsx +0 -1304
- package/src/components/inspector-pet/InspectorPet.tsx +0 -398
- package/src/components/inspector-pet/InspectorPetCrab3D.tsx +0 -455
- package/src/components/inspector-pet/inspectorPetLogic.ts +0 -272
- package/src/components/pi-agent/PiAgentPanel.tsx +0 -446
- package/src/components/pi-agent/piAgentChatLogic.ts +0 -273
- package/src/components/providers/ImportWizardDialog.tsx +0 -281
- package/src/components/providers/ProviderCard.tsx +0 -347
- package/src/components/providers/ProviderForm.tsx +0 -1183
- package/src/components/providers/ProviderLogo.tsx +0 -122
- package/src/components/providers/ProviderTestResultsView.tsx +0 -734
- package/src/components/providers/ProvidersPanel.tsx +0 -714
- package/src/components/providers/SettingsDialog.tsx +0 -1042
- package/src/components/providers/providerFormCapabilities.ts +0 -36
- package/src/components/proxy-viewer/AgentTraceSummary.tsx +0 -902
- package/src/components/proxy-viewer/AnswerMarkdown.tsx +0 -51
- package/src/components/proxy-viewer/ApplicationBar.tsx +0 -123
- package/src/components/proxy-viewer/CompareDrawer.tsx +0 -984
- package/src/components/proxy-viewer/ConversationGroup.tsx +0 -208
- package/src/components/proxy-viewer/ConversationGroupList.tsx +0 -652
- package/src/components/proxy-viewer/ConversationHeader.tsx +0 -429
- package/src/components/proxy-viewer/LiveConnectionStatus.tsx +0 -186
- package/src/components/proxy-viewer/LogEntry.tsx +0 -1419
- package/src/components/proxy-viewer/LogEntryHeader.tsx +0 -596
- package/src/components/proxy-viewer/ProviderLogoStack.tsx +0 -57
- package/src/components/proxy-viewer/RawExportWarning.tsx +0 -77
- package/src/components/proxy-viewer/ReplayDialog.tsx +0 -636
- package/src/components/proxy-viewer/RequestToolsPanel.tsx +0 -299
- package/src/components/proxy-viewer/ResponseView.tsx +0 -202
- package/src/components/proxy-viewer/SessionLoadProgressBar.tsx +0 -61
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +0 -265
- package/src/components/proxy-viewer/ThreadConnector.tsx +0 -165
- package/src/components/proxy-viewer/ToolTraceEvents.tsx +0 -64
- package/src/components/proxy-viewer/TurnGroup.tsx +0 -383
- package/src/components/proxy-viewer/TurnGroupList.tsx +0 -156
- package/src/components/proxy-viewer/accessibility.ts +0 -8
- package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +0 -887
- package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +0 -222
- package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +0 -737
- package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +0 -268
- package/src/components/proxy-viewer/anatomy/tokenEstimate.ts +0 -53
- package/src/components/proxy-viewer/anatomy/types.ts +0 -41
- package/src/components/proxy-viewer/anatomy/useAnatomyJump.ts +0 -114
- package/src/components/proxy-viewer/bodyHydration.ts +0 -123
- package/src/components/proxy-viewer/cacheTrend.ts +0 -50
- package/src/components/proxy-viewer/diff/DiffView.tsx +0 -321
- package/src/components/proxy-viewer/diff/computeDiff.ts +0 -178
- package/src/components/proxy-viewer/diff/index.ts +0 -3
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +0 -194
- package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +0 -81
- package/src/components/proxy-viewer/formats/anthropic/thinkingExtract.ts +0 -21
- package/src/components/proxy-viewer/formats/index.tsx +0 -47
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +0 -442
- package/src/components/proxy-viewer/index.ts +0 -9
- package/src/components/proxy-viewer/lazy.ts +0 -41
- package/src/components/proxy-viewer/liveConnectionState.ts +0 -158
- package/src/components/proxy-viewer/log-formats/anthropic.ts +0 -191
- package/src/components/proxy-viewer/log-formats/index.ts +0 -23
- package/src/components/proxy-viewer/log-formats/openai.ts +0 -256
- package/src/components/proxy-viewer/log-formats/types.ts +0 -40
- package/src/components/proxy-viewer/log-formats/unknown.ts +0 -18
- package/src/components/proxy-viewer/logEntryVisibility.ts +0 -73
- package/src/components/proxy-viewer/logFocus.ts +0 -54
- package/src/components/proxy-viewer/proxyViewerContainerLogic.ts +0 -124
- package/src/components/proxy-viewer/proxyViewerLogic.ts +0 -488
- package/src/components/proxy-viewer/replayComparison.ts +0 -131
- package/src/components/proxy-viewer/requestDiff.ts +0 -277
- package/src/components/proxy-viewer/requestTools.ts +0 -220
- package/src/components/proxy-viewer/useCopyFeedback.ts +0 -38
- package/src/components/proxy-viewer/useKeyboardNavigation.ts +0 -232
- package/src/components/proxy-viewer/viewerState.ts +0 -176
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/button.tsx +0 -47
- package/src/components/ui/collapsible.tsx +0 -21
- package/src/components/ui/confirm-dialog.tsx +0 -51
- package/src/components/ui/crab-logo.tsx +0 -45
- package/src/components/ui/crab-variants.tsx +0 -467
- package/src/components/ui/dialog.tsx +0 -130
- package/src/components/ui/icon-trigger.ts +0 -2
- package/src/components/ui/json-viewer-bulk.ts +0 -132
- package/src/components/ui/json-viewer.tsx +0 -508
- package/src/components/ui/scroll-area.tsx +0 -54
- package/src/components/ui/select.tsx +0 -178
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/tabs.tsx +0 -88
- package/src/components/ui/tooltip.tsx +0 -51
- package/src/components/ui/transient-toast.tsx +0 -105
- package/src/contracts/anthropic.ts +0 -230
- package/src/contracts/index.ts +0 -59
- package/src/contracts/json.ts +0 -37
- package/src/contracts/log.ts +0 -139
- package/src/contracts/openai.ts +0 -267
- package/src/index.css +0 -11
- package/src/knowledge/candidateStore.ts +0 -94
- package/src/knowledge/distiller.ts +0 -98
- package/src/knowledge/openclawClient.ts +0 -161
- package/src/knowledge/openclawGatewayClient.ts +0 -249
- package/src/knowledge/openclawMarkdown.ts +0 -146
- package/src/knowledge/redactor.ts +0 -80
- package/src/knowledge/types.ts +0 -83
- package/src/lib/alertContract.ts +0 -76
- package/src/lib/apiClient.ts +0 -166
- package/src/lib/apiFormat.ts +0 -29
- package/src/lib/backendImplementation.ts +0 -16
- package/src/lib/basePath.ts +0 -107
- package/src/lib/browserRuntimeContract.ts +0 -124
- package/src/lib/browserRuntimeResolver.ts +0 -333
- package/src/lib/chunkLoadRecovery.ts +0 -83
- package/src/lib/claudeCodeStrip.ts +0 -98
- package/src/lib/clipboard.ts +0 -67
- package/src/lib/codingAgentEndpoints.ts +0 -54
- package/src/lib/ecosystemContract.ts +0 -130
- package/src/lib/export-logs.ts +0 -287
- package/src/lib/groupContract.ts +0 -166
- package/src/lib/instanceContract.ts +0 -239
- package/src/lib/jsonFile.ts +0 -46
- package/src/lib/logImportContract.ts +0 -12
- package/src/lib/managedInstance.ts +0 -112
- package/src/lib/mask.ts +0 -4
- package/src/lib/objectUtils.ts +0 -22
- package/src/lib/piAgentContract.ts +0 -102
- package/src/lib/providerContract.ts +0 -125
- package/src/lib/providerImportContract.ts +0 -27
- package/src/lib/providerModelMetadata.ts +0 -458
- package/src/lib/providerTestContract.ts +0 -170
- package/src/lib/providerTestPrompt.ts +0 -100
- package/src/lib/publicBasePathContext.ts +0 -137
- package/src/lib/resourceLimits.ts +0 -345
- package/src/lib/runContract.ts +0 -164
- package/src/lib/runtimeConfig.ts +0 -43
- package/src/lib/safeDiagnostic.ts +0 -38
- package/src/lib/safeFetch.ts +0 -508
- package/src/lib/serverPort.ts +0 -47
- package/src/lib/sessionInfoContract.ts +0 -78
- package/src/lib/sessionUrl.ts +0 -46
- package/src/lib/ssrfGuard.ts +0 -133
- package/src/lib/stopReason.ts +0 -130
- package/src/lib/themeMode.ts +0 -41
- package/src/lib/timeDisplay.ts +0 -22
- package/src/lib/toolTrace.ts +0 -290
- package/src/lib/uiScale.ts +0 -117
- package/src/lib/unknown.ts +0 -27
- package/src/lib/upstreamUrl.ts +0 -150
- package/src/lib/useAlerts.ts +0 -82
- package/src/lib/useGroupEvidence.ts +0 -37
- package/src/lib/useGroups.ts +0 -32
- package/src/lib/useOnboarding.ts +0 -93
- package/src/lib/useProviders.ts +0 -30
- package/src/lib/useStripConfig.ts +0 -154
- package/src/lib/useThemeMode.ts +0 -40
- package/src/lib/useUiScale.ts +0 -52
- package/src/lib/utils.ts +0 -78
- package/src/mcp/currentContext.ts +0 -65
- package/src/mcp/instanceHandlers.ts +0 -151
- package/src/mcp/loopback.ts +0 -88
- package/src/mcp/mode.ts +0 -75
- package/src/mcp/previewExtractor.ts +0 -233
- package/src/mcp/server.ts +0 -2274
- package/src/mcp/toolHandlers.ts +0 -1533
- package/src/proxy/alerts.ts +0 -664
- package/src/proxy/chunkStorage.ts +0 -123
- package/src/proxy/config.ts +0 -218
- package/src/proxy/constants.ts +0 -66
- package/src/proxy/dataDir.ts +0 -147
- package/src/proxy/ecosystemExecutionConfirmation.ts +0 -114
- package/src/proxy/ecosystemExecutionRoute.ts +0 -116
- package/src/proxy/ecosystemRegistry.ts +0 -296
- package/src/proxy/ecosystemTasks.ts +0 -415
- package/src/proxy/evidenceAnalysis.ts +0 -526
- package/src/proxy/evidenceExporter.ts +0 -235
- package/src/proxy/formats/anthropic/anthropicProvider.ts +0 -75
- package/src/proxy/formats/anthropic/handler.ts +0 -75
- package/src/proxy/formats/anthropic/index.ts +0 -13
- package/src/proxy/formats/anthropic/register.ts +0 -4
- package/src/proxy/formats/anthropic/schemas.ts +0 -6
- package/src/proxy/formats/anthropic/stream.ts +0 -205
- package/src/proxy/formats/handler.ts +0 -46
- package/src/proxy/formats/index.ts +0 -13
- package/src/proxy/formats/jsonSchema.ts +0 -2
- package/src/proxy/formats/openai/alibabaProvider.ts +0 -34
- package/src/proxy/formats/openai/codexMetadata.ts +0 -61
- package/src/proxy/formats/openai/handler.ts +0 -133
- package/src/proxy/formats/openai/index.ts +0 -33
- package/src/proxy/formats/openai/provider.ts +0 -50
- package/src/proxy/formats/openai/register.ts +0 -4
- package/src/proxy/formats/openai/schemas.ts +0 -25
- package/src/proxy/formats/openai/stream.ts +0 -600
- package/src/proxy/formats/openai/zhipuProvider.ts +0 -31
- package/src/proxy/formats/providerAdapter.ts +0 -50
- package/src/proxy/formats/providerRegistry.ts +0 -51
- package/src/proxy/formats/providers/index.ts +0 -3
- package/src/proxy/formats/registry.ts +0 -65
- package/src/proxy/groupEvidenceExporter.ts +0 -371
- package/src/proxy/groupStore.ts +0 -336
- package/src/proxy/handler.ts +0 -729
- package/src/proxy/identityProxy.ts +0 -1842
- package/src/proxy/jsonlRecovery.ts +0 -554
- package/src/proxy/logBodyChunks.ts +0 -91
- package/src/proxy/logFinalizer.ts +0 -777
- package/src/proxy/logFinalizer.worker.ts +0 -24
- package/src/proxy/logImportUpload.ts +0 -128
- package/src/proxy/logImporter.ts +0 -813
- package/src/proxy/logIndex.ts +0 -663
- package/src/proxy/logSearch.ts +0 -122
- package/src/proxy/logger.ts +0 -537
- package/src/proxy/openaiOrphanToolStrip.ts +0 -142
- package/src/proxy/platformCommands.ts +0 -258
- package/src/proxy/privateDataPath.ts +0 -419
- package/src/proxy/providerImporters.ts +0 -578
- package/src/proxy/providerScanStore.ts +0 -87
- package/src/proxy/providerSecretStore.ts +0 -216
- package/src/proxy/providers.ts +0 -998
- package/src/proxy/rawStreamCapture.ts +0 -342
- package/src/proxy/runFailures.ts +0 -94
- package/src/proxy/runStore.ts +0 -214
- package/src/proxy/runtimeAdmission.ts +0 -55
- package/src/proxy/runtimeHealth.ts +0 -221
- package/src/proxy/runtimeMetrics.ts +0 -149
- package/src/proxy/runtimeShutdown.ts +0 -157
- package/src/proxy/schemas.ts +0 -112
- package/src/proxy/sessionArchive.ts +0 -479
- package/src/proxy/sessionInfo.ts +0 -266
- package/src/proxy/sessionProcess.ts +0 -194
- package/src/proxy/sessionRuntime.ts +0 -121
- package/src/proxy/sessionSupervisor.ts +0 -305
- package/src/proxy/sessionWorkerEntry.ts +0 -26
- package/src/proxy/shutdownCoordinator.ts +0 -90
- package/src/proxy/socketTracker.ts +0 -639
- package/src/proxy/sqliteLogIndex.ts +0 -733
- package/src/proxy/storageLifecycle.ts +0 -432
- package/src/proxy/store.ts +0 -1773
- package/src/proxy/streamTiming.ts +0 -31
- package/src/proxy/toolSchemaWarnings.ts +0 -529
- package/src/proxy/uiAssetServer.ts +0 -106
- package/src/proxy/upstream.ts +0 -127
- package/src/services/alerts.ts +0 -12
- package/src/services/groups.ts +0 -119
- package/src/services/piAgent.ts +0 -421
- package/src/services/piAgentRetrieval.ts +0 -1180
- package/src/services/result.ts +0 -17
- package/src/services/runs.ts +0 -76
- package/src/ui/bootstrap.ts +0 -167
- package/src/ui/index.html +0 -38
- package/src/ui/logsStreamClient.ts +0 -20
- package/src/ui/main.tsx +0 -13
- package/src/ui/public/runtime-config.js +0 -2
- package/src/ui/router.tsx +0 -13
- package/src/ui/routes/__root.tsx +0 -69
- package/src/ui/routes/index.tsx +0 -35
- package/src/ui/routes/session/$sessionId.tsx +0 -50
- package/src/ui/runtimeDiscovery.ts +0 -50
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { DEFAULT_RUNTIME_BUDGET_POLICY } from "../lib/resourceLimits";
|
|
3
|
-
import { safeFetch } from "../lib/safeFetch";
|
|
4
|
-
import type { KnowledgeCandidate, KnowledgeSearchResponse, OpenClawMemoryPayload } from "./types";
|
|
5
|
-
import { KnowledgeSearchResponseSchema, KnowledgeSearchResultSchema } from "./types";
|
|
6
|
-
import { isOpenClawGatewayConfigured, searchOpenClawGateway } from "./openclawGatewayClient";
|
|
7
|
-
import { isOpenClawFileBridgeConfigured, writeCandidateToOpenClawMemory } from "./openclawMarkdown";
|
|
8
|
-
import { redactCandidate } from "./redactor";
|
|
9
|
-
|
|
10
|
-
const OpenClawWriteResponseSchema = z.object({
|
|
11
|
-
id: z.string().optional(),
|
|
12
|
-
memoryId: z.string().optional(),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export type PromoteResult =
|
|
16
|
-
| {
|
|
17
|
-
success: true;
|
|
18
|
-
memoryId: string | null;
|
|
19
|
-
}
|
|
20
|
-
| {
|
|
21
|
-
success: false;
|
|
22
|
-
error: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function getLegacyEndpoint(): string | null {
|
|
26
|
-
const endpoint = process.env["OPENCLAW_MEMORY_URL"] ?? process.env["OPENCLAW_API_URL"];
|
|
27
|
-
if (endpoint === undefined || endpoint.trim() === "") return null;
|
|
28
|
-
return endpoint.trim();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function buildMemoryUrl(endpoint: string): string {
|
|
32
|
-
return endpoint.endsWith("/memories") ? endpoint : `${endpoint.replace(/\/$/, "")}/memories`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function buildSearchUrl(endpoint: string, query: string, project?: string): string {
|
|
36
|
-
const url = new URL(`${endpoint.replace(/\/$/, "")}/search`);
|
|
37
|
-
url.searchParams.set("q", query);
|
|
38
|
-
if (project !== undefined && project !== "") {
|
|
39
|
-
url.searchParams.set("project", project);
|
|
40
|
-
}
|
|
41
|
-
return url.toString();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function authHeaders(): Headers {
|
|
45
|
-
const headers = new Headers({ "content-type": "application/json" });
|
|
46
|
-
const token = process.env["OPENCLAW_API_KEY"];
|
|
47
|
-
if (token !== undefined && token !== "") {
|
|
48
|
-
headers.set("authorization", `Bearer ${token}`);
|
|
49
|
-
}
|
|
50
|
-
return headers;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function buildOpenClawPayload(candidate: KnowledgeCandidate): OpenClawMemoryPayload {
|
|
54
|
-
const sanitized = redactCandidate(candidate);
|
|
55
|
-
return {
|
|
56
|
-
idempotencyKey: `inspector:session:${sanitized.sessionId}:candidate:${sanitized.id}`,
|
|
57
|
-
type: sanitized.type,
|
|
58
|
-
title: sanitized.title,
|
|
59
|
-
content: sanitized.content,
|
|
60
|
-
tags: sanitized.tags,
|
|
61
|
-
source: "agent-inspector",
|
|
62
|
-
project: sanitized.evidence.project,
|
|
63
|
-
evidence: sanitized.evidence,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export async function promoteToOpenClaw(candidate: KnowledgeCandidate): Promise<PromoteResult> {
|
|
68
|
-
if (isOpenClawFileBridgeConfigured()) {
|
|
69
|
-
const result = await writeCandidateToOpenClawMemory(candidate);
|
|
70
|
-
if (result.success) {
|
|
71
|
-
return { success: true, memoryId: result.memoryId };
|
|
72
|
-
}
|
|
73
|
-
return { success: false, error: result.error };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const endpoint = getLegacyEndpoint();
|
|
77
|
-
if (endpoint === null) {
|
|
78
|
-
return {
|
|
79
|
-
success: false,
|
|
80
|
-
error:
|
|
81
|
-
"OpenClaw memory backend is not configured. Set OPENCLAW_WORKSPACE_DIR " +
|
|
82
|
-
"for file-backed memory or OPENCLAW_MEMORY_URL for a legacy HTTP backend.",
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const fetchResult = await safeFetch(
|
|
87
|
-
buildMemoryUrl(endpoint),
|
|
88
|
-
{
|
|
89
|
-
method: "POST",
|
|
90
|
-
headers: authHeaders(),
|
|
91
|
-
body: JSON.stringify(buildOpenClawPayload(candidate)),
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
bypass: true,
|
|
95
|
-
deadlineMs: DEFAULT_RUNTIME_BUDGET_POLICY.upstream.metadataDeadlineMs,
|
|
96
|
-
responseBytes: DEFAULT_RUNTIME_BUDGET_POLICY.upstream.metadataResponseBytes,
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
if (!fetchResult.ok) return { success: false, error: fetchResult.reason };
|
|
100
|
-
const response = fetchResult.response;
|
|
101
|
-
|
|
102
|
-
if (!response.ok) {
|
|
103
|
-
return { success: false, error: `OpenClaw memory write failed with ${response.status}` };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const raw: unknown = await response.json().catch(() => ({}));
|
|
107
|
-
const parsed = OpenClawWriteResponseSchema.safeParse(raw);
|
|
108
|
-
if (!parsed.success) {
|
|
109
|
-
return { success: true, memoryId: null };
|
|
110
|
-
}
|
|
111
|
-
return { success: true, memoryId: parsed.data.memoryId ?? parsed.data.id ?? null };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function searchOpenClaw(
|
|
115
|
-
query: string,
|
|
116
|
-
project?: string,
|
|
117
|
-
): Promise<KnowledgeSearchResponse> {
|
|
118
|
-
if (isOpenClawGatewayConfigured()) {
|
|
119
|
-
return await searchOpenClawGateway(query, project);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const endpoint = getLegacyEndpoint();
|
|
123
|
-
if (endpoint === null) {
|
|
124
|
-
const workspaceHint = isOpenClawFileBridgeConfigured()
|
|
125
|
-
? " OPENCLAW_WORKSPACE_DIR is configured for writes, but search requires OPENCLAW_GATEWAY_URL."
|
|
126
|
-
: "";
|
|
127
|
-
return {
|
|
128
|
-
results: [],
|
|
129
|
-
warning:
|
|
130
|
-
"OpenClaw search backend is not configured. Set OPENCLAW_GATEWAY_URL " +
|
|
131
|
-
`or OPENCLAW_MEMORY_URL.${workspaceHint}`,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const fetchResult = await safeFetch(
|
|
136
|
-
buildSearchUrl(endpoint, query, project),
|
|
137
|
-
{
|
|
138
|
-
method: "GET",
|
|
139
|
-
headers: authHeaders(),
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
bypass: true,
|
|
143
|
-
deadlineMs: DEFAULT_RUNTIME_BUDGET_POLICY.upstream.metadataDeadlineMs,
|
|
144
|
-
responseBytes: DEFAULT_RUNTIME_BUDGET_POLICY.upstream.metadataResponseBytes,
|
|
145
|
-
},
|
|
146
|
-
);
|
|
147
|
-
if (!fetchResult.ok) return { results: [], warning: fetchResult.reason };
|
|
148
|
-
const response = fetchResult.response;
|
|
149
|
-
if (!response.ok) {
|
|
150
|
-
return { results: [], warning: `OpenClaw search failed with ${response.status}` };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const raw: unknown = await response.json().catch(() => ({ results: [] }));
|
|
154
|
-
const parsed = KnowledgeSearchResponseSchema.safeParse(raw);
|
|
155
|
-
if (parsed.success) return parsed.data;
|
|
156
|
-
const arrayParsed = z.array(KnowledgeSearchResultSchema).safeParse(raw);
|
|
157
|
-
if (arrayParsed.success) {
|
|
158
|
-
return { results: arrayParsed.data, warning: null };
|
|
159
|
-
}
|
|
160
|
-
return { results: [], warning: "OpenClaw search returned an unparseable response." };
|
|
161
|
-
}
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { DEFAULT_RUNTIME_BUDGET_POLICY } from "../lib/resourceLimits";
|
|
3
|
-
import { safeFetch } from "../lib/safeFetch";
|
|
4
|
-
import type { KnowledgeSearchResponse, KnowledgeSearchResult } from "./types";
|
|
5
|
-
|
|
6
|
-
const OpenClawGatewayErrorSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
type: z.string().optional(),
|
|
9
|
-
message: z.string().optional(),
|
|
10
|
-
})
|
|
11
|
-
.passthrough();
|
|
12
|
-
|
|
13
|
-
const OpenClawGatewayInvokeResponseSchema = z
|
|
14
|
-
.object({
|
|
15
|
-
ok: z.boolean().optional(),
|
|
16
|
-
result: z.unknown().optional(),
|
|
17
|
-
error: OpenClawGatewayErrorSchema.optional(),
|
|
18
|
-
})
|
|
19
|
-
.passthrough();
|
|
20
|
-
|
|
21
|
-
const OpenClawGatewayContentItemSchema = z
|
|
22
|
-
.object({
|
|
23
|
-
type: z.string().optional(),
|
|
24
|
-
text: z.string().optional(),
|
|
25
|
-
})
|
|
26
|
-
.passthrough();
|
|
27
|
-
|
|
28
|
-
const OpenClawMemoryHitSchema = z
|
|
29
|
-
.object({
|
|
30
|
-
id: z.string().optional(),
|
|
31
|
-
path: z.string().optional(),
|
|
32
|
-
title: z.string().optional(),
|
|
33
|
-
kind: z.string().optional(),
|
|
34
|
-
corpus: z.string().optional(),
|
|
35
|
-
score: z.number().nullable().optional(),
|
|
36
|
-
snippet: z.string().optional(),
|
|
37
|
-
content: z.string().optional(),
|
|
38
|
-
source: z.string().nullable().optional(),
|
|
39
|
-
startLine: z.number().optional(),
|
|
40
|
-
endLine: z.number().optional(),
|
|
41
|
-
})
|
|
42
|
-
.passthrough();
|
|
43
|
-
|
|
44
|
-
const OpenClawToolResultDetailsSchema = z
|
|
45
|
-
.object({
|
|
46
|
-
results: z.array(OpenClawMemoryHitSchema).optional(),
|
|
47
|
-
})
|
|
48
|
-
.passthrough();
|
|
49
|
-
|
|
50
|
-
const OpenClawToolResultSchema = z
|
|
51
|
-
.object({
|
|
52
|
-
results: z.array(OpenClawMemoryHitSchema).optional(),
|
|
53
|
-
details: OpenClawToolResultDetailsSchema.optional(),
|
|
54
|
-
content: z.array(OpenClawGatewayContentItemSchema).optional(),
|
|
55
|
-
})
|
|
56
|
-
.passthrough();
|
|
57
|
-
|
|
58
|
-
type OpenClawMemoryHit = z.infer<typeof OpenClawMemoryHitSchema>;
|
|
59
|
-
|
|
60
|
-
export function getOpenClawGatewayUrl(): string | null {
|
|
61
|
-
const value = process.env["OPENCLAW_GATEWAY_URL"];
|
|
62
|
-
if (value === undefined || value.trim() === "") {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
return value.trim();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function isOpenClawGatewayConfigured(): boolean {
|
|
69
|
-
return getOpenClawGatewayUrl() !== null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function buildToolInvokeUrl(gatewayUrl: string): string {
|
|
73
|
-
return `${gatewayUrl.replace(/\/$/, "")}/tools/invoke`;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function getOpenClawSessionKey(): string {
|
|
77
|
-
const value = process.env["OPENCLAW_SESSION_KEY"];
|
|
78
|
-
return value === undefined || value.trim() === "" ? "main" : value.trim();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getGatewayToken(): string | null {
|
|
82
|
-
const token =
|
|
83
|
-
process.env["OPENCLAW_GATEWAY_TOKEN"] ??
|
|
84
|
-
process.env["OPENCLAW_GATEWAY_PASSWORD"] ??
|
|
85
|
-
process.env["OPENCLAW_API_KEY"];
|
|
86
|
-
if (token === undefined || token.trim() === "") {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
return token.trim();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function gatewayHeaders(): Headers {
|
|
93
|
-
const headers = new Headers({ "content-type": "application/json" });
|
|
94
|
-
const token = getGatewayToken();
|
|
95
|
-
if (token !== null) {
|
|
96
|
-
headers.set("authorization", `Bearer ${token}`);
|
|
97
|
-
}
|
|
98
|
-
return headers;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function buildSearchQuery(query: string, project?: string): string {
|
|
102
|
-
if (project === undefined || project === "") {
|
|
103
|
-
return query;
|
|
104
|
-
}
|
|
105
|
-
return `${query}\nProject: ${project}`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function formatHitTitle(hit: OpenClawMemoryHit, index: number): string {
|
|
109
|
-
if (hit.title !== undefined && hit.title !== "") {
|
|
110
|
-
return hit.title;
|
|
111
|
-
}
|
|
112
|
-
if (hit.path !== undefined && hit.path !== "") {
|
|
113
|
-
return hit.path;
|
|
114
|
-
}
|
|
115
|
-
if (hit.id !== undefined && hit.id !== "") {
|
|
116
|
-
return hit.id;
|
|
117
|
-
}
|
|
118
|
-
return `OpenClaw memory result ${String(index + 1)}`;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function formatHitId(hit: OpenClawMemoryHit, index: number): string {
|
|
122
|
-
const base = hit.id ?? hit.path ?? `result-${String(index + 1)}`;
|
|
123
|
-
const start = hit.startLine === undefined ? "" : `:${String(hit.startLine)}`;
|
|
124
|
-
const end = hit.endLine === undefined ? "" : `-${String(hit.endLine)}`;
|
|
125
|
-
return `openclaw:${base}${start}${end}`;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function formatHitContent(hit: OpenClawMemoryHit): string {
|
|
129
|
-
if (hit.snippet !== undefined && hit.snippet !== "") {
|
|
130
|
-
return hit.snippet;
|
|
131
|
-
}
|
|
132
|
-
if (hit.content !== undefined && hit.content !== "") {
|
|
133
|
-
return hit.content;
|
|
134
|
-
}
|
|
135
|
-
return "";
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function formatHitType(hit: OpenClawMemoryHit): string {
|
|
139
|
-
if (hit.kind !== undefined && hit.kind !== "") {
|
|
140
|
-
return hit.kind;
|
|
141
|
-
}
|
|
142
|
-
if (hit.corpus !== undefined && hit.corpus !== "") {
|
|
143
|
-
return hit.corpus;
|
|
144
|
-
}
|
|
145
|
-
return "openclaw-memory";
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function mapGatewayHit(
|
|
149
|
-
hit: OpenClawMemoryHit,
|
|
150
|
-
index: number,
|
|
151
|
-
project?: string,
|
|
152
|
-
): KnowledgeSearchResult {
|
|
153
|
-
return {
|
|
154
|
-
id: formatHitId(hit, index),
|
|
155
|
-
type: formatHitType(hit),
|
|
156
|
-
title: formatHitTitle(hit, index),
|
|
157
|
-
content: formatHitContent(hit),
|
|
158
|
-
score: hit.score ?? null,
|
|
159
|
-
source: hit.source ?? "openclaw",
|
|
160
|
-
project: project ?? null,
|
|
161
|
-
evidence: hit,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function extractGatewayHits(result: unknown): OpenClawMemoryHit[] | null {
|
|
166
|
-
const parsed = OpenClawToolResultSchema.safeParse(result);
|
|
167
|
-
if (!parsed.success) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
return parsed.data.details?.results ?? parsed.data.results ?? [];
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function formatGatewayError(raw: unknown): string {
|
|
174
|
-
const parsed = OpenClawGatewayInvokeResponseSchema.safeParse(raw);
|
|
175
|
-
if (!parsed.success) {
|
|
176
|
-
return "OpenClaw Gateway returned an unparseable response.";
|
|
177
|
-
}
|
|
178
|
-
const message = parsed.data.error?.message;
|
|
179
|
-
if (message !== undefined && message !== "") {
|
|
180
|
-
return message;
|
|
181
|
-
}
|
|
182
|
-
return "OpenClaw Gateway tool invocation failed.";
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export async function searchOpenClawGateway(
|
|
186
|
-
query: string,
|
|
187
|
-
project?: string,
|
|
188
|
-
): Promise<KnowledgeSearchResponse> {
|
|
189
|
-
const gatewayUrl = getOpenClawGatewayUrl();
|
|
190
|
-
if (gatewayUrl === null) {
|
|
191
|
-
return {
|
|
192
|
-
results: [],
|
|
193
|
-
warning: "OpenClaw Gateway is not configured. Set OPENCLAW_GATEWAY_URL.",
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const fetchResult = await safeFetch(
|
|
198
|
-
buildToolInvokeUrl(gatewayUrl),
|
|
199
|
-
{
|
|
200
|
-
method: "POST",
|
|
201
|
-
headers: gatewayHeaders(),
|
|
202
|
-
body: JSON.stringify({
|
|
203
|
-
tool: "memory_search",
|
|
204
|
-
args: {
|
|
205
|
-
query: buildSearchQuery(query, project),
|
|
206
|
-
maxResults: 10,
|
|
207
|
-
corpus: "all",
|
|
208
|
-
},
|
|
209
|
-
sessionKey: getOpenClawSessionKey(),
|
|
210
|
-
}),
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
bypass: true,
|
|
214
|
-
deadlineMs: DEFAULT_RUNTIME_BUDGET_POLICY.upstream.metadataDeadlineMs,
|
|
215
|
-
responseBytes: DEFAULT_RUNTIME_BUDGET_POLICY.upstream.metadataResponseBytes,
|
|
216
|
-
},
|
|
217
|
-
);
|
|
218
|
-
if (!fetchResult.ok) return { results: [], warning: fetchResult.reason };
|
|
219
|
-
const response = fetchResult.response;
|
|
220
|
-
|
|
221
|
-
const raw: unknown = await response.json().catch(() => null);
|
|
222
|
-
if (!response.ok) {
|
|
223
|
-
return {
|
|
224
|
-
results: [],
|
|
225
|
-
warning: `OpenClaw Gateway search failed with ${response.status}: ${formatGatewayError(raw)}`,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const parsed = OpenClawGatewayInvokeResponseSchema.safeParse(raw);
|
|
230
|
-
if (!parsed.success) {
|
|
231
|
-
return { results: [], warning: "OpenClaw Gateway returned an unparseable response." };
|
|
232
|
-
}
|
|
233
|
-
if (parsed.data.ok === false) {
|
|
234
|
-
return { results: [], warning: formatGatewayError(raw) };
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const hits = extractGatewayHits(parsed.data.result);
|
|
238
|
-
if (hits === null) {
|
|
239
|
-
return {
|
|
240
|
-
results: [],
|
|
241
|
-
warning: "OpenClaw memory_search returned an unparseable tool result.",
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return {
|
|
246
|
-
results: hits.map((hit, index) => mapGatewayHit(hit, index, project)),
|
|
247
|
-
warning: null,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import type { KnowledgeCandidate } from "./types";
|
|
4
|
-
import { redactCandidate } from "./redactor";
|
|
5
|
-
|
|
6
|
-
export type OpenClawFilePromotionResult =
|
|
7
|
-
| {
|
|
8
|
-
success: true;
|
|
9
|
-
memoryId: string;
|
|
10
|
-
relativePath: string;
|
|
11
|
-
absolutePath: string;
|
|
12
|
-
}
|
|
13
|
-
| {
|
|
14
|
-
success: false;
|
|
15
|
-
error: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function getOpenClawWorkspaceDir(): string | null {
|
|
19
|
-
const value = process.env["OPENCLAW_WORKSPACE_DIR"];
|
|
20
|
-
if (value === undefined || value.trim() === "") {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return value.trim();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function isOpenClawFileBridgeConfigured(): boolean {
|
|
27
|
-
return getOpenClawWorkspaceDir() !== null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function normalizeDatePrefix(value: string): string {
|
|
31
|
-
const date = value.slice(0, 10);
|
|
32
|
-
return /^\d{4}-\d{2}-\d{2}$/.test(date) ? date : "undated";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function normalizePathSegment(value: string, fallback: string): string {
|
|
36
|
-
const segment = value
|
|
37
|
-
.toLowerCase()
|
|
38
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
39
|
-
.replace(/^-+|-+$/g, "")
|
|
40
|
-
.slice(0, 96);
|
|
41
|
-
return segment === "" ? fallback : segment;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function formatNullable(value: string | null): string {
|
|
45
|
-
return value === null || value === "" ? "unknown" : value;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function formatList(values: string[]): string {
|
|
49
|
-
return values.length === 0 ? "none" : values.join(", ");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function buildEvidenceLink(candidate: KnowledgeCandidate): string {
|
|
53
|
-
return `agent-inspector:session:${candidate.sessionId}:candidate:${candidate.id}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function buildOpenClawMemoryRelativePath(candidate: KnowledgeCandidate): string {
|
|
57
|
-
const date = normalizeDatePrefix(candidate.updatedAt);
|
|
58
|
-
const slug = normalizePathSegment(candidate.id, "candidate");
|
|
59
|
-
return path.join("memory", "agent-inspector", date, `${slug}.md`).replace(/\\/g, "/");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function buildOpenClawMemoryMarkdown(candidate: KnowledgeCandidate): string {
|
|
63
|
-
const sanitized = redactCandidate(candidate);
|
|
64
|
-
return [
|
|
65
|
-
"# Agent Inspector Memory Candidate",
|
|
66
|
-
"",
|
|
67
|
-
"Layer: L3 memory candidate for OpenClaw L4 durable recall",
|
|
68
|
-
"Source: agent-inspector",
|
|
69
|
-
"",
|
|
70
|
-
"## Metadata",
|
|
71
|
-
"",
|
|
72
|
-
`- Type: ${sanitized.type}`,
|
|
73
|
-
`- Status: ${sanitized.status}`,
|
|
74
|
-
`- Project: ${formatNullable(sanitized.evidence.project)}`,
|
|
75
|
-
`- Session: ${sanitized.sessionId}`,
|
|
76
|
-
`- Log IDs: ${sanitized.logIds.join(", ")}`,
|
|
77
|
-
`- Models: ${formatList(sanitized.evidence.models)}`,
|
|
78
|
-
`- Tags: ${formatList(sanitized.tags)}`,
|
|
79
|
-
`- Created: ${sanitized.createdAt}`,
|
|
80
|
-
`- Updated: ${sanitized.updatedAt}`,
|
|
81
|
-
`- Evidence: ${buildEvidenceLink(sanitized)}`,
|
|
82
|
-
`- Redacted: ${String(sanitized.redaction.redacted)}`,
|
|
83
|
-
`- Redaction patterns: ${formatList(sanitized.redaction.patterns)}`,
|
|
84
|
-
"",
|
|
85
|
-
"## Durable Knowledge Candidate",
|
|
86
|
-
"",
|
|
87
|
-
sanitized.content,
|
|
88
|
-
"",
|
|
89
|
-
"## Recall Guidance",
|
|
90
|
-
"",
|
|
91
|
-
[
|
|
92
|
-
"- Treat this as reviewed Agent Inspector knowledge extracted from LLM interaction traces.",
|
|
93
|
-
"- Use the evidence id to return to Agent Inspector when raw proof is needed.",
|
|
94
|
-
"- Do not treat this file as raw logs; sensitive values were redacted before export.",
|
|
95
|
-
].join("\n"),
|
|
96
|
-
"",
|
|
97
|
-
].join("\n");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function resolveTargetPath(workspaceDir: string, relativePath: string): string | null {
|
|
101
|
-
const root = path.resolve(workspaceDir);
|
|
102
|
-
const target = path.resolve(root, relativePath);
|
|
103
|
-
const relative = path.relative(root, target);
|
|
104
|
-
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
return target;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function writeCandidateToOpenClawMemory(
|
|
111
|
-
candidate: KnowledgeCandidate,
|
|
112
|
-
): Promise<OpenClawFilePromotionResult> {
|
|
113
|
-
const workspaceDir = getOpenClawWorkspaceDir();
|
|
114
|
-
if (workspaceDir === null) {
|
|
115
|
-
return {
|
|
116
|
-
success: false,
|
|
117
|
-
error: "OpenClaw workspace is not configured. Set OPENCLAW_WORKSPACE_DIR.",
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const relativePath = buildOpenClawMemoryRelativePath(candidate);
|
|
122
|
-
const target = resolveTargetPath(workspaceDir, relativePath);
|
|
123
|
-
if (target === null) {
|
|
124
|
-
return {
|
|
125
|
-
success: false,
|
|
126
|
-
error: "OpenClaw memory target resolved outside OPENCLAW_WORKSPACE_DIR.",
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
132
|
-
await fs.writeFile(target, buildOpenClawMemoryMarkdown(candidate), "utf8");
|
|
133
|
-
} catch (error) {
|
|
134
|
-
return {
|
|
135
|
-
success: false,
|
|
136
|
-
error: `OpenClaw memory file write failed: ${String(error)}`,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
success: true,
|
|
142
|
-
memoryId: `openclaw-file:${relativePath}`,
|
|
143
|
-
relativePath,
|
|
144
|
-
absolutePath: target,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { KnowledgeCandidate, RedactionMetadata } from "./types";
|
|
2
|
-
|
|
3
|
-
type RedactionPattern = {
|
|
4
|
-
name: string;
|
|
5
|
-
pattern: RegExp;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const REDACTION_PATTERNS: RedactionPattern[] = [
|
|
9
|
-
{ name: "authorization-header", pattern: /\bAuthorization\s*:\s*[^\s,;]+/gi },
|
|
10
|
-
{ name: "bearer-token", pattern: /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi },
|
|
11
|
-
{ name: "api-key", pattern: /\b(?:sk|ak)-[A-Za-z0-9_-]{12,}\b/gi },
|
|
12
|
-
{ name: "cookie", pattern: /\bCookie\s*:\s*[^;\n]+(?:;[^\n]+)?/gi },
|
|
13
|
-
{
|
|
14
|
-
name: "secret-assignment",
|
|
15
|
-
pattern: /\b(?:api[_-]?key|token|secret|password)\s*=\s*["']?[^"'\s,;]{8,}["']?/gi,
|
|
16
|
-
},
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
type RedactedText = {
|
|
20
|
-
text: string;
|
|
21
|
-
patterns: string[];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function unique(values: string[]): string[] {
|
|
25
|
-
return [...new Set(values)];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function redactText(input: string): RedactedText {
|
|
29
|
-
let text = input;
|
|
30
|
-
const patterns: string[] = [];
|
|
31
|
-
for (const item of REDACTION_PATTERNS) {
|
|
32
|
-
let matched = false;
|
|
33
|
-
text = text.replace(item.pattern, () => {
|
|
34
|
-
matched = true;
|
|
35
|
-
return `[REDACTED:${item.name}]`;
|
|
36
|
-
});
|
|
37
|
-
if (matched) {
|
|
38
|
-
patterns.push(item.name);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return { text, patterns: unique(patterns) };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function combineRedaction(patterns: string[]): RedactionMetadata {
|
|
45
|
-
const uniquePatterns = unique(patterns);
|
|
46
|
-
return {
|
|
47
|
-
redacted: uniquePatterns.length > 0,
|
|
48
|
-
patterns: uniquePatterns,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function redactCandidate(candidate: KnowledgeCandidate): KnowledgeCandidate {
|
|
53
|
-
const title = redactText(candidate.title);
|
|
54
|
-
const content = redactText(candidate.content);
|
|
55
|
-
const tagResults = candidate.tags.map(redactText);
|
|
56
|
-
const evidenceProject =
|
|
57
|
-
candidate.evidence.project === null ? null : redactText(candidate.evidence.project);
|
|
58
|
-
const evidenceModels = candidate.evidence.models.map(redactText);
|
|
59
|
-
const patterns = [
|
|
60
|
-
...title.patterns,
|
|
61
|
-
...content.patterns,
|
|
62
|
-
...tagResults.flatMap((result) => result.patterns),
|
|
63
|
-
...(evidenceProject === null ? [] : evidenceProject.patterns),
|
|
64
|
-
...evidenceModels.flatMap((result) => result.patterns),
|
|
65
|
-
...candidate.redaction.patterns,
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
...candidate,
|
|
70
|
-
title: title.text,
|
|
71
|
-
content: content.text,
|
|
72
|
-
tags: tagResults.map((result) => result.text),
|
|
73
|
-
evidence: {
|
|
74
|
-
...candidate.evidence,
|
|
75
|
-
project: evidenceProject === null ? null : evidenceProject.text,
|
|
76
|
-
models: evidenceModels.map((result) => result.text),
|
|
77
|
-
},
|
|
78
|
-
redaction: combineRedaction(patterns),
|
|
79
|
-
};
|
|
80
|
-
}
|