UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.98 kB
import{f as shortenHomePath}from"./utils-Dlk0IYAa.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{i as listAgentIds}from"./agent-roster-4XrgUgPK.mjs";import{f as resolveAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{i as DEFAULT_MEMORY_FILENAME,s as DEFAULT_USER_FILENAME}from"./workspace-bootstrap-policy-B71K4ysN.mjs";import"./workspace-1G3FI-0P.mjs";import{r as isMemoryOriginEligibleForAutomaticInjection}from"./types-C4nBVSG1.mjs";import{n as classifyActiveMemoryWorkspacePaths}from"./memory-runtime-CqK_5Mw-.mjs";import{i as readMemoryArtifactProvenance}from"./memory-artifact-provenance-Bd8naUWA.mjs";import path from"node:path";import fs from"node:fs/promises"; //!src/commands/doctor-memory-provenance.ts const MEMORY_PROVENANCE_CHECK_ID=`core/doctor/memory-provenance`;const DOCS_URL=`https://docs.openclaw.ai/concepts/memory-provenance`;const FIX_HINT=`Review the file content. Writes from non-owner or tainted turns, and tracked writes after a shell or external edit, record untrusted provenance. This check reports the exclusion only; it does not change provenance.`;const PROFILE_ID_PATTERN=/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/;async function isFile(e){return fs.stat(e).then(e=>e.isFile(),()=>false)}async function listCuratedMemoryFiles(e){const t=await fs.readdir(path.join(e,`users`)).catch(()=>[]);const n=[DEFAULT_MEMORY_FILENAME,DEFAULT_USER_FILENAME,...t.filter(e=>PROFILE_ID_PATTERN.test(e)).toSorted().map(e=>`users/${e}/${DEFAULT_USER_FILENAME}`)];return(await Promise.all(n.map(async t=>await isFile(path.join(e,t))?t:void 0))).filter(e=>e!==void 0)}function finding(e,t){return{checkId:MEMORY_PROVENANCE_CHECK_ID,severity:`warning`,category:`fix-now`,docsUrl:DOCS_URL,message:t,path:e,fixHint:FIX_HINT}}async function collectMemoryProvenanceExclusionFindings(e){const t=listAgentIds(e);const n=[];const r=/* @__PURE__ */ new Set;for(const i of t){const a=resolveAgentWorkspaceDir(e,i);if(r.has(a))continue;r.add(a);const o=t.length>1?`Agent "${i}": `:``;try{const t=await listCuratedMemoryFiles(a);if(t.length===0)continue;const r=await classifyActiveMemoryWorkspacePaths({cfg:e,agentId:i,workspaceDir:a,relativePaths:t});if(r.status!==`classified`)continue;for(const{relativePath:e,originClass:t}of r.classifications){if(isMemoryOriginEligibleForAutomaticInjection(t))continue;const r=await readMemoryArtifactProvenance({workspaceDir:a,relativePath:e});const i=r?` Last recorded tracked write: ${new Date(r.observedAt).toISOString()}${r.sessionKey?`, session ${r.sessionKey}`:``}. The record names only the latest tracked write, not necessarily the write that quarantined the file.`:``;n.push(finding(path.join(a,e),`${o}${e} is excluded from automatic context: its memory provenance is ${t}.${i}`))}}catch(e){n.push(finding(a,`${o}Memory provenance inspection failed for ${shortenHomePath(a)}: ${formatErrorMessage(e)}`))}}return n}export{collectMemoryProvenanceExclusionFindings};