aws-runtime-bridge 1.9.117 → 1.9.119
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/dist/routes/instance.js +1 -1
- package/dist/services/lifecycle-state.d.ts +5 -0
- package/dist/services/lifecycle-state.js +2 -2
- package/package/acode/dist/runtime.js +24 -16
- package/package/aws-client-agent-mcp/dist/mcp-server.js +22 -22
- package/package/aws-client-agent-mcp/dist/mcp-tools.js +6 -6
- package/package/aws-client-agent-mcp/dist/mcp-tools.test.js +1 -1
- package/package/aws-client-agent-mcp/dist/memory-store.d.ts +3 -2
- package/package/aws-client-agent-mcp/dist/memory-store.js +3 -3
- package/package/aws-client-agent-mcp/dist/memory-store.test.js +122 -0
- package/package/aws-client-agent-mcp/dist/memory-tools.js +9 -6
- package/package/aws-client-agent-mcp/dist/server-memory-store.d.ts +1 -1
- package/package/aws-client-agent-mcp/dist/server-memory-store.js +1 -1
- package/package.json +1 -1
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import $ from"node:fs";import j from"node:os";import f from"node:path";import{Server as U}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as x}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as q,ListToolsRequestSchema as W}from"@modelcontextprotocol/sdk/types.js";import{AgentClient as H}from"./agent-client.js";import{MCP_SERVER_NAME as z,MCP_SERVER_VERSION as G,REGISTER_MAX_RETRIES as P,REGISTER_RETRY_INTERVAL_MS as Y,DEGRADED_MODE_ENABLED as L,DEGRADED_MODE_RETRY_INTERVAL_MS as J,DEGRADED_MODE_MAX_RETRIES as K}from"./constants.js";import{logger as a}from"./logger.js";import{MCP_TOOLS as D,MEMORY_TOOL_NAMES as F}from"./mcp-tools.js";import{MessageBuffer as V}from"./message-buffer.js";import{ContextManager as X}from"./context-manager.js";import{MemoryCapacityError as Z,MemoryStore as N}from"./memory-store.js";import{ServerMemoryStore as Q}from"./server-memory-store.js";const ee=3e3,te=10,re=new Set(["<",">",":",'"',"/","\\","|","?","*"]);class v{server;agentClient;messageBuffer;memoryStore;roleMemoryStore;sessionContextMemoryStore;initialRoleName="";hasRoleName=!1;contextManager;isSubAgent;leaseRenewalTimer=null;activeLeaseUris=new Set;static LEASE_DURATION_MINUTES=10;static LEASE_RENEW_INTERVAL_MS=6e4;profileSynced=!1;pendingPollMessage=null;syncRoleMemoryStore(e){if(a.info(`[McpServer] syncRoleMemoryStore \u88AB\u8C03\u7528: displayName=${e.displayName}, roleName="${e.roleName??"(\u7A7A)"}", id=${e.id}`),!e.roleName){a.warn(`[McpServer] syncRoleMemoryStore: profile.roleName \u4E3A\u7A7A\uFF0ChasRoleName \u4FDD\u6301 false\u3002profile=${JSON.stringify({id:e.id,displayName:e.displayName,roleName:e.roleName,instanceName:e.instanceName})}`);return}const t=v.sanitizeRoleDirectoryName(e.roleName);this.hasRoleName=!0,t!==this.initialRoleName&&(a.info(`[McpServer] \u89D2\u8272\u76EE\u5F55\u4E0E\u521D\u59CB\u503C\u4E0D\u4E00\u81F4\uFF0C\u91CD\u5EFA roleMemoryStore: "${this.initialRoleName}" -> "${t}"`),this.roleMemoryStore=new N(v.buildRoleMemoryStorePath(t)),this.initialRoleName=t)}maybeSyncPermanentMemoryToServer(){this.doMaybeSyncPermanentMemoryToServer().catch(e=>{a.warn("[McpServer] maybeSyncPermanentMemoryToServer \u5F02\u5E38: %s, stack=%s",e instanceof Error?e.message:String(e),e instanceof Error?e.stack:"(no stack)")})}async doMaybeSyncPermanentMemoryToServer(){a.info("[McpServer] maybeSyncPermanentMemoryToServer \u5F00\u59CB\uFF0CinitialRoleName="+this.initialRoleName);let e;try{e=await this.memoryStore.getStats()}catch(
|
|
2
|
-
${
|
|
3
|
-
`)}`)}toMemoryWriteResult(e){return{id:e.id,uri:e.uri,domain:e.domain,path:e.path,title:e.title,memory_type:e.memory_type,createdAt:e.createdAt,updatedAt:e.updatedAt,version:e.version,keywords:e.keywords,bound_files:e.bound_files}}toMemoryRecordWithMetadata(e){return{id:e.id,uri:e.uri,domain:e.domain,path:e.path,title:e.title,content:e.content,memory_type:e.memory_type,createdAt:e.createdAt,updatedAt:e.updatedAt,version:e.version,keywords:e.keywords,bound_files:e.bound_files,file_md5_map:e.file_md5_map,memory_status:e.memory_status,updating_agent_id:e.updating_agent_id,last_check_time:e.last_check_time}}constructor(){this.agentClient=new H,this.messageBuffer=new V,this.initialRoleName=v.resolveRoleMemoryDirectoryName(),this.hasRoleName=!!process.env.AWS_ROLE_NAME;const e=v.resolveMemoryStorePaths();this.memoryStore=new Q(this.agentClient),this.roleMemoryStore=new N(e.rolePath),this.sessionContextMemoryStore=new N(f.join(f.dirname(e.rolePath),"..","session_context")),this.isSubAgent=process.env.AWS_SUB_AGENT==="true",this.contextManager=new X(this.sessionContextMemoryStore),this.server=new U({name:z,version:G},{capabilities:{tools:{}}}),this.setupHandlers()}setupHandlers(){this.server.setRequestHandler(W,async()=>({tools:this.isSubAgent?D.filter(t=>F.has(t.name)):D})),this.server.setRequestHandler(q,async e=>{const{name:t,arguments:r}=e.params;try{const n=await this.handleToolCall(t,r);return{content:this.buildToolResultContent(n)}}catch(n){const i=n instanceof Error?n.message:String(n),s=n instanceof Z?{error:i,...n.details}:{error:i};return a.error("[McpServer] \u5DE5\u5177\u8C03\u7528\u5F02\u5E38: tool=%s, error=%s, stack=%s",t,i,n instanceof Error?n.stack:"(no stack)"),{content:[{type:"text",text:JSON.stringify(s,null,2)}],isError:!0}}})}buildToolResultContent(e){if(e&&typeof e=="object"&&!Array.isArray(e)){const t=e;if(typeof t.image=="string"&&typeof t.mimeType=="string")return[{type:"image",data:t.image,mimeType:t.mimeType}]}return[{type:"text",text:JSON.stringify(e,null,2)}]}async handleToolCall(e,t){const r=t?._aws_sub_agent===!0,n=t?._aws_silent_poll===!0,i=t?._aws_force_inject===!0,s={...t};delete s._aws_sub_agent,delete s._aws_silent_poll,delete s._aws_force_inject;const o=r?null:this.agentClient.getStatusReporter();o&&!n&&o.reportToolUse(e,this.sanitizeToolUseArgs(e,s));try{const l=await this.executeToolCall(e,s,{forceInject:i});if(o&&!n){const m=this.stripAutoDelegateForReporting(l);m!==null&&(o.reportToolResult(m),o.reportThinking())}return l}catch(l){throw o&&!n&&o.reportToolError(l),l}}async executeToolCall(e,t,r={}){if(this.isSubAgent&&!F.has(e))throw new Error(`Sub-agent is not allowed to call tool: ${e}`);switch(e){case"get_colleague":return await this.agentClient.discoverColleagues();case"get_group_rooms":return await this.agentClient.discoverGroupRooms();case"get_profile":return await this.agentClient.getProfile();case"hire_colleague":return await this.handleHireColleague(t);case"hire_colleagues_batch":return await this.handleHireColleaguesBatch(t);case"send_group":return await this.handleSendGroup(t);case"send_private":return await this.handleSendPrivate(t);case"poll_message":return await this.handlePollMessage();case"get_message":return this.handleGetMessage(r.forceInject===!0);case"get_dm_history":return await this.handleGetDmHistory(t);case"get_group_history":return await this.handleGetGroupHistory(t);case"my_task":return await this.agentClient.getMyTasks();case"create_task_instance_comment":return await this.handleCreateTaskInstanceComment(t);case"submit_task_result":return await this.handleSubmitTaskResult(t);case"start_task_rollback":return await this.handleStartTaskRollback(t);case"finish_task_rollback":return await this.handleFinishTaskRollback(t);case"reject_task":return await this.handleRejectTask(t);case"terminate_task":return await this.handleTerminateTask(t);case"create_memory":return await this.handleCreateMemory(t);case"read_memory":return await this.handleReadMemory(t);case"update_memory":return await this.handleUpdateMemory(t);case"delete_memory":return await this.handleDeleteMemory(t);case"search_memory":return await this.handleSearchMemory(t);case"list_memories":return await this.handleListMemories(t);case"get_memory_stats":return await this.handleGetMemoryStats(t);case"list_memories_by_file":return await this.handleListMemoriesByFile(t);case"abandon_memory_update":return await this.handleAbandonMemoryUpdate(t);case"memory_recurrence":return await this.handleMemoryRecurrence(t);case"memory_recurrence_complete":return await this.handleMemoryRecurrenceComplete();case"get_debug_log_config":return await this.agentClient.getDebugLogConfig();case"query_debug_logs":return await this.agentClient.queryDebugLogs(t);case"query_file_changes_history":return await this.agentClient.queryFileChangesHistory(t);default:throw new Error(`Unknown tool: ${e}`)}}static MEMORY_TYPES=["recently_memory","agent_memory","project_memory","session_context"];static MEMORY_TOOL_NAMES=new Set(["create_memory","read_memory","update_memory","delete_memory","search_memory","list_memories","get_memory_stats","list_memories_by_file","abandon_memory_update","memory_recurrence","memory_recurrence_complete"]);static findAgentsworkDirSync(e){let t=f.resolve(e);for(;;){if($.existsSync(f.join(t,".agentswork")))return f.join(t,".agentswork");const r=f.dirname(t);if(r===t)break;t=r}return f.join(f.resolve(e),".agentswork")}static sanitizeRoleDirectoryName(e){return String(e||"").trim().split("").map(r=>re.has(r)||r.charCodeAt(0)<32?"_":r).join("").replace(/^\.+|\.+$/g,"").trim()||"default-role"}static resolveRoleMemoryDirectoryName(){return v.sanitizeRoleDirectoryName(process.env.AWS_ROLE_NAME||"")}static buildRoleMemoryStorePath(e){const t=process.env.AWS_WORKSPACE_PATH||process.cwd(),r=v.findAgentsworkDirSync(t);return f.join(r,"memory","memory",v.sanitizeRoleDirectoryName(e))}static resolveMemoryStorePaths(){const e=String(process.env.AWS_MEMORY_STORE_PATH||"").trim();if(e)return{instancePath:e,rolePath:e};const t=process.env.AWS_WORKSPACE_PATH||process.cwd(),r=v.findAgentsworkDirSync(t),n=String(process.env.AWS_INSTANCE_MEMORY_STORE_PATH||"").trim()||f.join(r,"memory","server-managed"),i=String(process.env.AWS_ROLE_MEMORY_STORE_PATH||"").trim()||f.join(r,"memory","memory",v.resolveRoleMemoryDirectoryName());return{instancePath:n,rolePath:i}}getRequiredString(e,t){const r=e[t];if(typeof r!="string"||r.trim().length===0)throw new Error(`${t} is required`);return r}getOptionalString(e,t){const r=e[t];return typeof r=="string"?r:void 0}getOptionalNumber(e,t){const r=e[t];return typeof r=="number"?r:void 0}getOptionalStringArray(e,t){const r=e[t];return Array.isArray(r)?r.map(n=>String(n)):void 0}getOptionalMemoryType(e){const t=e.memory_type;if(t!==void 0)return this.parseMemoryType(t)}parseMemoryType(e){if(typeof e!="string")throw new Error(`Invalid memory_type: ${String(e)}`);const t=e.trim();if(!this.isMemoryType(t))throw new Error(`Invalid memory_type: ${e}`);return t}isMemoryType(e){return v.MEMORY_TYPES.some(t=>t===e)}getMemoryStoreForType(e){return this.memoryStore}async readMemoryFromScopedStores(e){if(e.memory_type)return await this.memoryStore.readMemory(e);const t=await this.memoryStore.readMemory({...e,memory_type:"project_memory"}).catch(()=>null);return t||await this.memoryStore.readMemory(e)}async backupProjectMemoryToLocal(e){try{const t=await this.memoryStore.readMemory({uri:e.uri,memory_type:"project_memory"});t&&(await this.roleMemoryStore.deleteMemory({uri:e.uri,memory_type:"project_memory"}).catch(()=>{}),await this.roleMemoryStore.createMemory(t))}catch(t){a.warn("[McpServer] backupProjectMemoryToLocal \u5931\u8D25: uri=%s",e.uri,t)}}async removeProjectMemoryLocalBackup(e){try{await this.roleMemoryStore.deleteMemory({uri:e,memory_type:"project_memory"})}catch(t){a.warn("[McpServer] removeProjectMemoryLocalBackup \u5931\u8D25: uri=%s",e,t)}}async findMemoryStoreForMutation(e){return e.memory_type?{store:this.memoryStore,memory_type:e.memory_type}:await this.memoryStore.readMemory({uri:e.uri,memory_type:"project_memory"}).catch(()=>null)?{store:this.memoryStore,memory_type:"project_memory"}:{store:this.memoryStore}}async reportMemoryStatsToServer(){const e=await this.memoryStore.getStats();try{await this.agentClient.reportMemoryStats(e)}catch(t){a.warn("[McpServer] \u4E0A\u62A5 memory \u7EDF\u8BA1\u5931\u8D25:",t)}}sanitizeToolUseArgs(e,t){if(!v.MEMORY_TOOL_NAMES.has(e))return t;const r={},n=this.getOptionalString(t,"uri"),i=this.getOptionalString(t,"memory_type"),s=this.getOptionalNumber(t,"limit");return n&&(r.uri=n),i&&(r.memory_type=i),typeof s=="number"&&(r.limit=s),e==="search_memory"&&(r.queryProvided=typeof t.query=="string"&&t.query.length>0,t.keyword_mode!==void 0&&(r.keyword_mode=t.keyword_mode)),r}stripAutoDelegateForReporting(e){if(!e||typeof e!="object")return e;const t=e,r=Array.isArray(t.directMessages)?t.directMessages:[],n=Array.isArray(t.groupMessages)?t.groupMessages:[],i=l=>!!l&&typeof l=="object"&&"_acodeAutoDelegate"in l;if(!r.some(i))return e;const o=r.filter(l=>!i(l));return o.length===0&&n.length===0?null:{...t,directMessages:o}}async handleCreateMemory(e){const t=this.normalizeBoundFiles(this.getOptionalStringArray(e,"bound_files"));await this.validateBoundFilesExist(t);let r,n;if(t&&t.length>0){r={};for(const o of t){const l=await this.calculateFileMd5(o);l&&(r[o]=l)}n=new Date().toISOString()}const i={memory_type:this.parseMemoryType(this.getRequiredString(e,"memory_type")),uri:this.getRequiredString(e,"uri"),title:this.getOptionalString(e,"title"),content:this.getRequiredString(e,"content"),keywords:this.getOptionalStringArray(e,"keywords"),bound_files:t,file_md5_map:r,last_check_time:n},s=await this.memoryStore.createMemory(i);return i.memory_type==="project_memory"&&this.backupProjectMemoryToLocal(i).catch(o=>{a.warn("[McpServer] \u5907\u4EFD project_memory \u5230\u672C\u5730\u5931\u8D25:",o)}),await this.reportMemoryStatsToServer(),this.toMemoryWriteResult(s)}async handleReadMemory(e){const t={uri:this.getRequiredString(e,"uri"),memory_type:this.getOptionalMemoryType(e)};return await this.readMemoryFromScopedStores(t)}async handleUpdateMemory(e){const t=typeof e.old_string=="string"||typeof e.new_string=="string",r=typeof e.old_string=="string"&&typeof e.new_string=="string",n=this.getOptionalString(e,"append");if(t&&!r)throw new Error("old_string and new_string must be provided together");const i={uri:this.getRequiredString(e,"uri"),memory_type:this.getOptionalMemoryType(e),title:this.getOptionalString(e,"title"),old_string:this.getOptionalString(e,"old_string"),new_string:this.getOptionalString(e,"new_string"),append:n,keywords:this.getOptionalStringArray(e,"keywords"),bound_files:this.normalizeBoundFiles(this.getOptionalStringArray(e,"bound_files"))},s=await this.findMemoryStoreForMutation(i),o=await s.store.readMemory({uri:i.uri,memory_type:s.memory_type??i.memory_type});i.bound_files!==void 0?await this.validateBoundFilesExist(i.bound_files):o?.bound_files&&o.bound_files.length>0&&await this.validateBoundFilesExist(o.bound_files);const l=i.bound_files??o?.bound_files;let m,u;if(l&&l.length>0){m={};for(const d of l){const p=await this.calculateFileMd5(d);p&&(m[d]=p)}u=new Date().toISOString()}const h=await s.store.updateMemory({...i,memory_type:s.memory_type??i.memory_type,file_md5_map:m,last_check_time:u});if(s.memory_type==="project_memory"&&this.backupProjectMemoryToLocal({...i,memory_type:"project_memory",file_md5_map:m,last_check_time:u}).catch(d=>{a.warn("[McpServer] \u5907\u4EFD project_memory \u66F4\u65B0\u5230\u672C\u5730\u5931\u8D25:",d)}),await this.reportMemoryStatsToServer(),s.memory_type==="project_memory"&&o?.memory_status==="updating")try{await this.memoryStore.releaseMemoryClaim(i.uri),this.activeLeaseUris.delete(i.uri),this.activeLeaseUris.size===0&&this.stopLeaseRenewal()}catch(d){a.warn("[McpServer] \u91CA\u653E memory claim \u5931\u8D25: uri=%s, error=%s",i.uri,d instanceof Error?d.message:String(d))}return this.toMemoryWriteResult(h)}async handleDeleteMemory(e){const t=typeof e.uri=="string"?e.uri:void 0,r=Array.isArray(e.memories)?e.memories:void 0;if(t&&r&&r.length>0)throw new Error("delete_memory \u4E0D\u652F\u6301\u540C\u65F6\u4F20\u5165 uri \u548C memories\uFF0C\u8BF7\u4E8C\u9009\u4E00");if(!t&&(!r||r.length===0))throw new Error("delete_memory \u9700\u8981 uri \u6216 memories \u53C2\u6570");if(t){const o=this.getOptionalMemoryType(e);return{deleted:await this.deleteMemorySingle(t,o)}}let n=0;const i=[],s=[];for(let o=0;o<r.length;o++){const l=r[o];if(typeof l!="object"||l===null){s.push({uri:String(l),reason:`memories[${o}] \u4E0D\u662F\u5BF9\u8C61`});continue}const m=l,u=typeof m.uri=="string"?m.uri:"";if(!u){s.push({uri:"",reason:`memories[${o}].uri \u7F3A\u5931`});continue}const h=typeof m.memory_type=="string"?this.parseMemoryType(m.memory_type):void 0;try{await this.deleteMemorySingle(u,h,!0)?n++:i.push(u)}catch(d){s.push({uri:u,reason:d instanceof Error?d.message:String(d)})}}return n>0&&await this.reportMemoryStatsToServer(),{deleted:n,not_found:i,failed:s}}async deleteMemorySingle(e,t,r=!1){const n={uri:e,memory_type:t},i=await this.findMemoryStoreForMutation(n),s=i.memory_type??n.memory_type,o=await i.store.deleteMemory({...n,memory_type:s});return o&&(s==="project_memory"&&this.removeProjectMemoryLocalBackup(e).catch(l=>{a.warn("[McpServer] \u5220\u9664 project_memory \u672C\u5730\u5907\u4EFD\u5931\u8D25:",l)}),r||await this.reportMemoryStatsToServer()),o}async handleSearchMemory(e){const t=this.getOptionalString(e,"scope"),r=t==="children"||t==="all"?t:"own",n=this.getOptionalString(e,"keyword_mode"),i=n==="all"?"all":n==="any"?"any":void 0,s={query:this.getRequiredString(e,"query"),limit:this.getOptionalNumber(e,"limit"),memory_type:this.getOptionalMemoryType(e),keywords:this.getOptionalStringArray(e,"keywords"),keyword_mode:i,scope:r};if(r==="children")return await this.memoryStore.searchMemory(s);const o=await this.searchOwnMemories(s);if(r==="own")return o;const l=await this.memoryStore.searchMemory({...s,scope:"children"});return this.mergeSearchResults(o,l,s.limit)}async searchOwnMemories(e){return await this.memoryStore.searchMemory(e)}mergeSearchResults(e,t,r){const n=new Set,i=typeof r=="number"&&r>0?r:10,s=[...e.results,...t.results].filter(o=>{const l=o.uri;return n.has(l)?!1:(n.add(l),!0)}).sort((o,l)=>l.updatedAt.localeCompare(o.updatedAt)).slice(0,i);return{query:e.query||t.query,results:s}}async handleListMemories(e){const t=this.getRequiredString(e,"memory_type");if(t==="project_memory"||t==="session_context")throw new Error(`Invalid memory_type: ${t}`);return await this.memoryStore.listByType(t)}async handleGetMemoryStats(e){const t=await this.memoryStore.getStats(),r=this.getOptionalMemoryType(e);return r?{memory_type:r,total:t.by_type[r].count,by_type:{[r]:t.by_type[r]}}:t}async handleListMemoriesByFile(e){const t=this.getRequiredString(e,"file_path"),r=this.normalizeBoundFilePath(t),n=this.getOptionalMemoryType(e),i=this.getOptionalString(e,"scope"),s=i==="own"||i==="children"?i:"all",o=async()=>await this.memoryStore.listByFile(r,{memory_type:n,scope:"children"}).catch(()=>[]);if(s==="children"){const d=await o();return{file_path:r,count:d.length,memories:d.map(p=>this.toMemoryRecordWithMetadata(p))}}const l=await this.collectOwnMemoriesByFile(r,n);if(s==="own")return{file_path:r,count:l.length,memories:l.map(d=>this.toMemoryRecordWithMetadata(d))};const m=await o(),u=new Set(l.map(d=>d.id)),h=[...l];for(const d of m)u.has(d.id)||(h.push(d),u.add(d.id));return h.sort((d,p)=>p.updatedAt.localeCompare(d.updatedAt)),{file_path:r,count:h.length,memories:h.map(d=>this.toMemoryRecordWithMetadata(d))}}mergeIdDedupe(e,t){const r=new Set;for(const i of e)i.id&&r.add(i.id);const n=[...e];for(const i of t)i.id&&!r.has(i.id)&&(n.push(i),r.add(i.id));return n.sort((i,s)=>s.updatedAt.localeCompare(i.updatedAt)),n}async searchChildMemoriesByFileLocal(e,t){const r=process.env.AWS_WORKSPACE_PATH||process.cwd(),n=this.normalizeBoundFilePath(e),s=(n.startsWith("./")?n.substring(2):n).split("/"),o=[],l=new Set,{access:m,readdir:u,readFile:h}=await import("node:fs/promises");for(let d=s.length-1;d>=1;d--){const p=s.slice(0,d),R="./"+s.slice(d).join("/"),A=f.join(r,...p);if(A===r)continue;const c=f.join(A,".agentswork");try{await m(c)}catch{continue}const g=f.join(c,"memory","memory");let b;try{b=(await u(g,{withFileTypes:!0})).filter(_=>_.isDirectory()).map(_=>_.name)}catch{continue}for(const M of b){const _=f.join(g,M);let C;try{C=await u(_)}catch{continue}for(const y of C){if(!y.endsWith(".json"))continue;const w=f.join(_,y);let S;try{S=await h(w,"utf-8")}catch{continue}let k;try{k=JSON.parse(S)}catch{continue}if(k.by_uri)for(const[E,I]of Object.entries(k.by_uri)){if(!I)continue;const O=I.id||E;l.has(O)||t&&I.memory_type!==t||I.bound_files&&I.bound_files.length>0&&I.bound_files.some(B=>this.normalizeBoundFilePath(B)===R)&&(l.add(O),o.push({...I,uri:I.uri||E}))}}}}return o.sort((d,p)=>p.updatedAt.localeCompare(d.updatedAt)),o}async collectOwnMemoriesByFile(e,t){return await this.memoryStore.listByFile(e,{memory_type:t})}async handleAbandonMemoryUpdate(e){const t=this.getRequiredString(e,"uri"),r=this.getOptionalMemoryType(e),n=await this.memoryStore.readMemory({uri:t,memory_type:r});return n?.bound_files&&n.bound_files.length>0&&await this.validateBoundFilesExist(n.bound_files),await this.memoryStore.releaseMemoryClaim(t),n?.memory_type==="project_memory"&&this.backupProjectMemoryToLocal({uri:t,memory_type:"project_memory"}).catch(i=>{a.info(`[McpServer] abandon_memory_update: \u540C\u6B65\u672C\u5730\u5907\u4EFD\u5931\u8D25: ${t}`,i)}),this.activeLeaseUris.delete(t),this.activeLeaseUris.size===0&&this.stopLeaseRenewal(),{success:!0,uri:t,message:"Memory \u66F4\u65B0\u72B6\u6001\u5DF2\u6E05\u9664"}}async handleMemoryRecurrence(e){const t=Math.max(1,e?.limit??10),r=await this.memoryStore.listExpiredRecentlyMemories();if(r.length===0)return{memories:[],count:0,remaining:0,totalExpired:0,message:"\u6CA1\u6709\u5F85\u56DE\u5FC6\u7684\u5373\u5C06\u9057\u5FD8\u8BB0\u5FC6\u3002"};const i=[...r].sort((m,u)=>{const h=new Date(m.expiresAt||m.createdAt||0).getTime(),d=new Date(u.expiresAt||u.createdAt||0).getTime();return h-d}).slice(0,t),s=i.map(m=>m.uri);try{await this.memoryStore.markExpiredMemoriesRecalling(s)}catch(m){a.warn("[McpServer] \u6807\u8BB0\u8FC7\u671F\u8BB0\u5FC6\u4E3A recalling \u5931\u8D25: uriCount=%s, error=%s",s.length,m instanceof Error?m.message:String(m))}const o=Math.max(0,r.length-i.length);return{memories:i.map(m=>({uri:m.uri,title:m.title,domain:m.domain,path:m.path,memory_status:"recalling",contentPreview:typeof m.content=="string"&&m.content.length>200?m.content.substring(0,200)+"...":m.content,createdAt:m.createdAt,updatedAt:m.updatedAt})),count:i.length,limit:t,remaining:o,totalExpired:r.length,message:o>0?`\u672C\u6B21\u5904\u7406 ${i.length} \u6761\u5373\u5C06\u9057\u5FD8\u7684\u8BB0\u5FC6\uFF08\u6700\u65E9\u8FC7\u671F\u4F18\u5148\uFF09\uFF0C\u5269\u4F59 ${o} \u6761\u5F85\u5904\u7406\u3002
|
|
1
|
+
import $ from"node:fs";import j from"node:os";import f from"node:path";import{Server as U}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as x}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as q,ListToolsRequestSchema as W}from"@modelcontextprotocol/sdk/types.js";import{AgentClient as H}from"./agent-client.js";import{MCP_SERVER_NAME as z,MCP_SERVER_VERSION as G,REGISTER_MAX_RETRIES as P,REGISTER_RETRY_INTERVAL_MS as Y,DEGRADED_MODE_ENABLED as L,DEGRADED_MODE_RETRY_INTERVAL_MS as J,DEGRADED_MODE_MAX_RETRIES as K}from"./constants.js";import{logger as a}from"./logger.js";import{MCP_TOOLS as D,MEMORY_TOOL_NAMES as F}from"./mcp-tools.js";import{MessageBuffer as V}from"./message-buffer.js";import{ContextManager as X}from"./context-manager.js";import{MemoryCapacityError as Z,MemoryStore as N}from"./memory-store.js";import{ServerMemoryStore as Q}from"./server-memory-store.js";const ee=3e3,te=10,re=new Set(["<",">",":",'"',"/","\\","|","?","*"]);class v{server;agentClient;messageBuffer;memoryStore;roleMemoryStore;sessionContextMemoryStore;initialRoleName="";hasRoleName=!1;contextManager;isSubAgent;leaseRenewalTimer=null;activeLeaseUris=new Set;static LEASE_DURATION_MINUTES=10;static LEASE_RENEW_INTERVAL_MS=6e4;profileSynced=!1;pendingPollMessage=null;syncRoleMemoryStore(e){if(a.info(`[McpServer] syncRoleMemoryStore \u88AB\u8C03\u7528: displayName=${e.displayName}, roleName="${e.roleName??"(\u7A7A)"}", id=${e.id}`),!e.roleName){a.warn(`[McpServer] syncRoleMemoryStore: profile.roleName \u4E3A\u7A7A\uFF0ChasRoleName \u4FDD\u6301 false\u3002profile=${JSON.stringify({id:e.id,displayName:e.displayName,roleName:e.roleName,instanceName:e.instanceName})}`);return}const t=v.sanitizeRoleDirectoryName(e.roleName);this.hasRoleName=!0,t!==this.initialRoleName&&(a.info(`[McpServer] \u89D2\u8272\u76EE\u5F55\u4E0E\u521D\u59CB\u503C\u4E0D\u4E00\u81F4\uFF0C\u91CD\u5EFA roleMemoryStore: "${this.initialRoleName}" -> "${t}"`),this.roleMemoryStore=new N(v.buildRoleMemoryStorePath(t)),this.initialRoleName=t)}maybeSyncPermanentMemoryToServer(){this.doMaybeSyncPermanentMemoryToServer().catch(e=>{a.warn("[McpServer] maybeSyncPermanentMemoryToServer \u5F02\u5E38: %s, stack=%s",e instanceof Error?e.message:String(e),e instanceof Error?e.stack:"(no stack)")})}async doMaybeSyncPermanentMemoryToServer(){a.info("[McpServer] maybeSyncPermanentMemoryToServer \u5F00\u59CB\uFF0CinitialRoleName="+this.initialRoleName);let e;try{e=await this.memoryStore.getStats()}catch(n){a.warn("[McpServer] \u83B7\u53D6 server \u8BB0\u5FC6\u7EDF\u8BA1\u5931\u8D25\uFF0C\u8DF3\u8FC7\u540C\u6B65:",n instanceof Error?n.message:n);return}const t=e.by_type.project_memory?.count??0;if(a.info(`[McpServer] server memory \u8BA1\u6570=${t}\uFF0C\u662F\u5426\u9700\u8981\u540C\u6B65=${t===0}`),t>0)return;let r=[];try{r=await this.roleMemoryStore.listByType("project_memory"),a.info(`[McpServer] \u89D2\u8272\u5B50\u76EE\u5F55\u8BFB\u53D6\u5230 ${r.length} \u6761\u6C38\u4E45\u8BB0\u5FC6`)}catch(n){a.warn("[McpServer] \u8BFB\u53D6\u89D2\u8272\u5B50\u76EE\u5F55\u6C38\u4E45\u8BB0\u5FC6\u5931\u8D25:",n instanceof Error?n.message:n)}if(r.length===0){const n=f.dirname(v.buildRoleMemoryStorePath(this.initialRoleName));a.info(`[McpServer] \u5C1D\u8BD5\u4ECE\u9057\u7559\u76EE\u5F55\u8BFB\u53D6: ${n}`);try{const l=await new N(n).listByType("project_memory");l.length>0&&(a.info(`[McpServer] \u4ECE\u9057\u7559\u76EE\u5F55\u8BFB\u53D6\u5230 ${l.length} \u6761\u6C38\u4E45\u8BB0\u5FC6`),r=l)}catch(o){a.warn("[McpServer] \u8BFB\u53D6\u9057\u7559\u76EE\u5F55\u6C38\u4E45\u8BB0\u5FC6\u5931\u8D25:",o instanceof Error?o.message:o)}}if(r.length===0){a.info("[McpServer] \u672C\u5730\u4E5F\u65E0\u6C38\u4E45\u8BB0\u5FC6\uFF0C\u8DF3\u8FC7\u540C\u6B65");return}let s=0,i=0;for(const n of r)try{await this.memoryStore.createMemory({memory_type:"project_memory",uri:n.uri,title:n.title,content:n.content,keywords:n.keywords,bound_files:n.bound_files,file_md5_map:n.file_md5_map,last_check_time:n.last_check_time}),s++,a.info(`[McpServer] \u540C\u6B65\u6C38\u4E45\u8BB0\u5FC6\u6210\u529F: ${n.uri}`)}catch(o){const l=o instanceof Error?o.message:String(o);l.includes("already exists")||l.includes("Memory already exists")||a.warn(`[McpServer] \u540C\u6B65\u6C38\u4E45\u8BB0\u5FC6\u5931\u8D25 (${n.uri}): ${l}`),i++}a.info(`[McpServer] \u6C38\u4E45\u8BB0\u5FC6\u540C\u6B65\u5B8C\u6210: \u6210\u529F ${s}, \u8DF3\u8FC7 ${i}, \u5171 ${r.length}`),await this.reportMemoryStatsToServer()}normalizeBoundFilePath(e){const t=String(e||"").trim().replace(/\\/g,"/");if(!t)return t;const r=t.startsWith("@/")?t.substring(1):t;return r.startsWith("./")?r:`./${r.replace(/^\/+/,"")}`}normalizeBoundFiles(e){return!e||!Array.isArray(e)?e:e.map(t=>this.normalizeBoundFilePath(String(t)))}async validateBoundFilesExist(e){if(!e||e.length===0)return;const t=process.env.AWS_WORKSPACE_PATH||process.cwd(),{access:r}=await import("node:fs/promises"),s=[];for(const i of e)try{const n=f.resolve(t,i);await r(n)}catch{s.push(i)}if(s.length>0)throw new Error(`\u7ED1\u5B9A\u7684\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u786E\u8BA4\u6587\u4EF6\u8DEF\u5F84\u6B63\u786E\u540E\u518D\u91CD\u65B0\u63D0\u4EA4:
|
|
2
|
+
${s.map(i=>` - ${i}`).join(`
|
|
3
|
+
`)}`)}toMemoryWriteResult(e){return{id:e.id,uri:e.uri,domain:e.domain,path:e.path,title:e.title,memory_type:e.memory_type,createdAt:e.createdAt,updatedAt:e.updatedAt,version:e.version,keywords:e.keywords,bound_files:e.bound_files}}toMemoryRecordWithMetadata(e){return{id:e.id,uri:e.uri,domain:e.domain,path:e.path,title:e.title,content:e.content,memory_type:e.memory_type,createdAt:e.createdAt,updatedAt:e.updatedAt,version:e.version,keywords:e.keywords,bound_files:e.bound_files,file_md5_map:e.file_md5_map,memory_status:e.memory_status,updating_agent_id:e.updating_agent_id,last_check_time:e.last_check_time}}constructor(){this.agentClient=new H,this.messageBuffer=new V,this.initialRoleName=v.resolveRoleMemoryDirectoryName(),this.hasRoleName=!!process.env.AWS_ROLE_NAME;const e=v.resolveMemoryStorePaths();this.memoryStore=new Q(this.agentClient),this.roleMemoryStore=new N(e.rolePath),this.sessionContextMemoryStore=new N(f.join(f.dirname(e.rolePath),"..","session_context")),this.isSubAgent=process.env.AWS_SUB_AGENT==="true",this.contextManager=new X(this.sessionContextMemoryStore),this.server=new U({name:z,version:G},{capabilities:{tools:{}}}),this.setupHandlers()}setupHandlers(){this.server.setRequestHandler(W,async()=>({tools:this.isSubAgent?D.filter(t=>F.has(t.name)):D})),this.server.setRequestHandler(q,async e=>{const{name:t,arguments:r}=e.params;try{const s=await this.handleToolCall(t,r);return{content:this.buildToolResultContent(s)}}catch(s){const i=s instanceof Error?s.message:String(s),n=s instanceof Z?{error:i,...s.details}:{error:i};return a.error("[McpServer] \u5DE5\u5177\u8C03\u7528\u5F02\u5E38: tool=%s, error=%s, stack=%s",t,i,s instanceof Error?s.stack:"(no stack)"),{content:[{type:"text",text:JSON.stringify(n,null,2)}],isError:!0}}})}buildToolResultContent(e){if(e&&typeof e=="object"&&!Array.isArray(e)){const t=e;if(typeof t.image=="string"&&typeof t.mimeType=="string")return[{type:"image",data:t.image,mimeType:t.mimeType}]}return[{type:"text",text:JSON.stringify(e,null,2)}]}async handleToolCall(e,t){const r=t?._aws_sub_agent===!0,s=t?._aws_silent_poll===!0,i=t?._aws_force_inject===!0,n={...t};delete n._aws_sub_agent,delete n._aws_silent_poll,delete n._aws_force_inject;const o=r?null:this.agentClient.getStatusReporter();o&&!s&&o.reportToolUse(e,this.sanitizeToolUseArgs(e,n));try{const l=await this.executeToolCall(e,n,{forceInject:i});if(o&&!s){const h=this.stripAutoDelegateForReporting(l);h!==null&&(o.reportToolResult(h),o.reportThinking())}return l}catch(l){throw o&&!s&&o.reportToolError(l),l}}async executeToolCall(e,t,r={}){if(this.isSubAgent&&!F.has(e))throw new Error(`Sub-agent is not allowed to call tool: ${e}`);switch(e){case"get_colleague":return await this.agentClient.discoverColleagues();case"get_group_rooms":return await this.agentClient.discoverGroupRooms();case"get_profile":return await this.agentClient.getProfile();case"hire_colleague":return await this.handleHireColleague(t);case"hire_colleagues_batch":return await this.handleHireColleaguesBatch(t);case"send_group":return await this.handleSendGroup(t);case"send_private":return await this.handleSendPrivate(t);case"poll_message":return await this.handlePollMessage();case"get_message":return this.handleGetMessage(r.forceInject===!0);case"get_dm_history":return await this.handleGetDmHistory(t);case"get_group_history":return await this.handleGetGroupHistory(t);case"my_task":return await this.agentClient.getMyTasks();case"create_task_instance_comment":return await this.handleCreateTaskInstanceComment(t);case"submit_task_result":return await this.handleSubmitTaskResult(t);case"start_task_rollback":return await this.handleStartTaskRollback(t);case"finish_task_rollback":return await this.handleFinishTaskRollback(t);case"reject_task":return await this.handleRejectTask(t);case"terminate_task":return await this.handleTerminateTask(t);case"create_memory":return await this.handleCreateMemory(t);case"read_memory":return await this.handleReadMemory(t);case"update_memory":return await this.handleUpdateMemory(t);case"delete_memory":return await this.handleDeleteMemory(t);case"search_memory":return await this.handleSearchMemory(t);case"list_memories":return await this.handleListMemories(t);case"get_memory_stats":return await this.handleGetMemoryStats(t);case"list_memories_by_file":return await this.handleListMemoriesByFile(t);case"abandon_memory_update":return await this.handleAbandonMemoryUpdate(t);case"memory_recurrence":return await this.handleMemoryRecurrence(t);case"memory_recurrence_complete":return await this.handleMemoryRecurrenceComplete(t);case"get_debug_log_config":return await this.agentClient.getDebugLogConfig();case"query_debug_logs":return await this.agentClient.queryDebugLogs(t);case"query_file_changes_history":return await this.agentClient.queryFileChangesHistory(t);default:throw new Error(`Unknown tool: ${e}`)}}static MEMORY_TYPES=["recently_memory","agent_memory","project_memory","session_context"];static MEMORY_TOOL_NAMES=new Set(["create_memory","read_memory","update_memory","delete_memory","search_memory","list_memories","get_memory_stats","list_memories_by_file","abandon_memory_update","memory_recurrence","memory_recurrence_complete"]);static findAgentsworkDirSync(e){let t=f.resolve(e);for(;;){if($.existsSync(f.join(t,".agentswork")))return f.join(t,".agentswork");const r=f.dirname(t);if(r===t)break;t=r}return f.join(f.resolve(e),".agentswork")}static sanitizeRoleDirectoryName(e){return String(e||"").trim().split("").map(r=>re.has(r)||r.charCodeAt(0)<32?"_":r).join("").replace(/^\.+|\.+$/g,"").trim()||"default-role"}static resolveRoleMemoryDirectoryName(){return v.sanitizeRoleDirectoryName(process.env.AWS_ROLE_NAME||"")}static buildRoleMemoryStorePath(e){const t=process.env.AWS_WORKSPACE_PATH||process.cwd(),r=v.findAgentsworkDirSync(t);return f.join(r,"memory","memory",v.sanitizeRoleDirectoryName(e))}static resolveMemoryStorePaths(){const e=String(process.env.AWS_MEMORY_STORE_PATH||"").trim();if(e)return{instancePath:e,rolePath:e};const t=process.env.AWS_WORKSPACE_PATH||process.cwd(),r=v.findAgentsworkDirSync(t),s=String(process.env.AWS_INSTANCE_MEMORY_STORE_PATH||"").trim()||f.join(r,"memory","server-managed"),i=String(process.env.AWS_ROLE_MEMORY_STORE_PATH||"").trim()||f.join(r,"memory","memory",v.resolveRoleMemoryDirectoryName());return{instancePath:s,rolePath:i}}getRequiredString(e,t){const r=e[t];if(typeof r!="string"||r.trim().length===0)throw new Error(`${t} is required`);return r}getOptionalString(e,t){const r=e[t];return typeof r=="string"?r:void 0}getOptionalNumber(e,t){const r=e[t];return typeof r=="number"?r:void 0}getOptionalStringArray(e,t){const r=e[t];return Array.isArray(r)?r.map(s=>String(s)):void 0}getOptionalMemoryType(e){const t=e.memory_type;if(t!==void 0)return this.parseMemoryType(t)}parseMemoryType(e){if(typeof e!="string")throw new Error(`Invalid memory_type: ${String(e)}`);const t=e.trim();if(!this.isMemoryType(t))throw new Error(`Invalid memory_type: ${e}`);return t}isMemoryType(e){return v.MEMORY_TYPES.some(t=>t===e)}getMemoryStoreForType(e){return this.memoryStore}async readMemoryFromScopedStores(e){if(e.memory_type)return await this.memoryStore.readMemory(e);const t=await this.memoryStore.readMemory({...e,memory_type:"project_memory"}).catch(()=>null);return t||await this.memoryStore.readMemory(e)}async backupProjectMemoryToLocal(e){try{const t=await this.memoryStore.readMemory({uri:e.uri,memory_type:"project_memory"});t&&(await this.roleMemoryStore.deleteMemory({uri:e.uri,memory_type:"project_memory"}).catch(()=>{}),await this.roleMemoryStore.createMemory(t))}catch(t){a.warn("[McpServer] backupProjectMemoryToLocal \u5931\u8D25: uri=%s",e.uri,t)}}async removeProjectMemoryLocalBackup(e){try{await this.roleMemoryStore.deleteMemory({uri:e,memory_type:"project_memory"})}catch(t){a.warn("[McpServer] removeProjectMemoryLocalBackup \u5931\u8D25: uri=%s",e,t)}}async findMemoryStoreForMutation(e){return e.memory_type?{store:this.memoryStore,memory_type:e.memory_type}:await this.memoryStore.readMemory({uri:e.uri,memory_type:"project_memory"}).catch(()=>null)?{store:this.memoryStore,memory_type:"project_memory"}:{store:this.memoryStore}}async reportMemoryStatsToServer(){const e=await this.memoryStore.getStats();try{await this.agentClient.reportMemoryStats(e)}catch(t){a.warn("[McpServer] \u4E0A\u62A5 memory \u7EDF\u8BA1\u5931\u8D25:",t)}}sanitizeToolUseArgs(e,t){if(!v.MEMORY_TOOL_NAMES.has(e))return t;const r={},s=this.getOptionalString(t,"uri"),i=this.getOptionalString(t,"memory_type"),n=this.getOptionalNumber(t,"limit");return s&&(r.uri=s),i&&(r.memory_type=i),typeof n=="number"&&(r.limit=n),e==="search_memory"&&(r.queryProvided=typeof t.query=="string"&&t.query.length>0,t.keyword_mode!==void 0&&(r.keyword_mode=t.keyword_mode)),r}stripAutoDelegateForReporting(e){if(!e||typeof e!="object")return e;const t=e,r=Array.isArray(t.directMessages)?t.directMessages:[],s=Array.isArray(t.groupMessages)?t.groupMessages:[],i=l=>!!l&&typeof l=="object"&&"_acodeAutoDelegate"in l;if(!r.some(i))return e;const o=r.filter(l=>!i(l));return o.length===0&&s.length===0?null:{...t,directMessages:o}}async handleCreateMemory(e){const t=this.normalizeBoundFiles(this.getOptionalStringArray(e,"bound_files"));await this.validateBoundFilesExist(t);let r,s;if(t&&t.length>0){r={};for(const o of t){const l=await this.calculateFileMd5(o);l&&(r[o]=l)}s=new Date().toISOString()}const i={memory_type:this.parseMemoryType(this.getRequiredString(e,"memory_type")),uri:this.getRequiredString(e,"uri"),title:this.getOptionalString(e,"title"),content:this.getRequiredString(e,"content"),keywords:this.getOptionalStringArray(e,"keywords"),bound_files:t,file_md5_map:r,last_check_time:s},n=await this.memoryStore.createMemory(i);return i.memory_type==="project_memory"&&this.backupProjectMemoryToLocal(i).catch(o=>{a.warn("[McpServer] \u5907\u4EFD project_memory \u5230\u672C\u5730\u5931\u8D25:",o)}),await this.reportMemoryStatsToServer(),this.toMemoryWriteResult(n)}async handleReadMemory(e){const t={uri:this.getRequiredString(e,"uri"),memory_type:this.getOptionalMemoryType(e)};return await this.readMemoryFromScopedStores(t)}async handleUpdateMemory(e){const t=typeof e.old_string=="string"||typeof e.new_string=="string",r=typeof e.old_string=="string"&&typeof e.new_string=="string",s=this.getOptionalString(e,"append");if(t&&!r)throw new Error("old_string and new_string must be provided together");const i={uri:this.getRequiredString(e,"uri"),memory_type:this.getOptionalMemoryType(e),title:this.getOptionalString(e,"title"),old_string:this.getOptionalString(e,"old_string"),new_string:this.getOptionalString(e,"new_string"),append:s,keywords:this.getOptionalStringArray(e,"keywords"),bound_files:this.normalizeBoundFiles(this.getOptionalStringArray(e,"bound_files"))},n=await this.findMemoryStoreForMutation(i),o=await n.store.readMemory({uri:i.uri,memory_type:n.memory_type??i.memory_type});i.bound_files!==void 0?await this.validateBoundFilesExist(i.bound_files):o?.bound_files&&o.bound_files.length>0&&await this.validateBoundFilesExist(o.bound_files);const l=i.bound_files??o?.bound_files;let h,m;if(l&&l.length>0){h={};for(const u of l){const p=await this.calculateFileMd5(u);p&&(h[u]=p)}m=new Date().toISOString()}const d=await n.store.updateMemory({...i,memory_type:n.memory_type??i.memory_type,file_md5_map:h,last_check_time:m});if(n.memory_type==="project_memory"&&this.backupProjectMemoryToLocal({...i,memory_type:"project_memory",file_md5_map:h,last_check_time:m}).catch(u=>{a.warn("[McpServer] \u5907\u4EFD project_memory \u66F4\u65B0\u5230\u672C\u5730\u5931\u8D25:",u)}),await this.reportMemoryStatsToServer(),n.memory_type==="project_memory"&&o?.memory_status==="updating")try{await this.memoryStore.releaseMemoryClaim(i.uri),this.activeLeaseUris.delete(i.uri),this.activeLeaseUris.size===0&&this.stopLeaseRenewal()}catch(u){a.warn("[McpServer] \u91CA\u653E memory claim \u5931\u8D25: uri=%s, error=%s",i.uri,u instanceof Error?u.message:String(u))}return this.toMemoryWriteResult(d)}async handleDeleteMemory(e){const t=typeof e.uri=="string"?e.uri:void 0,r=Array.isArray(e.memories)?e.memories:void 0;if(t&&r&&r.length>0)throw new Error("delete_memory \u4E0D\u652F\u6301\u540C\u65F6\u4F20\u5165 uri \u548C memories\uFF0C\u8BF7\u4E8C\u9009\u4E00");if(!t&&(!r||r.length===0))throw new Error("delete_memory \u9700\u8981 uri \u6216 memories \u53C2\u6570");if(t){const o=this.getOptionalMemoryType(e);return{deleted:await this.deleteMemorySingle(t,o)}}let s=0;const i=[],n=[];for(let o=0;o<r.length;o++){const l=r[o];if(typeof l!="object"||l===null){n.push({uri:String(l),reason:`memories[${o}] \u4E0D\u662F\u5BF9\u8C61`});continue}const h=l,m=typeof h.uri=="string"?h.uri:"";if(!m){n.push({uri:"",reason:`memories[${o}].uri \u7F3A\u5931`});continue}const d=typeof h.memory_type=="string"?this.parseMemoryType(h.memory_type):void 0;try{await this.deleteMemorySingle(m,d,!0)?s++:i.push(m)}catch(u){n.push({uri:m,reason:u instanceof Error?u.message:String(u)})}}return s>0&&await this.reportMemoryStatsToServer(),{deleted:s,not_found:i,failed:n}}async deleteMemorySingle(e,t,r=!1){const s={uri:e,memory_type:t},i=await this.findMemoryStoreForMutation(s),n=i.memory_type??s.memory_type,o=await i.store.deleteMemory({...s,memory_type:n});return o&&(n==="project_memory"&&this.removeProjectMemoryLocalBackup(e).catch(l=>{a.warn("[McpServer] \u5220\u9664 project_memory \u672C\u5730\u5907\u4EFD\u5931\u8D25:",l)}),r||await this.reportMemoryStatsToServer()),o}async handleSearchMemory(e){const t=this.getOptionalString(e,"scope"),r=t==="children"||t==="all"?t:"own",s=this.getOptionalString(e,"keyword_mode"),i=s==="all"?"all":s==="any"?"any":void 0,n={query:this.getRequiredString(e,"query"),limit:this.getOptionalNumber(e,"limit"),memory_type:this.getOptionalMemoryType(e),keywords:this.getOptionalStringArray(e,"keywords"),keyword_mode:i,scope:r};if(r==="children")return await this.memoryStore.searchMemory(n);const o=await this.searchOwnMemories(n);if(r==="own")return o;const l=await this.memoryStore.searchMemory({...n,scope:"children"});return this.mergeSearchResults(o,l,n.limit)}async searchOwnMemories(e){return await this.memoryStore.searchMemory(e)}mergeSearchResults(e,t,r){const s=new Set,i=typeof r=="number"&&r>0?r:10,n=[...e.results,...t.results].filter(o=>{const l=o.uri;return s.has(l)?!1:(s.add(l),!0)}).sort((o,l)=>l.updatedAt.localeCompare(o.updatedAt)).slice(0,i);return{query:e.query||t.query,results:n}}async handleListMemories(e){const t=this.getRequiredString(e,"memory_type");if(t==="project_memory"||t==="session_context")throw new Error(`Invalid memory_type: ${t}`);return await this.memoryStore.listByType(t)}async handleGetMemoryStats(e){const t=await this.memoryStore.getStats(),r=this.getOptionalMemoryType(e);return r?{memory_type:r,total:t.by_type[r].count,by_type:{[r]:t.by_type[r]}}:t}async handleListMemoriesByFile(e){const t=this.getRequiredString(e,"file_path"),r=this.normalizeBoundFilePath(t),s=this.getOptionalMemoryType(e),i=this.getOptionalString(e,"scope"),n=i==="own"||i==="children"?i:"all",o=async()=>await this.memoryStore.listByFile(r,{memory_type:s,scope:"children"}).catch(()=>[]);if(n==="children"){const u=await o();return{file_path:r,count:u.length,memories:u.map(p=>this.toMemoryRecordWithMetadata(p))}}const l=await this.collectOwnMemoriesByFile(r,s);if(n==="own")return{file_path:r,count:l.length,memories:l.map(u=>this.toMemoryRecordWithMetadata(u))};const h=await o(),m=new Set(l.map(u=>u.id)),d=[...l];for(const u of h)m.has(u.id)||(d.push(u),m.add(u.id));return d.sort((u,p)=>p.updatedAt.localeCompare(u.updatedAt)),{file_path:r,count:d.length,memories:d.map(u=>this.toMemoryRecordWithMetadata(u))}}mergeIdDedupe(e,t){const r=new Set;for(const i of e)i.id&&r.add(i.id);const s=[...e];for(const i of t)i.id&&!r.has(i.id)&&(s.push(i),r.add(i.id));return s.sort((i,n)=>n.updatedAt.localeCompare(i.updatedAt)),s}async searchChildMemoriesByFileLocal(e,t){const r=process.env.AWS_WORKSPACE_PATH||process.cwd(),s=this.normalizeBoundFilePath(e),n=(s.startsWith("./")?s.substring(2):s).split("/"),o=[],l=new Set,{access:h,readdir:m,readFile:d}=await import("node:fs/promises");for(let u=n.length-1;u>=1;u--){const p=n.slice(0,u),b="./"+n.slice(u).join("/"),A=f.join(r,...p);if(A===r)continue;const c=f.join(A,".agentswork");try{await h(c)}catch{continue}const g=f.join(c,"memory","memory");let R;try{R=(await m(g,{withFileTypes:!0})).filter(_=>_.isDirectory()).map(_=>_.name)}catch{continue}for(const M of R){const _=f.join(g,M);let C;try{C=await m(_)}catch{continue}for(const y of C){if(!y.endsWith(".json"))continue;const w=f.join(_,y);let S;try{S=await d(w,"utf-8")}catch{continue}let k;try{k=JSON.parse(S)}catch{continue}if(k.by_uri)for(const[E,I]of Object.entries(k.by_uri)){if(!I)continue;const O=I.id||E;l.has(O)||t&&I.memory_type!==t||I.bound_files&&I.bound_files.length>0&&I.bound_files.some(B=>this.normalizeBoundFilePath(B)===b)&&(l.add(O),o.push({...I,uri:I.uri||E}))}}}}return o.sort((u,p)=>p.updatedAt.localeCompare(u.updatedAt)),o}async collectOwnMemoriesByFile(e,t){return await this.memoryStore.listByFile(e,{memory_type:t})}async handleAbandonMemoryUpdate(e){const t=this.getRequiredString(e,"uri"),r=this.getOptionalMemoryType(e),s=await this.memoryStore.readMemory({uri:t,memory_type:r});return s?.bound_files&&s.bound_files.length>0&&await this.validateBoundFilesExist(s.bound_files),await this.memoryStore.releaseMemoryClaim(t),s?.memory_type==="project_memory"&&this.backupProjectMemoryToLocal({uri:t,memory_type:"project_memory"}).catch(i=>{a.info(`[McpServer] abandon_memory_update: \u540C\u6B65\u672C\u5730\u5907\u4EFD\u5931\u8D25: ${t}`,i)}),this.activeLeaseUris.delete(t),this.activeLeaseUris.size===0&&this.stopLeaseRenewal(),{success:!0,uri:t,message:"Memory \u66F4\u65B0\u72B6\u6001\u5DF2\u6E05\u9664"}}async handleMemoryRecurrence(e){const t=Math.max(1,e?.limit??10);try{((await this.memoryStore.markExpiredMemoriesRecalling()).uris?.length??0)>0&&this.startLeaseRenewal()}catch(l){a.warn("[McpServer] \u539F\u5B50\u8BA4\u9886\u8FC7\u671F\u8BB0\u5FC6\u5931\u8D25: %s",l instanceof Error?l.message:String(l))}const r=await this.memoryStore.listExpiredRecentlyMemories();if(r.length===0)return{memories:[],count:0,limit:t,remaining:0,totalExpired:0,message:"\u6CA1\u6709\u5F85\u56DE\u5FC6\u7684\u5373\u5C06\u9057\u5FD8\u8BB0\u5FC6\u3002"};const i=[...r].sort((l,h)=>{const m=new Date(l.expiresAt||l.createdAt||0).getTime(),d=new Date(h.expiresAt||h.createdAt||0).getTime();return m-d}).slice(0,t),n=Math.max(0,r.length-i.length);return{memories:i.map(l=>({uri:l.uri,title:l.title,domain:l.domain,path:l.path,memory_status:"recalling",contentPreview:typeof l.content=="string"&&l.content.length>200?l.content.substring(0,200)+"...":l.content,createdAt:l.createdAt,updatedAt:l.updatedAt})),count:i.length,limit:t,remaining:n,totalExpired:r.length,message:n>0?`\u672C\u6B21\u5904\u7406 ${i.length} \u6761\u5373\u5C06\u9057\u5FD8\u7684\u8BB0\u5FC6\uFF08\u6700\u65E9\u8FC7\u671F\u4F18\u5148\uFF09\uFF0C\u5269\u4F59 ${n} \u6761\u5F85\u5904\u7406\u3002
|
|
4
4
|
\u8BF7\u5BA1\u67E5\u540E\u51B3\u5B9A\uFF08update_memory \u7EED\u671F\uFF0CTTL \xD72 / \u4E0D\u5904\u7406\uFF09\uFF0C
|
|
5
|
-
\u5B8C\
|
|
5
|
+
\u672C\u6279\u5BA1\u67E5\u5B8C\u6BD5\u540E\u8C03\u7528 memory_recurrence_complete(uris=[\u672C\u6279\u786E\u5B9A\u5220\u9664\u7684URI]) \u6E05\u7406\uFF0C\u518D\u8C03 memory_recurrence \u5904\u7406\u4E0B\u4E00\u6279\u3002`:`\u5DF2\u5904\u7406\u5168\u90E8 ${i.length} \u6761\u5373\u5C06\u9057\u5FD8\u7684\u8BB0\u5FC6\u3002
|
|
6
6
|
\u8BF7\u5BA1\u67E5\u540E\u51B3\u5B9A\uFF08update_memory \u7EED\u671F\uFF0CTTL \xD72 / \u4E0D\u5904\u7406\uFF09\uFF0C
|
|
7
|
-
\u5B8C\
|
|
7
|
+
\u672C\u6279\u5BA1\u67E5\u5B8C\u6BD5\u540E\u8C03\u7528 memory_recurrence_complete(uris=[\u672C\u6279\u786E\u5B9A\u5220\u9664\u7684URI]) \u6E05\u7406\u3002`}}async handleMemoryRecurrenceComplete(e){let t={deleted:0,uris:[]};try{t=await this.memoryStore.clearRecallingExpiredMemories(e?.uris)}catch(s){a.warn("[McpServer] \u6E05\u7406\u56DE\u5FC6\u4E2D\u8BB0\u5FC6\u5931\u8D25: %s",s instanceof Error?s.message:String(s))}await this.reportMemoryStatsToServer();const r=t.deleted??0;return{deleted:r,uris:t.uris??[],message:r===0?"\u6CA1\u6709\u5F85\u758F\u7406\u7684\u56DE\u5FC6\u4E2D\u8BB0\u5FC6\u3002":`\u5DF2\u6E05\u7406 ${r} \u6761\u5DF2\u8FC7\u671F\u8FD1\u671F\u8BB0\u5FC6\u3002`}}async fetchRecentMessages(){const[e,t]=await Promise.all([this.agentClient.getDmHistory(void 0,200).catch(()=>({messages:[],count:0})),this.agentClient.getGroupHistory(200).catch(()=>({messages:[],count:0}))]),r=[...e.messages,...t.messages];return r.sort((s,i)=>new Date(s.timestamp).getTime()-new Date(i.timestamp).getTime()),r}async handleSendGroup(e){if(!e.content||typeof e.content!="string")throw new Error("content is required");return this.recordMessageTokenUsage(e.content).catch(t=>a.warn("[McpServer] Failed to record token usage",t)),await this.agentClient.sendGroupMessage(e.content,e.projectId,e.roomId)}async recordMessageTokenUsage(e){try{const t=await this.agentClient.getProfile().catch(()=>null);if(!t?.runtimeSessionId)return;const r=this.contextManager.estimateTokens(e);await this.contextManager.recordUsage(t.runtimeSessionId,{input:0,output:r})}catch{}}async handleHireColleague(e){if(!e.workspacePath||typeof e.workspacePath!="string")throw new Error("workspacePath is required");return await this.agentClient.hireColleague(e)}async handleHireColleaguesBatch(e){if(!Array.isArray(e.items)||e.items.length===0)throw new Error("items is required and must contain at least one hire item");return e.items.forEach((t,r)=>{if(!t.workspacePath||typeof t.workspacePath!="string")throw new Error(`items[${r}].workspacePath is required`)}),await this.agentClient.hireColleaguesBatch(e)}async handleSendPrivate(e){if(!e.targetId||typeof e.targetId!="string")throw new Error("targetId is required");if(!e.content||typeof e.content!="string")throw new Error("content is required");return this.recordMessageTokenUsage(e.content).catch(t=>a.warn("[McpServer] Failed to record token usage",t)),await this.agentClient.sendDirectMessage(e.targetId,e.content,e.waitReply,e.replyToCallId,e.timeoutMs)}async handleCreateTaskInstanceComment(e){const t=this.getRequiredString(e,"taskInstanceId"),r=this.getRequiredString(e,"content");return await this.agentClient.createTaskInstanceComment({taskInstanceId:t,content:r})}async prependMemoryNotification(e,t){const r=await t();return r?(e.directMessages.unshift(r),!0):!1}async handlePollMessage(){if(a.info("[McpServer] handlePollMessage \u88AB\u8C03\u7528"),this.pendingPollMessage)return a.info("[McpServer] poll_message \u5DF2\u6709\u8FDB\u884C\u4E2D\u7684\u8C03\u7528\uFF0C\u7B49\u5F85\u5176\u5B8C\u6210"),await this.pendingPollMessage;this.pendingPollMessage=(async()=>await this.doPollMessage())();try{return await this.pendingPollMessage}finally{this.pendingPollMessage=null}}async doPollMessage(){a.info("[McpServer] doPollMessage \u88AB\u8C03\u7528");const e=await this.buildTodoBlockNotification();if(e)return this.buildPollResult({directMessages:[e],groupMessages:[]});await this.hydrateUnreadMessagesFromServer({blockIfEmpty:!1,includePipelineTasks:!0}),await this.hydrateBrowserListenerEvents();const t=await this.buildBackgroundTaskNotification(),r=this.messageBuffer.get();if(r.directMessages.length>0||r.groupMessages.length>0)return t&&r.directMessages.unshift(t),this.buildPollResult(r);if(t)return this.buildPollResult({directMessages:[t],groupMessages:[]});const s=await this.checkAllLocalNonUrgentNotifications();if(s.length>0)return this.buildPollResult({directMessages:s,groupMessages:[]});let i=!1,n=0;for(;;){if(!i){const p=this.agentClient.getStatusReporter();if(p){const T=p.getCurrentStatus();T.status==="tool_using"&&T.actionDetail!=null&&T.actionDetail.includes("poll_message")||p.reportToolUse("poll_message",{}),i=!0}}const o=await this.messageBuffer.poll(ee);if(o.directMessages.length>0||o.groupMessages.length>0)return this.buildPollResult(o);if(a.debug("[McpServer] poll \u8D85\u65F6\uFF0C\u68C0\u67E5\u6D4F\u89C8\u5668\u76D1\u542C\u5668\u4E8B\u4EF6"),await this.hydrateBrowserListenerEvents()){const p=this.messageBuffer.get();if(p.directMessages.length>0||p.groupMessages.length>0)return a.info("[McpServer] \u76D1\u542C\u5668\u4E8B\u4EF6\u5DF2\u6CE8\u5165\uFF0Cpoll_message \u8FD4\u56DE %d \u6761\u79C1\u4FE1",p.directMessages.length),this.buildPollResult(p)}if(n++,n<te)continue;n=0;const h=await this.buildTodoBlockNotification();if(h)return this.buildPollResult({directMessages:[h],groupMessages:[]});await this.hydrateUnreadMessagesFromServer({blockIfEmpty:!1,includePipelineTasks:!0});const m=await this.buildBackgroundTaskNotification(),d=this.messageBuffer.get();if(d.directMessages.length>0||d.groupMessages.length>0)return m&&d.directMessages.unshift(m),this.buildPollResult(d);if(m)return this.buildPollResult({directMessages:[m],groupMessages:[]});const u=await this.checkAllLocalNonUrgentNotifications(!1);if(u.length>0)return this.buildPollResult({directMessages:u,groupMessages:[]})}}async checkAllLocalNonUrgentNotifications(e=!0){const t=[],r=await this.buildMemoryRecurrenceNotification();if(r&&t.push(r),e){const i=await this.buildMemoryFileChangeNotification();i&&t.push(i)}const s=await this.buildMemoryCleanupNotification();return s&&t.push(s),t}buildPollResult(e,t=!0){return{directMessages:e.directMessages,groupMessages:e.groupMessages,fromBuffer:t,systemMessages:[]}}parsePositiveIntegerEnv(e,t){const r=process.env[e];if(!r||!r.trim())return t;const s=Number.parseInt(r,10);return!Number.isFinite(s)||s<=0?(a.warn(`[McpServer] ${e} \u65E0\u6548\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C ${t}ms`),t):s}sleep(e){return e<=0?Promise.resolve():new Promise(t=>setTimeout(t,e))}async buildMemoryCleanupNotification(){try{const e=await this.memoryStore.getStats(),t=Object.entries(e.by_type).filter(([,o])=>o.listable&&o.exceeded),r=Object.entries(e.by_type).flatMap(([o,l])=>l.listable?Object.entries(l.by_domain).filter(([,h])=>h.exceeded).map(([h,m])=>({memoryType:o,domain:h,domainStats:m})):[]);if(t.length===0&&r.length===0)return null;const s=t.map(([o,l])=>`${o} \u5F53\u524D ${l.domainCount} \u4E2A URI domain \u7C7B\u578B\uFF0C\u5EFA\u8BAE\u4E0A\u9650 ${l.limit} \u4E2A\uFF0C\u786C\u4E0A\u9650 ${l.hardLimit} \u4E2A`),i=r.map(({memoryType:o,domain:l,domainStats:h})=>`${o}/${l} \u7C7B\u578B\u4E0B\u5F53\u524D ${h.count} \u6761 memory\uFF0C\u5EFA\u8BAE\u4E0A\u9650 ${h.limit} \u6761\uFF0C\u786C\u4E0A\u9650 ${h.hardLimit} \u6761`),n=["\u8BF7\u8C03\u7528 get_memory_stats \u67E5\u770B\u5BB9\u91CF\u8BE6\u60C5","\u8C03\u7528 list_memories \u6309\u7C7B\u578B\u67E5\u770B\u8D85\u9650\u8BB0\u5FC6","\u5220\u9664\u4E0D\u518D\u9700\u8981\u7684 recently_memory","\u66F4\u65B0 agent_memory \u7EED\u671F\uFF08TTL \xD72\uFF09\u6216\u5220\u9664\u8FC7\u671F\u9879"].join("\uFF1B");return{msgId:`memory-cleanup-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:this.getCurrentAgentId()||void 0,content:`\u672C\u5730 memory \u5DF2\u8D85\u8FC7\u5EFA\u8BAE\u5BB9\u91CF\uFF0C\u9700\u8981\u6574\u7406\u3002${[...s,...i].join("\uFF1B")}\u3002${n}\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_cleanup",uris:r.map(o=>`${o.memoryType}/${o.domain}`)}}}catch(e){return a.warn("[McpServer] \u6784\u5EFA\u672C\u5730 memory \u6574\u7406\u63D0\u9192\u5931\u8D25: %s",e instanceof Error?e.message:String(e)),null}}async buildMemoryRecurrenceNotification(){try{const e=await this.memoryStore.listExpiredRecentlyMemories();if(e.length===0)return null;const t=this.getCurrentAgentId();if(!t)return null;const r=e.filter(i=>i.memory_status==="recalling"),s=e.filter(i=>!r.includes(i));if(r.length>0){const i=r.slice(0,5).map(n=>n.uri).join(`
|
|
8
8
|
`);return{msgId:`memory-recurrence-pending-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:t,content:`\u5B58\u5728\u5F85\u758F\u7406\u7684\u5373\u5C06\u9057\u5FD8\u8BB0\u5FC6\uFF08\u5171 ${r.length} \u6761\uFF09\uFF0C\u8BF7\u901A\u8FC7 memory_recurrence \u83B7\u53D6\u8FDB\u884C\u6574\u7406\u3002
|
|
9
9
|
|
|
10
10
|
\u5F85\u758F\u7406\u8BB0\u5FC6\uFF1A
|
|
11
11
|
${i}${r.length>5?`
|
|
12
|
-
...\u53CA\u5176\u4ED6 ${r.length-5} \u6761`:""}`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_expiration",uris:r.map(
|
|
13
|
-
`);return{msgId:`memory-recurrence-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:t,content:`\u6709 ${
|
|
12
|
+
...\u53CA\u5176\u4ED6 ${r.length-5} \u6761`:""}`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_expiration",uris:r.map(n=>n.uri)}}}if(s.length>0){const i=s.slice(0,5).map(n=>n.uri).join(`
|
|
13
|
+
`);return{msgId:`memory-recurrence-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:t,content:`\u6709 ${s.length} \u6761\u5373\u5C06\u9057\u5FD8\u7684\u8BB0\u5FC6\u5F97\u6574\u7406\uFF0C\u8BF7\u4F7F\u7528 memory_recurrence(limit=10) \u5206\u6279\u5904\u7406\uFF08\u6700\u65E9\u8FC7\u671F\u4F18\u5148\uFF0C\u6BCF\u6B21 10 \u6761\uFF09\u3002
|
|
14
14
|
|
|
15
15
|
\u5373\u5C06\u9057\u5FD8\u7684\u8BB0\u5FC6\uFF1A
|
|
16
|
-
${i}${
|
|
17
|
-
...\u53CA\u5176\u4ED6 ${
|
|
16
|
+
${i}${s.length>5?`
|
|
17
|
+
...\u53CA\u5176\u4ED6 ${s.length-5} \u6761`:""}`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_expiration",uris:s.map(n=>n.uri)}}}return null}catch(e){return a.warn("[McpServer] \u6784\u5EFA\u8FD1\u671F\u8BB0\u5FC6\u8FC7\u671F\u56DE\u5FC6\u901A\u77E5\u5931\u8D25: %s",e instanceof Error?e.message:String(e)),null}}async buildMemoryFileChangeNotification(){if(a.info(`[McpServer] buildMemoryFileChangeNotification \u88AB\u8C03\u7528: hasRoleName=${this.hasRoleName}, agentId=${this.getCurrentAgentId()??"(\u7A7A)"}`),!this.hasRoleName)return a.info("[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B\u8DF3\u8FC7: hasRoleName=false"),null;try{const e=this.getCurrentAgentId();if(!e)return a.info("[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B\u8DF3\u8FC7: agentId \u4E3A\u7A7A"),null;const t=await this.memoryStore.listByType("project_memory"),r=t.filter(c=>c.memory_status==="updating"&&c.updating_agent_id===e);if(r.length>0){this.startLeaseRenewal();const c=await this.checkMemoriesFileChanges(r);if(c.length>0){for(const S of c){const k=r.find(E=>E.id===S.memoryId);k&&await this.memoryStore.updateMemory({uri:k.uri,memory_type:"project_memory",memory_status:"updating",updating_agent_id:e,file_md5_map:k.file_md5_map,last_check_time:k.last_check_time,bound_files:k.bound_files})}const y=Math.min(c.length,5),w=c.slice(0,5).map(S=>`- ${S.memoryUri} (\u6587\u4EF6: ${S.changedFiles.join(", ")})`).join(`
|
|
18
18
|
`);return{msgId:`memory-file-change-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:e,content:`\u68C0\u6D4B\u5230\u4EE5\u4E0B ${y} \u4E2A\u5904\u4E8E\u66F4\u65B0\u4E2D\u7684 Memory \u7ED1\u5B9A\u7684\u6587\u4EF6\u518D\u6B21\u53D8\u66F4\uFF0C\u5DF2\u66F4\u65B0 MD5 \u8BB0\u5F55\uFF1A
|
|
19
19
|
|
|
20
20
|
${w}
|
|
21
21
|
|
|
22
|
-
\u8BF7\u8C03\u7528 read_memory \u67E5\u770B\u6700\u65B0\u5185\u5BB9\u5E76\u8C03\u7528 update_memory \u66F4\u65B0\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:c.slice(0,5).map(S=>S.memoryUri),fileChanges:c.slice(0,5).map(S=>{const k=r.find(E=>E.id===S.memoryId);return{uri:S.memoryUri,boundFiles:k?.bound_files??[],fileStatuses:S.fileStatuses,changedFiles:S.changedFiles}})}}}const g=r,
|
|
22
|
+
\u8BF7\u8C03\u7528 read_memory \u67E5\u770B\u6700\u65B0\u5185\u5BB9\u5E76\u8C03\u7528 update_memory \u66F4\u65B0\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:c.slice(0,5).map(S=>S.memoryUri),fileChanges:c.slice(0,5).map(S=>{const k=r.find(E=>E.id===S.memoryId);return{uri:S.memoryUri,boundFiles:k?.bound_files??[],fileStatuses:S.fileStatuses,changedFiles:S.changedFiles}})}}}const g=r,R=new Map;for(const y of g.slice(0,5))R.set(y.uri,await this.computeBoundFileStatuses(y));const M=g.filter(y=>{const w=R.get(y.uri);return!w||w.length===0?!1:w.some(S=>S.status==="content_changed"||S.status==="not_found")}),_=g.filter(y=>!M.includes(y));if(_.length>0){a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step1: ${_.length} \u4E2A updating memory \u7ED1\u5B9A\u6587\u4EF6\u65E0\u771F\u5B9E\u53D8\u66F4\uFF0C\u81EA\u52A8\u91CA\u653E: ${_.map(y=>y.uri).join(", ")}`);for(const y of _)try{await this.memoryStore.releaseMemoryClaim(y.uri),this.activeLeaseUris.delete(y.uri),await this.memoryStore.updateMemory({uri:y.uri,memory_type:"project_memory"})}catch(w){a.info(`[McpServer] \u81EA\u52A8\u91CA\u653E stale updating memory \u5931\u8D25: ${y.uri}`,w)}this.activeLeaseUris.size===0&&this.stopLeaseRenewal()}if(M.length===0)return a.info("[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step1: \u6240\u6709 updating memory \u7ED1\u5B9A\u6587\u4EF6\u5747\u65E0\u771F\u5B9E\u53D8\u66F4\uFF0C\u5DF2\u81EA\u52A8\u91CA\u653E\uFF0C\u8DF3\u8FC7\u59D4\u6258"),null;const C=M.slice(0,5).map(y=>`- ${y.uri} (\u6587\u4EF6: ${y.bound_files?.join(", ")||"\u672A\u77E5"})`).join(`
|
|
23
23
|
`);return a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step1: ${M.length}/${r.length} \u4E2A updating memory \u6709\u771F\u5B9E\u6587\u4EF6\u53D8\u66F4\uFF0C\u89E6\u53D1\u59D4\u6258`),{msgId:`memory-update-pending-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:e,content:`\u60A8\u6709\u4EE5\u4E0B Memory \u6B63\u5904\u4E8E\u66F4\u65B0\u4E2D\u72B6\u6001\u4F46\u5C1A\u672A\u5B8C\u6210\u66F4\u65B0\uFF1A
|
|
24
24
|
|
|
25
25
|
${C}
|
|
26
26
|
|
|
27
|
-
\u8BF7\u7EE7\u7EED\u5B8C\u6210\u66F4\u65B0\u5DE5\u4F5C\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:M.slice(0,5).map(y=>y.uri),fileChanges:M.slice(0,5).map(y=>({uri:y.uri,boundFiles:y.bound_files??[],fileStatuses:
|
|
27
|
+
\u8BF7\u7EE7\u7EED\u5B8C\u6210\u66F4\u65B0\u5DE5\u4F5C\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:M.slice(0,5).map(y=>y.uri),fileChanges:M.slice(0,5).map(y=>({uri:y.uri,boundFiles:y.bound_files??[],fileStatuses:R.get(y.uri)??[]}))}}}const s=await this.memoryStore.listByType("recently_memory"),i=await this.memoryStore.listByType("agent_memory"),n=[...s,...i],o=n.filter(c=>c.bound_files&&c.bound_files.length>0);a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step2: recently=${s.length}, agent=${i.length}, \u6709\u7ED1\u5B9A\u6587\u4EF6=${o.length}/${n.length}\u3002\u8BE6\u60C5: ${n.map(c=>`${c.uri}(bound=${c.bound_files?.length??0},md5=${Object.keys(c.file_md5_map??{}).length})`).join("; ")||"\u65E0 memory"}`);const l=new Map;for(const c of n)c.bound_files&&c.bound_files.length>0&&l.set(c.id,JSON.stringify(c.file_md5_map??{}));const h=await this.checkMemoriesFileChanges(n),m=h;a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step2: \u68C0\u6D4B\u5230\u53D8\u66F4=${h.length}`+(h.length>0?` \u53D8\u66F4\u9879: ${h.map(c=>`${c.memoryUri}(${c.changedFiles.join(",")})`).join("; ")}`:""));const d=n.filter(c=>{if(!c.bound_files||c.bound_files.length===0||h.some(M=>M.memoryId===c.id))return!1;const g=l.get(c.id),R=JSON.stringify(c.file_md5_map??{});return g!==R});if(d.length>0){a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step2: \u56DE\u5199 ${d.length} \u4E2A listable memory \u7684\u4FEE\u6B63 MD5 map`);for(const c of d)try{await this.memoryStore.updateMemory({uri:c.uri,memory_type:c.memory_type,file_md5_map:c.file_md5_map,last_check_time:c.last_check_time})}catch(g){a.info(`[McpServer] \u56DE\u5199 listable MD5 map \u5931\u8D25: ${c.uri}`,g)}}if(m.length>0){const c=m.map(g=>`- ${g.memoryUri} (\u6587\u4EF6: ${g.changedFiles.join(", ")})`).join(`
|
|
28
28
|
`);return{msgId:`memory-file-change-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:e,content:`\u68C0\u6D4B\u5230\u4EE5\u4E0B Memory \u7ED1\u5B9A\u7684\u6587\u4EF6\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u53CA\u65F6\u66F4\u65B0\uFF1A
|
|
29
29
|
|
|
30
30
|
${c}
|
|
31
31
|
|
|
32
|
-
\u8BF7\u8C03\u7528 read_memory \u67E5\u770B\u5185\u5BB9\u5E76\u8C03\u7528 update_memory \u66F4\u65B0\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:
|
|
32
|
+
\u8BF7\u8C03\u7528 read_memory \u67E5\u770B\u5185\u5BB9\u5E76\u8C03\u7528 update_memory \u66F4\u65B0\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:m.map(g=>g.memoryUri),fileChanges:m.map(g=>{const R=n.find(M=>M.id===g.memoryId);return{uri:g.memoryUri,boundFiles:R?.bound_files??[],fileStatuses:g.fileStatuses,changedFiles:g.changedFiles}})}}}const u=t.filter(c=>c.bound_files&&c.bound_files.length>0&&(c.memory_status==="normal"||!c.memory_status)&&!this.isClaimCached(c.uri)),p=t.filter(c=>c.bound_files&&c.bound_files.length>0);a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step3: project_memory \u603B\u6570=${t.length}, \u6709\u7ED1\u5B9A\u6587\u4EF6=${p.length}, \u5F85\u68C0\u6D4B(\u8FC7\u6EE4updating/claimed\u540E)=${u.length}\u3002\u88AB\u8FC7\u6EE4\u539F\u56E0: ${p.length-u.length} \u9879(memory_status=updating \u6216 isClaimCached)`);const T=new Map;for(const c of u)T.set(c.id,JSON.stringify(c.file_md5_map??{}));const b=await this.checkMemoriesFileChanges(u),A=u.filter(c=>{if(b.some(M=>M.memoryId===c.id))return!1;const g=T.get(c.id),R=JSON.stringify(c.file_md5_map??{});return g!==R&&c.file_md5_map&&Object.keys(c.file_md5_map).length>0});if(A.length>0){a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step3: \u56DE\u5199 ${A.length} \u4E2A memory \u7684\u4FEE\u6B63 MD5 map \u5230\u670D\u52A1\u7AEF\uFF08\u65E0\u57FA\u7EBF/\u952E\u7F3A\u5931\u4FEE\u590D\uFF09`);for(const c of A)try{await this.memoryStore.updateMemory({uri:c.uri,memory_type:"project_memory",file_md5_map:c.file_md5_map,last_check_time:c.last_check_time})}catch(g){a.info(`[McpServer] \u56DE\u5199\u57FA\u7EBF MD5 \u5931\u8D25: ${c.uri}`,g)}}if(a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B Step3: \u68C0\u6D4B\u5230\u53D8\u66F4=${b.length}`+(b.length>0?` \u53D8\u66F4\u9879: ${b.map(c=>`${c.memoryUri}(${c.changedFiles.join(",")})`).join("; ")}`:"")),b.length>0){const c=b.slice(0,5),g=c.map(_=>_.memoryUri);let R=!1,M=new Set;try{const _=await this.memoryStore.claimMemoryUpdate(g,v.LEASE_DURATION_MINUTES,"project_memory");M=new Set(_.claimed_uris??[]),R=!0}catch(_){a.info("[McpServer] Server claim API \u4E0D\u53EF\u7528\uFF0C\u964D\u7EA7\u5230\u672C\u5730\u76F4\u63A5\u6807\u8BB0:",_),M=new Set(g)}if(M.size>0){const _=c.filter(y=>M.has(y.memoryUri));for(const y of _){const w=t.find(S=>S.id===y.memoryId);w&&(await this.memoryStore.updateMemory({uri:w.uri,memory_type:"project_memory",memory_status:"updating",updating_agent_id:e,file_md5_map:w.file_md5_map,last_check_time:w.last_check_time,bound_files:w.bound_files}),this.activeLeaseUris.add(w.uri))}R&&M.size>0&&this.startLeaseRenewal();const C=_.map(y=>`- ${y.memoryUri} (\u6587\u4EF6: ${y.changedFiles.join(", ")})`).join(`
|
|
33
33
|
`);return{msgId:`memory-file-change-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:e,content:`\u68C0\u6D4B\u5230\u4EE5\u4E0B ${_.length} \u4E2A\u6C38\u4E45\u8BB0\u5FC6\u7ED1\u5B9A\u7684\u6587\u4EF6\u5DF2\u53D8\u66F4\uFF0C\u5DF2\u4E3A\u60A8\u6807\u8BB0\u4E3A\u66F4\u65B0\u4E2D\uFF1A
|
|
34
34
|
|
|
35
35
|
${C}
|
|
36
36
|
|
|
37
|
-
\u8BF7\u8C03\u7528 read_memory \u67E5\u770B\u5185\u5BB9\u5E76\u8C03\u7528 update_memory \u66F4\u65B0\u3002\u66F4\u65B0\u5B8C\u6210\u540E\u72B6\u6001\u5C06\u81EA\u52A8\u6062\u590D\u4E3A\u6B63\u5E38\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:_.map(y=>y.memoryUri),fileChanges:_.map(y=>{const w=t.find(S=>S.id===y.memoryId);return{uri:y.memoryUri,boundFiles:w?.bound_files??[],fileStatuses:y.fileStatuses,changedFiles:y.changedFiles}})}}}}return a.info("[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B\u5B8C\u6210: \u65E0\u53D8\u66F4\u901A\u77E5\u4EA7\u751F"),null}catch(e){return a.warn("[McpServer] \u6784\u5EFA Memory \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B\u901A\u77E5\u5931\u8D25: %s",e instanceof Error?e.message:String(e)),null}}isClaimCached(e){return this.activeLeaseUris.has(e)}async computeBoundFileStatuses(e){const t=[];if(!e.bound_files||e.bound_files.length===0)return t;const r=e.file_md5_map||{},
|
|
38
|
-
`:"",i=this.formatChangeType(e.changeType),
|
|
39
|
-
${
|
|
40
|
-
\u89E6\u53D1\u65F6\u95F4: ${
|
|
41
|
-
\u63D0\u793A\u8BCD: ${e.prompt}`;return{msgId:`browser-listener-${e.listenerId}-${e.triggeredAt}`,senderId:"MCP-BrowserListener",senderName:"\u6D4F\u89C8\u5668\u76D1\u542C\u5668",receiverId:t||void 0,content:o,requireReply:!1,role:"system",timestamp:
|
|
42
|
-
lines=${
|
|
43
|
-
Use read_background_output(task_id="${
|
|
37
|
+
\u8BF7\u8C03\u7528 read_memory \u67E5\u770B\u5185\u5BB9\u5E76\u8C03\u7528 update_memory \u66F4\u65B0\u3002\u66F4\u65B0\u5B8C\u6210\u540E\u72B6\u6001\u5C06\u81EA\u52A8\u6062\u590D\u4E3A\u6B63\u5E38\u3002`,requireReply:!1,timestamp:new Date().toISOString(),_acodeAutoDelegate:{type:"memory_file_change",uris:_.map(y=>y.memoryUri),fileChanges:_.map(y=>{const w=t.find(S=>S.id===y.memoryId);return{uri:y.memoryUri,boundFiles:w?.bound_files??[],fileStatuses:y.fileStatuses,changedFiles:y.changedFiles}})}}}}return a.info("[McpServer] \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B\u5B8C\u6210: \u65E0\u53D8\u66F4\u901A\u77E5\u4EA7\u751F"),null}catch(e){return a.warn("[McpServer] \u6784\u5EFA Memory \u6587\u4EF6\u53D8\u66F4\u68C0\u6D4B\u901A\u77E5\u5931\u8D25: %s",e instanceof Error?e.message:String(e)),null}}isClaimCached(e){return this.activeLeaseUris.has(e)}async computeBoundFileStatuses(e){const t=[];if(!e.bound_files||e.bound_files.length===0)return t;const r=e.file_md5_map||{},s=process.env.AWS_WORKSPACE_PATH||process.cwd();for(const i of e.bound_files)try{const n=await this.calculateFileMd5(i);if(n===null){const l=f.resolve(s,i);await this.verifyFileNotExist(l)&&r[i]?t.push({path:i,status:"not_found",serverMd5:r[i]}):t.push({path:i,status:"no_change"});continue}const o=r[i];o?o!==n?t.push({path:i,status:"content_changed",localMd5:n,serverMd5:o}):t.push({path:i,status:"no_change"}):t.push({path:i,status:"no_change"})}catch{t.push({path:i,status:"no_change"})}return t}async checkMemoriesFileChanges(e){const t=[];for(const r of e)if(!(!r.bound_files||r.bound_files.length===0))try{const s=[],i=[],n={},o=r.file_md5_map||{},l=process.env.AWS_WORKSPACE_PATH||process.cwd(),h=Object.keys(o).length===0;let m=!1;for(const d of r.bound_files)try{const u=await this.calculateFileMd5(d);if(u===null){const T=f.resolve(l,d);a.info(`[McpServer] MD5 \u8BA1\u7B97\u8FD4\u56DE null: ${d} -> ${T} (workspace=${l})`);const b=o[d];b?await this.verifyFileNotExist(T)?(i.push({path:d,status:"not_found",serverMd5:b}),s.push(`${d}\uFF08\u6587\u4EF6\u627E\u4E0D\u5230 Server: ${b}\uFF09`),r.bound_files&&(r.bound_files=r.bound_files.filter(c=>c!==d))):(a.info(`[McpServer] \u6587\u4EF6\u5B58\u5728\u4F46 MD5 \u8BA1\u7B97\u5931\u8D25\uFF08\u77AC\u6001\u9519\u8BEF\uFF09\uFF0C\u8DF3\u8FC7: ${d}`),i.push({path:d,status:"no_change"})):i.push({path:d,status:"no_change"});continue}n[d]=u;const p=o[d];p?p!==u?(a.info(`[McpServer] \u6587\u4EF6\u53D8\u66F4: ${d} old=${p} new=${u} (workspace=${l})`),i.push({path:d,status:"content_changed",localMd5:u,serverMd5:p}),s.push(`${d}\uFF08\u5185\u5BB9\u53D8\u66F4 \u672C\u5730: ${u} Server: ${p}\uFF09`)):i.push({path:d,status:"no_change"}):(i.push({path:d,status:"no_change"}),m=!0,a.info(`[McpServer] \u5EFA\u7ACB\u5355\u6587\u4EF6\u57FA\u7EBF: ${d} new=${u} (workspace=${l}, memory=${r.uri})`))}catch(u){a.info(`[McpServer] \u8BA1\u7B97\u6587\u4EF6 MD5 \u5931\u8D25: ${d}`,u),i.push({path:d,status:"no_change"})}if(h&&Object.keys(n).length>0){r.file_md5_map=n,r.last_check_time=new Date().toISOString();continue}m&&Object.keys(n).length>0&&(r.file_md5_map=n,r.last_check_time=new Date().toISOString()),s.length>0&&(t.push({memoryId:r.id,memoryUri:r.uri,fileStatuses:i,changedFiles:s}),r.last_check_time=new Date().toISOString())}catch(s){a.warn(`[McpServer] \u68C0\u67E5 Memory ${r.id} \u6587\u4EF6\u53D8\u66F4\u5931\u8D25:`,s)}return t}async calculateFileMd5(e){try{const{createReadStream:t}=await import("node:fs"),{createHash:r}=await import("node:crypto"),s=process.env.AWS_WORKSPACE_PATH||process.cwd(),i=f.resolve(s,e),n=f.resolve(s),o=f.resolve(i);return!o.startsWith(n+f.sep)&&o!==n?(a.warn(`[McpServer] calculateFileMd5: \u8DEF\u5F84\u9003\u9038\u88AB\u62D2\u7EDD: ${e}`),null):new Promise(l=>{const h=r("md5"),m=t(i);m.on("data",d=>h.update(d)),m.on("end",()=>l(h.digest("hex"))),m.on("error",()=>l(null))})}catch(t){return a.info(`[McpServer] \u8BA1\u7B97\u6587\u4EF6 MD5 \u5931\u8D25: ${e}`,t),null}}async verifyFileNotExist(e){try{return await $.promises.access(e,$.constants.F_OK),!1}catch{return!0}}async handleGetMessage(e=!1){if(e){const n=this.messageBuffer.takeForceDirectMessages();return this.buildPollResult(n)}const t=this.messageBuffer.size()>0;await this.hydrateUnreadMessagesFromServer();const r=this.messageBuffer.get(),s=r.directMessages.length>0||r.groupMessages.length>0,i=t||!s;return await this.prependMemoryNotification(r,()=>this.buildMemoryRecurrenceNotification())?this.buildPollResult(r,i):await this.prependMemoryNotification(r,()=>this.buildMemoryCleanupNotification())?this.buildPollResult(r,i):this.buildPollResult(r,i)}async hydrateUnreadMessagesFromServer(e={}){try{const t=await this.agentClient.fetchUnreadMessages({blockIfEmpty:e.blockIfEmpty??!1,blockTimeoutMs:e.blockTimeoutMs,includePipelineTasks:e.includePipelineTasks});if(t.directMessages.length===0&&t.groupMessages.length===0)return!0;const r=t.directMessages.filter(i=>this.shouldBufferIncomingMessage(i)),s=t.groupMessages.filter(i=>this.shouldBufferIncomingMessage(i));return r.forEach(i=>{this.messageBuffer.push(i)}),s.forEach(i=>{this.messageBuffer.push(i)}),a.info(`[McpServer] \u5DF2\u8865\u62C9\u672A\u8BFB\u6D88\u606F\uFF0C\u79C1\u804A: ${r.length}\uFF0C\u7FA4\u804A: ${s.length}`),!0}catch(t){return a.error("[McpServer] \u8865\u62C9\u672A\u8BFB\u6D88\u606F\u5931\u8D25: %s, stack=%s",t instanceof Error?t.message:String(t),t instanceof Error?t.stack:"(no stack)"),!1}}async hydrateBrowserListenerEvents(){try{const e=await this.agentClient.fetchBrowserListenerEvents();if(e.length===0)return!1;a.info(`[McpServer] \u62C9\u53D6\u5230 ${e.length} \u6761\u6D4F\u89C8\u5668\u76D1\u542C\u5668\u4E8B\u4EF6\uFF0C\u6CE8\u5165\u6D88\u606F\u7F13\u51B2`);for(const t of e){const r=this.buildListenerEventNotification(t);r&&this.messageBuffer.push(r)}return!0}catch(e){return a.warn("[McpServer] \u62C9\u53D6\u6D4F\u89C8\u5668\u76D1\u542C\u5668\u4E8B\u4EF6\u5931\u8D25: %s",e instanceof Error?e.message:String(e)),!1}}buildListenerEventNotification(e){try{const t=this.getCurrentAgentId(),r=e.browserId&&e.browserId!=="default"?`\u6D4F\u89C8\u5668[${e.browserId}]`:"\u6D4F\u89C8\u5668",s=e.selector?`\u5143\u7D20\u9009\u62E9\u5668: ${e.selector}
|
|
38
|
+
`:"",i=this.formatChangeType(e.changeType),n=new Date(e.triggeredAt).toISOString(),o=`\u3010\u6D4F\u89C8\u5668\u76D1\u542C\u5668\u89E6\u53D1 | ${r} | URL: ${e.url}\u3011
|
|
39
|
+
${s}\u53D8\u5316\u7C7B\u578B: ${i}
|
|
40
|
+
\u89E6\u53D1\u65F6\u95F4: ${n}
|
|
41
|
+
\u63D0\u793A\u8BCD: ${e.prompt}`;return{msgId:`browser-listener-${e.listenerId}-${e.triggeredAt}`,senderId:"MCP-BrowserListener",senderName:"\u6D4F\u89C8\u5668\u76D1\u542C\u5668",receiverId:t||void 0,content:o,requireReply:!1,role:"system",timestamp:n}}catch{return null}}formatChangeType(e){switch(e){case"added":return"\u65B0\u589E";case"removed":return"\u5220\u9664";case"changed":return"\u6539\u53D8";case"exists":return"\u5B58\u5728";default:return"\u6539\u53D8"}}async handleGetDmHistory(e){return await this.agentClient.getDmHistory(e.targetUserId,e.limit,e.since)}async handleGetGroupHistory(e){return await this.agentClient.getGroupHistory(e.limit,e.roomId,e.since)}async handleSubmitTaskResult(e){if(!e.nodeId||typeof e.nodeId!="string")throw new Error("nodeId is required");if(!e.outputPayload||typeof e.outputPayload!="string")throw new Error("outputPayload is required");const t=Array.isArray(e.changeLog)?e.changeLog:void 0;return await this.agentClient.submitTaskResult(e.nodeId,e.outputPayload,t)}async handleStartTaskRollback(e){const t={rollbackTaskId:this.getRequiredString(e,"rollbackTaskId")};return await this.agentClient.startTaskRollback(t)}async handleFinishTaskRollback(e){const t={rollbackTaskId:this.getRequiredString(e,"rollbackTaskId"),resultMessage:this.getOptionalString(e,"resultMessage")};return await this.agentClient.finishTaskRollback(t)}async handleRejectTask(e){if(!e.nodeId||typeof e.nodeId!="string")throw new Error("nodeId is required");if(!e.reason||typeof e.reason!="string")throw new Error("reason is required");return await this.agentClient.rejectTask(e.nodeId,e.reason)}async handleTerminateTask(e){if(!e.taskInstanceId||typeof e.taskInstanceId!="string")throw new Error("taskInstanceId is required");if(!e.reason||typeof e.reason!="string")throw new Error("reason is required");return await this.agentClient.terminateTask(e.taskInstanceId,e.reason)}async handleIncomingMessage(e){if(!this.shouldBufferIncomingMessage(e)){!this.isGroupMessage(e)&&this.isPipelineTaskAssignedNotification(e)&&(a.info("[McpServer] \u6536\u5230 pipeline_task_assigned \u5524\u9192\u4FE1\u53F7\uFF0C\u7ACB\u5373\u5524\u9192 poll \u8D70 hydrate \u91CD\u67E5"),this.messageBuffer.wakeUpWaiters());return}a.info(`[McpServer] \u6536\u5230\u6D88\u606F: ${e.content?.substring(0,50)||"(\u65E0\u5185\u5BB9)"}`),this.messageBuffer.push(e),!this.isGroupMessage(e)&&e.force===!0&&this.agentClient.notifyBridgeForceMessage().catch(()=>{})}shouldBufferIncomingMessage(e){return!e||typeof e!="object"?(a.warn("[McpServer] \u5FFD\u7565\u7ED3\u6784\u5F02\u5E38\u7684\u6D88\u606F\uFF0C\u907F\u514D\u7F13\u51B2\u533A\u6C61\u67D3"),!1):this.isSelfSentMessage(e)?(a.info("[McpServer] \u5FFD\u7565\u5F53\u524D Agent \u81EA\u5DF1\u53D1\u9001\u7684\u6D88\u606F\uFF0C\u907F\u514D poll_message/get_message \u56DE\u73AF"),!1):this.isGroupMessage(e)?!0:this.isPipelineTaskAssignedNotification(e)?(a.info("[McpServer] \u5FFD\u7565\u6301\u4E45\u5316 pipeline_task_assigned \u79C1\u4FE1\uFF0C\u4EC5\u4F5C\u4E3A poll_message \u5524\u9192\u4FE1\u53F7\u5904\u7406"),!1):!0}isGroupMessage(e){return!!e&&typeof e=="object"&&typeof e.msgId=="number"}isPipelineTaskAssignedNotification(e){const t=typeof e.content=="string"?e.content:"",r=typeof e.prompt=="string"?e.prompt:"";return t.includes("pipeline_task_assigned")||r.includes("pipeline_task_assigned")}isSelfSentMessage(e){if(!e||typeof e!="object")return!1;const t=this.getCurrentAgentId();return!!t&&typeof e.senderId=="string"&&e.senderId===t}getCurrentAgentId(){const e=this.agentClient;return typeof e.getState!="function"?null:e.getState().agentId??null}sanitizeAgentIdForTodoFile(e){return String(e).replace(/[^a-zA-Z0-9_-]/g,"_")}async buildTodoBlockNotification(){const e=this.getCurrentAgentId();if(!e)return null;const t=f.join(j.homedir(),".acode","todos",`${this.sanitizeAgentIdForTodoFile(e)}.json`);let r;try{r=await $.promises.readFile(t,"utf-8")}catch(o){return o?.code==="ENOENT"||a.warn("[McpServer] \u8BFB\u53D6 Todo \u6587\u4EF6\u5931\u8D25\uFF0C\u653E\u884C poll_message: %s",o instanceof Error?o.message:String(o)),null}let s;try{s=JSON.parse(r)}catch(o){return a.warn("[McpServer] \u89E3\u6790 Todo \u6587\u4EF6\u5931\u8D25\uFF0C\u653E\u884C poll_message: %s",o instanceof Error?o.message:String(o)),null}return(Array.isArray(s.todos)?s.todos:[]).filter(o=>o&&typeof o=="object"&&typeof o.content=="string"&&(o.status==="pending"||o.status==="in_progress"||o.status==="cancelled")).length===0?null:{msgId:`todo-block-${Date.now()}`,senderId:"MCP-System",senderName:"\u7CFB\u7EDF",receiverId:e,content:"\u5F53\u524D\u6709\u672A\u5904\u7406\u7684todo list\u4E0D\u80FD\u4F7F\u7528poll_message\u963B\u585E\u83B7\u53D6\u6D88\u606F",requireReply:!1,timestamp:new Date().toISOString()}}async buildBackgroundTaskNotification(){try{const e=this.getCurrentAgentId();if(!e)return null;const t=f.join(j.homedir(),".acode","bg-tasks",this.sanitizeAgentIdForTodoFile(e),"state.json");let r;try{r=await $.promises.readFile(t,"utf-8")}catch(m){if(m?.code==="ENOENT")return null;throw m}const s=JSON.parse(r),i=Array.isArray(s.tasks)?s.tasks:[],n=i.filter(m=>m&&typeof m=="object"&&typeof m.taskId=="string"&&m.status!=="running"&&!m.notified);if(n.length===0)return null;const o=n.slice(0,5),l=o.map(m=>`[bg:${m.taskId}] ${m.status} (exitCode=${m.exitCode??"?"}) ${m.commandPreview??""}
|
|
42
|
+
lines=${m.outputLineCount??0} bytes=${m.outputBytes??0}
|
|
43
|
+
Use read_background_output(task_id="${m.taskId}", mode="tail", lines=50) for full output.`).join(`
|
|
44
44
|
|
|
45
|
-
`),
|
|
45
|
+
`),h=n.length>o.length?`
|
|
46
46
|
|
|
47
|
-
\uFF08\u53E6\u6709 ${
|
|
48
|
-
${l}${
|
|
47
|
+
\uFF08\u53E6\u6709 ${n.length-o.length} \u6761\u5DF2\u5B8C\u6210\uFF0C\u8BF7\u7528 ListBackgroundCommands \u67E5\u770B\uFF09`:"";return await $.promises.writeFile(t,JSON.stringify({...s,updatedAt:Date.now(),tasks:i.map(m=>n.some(d=>d.taskId===m.taskId)?{...m,notified:!0}:m)},null,2),"utf-8").catch(m=>{a.warn("[McpServer] \u6807\u8BB0\u540E\u53F0\u4EFB\u52A1\u5DF2\u901A\u77E5\u5931\u8D25: %s",m?.message??m)}),{msgId:`bg-notif-${Date.now()}`,senderId:"MCP-System",senderName:"ACode Background",receiverId:e,content:`[Background commands completed]
|
|
48
|
+
${l}${h}`,requireReply:!1,timestamp:new Date().toISOString()}}catch(e){return a.warn("[McpServer] \u6784\u5EFA\u540E\u53F0\u547D\u4EE4\u5B8C\u6210\u901A\u77E5\u5931\u8D25: %s",e instanceof Error?e.message:String(e)),null}}async start(){const e=new x;await this.server.connect(e),await this.agentClient.initialize(),a.info("[McpServer] MCP Server \u5DF2\u542F\u52A8\uFF0C\u7B49\u5F85\u8FDE\u63A5..."),a.info(`[McpServer] \u53EF\u7528\u5DE5\u5177: ${D.map(t=>t.name).join(", ")}`),a.info(`[McpServer] \u5DE5\u4F5C\u76EE\u5F55: ${process.env.AWS_WORKSPACE_PATH||process.cwd()}`),L&&a.info("[McpServer] \u964D\u7EA7\u6A21\u5F0F\u5DF2\u542F\u7528\uFF0C\u6CE8\u518C\u5931\u8D25\u65F6\u5C06\u4EE5\u79BB\u7EBF\u6A21\u5F0F\u7EE7\u7EED\u8FD0\u884C"),this.autoRegisterInBackground(),a.info("[McpServer] MCP Server \u5DF2\u5C31\u7EEA\uFF0C\u5DE5\u5177\u5DF2\u53EF\u7528")}startLeaseRenewal(){this.leaseRenewalTimer||(this.leaseRenewalTimer=setInterval(async()=>{try{if(!this.getCurrentAgentId())return;(await this.memoryStore.renewMemoryLease(v.LEASE_DURATION_MINUTES)).renewed===0&&(a.warn("[McpServer] \u79DF\u7EA6\u5DF2\u4E22\u5931\uFF08renewed=0\uFF09\uFF0C\u505C\u6B62\u7EED\u671F\u5B9A\u65F6\u5668"),this.stopLeaseRenewal())}catch(e){const t=e instanceof Error?e.message:String(e);t.includes("not supported")?(a.info("[McpServer] \u5F53\u524D\u5B58\u50A8\u4E0D\u652F\u6301\u79DF\u7EA6\u7EED\u671F\uFF0C\u505C\u6B62\u7EED\u671F\u5B9A\u65F6\u5668"),this.stopLeaseRenewal()):a.warn("[McpServer] \u7EED\u671F\u79DF\u7EA6\u5931\u8D25: %s",t)}},v.LEASE_RENEW_INTERVAL_MS),a.info("[McpServer] \u79DF\u7EA6\u7EED\u671F\u5B9A\u65F6\u5668\u5DF2\u542F\u52A8\uFF0C\u95F4\u9694: 60s"))}stopLeaseRenewal(){this.leaseRenewalTimer&&(clearInterval(this.leaseRenewalTimer),this.leaseRenewalTimer=null,a.info("[McpServer] \u79DF\u7EA6\u7EED\u671F\u5B9A\u65F6\u5668\u5DF2\u505C\u6B62"))}stop(){this.stopLeaseRenewal(),this.getCurrentAgentId()&&this.memoryStore.releaseAllMemoryClaims().catch(t=>a.warn("[McpServer] \u91CA\u653E claim \u5931\u8D25: %s",t instanceof Error?t.message:String(t))),this.agentClient.stop(),a.info("[McpServer] MCP Server \u5DF2\u505C\u6B62")}async autoRegister(){const e=this.agentClient.getAgentConfig();a.info(`[McpServer] \u89D2\u8272: "${e.roleName}"`),a.info(`[McpServer] AgentID: "${e.agentId||"(\u81EA\u52A8\u5206\u914D)"}"`),a.info("[McpServer] \u6B63\u5728\u8BF7\u6C42\u8C03\u5EA6\u4E2D\u5FC3\u6CE8\u518C...");let t=0;for(;;)try{const r=await this.agentClient.register();a.info(`[McpServer] \u6CE8\u518C\u6210\u529F: ${r.displayName} (${r.agentId})`),a.info(`[McpServer] \u72B6\u6001: ${r.status}`),this.startListeningInternal(),a.info("[McpServer] \u6D88\u606F\u76D1\u542C\u5DF2\u81EA\u52A8\u542F\u52A8");const s=this.agentClient.getStatusReporter();s&&s.reportWaitingInput(),await this.reportMemoryStatsToServer(),this.maybeSyncPermanentMemoryToServer();return}catch(r){const s=r instanceof Error?r.message:String(r);if(t++,P>0&&t>=P){if(L){a.warn(`[McpServer] \u6CE8\u518C\u8D85\u8FC7\u6700\u5927\u91CD\u8BD5\u6B21\u6570 (${P}\u6B21)\uFF0C\u8FDB\u5165\u964D\u7EA7\u6A21\u5F0F`),this.agentClient.enterDegradedMode(),this.startListeningInternal(),a.info("[McpServer] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6D88\u606F\u76D1\u542C\u5DF2\u542F\u52A8"),this.agentClient.retryRegistrationInBackground(J,K);const i=this.agentClient.getStatusReporter();i&&i.reportWaitingInput(),await this.reportMemoryStatsToServer();return}throw new Error(`\u6CE8\u518C\u8D85\u8FC7\u6700\u5927\u91CD\u8BD5\u6B21\u6570 (${P}\u6B21)\uFF0C\u653E\u5F03\u542F\u52A8: ${s}`)}a.warn(`[McpServer] \u6CE8\u518C\u5931\u8D25\uFF0C\u7B49\u5F85\u91CD\u8BD5... (${t}/${P}): ${s}`),await this.delay(Y)}}autoRegisterInBackground(){this.autoRegister().catch(e=>{a.error("[McpServer] \u540E\u53F0\u6CE8\u518C\u5F02\u5E38: %s, stack=%s",e instanceof Error?e.message:String(e),e instanceof Error?e.stack:"(no stack)")})}startListeningInternal(){a.info("[McpServer] startListeningInternal \u88AB\u8C03\u7528");const e=t=>{a.info(`[McpServer] profileHandler \u88AB\u8C03\u7528\uFF0CdisplayName: ${t.displayName}`),this.messageBuffer.setProfileMessage(t),this.profileSynced=!0,this.syncRoleMemoryStore(t),this.maybeSyncPermanentMemoryToServer()};if(this.agentClient.isInDegradedMode()){a.info("[McpServer] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u8DF3\u8FC7 WebSocket \u8FDE\u63A5\uFF0C\u4EC5\u542F\u52A8\u672C\u5730\u6D88\u606F\u76D1\u542C"),this.agentClient.start(this.handleIncomingMessage.bind(this),{pollMode:!1,profileHandler:e}),this.activelySyncProfile();return}this.agentClient.start(this.handleIncomingMessage.bind(this),{pollMode:!1,profileHandler:e}),this.activelySyncProfile()}activelySyncProfile(){this.profileSynced||this.agentClient.getProfile().then(e=>{this.profileSynced||(this.profileSynced=!0,a.info(`[McpServer] \u4E3B\u52A8\u83B7\u53D6 profile \u6210\u529F: displayName=${e.displayName}, roleName="${e.roleName??"(\u7A7A)"}"`),this.messageBuffer.setProfileMessage(e),this.syncRoleMemoryStore(e),this.maybeSyncPermanentMemoryToServer())}).catch(e=>{a.warn("[McpServer] \u4E3B\u52A8\u83B7\u53D6 profile \u5931\u8D25: %s",e instanceof Error?e.message:String(e))})}delay(e){return new Promise(t=>setTimeout(t,e))}}export{v as McpServer};
|
|
49
49
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CREATE_MEMORY_TOOL as e,DELETE_MEMORY_TOOL as t,GET_MEMORY_STATS_TOOL as r,LIST_MEMORIES_TOOL as i,READ_MEMORY_TOOL as n,SEARCH_MEMORY_TOOL as s,UPDATE_MEMORY_TOOL as p,LIST_MEMORIES_BY_FILE_TOOL as o,ABANDON_MEMORY_UPDATE_TOOL as a,MEMORY_RECURRENCE_TOOL as c,MEMORY_RECURRENCE_COMPLETE_TOOL as d}from"./memory-tools.js";import{CREATE_MEMORY_TOOL as
|
|
1
|
+
import{CREATE_MEMORY_TOOL as e,DELETE_MEMORY_TOOL as t,GET_MEMORY_STATS_TOOL as r,LIST_MEMORIES_TOOL as i,READ_MEMORY_TOOL as n,SEARCH_MEMORY_TOOL as s,UPDATE_MEMORY_TOOL as p,LIST_MEMORIES_BY_FILE_TOOL as o,ABANDON_MEMORY_UPDATE_TOOL as a,MEMORY_RECURRENCE_TOOL as c,MEMORY_RECURRENCE_COMPLETE_TOOL as d}from"./memory-tools.js";import{CREATE_MEMORY_TOOL as Y,DELETE_MEMORY_TOOL as G,GET_MEMORY_STATS_TOOL as f,LIST_MEMORIES_TOOL as H,READ_MEMORY_TOOL as K,SEARCH_MEMORY_TOOL as w,UPDATE_MEMORY_TOOL as B,LIST_MEMORIES_BY_FILE_TOOL as F,ABANDON_MEMORY_UPDATE_TOOL as J,MEMORY_RECURRENCE_TOOL as V,MEMORY_RECURRENCE_COMPLETE_TOOL as W}from"./memory-tools.js";const _={name:"get_colleague",description:"\u83B7\u53D6\u5F53\u524D Agent \u53EF\u89C1\u7684\u540C\u4E8B Agent \u5217\u8868\uFF0C\u5305\u542B\u5728\u7EBF\u548C\u79BB\u7EBF\u72B6\u6001\u3002\u6BCF\u4E2A\u540C\u4E8B\u8FD4\u56DE id\u3001\u89D2\u8272ID\uFF08roleId\uFF09\u3001\u89D2\u8272\u540D\u79F0\uFF08roleName\uFF09\u3001\u9879\u76EEID\uFF1B\u914D\u5408 query_file_changes_history \u53EF\u6309\u540C\u4E8B\u7684 roleId/agentId \u8FC7\u6EE4\u67E5\u8BE2\u5176\u6587\u4EF6\u53D8\u66F4\u5386\u53F2\u3002",inputSchema:{type:"object",properties:{},required:[]}},m={name:"get_group_rooms",description:"\u83B7\u53D6\u5F53\u524D Agent \u5728\u5173\u7CFB\u56FE\u4E2D\u53EF\u53D1\u73B0\u7684\u7FA4\u7EC4\u5217\u8868\uFF0C\u5305\u62EC\u9879\u76EE\u516C\u5171\u7FA4\u804A\u4EE5\u53CA\u81EA\u5DF1\u6240\u5728\u7684\u5C0F\u7EC4\u7FA4\u3002",inputSchema:{type:"object",properties:{},required:[]}},E={name:"get_profile",description:`\u83B7\u53D6\u5F53\u524D Agent \u7684\u4E2A\u4EBA\u4FE1\u606F\uFF0C\u5305\u62EC ID\u3001\u89D2\u8272 ID/\u540D\u79F0\u3001\u663E\u793A\u540D\u79F0\u3001\u63D0\u793A\u8BCD\u7B49\u3002
|
|
2
2
|
|
|
3
3
|
\u3010\u7CFB\u7EDF\u63D0\u793A\u8BCD\u5206\u5C42\u7ED3\u6784\u3011
|
|
4
4
|
\u8FD4\u56DE\u7684 prompt \u5B57\u6BB5\u662F\u89D2\u8272/\u5B9E\u4F8B\u63D0\u793A\u8BCD\uFF08System 2\uFF09\uFF0CglobalAgentPrompt \u662F\u5168\u5C40\u7CFB\u7EDF\u63D0\u793A\u8BCD\uFF08System 1\uFF09\u3002
|
|
@@ -11,13 +11,13 @@ MCP \u5DE5\u5177\uFF08poll_message/get_message\uFF09\u4E0D\u518D\u8FD4\u56DE sys
|
|
|
11
11
|
- groupMessages: \u7FA4\u804A\u6D88\u606F
|
|
12
12
|
|
|
13
13
|
\u7CFB\u7EDF\u63D0\u793A\u8BCD\uFF08\u5168\u5C40\u63D0\u793A\u8BCD + \u89D2\u8272\u63D0\u793A\u8BCD + \u542F\u52A8\u8BB0\u5FC6\uFF09\u5DF2\u7531 runtime adapter
|
|
14
|
-
\u5728\u4F1A\u8BDD\u521B\u5EFA\u65F6\u6CE8\u5165\uFF0C\u65E0\u9700\u901A\u8FC7 MCP \u83B7\u53D6\u3002`,inputSchema:{type:"object",properties:{},required:[]}},
|
|
14
|
+
\u5728\u4F1A\u8BDD\u521B\u5EFA\u65F6\u6CE8\u5165\uFF0C\u65E0\u9700\u901A\u8FC7 MCP \u83B7\u53D6\u3002`,inputSchema:{type:"object",properties:{},required:[]}},l={name:"get_message",description:`\u83B7\u53D6\u672A\u8BFB\u6D88\u606F\uFF08\u975E\u963B\u585E\uFF09\uFF0C\u4ECE\u6D88\u606F\u7F13\u51B2\u533A\u83B7\u53D6\u6D88\u606F\uFF0C\u7ACB\u5373\u8FD4\u56DE\uFF0C\u82E5\u5F53\u524D\u6CA1\u6709\u4EFB\u52A1\u5E94\u4F7F\u7528 poll_message\u3002
|
|
15
15
|
|
|
16
16
|
\u3010\u8FD4\u56DE\u503C\u8BF4\u660E\u3011
|
|
17
17
|
- directMessages: \u79C1\u4FE1\u6D88\u606F
|
|
18
18
|
- groupMessages: \u7FA4\u804A\u6D88\u606F
|
|
19
19
|
|
|
20
|
-
\u7CFB\u7EDF\u63D0\u793A\u8BCD\u5DF2\u7531 runtime adapter \u5728\u4F1A\u8BDD\u521B\u5EFA\u65F6\u6CE8\u5165\uFF0C\u65E0\u9700\u901A\u8FC7 MCP \u83B7\u53D6\u3002`,inputSchema:{type:"object",properties:{},required:[]}},
|
|
20
|
+
\u7CFB\u7EDF\u63D0\u793A\u8BCD\u5DF2\u7531 runtime adapter \u5728\u4F1A\u8BDD\u521B\u5EFA\u65F6\u6CE8\u5165\uFF0C\u65E0\u9700\u901A\u8FC7 MCP \u83B7\u53D6\u3002`,inputSchema:{type:"object",properties:{},required:[]}},I={name:"get_dm_history",description:"\u83B7\u53D6\u79C1\u4FE1\u5386\u53F2\u6D88\u606F\u3002\u53EF\u4EE5\u83B7\u53D6\u4E0E\u7279\u5B9A\u7528\u6237\u7684\u5BF9\u8BDD\u5386\u53F2\uFF0C\u6216\u83B7\u53D6\u6240\u6709\u79C1\u4FE1\u5386\u53F2\u3002",inputSchema:{type:"object",properties:{targetUserId:{type:"string",description:"\u76EE\u6807\u7528\u6237ID\uFF08\u53EF\u9009\uFF09\u3002\u5982\u679C\u4E0D\u6307\u5B9A\uFF0C\u5219\u8FD4\u56DE\u6240\u6709\u79C1\u4FE1\u5386\u53F2\u3002"},limit:{type:"number",description:"\u83B7\u53D6\u6700\u8FD1\u5386\u53F2\u6D88\u606F\u7684\u6570\u91CF\uFF08\u9ED8\u8BA450\uFF09"},since:{type:"string",description:"\u8D77\u59CB\u65F6\u95F4\uFF08ISO 8601 \u683C\u5F0F\uFF0C\u53EF\u9009\uFF09\u3002\u65E9\u4E8E\u8BE5\u65F6\u95F4\u7684\u6D88\u606F\u5C06\u4E0D\u4F1A\u88AB\u8FD4\u56DE\u3002"}},required:[]}},R={name:"get_group_history",description:"\u83B7\u53D6\u516C\u5171\u7FA4\u804A\u7684\u5386\u53F2\u6D88\u606F\u3002",inputSchema:{type:"object",properties:{limit:{type:"number",description:"\u83B7\u53D6\u6700\u8FD1\u5386\u53F2\u6D88\u606F\u7684\u6570\u91CF\uFF08\u9ED8\u8BA450\uFF09"},since:{type:"string",description:"\u8D77\u59CB\u65F6\u95F4\uFF08ISO 8601 \u683C\u5F0F\uFF0C\u53EF\u9009\uFF09\u3002\u65E9\u4E8E\u8BE5\u65F6\u95F4\u7684\u6D88\u606F\u5C06\u4E0D\u4F1A\u88AB\u8FD4\u56DE\u3002"}},required:[]}},A={name:"my_task",description:"\u83B7\u53D6\u5F53\u524D Agent \u5DF2\u901A\u8FC7 poll_message \u540E\u53F0\u9759\u9ED8\u62A2\u5360\u6216\u6B63\u5728\u5904\u7406\u7684\u6D41\u7A0B\u7EBF\u4EFB\u52A1\u5217\u8868\u3002\u6B64\u5DE5\u5177\u53EA\u8BFB\u53D6\u5DF2\u5206\u914D\u7ED9\u5F53\u524D Agent \u7684\u4EFB\u52A1\u8BE6\u60C5\uFF0C\u4E0D\u4F1A\u4E3B\u52A8\u62A2\u5360\u65B0\u7684\u5F85\u5904\u7406\u8282\u70B9\u3002\u6536\u5230\u6D41\u7A0B\u7EBF\u4EFB\u52A1\u5206\u914D\u901A\u77E5\u540E\uFF0C\u8C03\u7528\u6B64\u5DE5\u5177\u83B7\u53D6\u4EFB\u52A1\u6307\u4EE4\u3001\u524D\u5E8F\u8282\u70B9\u8F93\u51FA\u3001requiredOutput \u8F93\u51FA\u5951\u7EA6\u7B49\uFF1B\u5B8C\u6210\u540E\u5FC5\u987B\u6309 requiredOutput \u4F7F\u7528 submit_task_result \u63D0\u4EA4\u7ED3\u679C\uFF0C\u63D0\u4EA4\u65F6\u8BF7\u4E00\u5E76\u4F20\u5165 changeLog\uFF08\u672C\u6B21\u5904\u7406\u7684\u6587\u4EF6/\u5185\u5BB9\u53D8\u66F4\u65E5\u5FD7\uFF0C\u5305\u542B operation \u4E0E path\uFF09\uFF0C\u7528\u4E8E AI \u56DE\u9000\u3002\u82E5 requiredOutput \u7684\u76EE\u6807\u662F HUMAN \u8282\u70B9\uFF0C\u63D0\u4EA4\u7ED9\u8BE5\u5206\u652F\u7684 output \u5FC5\u987B\u5305\u542B questions \u6570\u7EC4\u4E14\u81F3\u5C11\u4E00\u4E2A\u9898\u76EE\u5E26 question \u5B57\u6BB5\u3002",inputSchema:{type:"object",properties:{},required:[]}},L={name:"create_task_instance_comment",description:"\u4E3A\u5F53\u524D\u6B63\u5728\u5904\u7406\u7684\u6D41\u7A0B\u7EBF\u5B9E\u4F8B\u521B\u5EFA\u4E00\u6761\u5B9E\u4F8B\u7EA7\u7559\u8A00\u3002\u4EC5\u5141\u8BB8\u7531\u540E\u53F0\u9759\u9ED8\u62A2\u5360\u540E\u6B63\u5728\u5904\u7406\u8BE5\u5B9E\u4F8B\u8282\u70B9\u7684 Agent \u8C03\u7528\uFF1B\u5F53\u9700\u8981\u544A\u77E5\u540E\u7EED\u8282\u70B9\u9700\u8981\u6CE8\u610F\u7684\u70B9\u65F6\u4F7F\u7528\u7559\u8A00\u8FDB\u884C\u7559\u8A00\uFF1B\u7559\u8A00\u4F1A\u5728\u5B9E\u4F8B\u5217\u8868\u201C\u67E5\u770B\u7559\u8A00\u201D\u548C\u540E\u7EED my_task \u8FD4\u56DE\u4E2D\u5C55\u793A\u3002",inputSchema:{type:"object",properties:{taskInstanceId:{type:"string",description:"\u6D41\u7A0B\u7EBF\u4EFB\u52A1\u5B9E\u4F8BID\uFF08\u4ECE my_task \u8FD4\u56DE\u4E2D\u83B7\u53D6\uFF09"},content:{type:"string",description:"\u7559\u8A00\u5185\u5BB9"}},required:["taskInstanceId","content"]}},S={name:"submit_task_result",description:`\u63D0\u4EA4\u6D41\u7A0B\u7EBF\u4EFB\u52A1\u7684\u6267\u884C\u7ED3\u679C\u3002\u5B8C\u6210\u4EFB\u52A1\u540E\u8C03\u7528\u6B64\u5DE5\u5177\uFF0C\u8F93\u51FA\u5C06\u4F20\u9012\u7ED9\u4E0B\u4E00\u4E2A\u8282\u70B9\u3002outputPayload \u5FC5\u987B\u9075\u5FAA my_task \u8FD4\u56DE\u7684 requiredOutput\uFF1A\u6709\u540E\u7EE7\u5206\u652F\u65F6\u5FC5\u987B\u662F JSON \u6570\u7EC4\uFF0C\u6BCF\u9879\u5305\u542B targetNodeId \u548C output\u3002\u82E5\u76EE\u6807\u5206\u652F\u662F HUMAN \u8282\u70B9\uFF0Coutput \u5FC5\u987B\u662F JSON \u5BF9\u8C61\u5E76\u5305\u542B\u975E\u7A7A questions \u6570\u7EC4\uFF0Cquestions \u81F3\u5C11\u4E00\u4E2A\u9898\u76EE\u5FC5\u987B\u5305\u542B\u5B57\u7B26\u4E32 question \u5B57\u6BB5\u3002
|
|
21
21
|
\u63D0\u4EA4\u65F6\u8BF7\u4E00\u5E76\u4F20\u5165 changeLog\uFF08\u672C\u6B21\u4EFB\u52A1\u5904\u7406\u671F\u95F4\u4EA7\u751F\u7684\u6587\u4EF6/\u5185\u5BB9\u53D8\u66F4\u65E5\u5FD7\uFF09\uFF0C\u7528\u4E8E\u300CAI \u56DE\u9000\u300D\u7CBE\u786E\u8FD8\u539F\uFF1A\u6BCF\u9879\u5305\u542B operation(CREATE|UPDATE|DELETE|READ)\u3001path(\u76F8\u5BF9\u5DE5\u4F5C\u533A\u8DEF\u5F84)\u3001\u53EF\u9009 targetType/summary/beforeHash/afterHash/metadata\u3002\u672A\u8BB0\u5F55\u53D8\u66F4\u4F1A\u5BFC\u81F4 AI \u56DE\u9000\u7F3A\u5C11\u4F9D\u636E\u3002`,inputSchema:{type:"object",properties:{nodeId:{type:"string",description:"\u4EFB\u52A1\u8282\u70B9ID\uFF08\u4ECE my_task \u8FD4\u56DE\u7684\u4EFB\u52A1\u4FE1\u606F\u4E2D\u83B7\u53D6\uFF09"},outputPayload:{type:"string",description:'\u4EFB\u52A1\u6267\u884C\u7ED3\u679C\u7684 JSON \u5B57\u7B26\u4E32\u3002\u5FC5\u987B\u6309 my_task.requiredOutput \u9009\u62E9\u76EE\u6807\u5206\u652F\uFF0C\u4F8B\u5982 [{"targetNodeId":"<\u76EE\u6807\u8282\u70B9\u6A21\u677FID>","output":{...}}]\uFF1B\u63D0\u4EA4\u5230 HUMAN \u8282\u70B9\u65F6 output \u5FC5\u987B\u5F62\u5982 {"questions":[{"question":"\u8BF7\u786E\u8BA4...","options":[{"label":"\u901A\u8FC7"}]}]}\u3002'},changeLog:{type:"array",description:"\u53EF\u9009\u3002\u672C\u6B21\u4EFB\u52A1\u5904\u7406\u671F\u95F4\u4EA7\u751F\u7684\u6587\u4EF6/\u5185\u5BB9\u53D8\u66F4\u65E5\u5FD7\uFF0C\u7528\u4E8E AI \u56DE\u9000\u3002\u6BCF\u9879: { operation: 'CREATE'|'UPDATE'|'DELETE'|'READ', targetType?: string, path: string, summary?: string, beforeHash?: string, afterHash?: string, metadata?: string }\u3002\u5EFA\u8BAE\u5728\u5B8C\u6210\u4EFB\u52A1\u3001\u8C03\u7528 submit_task_result \u65F6\u4E00\u5E76\u63D0\u4EA4\u3002",items:{type:"object",properties:{operation:{type:"string",enum:["CREATE","UPDATE","DELETE","READ"],description:"\u53D8\u66F4\u64CD\u4F5C\u7C7B\u578B"},targetType:{type:"string",description:"\u53D8\u66F4\u76EE\u6807\u7C7B\u578B\uFF0C\u7F3A\u7701\u89C6\u4E3A FILE"},path:{type:"string",description:"\u53D8\u66F4\u6587\u4EF6/\u8D44\u6E90\u7684\u76F8\u5BF9\u8DEF\u5F84"},summary:{type:"string",description:"\u53D8\u66F4\u6458\u8981\u8BF4\u660E"},beforeHash:{type:"string",description:"\u53D8\u66F4\u524D\u5185\u5BB9 hash\uFF08\u5DEE\u5F02\u56DE\u9000\u7528\uFF09"},afterHash:{type:"string",description:"\u53D8\u66F4\u540E\u5185\u5BB9 hash\uFF08\u5DEE\u5F02\u56DE\u9000\u7528\uFF09"},metadata:{type:"string",description:"\u9644\u52A0\u5143\u6570\u636E JSON \u5B57\u7B26\u4E32\uFF08\u5982 cacheKey\uFF09"}},required:["operation","path"]}}},required:["nodeId","outputPayload"]}},M={name:"start_task_rollback",description:"\u5C06\u5206\u914D\u7ED9\u5F53\u524D Agent \u7684\u6D41\u7A0B\u7EBF AI \u56DE\u9000\u4EFB\u52A1\u6807\u8BB0\u4E3A\u56DE\u9000\u4E2D\u3002\u6536\u5230\u56DE\u9000\u59D4\u6258\u540E\uFF0C\u5F00\u59CB\u5B9E\u9645\u56DE\u9000\u524D\u8C03\u7528\u3002",inputSchema:{type:"object",properties:{rollbackTaskId:{type:"string",description:"AI \u56DE\u9000\u4EFB\u52A1ID\uFF08\u4ECE\u56DE\u9000\u59D4\u6258\u6D88\u606F\u4E2D\u83B7\u53D6\uFF09\u3002"}},required:["rollbackTaskId"]}},D={name:"finish_task_rollback",description:"\u5C06\u5206\u914D\u7ED9\u5F53\u524D Agent \u7684\u6D41\u7A0B\u7EBF AI \u56DE\u9000\u4EFB\u52A1\u6807\u8BB0\u4E3A\u5DF2\u56DE\u9000\uFF0C\u5E76\u8BB0\u5F55\u56DE\u9000\u7ED3\u679C\u3002\u5B8C\u6210\u56DE\u9000\u540E\u8C03\u7528\u3002",inputSchema:{type:"object",properties:{rollbackTaskId:{type:"string",description:"AI \u56DE\u9000\u4EFB\u52A1ID\uFF08\u4ECE\u56DE\u9000\u59D4\u6258\u6D88\u606F\u4E2D\u83B7\u53D6\uFF09\u3002"},resultMessage:{type:"string",description:"\u56DE\u9000\u7ED3\u679C\u8BF4\u660E\uFF08\u53EF\u9009\uFF09\u3002"}},required:["rollbackTaskId"]}},b={name:"reject_task",description:"\u62D2\u7EDD\u5BF9\u524D\u5E8F\u8282\u70B9\u8F93\u51FA\u7684\u4EFB\u52A1\uFF0C\u4EFB\u52A1\u5C06\u56DE\u9000\u5230\u524D\u4E00\u4E2A\u8282\u70B9\u91CD\u65B0\u6267\u884C\u3002\u9002\u7528\u4E8E\u524D\u5E8F\u8F93\u51FA\u4E0D\u6EE1\u8DB3\u8981\u6C42\u6216\u65E0\u6CD5\u7EE7\u7EED\u6267\u884C\u7684\u573A\u666F\u3002",inputSchema:{type:"object",properties:{nodeId:{type:"string",description:"\u4EFB\u52A1\u8282\u70B9ID\uFF08\u4ECE my_task \u8FD4\u56DE\u7684\u4EFB\u52A1\u4FE1\u606F\u4E2D\u83B7\u53D6\uFF09"},reason:{type:"string",description:"\u62D2\u7EDD\u539F\u56E0"}},required:["nodeId","reason"]}},h={name:"terminate_task",description:"\u7EC8\u6B62\u6574\u4E2A\u6D41\u7A0B\u7EBF\u4EFB\u52A1\u3002\u7EC8\u6B62\u540E\u4EFB\u52A1\u72B6\u6001\u53D8\u4E3A TERMINATED\uFF08\u5DF2\u7EC8\u6B62\uFF09\uFF0C\u6240\u6709\u672A\u5B8C\u6210\u7684\u8282\u70B9\u4E5F\u5C06\u88AB\u7EC8\u6B62\uFF0C\u4EFB\u52A1\u4E0D\u518D\u8FDB\u884C\u540E\u7EED\u6D41\u8F6C\u3002\u9002\u7528\u4E8E\u4EFB\u52A1\u65E0\u6CD5\u7EE7\u7EED\u6267\u884C\u6216\u9700\u8981\u5F3A\u5236\u505C\u6B62\u7684\u573A\u666F\u3002\u6CE8\u610F\uFF1A\u7EC8\u6B62\u64CD\u4F5C\u4E0D\u53EF\u9006\uFF0C\u8BF7\u8C28\u614E\u4F7F\u7528\u3002",inputSchema:{type:"object",properties:{taskInstanceId:{type:"string",description:"\u4EFB\u52A1\u5B9E\u4F8BID\uFF08\u4ECE my_task \u8FD4\u56DE\u7684\u4EFB\u52A1\u4FE1\u606F\u4E2D\u83B7\u53D6 taskInstanceId\uFF09"},reason:{type:"string",description:"\u7EC8\u6B62\u539F\u56E0"}},required:["taskInstanceId","reason"]}},N={name:"get_debug_log_config",description:`\u83B7\u53D6 Agent Debug \u65E5\u5FD7\u7CFB\u7EDF\u7684\u5199\u5165\u914D\u7F6E\u3002\u8FD4\u56DE\u5199\u5165\u7AEF\u70B9 URL\u3001\u5F53\u524D Agent \u6240\u5C5E\u9879\u76EE\u540D\u3001\u4EE5\u53CA\u65E5\u5FD7\u5199\u5165\u5BC6\u94A5\uFF08logWriteKey\uFF09\u3002
|
|
22
22
|
|
|
23
23
|
## \u5982\u4F55\u5199\u5165\u65E5\u5FD7
|
|
@@ -32,11 +32,11 @@ MCP \u5DE5\u5177\uFF08poll_message/get_message\uFF09\u4E0D\u518D\u8FD4\u56DE sys
|
|
|
32
32
|
- detail (\u53EF\u9009): \u65E5\u5FD7\u8BE6\u60C5\u5185\u5BB9
|
|
33
33
|
|
|
34
34
|
\u5F53 logWriteKey \u975E\u7A7A\u65F6\uFF0C\u4F7F\u7528\u8BE5 key \u5373\u53EF\u76F4\u63A5\u5199\u5165\u65E5\u5FD7\uFF0C\u65E0\u9700\u9879\u76EE\u6210\u5458\u6743\u9650\u3002
|
|
35
|
-
\u5F53 logWriteKey \u4E3A\u7A7A\u65F6\uFF0C\u9700\u4F7F\u7528\u9879\u76EE\u6210\u5458\u7684 API Key\uFF08\u9700\u9879\u76EE\u6210\u5458\u6743\u9650\uFF09\u3002`,inputSchema:{type:"object",properties:{},required:[]}},
|
|
35
|
+
\u5F53 logWriteKey \u4E3A\u7A7A\u65F6\uFF0C\u9700\u4F7F\u7528\u9879\u76EE\u6210\u5458\u7684 API Key\uFF08\u9700\u9879\u76EE\u6210\u5458\u6743\u9650\uFF09\u3002`,inputSchema:{type:"object",properties:{},required:[]}},P={name:"query_debug_logs",description:`\u5206\u9875\u67E5\u8BE2 Agent Debug \u65E5\u5FD7\uFF08\u6309\u65F6\u95F4\u5012\u5E8F\uFF09\u3002\u7528\u4E8E\u6392\u67E5\u4E1A\u52A1\u9879\u76EE\u8FD0\u884C\u65F6\u95EE\u9898\u3002
|
|
36
36
|
|
|
37
|
-
\u8FD4\u56DE\u5B57\u6BB5\uFF1Aid\u3001projectId\u3001businessLine\u3001module\u3001level\u3001detail\u3001createdAt\u3002`,inputSchema:{type:"object",properties:{projectId:{type:"string",description:"\u9879\u76EE ID\uFF08\u5FC5\u586B\uFF09"},businessLine:{type:"string",description:"\u4E1A\u52A1\u7EBF\u540D\u79F0\uFF08\u5FC5\u586B\uFF09"},module:{type:"string",description:"\u6A21\u5757\u540D\uFF08\u53EF\u9009\uFF09"},level:{type:"string",description:"\u65E5\u5FD7\u7EA7\u522B\uFF1ADEBUG / INFO / WARN / ERROR\uFF08\u53EF\u9009\uFF09",enum:["DEBUG","INFO","WARN","ERROR"]},startTime:{type:"string",description:"\u8D77\u59CB\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-01T00:00:00\uFF08\u53EF\u9009\uFF09"},endTime:{type:"string",description:"\u7ED3\u675F\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-02T00:00:00\uFF08\u53EF\u9009\uFF09"},offset:{type:"number",description:"\u504F\u79FB\u91CF\uFF0C\u9ED8\u8BA4 0"},limit:{type:"number",description:"\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 20\uFF0C\u6700\u5927 200"}},required:["projectId","businessLine"]}},
|
|
37
|
+
\u8FD4\u56DE\u5B57\u6BB5\uFF1Aid\u3001projectId\u3001businessLine\u3001module\u3001level\u3001detail\u3001createdAt\u3002`,inputSchema:{type:"object",properties:{projectId:{type:"string",description:"\u9879\u76EE ID\uFF08\u5FC5\u586B\uFF09"},businessLine:{type:"string",description:"\u4E1A\u52A1\u7EBF\u540D\u79F0\uFF08\u5FC5\u586B\uFF09"},module:{type:"string",description:"\u6A21\u5757\u540D\uFF08\u53EF\u9009\uFF09"},level:{type:"string",description:"\u65E5\u5FD7\u7EA7\u522B\uFF1ADEBUG / INFO / WARN / ERROR\uFF08\u53EF\u9009\uFF09",enum:["DEBUG","INFO","WARN","ERROR"]},startTime:{type:"string",description:"\u8D77\u59CB\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-01T00:00:00\uFF08\u53EF\u9009\uFF09"},endTime:{type:"string",description:"\u7ED3\u675F\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-02T00:00:00\uFF08\u53EF\u9009\uFF09"},offset:{type:"number",description:"\u504F\u79FB\u91CF\uFF0C\u9ED8\u8BA4 0"},limit:{type:"number",description:"\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 20\uFF0C\u6700\u5927 200"}},required:["projectId","businessLine"]}},C={name:"query_file_changes_history",description:`\u5206\u9875\u67E5\u8BE2\u6587\u4EF6\u53D8\u66F4\u5386\u53F2\uFF08\u6309\u65F6\u95F4\u5012\u5E8F\uFF09\u3002\u7528\u4E8E\u4E86\u89E3\u5176\u5B83 Agent \u5BF9\u6587\u4EF6\u505A\u8FC7\u54EA\u4E9B\u4FEE\u6539\u3001\u4FEE\u6539\u539F\u56E0\u4E0E\u5F53\u524D\u72B6\u6001\uFF0C\u652F\u6301\u6309 \u89D2\u8272/\u5B9E\u4F8B/\u6587\u4EF6\u540D/\u76F8\u5BF9\u8DEF\u5F84/\u64CD\u4F5C/\u72B6\u6001/\u4EFB\u52A1\u5B9E\u4F8B/\u65F6\u95F4\u8303\u56F4 \u8FC7\u6EE4\u3002
|
|
38
38
|
|
|
39
39
|
\u67E5\u8BE2\u8303\u56F4\u81EA\u52A8\u9650\u5B9A\u4E3A\u5F53\u524D Agent \u6240\u5C5E\u9879\u76EE\uFF08\u65E0\u9700\u4F20 projectId\uFF09\u3002agentId \u4E0D\u4F20\u8868\u793A\u67E5\u8BE2\u5F53\u524D\u9879\u76EE\u4E0B\u6240\u6709 Agent \u7684\u53D8\u66F4\u8BB0\u5F55\uFF0C\u4F20\u5176\u5B83 Agent \u5B9E\u4F8B ID \u65F6\u4EC5\u9650\u540C\u9879\u76EE\u5185\uFF08\u670D\u52A1\u7AEF\u6821\u9A8C\uFF0C\u9879\u76EE\u5916 Agent \u4F1A\u88AB\u62D2\u7EDD\uFF09\u3002
|
|
40
40
|
|
|
41
|
-
\u8FD4\u56DE\u5B57\u6BB5\uFF1Aid\u3001projectId\u3001roleName\u3001instanceName\u3001agentId\u3001operation\uFF08CREATE/UPDATE/DELETE\uFF09\u3001targetPath\u3001fullPath\u3001reason\u3001status\uFF08APPLIED/REVERTED/REVERT_FAILED\uFF09\u3001createdAt\u3001revertedAt\u3001revertedBy\u3002`,inputSchema:{type:"object",properties:{roleId:{type:"string",description:"\u89D2\u8272\u5B9A\u4E49 ID\uFF08\u53EF\u9009\uFF09"},agentId:{type:"string",description:"Agent \u5B9E\u4F8B ID\uFF08\u53EF\u9009\uFF1B\u4E0D\u4F20=\u67E5\u8BE2\u5F53\u524D\u9879\u76EE\u4E0B\u6240\u6709 Agent\uFF1B\u4F20\u5176\u5B83 Agent \u65F6\u670D\u52A1\u7AEF\u6821\u9A8C\u5176\u4E0E\u8C03\u7528\u8005\u540C\u9879\u76EE\uFF09"},fileName:{type:"string",description:"\u6587\u4EF6\u540D\uFF08\u53EF\u9009\uFF0C\u6A21\u7CCA\u5339\u914D\uFF09"},operation:{type:"string",description:"\u64CD\u4F5C\u7C7B\u578B\uFF1ACREATE / UPDATE / DELETE\uFF08\u53EF\u9009\uFF09",enum:["CREATE","UPDATE","DELETE"]},status:{type:"string",description:"\u8BB0\u5F55\u72B6\u6001\uFF1AAPPLIED\uFF08\u5DF2\u751F\u6548\uFF09/ REVERTED\uFF08\u5DF2\u64A4\u9500\uFF09/ REVERT_FAILED\uFF08\u64A4\u9500\u5931\u8D25\uFF09\uFF08\u53EF\u9009\uFF09",enum:["APPLIED","REVERTED","REVERT_FAILED"]},taskInstanceId:{type:"string",description:"\u4EFB\u52A1\u5B9E\u4F8B ID\uFF08\u53EF\u9009\uFF09"},startTime:{type:"string",description:"\u8D77\u59CB\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-01T00:00:00\uFF08\u53EF\u9009\uFF09"},endTime:{type:"string",description:"\u7ED3\u675F\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-02T00:00:00\uFF08\u53EF\u9009\uFF09"},page:{type:"number",description:"\u9875\u7801\uFF0C\u9ED8\u8BA4 1"},pageSize:{type:"number",description:"\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 20"}},required:[]}},q=new Set(["create_memory","read_memory","update_memory","delete_memory","search_memory","list_memories","get_memory_stats","list_memories_by_file","memory_recurrence","memory_recurrence_complete"]),j=[_,E,
|
|
41
|
+
\u8FD4\u56DE\u5B57\u6BB5\uFF1Aid\u3001projectId\u3001roleName\u3001instanceName\u3001agentId\u3001operation\uFF08CREATE/UPDATE/DELETE\uFF09\u3001targetPath\u3001fullPath\u3001reason\u3001status\uFF08APPLIED/REVERTED/REVERT_FAILED\uFF09\u3001createdAt\u3001revertedAt\u3001revertedBy\u3002`,inputSchema:{type:"object",properties:{roleId:{type:"string",description:"\u89D2\u8272\u5B9A\u4E49 ID\uFF08\u53EF\u9009\uFF09"},agentId:{type:"string",description:"Agent \u5B9E\u4F8B ID\uFF08\u53EF\u9009\uFF1B\u4E0D\u4F20=\u67E5\u8BE2\u5F53\u524D\u9879\u76EE\u4E0B\u6240\u6709 Agent\uFF1B\u4F20\u5176\u5B83 Agent \u65F6\u670D\u52A1\u7AEF\u6821\u9A8C\u5176\u4E0E\u8C03\u7528\u8005\u540C\u9879\u76EE\uFF09"},fileName:{type:"string",description:"\u6587\u4EF6\u540D\uFF08\u53EF\u9009\uFF0C\u6309 basename \u6A21\u7CCA\u5339\u914D\uFF09"},filePath:{type:"string",description:"\u5DE5\u4F5C\u533A\u76F8\u5BF9\u8DEF\u5F84\uFF08\u53EF\u9009\uFF0C\u6309\u8D26\u672C\u8BB0\u5F55\u7684\u76F8\u5BF9\u8DEF\u5F84 targetPath \u5339\u914D\uFF0C\u542B\u76EE\u5F55\u524D\u7F00\u5339\u914D\uFF09\u3002\u652F\u6301 ./xx\u3001xx\u3001@/xx\u3001/xx \u7B49\u4EF7\u5199\u6CD5\uFF08@ \u89C6\u4E3A\u5DE5\u4F5C\u533A\u6839\u8DEF\u5F84\u522B\u540D\uFF09\u3002\u793A\u4F8B\uFF1A@/src/main.ts \u7CBE\u786E\u5339\u914D src/main.ts\uFF1B@/src \u5339\u914D src/ \u76EE\u5F55\u53CA\u5176\u4E0B\u6240\u6709\u6587\u4EF6\u7684\u53D8\u66F4\u3002\u4E0E fileName \u6B63\u4EA4\uFF1AfileName \u6309\u6587\u4EF6\u540D\u6A21\u7CCA\uFF0CfilePath \u6309\u76F8\u5BF9\u8DEF\u5F84\u5339\u914D\u3002"},operation:{type:"string",description:"\u64CD\u4F5C\u7C7B\u578B\uFF1ACREATE / UPDATE / DELETE\uFF08\u53EF\u9009\uFF09",enum:["CREATE","UPDATE","DELETE"]},status:{type:"string",description:"\u8BB0\u5F55\u72B6\u6001\uFF1AAPPLIED\uFF08\u5DF2\u751F\u6548\uFF09/ REVERTED\uFF08\u5DF2\u64A4\u9500\uFF09/ REVERT_FAILED\uFF08\u64A4\u9500\u5931\u8D25\uFF09\uFF08\u53EF\u9009\uFF09",enum:["APPLIED","REVERTED","REVERT_FAILED"]},taskInstanceId:{type:"string",description:"\u4EFB\u52A1\u5B9E\u4F8B ID\uFF08\u53EF\u9009\uFF09"},startTime:{type:"string",description:"\u8D77\u59CB\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-01T00:00:00\uFF08\u53EF\u9009\uFF09"},endTime:{type:"string",description:"\u7ED3\u675F\u65F6\u95F4\uFF0CISO \u683C\u5F0F\u5982 2026-08-02T00:00:00\uFF08\u53EF\u9009\uFF09"},page:{type:"number",description:"\u9875\u7801\uFF0C\u9ED8\u8BA4 1"},pageSize:{type:"number",description:"\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 20"}},required:[]}},q=new Set(["create_memory","read_memory","update_memory","delete_memory","search_memory","list_memories","get_memory_stats","list_memories_by_file","memory_recurrence","memory_recurrence_complete"]),j=[_,m,E,y,O,g,u,T,l,I,R,A,L,S,M,D,b,h,e,n,p,t,s,i,r,o,a,c,d,N,P,C];export{J as ABANDON_MEMORY_UPDATE_TOOL,Y as CREATE_MEMORY_TOOL,L as CREATE_TASK_INSTANCE_COMMENT_TOOL,G as DELETE_MEMORY_TOOL,D as FINISH_TASK_ROLLBACK_TOOL,_ as GET_COLLEAGUE_TOOL,N as GET_DEBUG_LOG_CONFIG_TOOL,I as GET_DM_HISTORY_TOOL,R as GET_GROUP_HISTORY_TOOL,m as GET_GROUP_ROOMS_TOOL,f as GET_MEMORY_STATS_TOOL,l as GET_MESSAGE_TOOL,E as GET_PROFILE_TOOL,O as HIRE_COLLEAGUES_BATCH_TOOL,y as HIRE_COLLEAGUE_TOOL,F as LIST_MEMORIES_BY_FILE_TOOL,H as LIST_MEMORIES_TOOL,j as MCP_TOOLS,W as MEMORY_RECURRENCE_COMPLETE_TOOL,V as MEMORY_RECURRENCE_TOOL,q as MEMORY_TOOL_NAMES,A as MY_TASK_TOOL,T as POLL_MESSAGE_TOOL,P as QUERY_DEBUG_LOGS_TOOL,C as QUERY_FILE_CHANGES_HISTORY_TOOL,K as READ_MEMORY_TOOL,b as REJECT_TASK_TOOL,w as SEARCH_MEMORY_TOOL,g as SEND_GROUP_TOOL,u as SEND_PRIVATE_TOOL,M as START_TASK_ROLLBACK_TOOL,S as SUBMIT_TASK_RESULT_TOOL,h as TERMINATE_TASK_TOOL,B as UPDATE_MEMORY_TOOL};
|
|
42
42
|
|
|
@@ -43,7 +43,7 @@ describe("query_file_changes_history tool", () => {
|
|
|
43
43
|
assert.deepEqual(schema.required, []);
|
|
44
44
|
assertRecord(schema.properties, "query_file_changes_history properties");
|
|
45
45
|
assert.equal("projectId" in schema.properties, false, "projectId 不应出现在工具参数中(由服务端推导)");
|
|
46
|
-
for (const field of ["roleId", "agentId", "fileName", "operation", "status", "taskInstanceId", "startTime", "endTime", "page", "pageSize"]) {
|
|
46
|
+
for (const field of ["roleId", "agentId", "fileName", "filePath", "operation", "status", "taskInstanceId", "startTime", "endTime", "page", "pageSize"]) {
|
|
47
47
|
assertRecord(schema.properties[field], `${field} schema`);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
@@ -19,6 +19,7 @@ export interface MemoryRecord {
|
|
|
19
19
|
last_check_time?: string;
|
|
20
20
|
expiresAt?: string;
|
|
21
21
|
memory_status?: 'normal' | 'recalling' | 'updating';
|
|
22
|
+
lease_expires_at?: string;
|
|
22
23
|
}
|
|
23
24
|
export type TodoStatus = 'pending' | 'completed';
|
|
24
25
|
export interface CreateMemoryInput {
|
|
@@ -124,7 +125,7 @@ export interface MemoryStorePort {
|
|
|
124
125
|
marked: number;
|
|
125
126
|
uris: string[];
|
|
126
127
|
}>;
|
|
127
|
-
clearRecallingExpiredMemories(): Promise<{
|
|
128
|
+
clearRecallingExpiredMemories(uris?: string[]): Promise<{
|
|
128
129
|
deleted: number;
|
|
129
130
|
uris: string[];
|
|
130
131
|
}>;
|
|
@@ -191,7 +192,7 @@ export declare class MemoryStore implements MemoryStorePort {
|
|
|
191
192
|
uris: string[];
|
|
192
193
|
}>;
|
|
193
194
|
|
|
194
|
-
clearRecallingExpiredMemories(): Promise<{
|
|
195
|
+
clearRecallingExpiredMemories(uris?: string[]): Promise<{
|
|
195
196
|
deleted: number;
|
|
196
197
|
uris: string[];
|
|
197
198
|
}>;
|