qlogicagent 2.18.9 → 2.18.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/agent.js +17 -17
  2. package/dist/cli.js +1 -1
  3. package/dist/host-contract.js +1 -1
  4. package/dist/index.js +445 -984
  5. package/dist/pet-host.js +8 -8
  6. package/dist/project-memory-host.js +40 -0
  7. package/dist/protocol.js +1 -1
  8. package/dist/skills/mcp/astraclaw-native-mcp-server.js +6 -6
  9. package/dist/types/cli/acp-session-host.d.ts +1 -1
  10. package/dist/types/cli/community-resource-installer.d.ts +3 -5
  11. package/dist/types/cli/default-project-bootstrap.d.ts +1 -1
  12. package/dist/types/cli/handlers/agents-handler.d.ts +8 -6
  13. package/dist/types/cli/handlers/community-handler.d.ts +0 -4
  14. package/dist/types/cli/handlers/control-handler.d.ts +1 -1
  15. package/dist/types/cli/handlers/project-handler.d.ts +1 -1
  16. package/dist/types/cli/handlers/session-handler.d.ts +0 -7
  17. package/dist/types/cli/handlers/solo-handler.d.ts +0 -2
  18. package/dist/types/cli/memory-coordinator.d.ts +1 -1
  19. package/dist/types/cli/multi-agent-state-coordinator.d.ts +0 -3
  20. package/dist/types/cli/pet-runtime.d.ts +5 -5
  21. package/dist/types/cli/product-coordinator.d.ts +0 -2
  22. package/dist/types/cli/project-memory-store-factory.d.ts +11 -1
  23. package/dist/types/cli/rpc-registry.d.ts +0 -2
  24. package/dist/types/cli/stdio-runtime-bootstrap.d.ts +2 -0
  25. package/dist/types/cli/stdio-runtime-services.d.ts +2 -0
  26. package/dist/types/cli/stdio-server.d.ts +3 -1
  27. package/dist/types/config/cn-mirror.d.ts +2 -2
  28. package/dist/types/host-contract/index.d.ts +167 -9
  29. package/dist/types/orchestration/agent-instance.d.ts +1 -3
  30. package/dist/types/orchestration/goal-mode-adapters.d.ts +0 -3
  31. package/dist/types/orchestration/goal-run-persistence.d.ts +0 -3
  32. package/dist/types/orchestration/product-persistence.d.ts +1 -4
  33. package/dist/types/orchestration/product-planner.d.ts +2 -3
  34. package/dist/types/orchestration/run-state-host-authority.d.ts +7 -0
  35. package/dist/types/orchestration/solo-evaluator.d.ts +2 -3
  36. package/dist/types/orchestration/solo-persistence.d.ts +4 -7
  37. package/dist/types/orchestration/testing/delegate-test-bridge.d.ts +13 -2
  38. package/dist/types/orchestration/workflow/node-schema.d.ts +2 -1
  39. package/dist/types/orchestration/workflow/qla-executor-host.d.ts +1 -1
  40. package/dist/types/orchestration/workflow/workflow-bundle.d.ts +1 -1
  41. package/dist/types/project-memory-host.d.ts +3 -0
  42. package/dist/types/protocol/wire/acp-agent-management.d.ts +1 -1
  43. package/dist/types/protocol/wire/acp-protocol.d.ts +1 -1
  44. package/dist/types/protocol/wire/chat-types.d.ts +2 -0
  45. package/dist/types/runtime/execution/streaming-tool-executor.d.ts +2 -0
  46. package/dist/types/runtime/infra/acp-detector.d.ts +1 -1
  47. package/dist/types/runtime/infra/background-tasks.d.ts +1 -1
  48. package/dist/types/runtime/pet/pet-community-assets.d.ts +7 -17
  49. package/dist/types/runtime/pet/petdex-vision-qa.d.ts +12 -0
  50. package/dist/types/runtime/ports/agent-runtime-ports.d.ts +1 -0
  51. package/dist/types/runtime/ports/memory-recall-source.d.ts +10 -0
  52. package/dist/types/runtime/ports/project-memory-store.d.ts +1 -1
  53. package/dist/types/runtime/session/session-persistence.d.ts +3 -4
  54. package/dist/types/skills/memory/host-memory-provider.d.ts +2 -2
  55. package/dist/types/skills/memory/memory-config-resolver.d.ts +4 -0
  56. package/dist/types/skills/memory/task-distillation.d.ts +1 -1
  57. package/dist/types/skills/portable-tool.d.ts +5 -0
  58. package/dist/types/test-support/run-state-authority-setup.d.ts +1 -0
  59. package/dist/types/transport/host-pet-client.d.ts +20 -0
  60. package/dist/types/transport/host-run-state-client.d.ts +17 -0
  61. package/dist/workflow-host.js +9 -9
  62. package/package.json +12 -2
  63. package/dist/runtime/infra/mcp-bridge-server.js +0 -338
  64. package/dist/types/cli/handlers/message-feedback-handler.d.ts +0 -31
  65. package/dist/types/runtime/infra/agent-process.d.ts +0 -368
  66. package/dist/types/runtime/infra/external-agent-pool.d.ts +0 -89
  67. package/dist/types/skills/memory/local-memory-provider.d.ts +0 -325
  68. package/dist/types/skills/memory/memory-provider-factory.d.ts +0 -33
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import{createInterface as Ze}from"node:readline";import{existsSync as Xe,readFileSync as et}from"node:fs";import{readFileSync as Se}from"node:fs";import{randomUUID as Te}from"node:crypto";import{readdirSync as Rt,readFileSync as Mt,statSync as se,writeFileSync as Et}from"node:fs";import{readdir as ie,readFile as ae,stat as le,writeFile as ce}from"node:fs/promises";import{join as d}from"node:path";import{homedir as X}from"node:os";import{join as u}from"node:path";import{existsSync as yt}from"node:fs";import{createHash as ct}from"node:crypto";import{resolve as dt}from"node:path";var P=".qlogicagent";function p(){return process.env.QLOGICAGENT_HOME||u(X(),P)}function v(){return u(p(),"skills")}function _(){return u(p(),"mcp.json")}function ee(t){if(!t)throw new Error("getProjectAgentDir: cwd is required (must not fall back to process.cwd())");return u(t,P)}function C(t){return u(ee(t),"skills-disabled.json")}import{readFileSync as te,writeFileSync as Tt,mkdirSync as wt,renameSync as kt}from"node:fs";import{dirname as _t,join as re}from"node:path";function f(){return{version:1,disabled:[]}}function oe(t){let e;try{e=te(t,"utf8")}catch(n){return n.code==="ENOENT"?{list:f(),corrupt:!1}:(console.error(`[project-skill-manifest] Cannot read skill mute list at ${t} (${n instanceof Error?n.message:String(n)}); treating it as empty for reads \u2014 muted skills may reactivate.`),{list:f(),corrupt:!0})}let r;try{r=JSON.parse(e)}catch(n){return console.error(`[project-skill-manifest] Skill mute list at ${t} is corrupted (${n instanceof Error?n.message:String(n)}); treating it as empty for reads \u2014 muted skills may reactivate.`),{list:f(),corrupt:!0}}return!r||typeof r!="object"||!Array.isArray(r.disabled)?(console.error(`[project-skill-manifest] Skill mute list at ${t} has an unexpected shape; treating it as empty for reads \u2014 muted skills may reactivate.`),{list:f(),corrupt:!0}):{list:{version:1,disabled:[...new Set(r.disabled.filter(n=>typeof n=="string"&&n.trim().length>0))]},corrupt:!1}}function x(t){return oe(t).list}function ne(){return re(p(),"skills-disabled.json")}function A(){return new Set(x(ne()).disabled)}function R(t){return new Set(x(C(t)).disabled)}var ue=["auto-skill-","test-skill-"],de=".skills_prompt_snapshot.json";function me(t){return ue.some(e=>t.startsWith(e))}function pe(t){let e=t.replace(/\r\n/g,`
3
- `),r=e.match(/^---\n[\s\S]*?^version:\s*(\S+)/m),o=e.match(/^---\n[\s\S]*?^category:\s*(.+)/m),n=e.match(/^---\n[\s\S]*?^author:\s*(.+)/m),i=e.match(/^---\n[\s\S]*?^requires:\s*(.+)/m),s=e.match(/^---\n[\s\S]*?^environments:\s*(.+)/m),a=e.match(/^---\n([\s\S]*?)\n---/)?.[1]??"";return{version:r?.[1],description:fe(a),category:o?.[1]?.trim()||void 0,author:n?.[1]?.trim()||void 0,requiredTools:E(i?.[1]),environments:E(s?.[1])}}function fe(t){let e=t.split(`
4
- `),r=e.findIndex(s=>/^description:/.test(s));if(r===-1)return;let o=e[r].replace(/^description:[ \t]*/,"").trim(),n=/^[>|][+-]?$/.test(o),i=[];!n&&o&&i.push(o);for(let s=r+1;s<e.length;s++){let a=e[s];if(!/^[ \t]/.test(a))break;let l=a.trim();l&&i.push(l)}if(i.length!==0)return i.join(" ").replace(/^["']|["']$/g,"").trim()||void 0}var M=new Map,b=new Map;function ge(t,e,r,o){let n=e.has(t.name),i=r.has(t.name),s=!ve(t.meta,o);return{name:t.name,filePath:t.filePath,baseDir:t.baseDir,globallyDisabled:n,projectDisabled:i,active:!n&&!i&&!s,systemGenerated:t.systemGenerated,description:t.meta.description,version:t.meta.version,category:t.meta.category,author:t.meta.author,requiredTools:t.meta.requiredTools,environments:t.meta.environments}}async function he(t){let e;try{e=await ie(t,{withFileTypes:!0})}catch{e=[]}let r=[];for(let s of e){if(!s.isDirectory()||s.name.startsWith("."))continue;let a=d(t,s.name),l=d(a,"SKILL.md");try{let y=await le(l);if(!y.isFile())continue;r.push({name:s.name,filePath:l,baseDir:a,mtimeMs:y.mtimeMs,size:y.size})}catch{continue}}r.sort((s,a)=>s.name.localeCompare(a.name));let o=r.map(s=>`${s.name}:${s.mtimeMs}:${s.size}`).join("|"),n=M.get(t);if(n&&n.fingerprint===o)return n.raw;let i=[];for(let s of r){let a;try{a=await ae(s.filePath,"utf8")}catch{continue}i.push({name:s.name,filePath:s.filePath,baseDir:s.baseDir,systemGenerated:me(s.name),mtimeMs:s.mtimeMs,size:s.size,meta:pe(a)})}return M.set(t,{fingerprint:o,raw:i}),be(t,i),i}async function ye(t,e){let r=v(),o=A(),n=t?R(t):new Set,i=b.get(r);return i||(i=he(r).finally(()=>b.delete(r)),b.set(r,i)),(await i).map(a=>ge(a,o,n,e))}async function D(t,e){return(await ye(t,e)).filter(r=>r.active)}function I(t){let e=v(),r=d(e,t),o=d(r,"SKILL.md");try{if(se(o).isFile())return{baseDir:r,filePath:o}}catch{}return null}function E(t){if(!t)return;let e=t.replace(/^\[|\]$/g,"").split(/[,\s]+/).map(r=>r.replace(/^["']|["']$/g,"").trim()).filter(Boolean);return e.length>0?e:void 0}function ve(t,e){if(t.environments&&e?.currentEnvironment&&!t.environments.includes(e.currentEnvironment))return!1;if(t.requiredTools){if(!e?.availableToolNames)return!1;let r=new Set(e.availableToolNames);return t.requiredTools.every(o=>r.has(o))}return!0}async function be(t,e){try{let o={version:1,entries:e.map(n=>({name:n.name,size:n.size,mtimeMs:n.mtimeMs,description:n.meta.description,version:n.meta.version,requiredTools:n.meta.requiredTools,environments:n.meta.environments}))};await ce(d(t,de),JSON.stringify(o,null,2),"utf8")}catch{}}var j="astraclaw_capabilities";async function L(t){if(t.tool==="skills_list")return{handled:!0,result:{skills:(await D(t.projectRoot,{availableToolNames:t.availableToolNames,currentEnvironment:t.currentEnvironment??process.platform})).map(we)}};if(t.tool==="skill_view"){let e=typeof t.args.name=="string"?t.args.name.trim():"";if(!e)throw new Error("skill_view requires a skill name");let r=I(e);if(!r)throw new Error(`Skill not found: ${e}`);return{handled:!0,result:{name:e,content:Se(r.filePath,"utf8")}}}if(t.tool==="mcp_connectors_list"){let e=t.mcpServerFailures??[],r=e.length>0?{failedServers:e,note:`${e.length} configured MCP server(s) are unavailable this session; their tools are missing from this list.`}:{};if(!t.toolCatalog)return{handled:!0,result:{tools:[],note:"AstraClaw MCP connector catalog is not attached to this capability server instance.",...e.length>0?{failedServers:e}:{}}};let o=t.toolCatalog.getToolManifest().filter(n=>n.function.name.startsWith("mcp__")).map(n=>({toolName:n.function.name,server:Pe(n.function.name),name:_e(n.function.name),description:n.function.description,inputSchema:n.function.parameters}));return{handled:!0,result:{tools:o,count:o.length,...r}}}if(t.tool==="mcp_tool_call"){if(!t.toolCatalog)throw new Error("AstraClaw MCP connector catalog is not attached");let e=typeof t.args.toolName=="string"?t.args.toolName.trim():"";if(!e.startsWith("mcp__"))throw new Error("mcp_tool_call requires a connector toolName returned by mcp_connectors_list");let r=t.toolCatalog.findTool(e);if(!r?.execute)throw new Error(`MCP connector tool not found or not executable: ${e}`);let o=ke(t.args.args),n=`astraclaw_mcp_${Te().slice(0,8)}`,i=await r.execute(n,o);return{handled:!0,result:{toolName:e,content:i.content,details:i.details,imageUrls:i.imageUrls}}}return{handled:!1}}function we(t){return{name:t.name,description:t.description,version:t.version,category:t.category,requiredTools:t.requiredTools,environments:t.environments}}function ke(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}function Pe(t){let e=t.split("__");return e.length>=3?e[1]??"":""}function _e(t){let e=t.split("__");return e.length>=3?e.slice(2).join("__"):t}import m from"node:path";import{fileURLToPath as Me}from"node:url";import{createRuntime as Ee}from"mcporter";var O=new Set(["gateway","agents_list","session_status","sessions_send","sessions_list","sessions_history","sessions_spawn","cron","config","workflow"]),Ce=new Set([...O,"agent"]);function $(t){return t?.riskLevel?t.riskLevel:t?.isDangerous?"system":t?.isReadOnly?"read":t?.isEgress?"external_egress":"write"}var S=class{toolPool=new Map;setTools(e){this.toolPool.clear();for(let r of e)this.toolPool.set(r.name,r)}addTool(e){this.toolPool.set(e.name,e)}addTools(e){for(let r of e)this.addTool(r)}removeTool(e){return this.toolPool.delete(e)}findTool(e){return this.toolPool.get(e)}hasTool(e){return this.toolPool.has(e)}getToolNames(){return Array.from(this.toolPool.keys())}getToolCount(){return this.toolPool.size}async executeTool(e,r,o,n){let i=this.toolPool.get(e);if(!i)throw new Error(`Tool not found: ${e}`);return i.execute(r,o,n)}getTools(){return Array.from(this.toolPool.values()).filter(e=>e.isEnabled?.()!==!1)}getToolManifest(){let e=[];for(let r of this.toolPool.values()){if(r.isEnabled?.()===!1)continue;let o=$(r);e.push({type:"function",function:{name:r.name,description:r.description,parameters:r.parameters},meta:{category:r.category??"other",displayName:r.displayName??{key:`capability.tool.${r.name}.name`,fallback:r.label},displayDescription:r.displayDescription??{key:`capability.tool.${r.name}.description`,fallback:""},parallelSafe:r.isConcurrencySafe??!1,riskLevel:o,isReadOnly:o==="read",isDangerous:o==="system",isDelete:r.isDelete??!1,isEgress:r.isEgress??o==="external_egress",egressCarriesData:r.egressCarriesData??!1}})}return e}},N=new S;function F(t){N.addTools(t)}function U(t){return N.removeTool(t)}var xe=new Set(["describe","fetch","find","get","inspect","list","query","read","search","stat"]),Ae=new Set(["append","copy","create","delete","edit","move","patch","remove","rename","set","update","upload","write"]);function q(t){let e=t.annotations,r=Re(t.name),o=r.some(l=>Ae.has(l)),n=r.some(l=>xe.has(l)),i=e?.destructiveHint===!0||o,s=e?.readOnlyHint===!0||!i&&n,a=s||e?.idempotentHint===!0&&!i;return{isReadOnly:s,isConcurrencySafe:a,isDestructive:i}}function Re(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)}var K=12e4,G=1e3,z=6e5;function De(t){if(t===void 0)return K;if(!Number.isInteger(t)||t<G||t>z)throw new RangeError(`MCP callTimeoutMs must be an integer between ${G} and ${z}`);return t}var g=3,Ie=1e3;async function je(t,e){let r=e.sleep??(i=>new Promise(s=>setTimeout(s,i))),o=Math.max(1,e.attempts),n;for(let i=1;i<=o;i++)try{return await t()}catch(s){n=s,i<o&&(e.onRetry?.(i,s),await r(e.baseDelayMs*i))}throw n}var h=class{runtime=null;definitions=[];toolsByServer=new Map;injectedNames=new Set;log;workspaceRoot;toolCatalog;serverToolFilters=new Map;serverOAuth=new Map;serverCallTimeouts=new Map;failedServers=new Map;constructor(e){this.log=e.log??{info:()=>{},warn:()=>{}},this.workspaceRoot=e.workspaceRoot?m.resolve(e.workspaceRoot):void 0,this.toolCatalog=e.toolCatalog,this.definitions=e.servers.filter(r=>!r.disabled).filter(r=>{let o=Ve(r);for(let n of o)this.log.warn(`[mcp] rejected server "${r.name}": ${n.message}`);return r.tools&&this.serverToolFilters.set(r.name,r.tools),r.oauth===!0&&this.serverOAuth.set(r.name,!0),this.serverCallTimeouts.set(r.name,De(r.callTimeoutMs)),o.length===0}).map(r=>this.toServerDefinition(r)).filter(r=>r!==null)}markServerFailed(e,r,o){this.failedServers.set(e,{name:e,phase:r,error:o}),console.error(`[mcp] server "${e}" unavailable this session (${r}): ${o}`)}toServerDefinition(e){if((e.type??(e.url?"http":"stdio"))==="http"){if(!e.url)return this.log.warn(`[mcp] server "${e.name}" is type "http" but has no url, skipping`),this.markServerFailed(e.name,"config",'type "http" but no url'),null;let o;try{o=new URL(e.url)}catch{return this.log.warn(`[mcp] server "${e.name}" has an invalid url "${e.url}", skipping`),this.markServerFailed(e.name,"config",`invalid url "${e.url}"`),null}return{name:e.name,command:{kind:"http",url:o,headers:e.headers}}}return e.command?{name:e.name,command:{kind:"stdio",command:e.command,args:e.args??[],cwd:e.cwd??this.workspaceRoot??process.cwd()},env:e.env}:(this.log.warn(`[mcp] server "${e.name}" is type "stdio" but has no command, skipping`),this.markServerFailed(e.name,"config",'type "stdio" but no command'),null)}async connectAll(){this.definitions.length!==0&&(this.runtime=await Ee({servers:this.definitions,clientInfo:{name:"qlogicagent",version:"1.0.0"},logger:{info:e=>this.log.info(`[mcp] ${e}`),warn:e=>this.log.warn(`[mcp] ${e}`),error:(e,r)=>this.log.warn(`[mcp] ${e}${r?` (${r instanceof Error?r.message:String(r)})`:""}`),debug:()=>{}}}),await Promise.allSettled(this.definitions.map(async e=>{try{let r=await je(()=>this.runtime.listTools(e.name,{includeSchema:!0,disableOAuth:this.serverOAuth.get(e.name)!==!0}),{attempts:g,baseDelayMs:Ie,onRetry:(n,i)=>this.log.warn(`[mcp] connect attempt ${n}/${g} for ${e.name} failed, retrying: ${i instanceof Error?i.message:i}`)}),o=H(r,this.serverToolFilters.get(e.name));this.toolsByServer.set(e.name,o),this.failedServers.delete(e.name),this.log.info(`[mcp] connected to ${e.name} (${o.length}/${r.length} tools)`)}catch(r){this.log.warn(`[mcp] failed to connect to ${e.name} after ${g} attempts: ${r instanceof Error?r.message:r}`),this.markServerFailed(e.name,"connect",`${r instanceof Error?r.message:String(r)} (after ${g} attempts)`)}})))}injectTools(){for(let[e,r]of this.toolsByServer){let o=this.injectPortableTools(e,r);this.log.info(`[mcp] injected ${o.length} tools from ${e}`)}}async refreshServerTools(e){if(!this.runtime)throw new Error("MCP runtime is not connected");let r=await this.runtime.listTools(e,{includeSchema:!0,disableOAuth:this.serverOAuth.get(e)!==!0}),o=H(r,this.serverToolFilters.get(e));return this.toolsByServer.set(e,o),this.failedServers.delete(e),this.retractServerTools(e),this.injectPortableTools(e,o),o.length}getConnectedServers(){return Array.from(this.toolsByServer.keys())}getFailedServers(){return Array.from(this.failedServers.values())}getToolCount(){let e=0;for(let r of this.toolsByServer.values())e+=r.length;return e}async disconnectAll(){for(let r of this.injectedNames)this.removeRegisteredTool(r);this.injectedNames.clear(),this.toolsByServer.clear(),this.failedServers.clear();let e=this.runtime;if(this.runtime=null,e)try{await e.close()}catch{}}toPortableTool(e,r){let o=q({name:r.name,description:r.description});return{name:`mcp__${W(e)}__${r.name}`,label:`[${e}] ${r.name}`,category:"mcp",description:r.description??`MCP tool from ${e}`,parameters:r.inputSchema??{type:"object",properties:{}},isConcurrencySafe:o.isConcurrencySafe,isReadOnly:o.isReadOnly,isDestructive:o.isDestructive,searchHint:`mcp ${e} ${r.name.replace(/[_-]+/g," ")}`,execute:async(n,i)=>{let s=this.runtime;if(!s)return{content:[{type:"text",text:`MCP server "${e}" is not connected.`}],details:{error:"mcp_not_connected"}};try{let a=await s.callTool(e,r.name,{args:i,timeoutMs:this.serverCallTimeouts.get(e)??K});return Le(a)}catch(a){let l=a instanceof Error?a.message:String(a);return{content:[{type:"text",text:`MCP tool error: ${l}`}],details:{error:l}}}}}}wrapToolsForWorkspaceBoundary(e){return this.workspaceRoot?e.map(r=>{if(!r.execute)return r;let o=r.execute;return{...r,execute:async(n,i,s)=>{let a=$e(r.name,i,this.workspaceRoot);return a?{content:[{type:"text",text:a}],details:{type:"mcp",error:"workspace_boundary"}}:o(n,i,s)}}}):e}injectPortableTools(e,r){let o=this.wrapToolsForWorkspaceBoundary(r.map(n=>this.toPortableTool(e,n)));this.registerTools(o);for(let n of o)this.injectedNames.add(n.name);return o}retractServerTools(e){let r=`mcp__${W(e)}__`;for(let o of[...this.injectedNames])o.startsWith(r)&&(this.removeRegisteredTool(o),this.injectedNames.delete(o))}registerTools(e){this.toolCatalog?this.toolCatalog.addTools(e):F(e)}removeRegisteredTool(e){return this.toolCatalog?.removeTool(e)??U(e)}};function Le(t){let e=t&&typeof t=="object"?t:{},o=(Array.isArray(e.content)?e.content:[]).filter(a=>!!a&&typeof a=="object"),n=o.filter(a=>a.type==="text"&&typeof a.text=="string").map(a=>a.text),i=o.filter(a=>!(a.type==="text"&&typeof a.text=="string")).map(a=>typeof a.type=="string"&&a.type?a.type:"unknown"),s=n.join(`
2
+ import{createInterface as Ze}from"node:readline";import{existsSync as Xe,readFileSync as et}from"node:fs";import{readFileSync as Se}from"node:fs";import{randomUUID as Te}from"node:crypto";import{readdirSync as Mt,readFileSync as Rt,statSync as se,writeFileSync as Et}from"node:fs";import{readdir as ie,readFile as ae,stat as le,writeFile as ce}from"node:fs/promises";import{join as d}from"node:path";import{homedir as X}from"node:os";import{join as u}from"node:path";import{existsSync as yt}from"node:fs";import{createHash as ct}from"node:crypto";import{resolve as dt}from"node:path";var _=".qlogicagent";function p(){return process.env.QLOGICAGENT_HOME||u(X(),_)}function v(){return u(p(),"skills")}function C(){return u(p(),"mcp.json")}function ee(t){if(!t)throw new Error("getProjectAgentDir: cwd is required (must not fall back to process.cwd())");return u(t,_)}function x(t){return u(ee(t),"skills-disabled.json")}import{readFileSync as te,writeFileSync as Tt,mkdirSync as wt,renameSync as kt}from"node:fs";import{dirname as _t,join as re}from"node:path";function f(){return{version:1,disabled:[]}}function oe(t){let e;try{e=te(t,"utf8")}catch(n){return n.code==="ENOENT"?{list:f(),corrupt:!1}:(console.error(`[project-skill-manifest] Cannot read skill mute list at ${t} (${n instanceof Error?n.message:String(n)}); treating it as empty for reads \u2014 muted skills may reactivate.`),{list:f(),corrupt:!0})}let r;try{r=JSON.parse(e)}catch(n){return console.error(`[project-skill-manifest] Skill mute list at ${t} is corrupted (${n instanceof Error?n.message:String(n)}); treating it as empty for reads \u2014 muted skills may reactivate.`),{list:f(),corrupt:!0}}return!r||typeof r!="object"||!Array.isArray(r.disabled)?(console.error(`[project-skill-manifest] Skill mute list at ${t} has an unexpected shape; treating it as empty for reads \u2014 muted skills may reactivate.`),{list:f(),corrupt:!0}):{list:{version:1,disabled:[...new Set(r.disabled.filter(n=>typeof n=="string"&&n.trim().length>0))]},corrupt:!1}}function A(t){return oe(t).list}function ne(){return re(p(),"skills-disabled.json")}function M(){return new Set(A(ne()).disabled)}function R(t){return new Set(A(x(t)).disabled)}var ue=["auto-skill-","test-skill-"],de=".skills_prompt_snapshot.json";function me(t){return ue.some(e=>t.startsWith(e))}function pe(t){let e=t.replace(/\r\n/g,`
3
+ `),r=e.match(/^---\n[\s\S]*?^version:\s*(\S+)/m),o=e.match(/^---\n[\s\S]*?^category:\s*(.+)/m),n=e.match(/^---\n[\s\S]*?^author:\s*(.+)/m),i=e.match(/^---\n[\s\S]*?^requires:\s*(.+)/m),s=e.match(/^---\n[\s\S]*?^environments:\s*(.+)/m),a=e.match(/^---\n([\s\S]*?)\n---/)?.[1]??"";return{version:r?.[1],description:fe(a),category:o?.[1]?.trim()||void 0,author:n?.[1]?.trim()||void 0,requiredTools:D(i?.[1]),environments:D(s?.[1])}}function fe(t){let e=t.split(`
4
+ `),r=e.findIndex(s=>/^description:/.test(s));if(r===-1)return;let o=e[r].replace(/^description:[ \t]*/,"").trim(),n=/^[>|][+-]?$/.test(o),i=[];!n&&o&&i.push(o);for(let s=r+1;s<e.length;s++){let a=e[s];if(!/^[ \t]/.test(a))break;let l=a.trim();l&&i.push(l)}if(i.length!==0)return i.join(" ").replace(/^["']|["']$/g,"").trim()||void 0}var E=new Map,b=new Map;function ge(t,e,r,o){let n=e.has(t.name),i=r.has(t.name),s=!ve(t.meta,o);return{name:t.name,filePath:t.filePath,baseDir:t.baseDir,globallyDisabled:n,projectDisabled:i,active:!n&&!i&&!s,systemGenerated:t.systemGenerated,description:t.meta.description,version:t.meta.version,category:t.meta.category,author:t.meta.author,requiredTools:t.meta.requiredTools,environments:t.meta.environments}}async function he(t){let e;try{e=await ie(t,{withFileTypes:!0})}catch{e=[]}let r=[];for(let s of e){if(!s.isDirectory()||s.name.startsWith("."))continue;let a=d(t,s.name),l=d(a,"SKILL.md");try{let y=await le(l);if(!y.isFile())continue;r.push({name:s.name,filePath:l,baseDir:a,mtimeMs:y.mtimeMs,size:y.size})}catch{continue}}r.sort((s,a)=>s.name.localeCompare(a.name));let o=r.map(s=>`${s.name}:${s.mtimeMs}:${s.size}`).join("|"),n=E.get(t);if(n&&n.fingerprint===o)return n.raw;let i=[];for(let s of r){let a;try{a=await ae(s.filePath,"utf8")}catch{continue}i.push({name:s.name,filePath:s.filePath,baseDir:s.baseDir,systemGenerated:me(s.name),mtimeMs:s.mtimeMs,size:s.size,meta:pe(a)})}return E.set(t,{fingerprint:o,raw:i}),be(t,i),i}async function ye(t,e){let r=v(),o=M(),n=t?R(t):new Set,i=b.get(r);return i||(i=he(r).finally(()=>b.delete(r)),b.set(r,i)),(await i).map(a=>ge(a,o,n,e))}async function I(t,e){return(await ye(t,e)).filter(r=>r.active)}function j(t){let e=v(),r=d(e,t),o=d(r,"SKILL.md");try{if(se(o).isFile())return{baseDir:r,filePath:o}}catch{}return null}function D(t){if(!t)return;let e=t.replace(/^\[|\]$/g,"").split(/[,\s]+/).map(r=>r.replace(/^["']|["']$/g,"").trim()).filter(Boolean);return e.length>0?e:void 0}function ve(t,e){if(t.environments&&e?.currentEnvironment&&!t.environments.includes(e.currentEnvironment))return!1;if(t.requiredTools){if(!e?.availableToolNames)return!1;let r=new Set(e.availableToolNames);return t.requiredTools.every(o=>r.has(o))}return!0}async function be(t,e){try{let o={version:1,entries:e.map(n=>({name:n.name,size:n.size,mtimeMs:n.mtimeMs,description:n.meta.description,version:n.meta.version,requiredTools:n.meta.requiredTools,environments:n.meta.environments}))};await ce(d(t,de),JSON.stringify(o,null,2),"utf8")}catch{}}var L="astraclaw_capabilities";async function O(t){if(t.tool==="skills_list")return{handled:!0,result:{skills:(await I(t.projectRoot,{availableToolNames:t.availableToolNames,currentEnvironment:t.currentEnvironment??process.platform})).map(we)}};if(t.tool==="skill_view"){let e=typeof t.args.name=="string"?t.args.name.trim():"";if(!e)throw new Error("skill_view requires a skill name");let r=j(e);if(!r)throw new Error(`Skill not found: ${e}`);return{handled:!0,result:{name:e,content:Se(r.filePath,"utf8")}}}if(t.tool==="mcp_connectors_list"){let e=t.mcpServerFailures??[],r=e.length>0?{failedServers:e,note:`${e.length} configured MCP server(s) are unavailable this session; their tools are missing from this list.`}:{};if(!t.toolCatalog)return{handled:!0,result:{tools:[],note:"AstraClaw MCP connector catalog is not attached to this capability server instance.",...e.length>0?{failedServers:e}:{}}};let o=t.toolCatalog.getToolManifest().filter(n=>n.function.name.startsWith("mcp__")).map(n=>({toolName:n.function.name,server:Pe(n.function.name),name:_e(n.function.name),description:n.function.description,inputSchema:n.function.parameters}));return{handled:!0,result:{tools:o,count:o.length,...r}}}if(t.tool==="mcp_tool_call"){if(!t.toolCatalog)throw new Error("AstraClaw MCP connector catalog is not attached");let e=typeof t.args.toolName=="string"?t.args.toolName.trim():"";if(!e.startsWith("mcp__"))throw new Error("mcp_tool_call requires a connector toolName returned by mcp_connectors_list");let r=t.toolCatalog.findTool(e);if(!r?.execute)throw new Error(`MCP connector tool not found or not executable: ${e}`);let o=ke(t.args.args),n=`astraclaw_mcp_${Te().slice(0,8)}`,i=await r.execute(n,o);return{handled:!0,result:{toolName:e,content:i.content,details:i.details,imageUrls:i.imageUrls}}}return{handled:!1}}function we(t){return{name:t.name,description:t.description,version:t.version,category:t.category,requiredTools:t.requiredTools,environments:t.environments}}function ke(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}function Pe(t){let e=t.split("__");return e.length>=3?e[1]??"":""}function _e(t){let e=t.split("__");return e.length>=3?e.slice(2).join("__"):t}import m from"node:path";import{fileURLToPath as Re}from"node:url";import{createRuntime as Ee}from"mcporter";var $=new Set(["gateway","agents_list","session_status","sessions_send","sessions_list","sessions_history","sessions_spawn","cron","config","workflow"]),Ce=new Set([...$,"agent"]);function N(t){return t?.riskLevel?t.riskLevel:t?.isDangerous?"system":t?.isReadOnly?"read":t?.isEgress?"external_egress":"write"}var S=class{toolPool=new Map;setTools(e){this.toolPool.clear();for(let r of e)this.toolPool.set(r.name,r)}addTool(e){this.toolPool.set(e.name,e)}addTools(e){for(let r of e)this.addTool(r)}removeTool(e){return this.toolPool.delete(e)}findTool(e){return this.toolPool.get(e)}hasTool(e){return this.toolPool.has(e)}getToolNames(){return Array.from(this.toolPool.keys())}getToolCount(){return this.toolPool.size}async executeTool(e,r,o,n){let i=this.toolPool.get(e);if(!i)throw new Error(`Tool not found: ${e}`);return i.execute(r,o,n)}getTools(){return Array.from(this.toolPool.values()).filter(e=>e.isEnabled?.()!==!1)}getToolManifest(){let e=[];for(let r of this.toolPool.values()){if(r.isEnabled?.()===!1)continue;let o=N(r);e.push({type:"function",function:{name:r.name,description:r.description,parameters:r.parameters},meta:{category:r.category??"other",displayName:r.displayName??{key:`capability.tool.${r.name}.name`,fallback:r.label},displayDescription:r.displayDescription??{key:`capability.tool.${r.name}.description`,fallback:""},parallelSafe:r.isConcurrencySafe??!1,riskLevel:o,isReadOnly:o==="read",isDangerous:o==="system",isDelete:r.isDelete??!1,isEgress:r.isEgress??o==="external_egress",egressCarriesData:r.egressCarriesData??!1,...r.executionTimeoutMs!==void 0?{executionTimeoutMs:r.executionTimeoutMs}:{}}})}return e}},F=new S;function U(t){F.addTools(t)}function q(t){return F.removeTool(t)}var xe=new Set(["describe","fetch","find","get","inspect","list","query","read","search","stat"]),Ae=new Set(["append","copy","create","delete","edit","move","patch","remove","rename","set","update","upload","write"]);function G(t){let e=t.annotations,r=Me(t.name),o=r.some(l=>Ae.has(l)),n=r.some(l=>xe.has(l)),i=e?.destructiveHint===!0||o,s=e?.readOnlyHint===!0||!i&&n,a=s||e?.idempotentHint===!0&&!i;return{isReadOnly:s,isConcurrencySafe:a,isDestructive:i}}function Me(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)}var w=12e4,z=1e3,W=9e5;function De(t){if(t===void 0)return w;if(!Number.isInteger(t)||t<z||t>W)throw new RangeError(`MCP callTimeoutMs must be an integer between ${z} and ${W}`);return t}var g=3,Ie=1e3;async function je(t,e){let r=e.sleep??(i=>new Promise(s=>setTimeout(s,i))),o=Math.max(1,e.attempts),n;for(let i=1;i<=o;i++)try{return await t()}catch(s){n=s,i<o&&(e.onRetry?.(i,s),await r(e.baseDelayMs*i))}throw n}var h=class{runtime=null;definitions=[];toolsByServer=new Map;injectedNames=new Set;log;workspaceRoot;toolCatalog;serverToolFilters=new Map;serverOAuth=new Map;serverCallTimeouts=new Map;failedServers=new Map;constructor(e){this.log=e.log??{info:()=>{},warn:()=>{}},this.workspaceRoot=e.workspaceRoot?m.resolve(e.workspaceRoot):void 0,this.toolCatalog=e.toolCatalog,this.definitions=e.servers.filter(r=>!r.disabled).filter(r=>{let o=Ve(r);for(let n of o)this.log.warn(`[mcp] rejected server "${r.name}": ${n.message}`);return r.tools&&this.serverToolFilters.set(r.name,r.tools),r.oauth===!0&&this.serverOAuth.set(r.name,!0),this.serverCallTimeouts.set(r.name,De(r.callTimeoutMs)),o.length===0}).map(r=>this.toServerDefinition(r)).filter(r=>r!==null)}markServerFailed(e,r,o){this.failedServers.set(e,{name:e,phase:r,error:o}),console.error(`[mcp] server "${e}" unavailable this session (${r}): ${o}`)}toServerDefinition(e){if((e.type??(e.url?"http":"stdio"))==="http"){if(!e.url)return this.log.warn(`[mcp] server "${e.name}" is type "http" but has no url, skipping`),this.markServerFailed(e.name,"config",'type "http" but no url'),null;let o;try{o=new URL(e.url)}catch{return this.log.warn(`[mcp] server "${e.name}" has an invalid url "${e.url}", skipping`),this.markServerFailed(e.name,"config",`invalid url "${e.url}"`),null}return{name:e.name,command:{kind:"http",url:o,headers:e.headers}}}return e.command?{name:e.name,command:{kind:"stdio",command:e.command,args:e.args??[],cwd:e.cwd??this.workspaceRoot??process.cwd()},env:e.env}:(this.log.warn(`[mcp] server "${e.name}" is type "stdio" but has no command, skipping`),this.markServerFailed(e.name,"config",'type "stdio" but no command'),null)}async connectAll(){this.definitions.length!==0&&(this.runtime=await Ee({servers:this.definitions,clientInfo:{name:"qlogicagent",version:"1.0.0"},logger:{info:e=>this.log.info(`[mcp] ${e}`),warn:e=>this.log.warn(`[mcp] ${e}`),error:(e,r)=>this.log.warn(`[mcp] ${e}${r?` (${r instanceof Error?r.message:String(r)})`:""}`),debug:()=>{}}}),await Promise.allSettled(this.definitions.map(async e=>{try{let r=await je(()=>this.runtime.listTools(e.name,{includeSchema:!0,disableOAuth:this.serverOAuth.get(e.name)!==!0}),{attempts:g,baseDelayMs:Ie,onRetry:(n,i)=>this.log.warn(`[mcp] connect attempt ${n}/${g} for ${e.name} failed, retrying: ${i instanceof Error?i.message:i}`)}),o=J(r,this.serverToolFilters.get(e.name));this.toolsByServer.set(e.name,o),this.failedServers.delete(e.name),this.log.info(`[mcp] connected to ${e.name} (${o.length}/${r.length} tools)`)}catch(r){this.log.warn(`[mcp] failed to connect to ${e.name} after ${g} attempts: ${r instanceof Error?r.message:r}`),this.markServerFailed(e.name,"connect",`${r instanceof Error?r.message:String(r)} (after ${g} attempts)`)}})))}injectTools(){for(let[e,r]of this.toolsByServer){let o=this.injectPortableTools(e,r);this.log.info(`[mcp] injected ${o.length} tools from ${e}`)}}async refreshServerTools(e){if(!this.runtime)throw new Error("MCP runtime is not connected");let r=await this.runtime.listTools(e,{includeSchema:!0,disableOAuth:this.serverOAuth.get(e)!==!0}),o=J(r,this.serverToolFilters.get(e));return this.toolsByServer.set(e,o),this.failedServers.delete(e),this.retractServerTools(e),this.injectPortableTools(e,o),o.length}getConnectedServers(){return Array.from(this.toolsByServer.keys())}getFailedServers(){return Array.from(this.failedServers.values())}getToolCount(){let e=0;for(let r of this.toolsByServer.values())e+=r.length;return e}async disconnectAll(){for(let r of this.injectedNames)this.removeRegisteredTool(r);this.injectedNames.clear(),this.toolsByServer.clear(),this.failedServers.clear();let e=this.runtime;if(this.runtime=null,e)try{await e.close()}catch{}}toPortableTool(e,r){let o=G({name:r.name,description:r.description});return{name:`mcp__${B(e)}__${r.name}`,label:`[${e}] ${r.name}`,category:"mcp",description:r.description??`MCP tool from ${e}`,parameters:r.inputSchema??{type:"object",properties:{}},isConcurrencySafe:o.isConcurrencySafe,isReadOnly:o.isReadOnly,isDestructive:o.isDestructive,searchHint:`mcp ${e} ${r.name.replace(/[_-]+/g," ")}`,executionTimeoutMs:this.serverCallTimeouts.get(e)??w,execute:async(n,i)=>{let s=this.runtime;if(!s)return{content:[{type:"text",text:`MCP server "${e}" is not connected.`}],details:{error:"mcp_not_connected"}};try{let a=await s.callTool(e,r.name,{args:i,timeoutMs:this.serverCallTimeouts.get(e)??w});return Le(a)}catch(a){let l=a instanceof Error?a.message:String(a);return{content:[{type:"text",text:`MCP tool error: ${l}`}],details:{error:l}}}}}}wrapToolsForWorkspaceBoundary(e){return this.workspaceRoot?e.map(r=>{if(!r.execute)return r;let o=r.execute;return{...r,execute:async(n,i,s)=>{let a=$e(r.name,i,this.workspaceRoot);return a?{content:[{type:"text",text:a}],details:{type:"mcp",error:"workspace_boundary"}}:o(n,i,s)}}}):e}injectPortableTools(e,r){let o=this.wrapToolsForWorkspaceBoundary(r.map(n=>this.toPortableTool(e,n)));this.registerTools(o);for(let n of o)this.injectedNames.add(n.name);return o}retractServerTools(e){let r=`mcp__${B(e)}__`;for(let o of[...this.injectedNames])o.startsWith(r)&&(this.removeRegisteredTool(o),this.injectedNames.delete(o))}registerTools(e){this.toolCatalog?this.toolCatalog.addTools(e):U(e)}removeRegisteredTool(e){return this.toolCatalog?.removeTool(e)??q(e)}};function Le(t){let e=t&&typeof t=="object"?t:{},o=(Array.isArray(e.content)?e.content:[]).filter(a=>!!a&&typeof a=="object"),n=o.filter(a=>a.type==="text"&&typeof a.text=="string").map(a=>a.text),i=o.filter(a=>!(a.type==="text"&&typeof a.text=="string")).map(a=>typeof a.type=="string"&&a.type?a.type:"unknown"),s=n.join(`
5
5
  `);if(i.length>0){let a=[...new Set(i)].join(", ");s=s?`${s}
6
6
 
7
- [${i.length} non-text blocks omitted: ${a}]`:`[output contains only non-text blocks: ${a}]`}return{content:[{type:"text",text:s||"(no text output)"}],...e.isError?{details:{error:"mcp_tool_error"}}:{}}}function W(t){return t.replace(/[^a-zA-Z0-9_]/g,"_").toLowerCase()}var Oe=/(?:^|_)(path|paths|file|files|filename|filenames|dir|dirs|directory|directories|folder|folders|cwd|root|uri)(?:$|_)/i;function $e(t,e,r){if(!r)return null;for(let o of w(e)){let n=Ue(o.value,r);if(n&&!qe(n.candidate,n.root,n.pathApi))return`Blocked: MCP tool "${t}" path "${o.value}" is outside the workspace boundary "${n.root}"`}return null}function w(t,e="",r=0){if(r>8)return[];if(typeof t=="string")return Ne(e,t)?[{key:e,value:t}]:[];if(Array.isArray(t))return t.flatMap(n=>w(n,e,r+1));if(!t||typeof t!="object")return[];let o=[];for(let[n,i]of Object.entries(t))o.push(...w(i,n,r+1));return o}function Ne(t,e){if(!Oe.test(t))return!1;let r=e.trim();return!r||/^https?:\/\//i.test(r)?!1:Fe(r)}function Fe(t){return m.isAbsolute(t)||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\/.test(t)||/^file:\/\//i.test(t)||t.includes("../")||t.includes("..\\")||t.startsWith(".\\")||t.startsWith("./")||t.includes("/")||t.includes("\\")}function Ue(t,e){let r=t.trim();if(/^file:\/\//i.test(r))try{r=Me(r)}catch{return null}let o=B(r)||B(e)?m.win32:m,n=o.resolve(e);return{candidate:o.isAbsolute(r)?o.resolve(r):o.resolve(n,r),root:n,pathApi:o}}function qe(t,e,r){let o=r.relative(e,t);return o===""||!o.startsWith("..")&&!r.isAbsolute(o)}function B(t){return/^[A-Za-z]:[\\/]/.test(t)||/^\\\\/.test(t)}function Q(t){if(!t||typeof t!="object")return[];let e=t,r=[],o=e.mcpServers??e.servers??e;for(let[n,i]of Object.entries(o)){if(!i||typeof i!="object")continue;let s=i;if(typeof s.url=="string"){r.push({name:n,type:"http",url:s.url,headers:s.headers&&typeof s.headers=="object"?s.headers:void 0,disabled:s.disabled===!0,oauth:s.oauth===!0,tools:J(s.tools),callTimeoutMs:typeof s.callTimeoutMs=="number"?s.callTimeoutMs:void 0});continue}typeof s.command=="string"&&r.push({name:n,type:"stdio",command:s.command,args:Array.isArray(s.args)?s.args:void 0,env:s.env&&typeof s.env=="object"?s.env:void 0,cwd:typeof s.cwd=="string"?s.cwd:void 0,disabled:s.disabled===!0,oauth:s.oauth===!0,tools:J(s.tools),callTimeoutMs:typeof s.callTimeoutMs=="number"?s.callTimeoutMs:void 0})}return r}function H(t,e){let r=new Set(e?.include??[]),o=new Set(e?.exclude??[]);return t.filter(n=>r.size>0&&!r.has(n.name)?!1:!o.has(n.name))}function J(t){if(!t||typeof t!="object")return;let e=t,r=V(e.include),o=V(e.exclude);if(!(!r&&!o))return{...r?{include:r}:{},...o?{exclude:o}:{}}}function V(t){if(!Array.isArray(t))return;let e=t.filter(r=>typeof r=="string"&&r.trim().length>0);return e.length>0?e:void 0}var Ge=new Set(["bash","sh","zsh","fish","cmd","cmd.exe","powershell","powershell.exe","pwsh","pwsh.exe"]),ze=new Set(["-c","/c","-command","-encodedcommand","-e"]),We=["curl","wget","invokewebrequest","invoke-restmethod","iwr","irm","nc","netcat"],Be=["env","processenv","apikey","api_key","token","secret","credential","credentials","awsaccesskey","awssecret"],He=["authorizedkeys","sshknownhosts","crontab","launchctl","schtasks","startup","runkey","runonce","bashrc","profile"],Je=/\bssh-(?:rsa|ed25519|ecdsa-[^\s]+)\s+[A-Za-z0-9+/=]{40,}/i;function Ve(t){let e=[],r=[t.command??"",...t.args??[],...Object.keys(t.env??{}),...Object.values(t.env??{})].join(`
8
- `);if(Je.test(r)&&e.push({code:"ioc_public_key",message:"configuration contains an inline SSH public key IOC"}),(t.type??(t.url?"http":"stdio"))!=="stdio"||!Ke(t.command))return e;let o=Qe(t.args??[]);if(!o)return e;let n=Ye(o);return T(n,He)&&e.push({code:"persistence",message:"stdio shell command attempts a persistence write"}),T(n,We)&&T(n,Be)&&e.push({code:"dangerous_egress",message:"stdio shell command combines network egress with likely secret access"}),e}function Ke(t){if(!t)return!1;let e=m.basename(t).toLowerCase();return Ge.has(e)}function Qe(t){for(let e=0;e<t.length;e++){let r=t[e]?.toLowerCase();if(r&&ze.has(r))return t.slice(e+1).join(" ")}return""}function Ye(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"")}function T(t,e){return e.some(r=>t.includes(r))}var tt=[{name:"skills_list",description:"List AstraClaw skills active for the current workspace.",inputSchema:{type:"object",properties:{},additionalProperties:!1}},{name:"skill_view",description:"Read the full SKILL.md instructions for one AstraClaw skill.",inputSchema:{type:"object",properties:{name:{type:"string",description:"Skill name from skills_list."}},required:["name"],additionalProperties:!1}},{name:"mcp_connectors_list",description:"List MCP connector tools installed in AstraClaw's Plugins page and shared with this external agent.",inputSchema:{type:"object",properties:{},additionalProperties:!1}},{name:"mcp_tool_call",description:"Call one AstraClaw shared MCP connector tool by toolName from mcp_connectors_list.",inputSchema:{type:"object",properties:{toolName:{type:"string",description:"Connector tool name, for example mcp__filesystem__read_text_file."},args:{type:"object",description:"Arguments for the connector tool."}},required:["toolName"],additionalProperties:!1}}],k=class{tools=new Map;findTool(e){return this.tools.get(e)}getToolManifest(){return Array.from(this.tools.values()).map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.parameters}}))}getToolNames(){return Array.from(this.tools.keys())}setTools(e){this.tools.clear(),this.addTools(e)}addTool(e){this.tools.set(e.name,e)}addTools(e){for(let r of e)this.addTool(r)}removeTool(e){return this.tools.delete(e)}},c=null,rt=Ze({input:process.stdin,crlfDelay:Number.POSITIVE_INFINITY});rt.on("line",t=>{ot(t)});async function ot(t){let e=t.trim();if(!e)return;let r;try{r=JSON.parse(e)}catch{return}if(r.id===void 0||r.id===null)return r.method==="notifications/initialized",void 0;try{let o=await nt(r);Z({jsonrpc:"2.0",id:r.id,result:o})}catch(o){Z({jsonrpc:"2.0",id:r.id,error:{code:-32603,message:o instanceof Error?o.message:String(o)}})}}async function nt(t){switch(t.method){case"initialize":return{protocolVersion:"2024-11-05",capabilities:{tools:{}},serverInfo:{name:j,version:"1.0.0"}};case"tools/list":return{tools:tt};case"tools/call":{let e=Y(t.params),r=typeof e.name=="string"?e.name:"",o=Y(e.arguments),n=st(),i=r==="mcp_connectors_list"||r==="mcp_tool_call"?await it(n):void 0,s=await L({tool:r,args:o,projectRoot:n,toolCatalog:i,mcpServerFailures:i?c?.manager?.getFailedServers():void 0});if(!s.handled)throw new Error(`Unknown tool: ${r}`);return{content:[{type:"text",text:JSON.stringify(s.result)}]}}default:throw new Error(`Unknown method: ${t.method}`)}}function st(){return process.env.ASTRACLAW_PROJECT_ROOT||process.env.QLOGICAGENT_PROJECT_ROOT||process.cwd()}async function it(t){if(c?.projectRoot===t)return await c.ready,c.catalog;c?.manager?.disconnectAll().catch(()=>{});let e=new k,r=new h({servers:at(),workspaceRoot:t,toolCatalog:e,log:{info:n=>process.stderr.write(`${n}
7
+ [${i.length} non-text blocks omitted: ${a}]`:`[output contains only non-text blocks: ${a}]`}return{content:[{type:"text",text:s||"(no text output)"}],...e.isError?{details:{error:"mcp_tool_error"}}:{}}}function B(t){return t.replace(/[^a-zA-Z0-9_]/g,"_").toLowerCase()}var Oe=/(?:^|_)(path|paths|file|files|filename|filenames|dir|dirs|directory|directories|folder|folders|cwd|root|uri)(?:$|_)/i;function $e(t,e,r){if(!r)return null;for(let o of k(e)){let n=Ue(o.value,r);if(n&&!qe(n.candidate,n.root,n.pathApi))return`Blocked: MCP tool "${t}" path "${o.value}" is outside the workspace boundary "${n.root}"`}return null}function k(t,e="",r=0){if(r>8)return[];if(typeof t=="string")return Ne(e,t)?[{key:e,value:t}]:[];if(Array.isArray(t))return t.flatMap(n=>k(n,e,r+1));if(!t||typeof t!="object")return[];let o=[];for(let[n,i]of Object.entries(t))o.push(...k(i,n,r+1));return o}function Ne(t,e){if(!Oe.test(t))return!1;let r=e.trim();return!r||/^https?:\/\//i.test(r)?!1:Fe(r)}function Fe(t){return m.isAbsolute(t)||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\/.test(t)||/^file:\/\//i.test(t)||t.includes("../")||t.includes("..\\")||t.startsWith(".\\")||t.startsWith("./")||t.includes("/")||t.includes("\\")}function Ue(t,e){let r=t.trim();if(/^file:\/\//i.test(r))try{r=Re(r)}catch{return null}let o=H(r)||H(e)?m.win32:m,n=o.resolve(e);return{candidate:o.isAbsolute(r)?o.resolve(r):o.resolve(n,r),root:n,pathApi:o}}function qe(t,e,r){let o=r.relative(e,t);return o===""||!o.startsWith("..")&&!r.isAbsolute(o)}function H(t){return/^[A-Za-z]:[\\/]/.test(t)||/^\\\\/.test(t)}function Q(t){if(!t||typeof t!="object")return[];let e=t,r=[],o=e.mcpServers??e.servers??e;for(let[n,i]of Object.entries(o)){if(!i||typeof i!="object")continue;let s=i;if(typeof s.url=="string"){r.push({name:n,type:"http",url:s.url,headers:s.headers&&typeof s.headers=="object"?s.headers:void 0,disabled:s.disabled===!0,oauth:s.oauth===!0,tools:V(s.tools),callTimeoutMs:typeof s.callTimeoutMs=="number"?s.callTimeoutMs:void 0});continue}typeof s.command=="string"&&r.push({name:n,type:"stdio",command:s.command,args:Array.isArray(s.args)?s.args:void 0,env:s.env&&typeof s.env=="object"?s.env:void 0,cwd:typeof s.cwd=="string"?s.cwd:void 0,disabled:s.disabled===!0,oauth:s.oauth===!0,tools:V(s.tools),callTimeoutMs:typeof s.callTimeoutMs=="number"?s.callTimeoutMs:void 0})}return r}function J(t,e){let r=new Set(e?.include??[]),o=new Set(e?.exclude??[]);return t.filter(n=>r.size>0&&!r.has(n.name)?!1:!o.has(n.name))}function V(t){if(!t||typeof t!="object")return;let e=t,r=K(e.include),o=K(e.exclude);if(!(!r&&!o))return{...r?{include:r}:{},...o?{exclude:o}:{}}}function K(t){if(!Array.isArray(t))return;let e=t.filter(r=>typeof r=="string"&&r.trim().length>0);return e.length>0?e:void 0}var Ge=new Set(["bash","sh","zsh","fish","cmd","cmd.exe","powershell","powershell.exe","pwsh","pwsh.exe"]),ze=new Set(["-c","/c","-command","-encodedcommand","-e"]),We=["curl","wget","invokewebrequest","invoke-restmethod","iwr","irm","nc","netcat"],Be=["env","processenv","apikey","api_key","token","secret","credential","credentials","awsaccesskey","awssecret"],He=["authorizedkeys","sshknownhosts","crontab","launchctl","schtasks","startup","runkey","runonce","bashrc","profile"],Je=/\bssh-(?:rsa|ed25519|ecdsa-[^\s]+)\s+[A-Za-z0-9+/=]{40,}/i;function Ve(t){let e=[],r=[t.command??"",...t.args??[],...Object.keys(t.env??{}),...Object.values(t.env??{})].join(`
8
+ `);if(Je.test(r)&&e.push({code:"ioc_public_key",message:"configuration contains an inline SSH public key IOC"}),(t.type??(t.url?"http":"stdio"))!=="stdio"||!Ke(t.command))return e;let o=Qe(t.args??[]);if(!o)return e;let n=Ye(o);return T(n,He)&&e.push({code:"persistence",message:"stdio shell command attempts a persistence write"}),T(n,We)&&T(n,Be)&&e.push({code:"dangerous_egress",message:"stdio shell command combines network egress with likely secret access"}),e}function Ke(t){if(!t)return!1;let e=m.basename(t).toLowerCase();return Ge.has(e)}function Qe(t){for(let e=0;e<t.length;e++){let r=t[e]?.toLowerCase();if(r&&ze.has(r))return t.slice(e+1).join(" ")}return""}function Ye(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"")}function T(t,e){return e.some(r=>t.includes(r))}var tt=[{name:"skills_list",description:"List AstraClaw skills active for the current workspace.",inputSchema:{type:"object",properties:{},additionalProperties:!1}},{name:"skill_view",description:"Read the full SKILL.md instructions for one AstraClaw skill.",inputSchema:{type:"object",properties:{name:{type:"string",description:"Skill name from skills_list."}},required:["name"],additionalProperties:!1}},{name:"mcp_connectors_list",description:"List MCP connector tools installed in AstraClaw's Plugins page and shared with this external agent.",inputSchema:{type:"object",properties:{},additionalProperties:!1}},{name:"mcp_tool_call",description:"Call one AstraClaw shared MCP connector tool by toolName from mcp_connectors_list.",inputSchema:{type:"object",properties:{toolName:{type:"string",description:"Connector tool name, for example mcp__filesystem__read_text_file."},args:{type:"object",description:"Arguments for the connector tool."}},required:["toolName"],additionalProperties:!1}}],P=class{tools=new Map;findTool(e){return this.tools.get(e)}getToolManifest(){return Array.from(this.tools.values()).map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.parameters}}))}getToolNames(){return Array.from(this.tools.keys())}setTools(e){this.tools.clear(),this.addTools(e)}addTool(e){this.tools.set(e.name,e)}addTools(e){for(let r of e)this.addTool(r)}removeTool(e){return this.tools.delete(e)}},c=null,rt=Ze({input:process.stdin,crlfDelay:Number.POSITIVE_INFINITY});rt.on("line",t=>{ot(t)});async function ot(t){let e=t.trim();if(!e)return;let r;try{r=JSON.parse(e)}catch{return}if(r.id===void 0||r.id===null)return r.method==="notifications/initialized",void 0;try{let o=await nt(r);Z({jsonrpc:"2.0",id:r.id,result:o})}catch(o){Z({jsonrpc:"2.0",id:r.id,error:{code:-32603,message:o instanceof Error?o.message:String(o)}})}}async function nt(t){switch(t.method){case"initialize":return{protocolVersion:"2024-11-05",capabilities:{tools:{}},serverInfo:{name:L,version:"1.0.0"}};case"tools/list":return{tools:tt};case"tools/call":{let e=Y(t.params),r=typeof e.name=="string"?e.name:"",o=Y(e.arguments),n=st(),i=r==="mcp_connectors_list"||r==="mcp_tool_call"?await it(n):void 0,s=await O({tool:r,args:o,projectRoot:n,toolCatalog:i,mcpServerFailures:i?c?.manager?.getFailedServers():void 0});if(!s.handled)throw new Error(`Unknown tool: ${r}`);return{content:[{type:"text",text:JSON.stringify(s.result)}]}}default:throw new Error(`Unknown method: ${t.method}`)}}function st(){return process.env.ASTRACLAW_PROJECT_ROOT||process.env.QLOGICAGENT_PROJECT_ROOT||process.cwd()}async function it(t){if(c?.projectRoot===t)return await c.ready,c.catalog;c?.manager?.disconnectAll().catch(()=>{});let e=new P,r=new h({servers:at(),workspaceRoot:t,toolCatalog:e,log:{info:n=>process.stderr.write(`${n}
9
9
  `),warn:n=>process.stderr.write(`${n}
10
- `)}}),o=r.connectAll().then(()=>r.injectTools());return c={projectRoot:t,catalog:e,manager:r,ready:o},await o,e}function at(){let t=process.env.ASTRACLAW_MCP_CONFIG_PATH||_();if(!Xe(t))return[];try{let e=et(t,"utf8").replace(/^\uFEFF/,"");return Q(JSON.parse(e))}catch(e){return process.stderr.write(`[astraclaw-native-mcp] failed to read MCP config: ${e instanceof Error?e.message:String(e)}
10
+ `)}}),o=r.connectAll().then(()=>r.injectTools());return c={projectRoot:t,catalog:e,manager:r,ready:o},await o,e}function at(){let t=process.env.ASTRACLAW_MCP_CONFIG_PATH||C();if(!Xe(t))return[];try{let e=et(t,"utf8").replace(/^\uFEFF/,"");return Q(JSON.parse(e))}catch(e){return process.stderr.write(`[astraclaw-native-mcp] failed to read MCP config: ${e instanceof Error?e.message:String(e)}
11
11
  `),[]}}function Y(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}function Z(t){process.stdout.write(`${JSON.stringify(t)}
12
12
  `)}
@@ -46,7 +46,7 @@ export interface AcpSessionHost {
46
46
  cancelIdleDreamTimer(): void;
47
47
  disposeSessionRuntime?(): void;
48
48
  enableIdleDream(): void;
49
- ensureDefaultProject(): void;
49
+ ensureDefaultProject(): void | Promise<void>;
50
50
  initializeHostProjectAuthority?(): Promise<void>;
51
51
  /**
52
52
  * Ensure the model-registry catalog (this.models) is hydrated from the owner profile +
@@ -1,8 +1,8 @@
1
1
  import type { CommunityInstallResolution } from "../runtime/community/community-consent-client.js";
2
- import { type InstalledCommunityPet } from "../runtime/pet/pet-community-assets.js";
2
+ import { type CommunityPetAdoptionProposal } from "../runtime/pet/pet-community-assets.js";
3
3
  import { type CommunityInstalledResource, type InstallCommunitySkillOptions } from "./community-skill-installer.js";
4
4
  import { type CommunityWorkflowBundlePayload } from "./community-workflow-installer.js";
5
- export type CommunityInstalledAnyResource = CommunityInstalledResource | InstalledCommunityPet | CommunityWorkflowBundlePayload;
5
+ export type CommunityInstalledAnyResource = CommunityInstalledResource | CommunityPetAdoptionProposal | CommunityWorkflowBundlePayload;
6
6
  export interface CommunityMcpInstallPreview {
7
7
  kind: "mcp";
8
8
  mode: "preview";
@@ -27,6 +27,4 @@ export interface CommunityExecutableLauncherGate {
27
27
  autoRunBlocked: true;
28
28
  manifest: unknown;
29
29
  }
30
- export declare function installCommunityResource(install: CommunityInstallResolution, options?: InstallCommunitySkillOptions & {
31
- ownerUserId?: string;
32
- }): Promise<CommunityInstalledAnyResource | CommunityMcpInstallPreview | CommunityExecutableLauncherGate>;
30
+ export declare function installCommunityResource(install: CommunityInstallResolution, options?: InstallCommunitySkillOptions): Promise<CommunityInstalledAnyResource | CommunityMcpInstallPreview | CommunityExecutableLauncherGate>;
@@ -24,7 +24,7 @@ interface DeferredHeavyWork {
24
24
  }
25
25
  /** Resolves once the most recently scheduled deferred heavy work has settled (never rejects). */
26
26
  export declare function getDefaultProjectHeavyWorkPromise(): Promise<void>;
27
- export declare function ensureDefaultProjectBootstrap(deps: DefaultProjectBootstrapDeps): ProjectMemoryStore;
27
+ export declare function ensureDefaultProjectBootstrap(deps: DefaultProjectBootstrapDeps): Promise<ProjectMemoryStore>;
28
28
  /**
29
29
  * Schedule (fire-and-forget) the deferred heavy work so it runs off the synchronous initialize path.
30
30
  * Exposed for tests; production calls it from ensureDefaultProjectBootstrap. Records a gate promise on
@@ -5,15 +5,11 @@
5
5
  * agents.kill, agents.listConfigured, agents.getLog, agents.testConnection
6
6
  */
7
7
  import { type AgentRpcError, type AgentRpcRequest } from "../../protocol/wire/index.js";
8
- import type { AgentProcessManager } from "../../runtime/infra/agent-process.js";
9
8
  import type { AgentConfigStore } from "../../runtime/infra/agent-config-store.js";
10
9
  import { type AcpDetector } from "../../runtime/infra/acp-detector.js";
11
- import { type PooledTurnCtx } from "../../runtime/infra/external-agent-pool.js";
12
10
  import type { DelegateBridge } from "../../orchestration/delegation-coordinator.js";
13
11
  export interface AgentsHandlerHost {
14
12
  acpDetector: AcpDetector;
15
- soloProcessManager: AgentProcessManager | null;
16
- productProcessManager: AgentProcessManager | null;
17
13
  ensureAgentConfigStore(): Promise<AgentConfigStore>;
18
14
  getActiveProjectRoot?(): string;
19
15
  handleMcpToolCall?(memberId: string, tool: string, args: Record<string, unknown>): Promise<unknown>;
@@ -23,6 +19,13 @@ export interface AgentsHandlerHost {
23
19
  /** 激活层(S3c §1.1):gateway-routed delegate 桥(懒读;未挂/gate 关 = undefined → 旧进程池路径)。 */
24
20
  getDelegateBridge?(): DelegateBridge | undefined;
25
21
  }
22
+ interface PooledTurnCtx {
23
+ sessionId?: string;
24
+ turnId?: string;
25
+ requestId?: string;
26
+ deltas: string[];
27
+ streamedAny: boolean;
28
+ }
26
29
  export declare function relayPooledTurnNotification(input: {
27
30
  agentId: string;
28
31
  turn: PooledTurnCtx | null;
@@ -68,8 +71,6 @@ export declare function handleAgentsLogout(this: AgentsHandlerHost, msg: AgentRp
68
71
  export declare function handleAgentsSetGateway(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
69
72
  export declare function handleAgentsGetGateway(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
70
73
  export declare function handleAgentsListConfigured(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
71
- export declare function handleAgentsProcesses(this: AgentsHandlerHost, msg: AgentRpcRequest): void;
72
- export declare function handleAgentsKill(this: AgentsHandlerHost, msg: AgentRpcRequest): void;
73
74
  export declare function handleAgentsGetLog(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
74
75
  export declare function handleAgentsTestConnection(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
75
76
  /** Formats a session persisted transcript into a compact prior-conversation block for an external
@@ -117,3 +118,4 @@ export declare function resolveNativeColdResume(input: {
117
118
  /** Pre-warm an external agent's process (on agent-select) so the first message skips the cold start. */
118
119
  export declare function handleAgentsWarm(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
119
120
  export declare function handleAgentsPrompt(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
121
+ export {};
@@ -6,10 +6,6 @@ export interface CommunityHandlerHost {
6
6
  resolveCommunityConsentClient?: () => CommunityConsentClient | null;
7
7
  getHostCapabilityClient?(): HostCapabilityClient | undefined;
8
8
  sendResponse(id: string | number, result?: unknown, error?: AgentRpcError): void;
9
- /** Push a JSON-RPC notification (e.g. pet.asset.updated after a community pet install hydrates the UI store). */
10
- sendNotification(method: string, params: Record<string, unknown>): void;
11
- /** Active owner id, so community pet install/publish land in the same profile pet.status reads. */
12
- memoryUserId?: string;
13
9
  }
14
10
  export declare function handleCommunityResolveInstall(this: CommunityHandlerHost, msg: AgentRpcRequest): Promise<void>;
15
11
  export declare function handleCommunityListResourceVersions(this: CommunityHandlerHost, msg: AgentRpcRequest): Promise<void>;
@@ -14,7 +14,7 @@ export interface ControlHandlerHost {
14
14
  log(message: string): void;
15
15
  sendResponse(id: string | number, result?: unknown, error?: AgentRpcError): void;
16
16
  sendNotification<M extends keyof NotificationMethodMap>(method: M, params: NotificationMethodMap[M]): void;
17
- ensureDefaultProject(): void;
17
+ ensureDefaultProject(): void | Promise<void>;
18
18
  /** LH-10: propagate an explicit cancel to the background tasks the current
19
19
  * session launched. No-op if the host has no task registry. */
20
20
  cancelBackgroundTasksForSession?(sessionId?: string): void;
@@ -19,7 +19,7 @@ export interface ProjectHandlerHost {
19
19
  }
20
20
  export declare function handleProjectCreate(this: ProjectHandlerHost, msg: AgentRpcRequest): Promise<void>;
21
21
  export declare function handleProjectList(this: ProjectHandlerHost, msg: AgentRpcRequest): void;
22
- export declare function handleProjectSwitch(this: ProjectHandlerHost, msg: AgentRpcRequest): void;
22
+ export declare function handleProjectSwitch(this: ProjectHandlerHost, msg: AgentRpcRequest): Promise<void>;
23
23
  /**
24
24
  * Reliable recursive directory removal for Windows. fs.rmSync({recursive,force}) cannot be trusted
25
25
  * here: on git repos it silently leaves read-only object/pack files (and whole subtrees) behind
@@ -90,13 +90,6 @@ export declare function handleSessionArchive(this: SessionHandlerHost, msg: Agen
90
90
  export declare function handleSessionMarkCleanShutdown(this: SessionHandlerHost, msg: AgentRpcRequest): Promise<void>;
91
91
  export declare function handleSessionResume(this: SessionHandlerHost, msg: AgentRpcRequest): Promise<void>;
92
92
  export declare function handleSessionGetInfo(this: SessionHandlerHost, msg: AgentRpcRequest): void;
93
- export declare function handleSessionSwitchProject(this: SessionHandlerHost, msg: AgentRpcRequest): Promise<void>;
94
- export declare function handleSessionGetState(this: SessionHandlerHost, msg: AgentRpcRequest): void;
95
- /**
96
- * `session.focus` - Desktop UI reports which session is currently focused.
97
- * Agent switches active project/cwd to the session's owning project.
98
- */
99
- export declare function handleSessionFocus(this: SessionHandlerHost, msg: AgentRpcRequest): Promise<void>;
100
93
  /**
101
94
  * `session.moveToProject` - Move a session from one project to another.
102
95
  * Physically copies session files, updates metadata.projectId, then removes the source.
@@ -3,7 +3,6 @@
3
3
  * Handles: solo.start, solo.status, solo.cancel, solo.select,
4
4
  * solo.list, solo.delete, solo.message, solo.evaluate
5
5
  */
6
- import { AgentProcessManager } from "../../runtime/infra/agent-process.js";
7
6
  import type { AcpDetector } from "../../runtime/infra/acp-detector.js";
8
7
  import type { AgentConfigStore } from "../../runtime/infra/agent-config-store.js";
9
8
  import { SoloEvaluator } from "../../orchestration/solo-evaluator.js";
@@ -12,7 +11,6 @@ import { type AgentRpcError, type AgentRpcRequest } from "../../protocol/wire/in
12
11
  export declare const soloProjectMap: Map<string, string>;
13
12
  export interface SoloHandlerHost {
14
13
  soloEvaluator: SoloEvaluator | null;
15
- soloProcessManager: AgentProcessManager | null;
16
14
  acpDetector: AcpDetector;
17
15
  agentConfigStore: AgentConfigStore | null;
18
16
  sendNotification(method: string, params: Record<string, unknown>): void;
@@ -20,7 +20,7 @@ export interface MemoryHostRequestAccess {
20
20
  }
21
21
  /** 装配期绑定(stdio-runtime-services 注入;lazy resolver——gate 在创建时刻现读)。重绑重置选型护栏。 */
22
22
  export declare function bindMemoryHostRequestAccess(resolve: () => MemoryHostRequestAccess | null): void;
23
- export declare function ensureLocalMemoryProvider(currentUserId: string): MemoryProviderState;
23
+ export declare function ensureHostMemoryProvider(currentUserId: string): MemoryProviderState;
24
24
  export interface RegisterMemoryRuntimeHooksDeps {
25
25
  hooks: HookRegistry;
26
26
  currentUserId: string;
@@ -1,11 +1,8 @@
1
1
  import type { ProductOrchestrator } from "../orchestration/agent-instance.js";
2
2
  import type { ProductPlanner } from "../orchestration/product-planner.js";
3
3
  import type { SoloEvaluator } from "../orchestration/solo-evaluator.js";
4
- import type { AgentProcessManager } from "../runtime/infra/agent-process.js";
5
4
  export declare class MultiAgentStateCoordinator {
6
5
  soloEvaluator: SoloEvaluator | null;
7
6
  productOrchestrator: ProductOrchestrator | null;
8
7
  productPlanner: ProductPlanner | null;
9
- soloProcessManager: AgentProcessManager | null;
10
- productProcessManager: AgentProcessManager | null;
11
8
  }
@@ -2,6 +2,7 @@ import type { ChatMessage } from "../agent/types.js";
2
2
  import type { ModelPurpose } from "../runtime/infra/model-registry.js";
3
3
  import { type PetStats, type PetdexPetAsset, type PetdexValidationReport } from "../runtime/pet/index.js";
4
4
  import { type PetdexProductionRun } from "../runtime/pet/petdex-forge-service.js";
5
+ import type { HostPetClient } from "../transport/host-pet-client.js";
5
6
  import type { LLMTransport } from "./provider-core-facade.js";
6
7
  export type PetSoulGenerator = (rarity: string, stats: PetStats) => Promise<{
7
8
  name: string;
@@ -47,15 +48,14 @@ export interface PetRuntime {
47
48
  reactAfterTurn(messages: ChatMessage[]): Promise<void>;
48
49
  /** Backfill missing daily journey summaries (per-owner, cross-project, idempotent, best-effort).
49
50
  * Owns the LLM + project-listing side effects so stdio-server doesn't reach into runtime/infra. */
50
- catchUpJourney(memoryUserId: string): Promise<string[]>;
51
+ catchUpJourney(): Promise<string[]>;
52
+ refreshActive(): Promise<boolean>;
51
53
  isActive(): boolean;
52
54
  }
53
55
  export interface PetRuntimeDeps {
54
- getActiveProjectRoot(): string;
55
- resolveOwnerUserId?: () => string;
56
56
  resolveClientForPurpose(purpose: ModelPurpose): PetLlmClient | null;
57
57
  sendNotification(method: string, params: Record<string, unknown>): void;
58
- /** Project ids for the cross-project journey backfill — injected so pet-runtime never imports the project store. */
59
- listProjectIds?: () => string[];
58
+ getCurrentSessionId?(): string | undefined;
59
+ resolveHostPetClient?(): HostPetClient | undefined;
60
60
  }
61
61
  export declare function createPetRuntime(deps: PetRuntimeDeps): PetRuntime;
@@ -1,7 +1,6 @@
1
1
  import { ProductOrchestrator } from "../orchestration/agent-instance.js";
2
2
  import { ProductPlanner } from "../orchestration/product-planner.js";
3
3
  import type { DelegateBridge } from "../orchestration/delegation-coordinator.js";
4
- import { AgentProcessManager } from "../runtime/infra/agent-process.js";
5
4
  import type { AgentConfigStore } from "../runtime/infra/agent-config-store.js";
6
5
  import type { AcpDetector } from "../runtime/infra/acp-detector.js";
7
6
  export interface ProductCoordinatorHost {
@@ -9,7 +8,6 @@ export interface ProductCoordinatorHost {
9
8
  agentConfigStore: AgentConfigStore | null;
10
9
  productOrchestrator: ProductOrchestrator | null;
11
10
  productPlanner: ProductPlanner | null;
12
- productProcessManager: AgentProcessManager | null;
13
11
  emitAgentStatus(agentId: string, state: string, extra?: {
14
12
  missedBeats?: number;
15
13
  lastActivityAt?: number;
@@ -1,2 +1,12 @@
1
+ import type { HostRequestParams, HostRequestService } from "../host-contract/index.js";
1
2
  import type { ProjectMemoryStoreFactory } from "../runtime/ports/index.js";
2
- export declare function createCliProjectMemoryStoreFactory(): ProjectMemoryStoreFactory;
3
+ export interface ProjectMemoryHostRequestAccess {
4
+ supportsHostRequestService(service: HostRequestService): boolean;
5
+ readonly hostRequest: {
6
+ request(params: HostRequestParams, opts?: {
7
+ timeoutMs?: number;
8
+ signal?: AbortSignal;
9
+ }): Promise<unknown>;
10
+ };
11
+ }
12
+ export declare function createCliProjectMemoryStoreFactory(resolveAccess?: () => ProjectMemoryHostRequestAccess | null, resolveSessionId?: () => string | undefined): ProjectMemoryStoreFactory;
@@ -9,7 +9,6 @@ import { type ProjectHandlerHost } from "./handlers/project-handler.js";
9
9
  import { type SessionHandlerHost } from "./handlers/session-handler.js";
10
10
  import { type SkillsHandlerHost } from "./handlers/skills-handler.js";
11
11
  import { type TurnBaselineHandlerHost } from "./handlers/turn-baseline-handler.js";
12
- import { type MessageFeedbackHandlerHost } from "./handlers/message-feedback-handler.js";
13
12
  import { type TurnControlHandlerHost } from "./handlers/turn-handler.js";
14
13
  import { type WorkingMaterialsHandlerHost } from "./handlers/working-materials-handler.js";
15
14
  import { type DreamHandlerHost } from "./handlers/dream-handler.js";
@@ -56,7 +55,6 @@ export interface RpcHandlerHosts {
56
55
  dream: DreamHandlerHost;
57
56
  turn: TurnControlHandlerHost;
58
57
  turnBaseline: TurnBaselineHandlerHost;
59
- messageFeedback: MessageFeedbackHandlerHost;
60
58
  workingMaterials: WorkingMaterialsHandlerHost;
61
59
  /** agents/solo/product are served by the multi-agent sub-host. */
62
60
  multiAgent: MultiAgentHandlerHost;
@@ -4,6 +4,7 @@ import type { LLMTransport } from "./provider-core-facade.js";
4
4
  import type { MemoryHostRequestAccess } from "./memory-coordinator.js";
5
5
  import { type StdioRuntimeServices } from "./stdio-runtime-services.js";
6
6
  import type { HostProfileClient } from "../transport/host-profile-client.js";
7
+ import type { HostPetClient } from "../transport/host-pet-client.js";
7
8
  export interface StdioRuntimeBootstrapDeps {
8
9
  verbose: boolean;
9
10
  getActiveProjectRoot(): string;
@@ -20,5 +21,6 @@ export interface StdioRuntimeBootstrapDeps {
20
21
  resolveMemoryHostRequestAccess?(): MemoryHostRequestAccess | null;
21
22
  /** Lazy session-bound host profile facade; unavailable/non-ACP must fail loud at first web invoke. */
22
23
  resolveHostProfileClient?(): HostProfileClient | undefined;
24
+ resolveHostPetClient?(): HostPetClient | undefined;
23
25
  }
24
26
  export declare function bootstrapStdioRuntimeServices(deps: StdioRuntimeBootstrapDeps): StdioRuntimeServices;
@@ -4,6 +4,7 @@ import { MediaPersistence } from "../runtime/infra/media-persistence.js";
4
4
  import { MediaClient, ProviderRegistry, type LLMTransport } from "./provider-core-facade.js";
5
5
  import { type MemoryHostRequestAccess, type MemoryProviderState } from "./memory-coordinator.js";
6
6
  import { type PetRuntime } from "./pet-runtime.js";
7
+ import type { HostPetClient } from "../transport/host-pet-client.js";
7
8
  import { type TurnMediaSetupHost } from "./turn-media-setup.js";
8
9
  export interface StdioRuntimeServicesDeps {
9
10
  getActiveProjectRoot(): string;
@@ -19,6 +20,7 @@ export interface StdioRuntimeServicesDeps {
19
20
  * memory provider 工厂据此在创建时刻按 memory service 一次性选型 HostMemoryProvider。
20
21
  */
21
22
  resolveMemoryHostRequestAccess?(): MemoryHostRequestAccess | null;
23
+ resolveHostPetClient?(): HostPetClient | undefined;
22
24
  }
23
25
  export interface StdioRuntimeServices {
24
26
  providerRegistry: ProviderRegistry;
@@ -26,6 +26,7 @@ import { SessionHistoryCoordinator } from "./session-history-coordinator.js";
26
26
  import { PetConfirmCoordinator } from "./pet-confirm-coordinator.js";
27
27
  import type { MemoryDreamRuntimeProvider, MemoryHandlerProvider, PermissionMode, ProjectMemoryStore } from "../runtime/ports/index.js";
28
28
  import { HostProfileClient } from "../transport/host-profile-client.js";
29
+ import { HostPetClient } from "../transport/host-pet-client.js";
29
30
  import { HostCapabilityClient } from "../transport/host-capability-client.js";
30
31
  import { HostSessionClient } from "../transport/host-session-client.js";
31
32
  import { HostProjectClient } from "../transport/host-project-client.js";
@@ -126,6 +127,7 @@ export declare class StdioServer {
126
127
  /** D2 telemetry/feedback business facade; durable storage remains gateway-only. */
127
128
  getHostFeedbackClient(): HostFeedbackClient | undefined;
128
129
  getHostProjectClient(): HostProjectClient | undefined;
130
+ getHostPetClient(): HostPetClient | undefined;
129
131
  initializeHostProjectAuthority(): Promise<void>;
130
132
  /**
131
133
  * Mid-turn guidance queue (运行中引导). Reset per turn by runTurnPipeline, pushed by
@@ -197,7 +199,7 @@ export declare class StdioServer {
197
199
  * Ensure a default project exists on first start.
198
200
  * Called from both legacy handleInitialize and ACP acpHandleInitialize.
199
201
  */
200
- ensureDefaultProject(): void;
202
+ ensureDefaultProject(): Promise<void>;
201
203
  /**
202
204
  * Atomically resolve transport + model + apiKey for a given ModelPurpose.
203
205
  * If the resolved provider matches `this.currentProvider`, reuses cached transport.
@@ -4,7 +4,7 @@
4
4
  * NOT our OSS. Lives in the config layer (not infra) so it can be public API:
5
5
  * the runtime gateway merges it into the agent env when the user's region/network
6
6
  * switch is on (cross-cutting ③); MCP subprocesses and skill shells then inherit
7
- * it via the agent-process FORWARDED_ENV_KEYS list.
7
+ * it through the Gateway Supervisor child-environment allow-list.
8
8
  *
9
9
  * Honest scope: this only redirects dependency *resolution* to official mirrors
10
10
  * (covers most). It does NOT guarantee cold/new packages (npmmirror sync lag →
@@ -17,7 +17,7 @@ export declare const CN_BINARY_HOST = "https://registry.npmmirror.com/-/binary";
17
17
  /** Mirror endpoint values (official mirrors, not our OSS). */
18
18
  export declare function buildCnMirrorEnv(): Record<string, string>;
19
19
  /**
20
- * The env keys `buildCnMirrorEnv()` sets. agent-process appends these to its
20
+ * The env keys `buildCnMirrorEnv()` sets. The Gateway Supervisor appends these to its
21
21
  * forwarded-env list so a mirror set on the agent propagates to MCP/skill children.
22
22
  */
23
23
  export declare const CN_MIRROR_ENV_KEYS: string[];