morpheus-cli 0.4.15 → 0.5.1
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/README.md +293 -1115
- package/dist/channels/telegram.js +379 -74
- package/dist/cli/commands/doctor.js +34 -0
- package/dist/cli/commands/init.js +128 -0
- package/dist/cli/commands/restart.js +32 -14
- package/dist/cli/commands/start.js +28 -12
- package/dist/config/manager.js +82 -0
- package/dist/config/mcp-manager.js +19 -1
- package/dist/config/schemas.js +9 -0
- package/dist/devkit/tools/network.js +1 -1
- package/dist/http/api.js +399 -10
- package/dist/runtime/apoc.js +25 -17
- package/dist/runtime/memory/sati/repository.js +30 -2
- package/dist/runtime/memory/sati/service.js +46 -15
- package/dist/runtime/memory/sati/system-prompts.js +71 -29
- package/dist/runtime/memory/session-embedding-worker.js +3 -3
- package/dist/runtime/memory/sqlite.js +24 -0
- package/dist/runtime/memory/trinity-db.js +203 -0
- package/dist/runtime/neo.js +124 -0
- package/dist/runtime/oracle.js +252 -205
- package/dist/runtime/providers/factory.js +1 -12
- package/dist/runtime/session-embedding-scheduler.js +1 -1
- package/dist/runtime/tasks/context.js +53 -0
- package/dist/runtime/tasks/dispatcher.js +91 -0
- package/dist/runtime/tasks/notifier.js +68 -0
- package/dist/runtime/tasks/repository.js +370 -0
- package/dist/runtime/tasks/types.js +1 -0
- package/dist/runtime/tasks/worker.js +99 -0
- package/dist/runtime/tools/__tests__/tools.test.js +1 -3
- package/dist/runtime/tools/apoc-tool.js +61 -8
- package/dist/runtime/tools/delegation-guard.js +29 -0
- package/dist/runtime/tools/factory.js +1 -1
- package/dist/runtime/tools/index.js +2 -3
- package/dist/runtime/tools/morpheus-tools.js +742 -0
- package/dist/runtime/tools/neo-tool.js +109 -0
- package/dist/runtime/tools/trinity-tool.js +98 -0
- package/dist/runtime/trinity-connector.js +611 -0
- package/dist/runtime/trinity-crypto.js +52 -0
- package/dist/runtime/trinity.js +246 -0
- package/dist/runtime/webhooks/dispatcher.js +10 -19
- package/dist/types/config.js +10 -0
- package/dist/ui/assets/index-DP2V4kRd.js +112 -0
- package/dist/ui/assets/index-mglRG5Zw.css +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/ui/sw.js +1 -1
- package/package.json +6 -1
- package/dist/runtime/tools/analytics-tools.js +0 -139
- package/dist/runtime/tools/config-tools.js +0 -64
- package/dist/runtime/tools/diagnostic-tools.js +0 -153
- package/dist/ui/assets/index-LemKVRjC.js +0 -112
- package/dist/ui/assets/index-TCQ7VNYO.css +0 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { tool } from "@langchain/core/tools";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
3
|
+
import { TaskRepository } from "../tasks/repository.js";
|
|
4
|
+
import { TaskRequestContext } from "../tasks/context.js";
|
|
5
|
+
import { compositeDelegationError, isLikelyCompositeDelegationTask } from "./delegation-guard.js";
|
|
6
|
+
import { DisplayManager } from "../display.js";
|
|
4
7
|
/**
|
|
5
8
|
* Tool that Oracle uses to delegate devtools tasks to Apoc.
|
|
6
9
|
* Oracle should call this whenever the user requests operations like:
|
|
@@ -14,16 +17,66 @@ import { Apoc } from "../apoc.js";
|
|
|
14
17
|
*/
|
|
15
18
|
export const ApocDelegateTool = tool(async ({ task, context }) => {
|
|
16
19
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const display = DisplayManager.getInstance();
|
|
21
|
+
if (isLikelyCompositeDelegationTask(task)) {
|
|
22
|
+
display.log(`Apoc delegation rejected (non-atomic task): ${task.slice(0, 140)}`, {
|
|
23
|
+
source: "ApocDelegateTool",
|
|
24
|
+
level: "warning",
|
|
25
|
+
});
|
|
26
|
+
return compositeDelegationError();
|
|
27
|
+
}
|
|
28
|
+
const existingAck = TaskRequestContext.findDuplicateDelegation("apoc", task);
|
|
29
|
+
if (existingAck) {
|
|
30
|
+
display.log(`Apoc delegation deduplicated. Reusing task ${existingAck.task_id}.`, {
|
|
31
|
+
source: "ApocDelegateTool",
|
|
32
|
+
level: "info",
|
|
33
|
+
});
|
|
34
|
+
return `Task ${existingAck.task_id} already queued for ${existingAck.agent} execution.`;
|
|
35
|
+
}
|
|
36
|
+
if (!TaskRequestContext.canEnqueueDelegation()) {
|
|
37
|
+
display.log(`Apoc delegation blocked by per-turn limit.`, {
|
|
38
|
+
source: "ApocDelegateTool",
|
|
39
|
+
level: "warning",
|
|
40
|
+
});
|
|
41
|
+
return "Delegation limit reached for this user turn. Split the request or wait for current tasks.";
|
|
42
|
+
}
|
|
43
|
+
const ctx = TaskRequestContext.get();
|
|
44
|
+
const repository = TaskRepository.getInstance();
|
|
45
|
+
const created = repository.createTask({
|
|
46
|
+
agent: "apoc",
|
|
47
|
+
input: task,
|
|
48
|
+
context: context ?? null,
|
|
49
|
+
origin_channel: ctx?.origin_channel ?? "api",
|
|
50
|
+
session_id: ctx?.session_id ?? "default",
|
|
51
|
+
origin_message_id: ctx?.origin_message_id ?? null,
|
|
52
|
+
origin_user_id: ctx?.origin_user_id ?? null,
|
|
53
|
+
max_attempts: 3,
|
|
54
|
+
});
|
|
55
|
+
TaskRequestContext.setDelegationAck({ task_id: created.id, agent: "apoc", task });
|
|
56
|
+
display.log(`Apoc task created: ${created.id}`, {
|
|
57
|
+
source: "ApocDelegateTool",
|
|
58
|
+
level: "info",
|
|
59
|
+
meta: {
|
|
60
|
+
agent: created.agent,
|
|
61
|
+
origin_channel: created.origin_channel,
|
|
62
|
+
session_id: created.session_id,
|
|
63
|
+
input: created.input,
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return `Task ${created.id} queued for Apoc execution.`;
|
|
20
67
|
}
|
|
21
68
|
catch (err) {
|
|
22
|
-
|
|
69
|
+
const display = DisplayManager.getInstance();
|
|
70
|
+
display.log(`ApocDelegateTool error: ${err.message}`, { source: "ApocDelegateTool", level: "error" });
|
|
71
|
+
return `Apoc task enqueue failed: ${err.message}`;
|
|
23
72
|
}
|
|
24
73
|
}, {
|
|
25
74
|
name: "apoc_delegate",
|
|
26
|
-
description: `Delegate a devtools task to Apoc, the specialized development subagent.
|
|
75
|
+
description: `Delegate a devtools task to Apoc, the specialized development subagent, asynchronously.
|
|
76
|
+
|
|
77
|
+
This tool enqueues a background task and returns an acknowledgement with task id.
|
|
78
|
+
Do not expect final execution output in the same response.
|
|
79
|
+
Each task must contain a single atomic action with a clear expected result.
|
|
27
80
|
|
|
28
81
|
Use this tool when the user asks for ANY of the following:
|
|
29
82
|
- File operations: read, write, create, delete files or directories
|
|
@@ -39,7 +92,7 @@ Use this tool when the user asks for ANY of the following:
|
|
|
39
92
|
Provide a clear natural language task description. Optionally provide context
|
|
40
93
|
from the current conversation to help Apoc understand the broader goal.`,
|
|
41
94
|
schema: z.object({
|
|
42
|
-
task: z.string().describe("Clear description of the devtools task to execute"),
|
|
43
|
-
context: z.string().optional().describe("Optional context from the conversation to help Apoc understand the goal"),
|
|
95
|
+
task: z.string().describe("Clear description of the devtools task to execute **in the user's language**"),
|
|
96
|
+
context: z.string().optional().describe("Optional context from the conversation to help Apoc understand the goal **in the user's language**"),
|
|
44
97
|
}),
|
|
45
98
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function normalize(text) {
|
|
2
|
+
return text
|
|
3
|
+
.toLowerCase()
|
|
4
|
+
.replace(/\s+/g, " ")
|
|
5
|
+
.trim();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Heuristic guard to reject clearly multi-action delegations.
|
|
9
|
+
* Allows phrases like "do X and return/report Y".
|
|
10
|
+
*/
|
|
11
|
+
export function isLikelyCompositeDelegationTask(task) {
|
|
12
|
+
const t = normalize(task);
|
|
13
|
+
if (!t)
|
|
14
|
+
return false;
|
|
15
|
+
if (/[;\n]/.test(t))
|
|
16
|
+
return true;
|
|
17
|
+
const conjunction = /\b(and|then|also|e|depois|tambem|também|alem disso|além disso)\b/;
|
|
18
|
+
if (!conjunction.test(t))
|
|
19
|
+
return false;
|
|
20
|
+
// "and return/report" is usually part of a single atomic objective.
|
|
21
|
+
const allowedSecondStep = /\b(and|then|e|depois)\s+(return|report|summarize|retorne|informe|resuma|mostre|show)\b/;
|
|
22
|
+
if (allowedSecondStep.test(t))
|
|
23
|
+
return false;
|
|
24
|
+
const actionVerbAfterConjunction = /\b(and|then|also|e|depois|tambem|também)\s+(check|ping|run|execute|search|fetch|get|list|create|update|delete|open|verify|consult|verificar|fazer|executar|buscar|obter|listar|criar|atualizar|deletar|abrir)\b/;
|
|
25
|
+
return actionVerbAfterConjunction.test(t);
|
|
26
|
+
}
|
|
27
|
+
export function compositeDelegationError() {
|
|
28
|
+
return "Delegation rejected: task must be atomic (single action). Split this request into multiple delegations, one task per action/tool.";
|
|
29
|
+
}
|
|
@@ -85,7 +85,7 @@ export class Construtor {
|
|
|
85
85
|
const newName = `${serverName}_${originalName}`;
|
|
86
86
|
Object.defineProperty(tool, "name", { value: newName });
|
|
87
87
|
const shortDesc = tool.description && typeof tool.description === 'string' ? tool.description.slice(0, 100) + '...' : '';
|
|
88
|
-
display.log(
|
|
88
|
+
display.log(`Loaded MCP tool: ${tool.name} (from ${serverName})`, { level: 'info', source: 'Construtor' });
|
|
89
89
|
});
|
|
90
90
|
// Sanitize tool schemas to remove fields not supported by Gemini
|
|
91
91
|
const sanitizedTools = tools.map(tool => wrapToolWithSanitizedSchema(tool));
|