@hera-al/server 1.6.37 → 1.6.40

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.
@@ -1 +1 @@
1
- import{hostname as e,type as n,release as t,arch as o}from"node:os";import{modelRefName as s}from"../config.js";import{loadTemplate as a,loadBuiltInTools as r,formatWorkspaceFiles as i,formatWorkspaceFilesWithMeta as l,filterForSubagent as c}from"./workspace-files.js";import{createLogger as m}from"../utils/logger.js";const d=m("PromptBuilder");export function buildSystemPrompt(l){const{config:m,sessionContext:f,mode:E,hasNodeTools:y,hasMessageTools:_,coderSkill:I,subagentTask:O,toolServers:A}=l,R="minimal"===E?"SYSTEM_PROMPT_SUBAGENT.md":"SYSTEM_PROMPT.md",N=a(m.dataDir,R),w="minimal"===E?c(l.workspaceFiles):l.workspaceFiles,b=resolvePlaceholders(N,{SESSION_KEY:f.sessionKey,CHANNEL:f.channel,CHAT_ID:f.chatId,SESSION_ID:f.sessionId||"(new session)",MODEL:s(m.agent.model),HOSTNAME:e(),OS:`${n()} ${t()} (${o()})`,WORKSPACE_DIR:m.agent.workspacePath,DATA_DIR:m.dataDir,MEMORY_FILE:f.memoryFile||"(memory disabled)",ATTACHMENTS_DIR:f.attachmentsDir||"(memory disabled)",TIMEZONE:m.timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,CURRENT_DATE:(new Date).toLocaleDateString("en-US",{timeZone:m.timezone||void 0,weekday:"long",year:"numeric",month:"long",day:"numeric"}),SUBAGENT_TASK:O??"",NODE_TOOLS_INSTRUCTIONS:y?h():"",MESSAGE_TOOLS_INSTRUCTIONS:_?u():"",HEARTBEAT_INSTRUCTIONS:m.cron.enabled?p(m.cron.heartbeat.message):"",HEARTBEAT_PROMPT:m.cron.enabled?m.cron.heartbeat.message:"",CLAUDE_BUILT_IN_TOOLS:I?"":r(m.dataDir,E),SEARCH_IN_MEMORIES:"builtin-only"!==m.memory.recallStrategy?g():"",AVAILABLE_TOOLS:S(A),RUNTIME_LINE:T(m,f),WORKSPACE_FILES:i(w,m.dataDir)}).replace(/\n{3,}/g,"\n\n");return d.debug(`System prompt built (mode=${E}, template=${R}, length=${b.length})`),b}export function buildSystemPromptWithMeta(i){const{config:m,sessionContext:d,mode:f,hasNodeTools:E,hasMessageTools:y,coderSkill:_,subagentTask:I,toolServers:O}=i,A="minimal"===f?"SYSTEM_PROMPT_SUBAGENT.md":"SYSTEM_PROMPT.md",R=a(m.dataDir,A),N="minimal"===f?c(i.workspaceFiles):i.workspaceFiles,{formatted:w,meta:b}=l(N,m.dataDir);return{prompt:resolvePlaceholders(R,{SESSION_KEY:d.sessionKey,CHANNEL:d.channel,CHAT_ID:d.chatId,SESSION_ID:d.sessionId||"(new session)",MODEL:s(m.agent.model),HOSTNAME:e(),OS:`${n()} ${t()} (${o()})`,WORKSPACE_DIR:m.agent.workspacePath,DATA_DIR:m.dataDir,MEMORY_FILE:d.memoryFile||"(memory disabled)",ATTACHMENTS_DIR:d.attachmentsDir||"(memory disabled)",TIMEZONE:m.timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,CURRENT_DATE:(new Date).toLocaleDateString("en-US",{timeZone:m.timezone||void 0,weekday:"long",year:"numeric",month:"long",day:"numeric"}),SUBAGENT_TASK:I??"",NODE_TOOLS_INSTRUCTIONS:E?h():"",MESSAGE_TOOLS_INSTRUCTIONS:y?u():"",HEARTBEAT_INSTRUCTIONS:m.cron.enabled?p(m.cron.heartbeat.message):"",HEARTBEAT_PROMPT:m.cron.enabled?m.cron.heartbeat.message:"",CLAUDE_BUILT_IN_TOOLS:_?"":r(m.dataDir,f),SEARCH_IN_MEMORIES:"builtin-only"!==m.memory.recallStrategy?g():"",AVAILABLE_TOOLS:S(O),RUNTIME_LINE:T(m,d),WORKSPACE_FILES:w}).replace(/\n{3,}/g,"\n\n"),meta:b}}export function resolvePlaceholders(e,n){return e.replace(/\{\{(\w+)\}\}/g,(e,t)=>t in n?n[t]:(d.warn(`Unknown placeholder: {{${t}}}`),`{{${t}}}`))}function h(){return"# Remote Nodes\n\nYou have access to remote nodes — external machines that you can control. Use the node tools to discover and interact with them.\n\n## Available tools\n\n- **list_nodes**: Call this to see which nodes are currently connected. Returns each node's ID, name, platform, hostname, and available commands. Always call this first before trying to execute commands, so you know which nodes are online and what their IDs are.\n\n- **node_exec**: Execute a command on a specific node. You must provide the nodeId (from list_nodes), the command name, and its parameters.\n\n## Supported commands\n\n- **shell.run**: Run a shell command on the node. Params: { cmd: string, args?: string[], cwd?: string, timeout?: number, env?: Record<string,string> }. Returns { stdout, stderr, exitCode }.\n- **shell.which**: Check if a binary exists on the node. Params: { cmd: string }. Returns { path } or null.\n\n## Guidelines\n\n- Always call list_nodes first to discover available nodes and their IDs. Do not guess node IDs.\n- When a user asks to run something on a remote machine, a node, or a specific hostname, call list_nodes to see what's online, then use node_exec with the appropriate nodeId.\n- If multiple nodes are connected, ask the user which one to use when the intent is ambiguous.\n- If no nodes are connected, inform the user that no remote nodes are available.\n- Report command results clearly: show stdout, note any stderr, and mention non-zero exit codes."}function u(){return"# Messaging\n\nYou have tools to send messages to chat channels. Each message you process includes a <session_info> block with the current channel and chatId.\n\n## Available tools\n\n- **send_message**: Send a text message to a specific channel and chat. Use the channel and chatId from the session context to reply on the current conversation. You can also send to a different channel or chatId if instructed.\n\n- **list_channels**: List all registered channels. Returns each channel's name and whether it is active.\n\n## Guidelines\n\n- Use send_message when you need to proactively send a message outside of the normal response flow (e.g. notifications, forwarding, or sending to a different chat).\n- Your normal response text is already delivered to the user. Only use send_message for additional messages or cross-channel communication.\n- The channel and chatId from the session context identify the current conversation. Use them to send follow-up messages to the same chat.\n- If the user asks you to message someone on a different channel or chat, use the appropriate channel name and chatId.\n- Never spam or send unsolicited messages. Only send when explicitly asked or when it is clearly part of the task."}function p(e){return`# Heartbeats\n\nHeartbeat prompt: ${e}\nIf you receive a heartbeat poll (a user message matching the heartbeat prompt above), and there is nothing that needs attention, reply exactly:\nHEARTBEAT_OK\nThe system treats a leading/trailing "HEARTBEAT_OK" as a heartbeat ack and may suppress it (not deliver to the user).\nIf something needs attention, do NOT include "HEARTBEAT_OK"; reply with the alert text instead.`}function g(){return"## Memory Search Tools\n\nYou have access to memory search tools for recalling past conversations and knowledge:\n\n- `memory_search` — semantically searches Markdown chunks (~400 token target, 80-token overlap) from `MEMORY.md` + `memory/**/*.md`. It returns snippet text (capped ~700 chars), file path, line range, and score. No full file payload is returned.\n- `memory_get` — reads a specific memory Markdown file (workspace-relative), optionally from a starting line and for N lines. Paths outside `MEMORY.md` / `memory/` are rejected.\n\nUse `memory_search` to find relevant past context before answering questions that might relate to previous conversations. Use `memory_get` to read the full content of a memory file when a search snippet is not enough."}function S(e){if(!e||0===e.length)return"";const n=[];for(const t of e){const e=t,o=e.instance?._registeredTools;if(o)for(const[e,t]of Object.entries(o)){const o=t.description||"",s=t.inputSchema?.def?.shape,a=[];if(s)for(const[e,n]of Object.entries(s)){let t=n.type||"unknown";"ZodNumber"===t?t="number":"ZodString"===t?t="string":"ZodBoolean"===t?t="boolean":"ZodArray"===t?t="array":"ZodObject"===t?t="object":"ZodEnum"===t&&(t="enum");const o=n.isOptional?.()??!1;a.push(`${e}${o?"?":""}: ${t}`)}const r=a.length>0?`Params: { ${a.join(", ")} }`:"No parameters.",i=o.match(/\.\s*(Returns?\s.+?)\.?\s*$/i),l=i?i[1].trim():"";let c=`- **${e}**: ${i?o.slice(0,i.index).trim():o.trim()}. ${r}`;l&&(c+=`. ${l}.`),n.push(c)}}return 0===n.length?"":n.join("\n")}function T(a,r){return`host=${e()} | os=${n()} ${t()} (${o()}) | model=${s(a.agent.model)} | channel=${r.channel} | session=${r.sessionKey}`}export function buildPrompt(e,n,t,o){const s=[],a=[];if(o){const n=e.contentBlocks.find(e=>"text"===e.type)?.text??"",t=/^\[.*\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(n),a=/Current time: /.test(n),r=n.startsWith("/");if(!t&&!a&&!r){const e=new Date,n=new Intl.DateTimeFormat("en-US",{timeZone:o,weekday:"short"}).format(e),t=e.toLocaleString("en-US",{timeZone:o,year:"numeric"}),a=e.toLocaleString("en-US",{timeZone:o,month:"2-digit"}),r=e.toLocaleString("en-US",{timeZone:o,day:"2-digit"}),i=e.toLocaleString("en-GB",{timeZone:o,hour:"2-digit",minute:"2-digit",hour12:!1});s.push(`[${n} ${t}-${a}-${r} ${i}]`)}}n&&s.push("<conversation_history>",n,"</conversation_history>","");for(const n of e.contentBlocks)"text"===n.type&&n.text?s.push(n.text):"image"===n.type&&n.imageBase64&&a.push({base64:n.imageBase64,mimeType:n.imageMimeType??"image/jpeg"});const r=e.savedFiles.filter(e=>!e.endsWith(".tgs"));if(r.length>0){s.push(""),s.push("Files available in the current working directory:");for(const e of r)s.push(`- ${e}`)}return{text:s.join("\n"),images:a}}
1
+ import{hostname as e,type as n,release as t,arch as o}from"node:os";import{modelRefName as s}from"../config.js";import{loadTemplate as a,loadBuiltInTools as r,formatWorkspaceFiles as i,formatWorkspaceFilesWithMeta as l,filterForSubagent as c}from"./workspace-files.js";import{createLogger as m}from"../utils/logger.js";const d=m("PromptBuilder");export function buildSystemPrompt(l){const{config:m,sessionContext:f,mode:E,hasNodeTools:y,hasMessageTools:I,coderSkill:_,subagentTask:O,toolServers:A}=l,w="minimal"===E?"SYSTEM_PROMPT_SUBAGENT.md":"SYSTEM_PROMPT.md",N=a(m.dataDir,w),R="minimal"===E?c(l.workspaceFiles):l.workspaceFiles;var b;const M=resolvePlaceholders(N,{SESSION_KEY:f.sessionKey,CHANNEL:f.channel,CHAT_ID:f.chatId,SESSION_ID:f.sessionId||"(new session)",MODEL:s(m.agent.model),HOSTNAME:e(),OS:`${n()} ${t()} (${o()})`,WORKSPACE_DIR:m.agent.workspacePath,DATA_DIR:m.dataDir,MEMORY_FILE:f.memoryFile||"(memory disabled)",ATTACHMENTS_DIR:f.attachmentsDir||"(memory disabled)",TIMEZONE:m.timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,CURRENT_DATE:(new Date).toLocaleDateString("en-US",{timeZone:m.timezone||void 0,weekday:"long",year:"numeric",month:"long",day:"numeric"}),SUBAGENT_TASK:O??"",NODE_TOOLS_INSTRUCTIONS:y?h():"",MESSAGE_TOOLS_INSTRUCTIONS:I?u():"",HEARTBEAT_INSTRUCTIONS:m.cron.enabled?g(m.cron.heartbeat.message):"",HEARTBEAT_PROMPT:m.cron.enabled?m.cron.heartbeat.message:"",CLAUDE_BUILT_IN_TOOLS:_?"":r(m.dataDir,E),SEARCH_IN_MEMORIES:"builtin-only"!==m.memory.recallStrategy?p():"",AVAILABLE_TOOLS:S(A),MESH_INFO:m.channels.mesh.enabled?(b=m.channels.mesh.agentId,["## Mesh (Inter-Agent Communication)","",`You are connected to the Hera Mesh as **${b}**.`,"The mesh allows direct communication between agents (e.g. Dante ↔ Beatrice).","","- To see who's online: use the **mesh-agents** skill",'- To send a message: `send_message(channel="mesh", chatId="<agentId>", text="...")`',"- Incoming mesh messages appear as normal messages from channel=mesh",""].join("\n")):"",RUNTIME_LINE:T(m,f),WORKSPACE_FILES:i(R,m.dataDir)}).replace(/\n{3,}/g,"\n\n");return d.debug(`System prompt built (mode=${E}, template=${w}, length=${M.length})`),M}export function buildSystemPromptWithMeta(i){const{config:m,sessionContext:d,mode:f,hasNodeTools:E,hasMessageTools:y,coderSkill:I,subagentTask:_,toolServers:O}=i,A="minimal"===f?"SYSTEM_PROMPT_SUBAGENT.md":"SYSTEM_PROMPT.md",w=a(m.dataDir,A),N="minimal"===f?c(i.workspaceFiles):i.workspaceFiles,{formatted:R,meta:b}=l(N,m.dataDir);return{prompt:resolvePlaceholders(w,{SESSION_KEY:d.sessionKey,CHANNEL:d.channel,CHAT_ID:d.chatId,SESSION_ID:d.sessionId||"(new session)",MODEL:s(m.agent.model),HOSTNAME:e(),OS:`${n()} ${t()} (${o()})`,WORKSPACE_DIR:m.agent.workspacePath,DATA_DIR:m.dataDir,MEMORY_FILE:d.memoryFile||"(memory disabled)",ATTACHMENTS_DIR:d.attachmentsDir||"(memory disabled)",TIMEZONE:m.timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,CURRENT_DATE:(new Date).toLocaleDateString("en-US",{timeZone:m.timezone||void 0,weekday:"long",year:"numeric",month:"long",day:"numeric"}),SUBAGENT_TASK:_??"",NODE_TOOLS_INSTRUCTIONS:E?h():"",MESSAGE_TOOLS_INSTRUCTIONS:y?u():"",HEARTBEAT_INSTRUCTIONS:m.cron.enabled?g(m.cron.heartbeat.message):"",HEARTBEAT_PROMPT:m.cron.enabled?m.cron.heartbeat.message:"",CLAUDE_BUILT_IN_TOOLS:I?"":r(m.dataDir,f),SEARCH_IN_MEMORIES:"builtin-only"!==m.memory.recallStrategy?p():"",AVAILABLE_TOOLS:S(O),RUNTIME_LINE:T(m,d),WORKSPACE_FILES:R}).replace(/\n{3,}/g,"\n\n"),meta:b}}export function resolvePlaceholders(e,n){return e.replace(/\{\{(\w+)\}\}/g,(e,t)=>t in n?n[t]:(d.warn(`Unknown placeholder: {{${t}}}`),`{{${t}}}`))}function h(){return"# Remote Nodes\n\nYou have access to remote nodes — external machines that you can control. Use the node tools to discover and interact with them.\n\n## Available tools\n\n- **list_nodes**: Call this to see which nodes are currently connected. Returns each node's ID, name, platform, hostname, and available commands. Always call this first before trying to execute commands, so you know which nodes are online and what their IDs are.\n\n- **node_exec**: Execute a command on a specific node. You must provide the nodeId (from list_nodes), the command name, and its parameters.\n\n## Supported commands\n\n- **shell.run**: Run a shell command on the node. Params: { cmd: string, args?: string[], cwd?: string, timeout?: number, env?: Record<string,string> }. Returns { stdout, stderr, exitCode }.\n- **shell.which**: Check if a binary exists on the node. Params: { cmd: string }. Returns { path } or null.\n\n## Guidelines\n\n- Always call list_nodes first to discover available nodes and their IDs. Do not guess node IDs.\n- When a user asks to run something on a remote machine, a node, or a specific hostname, call list_nodes to see what's online, then use node_exec with the appropriate nodeId.\n- If multiple nodes are connected, ask the user which one to use when the intent is ambiguous.\n- If no nodes are connected, inform the user that no remote nodes are available.\n- Report command results clearly: show stdout, note any stderr, and mention non-zero exit codes."}function u(){return"# Messaging\n\nYou have tools to send messages to chat channels. Each message you process includes a <session_info> block with the current channel and chatId.\n\n## Available tools\n\n- **send_message**: Send a text message to a specific channel and chat. Use the channel and chatId from the session context to reply on the current conversation. You can also send to a different channel or chatId if instructed.\n\n- **list_channels**: List all registered channels. Returns each channel's name and whether it is active.\n\n## Guidelines\n\n- Use send_message when you need to proactively send a message outside of the normal response flow (e.g. notifications, forwarding, or sending to a different chat).\n- Your normal response text is already delivered to the user. Only use send_message for additional messages or cross-channel communication.\n- The channel and chatId from the session context identify the current conversation. Use them to send follow-up messages to the same chat.\n- If the user asks you to message someone on a different channel or chat, use the appropriate channel name and chatId.\n- Never spam or send unsolicited messages. Only send when explicitly asked or when it is clearly part of the task."}function g(e){return`# Heartbeats\n\nHeartbeat prompt: ${e}\nIf you receive a heartbeat poll (a user message matching the heartbeat prompt above), and there is nothing that needs attention, reply exactly:\nHEARTBEAT_OK\nThe system treats a leading/trailing "HEARTBEAT_OK" as a heartbeat ack and may suppress it (not deliver to the user).\nIf something needs attention, do NOT include "HEARTBEAT_OK"; reply with the alert text instead.`}function p(){return"## Memory Search Tools\n\nYou have access to memory search tools for recalling past conversations and knowledge:\n\n- `memory_search` — semantically searches Markdown chunks (~400 token target, 80-token overlap) from `MEMORY.md` + `memory/**/*.md`. It returns snippet text (capped ~700 chars), file path, line range, and score. No full file payload is returned.\n- `memory_get` — reads a specific memory Markdown file (workspace-relative), optionally from a starting line and for N lines. Paths outside `MEMORY.md` / `memory/` are rejected.\n\nUse `memory_search` to find relevant past context before answering questions that might relate to previous conversations. Use `memory_get` to read the full content of a memory file when a search snippet is not enough."}function S(e){if(!e||0===e.length)return"";const n=[];for(const t of e){const e=t,o=e.instance?._registeredTools;if(o)for(const[e,t]of Object.entries(o)){const o=t.description||"",s=t.inputSchema?.def?.shape,a=[];if(s)for(const[e,n]of Object.entries(s)){let t=n.type||"unknown";"ZodNumber"===t?t="number":"ZodString"===t?t="string":"ZodBoolean"===t?t="boolean":"ZodArray"===t?t="array":"ZodObject"===t?t="object":"ZodEnum"===t&&(t="enum");const o=n.isOptional?.()??!1;a.push(`${e}${o?"?":""}: ${t}`)}const r=a.length>0?`Params: { ${a.join(", ")} }`:"No parameters.",i=o.match(/\.\s*(Returns?\s.+?)\.?\s*$/i),l=i?i[1].trim():"";let c=`- **${e}**: ${i?o.slice(0,i.index).trim():o.trim()}. ${r}`;l&&(c+=`. ${l}.`),n.push(c)}}return 0===n.length?"":n.join("\n")}function T(a,r){return`host=${e()} | os=${n()} ${t()} (${o()}) | model=${s(a.agent.model)} | channel=${r.channel} | session=${r.sessionKey}`}export function buildPrompt(e,n,t,o){const s=[],a=[];if(o){const n=e.contentBlocks.find(e=>"text"===e.type)?.text??"",t=/^\[.*\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(n),a=/Current time: /.test(n),r=n.startsWith("/");if(!t&&!a&&!r){const e=new Date,n=new Intl.DateTimeFormat("en-US",{timeZone:o,weekday:"short"}).format(e),t=e.toLocaleString("en-US",{timeZone:o,year:"numeric"}),a=e.toLocaleString("en-US",{timeZone:o,month:"2-digit"}),r=e.toLocaleString("en-US",{timeZone:o,day:"2-digit"}),i=e.toLocaleString("en-GB",{timeZone:o,hour:"2-digit",minute:"2-digit",hour12:!1});s.push(`[${n} ${t}-${a}-${r} ${i}]`)}}n&&s.push("<conversation_history>",n,"</conversation_history>","");for(const n of e.contentBlocks)"text"===n.type&&n.text?s.push(n.text):"image"===n.type&&n.imageBase64&&a.push({base64:n.imageBase64,mimeType:n.imageMimeType??"image/jpeg"});const r=e.savedFiles.filter(e=>!e.endsWith(".tgs"));if(r.length>0){s.push(""),s.push("Files available in the current working directory:");for(const e of r)s.push(`- ${e}`)}return{text:s.join("\n"),images:a}}
@@ -23,11 +23,17 @@ export declare class MeshChannel implements ChannelAdapter {
23
23
  private reconnectDelay;
24
24
  private stopping;
25
25
  private pingTimer;
26
+ /** Track message IDs we sent, so we can recognize replies and not loop. */
27
+ private pendingOutbound;
26
28
  constructor(config: MeshChannelConfig);
27
29
  start(onMessage: MessageHandler): Promise<void>;
28
30
  private connect;
29
31
  /**
30
32
  * Convert an incoming mesh message into an IncomingMessage and dispatch it.
33
+ *
34
+ * Anti-loop logic: if the message is a reply (replyTo) to something we sent,
35
+ * it's a response — dispatch to agent but do NOT auto-send the agent's reply back.
36
+ * If it's a new message (no replyTo matching our outbound), dispatch AND auto-reply.
31
37
  */
32
38
  private handleMeshMessage;
33
39
  sendText(chatId: string, text: string): Promise<void>;
@@ -36,8 +42,23 @@ export declare class MeshChannel implements ChannelAdapter {
36
42
  */
37
43
  sendTyped(to: string, type: string, payload: unknown, replyTo?: string): string;
38
44
  getSessionToken(): string | null;
45
+ getAgentId(): string;
39
46
  getBrokerHttpUrl(): string;
40
47
  isConnected(): boolean;
48
+ /** Known peers from presence events. Updated in real-time. */
49
+ private knownPeers;
50
+ /**
51
+ * Fetch the list of agents from the broker HTTP API.
52
+ * Returns agent IDs with their online/offline status.
53
+ */
54
+ getAgents(): Promise<Array<{
55
+ agentId: string;
56
+ status: string;
57
+ }>>;
58
+ /**
59
+ * Get a summary string for system prompt injection.
60
+ */
61
+ getMeshPromptInfo(): Promise<string>;
41
62
  private sendRaw;
42
63
  private startPing;
43
64
  private stopPing;
@@ -1 +1 @@
1
- import e from"node:crypto";import{WebSocket as t}from"ws";import{createLogger as s}from"../../utils/logger.js";const n=s("Mesh");function o(t,s){const n=function(t){const s=Buffer.from(t,"hex"),n=Buffer.from("302e020100300506032b657004220420","hex"),o=Buffer.concat([n,s]);return e.createPrivateKey({key:o,format:"der",type:"pkcs8"})}(s),o=Buffer.from(t,"hex");return e.sign(null,o,n).toString("hex")}export class MeshChannel{name="mesh";ws=null;config;onMessage=null;sessionToken=null;connected=!1;reconnectTimer=null;reconnectDelay;stopping=!1;pingTimer=null;constructor(e){this.config=e,this.reconnectDelay=e.reconnectDelayMs??5e3}async start(e){this.onMessage=e,this.stopping=!1,await this.connect()}connect(){return new Promise((e,s)=>{const{brokerUrl:i,agentId:r}=this.config;n.info(`Connecting to mesh broker at ${i} as ${r}...`);try{this.ws=new t(i)}catch(t){return n.error(`Failed to create WebSocket: ${t}`),this.scheduleReconnect(),void e()}let c=!1;const a=t=>{c||(c=!0,t?(n.error(`Mesh connection failed: ${t.message}`),this.scheduleReconnect(),e()):e())},h=setTimeout(()=>{a(new Error("Connection timeout")),this.ws?.close()},1e4);this.ws.on("open",()=>{}),this.ws.on("message",e=>{let t;try{t=JSON.parse(e.toString())}catch{return void n.warn("Invalid JSON from mesh broker")}switch(t.type){case"challenge":{const e=o(t.challenge,this.config.privateKey);this.sendRaw({type:"auth",agentId:this.config.agentId,signature:e,timestamp:Date.now()});break}case"auth_result":clearTimeout(h),t.authenticated&&t.sessionToken?(this.connected=!0,this.sessionToken=t.sessionToken,n.info(`Authenticated as ${this.config.agentId} on mesh`),this.startPing(),a()):a(new Error(`Auth failed: ${t.error??"unknown"}`));break;case"message":this.handleMeshMessage(t.message),this.sendRaw({type:"ack",messageId:t.message.id});break;case"presence":n.info(`Mesh presence: ${t.agentId} is ${t.status}`);break;case"ping":this.sendRaw({type:"pong"});break;case"pong":case"ack":break;case"error":n.warn(`Mesh error: ${t.error}`)}}),this.ws.on("close",(e,t)=>{clearTimeout(h),this.connected=!1,this.sessionToken=null,this.stopPing(),n.info(`Mesh connection closed (code=${e}, reason=${t?.toString()??"?"})`),this.stopping||this.scheduleReconnect(),a()}),this.ws.on("error",e=>{n.error(`Mesh WebSocket error: ${e.message}`)})})}async handleMeshMessage(e){if(!this.onMessage)return;const t=e.from;let s;if("string"==typeof e.payload)s=e.payload;else if(e.payload&&"object"==typeof e.payload){const t=e.payload;s="string"==typeof t.text?t.text:`[Mesh ${e.type}] ${JSON.stringify(e.payload)}`}else s=`[Mesh ${e.type}]`;const o={chatId:t,userId:e.from,channelName:"mesh",text:s,attachments:[],username:e.from};n.info(`Message from ${e.from}: ${e.type} → dispatching to agent`);try{const e=await this.onMessage(o);e&&e.trim()&&await this.sendText(t,e)}catch(t){n.error(`Error handling mesh message from ${e.from}: ${t}`)}}async sendText(t,s){if(!this.connected||!this.ws)return void n.warn(`Cannot send to ${t}: mesh not connected`);const o={id:e.randomUUID(),from:this.config.agentId,to:t,type:"text",payload:{text:s},timestamp:Date.now()};this.sendRaw({type:"message",message:o}),n.debug(`Sent to ${t}: ${s.slice(0,80)}...`)}sendTyped(t,s,n,o){if(!this.connected||!this.ws)throw new Error("Mesh not connected");const i={id:e.randomUUID(),from:this.config.agentId,to:t,type:s,payload:n,timestamp:Date.now(),replyTo:o};return this.sendRaw({type:"message",message:i}),i.id}getSessionToken(){return this.sessionToken}getBrokerHttpUrl(){return this.config.brokerUrl.replace("ws://","http://").replace("wss://","https://").replace("/ws","")}isConnected(){return this.connected}sendRaw(e){this.ws&&this.ws.readyState===t.OPEN&&this.ws.send(JSON.stringify(e))}startPing(){this.stopPing(),this.pingTimer=setInterval(()=>{this.connected&&this.sendRaw({type:"ping"})},3e4)}stopPing(){this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=null)}scheduleReconnect(){this.stopping||this.reconnectTimer||(n.info(`Reconnecting in ${this.reconnectDelay}ms...`),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect().catch(e=>{n.error(`Reconnect failed: ${e}`)})},this.reconnectDelay))}async stop(){this.stopping=!0,this.stopPing(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws&&(this.ws.close(1e3,"Channel stopping"),this.ws=null),this.connected=!1,n.info("Mesh channel stopped")}}
1
+ import e from"node:crypto";import{WebSocket as t}from"ws";import{createLogger as n}from"../../utils/logger.js";const s=n("Mesh");function o(t,n){const s=function(t){const n=Buffer.from(t,"hex"),s=Buffer.from("302e020100300506032b657004220420","hex"),o=Buffer.concat([s,n]);return e.createPrivateKey({key:o,format:"der",type:"pkcs8"})}(n),o=Buffer.from(t,"hex");return e.sign(null,o,s).toString("hex")}export class MeshChannel{name="mesh";ws=null;config;onMessage=null;sessionToken=null;connected=!1;reconnectTimer=null;reconnectDelay;stopping=!1;pingTimer=null;pendingOutbound=new Set;constructor(e){this.config=e,this.reconnectDelay=e.reconnectDelayMs??5e3}async start(e){this.onMessage=e,this.stopping=!1,await this.connect()}connect(){return new Promise((e,n)=>{const{brokerUrl:i,agentId:r}=this.config;s.info(`Connecting to mesh broker at ${i} as ${r}...`);try{this.ws=new t(i)}catch(t){return s.error(`Failed to create WebSocket: ${t}`),this.scheduleReconnect(),void e()}let a=!1;const c=t=>{a||(a=!0,t?(s.error(`Mesh connection failed: ${t.message}`),this.scheduleReconnect(),e()):e())},h=setTimeout(()=>{c(new Error("Connection timeout")),this.ws?.close()},1e4);this.ws.on("open",()=>{}),this.ws.on("message",e=>{let t;try{t=JSON.parse(e.toString())}catch{return void s.warn("Invalid JSON from mesh broker")}switch(t.type){case"challenge":{const e=o(t.challenge,this.config.privateKey);this.sendRaw({type:"auth",agentId:this.config.agentId,signature:e,timestamp:Date.now()});break}case"auth_result":clearTimeout(h),t.authenticated&&t.sessionToken?(this.connected=!0,this.sessionToken=t.sessionToken,s.info(`Authenticated as ${this.config.agentId} on mesh`),this.startPing(),c()):c(new Error(`Auth failed: ${t.error??"unknown"}`));break;case"message":this.handleMeshMessage(t.message),this.sendRaw({type:"ack",messageId:t.message.id});break;case"presence":s.info(`Mesh presence: ${t.agentId} is ${t.status}`),this.knownPeers.set(t.agentId,t.status);break;case"ping":this.sendRaw({type:"pong"});break;case"pong":case"ack":break;case"error":s.warn(`Mesh error: ${t.error}`)}}),this.ws.on("close",(e,t)=>{clearTimeout(h),this.connected=!1,this.sessionToken=null,this.stopPing(),s.info(`Mesh connection closed (code=${e}, reason=${t?.toString()??"?"})`),this.stopping||this.scheduleReconnect(),c()}),this.ws.on("error",e=>{s.error(`Mesh WebSocket error: ${e.message}`)})})}async handleMeshMessage(t){if(!this.onMessage)return;const n=t.from,o=null!=t.replyTo&&this.pendingOutbound.has(t.replyTo);let i;if(t.replyTo&&this.pendingOutbound.has(t.replyTo)&&this.pendingOutbound.delete(t.replyTo),"string"==typeof t.payload)i=t.payload;else if(t.payload&&"object"==typeof t.payload){const e=t.payload;i="string"==typeof e.text?e.text:`[Mesh ${t.type}] ${JSON.stringify(t.payload)}`}else i=`[Mesh ${t.type}]`;const r={chatId:n,userId:t.from,channelName:"mesh",text:i,attachments:[],username:t.from};o?s.info(`Reply from ${t.from} (to outbound ${t.replyTo}) → dispatching to agent (no auto-reply)`):s.info(`New message from ${t.from}: ${t.type} → dispatching to agent (will auto-reply)`);try{const i=await this.onMessage(r);if(!o&&i&&i.trim()){const o={id:e.randomUUID(),from:this.config.agentId,to:n,type:"text",payload:{text:i},timestamp:Date.now(),replyTo:t.id};this.sendRaw({type:"message",message:o}),s.debug(`Auto-replied to ${t.from}: ${i.slice(0,80)}...`)}}catch(e){s.error(`Error handling mesh message from ${t.from}: ${e}`)}}async sendText(t,n){if(!this.connected||!this.ws)return void s.warn(`Cannot send to ${t}: mesh not connected`);const o=e.randomUUID(),i={id:o,from:this.config.agentId,to:t,type:"text",payload:{text:n},timestamp:Date.now()};this.pendingOutbound.add(o),this.sendRaw({type:"message",message:i}),s.debug(`Sent to ${t} (id=${o}): ${n.slice(0,80)}...`)}sendTyped(t,n,s,o){if(!this.connected||!this.ws)throw new Error("Mesh not connected");const i={id:e.randomUUID(),from:this.config.agentId,to:t,type:n,payload:s,timestamp:Date.now(),replyTo:o};return this.sendRaw({type:"message",message:i}),i.id}getSessionToken(){return this.sessionToken}getAgentId(){return this.config.agentId}getBrokerHttpUrl(){return this.config.brokerUrl.replace("ws://","http://").replace("wss://","https://").replace("/ws","")}isConnected(){return this.connected}knownPeers=new Map;async getAgents(){try{const e=this.getBrokerHttpUrl(),t=await fetch(`${e}/api/agents`,{headers:this.sessionToken?{Authorization:`Bearer ${this.sessionToken}`}:{}});if(!t.ok)throw new Error(`HTTP ${t.status}`);const n=await t.json();return Array.isArray(n.agents)?n.agents:[]}catch(e){s.warn(`Failed to fetch agents: ${e}`);const t=[];for(const[e,n]of this.knownPeers)t.push({agentId:e,status:n});return t}}async getMeshPromptInfo(){const e=(await this.getAgents()).filter(e=>e.agentId!==this.config.agentId);if(0===e.length)return"";const t=e.map(e=>`- **${e.agentId}** (${e.status??"unknown"})`);return["## Mesh (Inter-Agent Communication)",`You are connected to the Hera Mesh as **${this.config.agentId}**.`,"Other agents on the mesh:",...t,"",'To message an agent: use send_message(channel="mesh", chatId="<agentId>", text="...").',"When you receive a mesh message, it appears as a normal incoming message from channel=mesh."].join("\n")}sendRaw(e){this.ws&&this.ws.readyState===t.OPEN&&this.ws.send(JSON.stringify(e))}startPing(){this.stopPing(),this.pingTimer=setInterval(()=>{this.connected&&this.sendRaw({type:"ping"})},3e4)}stopPing(){this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=null)}scheduleReconnect(){this.stopping||this.reconnectTimer||(s.info(`Reconnecting in ${this.reconnectDelay}ms...`),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect().catch(e=>{s.error(`Reconnect failed: ${e}`)})},this.reconnectDelay))}async stop(){this.stopping=!0,this.stopPing(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws&&(this.ws.close(1e3,"Channel stopping"),this.ws=null),this.connected=!1,s.info("Mesh channel stopped")}}
@@ -1 +1 @@
1
- export function renderModals(){return'\n\x3c!-- Restart confirmation modal --\x3e\n<div class="modal-overlay" id="restartModal">\n <div class="modal">\n <button class="close-btn" onclick="closeRestartModal()">&times;</button>\n <h3>Restart Server</h3>\n <p>This will restart all channels, agents, and services. Active conversations will be interrupted.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn" onclick="doRestart()">Restart</button>\n <button class="btn-ghost" onclick="closeRestartModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="placeholderRefModal">\n <div class="modal" style="max-width:620px;text-align:left;max-height:85vh;overflow-y:auto">\n <button class="close-btn" onclick="document.getElementById(\'placeholderRefModal\').classList.remove(\'open\')">&times;</button>\n <h3 style="margin-bottom:14px">Placeholder Reference</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:14px">These placeholders are resolved at runtime when building the system prompt from templates.</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:40%">Placeholder</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><code>{{ATTACHMENTS_DIR}}</code></td><td>Path to the session attachments folder, or <code>(memory disabled)</code></td></tr>\n <tr><td><code>{{AVAILABLE_TOOLS}}</code></td><td>Auto-discovered list of all registered MCP tools with name, description, and parameters</td></tr>\n <tr><td><code>{{CHANNEL}}</code></td><td>Channel name, e.g. <code>telegram</code>, <code>responses</code></td></tr>\n <tr><td><code>{{CHAT_ID}}</code></td><td>Chat / conversation ID within the channel</td></tr>\n <tr><td><code>{{DATA_DIR}}</code></td><td>Absolute path to the data directory (workspace files, templates)</td></tr>\n <tr><td><code>{{HEARTBEAT_INSTRUCTIONS}}</code></td><td>Heartbeat/cron behavioral instructions, or empty if cron is disabled</td></tr>\n <tr><td><code>{{HEARTBEAT_PROMPT}}</code></td><td>Raw heartbeat prompt message from config</td></tr>\n <tr><td><code>{{HOSTNAME}}</code></td><td>Server hostname</td></tr>\n <tr><td><code>{{MEMORY_FILE}}</code></td><td>Path to the current conversation memory file, or <code>(memory disabled)</code></td></tr>\n <tr><td><code>{{MESSAGE_TOOLS_INSTRUCTIONS}}</code></td><td>Instructions for cross-channel messaging tools, or empty if not available</td></tr>\n <tr><td><code>{{MODEL}}</code></td><td>Active model ID, e.g. <code>claude-opus-4-6</code></td></tr>\n <tr><td><code>{{NODE_TOOLS_INSTRUCTIONS}}</code></td><td>Instructions for node remote-execution tools, or empty if no nodes connected</td></tr>\n <tr><td><code>{{OS}}</code></td><td>Operating system info (type, release, arch)</td></tr>\n <tr><td><code>{{RUNTIME_LINE}}</code></td><td>Composed runtime info line (host, OS, model, channel, session)</td></tr>\n <tr><td><code>{{SEARCH_IN_MEMORIES}}</code></td><td>Memory search tools instructions (<code>memory_search</code>, <code>memory_get</code>). Populated when Recall Strategy is not <code>builtin-only</code>, empty otherwise.</td></tr>\n <tr><td><code>{{SESSION_ID}}</code></td><td>SDK session ID for resumption, or <code>(new session)</code></td></tr>\n <tr><td><code>{{SESSION_KEY}}</code></td><td>Current session identifier, e.g. <code>telegram:12345</code></td></tr>\n <tr><td><code>{{SUBAGENT_TASK}}</code></td><td>Task description for subagent mode (empty for main agent)</td></tr>\n <tr><td><code>{{TIMEZONE}}</code></td><td>Server timezone, e.g. <code>Europe/Rome</code></td></tr>\n <tr><td><code>{{WORKSPACE_DIR}}</code></td><td>Absolute path to the agent workspace directory</td></tr>\n <tr><td><code>{{WORKSPACE_FILES}}</code></td><td>All workspace .md files inlined as <code>## FileName.md</code> sections</td></tr>\n </tbody>\n </table>\n\n <h4 style="margin:18px 0 8px;font-size:14px">File Includes</h4>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:10px">Workspace files can include other <code>.md</code> files from the data directory using inline placeholders. Includes are resolved once (no recursion).</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:40%">Syntax</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><code>{{FILE:name.md}}</code></td><td>Replaced with the full contents of <code>name.md</code> from the data directory. If the file is not found, a comment <code>&lt;!-- FILE:name.md not found --&gt;</code> is inserted instead. Only <code>[A-Za-z0-9_-]+.md</code> filenames are matched.</td></tr>\n </tbody>\n </table>\n <p style="font-size:12px;color:var(--text-muted);margin-top:6px">Example: place <code>{{FILE:BEHAVIOUR.md}}</code> inside <code>AGENTS.md</code> to inline BEHAVIOUR.md at that position.</p>\n\n <h4 style="margin:18px 0 8px;font-size:14px">Memory Budget (Hot/Cold)</h4>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:10px">When <code>MEMORY.md</code> exceeds 8000 chars, only sections wrapped in hot markers are included in the prompt. Cold content is omitted but remains searchable via <code>memory_search</code>.</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:40%">Marker</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><code>&lt;!-- hot --&gt;</code></td><td>Start of a hot section (included in prompt)</td></tr>\n <tr><td><code>&lt;!-- /hot --&gt;</code></td><td>End of a hot section</td></tr>\n </tbody>\n </table>\n <p style="font-size:12px;color:var(--text-muted);margin-top:6px">If no hot markers are found, the entire file is loaded (backward compatible). Multiple hot sections are supported and concatenated.</p>\n </div>\n</div>\n<div class="modal-overlay" id="agentHelpModal">\n <div class="modal" style="max-width:680px;text-align:left;max-height:85vh;overflow-y:auto">\n <button class="close-btn" onclick="document.getElementById(\'agentHelpModal\').classList.remove(\'open\')">&times;</button>\n <h3 style="margin-bottom:14px">Agent Configuration Reference</h3>\n\n <h4 style="margin:16px 0 8px;font-size:14px;color:var(--accent)">Main</h4>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:30%">Field</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><strong>Default Model</strong></td><td>The model used for all conversations. Must be one of the models defined in the Models section.</td></tr>\n <tr><td><strong>Fallback Model</strong></td><td>If the default model fails (API error, overloaded, etc.), the agent automatically retries with this model. Leave empty to disable fallback.</td></tr>\n </tbody>\n </table>\n\n <h4 style="margin:16px 0 8px;font-size:14px;color:var(--accent)">Configuration</h4>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:30%">Field</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><strong>Max Turns</strong></td><td>Maximum number of agentic turns (tool use round-trips) per single invocation. Prevents runaway loops. A typical value is 5&ndash;15.</td></tr>\n <tr><td><strong>Permission Mode</strong></td><td>Controls how the SDK handles tool permissions.<br><code>default</code> &mdash; ask the user before running tools.<br><code>bypassPermissions</code> &mdash; run all allowed tools without asking (recommended for automated agents).<br><code>plan</code> &mdash; the agent proposes a plan and waits for approval before executing.</td></tr>\n <tr><td><strong>Session TTL</strong></td><td>Time in seconds before an idle session expires. When a session expires, the next message starts a new conversation (no history carried over). Default: 3600 (1 hour).</td></tr>\n <tr><td><strong>Setting Sources</strong></td><td>Which SDK settings files to load.<br><code>nothing</code> &mdash; ignore all settings files.<br><code>user</code> &mdash; load user-level settings (~/.claude).<br><code>project</code> &mdash; load project-level settings from workspace.<br><code>both</code> &mdash; load both user and project settings.</td></tr>\n <tr><td><strong>Coder Skill</strong></td><td>When enabled, the builtin coding prompt is always prepended to the system prompt, adding coding-oriented instructions. When disabled, the system prompt is built entirely from your templates (SYSTEM_PROMPT.md).</td></tr>\n <tr><td><strong>Allowed Tools</strong></td><td>Which SDK tools the agent can use. Unchecked tools are not available to the agent. Common tools: <code>Read</code>, <code>Write</code>, <code>Edit</code> for file operations; <code>Bash</code> for shell commands; <code>Glob</code>/<code>Grep</code> for search; <code>WebSearch</code>/<code>WebFetch</code> for web access; <code>Task</code> for sub-agents; <code>Skill</code> for slash commands.</td></tr>\n <tr><td><strong>Auto Approve Tools</strong></td><td>Controls how tool permission requests from the SDK are handled.<br><strong>On (default)</strong> &mdash; all tool invocations are automatically approved. This prevents the SDK from blocking when <code>permissionMode</code> is set to <code>default</code>.<br><strong>Off</strong> &mdash; tool permission requests are forwarded to the user&rsquo;s channel as interactive messages with Approve/Deny buttons. The SDK waits until the user responds before proceeding.</td></tr>\n </tbody>\n </table>\n\n <h4 style="margin:16px 0 8px;font-size:14px;color:var(--accent)">Message Queue</h4>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:10px">Controls how incoming messages are handled while the agent is already processing a response.</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:30%">Field</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><strong>Queue Mode</strong></td><td>\n <code>queue</code> &mdash; Simple FIFO. Each message is processed one at a time in order. The user must wait for each response before the next message is handled.<br>\n <code>collect</code> &mdash; Messages sent while the agent is busy are buffered. After a debounce period, all buffered messages are merged into a single prompt and processed together.<br>\n <code>steer</code> &mdash; A new message interrupts the current processing. The agent stops its current response and immediately starts handling the new message, combining context from both.\n </td></tr>\n <tr><td><strong>Debounce (ms)</strong></td><td>Only applies in <code>collect</code> mode. After the last buffered message arrives, the system waits this many milliseconds before flushing the batch. This allows grouping rapid-fire messages into a single prompt. Set to 0 for immediate flush.</td></tr>\n <tr><td><strong>Queue Cap</strong></td><td>Maximum number of messages that can accumulate in the buffer. When this limit is reached, the Drop Policy kicks in. Set to 0 for unlimited.</td></tr>\n <tr><td><strong>Drop Policy</strong></td><td>What happens when Queue Cap is exceeded:<br>\n <code>new</code> &mdash; The incoming message is rejected; the user receives an error asking to wait.<br>\n <code>old</code> &mdash; The oldest buffered message is silently discarded to make room.<br>\n <code>summarize</code> &mdash; The oldest message is discarded but a truncated preview (first 140 chars) is preserved. When the batch is flushed, these previews are prepended so the agent knows messages were dropped and can see a summary of their content.\n </td></tr>\n <tr><td><strong>Inflight Typing</strong></td><td>When enabled, the typing indicator stays active as long as at least one message is being processed. Without this, a fast command (e.g. <code>/status</code>) finishing while the agent is still working would clear the typing indicator prematurely.</td></tr>\n </tbody>\n </table>\n </div>\n</div>\n<div class="modal-overlay" id="memViewModal">\n <div class="modal sim-modal">\n <button class="close-btn" onclick="closeMemViewModal()">&times;</button>\n <h3 id="memViewTitle">Memory Log</h3>\n <div id="memEditorWrap" class="monaco-wrap readonly" style="height:450px"></div>\n <div class="sim-info">\n <span id="memViewInfo"></span>\n <button class="btn btn-ghost btn-sm" onclick="copyMemView()">Copy</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="simModal">\n <div class="modal sim-modal">\n <button class="close-btn" onclick="closeSimModal()">&times;</button>\n <h3>Simulate Building</h3>\n <div class="sim-tabs">\n <button class="sim-tab active" onclick="switchSimTab(\'main\',this)">Main Agent</button>\n <button class="sim-tab" onclick="switchSimTab(\'subagent\',this)">Subagent</button>\n <button class="sim-tab" onclick="switchSimTab(\'buildinfo\',this)">Build Info</button>\n </div>\n <div id="simEditorWrap" class="monaco-wrap readonly" style="height:450px"></div>\n <div id="simBuildInfo" style="display:none;height:450px;overflow-y:auto;padding:16px;font-size:13px;line-height:1.6"></div>\n <div class="sim-info">\n <span id="simCharCount"></span>\n <button class="btn btn-ghost btn-sm" onclick="copySimPrompt()">Copy</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="memDisableModal">\n <div class="modal">\n <button class="close-btn" onclick="closeMemDisableModal(false)">&times;</button>\n <h3>Disable Memories</h3>\n <p>Disabling memories means the agent will no longer keep track of past conversations. Conversation logs will not be saved and the agent will have no continuity between sessions.</p>\n <p style="font-size:13px;color:var(--text-muted)">Existing memory files will not be deleted.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn btn-danger" onclick="closeMemDisableModal(true)">Disable</button>\n <button class="btn-ghost" onclick="closeMemDisableModal(false)">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="skillDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeSkillDeleteModal()">&times;</button>\n <h3>Delete Skill</h3>\n <p>Are you sure you want to delete <strong id="skillDeleteName"></strong>? This cannot be undone.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteSkill()">Delete</button>\n <button class="btn-ghost" onclick="closeSkillDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="commandDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeCommandDeleteModal()">&times;</button>\n <h3>Delete Command</h3>\n <p>Are you sure you want to delete <strong id="commandDeleteName"></strong>? This cannot be undone.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteCommand()">Delete</button>\n <button class="btn-ghost" onclick="closeCommandDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="pluginDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closePluginDeleteModal()">&times;</button>\n <h3>Delete Plugin</h3>\n <p>Are you sure you want to delete <strong id="pluginDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeletePlugin()">Delete</button>\n <button class="btn-ghost" onclick="closePluginDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="pluginUploadedModal">\n <div class="modal">\n <button class="close-btn" onclick="closePluginUploadedModal()">&times;</button>\n <h3>Plugin Added</h3>\n <p><strong id="pluginUploadedName"></strong> has been uploaded and saved to the configuration.</p>\n <p style="font-size:13px;color:var(--text-muted)">The plugin will appear as <em>invalid</em> until the server is restarted. Restart the server from the Dashboard to activate it.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closePluginUploadedModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="skillEditModal">\n <div class="modal" style="max-width:800px;width:90vw;text-align:left">\n <button class="close-btn" onclick="closeSkillEditModal()">&times;</button>\n <h3 style="margin-bottom:4px">Edit Skill</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:12px"><code id="skillEditPath"></code></p>\n <div id="skillEditorWrap" class="monaco-wrap" style="height:400px"></div>\n <div style="display:flex;gap:8px;justify-content:flex-end;margin-top:14px">\n <button class="btn-ghost" onclick="closeSkillEditModal()">Close</button>\n <button class="btn" onclick="saveSkillEdit()">Save</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="commandEditModal">\n <div class="modal" style="max-width:800px;width:90vw;text-align:left">\n <button class="close-btn" onclick="closeCommandEditModal()">&times;</button>\n <h3 style="margin-bottom:4px">Edit Command</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:12px"><code id="commandEditPath"></code></p>\n <div id="commandEditorWrap" class="monaco-wrap" style="height:400px"></div>\n <div style="display:flex;gap:8px;justify-content:flex-end;margin-top:14px">\n <button class="btn-ghost" onclick="closeCommandEditModal()">Close</button>\n <button class="btn" onclick="saveCommandEdit()">Save</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="commandUploadedModal">\n <div class="modal">\n <button class="close-btn" onclick="closeCommandUploadedModal()">&times;</button>\n <h3>Command Added</h3>\n <p><strong id="commandUploadedName"></strong> has been uploaded.</p>\n <p style="font-size:13px;color:var(--text-muted)">The command is ready to use immediately.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closeCommandUploadedModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="skillUploadedModal">\n <div class="modal">\n <button class="close-btn" onclick="closeSkillUploadedModal()">&times;</button>\n <h3>Skill Added</h3>\n <p><strong id="skillUploadedName"></strong> has been uploaded.</p>\n <p style="font-size:13px;color:var(--text-muted)">The skill is ready to use immediately.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closeSkillUploadedModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="varDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeVarDeleteModal()">&times;</button>\n <h3>Delete Var</h3>\n <p>Are you sure you want to delete <strong id="varDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteVar()">Delete</button>\n <button class="btn-ghost" onclick="closeVarDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="modelDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeModelDeleteModal()">&times;</button>\n <h3>Delete Model</h3>\n <p>Are you sure you want to delete <strong id="modelDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteModel()">Delete</button>\n <button class="btn-ghost" onclick="closeModelDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="saDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeSaDeleteModal()">&times;</button>\n <h3>Delete Sub Agent</h3>\n <p>Are you sure you want to delete <strong id="saDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteSubAgent()">Delete</button>\n <button class="btn-ghost" onclick="closeSaDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="tokenDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeTokenDeleteModal()">&times;</button>\n <h3>Delete Token</h3>\n <p>Are you sure you want to delete token <strong id="tokenDeleteId"></strong>? This cannot be undone.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteToken()">Delete</button>\n <button class="btn-ghost" onclick="closeTokenDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="regenKeyModal">\n <div class="modal">\n <button class="close-btn" onclick="closeRegenKeyModal()">&times;</button>\n <h3>Regenerate Access Key</h3>\n <p>This will invalidate the current access key. Any saved links or bookmarks using the old key will stop working.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="closeRegenKeyModal();regenKey()">Regenerate</button>\n <button class="btn-ghost" onclick="closeRegenKeyModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="heartbeatSimModal">\n <div class="modal" style="max-width:600px;text-align:left">\n <button class="close-btn" onclick="closeHeartbeatSimModal()">&times;</button>\n <h3 id="heartbeatSimTitle">Heartbeat Simulation</h3>\n <p id="heartbeatSimResult" style="margin:12px 0"></p>\n <label style="font-size:13px;font-weight:600;display:block;margin-bottom:6px">HEARTBEAT.md</label>\n <textarea id="heartbeatSimContent" readonly style="width:100%;height:200px;font-family:var(--mono);font-size:13px;resize:vertical;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:10px;color:var(--text)"></textarea>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closeHeartbeatSimModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="qrModal">\n <div class="modal">\n <button class="close-btn" onclick="closeQrModal()">&times;</button>\n <h3>Connect WhatsApp</h3>\n <p id="qrMsg">Waiting for QR code...</p>\n <div id="qrSpinner"><span class="spinner"></span> Connecting...</div>\n <img id="qrImg" style="display:none" alt="WhatsApp QR Code">\n <div id="qrStatus"></div>\n <button class="btn btn-ghost" onclick="closeQrModal()" style="margin-top:8px">Close</button>\n </div>\n</div>\n<div class="modal-overlay" id="internalToolsModal">\n <div class="modal" style="max-width:780px;text-align:left;max-height:85vh;display:flex;flex-direction:column">\n <button class="close-btn" onclick="document.getElementById(\'internalToolsModal\').classList.remove(\'open\')">&times;</button>\n <h3 style="margin-bottom:6px">Internal MCP Tools</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:14px">Built-in MCP tool servers registered for the agent.</p>\n <div style="overflow-y:auto;flex:1;min-height:0">\n <div id="internalToolsBody"><span class="spinner"></span> Loading...</div>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="cronMsgModal">\n <div class="modal" style="max-width:680px;text-align:left;max-height:80vh;display:flex;flex-direction:column">\n <button class="close-btn" onclick="document.getElementById(\'cronMsgModal\').classList.remove(\'open\')">&times;</button>\n <h3 id="cronMsgTitle" style="margin-bottom:10px">Job Message</h3>\n <textarea id="cronMsgBody" readonly style="flex:1;min-height:200px;width:100%;resize:none;font-family:monospace;font-size:13px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:var(--radius);padding:12px"></textarea>\n </div>\n</div>\n\x3c!-- Session expired modal --\x3e\n<div class="modal-overlay" id="sessionExpiredModal">\n <div class="modal" style="text-align:center">\n <h3>Session Expired</h3>\n <p style="margin:16px 0">The server was restarted or your session is no longer valid. Please re-authenticate.</p>\n <button class="btn" onclick="location.reload()">OK</button>\n </div>\n</div>\n'}
1
+ export function renderModals(){return'\n\x3c!-- Restart confirmation modal --\x3e\n<div class="modal-overlay" id="restartModal">\n <div class="modal">\n <button class="close-btn" onclick="closeRestartModal()">&times;</button>\n <h3>Restart Server</h3>\n <p>This will restart all channels, agents, and services. Active conversations will be interrupted.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn" onclick="doRestart()">Restart</button>\n <button class="btn-ghost" onclick="closeRestartModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="placeholderRefModal">\n <div class="modal" style="max-width:620px;text-align:left;max-height:85vh;overflow-y:auto">\n <button class="close-btn" onclick="document.getElementById(\'placeholderRefModal\').classList.remove(\'open\')">&times;</button>\n <h3 style="margin-bottom:14px">Placeholder Reference</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:14px">These placeholders are resolved at runtime when building the system prompt from templates.</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:40%">Placeholder</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><code>{{ATTACHMENTS_DIR}}</code></td><td>Path to the session attachments folder, or <code>(memory disabled)</code></td></tr>\n <tr><td><code>{{AVAILABLE_TOOLS}}</code></td><td>Auto-discovered list of all registered MCP tools with name, description, and parameters</td></tr>\n <tr><td><code>{{CHANNEL}}</code></td><td>Channel name, e.g. <code>telegram</code>, <code>responses</code></td></tr>\n <tr><td><code>{{CHAT_ID}}</code></td><td>Chat / conversation ID within the channel</td></tr>\n <tr><td><code>{{DATA_DIR}}</code></td><td>Absolute path to the data directory (workspace files, templates)</td></tr>\n <tr><td><code>{{HEARTBEAT_INSTRUCTIONS}}</code></td><td>Heartbeat/cron behavioral instructions, or empty if cron is disabled</td></tr>\n <tr><td><code>{{HEARTBEAT_PROMPT}}</code></td><td>Raw heartbeat prompt message from config</td></tr>\n <tr><td><code>{{HOSTNAME}}</code></td><td>Server hostname</td></tr>\n <tr><td><code>{{MEMORY_FILE}}</code></td><td>Path to the current conversation memory file, or <code>(memory disabled)</code></td></tr>\n <tr><td><code>{{MESH_INFO}}</code></td><td>Inter-agent mesh communication info. When mesh channel is enabled: agent ID, list of peers, and usage instructions. Empty when mesh is disabled.</td></tr>\n <tr><td><code>{{MESSAGE_TOOLS_INSTRUCTIONS}}</code></td><td>Instructions for cross-channel messaging tools, or empty if not available</td></tr>\n <tr><td><code>{{MODEL}}</code></td><td>Active model ID, e.g. <code>claude-opus-4-6</code></td></tr>\n <tr><td><code>{{NODE_TOOLS_INSTRUCTIONS}}</code></td><td>Instructions for node remote-execution tools, or empty if no nodes connected</td></tr>\n <tr><td><code>{{OS}}</code></td><td>Operating system info (type, release, arch)</td></tr>\n <tr><td><code>{{RUNTIME_LINE}}</code></td><td>Composed runtime info line (host, OS, model, channel, session)</td></tr>\n <tr><td><code>{{SEARCH_IN_MEMORIES}}</code></td><td>Memory search tools instructions (<code>memory_search</code>, <code>memory_get</code>). Populated when Recall Strategy is not <code>builtin-only</code>, empty otherwise.</td></tr>\n <tr><td><code>{{SESSION_ID}}</code></td><td>SDK session ID for resumption, or <code>(new session)</code></td></tr>\n <tr><td><code>{{SESSION_KEY}}</code></td><td>Current session identifier, e.g. <code>telegram:12345</code></td></tr>\n <tr><td><code>{{SUBAGENT_TASK}}</code></td><td>Task description for subagent mode (empty for main agent)</td></tr>\n <tr><td><code>{{TIMEZONE}}</code></td><td>Server timezone, e.g. <code>Europe/Rome</code></td></tr>\n <tr><td><code>{{WORKSPACE_DIR}}</code></td><td>Absolute path to the agent workspace directory</td></tr>\n <tr><td><code>{{WORKSPACE_FILES}}</code></td><td>All workspace .md files inlined as <code>## FileName.md</code> sections</td></tr>\n </tbody>\n </table>\n\n <h4 style="margin:18px 0 8px;font-size:14px">File Includes</h4>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:10px">Workspace files can include other <code>.md</code> files from the data directory using inline placeholders. Includes are resolved once (no recursion).</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:40%">Syntax</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><code>{{FILE:name.md}}</code></td><td>Replaced with the full contents of <code>name.md</code> from the data directory (the same folder where <code>AGENTS.md</code>, <code>SOUL.md</code>, <code>USER.md</code>, etc. live). If the file is not found, a comment <code>&lt;!-- FILE:name.md not found --&gt;</code> is inserted instead. Only <code>[A-Za-z0-9_-]+.md</code> filenames are matched.</td></tr>\n </tbody>\n </table>\n <p style="font-size:12px;color:var(--text-muted);margin-top:6px">Example: place <code>{{FILE:BEHAVIOUR.md}}</code> inside <code>AGENTS.md</code> to inline BEHAVIOUR.md at that position.</p>\n\n <h4 style="margin:18px 0 8px;font-size:14px">Memory Budget (Hot/Cold)</h4>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:10px">When <code>MEMORY.md</code> exceeds 8000 chars, only sections wrapped in hot markers are included in the prompt. Cold content is omitted but remains searchable via <code>memory_search</code>.</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:40%">Marker</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><code>&lt;!-- hot --&gt;</code></td><td>Start of a hot section (included in prompt)</td></tr>\n <tr><td><code>&lt;!-- /hot --&gt;</code></td><td>End of a hot section</td></tr>\n </tbody>\n </table>\n <p style="font-size:12px;color:var(--text-muted);margin-top:6px">If no hot markers are found, the entire file is loaded (backward compatible). Multiple hot sections are supported and concatenated.</p>\n </div>\n</div>\n<div class="modal-overlay" id="agentHelpModal">\n <div class="modal" style="max-width:680px;text-align:left;max-height:85vh;overflow-y:auto">\n <button class="close-btn" onclick="document.getElementById(\'agentHelpModal\').classList.remove(\'open\')">&times;</button>\n <h3 style="margin-bottom:14px">Agent Configuration Reference</h3>\n\n <h4 style="margin:16px 0 8px;font-size:14px;color:var(--accent)">Main</h4>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:30%">Field</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><strong>Default Model</strong></td><td>The model used for all conversations. Must be one of the models defined in the Models section.</td></tr>\n <tr><td><strong>Fallback Model</strong></td><td>If the default model fails (API error, overloaded, etc.), the agent automatically retries with this model. Leave empty to disable fallback.</td></tr>\n </tbody>\n </table>\n\n <h4 style="margin:16px 0 8px;font-size:14px;color:var(--accent)">Configuration</h4>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:30%">Field</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><strong>Max Turns</strong></td><td>Maximum number of agentic turns (tool use round-trips) per single invocation. Prevents runaway loops. A typical value is 5&ndash;15.</td></tr>\n <tr><td><strong>Permission Mode</strong></td><td>Controls how the SDK handles tool permissions.<br><code>default</code> &mdash; ask the user before running tools.<br><code>bypassPermissions</code> &mdash; run all allowed tools without asking (recommended for automated agents).<br><code>plan</code> &mdash; the agent proposes a plan and waits for approval before executing.</td></tr>\n <tr><td><strong>Session TTL</strong></td><td>Time in seconds before an idle session expires. When a session expires, the next message starts a new conversation (no history carried over). Default: 3600 (1 hour).</td></tr>\n <tr><td><strong>Setting Sources</strong></td><td>Which SDK settings files to load.<br><code>nothing</code> &mdash; ignore all settings files.<br><code>user</code> &mdash; load user-level settings (~/.claude).<br><code>project</code> &mdash; load project-level settings from workspace.<br><code>both</code> &mdash; load both user and project settings.</td></tr>\n <tr><td><strong>Coder Skill</strong></td><td>When enabled, the builtin coding prompt is always prepended to the system prompt, adding coding-oriented instructions. When disabled, the system prompt is built entirely from your templates (SYSTEM_PROMPT.md).</td></tr>\n <tr><td><strong>Allowed Tools</strong></td><td>Which SDK tools the agent can use. Unchecked tools are not available to the agent. Common tools: <code>Read</code>, <code>Write</code>, <code>Edit</code> for file operations; <code>Bash</code> for shell commands; <code>Glob</code>/<code>Grep</code> for search; <code>WebSearch</code>/<code>WebFetch</code> for web access; <code>Task</code> for sub-agents; <code>Skill</code> for slash commands.</td></tr>\n <tr><td><strong>Auto Approve Tools</strong></td><td>Controls how tool permission requests from the SDK are handled.<br><strong>On (default)</strong> &mdash; all tool invocations are automatically approved. This prevents the SDK from blocking when <code>permissionMode</code> is set to <code>default</code>.<br><strong>Off</strong> &mdash; tool permission requests are forwarded to the user&rsquo;s channel as interactive messages with Approve/Deny buttons. The SDK waits until the user responds before proceeding.</td></tr>\n </tbody>\n </table>\n\n <h4 style="margin:16px 0 8px;font-size:14px;color:var(--accent)">Message Queue</h4>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:10px">Controls how incoming messages are handled while the agent is already processing a response.</p>\n <table class="tbl" style="font-size:13px">\n <thead><tr><th style="width:30%">Field</th><th>Description</th></tr></thead>\n <tbody>\n <tr><td><strong>Queue Mode</strong></td><td>\n <code>queue</code> &mdash; Simple FIFO. Each message is processed one at a time in order. The user must wait for each response before the next message is handled.<br>\n <code>collect</code> &mdash; Messages sent while the agent is busy are buffered. After a debounce period, all buffered messages are merged into a single prompt and processed together.<br>\n <code>steer</code> &mdash; A new message interrupts the current processing. The agent stops its current response and immediately starts handling the new message, combining context from both.\n </td></tr>\n <tr><td><strong>Debounce (ms)</strong></td><td>Only applies in <code>collect</code> mode. After the last buffered message arrives, the system waits this many milliseconds before flushing the batch. This allows grouping rapid-fire messages into a single prompt. Set to 0 for immediate flush.</td></tr>\n <tr><td><strong>Queue Cap</strong></td><td>Maximum number of messages that can accumulate in the buffer. When this limit is reached, the Drop Policy kicks in. Set to 0 for unlimited.</td></tr>\n <tr><td><strong>Drop Policy</strong></td><td>What happens when Queue Cap is exceeded:<br>\n <code>new</code> &mdash; The incoming message is rejected; the user receives an error asking to wait.<br>\n <code>old</code> &mdash; The oldest buffered message is silently discarded to make room.<br>\n <code>summarize</code> &mdash; The oldest message is discarded but a truncated preview (first 140 chars) is preserved. When the batch is flushed, these previews are prepended so the agent knows messages were dropped and can see a summary of their content.\n </td></tr>\n <tr><td><strong>Inflight Typing</strong></td><td>When enabled, the typing indicator stays active as long as at least one message is being processed. Without this, a fast command (e.g. <code>/status</code>) finishing while the agent is still working would clear the typing indicator prematurely.</td></tr>\n </tbody>\n </table>\n </div>\n</div>\n<div class="modal-overlay" id="memViewModal">\n <div class="modal sim-modal">\n <button class="close-btn" onclick="closeMemViewModal()">&times;</button>\n <h3 id="memViewTitle">Memory Log</h3>\n <div id="memEditorWrap" class="monaco-wrap readonly" style="height:450px"></div>\n <div class="sim-info">\n <span id="memViewInfo"></span>\n <button class="btn btn-ghost btn-sm" onclick="copyMemView()">Copy</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="simModal">\n <div class="modal sim-modal">\n <button class="close-btn" onclick="closeSimModal()">&times;</button>\n <h3>Simulate Building</h3>\n <div class="sim-tabs">\n <button class="sim-tab active" onclick="switchSimTab(\'main\',this)">Main Agent</button>\n <button class="sim-tab" onclick="switchSimTab(\'subagent\',this)">Subagent</button>\n <button class="sim-tab" onclick="switchSimTab(\'buildinfo\',this)">Build Info</button>\n </div>\n <div id="simEditorWrap" class="monaco-wrap readonly" style="height:450px"></div>\n <div id="simBuildInfo" style="display:none;height:450px;overflow-y:auto;padding:16px;font-size:13px;line-height:1.6"></div>\n <div class="sim-info">\n <span id="simCharCount"></span>\n <button class="btn btn-ghost btn-sm" onclick="copySimPrompt()">Copy</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="memDisableModal">\n <div class="modal">\n <button class="close-btn" onclick="closeMemDisableModal(false)">&times;</button>\n <h3>Disable Memories</h3>\n <p>Disabling memories means the agent will no longer keep track of past conversations. Conversation logs will not be saved and the agent will have no continuity between sessions.</p>\n <p style="font-size:13px;color:var(--text-muted)">Existing memory files will not be deleted.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn btn-danger" onclick="closeMemDisableModal(true)">Disable</button>\n <button class="btn-ghost" onclick="closeMemDisableModal(false)">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="skillDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeSkillDeleteModal()">&times;</button>\n <h3>Delete Skill</h3>\n <p>Are you sure you want to delete <strong id="skillDeleteName"></strong>? This cannot be undone.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteSkill()">Delete</button>\n <button class="btn-ghost" onclick="closeSkillDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="commandDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeCommandDeleteModal()">&times;</button>\n <h3>Delete Command</h3>\n <p>Are you sure you want to delete <strong id="commandDeleteName"></strong>? This cannot be undone.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteCommand()">Delete</button>\n <button class="btn-ghost" onclick="closeCommandDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="pluginDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closePluginDeleteModal()">&times;</button>\n <h3>Delete Plugin</h3>\n <p>Are you sure you want to delete <strong id="pluginDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeletePlugin()">Delete</button>\n <button class="btn-ghost" onclick="closePluginDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="pluginUploadedModal">\n <div class="modal">\n <button class="close-btn" onclick="closePluginUploadedModal()">&times;</button>\n <h3>Plugin Added</h3>\n <p><strong id="pluginUploadedName"></strong> has been uploaded and saved to the configuration.</p>\n <p style="font-size:13px;color:var(--text-muted)">The plugin will appear as <em>invalid</em> until the server is restarted. Restart the server from the Dashboard to activate it.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closePluginUploadedModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="skillEditModal">\n <div class="modal" style="max-width:800px;width:90vw;text-align:left">\n <button class="close-btn" onclick="closeSkillEditModal()">&times;</button>\n <h3 style="margin-bottom:4px">Edit Skill</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:12px"><code id="skillEditPath"></code></p>\n <div id="skillEditorWrap" class="monaco-wrap" style="height:400px"></div>\n <div style="display:flex;gap:8px;justify-content:flex-end;margin-top:14px">\n <button class="btn-ghost" onclick="closeSkillEditModal()">Close</button>\n <button class="btn" onclick="saveSkillEdit()">Save</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="commandEditModal">\n <div class="modal" style="max-width:800px;width:90vw;text-align:left">\n <button class="close-btn" onclick="closeCommandEditModal()">&times;</button>\n <h3 style="margin-bottom:4px">Edit Command</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:12px"><code id="commandEditPath"></code></p>\n <div id="commandEditorWrap" class="monaco-wrap" style="height:400px"></div>\n <div style="display:flex;gap:8px;justify-content:flex-end;margin-top:14px">\n <button class="btn-ghost" onclick="closeCommandEditModal()">Close</button>\n <button class="btn" onclick="saveCommandEdit()">Save</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="commandUploadedModal">\n <div class="modal">\n <button class="close-btn" onclick="closeCommandUploadedModal()">&times;</button>\n <h3>Command Added</h3>\n <p><strong id="commandUploadedName"></strong> has been uploaded.</p>\n <p style="font-size:13px;color:var(--text-muted)">The command is ready to use immediately.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closeCommandUploadedModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="skillUploadedModal">\n <div class="modal">\n <button class="close-btn" onclick="closeSkillUploadedModal()">&times;</button>\n <h3>Skill Added</h3>\n <p><strong id="skillUploadedName"></strong> has been uploaded.</p>\n <p style="font-size:13px;color:var(--text-muted)">The skill is ready to use immediately.</p>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closeSkillUploadedModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="varDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeVarDeleteModal()">&times;</button>\n <h3>Delete Var</h3>\n <p>Are you sure you want to delete <strong id="varDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteVar()">Delete</button>\n <button class="btn-ghost" onclick="closeVarDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="modelDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeModelDeleteModal()">&times;</button>\n <h3>Delete Model</h3>\n <p>Are you sure you want to delete <strong id="modelDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteModel()">Delete</button>\n <button class="btn-ghost" onclick="closeModelDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="saDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeSaDeleteModal()">&times;</button>\n <h3>Delete Sub Agent</h3>\n <p>Are you sure you want to delete <strong id="saDeleteName"></strong>?</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteSubAgent()">Delete</button>\n <button class="btn-ghost" onclick="closeSaDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="tokenDeleteModal">\n <div class="modal">\n <button class="close-btn" onclick="closeTokenDeleteModal()">&times;</button>\n <h3>Delete Token</h3>\n <p>Are you sure you want to delete token <strong id="tokenDeleteId"></strong>? This cannot be undone.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="doDeleteToken()">Delete</button>\n <button class="btn-ghost" onclick="closeTokenDeleteModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="regenKeyModal">\n <div class="modal">\n <button class="close-btn" onclick="closeRegenKeyModal()">&times;</button>\n <h3>Regenerate Access Key</h3>\n <p>This will invalidate the current access key. Any saved links or bookmarks using the old key will stop working.</p>\n <div style="display:flex;gap:8px;justify-content:center">\n <button class="btn btn-danger" onclick="closeRegenKeyModal();regenKey()">Regenerate</button>\n <button class="btn-ghost" onclick="closeRegenKeyModal()">Cancel</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="heartbeatSimModal">\n <div class="modal" style="max-width:600px;text-align:left">\n <button class="close-btn" onclick="closeHeartbeatSimModal()">&times;</button>\n <h3 id="heartbeatSimTitle">Heartbeat Simulation</h3>\n <p id="heartbeatSimResult" style="margin:12px 0"></p>\n <label style="font-size:13px;font-weight:600;display:block;margin-bottom:6px">HEARTBEAT.md</label>\n <textarea id="heartbeatSimContent" readonly style="width:100%;height:200px;font-family:var(--mono);font-size:13px;resize:vertical;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:10px;color:var(--text)"></textarea>\n <div style="display:flex;gap:8px;justify-content:center;margin-top:16px">\n <button class="btn" onclick="closeHeartbeatSimModal()">OK</button>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="qrModal">\n <div class="modal">\n <button class="close-btn" onclick="closeQrModal()">&times;</button>\n <h3>Connect WhatsApp</h3>\n <p id="qrMsg">Waiting for QR code...</p>\n <div id="qrSpinner"><span class="spinner"></span> Connecting...</div>\n <img id="qrImg" style="display:none" alt="WhatsApp QR Code">\n <div id="qrStatus"></div>\n <button class="btn btn-ghost" onclick="closeQrModal()" style="margin-top:8px">Close</button>\n </div>\n</div>\n<div class="modal-overlay" id="internalToolsModal">\n <div class="modal" style="max-width:780px;text-align:left;max-height:85vh;display:flex;flex-direction:column">\n <button class="close-btn" onclick="document.getElementById(\'internalToolsModal\').classList.remove(\'open\')">&times;</button>\n <h3 style="margin-bottom:6px">Internal MCP Tools</h3>\n <p style="font-size:13px;color:var(--text-muted);margin-bottom:14px">Built-in MCP tool servers registered for the agent.</p>\n <div style="overflow-y:auto;flex:1;min-height:0">\n <div id="internalToolsBody"><span class="spinner"></span> Loading...</div>\n </div>\n </div>\n</div>\n<div class="modal-overlay" id="cronMsgModal">\n <div class="modal" style="max-width:680px;text-align:left;max-height:80vh;display:flex;flex-direction:column">\n <button class="close-btn" onclick="document.getElementById(\'cronMsgModal\').classList.remove(\'open\')">&times;</button>\n <h3 id="cronMsgTitle" style="margin-bottom:10px">Job Message</h3>\n <textarea id="cronMsgBody" readonly style="flex:1;min-height:200px;width:100%;resize:none;font-family:monospace;font-size:13px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:var(--radius);padding:12px"></textarea>\n </div>\n</div>\n\x3c!-- Session expired modal --\x3e\n<div class="modal-overlay" id="sessionExpiredModal">\n <div class="modal" style="text-align:center">\n <h3>Session Expired</h3>\n <p style="margin:16px 0">The server was restarted or your session is no longer valid. Please re-authenticate.</p>\n <button class="btn" onclick="location.reload()">OK</button>\n </div>\n</div>\n'}
@@ -50,6 +50,8 @@ If SOUL.md is present, embody its persona and tone.
50
50
 
51
51
  {{WORKSPACE_FILES}}
52
52
 
53
+ {{MESH_INFO}}
54
+
53
55
  # Runtime
54
56
 
55
57
  {{RUNTIME_LINE}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hera-al/server",
3
- "version": "1.6.37",
3
+ "version": "1.6.40",
4
4
  "private": false,
5
5
  "description": "Hera Artificial Life — Multi-channel AI agent gateway with autonomous capabilities",
6
6
  "license": "MIT",