@markus-global/cli 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/start.js +9 -0
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +949 -351
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/paths.js.map +1 -1
- package/dist/web-ui/assets/index-K1kqQIR7.js +351 -0
- package/dist/web-ui/assets/index-Q4_kHftV.css +1 -0
- package/dist/web-ui/index.html +2 -2
- package/package.json +1 -1
- package/templates/skills/agent-building/SKILL.md +12 -4
- package/templates/skills/agent-building/skill.json +6 -0
- package/templates/skills/chrome-devtools/skill.json +6 -0
- package/templates/skills/markitdown/skill.json +6 -0
- package/templates/skills/markus-admin-cli/skill.json +6 -0
- package/templates/skills/markus-agent-cli/skill.json +7 -0
- package/templates/skills/markus-cli/skill.json +6 -0
- package/templates/skills/markus-hub-connector/skill.json +6 -0
- package/templates/skills/markus-project-cli/skill.json +7 -0
- package/templates/skills/markus-skill-cli/skill.json +7 -0
- package/templates/skills/markus-team-cli/skill.json +7 -0
- package/templates/skills/self-evolution/skill.json +6 -0
- package/templates/skills/skill-building/skill.json +6 -0
- package/templates/skills/team-building/SKILL.md +14 -6
- package/templates/skills/team-building/skill.json +6 -0
- package/templates/teams/content-team/team.json +12 -0
- package/templates/teams/dev-squad/team.json +13 -0
- package/templates/teams/engineering-pod/team.json +13 -0
- package/templates/teams/research-lab/team.json +12 -0
- package/templates/teams/startup-team/team.json +11 -0
- package/dist/web-ui/assets/index-C6Wd5E5i.css +0 -1
- package/dist/web-ui/assets/index-CJje74ac.js +0 -342
package/dist/markus.mjs
CHANGED
|
@@ -3555,6 +3555,8 @@ function buildManifest(type, raw) {
|
|
|
3555
3555
|
category: raw.category ?? "general",
|
|
3556
3556
|
tags: toArr(raw.tags),
|
|
3557
3557
|
icon: raw.icon || void 0,
|
|
3558
|
+
thumbnail: raw.thumbnail || void 0,
|
|
3559
|
+
screenshots: Array.isArray(raw.screenshots) ? raw.screenshots : void 0,
|
|
3558
3560
|
source: raw.source,
|
|
3559
3561
|
dependencies: void 0
|
|
3560
3562
|
};
|
|
@@ -4610,6 +4612,8 @@ function resolveWebUiDir() {
|
|
|
4610
4612
|
if (existsSync5(devDir)) return devDir;
|
|
4611
4613
|
const pkgDir = resolve3(__dirname2, "web-ui");
|
|
4612
4614
|
if (existsSync5(pkgDir)) return pkgDir;
|
|
4615
|
+
const binDir = resolve3(__dirname2, "..", "web-ui");
|
|
4616
|
+
if (existsSync5(binDir)) return binDir;
|
|
4613
4617
|
return void 0;
|
|
4614
4618
|
}
|
|
4615
4619
|
var __filename, __dirname2;
|
|
@@ -6560,7 +6564,7 @@ var init_context_engine = __esm({
|
|
|
6560
6564
|
parts.push(this.buildMailboxSection(opts.mailboxContext));
|
|
6561
6565
|
}
|
|
6562
6566
|
const scenario = opts.scenario ?? "chat";
|
|
6563
|
-
parts.push(this.buildScenarioSection(scenario));
|
|
6567
|
+
parts.push(this.buildScenarioSection(scenario, { a2aWaitForReply: opts.a2aWaitForReply }));
|
|
6564
6568
|
const now2 = /* @__PURE__ */ new Date();
|
|
6565
6569
|
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
6566
6570
|
const offset = now2.getTimezoneOffset();
|
|
@@ -6604,7 +6608,7 @@ ${ctx.mergedContent.slice(0, SYSTEM_MAILBOX_MERGED_CHARS)}`);
|
|
|
6604
6608
|
}
|
|
6605
6609
|
return lines.join("\n");
|
|
6606
6610
|
}
|
|
6607
|
-
buildScenarioSection(scenario) {
|
|
6611
|
+
buildScenarioSection(scenario, extra) {
|
|
6608
6612
|
const lines = ["\n## Current Interaction Mode"];
|
|
6609
6613
|
switch (scenario) {
|
|
6610
6614
|
case "chat":
|
|
@@ -6654,10 +6658,19 @@ ${ctx.mergedContent.slice(0, SYSTEM_MAILBOX_MERGED_CHARS)}`);
|
|
|
6654
6658
|
lines.push("");
|
|
6655
6659
|
lines.push("If nothing needs attention, respond with exactly: HEARTBEAT_OK");
|
|
6656
6660
|
break;
|
|
6657
|
-
case "a2a":
|
|
6661
|
+
case "a2a": {
|
|
6662
|
+
const waitForReply = extra?.a2aWaitForReply;
|
|
6658
6663
|
lines.push("You are in an **agent-to-agent (A2A) conversation**. This context is for COORDINATION, not for executing work.");
|
|
6659
6664
|
lines.push("");
|
|
6660
|
-
|
|
6665
|
+
if (waitForReply) {
|
|
6666
|
+
lines.push("**Communication channel**: The peer agent is **waiting for your reply**. Your text output is sent **directly back** to the peer agent as the response. Humans do NOT see this conversation. To reach a human, use `notify_user`. To reach a different agent (not the one who messaged you), use `agent_send_message`.");
|
|
6667
|
+
} else {
|
|
6668
|
+
lines.push("**Communication channel**: The peer agent sent you a **one-way notification** and is **NOT waiting for a reply**. Your text output will NOT reach the sender. Humans do NOT see this conversation.");
|
|
6669
|
+
lines.push("- To **reply to the sender**, use `agent_send_message` with the sender's agent ID.");
|
|
6670
|
+
lines.push("- To reach a **human**, use `notify_user`.");
|
|
6671
|
+
lines.push("- To reach a **different agent**, use `agent_send_message`.");
|
|
6672
|
+
lines.push("- If no response is needed, just process the information silently (e.g., update your state, create tasks, take notes).");
|
|
6673
|
+
}
|
|
6661
6674
|
lines.push("");
|
|
6662
6675
|
lines.push("**Communication rules:**");
|
|
6663
6676
|
lines.push("- Be concise and structured \u2014 your colleague needs actionable information");
|
|
@@ -6672,6 +6685,7 @@ ${ctx.mergedContent.slice(0, SYSTEM_MAILBOX_MERGED_CHARS)}`);
|
|
|
6672
6685
|
lines.push("- For multi-agent work: decompose into a task DAG with `blocked_by` dependencies, assign each to the right agent");
|
|
6673
6686
|
lines.push("- If you cannot help, explain why and suggest who can");
|
|
6674
6687
|
break;
|
|
6688
|
+
}
|
|
6675
6689
|
case "comment_response":
|
|
6676
6690
|
lines.push("You are responding to a **comment on a task or requirement**. You MUST follow the context-first protocol below.");
|
|
6677
6691
|
lines.push("");
|
|
@@ -7576,6 +7590,251 @@ ${orgContext.customContext}`);
|
|
|
7576
7590
|
}
|
|
7577
7591
|
});
|
|
7578
7592
|
|
|
7593
|
+
// ../core/dist/cognitive.js
|
|
7594
|
+
function selectCognitiveDepth(scenario, agentState, stimulusLength) {
|
|
7595
|
+
const base = SCENARIO_DEPTH_MAP[scenario] ?? CognitiveDepth.D1_Reactive;
|
|
7596
|
+
if (base === CognitiveDepth.D0_Reflexive && agentState.hasFailedTasks) {
|
|
7597
|
+
return CognitiveDepth.D1_Reactive;
|
|
7598
|
+
}
|
|
7599
|
+
if (base === CognitiveDepth.D1_Reactive && stimulusLength > 500) {
|
|
7600
|
+
return CognitiveDepth.D2_Deliberative;
|
|
7601
|
+
}
|
|
7602
|
+
if (base === CognitiveDepth.D2_Deliberative && agentState.hasBlockers) {
|
|
7603
|
+
return CognitiveDepth.D3_MetaCognitive;
|
|
7604
|
+
}
|
|
7605
|
+
return base;
|
|
7606
|
+
}
|
|
7607
|
+
var log8, SCENARIO_DEPTH_MAP, CognitivePreparation;
|
|
7608
|
+
var init_cognitive2 = __esm({
|
|
7609
|
+
"../core/dist/cognitive.js"() {
|
|
7610
|
+
"use strict";
|
|
7611
|
+
init_dist();
|
|
7612
|
+
log8 = createLogger("cognitive");
|
|
7613
|
+
SCENARIO_DEPTH_MAP = {
|
|
7614
|
+
heartbeat: CognitiveDepth.D0_Reflexive,
|
|
7615
|
+
memory_consolidation: CognitiveDepth.D0_Reflexive,
|
|
7616
|
+
chat: CognitiveDepth.D1_Reactive,
|
|
7617
|
+
a2a: CognitiveDepth.D1_Reactive,
|
|
7618
|
+
comment_response: CognitiveDepth.D1_Reactive,
|
|
7619
|
+
review: CognitiveDepth.D1_Reactive,
|
|
7620
|
+
task_execution: CognitiveDepth.D2_Deliberative
|
|
7621
|
+
};
|
|
7622
|
+
CognitivePreparation = class {
|
|
7623
|
+
config;
|
|
7624
|
+
constructor(config) {
|
|
7625
|
+
this.config = config;
|
|
7626
|
+
}
|
|
7627
|
+
async prepare(stimulus, agent, depth, llm, retrieval) {
|
|
7628
|
+
const effectiveDepth = this.config.maxDepth !== void 0 ? Math.min(depth, this.config.maxDepth) : depth;
|
|
7629
|
+
if (!this.config.enabled || effectiveDepth === CognitiveDepth.D0_Reflexive) {
|
|
7630
|
+
return { depth: effectiveDepth, isEmpty: true };
|
|
7631
|
+
}
|
|
7632
|
+
log8.info("CPP starting", { depth: effectiveDepth, stimulus: stimulus.type, agent: agent.name });
|
|
7633
|
+
const appraisal = await this.appraise(stimulus, agent, llm);
|
|
7634
|
+
if (effectiveDepth === CognitiveDepth.D1_Reactive) {
|
|
7635
|
+
return {
|
|
7636
|
+
depth: effectiveDepth,
|
|
7637
|
+
cognitiveContext: appraisal.cognitiveContext,
|
|
7638
|
+
isEmpty: false
|
|
7639
|
+
};
|
|
7640
|
+
}
|
|
7641
|
+
if (!retrieval) {
|
|
7642
|
+
log8.warn("D2+ requested but no RetrievalBackend provided, returning appraisal only");
|
|
7643
|
+
return {
|
|
7644
|
+
depth: effectiveDepth,
|
|
7645
|
+
cognitiveContext: appraisal.cognitiveContext,
|
|
7646
|
+
isEmpty: false
|
|
7647
|
+
};
|
|
7648
|
+
}
|
|
7649
|
+
const retrieved = await this.retrieve(appraisal.retrievalPlan, retrieval, agent.id);
|
|
7650
|
+
let reflection;
|
|
7651
|
+
if (appraisal.reflectionNeeded && effectiveDepth >= CognitiveDepth.D2_Deliberative) {
|
|
7652
|
+
reflection = await this.reflect(stimulus, agent, retrieved, llm);
|
|
7653
|
+
}
|
|
7654
|
+
return this.assemble(effectiveDepth, appraisal, retrieved, reflection);
|
|
7655
|
+
}
|
|
7656
|
+
// ─── Phase 1: Appraisal ─────────────────────────────────────────────────────
|
|
7657
|
+
async appraise(stimulus, agent, llm) {
|
|
7658
|
+
const prompt = [
|
|
7659
|
+
`You are ${agent.name}, a ${agent.roleDescription}.`,
|
|
7660
|
+
`Current status: ${agent.status}`,
|
|
7661
|
+
agent.currentTask ? `Current task: ${agent.currentTask}` : "",
|
|
7662
|
+
agent.recentActivity.length > 0 ? `Recent activity:
|
|
7663
|
+
${agent.recentActivity.slice(-5).map((a) => `- ${a}`).join("\n")}` : "",
|
|
7664
|
+
"",
|
|
7665
|
+
"An incoming stimulus requires your attention:",
|
|
7666
|
+
`Type: ${stimulus.type}`,
|
|
7667
|
+
stimulus.sender ? `From: ${stimulus.sender}` : "",
|
|
7668
|
+
`Content: ${stimulus.content.slice(0, 800)}`,
|
|
7669
|
+
"",
|
|
7670
|
+
"Respond with a JSON object (no markdown fences):",
|
|
7671
|
+
"{",
|
|
7672
|
+
' "intent": "brief description of what this stimulus is asking/requiring",',
|
|
7673
|
+
' "relevance": "how this relates to your current work and role",',
|
|
7674
|
+
' "confidence": "high|medium|low \u2014 how confident you are in understanding this",',
|
|
7675
|
+
' "retrievalPlan": {',
|
|
7676
|
+
' "memoryQueries": ["keywords to search your memory for relevant knowledge"],',
|
|
7677
|
+
' "activityQueries": ["keywords to search your past activities"],',
|
|
7678
|
+
' "taskQueries": ["keywords to search task board"]',
|
|
7679
|
+
" },",
|
|
7680
|
+
' "reflectionNeeded": true/false,',
|
|
7681
|
+
' "cognitiveContext": "1-2 sentence summary of your assessment for the main reasoning call"',
|
|
7682
|
+
"}"
|
|
7683
|
+
].filter(Boolean).join("\n");
|
|
7684
|
+
try {
|
|
7685
|
+
const response = await llm.chat({
|
|
7686
|
+
messages: [{ role: "user", content: prompt }],
|
|
7687
|
+
maxTokens: 500,
|
|
7688
|
+
temperature: 0.3,
|
|
7689
|
+
metadata: { purpose: "cognitive_appraisal" }
|
|
7690
|
+
});
|
|
7691
|
+
const parsed = JSON.parse(response.content.trim());
|
|
7692
|
+
log8.debug("Appraisal completed", { intent: parsed.intent, confidence: parsed.confidence });
|
|
7693
|
+
return parsed;
|
|
7694
|
+
} catch (err) {
|
|
7695
|
+
log8.warn("Appraisal LLM call failed, using fallback", { error: String(err) });
|
|
7696
|
+
return {
|
|
7697
|
+
intent: stimulus.summary || stimulus.type,
|
|
7698
|
+
relevance: "unknown",
|
|
7699
|
+
confidence: "low",
|
|
7700
|
+
retrievalPlan: { memoryQueries: [], activityQueries: [], taskQueries: [] },
|
|
7701
|
+
reflectionNeeded: false,
|
|
7702
|
+
cognitiveContext: `Incoming ${stimulus.type}: ${stimulus.summary || stimulus.content.slice(0, 100)}`
|
|
7703
|
+
};
|
|
7704
|
+
}
|
|
7705
|
+
}
|
|
7706
|
+
// ─── Phase 2: Directed Retrieval ────────────────────────────────────────────
|
|
7707
|
+
async retrieve(plan, backend, agentId2) {
|
|
7708
|
+
const result = { memories: [], activities: [], tasks: [] };
|
|
7709
|
+
for (const q of plan.memoryQueries.slice(0, 3)) {
|
|
7710
|
+
try {
|
|
7711
|
+
const hits = backend.searchMemories(q, 5);
|
|
7712
|
+
result.memories.push(...hits);
|
|
7713
|
+
} catch (err) {
|
|
7714
|
+
log8.warn("Memory retrieval failed", { query: q, error: String(err) });
|
|
7715
|
+
}
|
|
7716
|
+
}
|
|
7717
|
+
for (const q of plan.activityQueries.slice(0, 3)) {
|
|
7718
|
+
try {
|
|
7719
|
+
const hits = backend.searchActivities(agentId2, q, 5);
|
|
7720
|
+
result.activities.push(...hits);
|
|
7721
|
+
} catch (err) {
|
|
7722
|
+
log8.warn("Activity retrieval failed", { query: q, error: String(err) });
|
|
7723
|
+
}
|
|
7724
|
+
}
|
|
7725
|
+
for (const q of plan.taskQueries.slice(0, 3)) {
|
|
7726
|
+
try {
|
|
7727
|
+
const hits = backend.searchTasks(q, 5);
|
|
7728
|
+
result.tasks.push(...hits);
|
|
7729
|
+
} catch (err) {
|
|
7730
|
+
log8.warn("Task retrieval failed", { query: q, error: String(err) });
|
|
7731
|
+
}
|
|
7732
|
+
}
|
|
7733
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7734
|
+
result.memories = result.memories.filter((m) => {
|
|
7735
|
+
const key2 = m.content.slice(0, 100);
|
|
7736
|
+
if (seen.has(key2))
|
|
7737
|
+
return false;
|
|
7738
|
+
seen.add(key2);
|
|
7739
|
+
return true;
|
|
7740
|
+
});
|
|
7741
|
+
log8.debug("Retrieval completed", {
|
|
7742
|
+
memories: result.memories.length,
|
|
7743
|
+
activities: result.activities.length,
|
|
7744
|
+
tasks: result.tasks.length
|
|
7745
|
+
});
|
|
7746
|
+
return result;
|
|
7747
|
+
}
|
|
7748
|
+
// ─── Phase 3: Reflection ────────────────────────────────────────────────────
|
|
7749
|
+
async reflect(stimulus, agent, retrieved, llm) {
|
|
7750
|
+
const contextSummary = [
|
|
7751
|
+
retrieved.memories.length > 0 ? `Relevant knowledge:
|
|
7752
|
+
${retrieved.memories.slice(0, 5).map((m) => `- ${m.content}`).join("\n")}` : "",
|
|
7753
|
+
retrieved.activities.length > 0 ? `Past activities:
|
|
7754
|
+
${retrieved.activities.slice(0, 5).map((a) => `- [${a.type}] ${a.summary}`).join("\n")}` : "",
|
|
7755
|
+
retrieved.tasks.length > 0 ? `Related tasks:
|
|
7756
|
+
${retrieved.tasks.slice(0, 5).map((t) => `- [${t.status}] ${t.title} (${t.id})`).join("\n")}` : ""
|
|
7757
|
+
].filter(Boolean).join("\n\n");
|
|
7758
|
+
const prompt = [
|
|
7759
|
+
`You are ${agent.name}, a ${agent.roleDescription}.`,
|
|
7760
|
+
`Current status: ${agent.status}`,
|
|
7761
|
+
"",
|
|
7762
|
+
`You are about to respond to: ${stimulus.summary || stimulus.content.slice(0, 200)}`,
|
|
7763
|
+
"",
|
|
7764
|
+
"Here is the context retrieved from your memory and experience:",
|
|
7765
|
+
contextSummary || "(No relevant context found)",
|
|
7766
|
+
"",
|
|
7767
|
+
"Reflect on this from your role's perspective. Respond with JSON (no markdown fences):",
|
|
7768
|
+
"{",
|
|
7769
|
+
' "interpretation": "What this context means for how you should approach the stimulus",',
|
|
7770
|
+
' "recommendations": ["specific action or consideration 1", "specific action 2"]',
|
|
7771
|
+
"}"
|
|
7772
|
+
].join("\n");
|
|
7773
|
+
try {
|
|
7774
|
+
const response = await llm.chat({
|
|
7775
|
+
messages: [{ role: "user", content: prompt }],
|
|
7776
|
+
maxTokens: 400,
|
|
7777
|
+
temperature: 0.3,
|
|
7778
|
+
metadata: { purpose: "cognitive_reflection" }
|
|
7779
|
+
});
|
|
7780
|
+
const parsed = JSON.parse(response.content.trim());
|
|
7781
|
+
log8.debug("Reflection completed", { recommendations: parsed.recommendations.length });
|
|
7782
|
+
return parsed;
|
|
7783
|
+
} catch (err) {
|
|
7784
|
+
log8.warn("Reflection LLM call failed", { error: String(err) });
|
|
7785
|
+
return {
|
|
7786
|
+
interpretation: "Unable to reflect \u2014 proceeding with available context.",
|
|
7787
|
+
recommendations: []
|
|
7788
|
+
};
|
|
7789
|
+
}
|
|
7790
|
+
}
|
|
7791
|
+
// ─── Phase 4: Assembly ──────────────────────────────────────────────────────
|
|
7792
|
+
assemble(depth, appraisal, retrieved, reflection) {
|
|
7793
|
+
const sections = [];
|
|
7794
|
+
const cognitiveContext = appraisal.cognitiveContext;
|
|
7795
|
+
const retrievedParts = [];
|
|
7796
|
+
if (retrieved.memories.length > 0) {
|
|
7797
|
+
retrievedParts.push("**From your knowledge:**");
|
|
7798
|
+
for (const m of retrieved.memories.slice(0, 5)) {
|
|
7799
|
+
retrievedParts.push(`- ${m.content}`);
|
|
7800
|
+
}
|
|
7801
|
+
}
|
|
7802
|
+
if (retrieved.activities.length > 0) {
|
|
7803
|
+
retrievedParts.push("**From past experience:**");
|
|
7804
|
+
for (const a of retrieved.activities.slice(0, 5)) {
|
|
7805
|
+
retrievedParts.push(`- [${a.type}] ${a.summary}`);
|
|
7806
|
+
}
|
|
7807
|
+
}
|
|
7808
|
+
if (retrieved.tasks.length > 0) {
|
|
7809
|
+
retrievedParts.push("**Related tasks:**");
|
|
7810
|
+
for (const t of retrieved.tasks.slice(0, 5)) {
|
|
7811
|
+
retrievedParts.push(`- [${t.status}] ${t.title} (${t.id})`);
|
|
7812
|
+
}
|
|
7813
|
+
}
|
|
7814
|
+
const retrievedContext = retrievedParts.length > 0 ? retrievedParts.join("\n") : void 0;
|
|
7815
|
+
let reflectionText;
|
|
7816
|
+
if (reflection) {
|
|
7817
|
+
sections.length = 0;
|
|
7818
|
+
sections.push(reflection.interpretation);
|
|
7819
|
+
if (reflection.recommendations.length > 0) {
|
|
7820
|
+
for (const r of reflection.recommendations) {
|
|
7821
|
+
sections.push(`- ${r}`);
|
|
7822
|
+
}
|
|
7823
|
+
}
|
|
7824
|
+
reflectionText = sections.join("\n");
|
|
7825
|
+
}
|
|
7826
|
+
return {
|
|
7827
|
+
depth,
|
|
7828
|
+
cognitiveContext,
|
|
7829
|
+
retrievedContext,
|
|
7830
|
+
reflection: reflectionText,
|
|
7831
|
+
isEmpty: false
|
|
7832
|
+
};
|
|
7833
|
+
}
|
|
7834
|
+
};
|
|
7835
|
+
}
|
|
7836
|
+
});
|
|
7837
|
+
|
|
7579
7838
|
// ../core/dist/environment-profile.js
|
|
7580
7839
|
import { execSync } from "node:child_process";
|
|
7581
7840
|
import { existsSync as existsSync9 } from "node:fs";
|
|
@@ -7704,7 +7963,7 @@ async function detectEnvironment(workdir) {
|
|
|
7704
7963
|
if (cachedProfile && Date.now() - new Date(cachedProfile.detectedAt).getTime() < 3e5) {
|
|
7705
7964
|
return cachedProfile;
|
|
7706
7965
|
}
|
|
7707
|
-
|
|
7966
|
+
log9.info("Detecting runtime environment...");
|
|
7708
7967
|
const start = Date.now();
|
|
7709
7968
|
const profile = {
|
|
7710
7969
|
os: { platform: platform(), arch: arch(), release: release() },
|
|
@@ -7724,7 +7983,7 @@ async function detectEnvironment(workdir) {
|
|
|
7724
7983
|
};
|
|
7725
7984
|
cachedProfile = profile;
|
|
7726
7985
|
const elapsed = Date.now() - start;
|
|
7727
|
-
|
|
7986
|
+
log9.info("Environment detection complete", {
|
|
7728
7987
|
os: `${profile.os.platform} ${profile.os.arch}`,
|
|
7729
7988
|
tools: profile.tools.length,
|
|
7730
7989
|
runtimes: profile.runtimes.length,
|
|
@@ -7733,23 +7992,23 @@ async function detectEnvironment(workdir) {
|
|
|
7733
7992
|
});
|
|
7734
7993
|
return profile;
|
|
7735
7994
|
}
|
|
7736
|
-
var
|
|
7995
|
+
var log9, cachedProfile;
|
|
7737
7996
|
var init_environment_profile = __esm({
|
|
7738
7997
|
"../core/dist/environment-profile.js"() {
|
|
7739
7998
|
"use strict";
|
|
7740
7999
|
init_dist();
|
|
7741
|
-
|
|
8000
|
+
log9 = createLogger("environment-profile");
|
|
7742
8001
|
cachedProfile = null;
|
|
7743
8002
|
}
|
|
7744
8003
|
});
|
|
7745
8004
|
|
|
7746
8005
|
// ../core/dist/tool-selector.js
|
|
7747
|
-
var
|
|
8006
|
+
var log10, TOOL_GROUPS, BASE_TOOL_NAMES, ToolSelector;
|
|
7748
8007
|
var init_tool_selector = __esm({
|
|
7749
8008
|
"../core/dist/tool-selector.js"() {
|
|
7750
8009
|
"use strict";
|
|
7751
8010
|
init_dist();
|
|
7752
|
-
|
|
8011
|
+
log10 = createLogger("tool-selector");
|
|
7753
8012
|
TOOL_GROUPS = [
|
|
7754
8013
|
{
|
|
7755
8014
|
name: "shell",
|
|
@@ -7987,7 +8246,7 @@ var init_tool_selector = __esm({
|
|
|
7987
8246
|
if (opts.allTools.has(name))
|
|
7988
8247
|
selected.add(name);
|
|
7989
8248
|
}
|
|
7990
|
-
|
|
8249
|
+
log10.debug("Tool group activated by keyword", { group: group.name });
|
|
7991
8250
|
}
|
|
7992
8251
|
}
|
|
7993
8252
|
if (opts.recentToolNames) {
|
|
@@ -8069,7 +8328,7 @@ var init_tool_selector = __esm({
|
|
|
8069
8328
|
required: ["operation"]
|
|
8070
8329
|
}
|
|
8071
8330
|
});
|
|
8072
|
-
|
|
8331
|
+
log10.debug("Tool selection complete", {
|
|
8073
8332
|
total: opts.allTools.size,
|
|
8074
8333
|
selected: result.length,
|
|
8075
8334
|
groups: this.groups.filter((g) => g.toolNames.some((n) => selected.has(n))).map((g) => g.name)
|
|
@@ -8146,12 +8405,12 @@ Inactive tools (${unloaded.length}):`);
|
|
|
8146
8405
|
});
|
|
8147
8406
|
|
|
8148
8407
|
// ../core/dist/security.js
|
|
8149
|
-
var
|
|
8408
|
+
var log11, DANGEROUS_PATTERNS, DEFAULT_PATH_DENY, SecurityGuard, defaultSecurityGuard;
|
|
8150
8409
|
var init_security = __esm({
|
|
8151
8410
|
"../core/dist/security.js"() {
|
|
8152
8411
|
"use strict";
|
|
8153
8412
|
init_dist();
|
|
8154
|
-
|
|
8413
|
+
log11 = createLogger("security");
|
|
8155
8414
|
DANGEROUS_PATTERNS = [
|
|
8156
8415
|
/\brm\s+(-[a-zA-Z]*f[a-zA-Z]*\s+|.*--no-preserve-root)/,
|
|
8157
8416
|
/\brm\s+-[a-zA-Z]*r[a-zA-Z]*\s+\//,
|
|
@@ -8182,7 +8441,7 @@ var init_security = __esm({
|
|
|
8182
8441
|
const denyPatterns = [...DANGEROUS_PATTERNS, ...this.policy.shellDenyPatterns ?? []];
|
|
8183
8442
|
for (const pattern of denyPatterns) {
|
|
8184
8443
|
if (pattern.test(command)) {
|
|
8185
|
-
|
|
8444
|
+
log11.warn("Shell command denied by security policy", { command: command.slice(0, 100), pattern: pattern.source });
|
|
8186
8445
|
return { allowed: false, reason: `Blocked by security policy: matches dangerous pattern` };
|
|
8187
8446
|
}
|
|
8188
8447
|
}
|
|
@@ -8219,7 +8478,7 @@ var init_security = __esm({
|
|
|
8219
8478
|
const denyPaths = [...DEFAULT_PATH_DENY, ...this.policy.pathDenylist ?? []];
|
|
8220
8479
|
for (const deny of denyPaths) {
|
|
8221
8480
|
if (path.includes(deny)) {
|
|
8222
|
-
|
|
8481
|
+
log11.warn("File path denied by security policy", { path });
|
|
8223
8482
|
return { allowed: false, reason: `Access to ${deny} is blocked` };
|
|
8224
8483
|
}
|
|
8225
8484
|
}
|
|
@@ -41978,7 +42237,7 @@ async function llmCallWithRetry(fn, label) {
|
|
|
41978
42237
|
throw err;
|
|
41979
42238
|
}
|
|
41980
42239
|
const delay = SUBAGENT_RETRY_BASE_MS * Math.pow(2, attempt);
|
|
41981
|
-
|
|
42240
|
+
log12.warn(`${label}: retryable error, attempt ${attempt + 1}/${SUBAGENT_MAX_LLM_RETRIES + 1}`, {
|
|
41982
42241
|
error: String(err).slice(0, SUBAGENT_ERROR_PREVIEW_CHARS),
|
|
41983
42242
|
delay
|
|
41984
42243
|
});
|
|
@@ -41996,10 +42255,10 @@ function persistSubagentLog(dataDir, subagentId, entries2) {
|
|
|
41996
42255
|
const filePath = join7(logsDir, `${subagentId}.jsonl`);
|
|
41997
42256
|
const content = entries2.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
41998
42257
|
writeFileSync7(filePath, content);
|
|
41999
|
-
|
|
42258
|
+
log12.debug("Subagent log persisted", { path: filePath, entries: entries2.length });
|
|
42000
42259
|
return filePath;
|
|
42001
42260
|
} catch (err) {
|
|
42002
|
-
|
|
42261
|
+
log12.warn("Failed to persist subagent log", { error: String(err) });
|
|
42003
42262
|
return void 0;
|
|
42004
42263
|
}
|
|
42005
42264
|
}
|
|
@@ -42025,7 +42284,7 @@ async function runSubagentLoop(ctx, task, opts) {
|
|
|
42025
42284
|
];
|
|
42026
42285
|
logEntries.push({ ts: (/* @__PURE__ */ new Date()).toISOString(), role: "system", content: systemContent });
|
|
42027
42286
|
logEntries.push({ ts: (/* @__PURE__ */ new Date()).toISOString(), role: "user", content: task });
|
|
42028
|
-
|
|
42287
|
+
log12.info("Subagent started", {
|
|
42029
42288
|
parentAgent: ctx.agentId,
|
|
42030
42289
|
subagentId,
|
|
42031
42290
|
taskLength: task.length,
|
|
@@ -42045,7 +42304,7 @@ async function runSubagentLoop(ctx, task, opts) {
|
|
|
42045
42304
|
let iterations = 0;
|
|
42046
42305
|
while (response.finishReason === "tool_use" && response.toolCalls?.length || response.finishReason === "max_tokens") {
|
|
42047
42306
|
if (++iterations > maxIter) {
|
|
42048
|
-
|
|
42307
|
+
log12.warn("Subagent hit max iterations", { parentAgent: ctx.agentId, subagentId, iterations });
|
|
42049
42308
|
onProgress?.({ type: "error", content: `Subagent hit max iterations (${maxIter})` });
|
|
42050
42309
|
break;
|
|
42051
42310
|
}
|
|
@@ -42138,7 +42397,7 @@ async function runSubagentLoop(ctx, task, opts) {
|
|
|
42138
42397
|
if (ctx.dataDir) {
|
|
42139
42398
|
logPath = persistSubagentLog(ctx.dataDir, subagentId, logEntries);
|
|
42140
42399
|
}
|
|
42141
|
-
|
|
42400
|
+
log12.info("Subagent completed", {
|
|
42142
42401
|
parentAgent: ctx.agentId,
|
|
42143
42402
|
subagentId,
|
|
42144
42403
|
iterations,
|
|
@@ -42193,7 +42452,7 @@ function createSubagentTool(ctx) {
|
|
|
42193
42452
|
});
|
|
42194
42453
|
return JSON.stringify({ status: "completed", result });
|
|
42195
42454
|
} catch (err) {
|
|
42196
|
-
|
|
42455
|
+
log12.error("Subagent execution failed", { error: String(err) });
|
|
42197
42456
|
return JSON.stringify({ status: "error", error: `Subagent failed: ${String(err)}` });
|
|
42198
42457
|
}
|
|
42199
42458
|
}
|
|
@@ -42253,7 +42512,7 @@ function createParallelSubagentTool(ctx) {
|
|
|
42253
42512
|
});
|
|
42254
42513
|
}
|
|
42255
42514
|
const sharedSystemPrompt = args["system_prompt"];
|
|
42256
|
-
|
|
42515
|
+
log12.info("Spawning parallel subagents", {
|
|
42257
42516
|
parentAgent: ctx.agentId,
|
|
42258
42517
|
count: tasks.length,
|
|
42259
42518
|
taskIds: tasks.map((t) => t.id)
|
|
@@ -42287,7 +42546,7 @@ function createParallelSubagentTool(ctx) {
|
|
|
42287
42546
|
const completed = output.filter((o) => o.status === "completed").length;
|
|
42288
42547
|
const failed = output.filter((o) => o.status === "error").length;
|
|
42289
42548
|
const durationMs = Date.now() - startTime;
|
|
42290
|
-
|
|
42549
|
+
log12.info("Parallel subagents finished", {
|
|
42291
42550
|
parentAgent: ctx.agentId,
|
|
42292
42551
|
completed,
|
|
42293
42552
|
failed,
|
|
@@ -42307,12 +42566,12 @@ function createParallelSubagentTool(ctx) {
|
|
|
42307
42566
|
}
|
|
42308
42567
|
};
|
|
42309
42568
|
}
|
|
42310
|
-
var
|
|
42569
|
+
var log12, DEFAULT_MAX_SUBAGENT_ITERATIONS, BLOCKED_TOOLS, RETRYABLE_STATUS_CODES;
|
|
42311
42570
|
var init_subagent = __esm({
|
|
42312
42571
|
"../core/dist/tools/subagent.js"() {
|
|
42313
42572
|
"use strict";
|
|
42314
42573
|
init_dist();
|
|
42315
|
-
|
|
42574
|
+
log12 = createLogger("subagent");
|
|
42316
42575
|
DEFAULT_MAX_SUBAGENT_ITERATIONS = Infinity;
|
|
42317
42576
|
BLOCKED_TOOLS = /* @__PURE__ */ new Set([
|
|
42318
42577
|
"spawn_subagent",
|
|
@@ -42326,12 +42585,12 @@ var init_subagent = __esm({
|
|
|
42326
42585
|
});
|
|
42327
42586
|
|
|
42328
42587
|
// ../core/dist/mailbox.js
|
|
42329
|
-
var
|
|
42588
|
+
var log13, MailboxCancelledError, DEFAULT_PRIORITY, AgentMailbox;
|
|
42330
42589
|
var init_mailbox2 = __esm({
|
|
42331
42590
|
"../core/dist/mailbox.js"() {
|
|
42332
42591
|
"use strict";
|
|
42333
42592
|
init_dist();
|
|
42334
|
-
|
|
42593
|
+
log13 = createLogger("mailbox");
|
|
42335
42594
|
MailboxCancelledError = class extends Error {
|
|
42336
42595
|
constructor() {
|
|
42337
42596
|
super("Mailbox wait cancelled");
|
|
@@ -42379,7 +42638,7 @@ var init_mailbox2 = __esm({
|
|
|
42379
42638
|
}
|
|
42380
42639
|
const merged = this.deduplicateQueue();
|
|
42381
42640
|
if (restored > 0 || expired > 0 || merged > 0) {
|
|
42382
|
-
|
|
42641
|
+
log13.info("Mailbox recovery from DB", {
|
|
42383
42642
|
agentId: this.agentId,
|
|
42384
42643
|
restored,
|
|
42385
42644
|
expired,
|
|
@@ -42477,7 +42736,7 @@ ${item.payload.content}`;
|
|
|
42477
42736
|
return item.payload.requirementId;
|
|
42478
42737
|
}, "requirement");
|
|
42479
42738
|
if (removed > 0) {
|
|
42480
|
-
|
|
42739
|
+
log13.info("Pre-triage consolidation", { agentId: this.agentId, merged: removed });
|
|
42481
42740
|
}
|
|
42482
42741
|
return removed;
|
|
42483
42742
|
}
|
|
@@ -42554,7 +42813,7 @@ ${typeLabel}${item.payload.content}`;
|
|
|
42554
42813
|
};
|
|
42555
42814
|
this.insertSorted(item);
|
|
42556
42815
|
this.persistence?.save(item);
|
|
42557
|
-
|
|
42816
|
+
log13.debug("Mailbox enqueue", {
|
|
42558
42817
|
agentId: this.agentId,
|
|
42559
42818
|
itemId: item.id,
|
|
42560
42819
|
type: sourceType,
|
|
@@ -42718,7 +42977,7 @@ ${typeLabel}${item.payload.content}`;
|
|
|
42718
42977
|
item.completedAt = void 0;
|
|
42719
42978
|
this.insertSorted(item);
|
|
42720
42979
|
this.persistence?.updateStatus(item.id, "queued", { retryCount: item.retryCount });
|
|
42721
|
-
|
|
42980
|
+
log13.info("Mailbox item requeued for retry", {
|
|
42722
42981
|
agentId: this.agentId,
|
|
42723
42982
|
itemId: item.id,
|
|
42724
42983
|
type: item.sourceType,
|
|
@@ -42781,7 +43040,7 @@ ${typeLabel}${item.payload.content}`;
|
|
|
42781
43040
|
}
|
|
42782
43041
|
}
|
|
42783
43042
|
if (resurfaced > 0) {
|
|
42784
|
-
|
|
43043
|
+
log13.info("Resurfaced deferred items", { agentId: this.agentId, count: resurfaced });
|
|
42785
43044
|
}
|
|
42786
43045
|
return resurfaced;
|
|
42787
43046
|
}
|
|
@@ -42814,7 +43073,7 @@ ${typeLabel}${item.payload.content}`;
|
|
|
42814
43073
|
this.persistence?.updateStatus(item.id, "dropped");
|
|
42815
43074
|
}
|
|
42816
43075
|
if (toRemove.length > 0) {
|
|
42817
|
-
|
|
43076
|
+
log13.info("Purged stale informational items", {
|
|
42818
43077
|
agentId: this.agentId,
|
|
42819
43078
|
count: toRemove.length
|
|
42820
43079
|
});
|
|
@@ -42874,7 +43133,7 @@ ${typeLabel}${item.payload.content}`;
|
|
|
42874
43133
|
${payload.content}`;
|
|
42875
43134
|
existing.payload.summary += ` (+1)`;
|
|
42876
43135
|
this.persistence?.updateStatus(existing.id, "queued", existing);
|
|
42877
|
-
|
|
43136
|
+
log13.debug("Mailbox enqueue-time dedup: merged into existing item", {
|
|
42878
43137
|
agentId: this.agentId,
|
|
42879
43138
|
existingId: existing.id,
|
|
42880
43139
|
sourceType
|
|
@@ -42916,12 +43175,12 @@ function detectAbnormalCompletion(reply, item) {
|
|
|
42916
43175
|
}
|
|
42917
43176
|
return void 0;
|
|
42918
43177
|
}
|
|
42919
|
-
var
|
|
43178
|
+
var log14, AttentionController;
|
|
42920
43179
|
var init_attention = __esm({
|
|
42921
43180
|
"../core/dist/attention.js"() {
|
|
42922
43181
|
"use strict";
|
|
42923
43182
|
init_dist();
|
|
42924
|
-
|
|
43183
|
+
log14 = createLogger("attention");
|
|
42925
43184
|
AttentionController = class _AttentionController {
|
|
42926
43185
|
state = "idle";
|
|
42927
43186
|
currentFocus;
|
|
@@ -42979,10 +43238,10 @@ var init_attention = __esm({
|
|
|
42979
43238
|
this.startWatchdog();
|
|
42980
43239
|
this.loopPromise = this.runLoop().catch((err) => {
|
|
42981
43240
|
if (this.running) {
|
|
42982
|
-
|
|
43241
|
+
log14.error("Attention loop crashed unexpectedly", { agentId: this.agentId, error: String(err) });
|
|
42983
43242
|
}
|
|
42984
43243
|
});
|
|
42985
|
-
|
|
43244
|
+
log14.info("Attention controller started", { agentId: this.agentId });
|
|
42986
43245
|
}
|
|
42987
43246
|
/**
|
|
42988
43247
|
* Stop the attention loop.
|
|
@@ -42993,7 +43252,7 @@ var init_attention = __esm({
|
|
|
42993
43252
|
this.unsubscribeNewItem = void 0;
|
|
42994
43253
|
this.stopWatchdog();
|
|
42995
43254
|
this.mailbox.cancelWait();
|
|
42996
|
-
|
|
43255
|
+
log14.info("Attention controller stopped", { agentId: this.agentId });
|
|
42997
43256
|
}
|
|
42998
43257
|
// ─── Sleep Watchdog ──────────────────────────────────────────────────────
|
|
42999
43258
|
startWatchdog() {
|
|
@@ -43005,7 +43264,7 @@ var init_attention = __esm({
|
|
|
43005
43264
|
if (elapsed > WATCHDOG_INTERVAL_MS + WATCHDOG_DRIFT_THRESHOLD_MS) {
|
|
43006
43265
|
const focusedId = this.currentFocus?.id;
|
|
43007
43266
|
const processingFor = this.processingStartedAt ? Math.round((now2 - this.processingStartedAt) / 1e3) : 0;
|
|
43008
|
-
|
|
43267
|
+
log14.warn("System sleep/wake detected", {
|
|
43009
43268
|
agentId: this.agentId,
|
|
43010
43269
|
driftMs: elapsed,
|
|
43011
43270
|
state: this.state,
|
|
@@ -43057,7 +43316,7 @@ var init_attention = __esm({
|
|
|
43057
43316
|
metadata: item.metadata
|
|
43058
43317
|
});
|
|
43059
43318
|
} catch (err) {
|
|
43060
|
-
|
|
43319
|
+
log14.warn("Failed to re-enqueue item on shutdown", { itemId: item.id, error: String(err) });
|
|
43061
43320
|
}
|
|
43062
43321
|
}
|
|
43063
43322
|
break;
|
|
@@ -43066,7 +43325,7 @@ var init_attention = __esm({
|
|
|
43066
43325
|
this.mailbox.putBack(item);
|
|
43067
43326
|
const purged = this.mailbox.purgeStaleItems();
|
|
43068
43327
|
if (purged > 0) {
|
|
43069
|
-
|
|
43328
|
+
log14.info("Pre-triage stale purge", { agentId: this.agentId, purged });
|
|
43070
43329
|
}
|
|
43071
43330
|
const consolidated = this.mailbox.consolidateByEntity();
|
|
43072
43331
|
const reHead = this.mailbox.dequeue();
|
|
@@ -43074,7 +43333,7 @@ var init_attention = __esm({
|
|
|
43074
43333
|
item = reHead;
|
|
43075
43334
|
}
|
|
43076
43335
|
if (consolidated > 0) {
|
|
43077
|
-
|
|
43336
|
+
log14.info("Pre-triage consolidation reduced queue", {
|
|
43078
43337
|
agentId: this.agentId,
|
|
43079
43338
|
merged: consolidated,
|
|
43080
43339
|
remainingDepth: this.mailbox.depth
|
|
@@ -43155,7 +43414,7 @@ var init_attention = __esm({
|
|
|
43155
43414
|
reply = result.reply;
|
|
43156
43415
|
} else {
|
|
43157
43416
|
timedOut = true;
|
|
43158
|
-
|
|
43417
|
+
log14.error("Processing exceeded backstop timeout \u2014 requeueing", {
|
|
43159
43418
|
agentId: this.agentId,
|
|
43160
43419
|
itemId: item.id,
|
|
43161
43420
|
type: item.sourceType,
|
|
@@ -43163,7 +43422,7 @@ var init_attention = __esm({
|
|
|
43163
43422
|
});
|
|
43164
43423
|
}
|
|
43165
43424
|
} catch (err) {
|
|
43166
|
-
|
|
43425
|
+
log14.warn("Error processing mailbox item", {
|
|
43167
43426
|
agentId: this.agentId,
|
|
43168
43427
|
itemId: item.id,
|
|
43169
43428
|
type: item.sourceType,
|
|
@@ -43174,21 +43433,21 @@ var init_attention = __esm({
|
|
|
43174
43433
|
if (timedOut) {
|
|
43175
43434
|
this.mailbox.requeue(item);
|
|
43176
43435
|
} else if (reply === "[cancelled]" || this.lastYieldDecision === "cancel") {
|
|
43177
|
-
|
|
43436
|
+
log14.info("Item cancelled \u2014 dropping permanently", {
|
|
43178
43437
|
agentId: this.agentId,
|
|
43179
43438
|
itemId: item.id,
|
|
43180
43439
|
type: item.sourceType
|
|
43181
43440
|
});
|
|
43182
43441
|
this.mailbox.complete(item.id);
|
|
43183
43442
|
} else if (reply === "[preempted]" || this.lastYieldDecision === "preempt") {
|
|
43184
|
-
|
|
43443
|
+
log14.info("Item preempted (paused) \u2014 deferring for later resumption", {
|
|
43185
43444
|
agentId: this.agentId,
|
|
43186
43445
|
itemId: item.id,
|
|
43187
43446
|
type: item.sourceType
|
|
43188
43447
|
});
|
|
43189
43448
|
this.mailbox.deferDequeued(item);
|
|
43190
43449
|
} else if (!this.running) {
|
|
43191
|
-
|
|
43450
|
+
log14.info("Agent stopped during processing \u2014 requeueing item", {
|
|
43192
43451
|
agentId: this.agentId,
|
|
43193
43452
|
itemId: item.id,
|
|
43194
43453
|
type: item.sourceType
|
|
@@ -43198,7 +43457,7 @@ var init_attention = __esm({
|
|
|
43198
43457
|
const abnormalReason = detectAbnormalCompletion(reply, item);
|
|
43199
43458
|
const retries = item.retryCount ?? 0;
|
|
43200
43459
|
if (abnormalReason && retries < MAILBOX_ITEM_MAX_RETRIES) {
|
|
43201
|
-
|
|
43460
|
+
log14.warn("Abnormal completion detected, requeueing for retry", {
|
|
43202
43461
|
agentId: this.agentId,
|
|
43203
43462
|
itemId: item.id,
|
|
43204
43463
|
type: item.sourceType,
|
|
@@ -43208,7 +43467,7 @@ var init_attention = __esm({
|
|
|
43208
43467
|
this.mailbox.requeue(item);
|
|
43209
43468
|
} else {
|
|
43210
43469
|
if (abnormalReason) {
|
|
43211
|
-
|
|
43470
|
+
log14.error("Abnormal completion persisted after max retries, completing anyway", {
|
|
43212
43471
|
agentId: this.agentId,
|
|
43213
43472
|
itemId: item.id,
|
|
43214
43473
|
type: item.sourceType,
|
|
@@ -43396,7 +43655,7 @@ var init_attention = __esm({
|
|
|
43396
43655
|
if (validDecisions.includes(llmDecision))
|
|
43397
43656
|
return llmDecision;
|
|
43398
43657
|
} catch (err) {
|
|
43399
|
-
|
|
43658
|
+
log14.debug("LLM judge failed, falling back to heuristic", {
|
|
43400
43659
|
agentId: this.agentId,
|
|
43401
43660
|
error: String(err)
|
|
43402
43661
|
});
|
|
@@ -43527,17 +43786,17 @@ var init_attention = __esm({
|
|
|
43527
43786
|
const cleaned = raw.replace(/<think>[\s\S]*?<\/think>/gi, "").replace(/<think>[\s\S]*/gi, "").trim();
|
|
43528
43787
|
const jsonMatch = cleaned.match(/\{[\s\S]*\}/);
|
|
43529
43788
|
if (!jsonMatch) {
|
|
43530
|
-
|
|
43789
|
+
log14.warn("Triage judge returned non-JSON response", { agentId: this.agentId, raw: raw.slice(0, 300) });
|
|
43531
43790
|
return null;
|
|
43532
43791
|
}
|
|
43533
43792
|
const parsed = JSON.parse(jsonMatch[0]);
|
|
43534
43793
|
if (!parsed.processItemId || !parsed.reasoning) {
|
|
43535
|
-
|
|
43794
|
+
log14.warn("Triage judge returned incomplete result", { agentId: this.agentId, parsed });
|
|
43536
43795
|
return null;
|
|
43537
43796
|
}
|
|
43538
43797
|
const allCandidateIds = /* @__PURE__ */ new Set([headItem.id, ...this.mailbox.getQueuedItems().map((i) => i.id)]);
|
|
43539
43798
|
if (!allCandidateIds.has(parsed.processItemId)) {
|
|
43540
|
-
|
|
43799
|
+
log14.warn("Triage judge chose unknown item ID", {
|
|
43541
43800
|
agentId: this.agentId,
|
|
43542
43801
|
chosen: parsed.processItemId,
|
|
43543
43802
|
candidates: [...allCandidateIds]
|
|
@@ -43551,7 +43810,7 @@ var init_attention = __esm({
|
|
|
43551
43810
|
reasoning: parsed.reasoning
|
|
43552
43811
|
};
|
|
43553
43812
|
} catch (err) {
|
|
43554
|
-
|
|
43813
|
+
log14.warn("Triage deliberation failed, falling back to priority order", {
|
|
43555
43814
|
agentId: this.agentId,
|
|
43556
43815
|
error: String(err)
|
|
43557
43816
|
});
|
|
@@ -44468,12 +44727,12 @@ function hashString(str) {
|
|
|
44468
44727
|
function noDetection() {
|
|
44469
44728
|
return { detected: false, severity: "none", pattern: "", message: "" };
|
|
44470
44729
|
}
|
|
44471
|
-
var
|
|
44730
|
+
var log15, DEFAULT_CONFIG3, ToolLoopDetector;
|
|
44472
44731
|
var init_tool_loop_detector = __esm({
|
|
44473
44732
|
"../core/dist/tool-loop-detector.js"() {
|
|
44474
44733
|
"use strict";
|
|
44475
44734
|
init_dist();
|
|
44476
|
-
|
|
44735
|
+
log15 = createLogger("tool-loop-detector");
|
|
44477
44736
|
DEFAULT_CONFIG3 = {
|
|
44478
44737
|
enabled: true,
|
|
44479
44738
|
historySize: 30,
|
|
@@ -44543,12 +44802,12 @@ var init_tool_loop_detector = __esm({
|
|
|
44543
44802
|
}
|
|
44544
44803
|
if (streak >= this.config.criticalThreshold) {
|
|
44545
44804
|
const msg = `Critical: "${last.name}" called ${streak} times with identical arguments`;
|
|
44546
|
-
|
|
44805
|
+
log15.warn(msg);
|
|
44547
44806
|
return { detected: true, severity: "critical", pattern: "genericRepeat", message: msg };
|
|
44548
44807
|
}
|
|
44549
44808
|
if (streak >= this.config.warningThreshold) {
|
|
44550
44809
|
const msg = `Warning: "${last.name}" called ${streak} times with identical arguments`;
|
|
44551
|
-
|
|
44810
|
+
log15.warn(msg);
|
|
44552
44811
|
return { detected: true, severity: "warning", pattern: "genericRepeat", message: msg };
|
|
44553
44812
|
}
|
|
44554
44813
|
return noDetection();
|
|
@@ -44576,12 +44835,12 @@ var init_tool_loop_detector = __esm({
|
|
|
44576
44835
|
}
|
|
44577
44836
|
if (cycles >= Math.ceil(this.config.criticalThreshold / 2)) {
|
|
44578
44837
|
const msg = `Critical: ping-pong pattern detected \u2014 "${recent[recent.length - 2].name}" \u2194 "${recent[recent.length - 1].name}" for ${cycles} cycles`;
|
|
44579
|
-
|
|
44838
|
+
log15.warn(msg);
|
|
44580
44839
|
return { detected: true, severity: "critical", pattern: "pingPong", message: msg };
|
|
44581
44840
|
}
|
|
44582
44841
|
if (cycles >= Math.ceil(this.config.warningThreshold / 2)) {
|
|
44583
44842
|
const msg = `Warning: ping-pong pattern \u2014 "${recent[recent.length - 2].name}" \u2194 "${recent[recent.length - 1].name}" for ${cycles} cycles`;
|
|
44584
|
-
|
|
44843
|
+
log15.warn(msg);
|
|
44585
44844
|
return { detected: true, severity: "warning", pattern: "pingPong", message: msg };
|
|
44586
44845
|
}
|
|
44587
44846
|
return noDetection();
|
|
@@ -44605,12 +44864,12 @@ var init_tool_loop_detector = __esm({
|
|
|
44605
44864
|
}
|
|
44606
44865
|
if (sameResultStreak >= this.config.criticalThreshold) {
|
|
44607
44866
|
const msg = `Critical: "${recent[recent.length - 1].name}" returned identical results ${sameResultStreak} times \u2014 no progress`;
|
|
44608
|
-
|
|
44867
|
+
log15.warn(msg);
|
|
44609
44868
|
return { detected: true, severity: "critical", pattern: "noProgress", message: msg };
|
|
44610
44869
|
}
|
|
44611
44870
|
if (sameResultStreak >= this.config.warningThreshold) {
|
|
44612
44871
|
const msg = `Warning: "${recent[recent.length - 1].name}" returned identical results ${sameResultStreak} times`;
|
|
44613
|
-
|
|
44872
|
+
log15.warn(msg);
|
|
44614
44873
|
return { detected: true, severity: "warning", pattern: "noProgress", message: msg };
|
|
44615
44874
|
}
|
|
44616
44875
|
return noDetection();
|
|
@@ -44651,7 +44910,7 @@ async function checkMarkitdown() {
|
|
|
44651
44910
|
execFile2("markitdown", ["--help"], { timeout: 5e3 }, (err) => {
|
|
44652
44911
|
markitdownAvailable = !err;
|
|
44653
44912
|
if (!markitdownAvailable) {
|
|
44654
|
-
|
|
44913
|
+
log16.info('markitdown CLI not found; file-to-text conversion will be limited. Install with: pip install "markitdown[all]"');
|
|
44655
44914
|
}
|
|
44656
44915
|
resolve20(markitdownAvailable);
|
|
44657
44916
|
});
|
|
@@ -44698,7 +44957,7 @@ async function convertFilesToText(dataUrls, fileNames) {
|
|
|
44698
44957
|
await unlink(filePath).catch(() => {
|
|
44699
44958
|
});
|
|
44700
44959
|
} catch (err) {
|
|
44701
|
-
|
|
44960
|
+
log16.warn(`markitdown conversion failed for ${name}: ${err}`);
|
|
44702
44961
|
results.push({ name, mimeType: parsed.mimeType, text: fallbackImageDescription(name, parsed.mimeType, parsed.data.length) });
|
|
44703
44962
|
}
|
|
44704
44963
|
} else {
|
|
@@ -44717,12 +44976,12 @@ async function convertFilesToText(dataUrls, fileNames) {
|
|
|
44717
44976
|
function resetMarkitdownCache() {
|
|
44718
44977
|
markitdownAvailable = null;
|
|
44719
44978
|
}
|
|
44720
|
-
var
|
|
44979
|
+
var log16, MIME_TO_EXT, markitdownAvailable;
|
|
44721
44980
|
var init_file_converter = __esm({
|
|
44722
44981
|
"../core/dist/file-converter.js"() {
|
|
44723
44982
|
"use strict";
|
|
44724
44983
|
init_dist();
|
|
44725
|
-
|
|
44984
|
+
log16 = createLogger("file-converter");
|
|
44726
44985
|
MIME_TO_EXT = {
|
|
44727
44986
|
"image/png": ".png",
|
|
44728
44987
|
"image/jpeg": ".jpg",
|
|
@@ -44785,7 +45044,7 @@ function isErrorResult2(result) {
|
|
|
44785
45044
|
return false;
|
|
44786
45045
|
}
|
|
44787
45046
|
}
|
|
44788
|
-
var taskAsyncContext, chatSubagentContext,
|
|
45047
|
+
var taskAsyncContext, chatSubagentContext, log17, RAW_TOOL_XML_RE, Agent;
|
|
44789
45048
|
var init_agent2 = __esm({
|
|
44790
45049
|
"../core/dist/agent.js"() {
|
|
44791
45050
|
"use strict";
|
|
@@ -44798,6 +45057,7 @@ var init_agent2 = __esm({
|
|
|
44798
45057
|
init_store();
|
|
44799
45058
|
init_agent_metrics();
|
|
44800
45059
|
init_context_engine();
|
|
45060
|
+
init_cognitive2();
|
|
44801
45061
|
init_environment_profile();
|
|
44802
45062
|
init_tool_selector();
|
|
44803
45063
|
init_builtin();
|
|
@@ -44810,7 +45070,7 @@ var init_agent2 = __esm({
|
|
|
44810
45070
|
init_tool_loop_detector();
|
|
44811
45071
|
taskAsyncContext = new AsyncLocalStorage();
|
|
44812
45072
|
chatSubagentContext = new AsyncLocalStorage();
|
|
44813
|
-
|
|
45073
|
+
log17 = createLogger("agent");
|
|
44814
45074
|
RAW_TOOL_XML_RE = /(?:minimax:tool_call\s*)?<invoke\s+name="[^"]*">\s*(?:<parameter\s+name="[^"]*">[^<]*<\/parameter>\s*)*<\/invoke>\s*(?:<\/minimax:tool_call>)?/gi;
|
|
44815
45075
|
Agent = class _Agent {
|
|
44816
45076
|
id;
|
|
@@ -44873,6 +45133,8 @@ var init_agent2 = __esm({
|
|
|
44873
45133
|
lastInjectedActivityType;
|
|
44874
45134
|
/** Persistent situational awareness from the latest triage deliberation. */
|
|
44875
45135
|
currentCognition;
|
|
45136
|
+
/** Cognitive Preparation Pipeline instance (null when CPP is disabled) */
|
|
45137
|
+
cognitivePrep;
|
|
44876
45138
|
/** Ring buffer of recent activity summaries for triage context. */
|
|
44877
45139
|
recentActivityRing = [];
|
|
44878
45140
|
static ACTIVITY_RING_SIZE = 8;
|
|
@@ -44942,6 +45204,9 @@ var init_agent2 = __esm({
|
|
|
44942
45204
|
this.guardrails = new GuardrailPipeline();
|
|
44943
45205
|
this.toolHooks = new ToolHookRegistry();
|
|
44944
45206
|
this.metricsCollector = new AgentMetricsCollector(this.id, options.dataDir);
|
|
45207
|
+
if (options.cognitive?.enabled) {
|
|
45208
|
+
this.cognitivePrep = new CognitivePreparation(options.cognitive);
|
|
45209
|
+
}
|
|
44945
45210
|
this.heartbeat = new HeartbeatScheduler(this.id, this.eventBus, {
|
|
44946
45211
|
intervalMs: this.config.heartbeatIntervalMs,
|
|
44947
45212
|
enabled: true
|
|
@@ -45008,17 +45273,17 @@ ${notification.stdoutTail}`);
|
|
|
45008
45273
|
if ((ctx.toolName === "file_edit" || ctx.toolName === "file_write") && ctx.success) {
|
|
45009
45274
|
const targetPath = ctx.arguments["path"] ?? ctx.arguments["filePath"] ?? "";
|
|
45010
45275
|
if (targetPath === roleFilePath || targetPath.endsWith("/role/ROLE.md")) {
|
|
45011
|
-
|
|
45276
|
+
log17.info("Agent modified its own ROLE.md \u2014 reloading role definition");
|
|
45012
45277
|
this.reloadRole();
|
|
45013
45278
|
}
|
|
45014
45279
|
if (targetPath === heartbeatFilePath || targetPath.endsWith("/role/HEARTBEAT.md")) {
|
|
45015
|
-
|
|
45280
|
+
log17.info("Agent modified its own HEARTBEAT.md \u2014 reloading heartbeat checklist");
|
|
45016
45281
|
this.reloadHeartbeat();
|
|
45017
45282
|
}
|
|
45018
45283
|
}
|
|
45019
45284
|
}
|
|
45020
45285
|
});
|
|
45021
|
-
|
|
45286
|
+
log17.info(`Agent created: ${this.id}`, { name: this.config.name, role: this.role.name });
|
|
45022
45287
|
}
|
|
45023
45288
|
/**
|
|
45024
45289
|
* Resolve the LLM provider name for this agent.
|
|
@@ -45054,32 +45319,32 @@ ${notification.stdoutTail}`);
|
|
|
45054
45319
|
try {
|
|
45055
45320
|
this.environmentProfile = await detectEnvironment();
|
|
45056
45321
|
} catch (e) {
|
|
45057
|
-
|
|
45322
|
+
log17.warn("Environment detection failed", { error: String(e) });
|
|
45058
45323
|
}
|
|
45059
45324
|
const latestSession = this.memory.getLatestSession(this.id);
|
|
45060
45325
|
if (latestSession && latestSession.messages.length > 0) {
|
|
45061
45326
|
this.currentSessionId = latestSession.id;
|
|
45062
|
-
|
|
45327
|
+
log17.info(`Resumed session ${latestSession.id} with ${latestSession.messages.length} messages`);
|
|
45063
45328
|
}
|
|
45064
45329
|
if (!this.currentSessionId) {
|
|
45065
45330
|
const fallback = this.memory.createSession(this.id);
|
|
45066
45331
|
this.currentSessionId = fallback.id;
|
|
45067
|
-
|
|
45332
|
+
log17.info(`Created fallback session for activity injection: ${fallback.id}`);
|
|
45068
45333
|
}
|
|
45069
45334
|
if (shouldPause) {
|
|
45070
45335
|
this.setStatus("paused");
|
|
45071
45336
|
this.pauseReason = this.pauseReason || "Restored as paused from previous session";
|
|
45072
45337
|
this.eventBus.emit("agent:paused", { agentId: this.id, reason: this.pauseReason });
|
|
45073
|
-
|
|
45338
|
+
log17.info(`Agent started as paused: ${this.config.name}`);
|
|
45074
45339
|
return;
|
|
45075
45340
|
}
|
|
45076
45341
|
this.heartbeat.start(options?.initialHeartbeatDelayMs);
|
|
45077
45342
|
this.attentionController.start();
|
|
45078
45343
|
this.memoryConsolidationTimer = setInterval(() => {
|
|
45079
|
-
this.consolidateMemory().catch((e) =>
|
|
45344
|
+
this.consolidateMemory().catch((e) => log17.warn("Memory consolidation failed", { error: String(e) }));
|
|
45080
45345
|
}, _Agent.MEMORY_CONSOLIDATION_INTERVAL_MS);
|
|
45081
45346
|
this.eventBus.emit("agent:started", { agentId: this.id });
|
|
45082
|
-
|
|
45347
|
+
log17.info(`Agent started: ${this.config.name}`);
|
|
45083
45348
|
}
|
|
45084
45349
|
async stop() {
|
|
45085
45350
|
this.cancelActiveStream();
|
|
@@ -45094,7 +45359,7 @@ ${notification.stdoutTail}`);
|
|
|
45094
45359
|
const wasPaused = this.state.status === "paused";
|
|
45095
45360
|
this.setStatus(wasPaused ? "paused" : "offline");
|
|
45096
45361
|
this.eventBus.emit("agent:stopped", { agentId: this.id });
|
|
45097
|
-
|
|
45362
|
+
log17.info(`Agent stopped: ${this.config.name}${wasPaused ? " (preserving paused state)" : ""}`);
|
|
45098
45363
|
}
|
|
45099
45364
|
// ─── Mailbox & Attention ──────────────────────────────────────────────────
|
|
45100
45365
|
/**
|
|
@@ -45126,7 +45391,8 @@ ${notification.stdoutTail}`);
|
|
|
45126
45391
|
fileNames: options?.fileNames,
|
|
45127
45392
|
allowedTools: options?.allowedTools ? [...options.allowedTools] : void 0,
|
|
45128
45393
|
scenario: options?.scenario,
|
|
45129
|
-
toolEventCollector: options?.toolEventCollector
|
|
45394
|
+
toolEventCollector: options?.toolEventCollector,
|
|
45395
|
+
waitForReply: options?.waitForReply
|
|
45130
45396
|
}
|
|
45131
45397
|
};
|
|
45132
45398
|
return new Promise((resolve20, reject) => {
|
|
@@ -45260,7 +45526,7 @@ ${notification.stdoutTail}`);
|
|
|
45260
45526
|
return this.processMailboxItemInternal(item);
|
|
45261
45527
|
},
|
|
45262
45528
|
onDecisionMade: (decision) => {
|
|
45263
|
-
|
|
45529
|
+
log17.debug("Attention decision", {
|
|
45264
45530
|
agentId: this.id,
|
|
45265
45531
|
type: decision.decisionType,
|
|
45266
45532
|
itemType: this.attentionController.getCurrentFocus()?.sourceType,
|
|
@@ -45340,6 +45606,8 @@ ${notification.stdoutTail}`);
|
|
|
45340
45606
|
opts.scenario = extra.scenario;
|
|
45341
45607
|
if (extra.toolEventCollector !== void 0)
|
|
45342
45608
|
opts.toolEventCollector = extra.toolEventCollector;
|
|
45609
|
+
if (extra.waitForReply !== void 0)
|
|
45610
|
+
opts.waitForReply = extra.waitForReply;
|
|
45343
45611
|
if (extra.allowedTools !== void 0) {
|
|
45344
45612
|
opts.allowedTools = new Set(extra.allowedTools);
|
|
45345
45613
|
}
|
|
@@ -45369,7 +45637,7 @@ ${notification.stdoutTail}`);
|
|
|
45369
45637
|
resolveResponse("");
|
|
45370
45638
|
return;
|
|
45371
45639
|
}
|
|
45372
|
-
|
|
45640
|
+
log17.info("Task status update (informational, no LLM)", {
|
|
45373
45641
|
agentId: this.id,
|
|
45374
45642
|
summary: item.payload.summary
|
|
45375
45643
|
});
|
|
@@ -45388,7 +45656,7 @@ ${notification.stdoutTail}`);
|
|
|
45388
45656
|
resolveResponse(reply);
|
|
45389
45657
|
return reply;
|
|
45390
45658
|
}
|
|
45391
|
-
|
|
45659
|
+
log17.info("Requirement update (informational, no LLM)", {
|
|
45392
45660
|
agentId: this.id,
|
|
45393
45661
|
summary: item.payload.summary
|
|
45394
45662
|
});
|
|
@@ -45528,9 +45796,9 @@ ${notification.stdoutTail}`);
|
|
|
45528
45796
|
name,
|
|
45529
45797
|
systemPrompt: content
|
|
45530
45798
|
};
|
|
45531
|
-
|
|
45799
|
+
log17.info(`Role reloaded from disk for agent ${this.config.name}`);
|
|
45532
45800
|
} catch (err) {
|
|
45533
|
-
|
|
45801
|
+
log17.warn(`Failed to reload role for agent ${this.config.name}`, { error: String(err) });
|
|
45534
45802
|
}
|
|
45535
45803
|
}
|
|
45536
45804
|
/**
|
|
@@ -45547,9 +45815,9 @@ ${notification.stdoutTail}`);
|
|
|
45547
45815
|
...this.role,
|
|
45548
45816
|
heartbeatChecklist: content
|
|
45549
45817
|
};
|
|
45550
|
-
|
|
45818
|
+
log17.info(`Heartbeat checklist reloaded from disk for agent ${this.config.name}`);
|
|
45551
45819
|
} catch (err) {
|
|
45552
|
-
|
|
45820
|
+
log17.warn(`Failed to reload heartbeat for agent ${this.config.name}`, { error: String(err) });
|
|
45553
45821
|
}
|
|
45554
45822
|
}
|
|
45555
45823
|
/**
|
|
@@ -45559,7 +45827,7 @@ ${notification.stdoutTail}`);
|
|
|
45559
45827
|
startNewSession() {
|
|
45560
45828
|
const session = this.memory.createSession(this.id);
|
|
45561
45829
|
this.currentSessionId = session.id;
|
|
45562
|
-
|
|
45830
|
+
log17.info(`New session started for agent ${this.config.name}: ${session.id}`);
|
|
45563
45831
|
}
|
|
45564
45832
|
/**
|
|
45565
45833
|
* Bind the current in-memory session to a DB session ID (ses_*).
|
|
@@ -45569,7 +45837,7 @@ ${notification.stdoutTail}`);
|
|
|
45569
45837
|
bindDbSession(dbSessionId) {
|
|
45570
45838
|
if (this.currentSessionId) {
|
|
45571
45839
|
this.dbSessionMap.set(dbSessionId, this.currentSessionId);
|
|
45572
|
-
|
|
45840
|
+
log17.debug(`Bound DB session ${dbSessionId} \u2192 memory session ${this.currentSessionId}`);
|
|
45573
45841
|
}
|
|
45574
45842
|
}
|
|
45575
45843
|
/**
|
|
@@ -45594,9 +45862,9 @@ ${notification.stdoutTail}`);
|
|
|
45594
45862
|
if (session2.messages.length > 0 && session2.messages[session2.messages.length - 1].role === "user") {
|
|
45595
45863
|
session2.messages.pop();
|
|
45596
45864
|
}
|
|
45597
|
-
|
|
45865
|
+
log17.info(`Trimmed memory session for retry: ${existingMemorySessionId} (${session2.messages.length} messages remaining)`);
|
|
45598
45866
|
}
|
|
45599
|
-
|
|
45867
|
+
log17.debug(`Switched to existing memory session ${existingMemorySessionId} for DB session ${dbSessionId}`);
|
|
45600
45868
|
return;
|
|
45601
45869
|
}
|
|
45602
45870
|
this.dbSessionMap.delete(dbSessionId);
|
|
@@ -45612,7 +45880,7 @@ ${notification.stdoutTail}`);
|
|
|
45612
45880
|
}
|
|
45613
45881
|
}
|
|
45614
45882
|
this.currentSessionId = session.id;
|
|
45615
|
-
|
|
45883
|
+
log17.info(`Restored session context for DB session ${dbSessionId} \u2192 memory session ${session.id} (${dbMessages.length} messages)`);
|
|
45616
45884
|
}
|
|
45617
45885
|
pause(reason) {
|
|
45618
45886
|
this.pauseReason = reason;
|
|
@@ -45627,7 +45895,7 @@ ${notification.stdoutTail}`);
|
|
|
45627
45895
|
}
|
|
45628
45896
|
this.setStatus("paused");
|
|
45629
45897
|
this.eventBus.emit("agent:paused", { agentId: this.id, reason });
|
|
45630
|
-
|
|
45898
|
+
log17.info(`Agent paused: ${this.config.name}`, { reason });
|
|
45631
45899
|
}
|
|
45632
45900
|
resume() {
|
|
45633
45901
|
if (this.state.status !== "paused")
|
|
@@ -45637,12 +45905,12 @@ ${notification.stdoutTail}`);
|
|
|
45637
45905
|
this.attentionController.start();
|
|
45638
45906
|
if (!this.memoryConsolidationTimer) {
|
|
45639
45907
|
this.memoryConsolidationTimer = setInterval(() => {
|
|
45640
|
-
this.consolidateMemory().catch((e) =>
|
|
45908
|
+
this.consolidateMemory().catch((e) => log17.warn("Memory consolidation failed", { error: String(e) }));
|
|
45641
45909
|
}, _Agent.MEMORY_CONSOLIDATION_INTERVAL_MS);
|
|
45642
45910
|
}
|
|
45643
45911
|
this.setStatus(this.activeTasks.size > 0 ? "working" : "idle");
|
|
45644
45912
|
this.eventBus.emit("agent:resumed", { agentId: this.id });
|
|
45645
|
-
|
|
45913
|
+
log17.info(`Agent resumed: ${this.config.name}`);
|
|
45646
45914
|
}
|
|
45647
45915
|
getPauseReason() {
|
|
45648
45916
|
return this.pauseReason;
|
|
@@ -45666,10 +45934,10 @@ ${notification.stdoutTail}`);
|
|
|
45666
45934
|
this.pendingInjections.set(sessionId, queue);
|
|
45667
45935
|
}
|
|
45668
45936
|
queue.push(content);
|
|
45669
|
-
|
|
45937
|
+
log17.debug("Buffered injected message for next LLM turn", { sessionId, contentLength: content.length, queueSize: queue.length });
|
|
45670
45938
|
} else {
|
|
45671
45939
|
this.memory.appendMessage(sessionId, { role: "user", content });
|
|
45672
|
-
|
|
45940
|
+
log17.debug("Injected user message into session (direct)", { sessionId, contentLength: content.length });
|
|
45673
45941
|
}
|
|
45674
45942
|
}
|
|
45675
45943
|
/**
|
|
@@ -45683,7 +45951,7 @@ ${notification.stdoutTail}`);
|
|
|
45683
45951
|
for (const content of queue) {
|
|
45684
45952
|
this.memory.appendMessage(sessionId, { role: "user", content });
|
|
45685
45953
|
}
|
|
45686
|
-
|
|
45954
|
+
log17.info("Flushed pending injections into session", { sessionId, count: queue.length });
|
|
45687
45955
|
this.pendingInjections.delete(sessionId);
|
|
45688
45956
|
}
|
|
45689
45957
|
/**
|
|
@@ -45809,7 +46077,7 @@ ${notification.stdoutTail}`);
|
|
|
45809
46077
|
cancelActiveStream() {
|
|
45810
46078
|
if (this.activeStreamToken) {
|
|
45811
46079
|
this.activeStreamToken.cancelled = true;
|
|
45812
|
-
|
|
46080
|
+
log17.info("Active stream cancelled", { agentId: this.id });
|
|
45813
46081
|
}
|
|
45814
46082
|
}
|
|
45815
46083
|
/** Get a cancel token for the current stream */
|
|
@@ -45970,7 +46238,7 @@ ${conversationText}`
|
|
|
45970
46238
|
const dailyLimit = this.config.llmConfig?.maxTokensPerDay;
|
|
45971
46239
|
if (dailyLimit && this.getTokensUsed() >= dailyLimit) {
|
|
45972
46240
|
const msg = `Daily token budget exhausted (${this.getTokensUsed()} / ${dailyLimit})`;
|
|
45973
|
-
|
|
46241
|
+
log17.warn(msg, { agentId: this.id });
|
|
45974
46242
|
this.pause(msg);
|
|
45975
46243
|
throw new Error(`Agent ${this.id}: ${msg}`);
|
|
45976
46244
|
}
|
|
@@ -46154,6 +46422,43 @@ ${instructions}
|
|
|
46154
46422
|
}
|
|
46155
46423
|
return parts.length > 0 ? parts.join("\n\n") : void 0;
|
|
46156
46424
|
}
|
|
46425
|
+
/**
|
|
46426
|
+
* Run the Cognitive Preparation Pipeline (appraisal phase) before the main LLM call.
|
|
46427
|
+
* Returns undefined when CPP is disabled or on error (caller falls back to mechanical retrieval).
|
|
46428
|
+
*/
|
|
46429
|
+
async prepareCognitiveContext(scenario, message, sender) {
|
|
46430
|
+
if (!this.cognitivePrep)
|
|
46431
|
+
return void 0;
|
|
46432
|
+
const stimulus = {
|
|
46433
|
+
type: scenario,
|
|
46434
|
+
summary: message.slice(0, 200),
|
|
46435
|
+
content: message,
|
|
46436
|
+
sender,
|
|
46437
|
+
scenario
|
|
46438
|
+
};
|
|
46439
|
+
const agentCtx = {
|
|
46440
|
+
id: this.id,
|
|
46441
|
+
name: this.config.name,
|
|
46442
|
+
roleDescription: this.role.systemPrompt.slice(0, 300),
|
|
46443
|
+
status: this.state.status,
|
|
46444
|
+
currentTask: this.currentTaskId,
|
|
46445
|
+
recentActivity: this.recentActivityRing.slice(-5)
|
|
46446
|
+
};
|
|
46447
|
+
const tasks = this.tasksFetcher?.();
|
|
46448
|
+
const hasFailedTasks = tasks?.some((t) => t.status === "failed") ?? false;
|
|
46449
|
+
const hasBlockers = tasks?.some((t) => t.status === "blocked") ?? false;
|
|
46450
|
+
const depth = selectCognitiveDepth(scenario, { hasFailedTasks, hasBlockers }, message.length);
|
|
46451
|
+
try {
|
|
46452
|
+
const startMs = Date.now();
|
|
46453
|
+
const result = await this.cognitivePrep.prepare(stimulus, agentCtx, depth, this.llmRouter);
|
|
46454
|
+
const elapsedMs = Date.now() - startMs;
|
|
46455
|
+
log17.info("CPP completed", { depth: result.depth, isEmpty: result.isEmpty, elapsedMs });
|
|
46456
|
+
return result;
|
|
46457
|
+
} catch (err) {
|
|
46458
|
+
log17.warn("CPP failed, falling back to mechanical retrieval", { error: String(err) });
|
|
46459
|
+
return void 0;
|
|
46460
|
+
}
|
|
46461
|
+
}
|
|
46157
46462
|
getMailboxContext() {
|
|
46158
46463
|
const mind = this.attentionController.getMindState();
|
|
46159
46464
|
if (mind.attentionState === "idle" && mind.mailboxDepth === 0 && mind.recentDecisions.length === 0) {
|
|
@@ -46430,7 +46735,7 @@ No recent activity recorded.`,
|
|
|
46430
46735
|
${report}`);
|
|
46431
46736
|
return report;
|
|
46432
46737
|
} catch (error) {
|
|
46433
|
-
|
|
46738
|
+
log17.error("Failed to generate daily report", { error: String(error) });
|
|
46434
46739
|
return `Unable to generate report: ${String(error)}`;
|
|
46435
46740
|
}
|
|
46436
46741
|
}
|
|
@@ -46530,6 +46835,7 @@ ${block}
|
|
|
46530
46835
|
counter.setActiveModel(effectiveModelName);
|
|
46531
46836
|
await counter.ensureReady();
|
|
46532
46837
|
}
|
|
46838
|
+
const cognitiveContext = await this.prepareCognitiveContext(scenario, effectiveMessage, senderId);
|
|
46533
46839
|
const systemPrompt = await this.contextEngine.buildSystemPrompt({
|
|
46534
46840
|
agentId: this.id,
|
|
46535
46841
|
agentName: this.config.name,
|
|
@@ -46544,6 +46850,7 @@ ${block}
|
|
|
46544
46850
|
deliverableContext: isLightweight ? void 0 : this.getDeliverableContext(effectiveMessage),
|
|
46545
46851
|
environment: this.environmentProfile,
|
|
46546
46852
|
scenario,
|
|
46853
|
+
a2aWaitForReply: scenario === "a2a" ? options?.waitForReply : void 0,
|
|
46547
46854
|
agentWorkspace: this.pathPolicy ? {
|
|
46548
46855
|
primaryWorkspace: this.pathPolicy.primaryWorkspace,
|
|
46549
46856
|
sharedWorkspace: this.pathPolicy.sharedWorkspace,
|
|
@@ -46553,6 +46860,7 @@ ${block}
|
|
|
46553
46860
|
agentDataDir: this.dataDir,
|
|
46554
46861
|
availableSkills: this.availableSkillCatalog,
|
|
46555
46862
|
mailboxContext: this.getMailboxContext(),
|
|
46863
|
+
cognitiveContext,
|
|
46556
46864
|
...this.getTeamContextParams()
|
|
46557
46865
|
});
|
|
46558
46866
|
let llmTools = this.buildToolDefinitions({
|
|
@@ -46574,7 +46882,7 @@ ${block}
|
|
|
46574
46882
|
toolDefinitions: llmTools
|
|
46575
46883
|
});
|
|
46576
46884
|
const messages = prepared.messages;
|
|
46577
|
-
|
|
46885
|
+
log17.debug("Context usage for chat", { usagePercent: prepared.usage.usagePercent, totalUsed: prepared.usage.totalUsed });
|
|
46578
46886
|
const useCompaction = this.llmRouter.isCompactionSupported(this.getEffectiveProvider());
|
|
46579
46887
|
try {
|
|
46580
46888
|
this.checkDailyTokenBudget();
|
|
@@ -46600,7 +46908,7 @@ ${block}
|
|
|
46600
46908
|
const effectiveMaxIter = options?.maxToolIterations ?? this._maxToolIterations;
|
|
46601
46909
|
while (response.finishReason === "tool_use" && response.toolCalls?.length || response.finishReason === "max_tokens") {
|
|
46602
46910
|
if (++toolIterations > effectiveMaxIter) {
|
|
46603
|
-
|
|
46911
|
+
log17.warn("Tool loop hit max iterations", {
|
|
46604
46912
|
agentId: this.id,
|
|
46605
46913
|
iterations: toolIterations,
|
|
46606
46914
|
cap: effectiveMaxIter
|
|
@@ -46701,7 +47009,7 @@ ${block}
|
|
|
46701
47009
|
const warningMsg = `[SYSTEM] Loop detected: ${loopCheck.message}. You are repeating the same actions without progress. Try a different approach or stop.`;
|
|
46702
47010
|
this.memory.appendMessage(sessionId, { role: "user", content: warningMsg });
|
|
46703
47011
|
if (loopCheck.severity === "critical") {
|
|
46704
|
-
|
|
47012
|
+
log17.warn("Loop detector: critical pattern \u2014 force-breaking tool loop", {
|
|
46705
47013
|
agentId: this.id,
|
|
46706
47014
|
pattern: loopCheck.pattern
|
|
46707
47015
|
});
|
|
@@ -46709,7 +47017,7 @@ ${block}
|
|
|
46709
47017
|
}
|
|
46710
47018
|
}
|
|
46711
47019
|
if (isPreemptable && this.attentionController.hasInterruptPending()) {
|
|
46712
|
-
|
|
47020
|
+
log17.info("Interrupt arrived during parallel tool execution, breaking early", {
|
|
46713
47021
|
agentId: this.id,
|
|
46714
47022
|
scenario
|
|
46715
47023
|
});
|
|
@@ -46720,7 +47028,7 @@ ${block}
|
|
|
46720
47028
|
if (chatYield.decision === "preempt" || chatYield.decision === "cancel") {
|
|
46721
47029
|
if (isPreemptable) {
|
|
46722
47030
|
const marker = chatYield.decision === "cancel" ? "[cancelled]" : "[preempted]";
|
|
46723
|
-
|
|
47031
|
+
log17.info(`handleMessage ${chatYield.decision} by higher-priority item`, {
|
|
46724
47032
|
agentId: this.id,
|
|
46725
47033
|
scenario,
|
|
46726
47034
|
preemptedBy: chatYield.item?.sourceType
|
|
@@ -46814,7 +47122,7 @@ ${chatYield.item.payload.content}`;
|
|
|
46814
47122
|
success: false,
|
|
46815
47123
|
detail: String(error)
|
|
46816
47124
|
});
|
|
46817
|
-
|
|
47125
|
+
log17.error("Failed to handle message", { error: String(error) });
|
|
46818
47126
|
throw error;
|
|
46819
47127
|
}
|
|
46820
47128
|
}
|
|
@@ -46843,6 +47151,7 @@ ${chatYield.item.payload.content}`;
|
|
|
46843
47151
|
}
|
|
46844
47152
|
const userContent = await this.buildUserContent(userMessage, images, fileNames);
|
|
46845
47153
|
this.memory.appendMessage(this.currentSessionId, { role: "user", content: userContent });
|
|
47154
|
+
const cognitiveContext = await this.prepareCognitiveContext("chat", effectiveMessage, senderId);
|
|
46846
47155
|
const systemPrompt = await this.contextEngine.buildSystemPrompt({
|
|
46847
47156
|
agentId: this.id,
|
|
46848
47157
|
agentName: this.config.name,
|
|
@@ -46866,6 +47175,7 @@ ${chatYield.item.payload.content}`;
|
|
|
46866
47175
|
agentDataDir: this.dataDir,
|
|
46867
47176
|
availableSkills: this.availableSkillCatalog,
|
|
46868
47177
|
mailboxContext: this.getMailboxContext(),
|
|
47178
|
+
cognitiveContext,
|
|
46869
47179
|
...this.getTeamContextParams()
|
|
46870
47180
|
});
|
|
46871
47181
|
const llmTools = this.buildToolDefinitions({ userMessage: effectiveMessage });
|
|
@@ -46881,7 +47191,7 @@ ${chatYield.item.payload.content}`;
|
|
|
46881
47191
|
toolDefinitions: llmTools
|
|
46882
47192
|
});
|
|
46883
47193
|
const messages = preparedStream.messages;
|
|
46884
|
-
|
|
47194
|
+
log17.debug("Context usage for stream", { usagePercent: preparedStream.usage.usagePercent });
|
|
46885
47195
|
const useCompaction = this.llmRouter.isCompactionSupported(this.getEffectiveProvider());
|
|
46886
47196
|
const abortController = new AbortController();
|
|
46887
47197
|
let cancelPollTimer;
|
|
@@ -46930,14 +47240,14 @@ ${chatYield.item.payload.content}`;
|
|
|
46930
47240
|
let streamToolIterations = 0;
|
|
46931
47241
|
while (response.finishReason === "tool_use" && response.toolCalls?.length || response.finishReason === "max_tokens") {
|
|
46932
47242
|
if (++streamToolIterations > this._maxToolIterations) {
|
|
46933
|
-
|
|
47243
|
+
log17.warn("Stream tool loop hit max iterations", {
|
|
46934
47244
|
agentId: this.id,
|
|
46935
47245
|
iterations: streamToolIterations
|
|
46936
47246
|
});
|
|
46937
47247
|
break;
|
|
46938
47248
|
}
|
|
46939
47249
|
if (cancelToken?.cancelled) {
|
|
46940
|
-
|
|
47250
|
+
log17.info("Stream cancelled by user during tool loop", { agentId: this.id });
|
|
46941
47251
|
if (lastResponseContent && this.currentSessionId) {
|
|
46942
47252
|
this.memory.appendMessage(this.currentSessionId, {
|
|
46943
47253
|
role: "assistant",
|
|
@@ -47032,7 +47342,7 @@ ${chatYield.item.payload.content}`;
|
|
|
47032
47342
|
const warningMsg = `[SYSTEM] Loop detected: ${loopCheck.message}. You are repeating the same actions without progress. Try a different approach or stop.`;
|
|
47033
47343
|
this.memory.appendMessage(this.currentSessionId, { role: "user", content: warningMsg });
|
|
47034
47344
|
if (loopCheck.severity === "critical") {
|
|
47035
|
-
|
|
47345
|
+
log17.warn("Stream loop detector: critical pattern \u2014 force-breaking tool loop", {
|
|
47036
47346
|
agentId: this.id,
|
|
47037
47347
|
pattern: loopCheck.pattern
|
|
47038
47348
|
});
|
|
@@ -47062,7 +47372,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47062
47372
|
});
|
|
47063
47373
|
const updatedMessages = preparedCont.messages;
|
|
47064
47374
|
if (cancelToken?.cancelled) {
|
|
47065
|
-
|
|
47375
|
+
log17.info("Stream cancelled before LLM re-call", { agentId: this.id });
|
|
47066
47376
|
if (lastResponseContent && this.currentSessionId) {
|
|
47067
47377
|
this.memory.appendMessage(this.currentSessionId, {
|
|
47068
47378
|
role: "assistant",
|
|
@@ -47156,7 +47466,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47156
47466
|
success: false,
|
|
47157
47467
|
detail: String(error)
|
|
47158
47468
|
});
|
|
47159
|
-
|
|
47469
|
+
log17.error("Failed to handle stream message", { error: String(error) });
|
|
47160
47470
|
throw error;
|
|
47161
47471
|
} finally {
|
|
47162
47472
|
if (cancelPollTimer)
|
|
@@ -47236,7 +47546,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47236
47546
|
}
|
|
47237
47547
|
emit("status", "started", { agentId: this.id, agentName: this.config.name });
|
|
47238
47548
|
if (taskProjectContext) {
|
|
47239
|
-
|
|
47549
|
+
log17.info("Task execution with project context", {
|
|
47240
47550
|
taskId: taskId2,
|
|
47241
47551
|
agentId: this.id,
|
|
47242
47552
|
repos: taskProjectContext.repositories.map((r) => r.localPath)
|
|
@@ -47312,6 +47622,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47312
47622
|
} else {
|
|
47313
47623
|
this.memory.appendMessage(sessionId, { role: "user", content: taskPrompt });
|
|
47314
47624
|
}
|
|
47625
|
+
const cognitiveContext = await this.prepareCognitiveContext("task_execution", taskPrompt);
|
|
47315
47626
|
const systemPrompt = await this.contextEngine.buildSystemPrompt({
|
|
47316
47627
|
agentId: this.id,
|
|
47317
47628
|
agentName: this.config.name,
|
|
@@ -47335,6 +47646,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47335
47646
|
agentDataDir: this.dataDir,
|
|
47336
47647
|
availableSkills: this.availableSkillCatalog,
|
|
47337
47648
|
mailboxContext: this.getMailboxContext(),
|
|
47649
|
+
cognitiveContext,
|
|
47338
47650
|
...this.getTeamContextParams()
|
|
47339
47651
|
});
|
|
47340
47652
|
const llmTools = this.buildToolDefinitions({ userMessage: taskPrompt, isTaskExecution: true });
|
|
@@ -47381,7 +47693,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47381
47693
|
toolDefinitions: llmTools
|
|
47382
47694
|
});
|
|
47383
47695
|
const messages = preparedTask.messages;
|
|
47384
|
-
|
|
47696
|
+
log17.debug("Context usage for task execution", { taskId: taskId2, usagePercent: preparedTask.usage.usagePercent, totalUsed: preparedTask.usage.totalUsed });
|
|
47385
47697
|
let taskLlmStart = Date.now();
|
|
47386
47698
|
let response = await this.withNetworkRetry(() => this.llmRouter.chatStream({ messages, tools: llmTools.length > 0 ? llmTools : void 0, metadata: this.getLLMMetadata(sessionId), compaction: useCompaction }, handleStreamEvent, this.getEffectiveProvider(), abortController.signal), "Task execution LLM call", abortController.signal);
|
|
47387
47699
|
let taskLlmTokens = response.usage.inputTokens + response.usage.outputTokens;
|
|
@@ -47393,7 +47705,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47393
47705
|
if (cancelToken?.cancelled) {
|
|
47394
47706
|
flushText();
|
|
47395
47707
|
emit("status", "cancelled", { reason: "Task execution was stopped externally" });
|
|
47396
|
-
|
|
47708
|
+
log17.info("Task execution cancelled externally", { taskId: taskId2, agentId: this.id });
|
|
47397
47709
|
return;
|
|
47398
47710
|
}
|
|
47399
47711
|
flushText();
|
|
@@ -47415,7 +47727,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47415
47727
|
if (cancelToken?.cancelled)
|
|
47416
47728
|
break;
|
|
47417
47729
|
if (this.attentionController.hasInterruptPending()) {
|
|
47418
|
-
|
|
47730
|
+
log17.info("Attention interrupt pending \u2014 skipping remaining tools", {
|
|
47419
47731
|
agentId: this.id,
|
|
47420
47732
|
taskId: taskId2,
|
|
47421
47733
|
skippedTool: tc.name
|
|
@@ -47440,7 +47752,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47440
47752
|
this.attentionController.clearPreemptionSignal();
|
|
47441
47753
|
let result;
|
|
47442
47754
|
if (raceResult.source === "preempt") {
|
|
47443
|
-
|
|
47755
|
+
log17.info("Tool execution preempted by critical interrupt", {
|
|
47444
47756
|
agentId: this.id,
|
|
47445
47757
|
taskId: taskId2,
|
|
47446
47758
|
tool: tc.name,
|
|
@@ -47496,7 +47808,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47496
47808
|
}
|
|
47497
47809
|
if (cancelToken?.cancelled) {
|
|
47498
47810
|
emit("status", "cancelled", { reason: "Task execution was stopped externally" });
|
|
47499
|
-
|
|
47811
|
+
log17.info("Task execution cancelled externally after tools", { taskId: taskId2, agentId: this.id });
|
|
47500
47812
|
return;
|
|
47501
47813
|
}
|
|
47502
47814
|
this.flushPendingInjections(sessionId);
|
|
@@ -47507,7 +47819,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47507
47819
|
reason: yieldResult.reasoning,
|
|
47508
47820
|
preemptedBy: yieldResult.item?.sourceType
|
|
47509
47821
|
});
|
|
47510
|
-
|
|
47822
|
+
log17.info(`Task ${statusLabel} by higher-priority mailbox item`, {
|
|
47511
47823
|
taskId: taskId2,
|
|
47512
47824
|
agentId: this.id,
|
|
47513
47825
|
decision: yieldResult.decision,
|
|
@@ -47523,7 +47835,7 @@ ${streamYield.item.payload.content}`;
|
|
|
47523
47835
|
|
|
47524
47836
|
${yieldResult.item.payload.content}`
|
|
47525
47837
|
});
|
|
47526
|
-
|
|
47838
|
+
log17.debug("Merged mailbox item into active task session", {
|
|
47527
47839
|
taskId: taskId2,
|
|
47528
47840
|
mergedType: yieldResult.item.sourceType
|
|
47529
47841
|
});
|
|
@@ -47540,7 +47852,7 @@ ${yieldResult.item.payload.content}`
|
|
|
47540
47852
|
"- Use `task_note` to record progress before submitting."
|
|
47541
47853
|
].join("\n")
|
|
47542
47854
|
});
|
|
47543
|
-
|
|
47855
|
+
log17.debug("Injected task completion reminder", { taskId: taskId2, iteration: taskToolIterations });
|
|
47544
47856
|
}
|
|
47545
47857
|
if (taskToolIterations > 0 && taskToolIterations % 30 === 0) {
|
|
47546
47858
|
this.memory.appendMessage(sessionId, {
|
|
@@ -47555,7 +47867,7 @@ ${yieldResult.item.payload.content}`
|
|
|
47555
47867
|
"Then continue with the task."
|
|
47556
47868
|
].join("\n")
|
|
47557
47869
|
});
|
|
47558
|
-
|
|
47870
|
+
log17.debug("Injected mid-execution reflection nudge", { taskId: taskId2, iteration: taskToolIterations });
|
|
47559
47871
|
}
|
|
47560
47872
|
const preparedTaskCont = await this.contextEngine.prepareMessages({
|
|
47561
47873
|
systemPrompt,
|
|
@@ -47582,13 +47894,13 @@ ${yieldResult.item.payload.content}`
|
|
|
47582
47894
|
if (cancelToken?.cancelled) {
|
|
47583
47895
|
flushText();
|
|
47584
47896
|
emit("status", "cancelled", { reason: "Task execution was stopped externally" });
|
|
47585
|
-
|
|
47897
|
+
log17.info("Task execution cancelled externally after completion", { taskId: taskId2, agentId: this.id });
|
|
47586
47898
|
return;
|
|
47587
47899
|
}
|
|
47588
47900
|
const sessionMsgs = this.memory.getRecentMessages(sessionId, 500);
|
|
47589
47901
|
const didSubmitReview = sessionMsgs.some((m) => m.role === "assistant" && m.toolCalls?.some((tc) => tc.name === "task_submit_review"));
|
|
47590
47902
|
if (!didSubmitReview && !cancelToken?.cancelled) {
|
|
47591
|
-
|
|
47903
|
+
log17.warn("Task execution ending without task_submit_review \u2014 injecting final reminder", { taskId: taskId2, agentId: this.id });
|
|
47592
47904
|
flushText();
|
|
47593
47905
|
this.memory.appendMessage(sessionId, { role: "assistant", content: response.content, reasoningContent: response.reasoningContent });
|
|
47594
47906
|
this.memory.appendMessage(sessionId, {
|
|
@@ -47673,12 +47985,12 @@ ${yieldResult.item.payload.content}`
|
|
|
47673
47985
|
emit("status", "execution_finished", {});
|
|
47674
47986
|
this.metricsCollector.recordTaskCompletion(taskId2, "completed", Date.now() - taskStartMs);
|
|
47675
47987
|
this.eventBus.emit("task:completed", { taskId: taskId2, agentId: this.id });
|
|
47676
|
-
|
|
47988
|
+
log17.info("Task execution finished", { taskId: taskId2, agentId: this.id });
|
|
47677
47989
|
} catch (error) {
|
|
47678
47990
|
if (cancelToken?.cancelled) {
|
|
47679
47991
|
flushText();
|
|
47680
47992
|
emit("status", "cancelled", { reason: "Task execution was stopped externally" });
|
|
47681
|
-
|
|
47993
|
+
log17.info("Task execution cancelled (caught abort)", { taskId: taskId2, agentId: this.id });
|
|
47682
47994
|
return;
|
|
47683
47995
|
}
|
|
47684
47996
|
if (textBuffer.trim()) {
|
|
@@ -47696,7 +48008,7 @@ ${yieldResult.item.payload.content}`
|
|
|
47696
48008
|
success: false,
|
|
47697
48009
|
detail: String(error)
|
|
47698
48010
|
});
|
|
47699
|
-
|
|
48011
|
+
log17.error("Task execution failed", { taskId: taskId2, agentId: this.id, error: String(error) });
|
|
47700
48012
|
this.eventBus.emit("task:failed", { taskId: taskId2, agentId: this.id, error: String(error) });
|
|
47701
48013
|
taskFailed = String(error);
|
|
47702
48014
|
throw error;
|
|
@@ -47744,6 +48056,7 @@ ${yieldResult.item.payload.content}`
|
|
|
47744
48056
|
const emitDelta = markerDeltaRIS.emit;
|
|
47745
48057
|
this.memory.getOrCreateSession(this.id, sessionId);
|
|
47746
48058
|
this.memory.appendMessage(sessionId, { role: "user", content: userMessage });
|
|
48059
|
+
const cognitiveContext = await this.prepareCognitiveContext("chat", userMessage);
|
|
47747
48060
|
const systemPrompt = await this.contextEngine.buildSystemPrompt({
|
|
47748
48061
|
agentId: this.id,
|
|
47749
48062
|
agentName: this.config.name,
|
|
@@ -47766,6 +48079,7 @@ ${yieldResult.item.payload.content}`
|
|
|
47766
48079
|
agentDataDir: this.dataDir,
|
|
47767
48080
|
availableSkills: this.availableSkillCatalog,
|
|
47768
48081
|
mailboxContext: this.getMailboxContext(),
|
|
48082
|
+
cognitiveContext,
|
|
47769
48083
|
...this.getTeamContextParams()
|
|
47770
48084
|
});
|
|
47771
48085
|
const llmTools = this.buildToolDefinitions({ userMessage });
|
|
@@ -48071,7 +48385,7 @@ ${d.text}
|
|
|
48071
48385
|
try {
|
|
48072
48386
|
const installArgs = { ...args, name: skillName };
|
|
48073
48387
|
const result2 = await this.skillInstaller(installArgs);
|
|
48074
|
-
|
|
48388
|
+
log17.info("Skill installed via discover_tools", { agentId: this.id, skill: skillName, method: result2.method });
|
|
48075
48389
|
return JSON.stringify({
|
|
48076
48390
|
status: "ok",
|
|
48077
48391
|
installed: result2.name,
|
|
@@ -48109,7 +48423,7 @@ ${d.text}
|
|
|
48109
48423
|
this.activateTools(toolNames);
|
|
48110
48424
|
mcpToolCount = mcpTools.length;
|
|
48111
48425
|
} catch (err) {
|
|
48112
|
-
|
|
48426
|
+
log17.warn("Failed to activate skill MCP servers via discover_tools", {
|
|
48113
48427
|
agentId: this.id,
|
|
48114
48428
|
skill: name,
|
|
48115
48429
|
error: String(err)
|
|
@@ -48124,7 +48438,7 @@ ${d.text}
|
|
|
48124
48438
|
if (!skill.manifest.instructions && mcpToolCount === 0)
|
|
48125
48439
|
parts.push("skill found but has no instructions or MCP tools");
|
|
48126
48440
|
activated.push(parts.length > 1 ? `${parts[0]} (${parts.slice(1).join(", ")})` : parts[0]);
|
|
48127
|
-
|
|
48441
|
+
log17.info("Skill activated via discover_tools", {
|
|
48128
48442
|
agentId: this.id,
|
|
48129
48443
|
skill: name,
|
|
48130
48444
|
mcpToolCount,
|
|
@@ -48184,7 +48498,7 @@ ${body}`;
|
|
|
48184
48498
|
taskId: taskId2,
|
|
48185
48499
|
requirementId: requirementId2
|
|
48186
48500
|
});
|
|
48187
|
-
|
|
48501
|
+
log17.info("User notification sent", { agentId: this.id, title });
|
|
48188
48502
|
return JSON.stringify({ status: "ok", message: "Notification sent to user." });
|
|
48189
48503
|
} catch (err) {
|
|
48190
48504
|
return JSON.stringify({ status: "error", message: `Failed to send notification: ${String(err)}` });
|
|
@@ -48216,7 +48530,7 @@ ${body}`;
|
|
|
48216
48530
|
priority,
|
|
48217
48531
|
relatedTaskId
|
|
48218
48532
|
});
|
|
48219
|
-
|
|
48533
|
+
log17.info("User approval response received", { agentId: this.id, title, approved: result.approved, selectedOption: result.selectedOption });
|
|
48220
48534
|
return JSON.stringify({
|
|
48221
48535
|
status: "ok",
|
|
48222
48536
|
approved: result.approved,
|
|
@@ -48248,7 +48562,7 @@ ${body}`;
|
|
|
48248
48562
|
const needsApproval = this.config.profile?.requireApprovalFor?.some((pattern) => toolCall.name === pattern || toolCall.name.startsWith(pattern.replace("*", "")));
|
|
48249
48563
|
if (needsApproval) {
|
|
48250
48564
|
if (this.approvalCallback) {
|
|
48251
|
-
|
|
48565
|
+
log17.info(`Tool ${toolCall.name} requires approval, requesting...`, { agentId: this.id });
|
|
48252
48566
|
const result = await this.approvalCallback({
|
|
48253
48567
|
agentId: this.id,
|
|
48254
48568
|
agentName: this.config.name,
|
|
@@ -48259,15 +48573,15 @@ ${body}`;
|
|
|
48259
48573
|
});
|
|
48260
48574
|
if (!result.approved) {
|
|
48261
48575
|
const reason = result.comment ? `: ${result.comment}` : "";
|
|
48262
|
-
|
|
48576
|
+
log17.info(`Tool ${toolCall.name} execution denied by human`, { agentId: this.id });
|
|
48263
48577
|
return JSON.stringify({
|
|
48264
48578
|
status: "denied",
|
|
48265
48579
|
error: `Execution of '${toolCall.name}' was denied by human reviewer${reason}`
|
|
48266
48580
|
});
|
|
48267
48581
|
}
|
|
48268
|
-
|
|
48582
|
+
log17.info(`Tool ${toolCall.name} approved by human`, { agentId: this.id });
|
|
48269
48583
|
} else {
|
|
48270
|
-
|
|
48584
|
+
log17.warn(`Tool ${toolCall.name} requires approval but no approval callback set`, {
|
|
48271
48585
|
agentId: this.id
|
|
48272
48586
|
});
|
|
48273
48587
|
}
|
|
@@ -48309,10 +48623,10 @@ ${body}`;
|
|
|
48309
48623
|
try {
|
|
48310
48624
|
if (attempt > 0) {
|
|
48311
48625
|
const delay = _Agent.TOOL_RETRY_BASE_MS * Math.pow(2, attempt - 1);
|
|
48312
|
-
|
|
48626
|
+
log17.info(`Retrying tool ${toolCall.name} (attempt ${attempt + 1})`, { delay });
|
|
48313
48627
|
await new Promise((r) => setTimeout(r, delay));
|
|
48314
48628
|
}
|
|
48315
|
-
|
|
48629
|
+
log17.debug(`Executing tool: ${toolCall.name}`, { args: effectiveArgs, attempt });
|
|
48316
48630
|
const span = startSpan("agent.tool", { tool: toolCall.name, attempt });
|
|
48317
48631
|
try {
|
|
48318
48632
|
const result = await handler4.execute(effectiveArgs, onOutput);
|
|
@@ -48335,7 +48649,7 @@ ${body}`;
|
|
|
48335
48649
|
}
|
|
48336
48650
|
} catch (error) {
|
|
48337
48651
|
lastError = error;
|
|
48338
|
-
|
|
48652
|
+
log17.error(`Tool execution failed: ${toolCall.name} (attempt ${attempt + 1})`, {
|
|
48339
48653
|
error: String(error)
|
|
48340
48654
|
});
|
|
48341
48655
|
}
|
|
@@ -48347,7 +48661,7 @@ ${body}`;
|
|
|
48347
48661
|
handleFailure(reason) {
|
|
48348
48662
|
this.consecutiveFailures++;
|
|
48349
48663
|
if (this.consecutiveFailures >= _Agent.MAX_CONSECUTIVE_FAILURES) {
|
|
48350
|
-
|
|
48664
|
+
log17.warn("Consecutive failure threshold reached, escalating to human", {
|
|
48351
48665
|
agentId: this.id,
|
|
48352
48666
|
failures: this.consecutiveFailures
|
|
48353
48667
|
});
|
|
@@ -48393,7 +48707,7 @@ ${escalationReason}`;
|
|
|
48393
48707
|
throw error;
|
|
48394
48708
|
}
|
|
48395
48709
|
const delay = _Agent.NETWORK_RETRY_BASE_MS * Math.pow(2, attempt);
|
|
48396
|
-
|
|
48710
|
+
log17.warn(`${label} failed with network error, retrying (${attempt + 1}/${_Agent.NETWORK_RETRY_MAX})`, {
|
|
48397
48711
|
agentId: this.id,
|
|
48398
48712
|
error: String(error).slice(0, 200),
|
|
48399
48713
|
delay
|
|
@@ -48417,7 +48731,7 @@ ${escalationReason}`;
|
|
|
48417
48731
|
}
|
|
48418
48732
|
}
|
|
48419
48733
|
async handleHeartbeat(ctx) {
|
|
48420
|
-
|
|
48734
|
+
log17.info("Processing heartbeat check-in");
|
|
48421
48735
|
const activityId = this.startActivity("heartbeat", "Heartbeat check-in", {});
|
|
48422
48736
|
let lastHeartbeatSummary = "";
|
|
48423
48737
|
try {
|
|
@@ -48675,7 +48989,7 @@ ${todayLog.slice(0, HEARTBEAT_DAILY_LOG_CHARS)}
|
|
|
48675
48989
|
lastError = error;
|
|
48676
48990
|
if (attempt < HEARTBEAT_MAX_RETRIES) {
|
|
48677
48991
|
const delay = HEARTBEAT_RETRY_BASE_MS * Math.pow(2, attempt);
|
|
48678
|
-
|
|
48992
|
+
log17.warn(`Heartbeat attempt ${attempt + 1}/${HEARTBEAT_MAX_RETRIES + 1} failed, retrying in ${delay}ms`, {
|
|
48679
48993
|
agentId: this.id,
|
|
48680
48994
|
error: String(error).slice(0, 200)
|
|
48681
48995
|
});
|
|
@@ -48686,7 +49000,7 @@ ${todayLog.slice(0, HEARTBEAT_DAILY_LOG_CHARS)}
|
|
|
48686
49000
|
this.emitActivityLog(activityId, "error", String(lastError));
|
|
48687
49001
|
this.endActivity(activityId);
|
|
48688
49002
|
this.metricsCollector.recordHeartbeat(false);
|
|
48689
|
-
|
|
49003
|
+
log17.error("Heartbeat failed after all retries", {
|
|
48690
49004
|
agentId: this.id,
|
|
48691
49005
|
attempts: HEARTBEAT_MAX_RETRIES + 1,
|
|
48692
49006
|
error: String(lastError)
|
|
@@ -48724,9 +49038,9 @@ ${todayLog.slice(0, HEARTBEAT_DAILY_LOG_CHARS)}
|
|
|
48724
49038
|
sessionId: `sys_${this.id}_${Date.now()}`,
|
|
48725
49039
|
scenario: "heartbeat"
|
|
48726
49040
|
});
|
|
48727
|
-
|
|
49041
|
+
log17.info("Memory flush completed before compaction", { agentId: this.id, sessionId });
|
|
48728
49042
|
} catch (error) {
|
|
48729
|
-
|
|
49043
|
+
log17.warn("Memory flush failed, proceeding with compaction anyway", { error: String(error) });
|
|
48730
49044
|
}
|
|
48731
49045
|
}
|
|
48732
49046
|
/**
|
|
@@ -48744,9 +49058,9 @@ ${todayLog.slice(0, HEARTBEAT_DAILY_LOG_CHARS)}
|
|
|
48744
49058
|
await this.dreamConsolidateMemory(entries2);
|
|
48745
49059
|
this.pruneMemoryMd();
|
|
48746
49060
|
}
|
|
48747
|
-
|
|
49061
|
+
log17.debug("Memory consolidation completed", { agentId: this.id });
|
|
48748
49062
|
} catch (error) {
|
|
48749
|
-
|
|
49063
|
+
log17.warn("Memory consolidation failed", { agentId: this.id, error: String(error) });
|
|
48750
49064
|
}
|
|
48751
49065
|
}
|
|
48752
49066
|
/**
|
|
@@ -48762,7 +49076,7 @@ ${todayLog.slice(0, HEARTBEAT_DAILY_LOG_CHARS)}
|
|
|
48762
49076
|
return `[${i}] id=${e.id} type=${e.type} date=${e.timestamp?.slice(0, 10) ?? "?"}${tags}
|
|
48763
49077
|
${e.content.slice(0, 200)}`;
|
|
48764
49078
|
}).join("\n\n");
|
|
48765
|
-
|
|
49079
|
+
log17.info("Dream cycle starting", {
|
|
48766
49080
|
agentId: this.id,
|
|
48767
49081
|
totalEntries: entries2.length,
|
|
48768
49082
|
batchSize: batch.length,
|
|
@@ -48821,7 +49135,7 @@ ${knowledgePreview}
|
|
|
48821
49135
|
});
|
|
48822
49136
|
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
48823
49137
|
if (!jsonMatch) {
|
|
48824
|
-
|
|
49138
|
+
log17.debug("Dream cycle: no valid JSON in response, skipping");
|
|
48825
49139
|
return;
|
|
48826
49140
|
}
|
|
48827
49141
|
const rawPlan = JSON.parse(jsonMatch[0]);
|
|
@@ -48834,12 +49148,12 @@ ${knowledgePreview}
|
|
|
48834
49148
|
promote: (rawPlan.promote ?? []).filter((p) => p.sourceIds.every((id) => entryIds.has(id)) && p.content?.length > 0 && p.section?.length > 0).slice(0, MAX_MERGE_PER_CYCLE)
|
|
48835
49149
|
};
|
|
48836
49150
|
if ((rawPlan.remove?.length ?? 0) > MAX_REMOVE_PER_CYCLE) {
|
|
48837
|
-
|
|
49151
|
+
log17.warn("Dream cycle: remove list truncated", {
|
|
48838
49152
|
requested: rawPlan.remove.length,
|
|
48839
49153
|
cap: MAX_REMOVE_PER_CYCLE
|
|
48840
49154
|
});
|
|
48841
49155
|
}
|
|
48842
|
-
|
|
49156
|
+
log17.info("Dream cycle plan (audited)", {
|
|
48843
49157
|
agentId: this.id,
|
|
48844
49158
|
toRemove: plan.remove.length,
|
|
48845
49159
|
toMerge: plan.merge.length,
|
|
@@ -48900,7 +49214,7 @@ ${promo.content}` : promo.content;
|
|
|
48900
49214
|
}
|
|
48901
49215
|
}
|
|
48902
49216
|
promotedCount++;
|
|
48903
|
-
|
|
49217
|
+
log17.debug("Dream cycle: promoted pattern to MEMORY.md", {
|
|
48904
49218
|
section: section4,
|
|
48905
49219
|
sourceCount: promo.sourceIds.length,
|
|
48906
49220
|
removed,
|
|
@@ -48909,7 +49223,7 @@ ${promo.content}` : promo.content;
|
|
|
48909
49223
|
}
|
|
48910
49224
|
}
|
|
48911
49225
|
if (removedCount > 0 || mergedCount > 0 || promotedCount > 0) {
|
|
48912
|
-
|
|
49226
|
+
log17.info("Dream cycle completed", {
|
|
48913
49227
|
agentId: this.id,
|
|
48914
49228
|
entriesBefore: entries2.length,
|
|
48915
49229
|
removed: removedCount,
|
|
@@ -48918,10 +49232,10 @@ ${promo.content}` : promo.content;
|
|
|
48918
49232
|
entriesAfter: this.memory.getEntries().length
|
|
48919
49233
|
});
|
|
48920
49234
|
} else {
|
|
48921
|
-
|
|
49235
|
+
log17.debug("Dream cycle: no changes needed", { agentId: this.id });
|
|
48922
49236
|
}
|
|
48923
49237
|
} catch (error) {
|
|
48924
|
-
|
|
49238
|
+
log17.warn("Dream cycle failed", { agentId: this.id, error: String(error) });
|
|
48925
49239
|
}
|
|
48926
49240
|
}
|
|
48927
49241
|
/**
|
|
@@ -48964,7 +49278,7 @@ ${promo.content}` : promo.content;
|
|
|
48964
49278
|
if (pruned !== content.trim()) {
|
|
48965
49279
|
const memoryMdPath = join9(this.dataDir, "MEMORY.md");
|
|
48966
49280
|
writeFileSync8(memoryMdPath, pruned + "\n");
|
|
48967
|
-
|
|
49281
|
+
log17.info("Pruned MEMORY.md: removed daily-report sections and LLM artifacts", { agentId: this.id });
|
|
48968
49282
|
}
|
|
48969
49283
|
}
|
|
48970
49284
|
};
|
|
@@ -49122,12 +49436,12 @@ ${sharedContent}` : roleContent;
|
|
|
49122
49436
|
|
|
49123
49437
|
// ../core/dist/tools/mcp-client.js
|
|
49124
49438
|
import { spawn as spawn3 } from "node:child_process";
|
|
49125
|
-
var
|
|
49439
|
+
var log18, MCPClientManager;
|
|
49126
49440
|
var init_mcp_client = __esm({
|
|
49127
49441
|
"../core/dist/tools/mcp-client.js"() {
|
|
49128
49442
|
"use strict";
|
|
49129
49443
|
init_dist();
|
|
49130
|
-
|
|
49444
|
+
log18 = createLogger("mcp-client");
|
|
49131
49445
|
MCPClientManager = class _MCPClientManager {
|
|
49132
49446
|
servers = /* @__PURE__ */ new Map();
|
|
49133
49447
|
requestId = 0;
|
|
@@ -49143,32 +49457,32 @@ var init_mcp_client = __esm({
|
|
|
49143
49457
|
async connectByKey(key2, displayName, config) {
|
|
49144
49458
|
const existing = this.servers.get(key2);
|
|
49145
49459
|
if (existing) {
|
|
49146
|
-
|
|
49460
|
+
log18.info(`MCP server ${displayName} already connected, reusing (${existing.tools.length} tools)`);
|
|
49147
49461
|
return existing.tools;
|
|
49148
49462
|
}
|
|
49149
|
-
|
|
49463
|
+
log18.info(`Connecting to MCP server: ${displayName}`, { command: config.command, key: key2 });
|
|
49150
49464
|
const proc = spawn3(config.command, config.args ?? [], {
|
|
49151
49465
|
stdio: ["pipe", "pipe", "pipe"],
|
|
49152
49466
|
env: { ...process.env, ...config.env },
|
|
49153
49467
|
shell: process.platform === "win32"
|
|
49154
49468
|
});
|
|
49155
49469
|
proc.on("error", (err) => {
|
|
49156
|
-
|
|
49470
|
+
log18.error(`MCP server ${displayName} error`, { error: String(err) });
|
|
49157
49471
|
});
|
|
49158
49472
|
const stderrChunks = [];
|
|
49159
49473
|
proc.stderr?.on("data", (data) => {
|
|
49160
49474
|
const text = data.toString();
|
|
49161
49475
|
stderrChunks.push(text);
|
|
49162
49476
|
if (stderrChunks.length <= 5) {
|
|
49163
|
-
|
|
49477
|
+
log18.warn(`MCP server ${displayName} stderr`, { text: text.trimEnd() });
|
|
49164
49478
|
}
|
|
49165
49479
|
});
|
|
49166
49480
|
proc.on("exit", (code) => {
|
|
49167
49481
|
const stderr = stderrChunks.join("").trim();
|
|
49168
49482
|
if (stderr) {
|
|
49169
|
-
|
|
49483
|
+
log18.error(`MCP server ${displayName} exited with stderr`, { code, stderr: stderr.slice(0, 500) });
|
|
49170
49484
|
} else {
|
|
49171
|
-
|
|
49485
|
+
log18.info(`MCP server ${displayName} exited`, { code });
|
|
49172
49486
|
}
|
|
49173
49487
|
this.servers.delete(key2);
|
|
49174
49488
|
this.stdoutBuffers.delete(proc);
|
|
@@ -49192,7 +49506,7 @@ var init_mcp_client = __esm({
|
|
|
49192
49506
|
const toolsResult = await this.sendRequest(proc, "tools/list", {});
|
|
49193
49507
|
const tools = toolsResult?.tools ?? [];
|
|
49194
49508
|
this.servers.set(key2, { process: proc, tools });
|
|
49195
|
-
|
|
49509
|
+
log18.info(`MCP server ${displayName} connected with ${tools.length} tools`);
|
|
49196
49510
|
return tools;
|
|
49197
49511
|
} catch (err) {
|
|
49198
49512
|
proc.kill();
|
|
@@ -49267,7 +49581,7 @@ var init_mcp_client = __esm({
|
|
|
49267
49581
|
server.process.kill();
|
|
49268
49582
|
this.servers.delete(name);
|
|
49269
49583
|
this.stdoutBuffers.delete(server.process);
|
|
49270
|
-
|
|
49584
|
+
log18.info(`MCP server disconnected: ${name}`);
|
|
49271
49585
|
}
|
|
49272
49586
|
}
|
|
49273
49587
|
async disconnectServerScoped(name, scopeId) {
|
|
@@ -49344,12 +49658,12 @@ var init_mcp_client = __esm({
|
|
|
49344
49658
|
});
|
|
49345
49659
|
|
|
49346
49660
|
// ../core/dist/tools/browser-session.js
|
|
49347
|
-
var
|
|
49661
|
+
var log19, SESSION_KEY, BrowserSessionManager;
|
|
49348
49662
|
var init_browser_session = __esm({
|
|
49349
49663
|
"../core/dist/tools/browser-session.js"() {
|
|
49350
49664
|
"use strict";
|
|
49351
49665
|
init_dist();
|
|
49352
|
-
|
|
49666
|
+
log19 = createLogger("browser-session");
|
|
49353
49667
|
SESSION_KEY = "_browserSessionId";
|
|
49354
49668
|
BrowserSessionManager = class {
|
|
49355
49669
|
/**
|
|
@@ -49437,7 +49751,7 @@ var init_browser_session = __esm({
|
|
|
49437
49751
|
await selectHandler.execute({ pageId, bringToFront: this._bringToFront });
|
|
49438
49752
|
this.lastActiveSession.set(agentId2, { ownerKey, pageId });
|
|
49439
49753
|
} catch (err) {
|
|
49440
|
-
|
|
49754
|
+
log19.warn(`Auto-select page ${pageId} failed for ${ownerKey}: ${err}`);
|
|
49441
49755
|
}
|
|
49442
49756
|
}
|
|
49443
49757
|
extractOwnerKey(agentId2, args) {
|
|
@@ -49540,9 +49854,9 @@ var init_browser_session = __esm({
|
|
|
49540
49854
|
owned.add(newPage.id);
|
|
49541
49855
|
this.currentPage.set(ownerKey, newPage.id);
|
|
49542
49856
|
this.lastActiveSession.set(agentId2, { ownerKey, pageId: newPage.id });
|
|
49543
|
-
|
|
49857
|
+
log19.debug(`Page ${newPage.id} (${newPage.url}) assigned to ${ownerKey}`);
|
|
49544
49858
|
} else {
|
|
49545
|
-
|
|
49859
|
+
log19.warn(`new_page response contained no pages for ${ownerKey}`);
|
|
49546
49860
|
}
|
|
49547
49861
|
return this.annotateResponse(result, ownerKey);
|
|
49548
49862
|
});
|
|
@@ -49568,7 +49882,7 @@ var init_browser_session = __esm({
|
|
|
49568
49882
|
const pageId = typeof args.pageId === "number" ? args.pageId : void 0;
|
|
49569
49883
|
if (pageId !== void 0 && !this.getOwned(ownerKey).has(pageId)) {
|
|
49570
49884
|
const msg = `Cannot select page ${pageId}: it is NOT your tab. ${this.ownedPagesSummary(ownerKey)}`;
|
|
49571
|
-
|
|
49885
|
+
log19.warn(msg, { ownerKey, pageId });
|
|
49572
49886
|
return JSON.stringify({ error: msg });
|
|
49573
49887
|
}
|
|
49574
49888
|
if (args.bringToFront === void 0) {
|
|
@@ -49593,7 +49907,7 @@ var init_browser_session = __esm({
|
|
|
49593
49907
|
const pageId = typeof args.pageId === "number" ? args.pageId : void 0;
|
|
49594
49908
|
if (pageId !== void 0 && !this.getOwned(ownerKey).has(pageId)) {
|
|
49595
49909
|
const msg = `Cannot close page ${pageId}: it is NOT your tab -- do not close tabs you did not create. ${this.ownedPagesSummary(ownerKey)}`;
|
|
49596
|
-
|
|
49910
|
+
log19.warn(msg, { ownerKey, pageId });
|
|
49597
49911
|
return JSON.stringify({ error: msg });
|
|
49598
49912
|
}
|
|
49599
49913
|
return this.withAgentLock(agentId2, async () => {
|
|
@@ -49632,15 +49946,15 @@ var init_browser_session = __esm({
|
|
|
49632
49946
|
const url = args.url;
|
|
49633
49947
|
if (!url) {
|
|
49634
49948
|
const msg = "Cannot navigate: you have no owned tabs and no URL provided. Call new_page first or provide a URL.";
|
|
49635
|
-
|
|
49949
|
+
log19.warn(msg, { ownerKey });
|
|
49636
49950
|
return JSON.stringify({ error: msg });
|
|
49637
49951
|
}
|
|
49638
49952
|
if (!newPageHandler) {
|
|
49639
49953
|
const msg = "No owned pages and new_page tool unavailable. Cannot navigate safely.";
|
|
49640
|
-
|
|
49954
|
+
log19.error(msg, { ownerKey });
|
|
49641
49955
|
return JSON.stringify({ error: msg });
|
|
49642
49956
|
}
|
|
49643
|
-
|
|
49957
|
+
log19.info(`Session ${ownerKey} called navigate_page with no owned pages -- auto-creating via new_page`, { url });
|
|
49644
49958
|
return this.withAgentLock(agentId2, async () => {
|
|
49645
49959
|
const newPageArgs = { url, background: !this._bringToFront };
|
|
49646
49960
|
if (args.timeout)
|
|
@@ -49654,14 +49968,14 @@ var init_browser_session = __esm({
|
|
|
49654
49968
|
owned.add(newPage.id);
|
|
49655
49969
|
this.currentPage.set(ownerKey, newPage.id);
|
|
49656
49970
|
this.lastActiveSession.set(agentId2, { ownerKey, pageId: newPage.id });
|
|
49657
|
-
|
|
49971
|
+
log19.info(`Auto-created page ${newPage.id} (${newPage.url}) for ${ownerKey}`);
|
|
49658
49972
|
} else {
|
|
49659
|
-
|
|
49973
|
+
log19.warn(`Auto-created page but could not determine its ID for ${ownerKey}`);
|
|
49660
49974
|
}
|
|
49661
49975
|
return this.annotateResponse(result, ownerKey);
|
|
49662
49976
|
} catch (err) {
|
|
49663
49977
|
const msg = `Failed to auto-create new tab: ${err}`;
|
|
49664
|
-
|
|
49978
|
+
log19.error(msg, { ownerKey });
|
|
49665
49979
|
return JSON.stringify({ error: msg });
|
|
49666
49980
|
}
|
|
49667
49981
|
});
|
|
@@ -49686,13 +50000,13 @@ var init_browser_session = __esm({
|
|
|
49686
50000
|
const owned = this.getOwned(ownerKey);
|
|
49687
50001
|
if (owned.size === 0) {
|
|
49688
50002
|
const msg = `Cannot use ${toolName}: you have no owned tabs yet. Call navigate_page (auto-creates a tab) or new_page first.`;
|
|
49689
|
-
|
|
50003
|
+
log19.warn(`${ownerKey} called ${toolName} with no owned pages`);
|
|
49690
50004
|
return JSON.stringify({ error: msg });
|
|
49691
50005
|
}
|
|
49692
50006
|
const pageId = typeof args.pageId === "number" ? args.pageId : void 0;
|
|
49693
50007
|
if (pageId !== void 0 && !owned.has(pageId)) {
|
|
49694
50008
|
const msg = `Cannot use ${toolName} on page ${pageId}: it is NOT your tab. ${this.ownedPagesSummary(ownerKey)}`;
|
|
49695
|
-
|
|
50009
|
+
log19.warn(msg, { ownerKey, pageId, toolName });
|
|
49696
50010
|
return JSON.stringify({ error: msg });
|
|
49697
50011
|
}
|
|
49698
50012
|
return this.withAgentLock(agentId2, async () => {
|
|
@@ -49721,7 +50035,7 @@ var init_browser_session = __esm({
|
|
|
49721
50035
|
this.selectPageHandlers.delete(agentId2);
|
|
49722
50036
|
this.lastActiveSession.delete(agentId2);
|
|
49723
50037
|
if (total > 0) {
|
|
49724
|
-
|
|
50038
|
+
log19.info(`Cleaning up ${total} browser page(s) for agent ${agentId2}`);
|
|
49725
50039
|
}
|
|
49726
50040
|
}
|
|
49727
50041
|
};
|
|
@@ -49770,7 +50084,7 @@ function createManagerTools(ctx) {
|
|
|
49770
50084
|
const targetId = args["agent_id"];
|
|
49771
50085
|
const message = args["message"];
|
|
49772
50086
|
ctx.delegateMessage(targetId, message, "manager").catch((err) => {
|
|
49773
|
-
|
|
50087
|
+
log20.warn(`Delegated task to ${targetId} failed in background`, { error: String(err) });
|
|
49774
50088
|
});
|
|
49775
50089
|
return JSON.stringify({ status: "dispatched", message: "Task dispatched. The agent will work on it independently." });
|
|
49776
50090
|
}
|
|
@@ -50030,12 +50344,12 @@ function createManagerTools(ctx) {
|
|
|
50030
50344
|
] : []
|
|
50031
50345
|
];
|
|
50032
50346
|
}
|
|
50033
|
-
var
|
|
50347
|
+
var log20;
|
|
50034
50348
|
var init_manager = __esm({
|
|
50035
50349
|
"../core/dist/tools/manager.js"() {
|
|
50036
50350
|
"use strict";
|
|
50037
50351
|
init_dist();
|
|
50038
|
-
|
|
50352
|
+
log20 = createLogger("manager-tools");
|
|
50039
50353
|
}
|
|
50040
50354
|
});
|
|
50041
50355
|
|
|
@@ -50144,19 +50458,19 @@ function createA2ATools(ctx) {
|
|
|
50144
50458
|
return JSON.stringify({ status: "error", error: "Cannot send a message to yourself" });
|
|
50145
50459
|
}
|
|
50146
50460
|
if (waitForReply) {
|
|
50147
|
-
|
|
50461
|
+
log21.info(`A2A request (sync): ${ctx.selfName} \u2192 ${targetId}`, { messageLen: message.length });
|
|
50148
50462
|
try {
|
|
50149
|
-
const reply = await ctx.sendMessage(targetId, message, ctx.selfId, ctx.selfName, 0);
|
|
50150
|
-
|
|
50463
|
+
const reply = await ctx.sendMessage(targetId, message, ctx.selfId, ctx.selfName, 0, true);
|
|
50464
|
+
log21.info(`A2A reply received: ${targetId} \u2192 ${ctx.selfName}`, { replyLen: reply.length });
|
|
50151
50465
|
return JSON.stringify({ status: "replied", from: targetId, reply });
|
|
50152
50466
|
} catch (err) {
|
|
50153
|
-
|
|
50467
|
+
log21.warn(`A2A sync message to ${targetId} failed`, { error: String(err) });
|
|
50154
50468
|
return JSON.stringify({ status: "error", error: `Failed to get reply: ${String(err)}` });
|
|
50155
50469
|
}
|
|
50156
50470
|
}
|
|
50157
|
-
|
|
50158
|
-
ctx.sendMessage(targetId, message, ctx.selfId, ctx.selfName).catch((err) => {
|
|
50159
|
-
|
|
50471
|
+
log21.info(`A2A notify (async): ${ctx.selfName} \u2192 ${targetId}`, { messageLen: message.length });
|
|
50472
|
+
ctx.sendMessage(targetId, message, ctx.selfId, ctx.selfName, void 0, false).catch((err) => {
|
|
50473
|
+
log21.warn(`A2A async message to ${targetId} failed in background`, { error: String(err) });
|
|
50160
50474
|
});
|
|
50161
50475
|
return JSON.stringify({ status: "dispatched", message: "Notification sent. The agent will process it independently." });
|
|
50162
50476
|
}
|
|
@@ -50293,12 +50607,12 @@ function createA2ATools(ctx) {
|
|
|
50293
50607
|
}] : []
|
|
50294
50608
|
];
|
|
50295
50609
|
}
|
|
50296
|
-
var
|
|
50610
|
+
var log21;
|
|
50297
50611
|
var init_a2a = __esm({
|
|
50298
50612
|
"../core/dist/tools/a2a.js"() {
|
|
50299
50613
|
"use strict";
|
|
50300
50614
|
init_dist();
|
|
50301
|
-
|
|
50615
|
+
log21 = createLogger("a2a-tools");
|
|
50302
50616
|
}
|
|
50303
50617
|
});
|
|
50304
50618
|
|
|
@@ -50325,15 +50639,15 @@ function createStructuredA2ATools(ctx) {
|
|
|
50325
50639
|
}
|
|
50326
50640
|
};
|
|
50327
50641
|
const message = JSON.stringify(structuredMessage);
|
|
50328
|
-
|
|
50642
|
+
log22.info(`Structured A2A message dispatched: ${ctx.selfName} \u2192 ${targetId}`, {
|
|
50329
50643
|
messageType,
|
|
50330
50644
|
payloadSize: JSON.stringify(payload).length
|
|
50331
50645
|
});
|
|
50332
50646
|
enqueueSend(async () => {
|
|
50333
50647
|
try {
|
|
50334
|
-
await ctx.sendMessage(targetId, message, ctx.selfId, ctx.selfName);
|
|
50648
|
+
await ctx.sendMessage(targetId, message, ctx.selfId, ctx.selfName, void 0, false);
|
|
50335
50649
|
} catch (err) {
|
|
50336
|
-
|
|
50650
|
+
log22.warn(`Structured A2A message to ${targetId} failed in background`, {
|
|
50337
50651
|
error: String(err),
|
|
50338
50652
|
messageType
|
|
50339
50653
|
});
|
|
@@ -50427,12 +50741,12 @@ function createStructuredA2ATools(ctx) {
|
|
|
50427
50741
|
}
|
|
50428
50742
|
];
|
|
50429
50743
|
}
|
|
50430
|
-
var
|
|
50744
|
+
var log22, A2A_SEND_INTERVAL_MS, sendQueue;
|
|
50431
50745
|
var init_a2a_structured = __esm({
|
|
50432
50746
|
"../core/dist/tools/a2a-structured.js"() {
|
|
50433
50747
|
"use strict";
|
|
50434
50748
|
init_dist();
|
|
50435
|
-
|
|
50749
|
+
log22 = createLogger("a2a-structured-tools");
|
|
50436
50750
|
A2A_SEND_INTERVAL_MS = 3e4;
|
|
50437
50751
|
sendQueue = Promise.resolve();
|
|
50438
50752
|
}
|
|
@@ -50562,7 +50876,7 @@ function createAgentTaskTools(ctx) {
|
|
|
50562
50876
|
taskType,
|
|
50563
50877
|
scheduleConfig
|
|
50564
50878
|
});
|
|
50565
|
-
|
|
50879
|
+
log23.info(`Task created by agent ${ctx.agentId}`, { taskId: task.id, title: task.title, assignedAgentId });
|
|
50566
50880
|
if (task.status === "pending") {
|
|
50567
50881
|
return JSON.stringify({
|
|
50568
50882
|
status: "pending",
|
|
@@ -50576,7 +50890,7 @@ function createAgentTaskTools(ctx) {
|
|
|
50576
50890
|
message: `Task created: "${task.title}" (ID: ${task.id})`
|
|
50577
50891
|
});
|
|
50578
50892
|
} catch (error) {
|
|
50579
|
-
|
|
50893
|
+
log23.error("task_create failed", { error: String(error) });
|
|
50580
50894
|
return JSON.stringify({ status: "error", error: String(error) });
|
|
50581
50895
|
}
|
|
50582
50896
|
}
|
|
@@ -50808,7 +51122,7 @@ function createAgentTaskTools(ctx) {
|
|
|
50808
51122
|
await ctx.addTaskNote(task2.id, note, ctx.agentName).catch(() => {
|
|
50809
51123
|
});
|
|
50810
51124
|
}
|
|
50811
|
-
|
|
51125
|
+
log23.info(`Pending task cancelled by creator ${ctx.agentId}`, { taskId: task2.id });
|
|
50812
51126
|
return JSON.stringify({
|
|
50813
51127
|
status: "success",
|
|
50814
51128
|
task: task2,
|
|
@@ -50821,7 +51135,7 @@ function createAgentTaskTools(ctx) {
|
|
|
50821
51135
|
});
|
|
50822
51136
|
}
|
|
50823
51137
|
if (existing?.assignedAgentId === ctx.agentId && existing?.status === "in_progress") {
|
|
50824
|
-
|
|
51138
|
+
log23.warn(`Agent ${ctx.agentId} attempted to set own running task to "${newStatus}"`, { taskId: taskId2 });
|
|
50825
51139
|
return JSON.stringify({
|
|
50826
51140
|
status: "denied",
|
|
50827
51141
|
error: `Setting your own running task to "${newStatus}" will immediately abort all ongoing work. If you truly need to stop, confirm by adding a note explaining why. Otherwise, continue working on the task.`
|
|
@@ -50834,7 +51148,7 @@ function createAgentTaskTools(ctx) {
|
|
|
50834
51148
|
const reason = note || "Revision requested";
|
|
50835
51149
|
try {
|
|
50836
51150
|
const task2 = await ctx.requestRevision(taskId2, reason);
|
|
50837
|
-
|
|
51151
|
+
log23.info(`Task revision requested by agent ${ctx.agentId}`, { taskId: task2.id, reason });
|
|
50838
51152
|
return JSON.stringify({
|
|
50839
51153
|
status: "success",
|
|
50840
51154
|
task: task2,
|
|
@@ -50858,7 +51172,7 @@ function createAgentTaskTools(ctx) {
|
|
|
50858
51172
|
await ctx.addTaskNote(task.id, note, ctx.agentName).catch(() => {
|
|
50859
51173
|
});
|
|
50860
51174
|
}
|
|
50861
|
-
|
|
51175
|
+
log23.info(`Task updated by agent ${ctx.agentId}`, {
|
|
50862
51176
|
taskId: task.id,
|
|
50863
51177
|
status: task.status
|
|
50864
51178
|
});
|
|
@@ -50875,7 +51189,7 @@ function createAgentTaskTools(ctx) {
|
|
|
50875
51189
|
await ctx.addTaskNote(taskId2, note, ctx.agentName);
|
|
50876
51190
|
}
|
|
50877
51191
|
const task = ctx.getTask ? await ctx.getTask(taskId2) : null;
|
|
50878
|
-
|
|
51192
|
+
log23.info(`Task updated by agent ${ctx.agentId}`, { taskId: taskId2, hasNote: !!note, hasDescription: description !== void 0, hasBlockedBy: blockedBy !== void 0 });
|
|
50879
51193
|
return JSON.stringify({
|
|
50880
51194
|
status: "success",
|
|
50881
51195
|
task,
|
|
@@ -51220,7 +51534,7 @@ function createAgentTaskTools(ctx) {
|
|
|
51220
51534
|
projectId: args["project_id"],
|
|
51221
51535
|
tags: args["tags"]
|
|
51222
51536
|
});
|
|
51223
|
-
|
|
51537
|
+
log23.info(`Requirement proposed by agent ${ctx.agentId}`, {
|
|
51224
51538
|
requirementId: req.id,
|
|
51225
51539
|
title: req.title
|
|
51226
51540
|
});
|
|
@@ -51230,7 +51544,7 @@ function createAgentTaskTools(ctx) {
|
|
|
51230
51544
|
message: `Requirement proposed: "${req.title}" (ID: ${req.id}). It will be reviewed by a human user. Do NOT create tasks for this until it is approved.`
|
|
51231
51545
|
});
|
|
51232
51546
|
} catch (error) {
|
|
51233
|
-
|
|
51547
|
+
log23.error("requirement_propose failed", { error: String(error) });
|
|
51234
51548
|
return JSON.stringify({ status: "error", error: String(error) });
|
|
51235
51549
|
}
|
|
51236
51550
|
}
|
|
@@ -51384,7 +51698,7 @@ function createAgentTaskTools(ctx) {
|
|
|
51384
51698
|
async execute(args) {
|
|
51385
51699
|
try {
|
|
51386
51700
|
const req = await ctx.updateRequirementStatus(args["requirement_id"], args["status"], args["reason"]);
|
|
51387
|
-
|
|
51701
|
+
log23.info(`Requirement status updated by agent ${ctx.agentId}`, {
|
|
51388
51702
|
requirementId: req.id,
|
|
51389
51703
|
newStatus: req.status,
|
|
51390
51704
|
reason: args["reason"]
|
|
@@ -51395,7 +51709,7 @@ function createAgentTaskTools(ctx) {
|
|
|
51395
51709
|
message: `Requirement "${req.title}" (ID: ${req.id}) status changed to ${req.status}.`
|
|
51396
51710
|
});
|
|
51397
51711
|
} catch (error) {
|
|
51398
|
-
|
|
51712
|
+
log23.error("requirement_update_status failed", { error: String(error) });
|
|
51399
51713
|
return JSON.stringify({ status: "error", error: String(error) });
|
|
51400
51714
|
}
|
|
51401
51715
|
}
|
|
@@ -51455,7 +51769,7 @@ function createAgentTaskTools(ctx) {
|
|
|
51455
51769
|
message: `Requirement "${req.title}" (ID: ${req.id}) updated successfully.`
|
|
51456
51770
|
});
|
|
51457
51771
|
} catch (error) {
|
|
51458
|
-
|
|
51772
|
+
log23.error("requirement_update failed", { error: String(error) });
|
|
51459
51773
|
return JSON.stringify({ status: "error", error: String(error) });
|
|
51460
51774
|
}
|
|
51461
51775
|
}
|
|
@@ -51517,7 +51831,7 @@ function createAgentTaskTools(ctx) {
|
|
|
51517
51831
|
message: `Requirement "${req.title}" (ID: ${req.id}) has been resubmitted for review${hasUpdates ? " with updates" : ""}.`
|
|
51518
51832
|
});
|
|
51519
51833
|
} catch (error) {
|
|
51520
|
-
|
|
51834
|
+
log23.error("requirement_resubmit failed", { error: String(error) });
|
|
51521
51835
|
return JSON.stringify({ status: "error", error: String(error) });
|
|
51522
51836
|
}
|
|
51523
51837
|
}
|
|
@@ -51611,12 +51925,12 @@ function createAgentTaskTools(ctx) {
|
|
|
51611
51925
|
] : []
|
|
51612
51926
|
];
|
|
51613
51927
|
}
|
|
51614
|
-
var
|
|
51928
|
+
var log23;
|
|
51615
51929
|
var init_task_tools = __esm({
|
|
51616
51930
|
"../core/dist/tools/task-tools.js"() {
|
|
51617
51931
|
"use strict";
|
|
51618
51932
|
init_dist();
|
|
51619
|
-
|
|
51933
|
+
log23 = createLogger("task-tools");
|
|
51620
51934
|
}
|
|
51621
51935
|
});
|
|
51622
51936
|
|
|
@@ -52039,10 +52353,10 @@ function createMemoryTools(ctx) {
|
|
|
52039
52353
|
ctx.memory.addEntry(entry);
|
|
52040
52354
|
if (ctx.semanticSearch?.isEnabled()) {
|
|
52041
52355
|
ctx.semanticSearch.indexMemory(entry, ctx.agentId).catch((err) => {
|
|
52042
|
-
|
|
52356
|
+
log24.warn("Failed to index memory for semantic search", { error: String(err) });
|
|
52043
52357
|
});
|
|
52044
52358
|
}
|
|
52045
|
-
|
|
52359
|
+
log24.info("Agent saved memory", { agentId: ctx.agentId, type, contentLen: content.length });
|
|
52046
52360
|
return JSON.stringify({ status: "saved", id: entry.id, type });
|
|
52047
52361
|
}
|
|
52048
52362
|
},
|
|
@@ -52081,7 +52395,7 @@ function createMemoryTools(ctx) {
|
|
|
52081
52395
|
let entries2 = semResults.map((r) => r.entry);
|
|
52082
52396
|
if (type)
|
|
52083
52397
|
entries2 = entries2.filter((e) => e.type === type);
|
|
52084
|
-
|
|
52398
|
+
log24.debug("Semantic memory search", { agentId: ctx.agentId, query: query2, results: entries2.length });
|
|
52085
52399
|
return JSON.stringify({
|
|
52086
52400
|
results: entries2.map((e) => ({
|
|
52087
52401
|
id: e.id,
|
|
@@ -52093,14 +52407,14 @@ function createMemoryTools(ctx) {
|
|
|
52093
52407
|
count: entries2.length
|
|
52094
52408
|
});
|
|
52095
52409
|
} catch (err) {
|
|
52096
|
-
|
|
52410
|
+
log24.warn("Semantic search failed, falling back to substring", { error: String(err) });
|
|
52097
52411
|
}
|
|
52098
52412
|
}
|
|
52099
52413
|
let results = ctx.memory.search(query2);
|
|
52100
52414
|
if (type)
|
|
52101
52415
|
results = results.filter((e) => e.type === type);
|
|
52102
52416
|
results = results.slice(0, limit);
|
|
52103
|
-
|
|
52417
|
+
log24.debug("Memory search (substring)", { agentId: ctx.agentId, query: query2, results: results.length });
|
|
52104
52418
|
return JSON.stringify({
|
|
52105
52419
|
results: results.map((e) => ({
|
|
52106
52420
|
id: e.id,
|
|
@@ -52179,18 +52493,18 @@ ${content}` : content;
|
|
|
52179
52493
|
} else {
|
|
52180
52494
|
ctx.memory.addLongTermMemory(section4, content);
|
|
52181
52495
|
}
|
|
52182
|
-
|
|
52496
|
+
log24.info("Agent updated long-term memory", { agentId: ctx.agentId, section: section4, mode, contentLen: content.length });
|
|
52183
52497
|
return JSON.stringify({ status: "updated", section: section4, mode });
|
|
52184
52498
|
}
|
|
52185
52499
|
}
|
|
52186
52500
|
];
|
|
52187
52501
|
}
|
|
52188
|
-
var
|
|
52502
|
+
var log24;
|
|
52189
52503
|
var init_memory = __esm({
|
|
52190
52504
|
"../core/dist/tools/memory.js"() {
|
|
52191
52505
|
"use strict";
|
|
52192
52506
|
init_dist();
|
|
52193
|
-
|
|
52507
|
+
log24 = createLogger("memory-tools");
|
|
52194
52508
|
}
|
|
52195
52509
|
});
|
|
52196
52510
|
|
|
@@ -52255,7 +52569,7 @@ function createSettingsTools(ctx) {
|
|
|
52255
52569
|
try {
|
|
52256
52570
|
ctx.persistConfig({ llm: { providers: { [provider]: { model } } } });
|
|
52257
52571
|
} catch (e) {
|
|
52258
|
-
|
|
52572
|
+
log25.warn("Failed to persist model change", { error: String(e) });
|
|
52259
52573
|
}
|
|
52260
52574
|
}
|
|
52261
52575
|
return JSON.stringify({
|
|
@@ -52295,7 +52609,7 @@ function createSettingsTools(ctx) {
|
|
|
52295
52609
|
try {
|
|
52296
52610
|
ctx.persistConfig({ llm: { defaultProvider: provider } });
|
|
52297
52611
|
} catch (e) {
|
|
52298
|
-
|
|
52612
|
+
log25.warn("Failed to persist default provider change", { error: String(e) });
|
|
52299
52613
|
}
|
|
52300
52614
|
}
|
|
52301
52615
|
return JSON.stringify({
|
|
@@ -52364,7 +52678,7 @@ function createSettingsTools(ctx) {
|
|
|
52364
52678
|
}
|
|
52365
52679
|
});
|
|
52366
52680
|
} catch (e) {
|
|
52367
|
-
|
|
52681
|
+
log25.warn("Failed to persist new provider", { error: String(e) });
|
|
52368
52682
|
}
|
|
52369
52683
|
}
|
|
52370
52684
|
return JSON.stringify({
|
|
@@ -52432,7 +52746,7 @@ function createSettingsTools(ctx) {
|
|
|
52432
52746
|
updates.baseUrl = baseUrl || void 0;
|
|
52433
52747
|
ctx.persistConfig({ llm: { providers: { [providerName]: updates } } });
|
|
52434
52748
|
} catch (e) {
|
|
52435
|
-
|
|
52749
|
+
log25.warn("Failed to persist provider edit", { error: String(e) });
|
|
52436
52750
|
}
|
|
52437
52751
|
}
|
|
52438
52752
|
return JSON.stringify({
|
|
@@ -52513,7 +52827,7 @@ function createSettingsTools(ctx) {
|
|
|
52513
52827
|
llm: { customModels: { [providerName]: [modelDef] } }
|
|
52514
52828
|
});
|
|
52515
52829
|
} catch (e) {
|
|
52516
|
-
|
|
52830
|
+
log25.warn("Failed to persist custom model", { error: String(e) });
|
|
52517
52831
|
}
|
|
52518
52832
|
}
|
|
52519
52833
|
return JSON.stringify({
|
|
@@ -52529,12 +52843,12 @@ function createSettingsTools(ctx) {
|
|
|
52529
52843
|
}
|
|
52530
52844
|
];
|
|
52531
52845
|
}
|
|
52532
|
-
var
|
|
52846
|
+
var log25;
|
|
52533
52847
|
var init_settings = __esm({
|
|
52534
52848
|
"../core/dist/tools/settings.js"() {
|
|
52535
52849
|
"use strict";
|
|
52536
52850
|
init_dist();
|
|
52537
|
-
|
|
52851
|
+
log25 = createLogger("settings-tools");
|
|
52538
52852
|
}
|
|
52539
52853
|
});
|
|
52540
52854
|
|
|
@@ -52602,7 +52916,7 @@ function createRecallTool(ctx) {
|
|
|
52602
52916
|
}))
|
|
52603
52917
|
});
|
|
52604
52918
|
} catch (err) {
|
|
52605
|
-
|
|
52919
|
+
log26.error("recall_activity list failed", { error: String(err) });
|
|
52606
52920
|
return JSON.stringify({ status: "error", message: String(err) });
|
|
52607
52921
|
}
|
|
52608
52922
|
}
|
|
@@ -52635,7 +52949,7 @@ function createRecallTool(ctx) {
|
|
|
52635
52949
|
}))
|
|
52636
52950
|
});
|
|
52637
52951
|
} catch (err) {
|
|
52638
|
-
|
|
52952
|
+
log26.error("recall_activity search failed", { error: String(err) });
|
|
52639
52953
|
return JSON.stringify({ status: "error", message: String(err) });
|
|
52640
52954
|
}
|
|
52641
52955
|
}
|
|
@@ -52659,7 +52973,7 @@ function createRecallTool(ctx) {
|
|
|
52659
52973
|
}))
|
|
52660
52974
|
});
|
|
52661
52975
|
} catch (err) {
|
|
52662
|
-
|
|
52976
|
+
log26.error("recall_activity get failed", { error: String(err) });
|
|
52663
52977
|
return JSON.stringify({ status: "error", message: String(err) });
|
|
52664
52978
|
}
|
|
52665
52979
|
}
|
|
@@ -52667,12 +52981,12 @@ function createRecallTool(ctx) {
|
|
|
52667
52981
|
}
|
|
52668
52982
|
};
|
|
52669
52983
|
}
|
|
52670
|
-
var
|
|
52984
|
+
var log26, CONTENT_TRUNCATE_LIMIT;
|
|
52671
52985
|
var init_recall = __esm({
|
|
52672
52986
|
"../core/dist/tools/recall.js"() {
|
|
52673
52987
|
"use strict";
|
|
52674
52988
|
init_dist();
|
|
52675
|
-
|
|
52989
|
+
log26 = createLogger("recall-tools");
|
|
52676
52990
|
CONTENT_TRUNCATE_LIMIT = 500;
|
|
52677
52991
|
}
|
|
52678
52992
|
});
|
|
@@ -52692,12 +53006,12 @@ function cosineSimilarity(a, b) {
|
|
|
52692
53006
|
const denom = Math.sqrt(normA) * Math.sqrt(normB);
|
|
52693
53007
|
return denom === 0 ? 0 : dot / denom;
|
|
52694
53008
|
}
|
|
52695
|
-
var
|
|
53009
|
+
var log27, OpenAIEmbeddingProvider, LocalVectorStore, SemanticMemorySearch;
|
|
52696
53010
|
var init_semantic_search = __esm({
|
|
52697
53011
|
"../core/dist/memory/semantic-search.js"() {
|
|
52698
53012
|
"use strict";
|
|
52699
53013
|
init_dist();
|
|
52700
|
-
|
|
53014
|
+
log27 = createLogger("semantic-search");
|
|
52701
53015
|
OpenAIEmbeddingProvider = class {
|
|
52702
53016
|
dimensions;
|
|
52703
53017
|
apiKey;
|
|
@@ -52777,10 +53091,10 @@ var init_semantic_search = __esm({
|
|
|
52777
53091
|
if (existsSync16(this.storePath)) {
|
|
52778
53092
|
const data = JSON.parse(readFileSync11(this.storePath, "utf-8"));
|
|
52779
53093
|
this.vectors = new Map(data);
|
|
52780
|
-
|
|
53094
|
+
log27.info("Local vector store loaded", { entries: this.vectors.size });
|
|
52781
53095
|
}
|
|
52782
53096
|
} catch (err) {
|
|
52783
|
-
|
|
53097
|
+
log27.warn("Failed to load local vector store", { error: String(err) });
|
|
52784
53098
|
}
|
|
52785
53099
|
}
|
|
52786
53100
|
scheduleSave() {
|
|
@@ -52795,7 +53109,7 @@ var init_semantic_search = __esm({
|
|
|
52795
53109
|
writeFileSync9(this.storePath, JSON.stringify(Array.from(this.vectors.entries())));
|
|
52796
53110
|
this.dirty = false;
|
|
52797
53111
|
} catch (err) {
|
|
52798
|
-
|
|
53112
|
+
log27.warn("Failed to save local vector store", { error: String(err) });
|
|
52799
53113
|
}
|
|
52800
53114
|
}, 2e3);
|
|
52801
53115
|
}
|
|
@@ -52826,7 +53140,7 @@ var init_semantic_search = __esm({
|
|
|
52826
53140
|
type: entry.type
|
|
52827
53141
|
});
|
|
52828
53142
|
} catch (err) {
|
|
52829
|
-
|
|
53143
|
+
log27.warn("Failed to index memory entry", { id: entry.id, error: String(err) });
|
|
52830
53144
|
}
|
|
52831
53145
|
}
|
|
52832
53146
|
async search(query2, opts) {
|
|
@@ -52849,7 +53163,7 @@ var init_semantic_search = __esm({
|
|
|
52849
53163
|
similarity: r.similarity
|
|
52850
53164
|
}));
|
|
52851
53165
|
} catch (err) {
|
|
52852
|
-
|
|
53166
|
+
log27.warn("Semantic search failed, returning empty results", { error: String(err) });
|
|
52853
53167
|
return [];
|
|
52854
53168
|
}
|
|
52855
53169
|
}
|
|
@@ -52863,22 +53177,22 @@ var init_semantic_search = __esm({
|
|
|
52863
53177
|
});
|
|
52864
53178
|
|
|
52865
53179
|
// ../a2a/dist/bus.js
|
|
52866
|
-
var
|
|
53180
|
+
var log28;
|
|
52867
53181
|
var init_bus = __esm({
|
|
52868
53182
|
"../a2a/dist/bus.js"() {
|
|
52869
53183
|
"use strict";
|
|
52870
53184
|
init_dist();
|
|
52871
|
-
|
|
53185
|
+
log28 = createLogger("a2a-bus");
|
|
52872
53186
|
}
|
|
52873
53187
|
});
|
|
52874
53188
|
|
|
52875
53189
|
// ../a2a/dist/delegation.js
|
|
52876
|
-
var
|
|
53190
|
+
var log29, DelegationManager;
|
|
52877
53191
|
var init_delegation = __esm({
|
|
52878
53192
|
"../a2a/dist/delegation.js"() {
|
|
52879
53193
|
"use strict";
|
|
52880
53194
|
init_dist();
|
|
52881
|
-
|
|
53195
|
+
log29 = createLogger("a2a-delegation");
|
|
52882
53196
|
DelegationManager = class {
|
|
52883
53197
|
agentCards = /* @__PURE__ */ new Map();
|
|
52884
53198
|
delegationHandler;
|
|
@@ -52930,7 +53244,7 @@ var init_delegation = __esm({
|
|
|
52930
53244
|
if (this.delegationHandler) {
|
|
52931
53245
|
await this.delegationHandler(envelope, delegation);
|
|
52932
53246
|
}
|
|
52933
|
-
|
|
53247
|
+
log29.info(`Task delegated from ${fromAgentId} to ${targetId}`, {
|
|
52934
53248
|
taskId: delegation.taskId,
|
|
52935
53249
|
title: delegation.title
|
|
52936
53250
|
});
|
|
@@ -52940,7 +53254,7 @@ var init_delegation = __esm({
|
|
|
52940
53254
|
const card = this.agentCards.get(agentId2);
|
|
52941
53255
|
if (card) {
|
|
52942
53256
|
card.status = status;
|
|
52943
|
-
|
|
53257
|
+
log29.debug("Updated agent card status", { agentId: agentId2, status });
|
|
52944
53258
|
}
|
|
52945
53259
|
}
|
|
52946
53260
|
getAgentCards() {
|
|
@@ -52951,22 +53265,22 @@ var init_delegation = __esm({
|
|
|
52951
53265
|
});
|
|
52952
53266
|
|
|
52953
53267
|
// ../a2a/dist/collaboration.js
|
|
52954
|
-
var
|
|
53268
|
+
var log30;
|
|
52955
53269
|
var init_collaboration = __esm({
|
|
52956
53270
|
"../a2a/dist/collaboration.js"() {
|
|
52957
53271
|
"use strict";
|
|
52958
53272
|
init_dist();
|
|
52959
|
-
|
|
53273
|
+
log30 = createLogger("a2a-collaboration");
|
|
52960
53274
|
}
|
|
52961
53275
|
});
|
|
52962
53276
|
|
|
52963
53277
|
// ../a2a/dist/structured.js
|
|
52964
|
-
var
|
|
53278
|
+
var log31;
|
|
52965
53279
|
var init_structured = __esm({
|
|
52966
53280
|
"../a2a/dist/structured.js"() {
|
|
52967
53281
|
"use strict";
|
|
52968
53282
|
init_dist();
|
|
52969
|
-
|
|
53283
|
+
log31 = createLogger("a2a-structured");
|
|
52970
53284
|
}
|
|
52971
53285
|
});
|
|
52972
53286
|
|
|
@@ -52994,7 +53308,7 @@ function resolveCurrentTaskId(agentObj, ts, agentId2) {
|
|
|
52994
53308
|
const currentTask = ts.getTask(currentId);
|
|
52995
53309
|
if (currentTask?.status === "in_progress")
|
|
52996
53310
|
return currentId;
|
|
52997
|
-
|
|
53311
|
+
log32.warn("Agent currentTaskId is no longer in_progress, searching activeTasks for a valid candidate", {
|
|
52998
53312
|
agentId: agentId2,
|
|
52999
53313
|
currentTaskId: currentId,
|
|
53000
53314
|
actualStatus: currentTask?.status
|
|
@@ -53008,13 +53322,13 @@ function resolveCurrentTaskId(agentObj, ts, agentId2) {
|
|
|
53008
53322
|
for (const t of activeTasks) {
|
|
53009
53323
|
const task = ts.getTask(t.taskId);
|
|
53010
53324
|
if (task && ["completed", "failed", "cancelled", "archived"].includes(task.status)) {
|
|
53011
|
-
|
|
53325
|
+
log32.warn("Removing stale task from agent activeTasks", { agentId: agentId2, taskId: t.taskId, status: task.status });
|
|
53012
53326
|
agentObj?.removeActiveTask(t.taskId);
|
|
53013
53327
|
}
|
|
53014
53328
|
}
|
|
53015
53329
|
throw new Error(`No in_progress task found for agent ${agentId2} \u2014 cannot submit for review. Active task IDs: [${activeTasks.map((t) => t.taskId).join(", ")}]`);
|
|
53016
53330
|
}
|
|
53017
|
-
var
|
|
53331
|
+
var log32, AgentManager;
|
|
53018
53332
|
var init_agent_manager = __esm({
|
|
53019
53333
|
"../core/dist/agent-manager.js"() {
|
|
53020
53334
|
"use strict";
|
|
@@ -53037,7 +53351,7 @@ var init_agent_manager = __esm({
|
|
|
53037
53351
|
init_semantic_search();
|
|
53038
53352
|
init_security();
|
|
53039
53353
|
init_dist3();
|
|
53040
|
-
|
|
53354
|
+
log32 = createLogger("agent-manager");
|
|
53041
53355
|
AgentManager = class _AgentManager {
|
|
53042
53356
|
agents = /* @__PURE__ */ new Map();
|
|
53043
53357
|
eventBus;
|
|
@@ -53070,6 +53384,7 @@ var init_agent_manager = __esm({
|
|
|
53070
53384
|
recallCallbacks;
|
|
53071
53385
|
delegationManager;
|
|
53072
53386
|
_maxToolIterations = Infinity;
|
|
53387
|
+
_cognitiveConfig;
|
|
53073
53388
|
templateRegistry;
|
|
53074
53389
|
builderService;
|
|
53075
53390
|
hubClient;
|
|
@@ -53189,18 +53504,18 @@ var init_agent_manager = __esm({
|
|
|
53189
53504
|
this.semanticSearch = new SemanticMemorySearch(embeddingProvider, vectorStore);
|
|
53190
53505
|
this.semanticSearch.initialize().then((ok4) => {
|
|
53191
53506
|
if (ok4)
|
|
53192
|
-
|
|
53507
|
+
log32.info("Semantic memory search initialized (LocalVectorStore)");
|
|
53193
53508
|
else
|
|
53194
|
-
|
|
53509
|
+
log32.warn("Semantic memory search initialization failed");
|
|
53195
53510
|
}).catch((err) => {
|
|
53196
|
-
|
|
53511
|
+
log32.warn("Semantic memory search init error", { error: String(err) });
|
|
53197
53512
|
});
|
|
53198
53513
|
}
|
|
53199
53514
|
this.delegationManager = new DelegationManager();
|
|
53200
53515
|
this.delegationManager.onDelegationReceived(async (envelope, delegation) => {
|
|
53201
53516
|
const targetAgent = this.agents.get(envelope.to);
|
|
53202
53517
|
if (!targetAgent) {
|
|
53203
|
-
|
|
53518
|
+
log32.warn("Delegation target agent not found", { to: envelope.to });
|
|
53204
53519
|
return;
|
|
53205
53520
|
}
|
|
53206
53521
|
if (this.taskService) {
|
|
@@ -53217,7 +53532,7 @@ var init_agent_manager = __esm({
|
|
|
53217
53532
|
acceptanceCriteria: delegation.expectedOutput,
|
|
53218
53533
|
deadline: delegation.deadline
|
|
53219
53534
|
});
|
|
53220
|
-
|
|
53535
|
+
log32.info("Delegation created real task", {
|
|
53221
53536
|
taskId: task.id,
|
|
53222
53537
|
delegatedTo: envelope.to,
|
|
53223
53538
|
from: envelope.from,
|
|
@@ -53227,7 +53542,7 @@ var init_agent_manager = __esm({
|
|
|
53227
53542
|
await targetAgent.sendMessage(`[Delegated Task from ${envelope.from}]
|
|
53228
53543
|
Title: ${delegation.title}
|
|
53229
53544
|
Description: ${delegation.description}
|
|
53230
|
-
Priority: ${delegation.priority}`, envelope.from, { name: envelope.from, role: "manager" }, { sourceType: "a2a_message", sessionId: `sys_${envelope.from}_${Date.now()}
|
|
53545
|
+
Priority: ${delegation.priority}`, envelope.from, { name: envelope.from, role: "manager" }, { sourceType: "a2a_message", sessionId: `sys_${envelope.from}_${Date.now()}`, waitForReply: false });
|
|
53231
53546
|
}
|
|
53232
53547
|
});
|
|
53233
53548
|
this.templateRegistry = options.templateRegistry;
|
|
@@ -53239,6 +53554,12 @@ Priority: ${delegation.priority}`, envelope.from, { name: envelope.from, role: "
|
|
|
53239
53554
|
set maxToolIterations(value) {
|
|
53240
53555
|
this._maxToolIterations = value <= 0 ? Infinity : value;
|
|
53241
53556
|
}
|
|
53557
|
+
get cognitiveConfig() {
|
|
53558
|
+
return this._cognitiveConfig;
|
|
53559
|
+
}
|
|
53560
|
+
set cognitiveConfig(value) {
|
|
53561
|
+
this._cognitiveConfig = value;
|
|
53562
|
+
}
|
|
53242
53563
|
setBrowserBringToFront(value) {
|
|
53243
53564
|
this.browserSessionManager.bringToFront = value;
|
|
53244
53565
|
}
|
|
@@ -53430,7 +53751,8 @@ You are ${request.name}.`,
|
|
|
53430
53751
|
orgContext: request.orgContext,
|
|
53431
53752
|
pathPolicy,
|
|
53432
53753
|
skillRegistry: this.skillRegistry,
|
|
53433
|
-
maxToolIterations: this._maxToolIterations
|
|
53754
|
+
maxToolIterations: this._maxToolIterations,
|
|
53755
|
+
cognitive: this._cognitiveConfig
|
|
53434
53756
|
};
|
|
53435
53757
|
const agent = new Agent(agentOpts);
|
|
53436
53758
|
if (this.skillRegistry) {
|
|
@@ -53439,14 +53761,14 @@ You are ${request.name}.`,
|
|
|
53439
53761
|
agent.injectSkillInstructions(skillName, instructions);
|
|
53440
53762
|
}
|
|
53441
53763
|
if (builtinInstructions.size > 0) {
|
|
53442
|
-
|
|
53764
|
+
log32.info(`Always-on builtin skills injected for agent ${id}`, { skills: [...builtinInstructions.keys()] });
|
|
53443
53765
|
}
|
|
53444
53766
|
agent.setAvailableSkillCatalog(this.skillRegistry.getSkillCatalog());
|
|
53445
53767
|
}
|
|
53446
53768
|
if (this.skillRegistry && config.skills.length > 0) {
|
|
53447
53769
|
const missingSkills = config.skills.filter((s) => !this.skillRegistry.get(s));
|
|
53448
53770
|
if (missingSkills.length > 0) {
|
|
53449
|
-
|
|
53771
|
+
log32.warn(`Agent ${config.name} (${id}) references skills not found in registry`, {
|
|
53450
53772
|
missing: missingSkills,
|
|
53451
53773
|
available: this.skillRegistry.list().map((s) => s.name)
|
|
53452
53774
|
});
|
|
@@ -53479,12 +53801,12 @@ You are ${request.name}.`,
|
|
|
53479
53801
|
toolNames.push(tool.name);
|
|
53480
53802
|
}
|
|
53481
53803
|
agent.activateTools(toolNames);
|
|
53482
|
-
|
|
53804
|
+
log32.info(`Skill ${skillName} MCP server ${serverName} connected for agent ${id}`, {
|
|
53483
53805
|
toolCount: mcpTools.length,
|
|
53484
53806
|
isolated
|
|
53485
53807
|
});
|
|
53486
53808
|
} catch (error) {
|
|
53487
|
-
|
|
53809
|
+
log32.warn(`Failed to connect skill ${skillName} MCP server ${serverName} for agent ${id}`, {
|
|
53488
53810
|
error: String(error)
|
|
53489
53811
|
});
|
|
53490
53812
|
}
|
|
@@ -53530,7 +53852,7 @@ You are ${request.name}.`,
|
|
|
53530
53852
|
return { ...a, skills: [] };
|
|
53531
53853
|
}
|
|
53532
53854
|
}),
|
|
53533
|
-
sendMessage: async (targetId, message, fromId, fromName, priority) => {
|
|
53855
|
+
sendMessage: async (targetId, message, fromId, fromName, priority, waitForReply) => {
|
|
53534
53856
|
try {
|
|
53535
53857
|
const parsed = JSON.parse(message);
|
|
53536
53858
|
if (parsed.type === "status_broadcast") {
|
|
@@ -53547,7 +53869,8 @@ You are ${request.name}.`,
|
|
|
53547
53869
|
sourceType: "a2a_message",
|
|
53548
53870
|
sessionId: `a2a_${targetId}_${Date.now()}`,
|
|
53549
53871
|
scenario: "a2a",
|
|
53550
|
-
priority
|
|
53872
|
+
priority,
|
|
53873
|
+
waitForReply
|
|
53551
53874
|
});
|
|
53552
53875
|
return stripInternalBlocks(reply);
|
|
53553
53876
|
},
|
|
@@ -53766,7 +54089,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
53766
54089
|
return [];
|
|
53767
54090
|
}
|
|
53768
54091
|
});
|
|
53769
|
-
|
|
54092
|
+
log32.info(`Task tools injected for agent ${id}`);
|
|
53770
54093
|
}
|
|
53771
54094
|
if (this.projectService) {
|
|
53772
54095
|
const ah = this.approvalHandler;
|
|
@@ -53796,7 +54119,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
53796
54119
|
}),
|
|
53797
54120
|
delegateMessage: async (targetId, message, _from) => {
|
|
53798
54121
|
const target = this.getAgent(targetId);
|
|
53799
|
-
const reply = await target.sendMessage(message, id, { name: config.name, role: "manager" }, { sourceType: "a2a_message" });
|
|
54122
|
+
const reply = await target.sendMessage(message, id, { name: config.name, role: "manager" }, { sourceType: "a2a_message", waitForReply: false });
|
|
53800
54123
|
return stripInternalBlocks(reply);
|
|
53801
54124
|
},
|
|
53802
54125
|
getTeamStatus: () => filterByTeam(this.listAgents()).map((a) => {
|
|
@@ -53870,11 +54193,11 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
53870
54193
|
for (const tool of mcpTools) {
|
|
53871
54194
|
agent.registerTool(tool);
|
|
53872
54195
|
}
|
|
53873
|
-
|
|
54196
|
+
log32.info(`MCP server ${serverName} tools registered for agent ${id}`, {
|
|
53874
54197
|
toolCount: mcpTools.length
|
|
53875
54198
|
});
|
|
53876
54199
|
} catch (error) {
|
|
53877
|
-
|
|
54200
|
+
log32.warn(`Failed to connect MCP server ${serverName} for agent ${id}`, {
|
|
53878
54201
|
error: String(error)
|
|
53879
54202
|
});
|
|
53880
54203
|
}
|
|
@@ -53911,7 +54234,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
53911
54234
|
status: "idle"
|
|
53912
54235
|
});
|
|
53913
54236
|
this.eventBus.emit("agent:created", { agentId: id, name: request.name });
|
|
53914
|
-
|
|
54237
|
+
log32.info(`Agent created: ${request.name} (${id})`);
|
|
53915
54238
|
return agent;
|
|
53916
54239
|
}
|
|
53917
54240
|
/**
|
|
@@ -54021,7 +54344,8 @@ You are ${row.name}.`,
|
|
|
54021
54344
|
pathPolicy,
|
|
54022
54345
|
restoredState: { tokensUsedToday: row.tokensUsedToday ?? 0 },
|
|
54023
54346
|
skillRegistry: this.skillRegistry,
|
|
54024
|
-
maxToolIterations: this._maxToolIterations
|
|
54347
|
+
maxToolIterations: this._maxToolIterations,
|
|
54348
|
+
cognitive: this._cognitiveConfig
|
|
54025
54349
|
});
|
|
54026
54350
|
if (this.skillRegistry) {
|
|
54027
54351
|
const builtinInstructions = this.skillRegistry.getBuiltinInstructions();
|
|
@@ -54033,7 +54357,7 @@ You are ${row.name}.`,
|
|
|
54033
54357
|
if (this.skillRegistry && config.skills.length > 0) {
|
|
54034
54358
|
const missingSkills = config.skills.filter((s) => !this.skillRegistry.get(s));
|
|
54035
54359
|
if (missingSkills.length > 0) {
|
|
54036
|
-
|
|
54360
|
+
log32.warn(`Restored agent ${config.name} (${id}) references skills not found in registry`, {
|
|
54037
54361
|
missing: missingSkills,
|
|
54038
54362
|
available: this.skillRegistry.list().map((s) => s.name)
|
|
54039
54363
|
});
|
|
@@ -54068,12 +54392,12 @@ You are ${row.name}.`,
|
|
|
54068
54392
|
toolNames.push(tool.name);
|
|
54069
54393
|
}
|
|
54070
54394
|
agent.activateTools(toolNames);
|
|
54071
|
-
|
|
54395
|
+
log32.info(`Skill ${skillName} MCP server ${serverName} restored for agent ${id}`, {
|
|
54072
54396
|
toolCount: mcpTools.length,
|
|
54073
54397
|
isolated
|
|
54074
54398
|
});
|
|
54075
54399
|
} catch (error) {
|
|
54076
|
-
|
|
54400
|
+
log32.warn(`Failed to restore skill ${skillName} MCP server ${serverName} for agent ${id}`, {
|
|
54077
54401
|
error: String(error)
|
|
54078
54402
|
});
|
|
54079
54403
|
}
|
|
@@ -54121,7 +54445,7 @@ You are ${row.name}.`,
|
|
|
54121
54445
|
return { ...a, skills: [] };
|
|
54122
54446
|
}
|
|
54123
54447
|
}),
|
|
54124
|
-
sendMessage: async (targetId, message, fromId, fromName, priority) => {
|
|
54448
|
+
sendMessage: async (targetId, message, fromId, fromName, priority, waitForReply) => {
|
|
54125
54449
|
try {
|
|
54126
54450
|
const parsed = JSON.parse(message);
|
|
54127
54451
|
if (parsed.type === "status_broadcast") {
|
|
@@ -54138,7 +54462,8 @@ You are ${row.name}.`,
|
|
|
54138
54462
|
sourceType: "a2a_message",
|
|
54139
54463
|
sessionId: `a2a_${targetId}_${Date.now()}`,
|
|
54140
54464
|
scenario: "a2a",
|
|
54141
|
-
priority
|
|
54465
|
+
priority,
|
|
54466
|
+
waitForReply
|
|
54142
54467
|
});
|
|
54143
54468
|
},
|
|
54144
54469
|
delegateTask: async (targetId, delegation) => this.delegationManager.delegateTask(id, delegation, targetId),
|
|
@@ -54356,7 +54681,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54356
54681
|
}),
|
|
54357
54682
|
delegateMessage: async (targetId, message) => {
|
|
54358
54683
|
const target = this.getAgent(targetId);
|
|
54359
|
-
const reply = await target.sendMessage(message, id, { name: config.name, role: "manager" }, { sourceType: "a2a_message" });
|
|
54684
|
+
const reply = await target.sendMessage(message, id, { name: config.name, role: "manager" }, { sourceType: "a2a_message", waitForReply: false });
|
|
54360
54685
|
return stripInternalBlocks(reply);
|
|
54361
54686
|
},
|
|
54362
54687
|
getTeamStatus: () => filterByTeamRestored(this.listAgents()).map((a) => {
|
|
@@ -54451,7 +54776,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54451
54776
|
status: "idle"
|
|
54452
54777
|
});
|
|
54453
54778
|
this.eventBus.emit("agent:created", { agentId: id, name: row.name });
|
|
54454
|
-
|
|
54779
|
+
log32.info(`Agent restored: ${row.name} (${id})`, {
|
|
54455
54780
|
profile: config.profile ? "yes" : "no",
|
|
54456
54781
|
tokensUsedToday: row.tokensUsedToday ?? 0,
|
|
54457
54782
|
activeTaskIds: Array.isArray(row.activeTaskIds) ? row.activeTaskIds.length : 0
|
|
@@ -54472,21 +54797,21 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54472
54797
|
try {
|
|
54473
54798
|
const task = this.taskService.getTask(taskId2);
|
|
54474
54799
|
if (!task) {
|
|
54475
|
-
|
|
54800
|
+
log32.warn("Task not found during rehydration, skipping", { agentId: agentId2, taskId: taskId2 });
|
|
54476
54801
|
continue;
|
|
54477
54802
|
}
|
|
54478
54803
|
if (task.status === "completed" || task.status === "cancelled" || task.status === "failed") {
|
|
54479
|
-
|
|
54804
|
+
log32.debug("Task already terminal, skipping rehydration", {
|
|
54480
54805
|
agentId: agentId2,
|
|
54481
54806
|
taskId: taskId2,
|
|
54482
54807
|
status: task.status
|
|
54483
54808
|
});
|
|
54484
54809
|
continue;
|
|
54485
54810
|
}
|
|
54486
|
-
|
|
54811
|
+
log32.info("Re-queuing interrupted task", { agentId: agentId2, taskId: taskId2, title: task.title });
|
|
54487
54812
|
this.taskService.assignTask(taskId2, agentId2);
|
|
54488
54813
|
} catch (error) {
|
|
54489
|
-
|
|
54814
|
+
log32.warn("Failed to rehydrate task", { agentId: agentId2, taskId: taskId2, error: String(error) });
|
|
54490
54815
|
}
|
|
54491
54816
|
}
|
|
54492
54817
|
}
|
|
@@ -54516,13 +54841,13 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54516
54841
|
if (existsSync17(agentDir)) {
|
|
54517
54842
|
try {
|
|
54518
54843
|
rmSync(agentDir, { recursive: true, force: true });
|
|
54519
|
-
|
|
54844
|
+
log32.info(`Agent data directory purged: ${agentDir}`);
|
|
54520
54845
|
} catch (err) {
|
|
54521
|
-
|
|
54846
|
+
log32.warn("Failed to purge agent data directory", { agentId: agentId2, error: String(err) });
|
|
54522
54847
|
}
|
|
54523
54848
|
}
|
|
54524
54849
|
}
|
|
54525
|
-
|
|
54850
|
+
log32.info(`Agent removed: ${agentId2}`, { purgeFiles: !!opts?.purgeFiles });
|
|
54526
54851
|
}
|
|
54527
54852
|
/** Remove orphaned agent directories that have no matching DB record */
|
|
54528
54853
|
purgeOrphanedAgentDirs(knownAgentIds) {
|
|
@@ -54544,7 +54869,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54544
54869
|
}
|
|
54545
54870
|
}
|
|
54546
54871
|
if (removed.length > 0)
|
|
54547
|
-
|
|
54872
|
+
log32.info(`Purged ${removed.length} orphaned agent directories`);
|
|
54548
54873
|
return { removed, failed };
|
|
54549
54874
|
}
|
|
54550
54875
|
getAgent(agentId2) {
|
|
@@ -54780,12 +55105,12 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54780
55105
|
try {
|
|
54781
55106
|
agent.pause(reason);
|
|
54782
55107
|
} catch (err) {
|
|
54783
|
-
|
|
55108
|
+
log32.warn("Failed to pause agent", { agentId: id, error: String(err) });
|
|
54784
55109
|
}
|
|
54785
55110
|
}
|
|
54786
55111
|
this.globalPaused = true;
|
|
54787
55112
|
this.eventBus.emit("system:pause-all", { reason });
|
|
54788
|
-
|
|
55113
|
+
log32.info("All agents paused", { reason });
|
|
54789
55114
|
}
|
|
54790
55115
|
async resumeAllAgents() {
|
|
54791
55116
|
for (const [id, agent] of this.agents) {
|
|
@@ -54794,13 +55119,13 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54794
55119
|
agent.resume();
|
|
54795
55120
|
}
|
|
54796
55121
|
} catch (err) {
|
|
54797
|
-
|
|
55122
|
+
log32.warn("Failed to resume agent", { agentId: id, error: String(err) });
|
|
54798
55123
|
}
|
|
54799
55124
|
}
|
|
54800
55125
|
this.globalPaused = false;
|
|
54801
55126
|
this.emergencyMode = false;
|
|
54802
55127
|
this.eventBus.emit("system:resume-all", {});
|
|
54803
|
-
|
|
55128
|
+
log32.info("All agents resumed");
|
|
54804
55129
|
}
|
|
54805
55130
|
async emergencyStop() {
|
|
54806
55131
|
for (const [id, agent] of this.agents) {
|
|
@@ -54808,13 +55133,13 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54808
55133
|
agent.cancelActiveStream();
|
|
54809
55134
|
await agent.stop();
|
|
54810
55135
|
} catch (err) {
|
|
54811
|
-
|
|
55136
|
+
log32.warn("Failed to stop agent during emergency", { agentId: id, error: String(err) });
|
|
54812
55137
|
}
|
|
54813
55138
|
}
|
|
54814
55139
|
this.emergencyMode = true;
|
|
54815
55140
|
this.globalPaused = true;
|
|
54816
55141
|
this.eventBus.emit("system:emergency-stop", {});
|
|
54817
|
-
|
|
55142
|
+
log32.warn("EMERGENCY STOP \u2014 all agents stopped");
|
|
54818
55143
|
}
|
|
54819
55144
|
isGlobalPaused() {
|
|
54820
55145
|
return this.globalPaused;
|
|
@@ -54828,7 +55153,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54828
55153
|
clearEmergencyMode() {
|
|
54829
55154
|
this.emergencyMode = false;
|
|
54830
55155
|
this.globalPaused = false;
|
|
54831
|
-
|
|
55156
|
+
log32.info("Emergency mode cleared");
|
|
54832
55157
|
}
|
|
54833
55158
|
async shutdown() {
|
|
54834
55159
|
for (const [, agent] of this.agents) {
|
|
@@ -54837,7 +55162,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54837
55162
|
} catch {
|
|
54838
55163
|
}
|
|
54839
55164
|
}
|
|
54840
|
-
|
|
55165
|
+
log32.info("AgentManager shutdown complete \u2014 all metrics flushed");
|
|
54841
55166
|
}
|
|
54842
55167
|
// ─── Role Template Versioning & Sync ──────────────────────────────────────
|
|
54843
55168
|
static ROLE_FILES = ["ROLE.md", "HEARTBEAT.md", "POLICIES.md", "CONTEXT.md"];
|
|
@@ -54928,7 +55253,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54928
55253
|
}
|
|
54929
55254
|
}
|
|
54930
55255
|
agent.reloadRole();
|
|
54931
|
-
|
|
55256
|
+
log32.info("Synced agent role from template", { agentId: agentId2, roleId, synced });
|
|
54932
55257
|
return { agentId: agentId2, success: true, synced };
|
|
54933
55258
|
}
|
|
54934
55259
|
checkAllRoleUpdates() {
|
|
@@ -54956,7 +55281,7 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
54956
55281
|
}
|
|
54957
55282
|
}
|
|
54958
55283
|
this.eventBus.emit("system:announcement", announcement);
|
|
54959
|
-
|
|
55284
|
+
log32.info("Announcement broadcast", { id: announcement.id, title: announcement.title });
|
|
54960
55285
|
}
|
|
54961
55286
|
getActiveAnnouncements() {
|
|
54962
55287
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -55024,31 +55349,12 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
55024
55349
|
};
|
|
55025
55350
|
agent.setIdentityContext(identity);
|
|
55026
55351
|
}
|
|
55027
|
-
|
|
55352
|
+
log32.info(`Refreshed identity contexts for ${orgAgents.length} agents in org ${orgId2}`);
|
|
55028
55353
|
}
|
|
55029
55354
|
};
|
|
55030
55355
|
}
|
|
55031
55356
|
});
|
|
55032
55357
|
|
|
55033
|
-
// ../core/dist/cognitive.js
|
|
55034
|
-
var log32, SCENARIO_DEPTH_MAP;
|
|
55035
|
-
var init_cognitive2 = __esm({
|
|
55036
|
-
"../core/dist/cognitive.js"() {
|
|
55037
|
-
"use strict";
|
|
55038
|
-
init_dist();
|
|
55039
|
-
log32 = createLogger("cognitive");
|
|
55040
|
-
SCENARIO_DEPTH_MAP = {
|
|
55041
|
-
heartbeat: CognitiveDepth.D0_Reflexive,
|
|
55042
|
-
memory_consolidation: CognitiveDepth.D0_Reflexive,
|
|
55043
|
-
human_chat: CognitiveDepth.D1_Reactive,
|
|
55044
|
-
a2a: CognitiveDepth.D1_Reactive,
|
|
55045
|
-
a2a_message: CognitiveDepth.D1_Reactive,
|
|
55046
|
-
comment_response: CognitiveDepth.D1_Reactive,
|
|
55047
|
-
task_execution: CognitiveDepth.D2_Deliberative
|
|
55048
|
-
};
|
|
55049
|
-
}
|
|
55050
|
-
});
|
|
55051
|
-
|
|
55052
55358
|
// ../core/dist/llm/anthropic.js
|
|
55053
55359
|
var AnthropicProvider;
|
|
55054
55360
|
var init_anthropic = __esm({
|
|
@@ -58577,7 +58883,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58577
58883
|
skills: [],
|
|
58578
58884
|
tags: ["development", "coding", "fullstack", "backend", "frontend"],
|
|
58579
58885
|
category: "development",
|
|
58580
|
-
icon: "code"
|
|
58886
|
+
icon: "code",
|
|
58887
|
+
i18n: { "zh-CN": { name: "\u5168\u6808\u5F00\u53D1\u8005", description: "\u5168\u6808\u5F00\u53D1\u667A\u80FD\u4F53\uFF0C\u64C5\u957F\u4EE3\u7801\u7F16\u5199\u3001\u5BA1\u67E5\u548C\u8C03\u8BD5\uFF0C\u7CBE\u901A\u591A\u79CD\u7F16\u7A0B\u8BED\u8A00\u548C\u6846\u67B6\u3002" } }
|
|
58581
58888
|
},
|
|
58582
58889
|
{
|
|
58583
58890
|
id: "tpl-reviewer",
|
|
@@ -58591,7 +58898,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58591
58898
|
skills: [],
|
|
58592
58899
|
tags: ["review", "quality", "best-practices"],
|
|
58593
58900
|
category: "development",
|
|
58594
|
-
icon: "search"
|
|
58901
|
+
icon: "search",
|
|
58902
|
+
i18n: { "zh-CN": { name: "\u4EE3\u7801\u5BA1\u67E5\u5458", description: "\u4E13\u6CE8\u4E8E\u4EE3\u7801\u5BA1\u67E5\u3001\u8D28\u91CF\u4FDD\u8BC1\u548C\u6700\u4F73\u5B9E\u8DF5\u6267\u884C\uFF0C\u5BA1\u67E5 PR \u5E76\u63D0\u51FA\u6539\u8FDB\u5EFA\u8BAE\u3002" } }
|
|
58595
58903
|
},
|
|
58596
58904
|
{
|
|
58597
58905
|
id: "tpl-project-manager",
|
|
@@ -58606,7 +58914,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58606
58914
|
tags: ["management", "planning", "coordination", "tracking"],
|
|
58607
58915
|
category: "management",
|
|
58608
58916
|
heartbeatIntervalMs: 15 * 60 * 1e3,
|
|
58609
|
-
icon: "clipboard"
|
|
58917
|
+
icon: "clipboard",
|
|
58918
|
+
i18n: { "zh-CN": { name: "\u9879\u76EE\u7ECF\u7406", description: "\u7BA1\u7406\u4EFB\u52A1\u3001\u534F\u8C03\u56E2\u961F\u6210\u5458\u3001\u8DDF\u8E2A\u8FDB\u5EA6\uFF0C\u786E\u4FDD\u9879\u76EE\u91CC\u7A0B\u7891\u6309\u65F6\u5B8C\u6210\u3002" } }
|
|
58610
58919
|
},
|
|
58611
58920
|
{
|
|
58612
58921
|
id: "tpl-qa-engineer",
|
|
@@ -58620,7 +58929,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58620
58929
|
skills: [],
|
|
58621
58930
|
tags: ["testing", "qa", "automation", "quality"],
|
|
58622
58931
|
category: "development",
|
|
58623
|
-
icon: "check-circle"
|
|
58932
|
+
icon: "check-circle",
|
|
58933
|
+
i18n: { "zh-CN": { name: "\u8D28\u91CF\u5DE5\u7A0B\u5E08", description: "\u81EA\u52A8\u5316\u6D4B\u8BD5\u4E13\u5BB6\uFF0C\u7F16\u5199\u6D4B\u8BD5\u7528\u4F8B\u3001\u6267\u884C\u96C6\u6210\u6D4B\u8BD5\uFF0C\u786E\u4FDD\u8F6F\u4EF6\u8D28\u91CF\u3002" } }
|
|
58624
58934
|
},
|
|
58625
58935
|
{
|
|
58626
58936
|
id: "tpl-devops",
|
|
@@ -58634,7 +58944,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58634
58944
|
skills: [],
|
|
58635
58945
|
tags: ["devops", "ci-cd", "infrastructure", "deployment", "monitoring"],
|
|
58636
58946
|
category: "devops",
|
|
58637
|
-
icon: "server"
|
|
58947
|
+
icon: "server",
|
|
58948
|
+
i18n: { "zh-CN": { name: "DevOps \u5DE5\u7A0B\u5E08", description: "\u57FA\u7840\u8BBE\u65BD\u3001CI/CD\u3001\u90E8\u7F72\u548C\u76D1\u63A7\u4E13\u5BB6\uFF0C\u7BA1\u7406\u6784\u5EFA\u6D41\u6C34\u7EBF\u548C\u8FD0\u884C\u73AF\u5883\u3002" } }
|
|
58638
58949
|
},
|
|
58639
58950
|
{
|
|
58640
58951
|
id: "tpl-tech-writer",
|
|
@@ -58648,7 +58959,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58648
58959
|
skills: [],
|
|
58649
58960
|
tags: ["documentation", "writing", "api-docs"],
|
|
58650
58961
|
category: "productivity",
|
|
58651
|
-
icon: "file-text"
|
|
58962
|
+
icon: "file-text",
|
|
58963
|
+
i18n: { "zh-CN": { name: "\u6280\u672F\u6587\u6863\u5DE5\u7A0B\u5E08", description: "\u6587\u6863\u4E13\u5BB6\uFF0C\u521B\u5EFA\u548C\u7EF4\u62A4\u6280\u672F\u6587\u6863\u3001API \u53C2\u8003\u548C\u7528\u6237\u6307\u5357\u3002" } }
|
|
58652
58964
|
},
|
|
58653
58965
|
{
|
|
58654
58966
|
id: "tpl-research-assistant",
|
|
@@ -58662,7 +58974,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58662
58974
|
skills: [],
|
|
58663
58975
|
tags: ["research", "analysis", "information-gathering"],
|
|
58664
58976
|
category: "general",
|
|
58665
|
-
icon: "book-open"
|
|
58977
|
+
icon: "book-open",
|
|
58978
|
+
i18n: { "zh-CN": { name: "\u7814\u7A76\u52A9\u7406", description: "\u6536\u96C6\u4FE1\u606F\u3001\u5206\u6790\u6570\u636E\u3001\u603B\u7ED3\u53D1\u73B0\uFF0C\u4EE5\u5FAA\u8BC1\u7814\u7A76\u652F\u6301\u51B3\u7B56\u5236\u5B9A\u3002" } }
|
|
58666
58979
|
},
|
|
58667
58980
|
{
|
|
58668
58981
|
id: "tpl-hr-specialist",
|
|
@@ -58676,7 +58989,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58676
58989
|
skills: [],
|
|
58677
58990
|
tags: ["hr", "recruitment", "onboarding", "people", "culture"],
|
|
58678
58991
|
category: "management",
|
|
58679
|
-
icon: "users"
|
|
58992
|
+
icon: "users",
|
|
58993
|
+
i18n: { "zh-CN": { name: "\u4EBA\u529B\u8D44\u6E90\u4E13\u5458", description: "\u4EBA\u529B\u8D44\u6E90\u4E13\u5BB6\uFF0C\u8D1F\u8D23\u62DB\u8058\u3001\u5165\u804C\u3001\u5236\u5EA6\u7BA1\u7406\u3001\u5458\u5DE5\u5173\u7CFB\u548C\u7EC4\u7EC7\u53D1\u5C55\u3002" } }
|
|
58680
58994
|
},
|
|
58681
58995
|
{
|
|
58682
58996
|
id: "tpl-finance-analyst",
|
|
@@ -58690,7 +59004,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58690
59004
|
skills: [],
|
|
58691
59005
|
tags: ["finance", "budget", "accounting", "forecasting", "reporting"],
|
|
58692
59006
|
category: "management",
|
|
58693
|
-
icon: "dollar-sign"
|
|
59007
|
+
icon: "dollar-sign",
|
|
59008
|
+
i18n: { "zh-CN": { name: "\u8D22\u52A1\u5206\u6790\u5E08", description: "\u8D22\u52A1\u5206\u6790\u3001\u9884\u7B97\u7F16\u5236\u3001\u8D22\u52A1\u9884\u6D4B\u3001\u8D39\u7528\u8FFD\u8E2A\u548C\u8D22\u52A1\u62A5\u544A\u4E13\u5BB6\u3002" } }
|
|
58694
59009
|
},
|
|
58695
59010
|
{
|
|
58696
59011
|
id: "tpl-marketing-specialist",
|
|
@@ -58704,7 +59019,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58704
59019
|
skills: [],
|
|
58705
59020
|
tags: ["marketing", "content", "seo", "social-media", "campaigns"],
|
|
58706
59021
|
category: "productivity",
|
|
58707
|
-
icon: "megaphone"
|
|
59022
|
+
icon: "megaphone",
|
|
59023
|
+
i18n: { "zh-CN": { name: "\u5E02\u573A\u8425\u9500\u4E13\u5458", description: "\u5E02\u573A\u8425\u9500\u7B56\u7565\u3001\u5185\u5BB9\u521B\u4F5C\u3001\u6D3B\u52A8\u7BA1\u7406\u3001SEO/SEM\u3001\u793E\u4EA4\u5A92\u4F53\u548C\u5E02\u573A\u5206\u6790\u3002" } }
|
|
58708
59024
|
},
|
|
58709
59025
|
{
|
|
58710
59026
|
id: "tpl-content-writer",
|
|
@@ -58718,7 +59034,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58718
59034
|
skills: [],
|
|
58719
59035
|
tags: ["writing", "content", "blog", "copywriting", "seo"],
|
|
58720
59036
|
category: "productivity",
|
|
58721
|
-
icon: "edit"
|
|
59037
|
+
icon: "edit",
|
|
59038
|
+
i18n: { "zh-CN": { name: "\u5185\u5BB9\u521B\u4F5C\u8005", description: "\u521B\u4F5C\u535A\u5BA2\u6587\u7AE0\u3001\u793E\u4EA4\u5A92\u4F53\u5185\u5BB9\u3001\u65B0\u95FB\u901A\u8BAF\u548C\u8425\u9500\u6587\u6848\uFF0C\u5177\u5907 SEO \u610F\u8BC6\u3002" } }
|
|
58722
59039
|
},
|
|
58723
59040
|
{
|
|
58724
59041
|
id: "tpl-customer-support",
|
|
@@ -58732,7 +59049,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58732
59049
|
skills: [],
|
|
58733
59050
|
tags: ["support", "customer-service", "helpdesk", "tickets"],
|
|
58734
59051
|
category: "general",
|
|
58735
|
-
icon: "headphones"
|
|
59052
|
+
icon: "headphones",
|
|
59053
|
+
i18n: { "zh-CN": { name: "\u5BA2\u6237\u652F\u6301", description: "\u5904\u7406\u5BA2\u6237\u54A8\u8BE2\u3001\u6545\u969C\u6392\u9664\u3001\u5DE5\u5355\u7BA1\u7406\u548C\u4EA4\u4ED8\u7269\u7BA1\u7406\u3002" } }
|
|
58736
59054
|
},
|
|
58737
59055
|
{
|
|
58738
59056
|
id: "tpl-operations-manager",
|
|
@@ -58747,7 +59065,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58747
59065
|
tags: ["operations", "process", "efficiency", "coordination"],
|
|
58748
59066
|
category: "management",
|
|
58749
59067
|
heartbeatIntervalMs: 15 * 60 * 1e3,
|
|
58750
|
-
icon: "settings"
|
|
59068
|
+
icon: "settings",
|
|
59069
|
+
i18n: { "zh-CN": { name: "\u8FD0\u8425\u7ECF\u7406", description: "\u76D1\u7763\u65E5\u5E38\u8FD0\u8425\u3001\u6D41\u7A0B\u4F18\u5316\u3001\u8D44\u6E90\u8C03\u914D\u548C\u8DE8\u90E8\u95E8\u534F\u8C03\u3002" } }
|
|
58751
59070
|
},
|
|
58752
59071
|
{
|
|
58753
59072
|
id: "tpl-product-manager",
|
|
@@ -58762,7 +59081,8 @@ function createDefaultTemplateRegistry() {
|
|
|
58762
59081
|
tags: ["product", "strategy", "roadmap", "user-research"],
|
|
58763
59082
|
category: "management",
|
|
58764
59083
|
heartbeatIntervalMs: 15 * 60 * 1e3,
|
|
58765
|
-
icon: "target"
|
|
59084
|
+
icon: "target",
|
|
59085
|
+
i18n: { "zh-CN": { name: "\u4EA7\u54C1\u7ECF\u7406", description: "\u4EA7\u54C1\u7B56\u7565\u3001\u8DEF\u7EBF\u56FE\u89C4\u5212\u3001\u7528\u6237\u7814\u7A76\u3001\u529F\u80FD\u4F18\u5148\u7EA7\u6392\u5E8F\u548C\u5229\u76CA\u76F8\u5173\u8005\u6C9F\u901A\u3002" } }
|
|
58766
59086
|
}
|
|
58767
59087
|
];
|
|
58768
59088
|
for (const tpl of builtins) {
|
|
@@ -59390,7 +59710,8 @@ function loadTeamTemplateFromDir(dirPath) {
|
|
|
59390
59710
|
category: manifest.category,
|
|
59391
59711
|
icon: manifest.icon,
|
|
59392
59712
|
announcements: existsSync21(annPath) ? readFileSync16(annPath, "utf-8") : void 0,
|
|
59393
|
-
norms: existsSync21(normsPath) ? readFileSync16(normsPath, "utf-8") : void 0
|
|
59713
|
+
norms: existsSync21(normsPath) ? readFileSync16(normsPath, "utf-8") : void 0,
|
|
59714
|
+
i18n: manifest.i18n
|
|
59394
59715
|
};
|
|
59395
59716
|
} catch (err) {
|
|
59396
59717
|
log46.warn(`Failed to load team template from ${dirPath}`, { error: String(err) });
|
|
@@ -65453,7 +65774,7 @@ var init_api_server = __esm({
|
|
|
65453
65774
|
summary: `Group chat message from ${senderName}`,
|
|
65454
65775
|
content: `[Group chat message from ${senderName}]:
|
|
65455
65776
|
${cleanText}`,
|
|
65456
|
-
extra: { senderId, senderName, channelKey }
|
|
65777
|
+
extra: { senderId, senderName, channelKey, waitForReply: false }
|
|
65457
65778
|
}, {
|
|
65458
65779
|
metadata: { senderId, senderName, senderRole: "agent" }
|
|
65459
65780
|
});
|
|
@@ -66002,7 +66323,8 @@ ${cleanText}`,
|
|
|
66002
66323
|
sourceType: isA2A ? "a2a_message" : "human_chat",
|
|
66003
66324
|
scenario: isA2A ? "a2a" : void 0,
|
|
66004
66325
|
channelContext,
|
|
66005
|
-
toolEventCollector: toolEvents
|
|
66326
|
+
toolEventCollector: toolEvents,
|
|
66327
|
+
waitForReply: isA2A ? true : void 0
|
|
66006
66328
|
});
|
|
66007
66329
|
if (!reply || !reply.trim() || reply.includes("[NO_RESPONSE]")) {
|
|
66008
66330
|
return;
|
|
@@ -66202,9 +66524,11 @@ ${cleanText}`,
|
|
|
66202
66524
|
return;
|
|
66203
66525
|
}
|
|
66204
66526
|
if (req.method === "POST" || req.method === "PUT" || req.method === "PATCH") {
|
|
66205
|
-
const contentType = req.headers["content-type"];
|
|
66206
|
-
|
|
66207
|
-
|
|
66527
|
+
const contentType = String(req.headers["content-type"] ?? "").toLowerCase();
|
|
66528
|
+
const isJson2 = contentType.includes("application/json");
|
|
66529
|
+
const isMultipart = contentType.includes("multipart/form-data");
|
|
66530
|
+
if (!isJson2 && !isMultipart) {
|
|
66531
|
+
this.json(res, 415, { error: "Content-Type must be application/json or multipart/form-data" });
|
|
66208
66532
|
return;
|
|
66209
66533
|
}
|
|
66210
66534
|
}
|
|
@@ -66234,7 +66558,10 @@ ${cleanText}`,
|
|
|
66234
66558
|
}
|
|
66235
66559
|
async route(req, res, path, url) {
|
|
66236
66560
|
if (req.method === "POST" || req.method === "PUT" || req.method === "PATCH") {
|
|
66237
|
-
|
|
66561
|
+
const ct = String(req.headers["content-type"] ?? "").toLowerCase();
|
|
66562
|
+
if (!ct.includes("multipart/form-data")) {
|
|
66563
|
+
await this.readBody(req);
|
|
66564
|
+
}
|
|
66238
66565
|
}
|
|
66239
66566
|
if (path === "/api/auth/login" && req.method === "POST") {
|
|
66240
66567
|
const body = await this.readBody(req);
|
|
@@ -66959,7 +67286,7 @@ ${cleanText}`,
|
|
|
66959
67286
|
const reply = await targetAgent.sendMessage(messageText, fromAgentId, {
|
|
66960
67287
|
name: fromAgent.config.name,
|
|
66961
67288
|
role: fromAgent.config.agentRole ?? "worker"
|
|
66962
|
-
}, { sourceType: "a2a_message" });
|
|
67289
|
+
}, { sourceType: "a2a_message", waitForReply: true });
|
|
66963
67290
|
this.json(res, 200, { from: fromAgentId, to: agentId2, reply });
|
|
66964
67291
|
return;
|
|
66965
67292
|
}
|
|
@@ -69641,8 +69968,28 @@ EXPLANATION_END`;
|
|
|
69641
69968
|
const builtinDir = resolve13(process.cwd(), "templates", "skills");
|
|
69642
69969
|
const found = discoverSkillsInDir(builtinDir);
|
|
69643
69970
|
const installedSkills = new Map((this.skillRegistry?.list() ?? []).map((s) => [s.name, s]));
|
|
69644
|
-
const
|
|
69971
|
+
const rawManifests = /* @__PURE__ */ new Map();
|
|
69972
|
+
try {
|
|
69973
|
+
const { readdirSync: readdirSync13, readFileSync: readFileSync26, existsSync: existsSync36 } = await import("node:fs");
|
|
69974
|
+
for (const entry of readdirSync13(builtinDir, { withFileTypes: true })) {
|
|
69975
|
+
if (!entry.isDirectory())
|
|
69976
|
+
continue;
|
|
69977
|
+
const sjPath = resolve13(builtinDir, entry.name, "skill.json");
|
|
69978
|
+
if (existsSync36(sjPath)) {
|
|
69979
|
+
try {
|
|
69980
|
+
rawManifests.set(entry.name, JSON.parse(readFileSync26(sjPath, "utf-8")));
|
|
69981
|
+
} catch {
|
|
69982
|
+
}
|
|
69983
|
+
}
|
|
69984
|
+
}
|
|
69985
|
+
} catch {
|
|
69986
|
+
}
|
|
69987
|
+
const skills = found.filter(({ manifest }) => {
|
|
69988
|
+
const raw = rawManifests.get(manifest.name);
|
|
69989
|
+
return !raw?.hidden;
|
|
69990
|
+
}).map(({ manifest, path: p }) => {
|
|
69645
69991
|
const inst = installedSkills.get(manifest.name);
|
|
69992
|
+
const raw = rawManifests.get(manifest.name);
|
|
69646
69993
|
return {
|
|
69647
69994
|
name: manifest.name,
|
|
69648
69995
|
version: manifest.version,
|
|
@@ -69652,10 +69999,12 @@ EXPLANATION_END`;
|
|
|
69652
69999
|
tags: manifest.tags ?? [],
|
|
69653
70000
|
hasMcpServers: !!manifest.mcpServers && Object.keys(manifest.mcpServers).length > 0,
|
|
69654
70001
|
hasInstructions: !!manifest.instructions,
|
|
70002
|
+
instructions: manifest.instructions ?? void 0,
|
|
69655
70003
|
requiredPermissions: manifest.requiredPermissions ?? [],
|
|
69656
70004
|
sourcePath: p,
|
|
69657
70005
|
installed: !!inst,
|
|
69658
|
-
installedVersion: inst?.version ?? null
|
|
70006
|
+
installedVersion: inst?.version ?? null,
|
|
70007
|
+
i18n: raw?.i18n ?? void 0
|
|
69659
70008
|
};
|
|
69660
70009
|
});
|
|
69661
70010
|
this.json(res, 200, { skills });
|
|
@@ -70171,6 +70520,132 @@ EXPLANATION_END`;
|
|
|
70171
70520
|
return;
|
|
70172
70521
|
}
|
|
70173
70522
|
}
|
|
70523
|
+
{
|
|
70524
|
+
const imgPostMatch = path.match(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)\/images$/);
|
|
70525
|
+
if (imgPostMatch && req.method === "POST") {
|
|
70526
|
+
const rawType = imgPostMatch[1];
|
|
70527
|
+
const name = decodeURIComponent(imgPostMatch[2]);
|
|
70528
|
+
const typeDir = rawType.endsWith("s") ? rawType : rawType + "s";
|
|
70529
|
+
const type = typeDir === "agents" ? "agent" : typeDir === "teams" ? "team" : "skill";
|
|
70530
|
+
const artDir = join22(homedir14(), ".markus", "builder-artifacts", typeDir, name);
|
|
70531
|
+
if (!existsSync26(artDir)) {
|
|
70532
|
+
this.json(res, 404, { error: "Artifact not found" });
|
|
70533
|
+
return;
|
|
70534
|
+
}
|
|
70535
|
+
try {
|
|
70536
|
+
const imagesDir = join22(artDir, "images");
|
|
70537
|
+
if (!existsSync26(imagesDir))
|
|
70538
|
+
mkdirSync18(imagesDir, { recursive: true });
|
|
70539
|
+
const chunks = [];
|
|
70540
|
+
for await (const chunk of req)
|
|
70541
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
70542
|
+
const body = Buffer.concat(chunks);
|
|
70543
|
+
const contentType = req.headers["content-type"] ?? "";
|
|
70544
|
+
if (contentType.includes("multipart/form-data")) {
|
|
70545
|
+
const boundary = contentType.split("boundary=")[1]?.split(";")[0];
|
|
70546
|
+
if (!boundary) {
|
|
70547
|
+
this.json(res, 400, { error: "Missing boundary" });
|
|
70548
|
+
return;
|
|
70549
|
+
}
|
|
70550
|
+
const bodyStr = body.toString("latin1");
|
|
70551
|
+
const parts = bodyStr.split("--" + boundary).filter((p) => p.includes("Content-Disposition"));
|
|
70552
|
+
for (const part of parts) {
|
|
70553
|
+
const nameMatch = part.match(/filename="([^"]+)"/);
|
|
70554
|
+
if (!nameMatch)
|
|
70555
|
+
continue;
|
|
70556
|
+
const filename = nameMatch[1].replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
70557
|
+
const headerEnd = part.indexOf("\r\n\r\n");
|
|
70558
|
+
if (headerEnd < 0)
|
|
70559
|
+
continue;
|
|
70560
|
+
const fileContent = part.slice(headerEnd + 4).replace(/\r\n$/, "").replace(/\r\n--$/, "");
|
|
70561
|
+
const filePath = join22(imagesDir, filename);
|
|
70562
|
+
writeFileSync16(filePath, Buffer.from(fileContent, "latin1"));
|
|
70563
|
+
const manifestFile = join22(artDir, `${type}.json`);
|
|
70564
|
+
if (existsSync26(manifestFile)) {
|
|
70565
|
+
try {
|
|
70566
|
+
const manifest = JSON.parse(readFileSync20(manifestFile, "utf-8"));
|
|
70567
|
+
const screenshots = manifest.screenshots ?? [];
|
|
70568
|
+
const relPath = `images/${filename}`;
|
|
70569
|
+
if (!screenshots.includes(relPath)) {
|
|
70570
|
+
screenshots.push(relPath);
|
|
70571
|
+
manifest.screenshots = screenshots;
|
|
70572
|
+
if (!manifest.thumbnail)
|
|
70573
|
+
manifest.thumbnail = relPath;
|
|
70574
|
+
writeFileSync16(manifestFile, JSON.stringify(manifest, null, 2));
|
|
70575
|
+
}
|
|
70576
|
+
} catch {
|
|
70577
|
+
}
|
|
70578
|
+
}
|
|
70579
|
+
this.json(res, 200, { filename, path: `images/${filename}` });
|
|
70580
|
+
return;
|
|
70581
|
+
}
|
|
70582
|
+
this.json(res, 400, { error: "No image file found in upload" });
|
|
70583
|
+
} else {
|
|
70584
|
+
this.json(res, 400, { error: "Expected multipart/form-data" });
|
|
70585
|
+
}
|
|
70586
|
+
} catch (err) {
|
|
70587
|
+
this.json(res, 500, { error: `Upload failed: ${String(err)}` });
|
|
70588
|
+
}
|
|
70589
|
+
return;
|
|
70590
|
+
}
|
|
70591
|
+
}
|
|
70592
|
+
{
|
|
70593
|
+
const imgGetMatch = path.match(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)\/images\/([^/]+)$/);
|
|
70594
|
+
if (imgGetMatch && req.method === "GET") {
|
|
70595
|
+
const rawType = imgGetMatch[1];
|
|
70596
|
+
const name = decodeURIComponent(imgGetMatch[2]);
|
|
70597
|
+
const filename = decodeURIComponent(imgGetMatch[3]);
|
|
70598
|
+
const typeDir = rawType.endsWith("s") ? rawType : rawType + "s";
|
|
70599
|
+
const filePath = join22(homedir14(), ".markus", "builder-artifacts", typeDir, name, "images", filename);
|
|
70600
|
+
if (!existsSync26(filePath)) {
|
|
70601
|
+
this.json(res, 404, { error: "Image not found" });
|
|
70602
|
+
return;
|
|
70603
|
+
}
|
|
70604
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
|
70605
|
+
const mimeTypes = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", svg: "image/svg+xml" };
|
|
70606
|
+
res.writeHead(200, { "Content-Type": mimeTypes[ext] ?? "application/octet-stream", "Cache-Control": "public, max-age=3600" });
|
|
70607
|
+
res.end(readFileSync20(filePath));
|
|
70608
|
+
return;
|
|
70609
|
+
}
|
|
70610
|
+
}
|
|
70611
|
+
{
|
|
70612
|
+
const imgDelMatch = path.match(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)\/images\/([^/]+)$/);
|
|
70613
|
+
if (imgDelMatch && req.method === "DELETE") {
|
|
70614
|
+
const rawType = imgDelMatch[1];
|
|
70615
|
+
const name = decodeURIComponent(imgDelMatch[2]);
|
|
70616
|
+
const filename = decodeURIComponent(imgDelMatch[3]);
|
|
70617
|
+
const typeDir = rawType.endsWith("s") ? rawType : rawType + "s";
|
|
70618
|
+
const type = typeDir === "agents" ? "agent" : typeDir === "teams" ? "team" : "skill";
|
|
70619
|
+
const artDir = join22(homedir14(), ".markus", "builder-artifacts", typeDir, name);
|
|
70620
|
+
const filePath = join22(artDir, "images", filename);
|
|
70621
|
+
if (!existsSync26(filePath)) {
|
|
70622
|
+
this.json(res, 404, { error: "Image not found" });
|
|
70623
|
+
return;
|
|
70624
|
+
}
|
|
70625
|
+
try {
|
|
70626
|
+
rmSync3(filePath);
|
|
70627
|
+
const manifestFile = join22(artDir, `${type}.json`);
|
|
70628
|
+
if (existsSync26(manifestFile)) {
|
|
70629
|
+
try {
|
|
70630
|
+
const manifest = JSON.parse(readFileSync20(manifestFile, "utf-8"));
|
|
70631
|
+
const relPath = `images/${filename}`;
|
|
70632
|
+
if (Array.isArray(manifest.screenshots)) {
|
|
70633
|
+
manifest.screenshots = manifest.screenshots.filter((s) => s !== relPath);
|
|
70634
|
+
}
|
|
70635
|
+
if (manifest.thumbnail === relPath) {
|
|
70636
|
+
manifest.thumbnail = manifest.screenshots?.[0] ?? void 0;
|
|
70637
|
+
}
|
|
70638
|
+
writeFileSync16(manifestFile, JSON.stringify(manifest, null, 2));
|
|
70639
|
+
} catch {
|
|
70640
|
+
}
|
|
70641
|
+
}
|
|
70642
|
+
this.json(res, 200, { deleted: true, filename });
|
|
70643
|
+
} catch (err) {
|
|
70644
|
+
this.json(res, 500, { error: `Delete failed: ${String(err)}` });
|
|
70645
|
+
}
|
|
70646
|
+
return;
|
|
70647
|
+
}
|
|
70648
|
+
}
|
|
70174
70649
|
if (path === "/api/skills/registry/skillhub" && req.method === "GET") {
|
|
70175
70650
|
const q = url.searchParams.get("q") ?? "";
|
|
70176
70651
|
const category = url.searchParams.get("category") ?? "";
|
|
@@ -70361,6 +70836,47 @@ EXPLANATION_END`;
|
|
|
70361
70836
|
this.json(res, 200, { template });
|
|
70362
70837
|
return;
|
|
70363
70838
|
}
|
|
70839
|
+
if (path.match(/^\/api\/templates\/[^/]+\/files$/) && req.method === "GET") {
|
|
70840
|
+
if (!this.templateRegistry) {
|
|
70841
|
+
this.json(res, 404, { error: "Template registry not configured" });
|
|
70842
|
+
return;
|
|
70843
|
+
}
|
|
70844
|
+
const templateId = path.split("/")[3];
|
|
70845
|
+
const template = this.templateRegistry.get(templateId);
|
|
70846
|
+
if (!template) {
|
|
70847
|
+
this.json(res, 404, { error: `Template not found: ${templateId}` });
|
|
70848
|
+
return;
|
|
70849
|
+
}
|
|
70850
|
+
const { existsSync: ex, readFileSync: rf, readdirSync: rd } = await import("node:fs");
|
|
70851
|
+
const roleId = template.roleId;
|
|
70852
|
+
const candidates = [
|
|
70853
|
+
resolve13(process.cwd(), "templates", "roles", roleId)
|
|
70854
|
+
];
|
|
70855
|
+
try {
|
|
70856
|
+
const thisFile = (await import("node:url")).fileURLToPath(import.meta.url);
|
|
70857
|
+
const thisDir = (await import("node:path")).dirname(thisFile);
|
|
70858
|
+
candidates.unshift(resolve13(thisDir, "..", "templates", "roles", roleId));
|
|
70859
|
+
candidates.push(resolve13(thisDir, "..", "..", "..", "..", "templates", "roles", roleId));
|
|
70860
|
+
} catch {
|
|
70861
|
+
}
|
|
70862
|
+
const roleDir = candidates.find((d) => ex(d));
|
|
70863
|
+
const files = {};
|
|
70864
|
+
if (roleDir) {
|
|
70865
|
+
try {
|
|
70866
|
+
for (const entry of rd(roleDir, { withFileTypes: true })) {
|
|
70867
|
+
if (entry.isFile() && !entry.name.endsWith(".json")) {
|
|
70868
|
+
try {
|
|
70869
|
+
files[entry.name] = rf(resolve13(roleDir, entry.name), "utf-8");
|
|
70870
|
+
} catch {
|
|
70871
|
+
}
|
|
70872
|
+
}
|
|
70873
|
+
}
|
|
70874
|
+
} catch {
|
|
70875
|
+
}
|
|
70876
|
+
}
|
|
70877
|
+
this.json(res, 200, { files });
|
|
70878
|
+
return;
|
|
70879
|
+
}
|
|
70364
70880
|
if (path === "/api/templates/instantiate" && req.method === "POST") {
|
|
70365
70881
|
const body = await this.readBody(req);
|
|
70366
70882
|
const templateId = body["templateId"];
|
|
@@ -70851,14 +71367,27 @@ EXPLANATION_END`;
|
|
|
70851
71367
|
const hubPath = path.slice("/api/hub".length);
|
|
70852
71368
|
const reqUrl = new URL(req.url, `http://${req.headers.host}`);
|
|
70853
71369
|
const hubTargetUrl = `${this.hubUrl}/api${hubPath}${reqUrl.search}`;
|
|
70854
|
-
const
|
|
71370
|
+
const ct = String(req.headers["content-type"] ?? "").toLowerCase();
|
|
71371
|
+
const isMultipart = ct.includes("multipart/form-data");
|
|
71372
|
+
const proxyHeaders = {};
|
|
71373
|
+
if (!isMultipart)
|
|
71374
|
+
proxyHeaders["Content-Type"] = "application/json";
|
|
71375
|
+
else
|
|
71376
|
+
proxyHeaders["Content-Type"] = req.headers["content-type"];
|
|
70855
71377
|
const authHeader = req.headers["authorization"];
|
|
70856
71378
|
if (authHeader)
|
|
70857
71379
|
proxyHeaders["Authorization"] = authHeader;
|
|
70858
71380
|
try {
|
|
70859
71381
|
let body;
|
|
70860
71382
|
if (req.method === "POST" || req.method === "PUT" || req.method === "PATCH") {
|
|
70861
|
-
|
|
71383
|
+
if (isMultipart) {
|
|
71384
|
+
const chunks = [];
|
|
71385
|
+
for await (const chunk of req)
|
|
71386
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
71387
|
+
body = Buffer.concat(chunks);
|
|
71388
|
+
} else {
|
|
71389
|
+
body = JSON.stringify(await this.readBody(req));
|
|
71390
|
+
}
|
|
70862
71391
|
}
|
|
70863
71392
|
let hubRes = await fetch(hubTargetUrl, {
|
|
70864
71393
|
method: req.method,
|
|
@@ -70960,7 +71489,10 @@ EXPLANATION_END`;
|
|
|
70960
71489
|
}
|
|
70961
71490
|
if (path === "/api/settings/agent" && req.method === "GET") {
|
|
70962
71491
|
const am = this.orgService.getAgentManager();
|
|
70963
|
-
this.json(res, 200, {
|
|
71492
|
+
this.json(res, 200, {
|
|
71493
|
+
maxToolIterations: am.maxToolIterations,
|
|
71494
|
+
cognitive: am.cognitiveConfig ?? { enabled: false }
|
|
71495
|
+
});
|
|
70964
71496
|
return;
|
|
70965
71497
|
}
|
|
70966
71498
|
if (path === "/api/settings/agent" && req.method === "POST") {
|
|
@@ -70974,6 +71506,16 @@ EXPLANATION_END`;
|
|
|
70974
71506
|
am.maxToolIterations = body["maxToolIterations"];
|
|
70975
71507
|
changed = true;
|
|
70976
71508
|
}
|
|
71509
|
+
if (body["cognitive"] && typeof body["cognitive"] === "object") {
|
|
71510
|
+
const cc = body["cognitive"];
|
|
71511
|
+
am.cognitiveConfig = {
|
|
71512
|
+
enabled: cc["enabled"] === true,
|
|
71513
|
+
maxDepth: typeof cc["maxDepth"] === "number" ? cc["maxDepth"] : void 0,
|
|
71514
|
+
appraisalModel: typeof cc["appraisalModel"] === "string" ? cc["appraisalModel"] : void 0,
|
|
71515
|
+
timeoutMs: typeof cc["timeoutMs"] === "number" ? cc["timeoutMs"] : void 0
|
|
71516
|
+
};
|
|
71517
|
+
changed = true;
|
|
71518
|
+
}
|
|
70977
71519
|
if (changed) {
|
|
70978
71520
|
try {
|
|
70979
71521
|
saveConfig({ agent: { maxToolIterations: am.maxToolIterations } }, this.markusConfigPath);
|
|
@@ -70994,7 +71536,10 @@ EXPLANATION_END`;
|
|
|
70994
71536
|
success: true
|
|
70995
71537
|
});
|
|
70996
71538
|
}
|
|
70997
|
-
this.json(res, 200, {
|
|
71539
|
+
this.json(res, 200, {
|
|
71540
|
+
maxToolIterations: am.maxToolIterations,
|
|
71541
|
+
cognitive: am.cognitiveConfig ?? { enabled: false }
|
|
71542
|
+
});
|
|
70998
71543
|
return;
|
|
70999
71544
|
}
|
|
71000
71545
|
if (path === "/api/settings/browser" && req.method === "GET") {
|
|
@@ -72096,6 +72641,48 @@ EXPLANATION_END`;
|
|
|
72096
72641
|
this.json(res, 201, { template: tpl });
|
|
72097
72642
|
return;
|
|
72098
72643
|
}
|
|
72644
|
+
if (path.match(/^\/api\/team-templates\/[^/]+\/files$/) && req.method === "GET") {
|
|
72645
|
+
const id = path.split("/")[3];
|
|
72646
|
+
const tpl = this.teamTemplateRegistry.get(id);
|
|
72647
|
+
if (!tpl) {
|
|
72648
|
+
this.json(res, 404, { error: "Team template not found" });
|
|
72649
|
+
return;
|
|
72650
|
+
}
|
|
72651
|
+
const { existsSync: ex, readFileSync: rf, readdirSync: rd } = await import("node:fs");
|
|
72652
|
+
const rolesDir = resolve13(process.cwd(), "templates", "roles");
|
|
72653
|
+
const rolesCandidates = [rolesDir];
|
|
72654
|
+
try {
|
|
72655
|
+
const thisFile = (await import("node:url")).fileURLToPath(import.meta.url);
|
|
72656
|
+
const thisDir = (await import("node:path")).dirname(thisFile);
|
|
72657
|
+
rolesCandidates.unshift(resolve13(thisDir, "..", "templates", "roles"));
|
|
72658
|
+
rolesCandidates.push(resolve13(thisDir, "..", "..", "..", "..", "templates", "roles"));
|
|
72659
|
+
} catch {
|
|
72660
|
+
}
|
|
72661
|
+
const rolesRoot = rolesCandidates.find((d) => ex(d)) ?? rolesDir;
|
|
72662
|
+
const files = {};
|
|
72663
|
+
for (const member of tpl.members) {
|
|
72664
|
+
const roleName = member.roleName;
|
|
72665
|
+
if (!roleName)
|
|
72666
|
+
continue;
|
|
72667
|
+
const memberSlug = (member.name ?? roleName).toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
|
|
72668
|
+
const roleDir = resolve13(rolesRoot, roleName);
|
|
72669
|
+
if (!ex(roleDir))
|
|
72670
|
+
continue;
|
|
72671
|
+
try {
|
|
72672
|
+
for (const entry of rd(roleDir, { withFileTypes: true })) {
|
|
72673
|
+
if (entry.isFile() && !entry.name.endsWith(".json")) {
|
|
72674
|
+
try {
|
|
72675
|
+
files[`members/${memberSlug}/${entry.name}`] = rf(resolve13(roleDir, entry.name), "utf-8");
|
|
72676
|
+
} catch {
|
|
72677
|
+
}
|
|
72678
|
+
}
|
|
72679
|
+
}
|
|
72680
|
+
} catch {
|
|
72681
|
+
}
|
|
72682
|
+
}
|
|
72683
|
+
this.json(res, 200, { files });
|
|
72684
|
+
return;
|
|
72685
|
+
}
|
|
72099
72686
|
if (path.startsWith("/api/team-templates/") && req.method === "GET") {
|
|
72100
72687
|
const id = path.split("/")[3];
|
|
72101
72688
|
const tpl = this.teamTemplateRegistry.get(id);
|
|
@@ -73296,6 +73883,8 @@ EXPLANATION_END`;
|
|
|
73296
73883
|
regex(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)$/, "GET", "DELETE"),
|
|
73297
73884
|
regex(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)\/install$/, "POST"),
|
|
73298
73885
|
regex(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)\/uninstall$/, "POST"),
|
|
73886
|
+
regex(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)\/images$/, "POST"),
|
|
73887
|
+
regex(/^\/api\/builder\/artifacts\/(agents?|teams?|skills?)\/([^/]+)\/images\/([^/]+)$/, "GET", "DELETE"),
|
|
73299
73888
|
// ── Hub ──────────────────────────────────────────────────────────────
|
|
73300
73889
|
exact("/api/hub/publish", "POST"),
|
|
73301
73890
|
startsWith("/api/hub/", "GET", "POST", "PUT", "PATCH"),
|
|
@@ -81472,6 +82061,15 @@ async function createServices(config) {
|
|
|
81472
82061
|
if (config.agent?.maxToolIterations) {
|
|
81473
82062
|
agentManager.maxToolIterations = config.agent.maxToolIterations;
|
|
81474
82063
|
}
|
|
82064
|
+
if (config.agent?.cognitive) {
|
|
82065
|
+
const cc = config.agent.cognitive;
|
|
82066
|
+
agentManager.cognitiveConfig = {
|
|
82067
|
+
enabled: cc.enabled ?? false,
|
|
82068
|
+
maxDepth: cc.maxDepth,
|
|
82069
|
+
appraisalModel: cc.appraisalModel,
|
|
82070
|
+
timeoutMs: cc.timeoutMs
|
|
82071
|
+
};
|
|
82072
|
+
}
|
|
81475
82073
|
if (config.browser?.bringToFront !== void 0) {
|
|
81476
82074
|
agentManager.setBrowserBringToFront(config.browser.bringToFront);
|
|
81477
82075
|
}
|