@agentprojectcontext/apx 1.6.0 → 1.8.0
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 +4 -0
- package/package.json +1 -1
- package/src/cli/commands/config.js +23 -0
- package/src/cli/commands/messages.js +45 -0
- package/src/cli/commands/routine.js +27 -2
- package/src/cli/commands/setup.js +2 -2
- package/src/cli/index.js +969 -3
- package/src/core/apc-context-skill.md +3 -0
- package/src/core/apx-skill.md +30 -0
- package/src/core/config.js +2 -0
- package/src/core/mascot.js +5 -7
- package/src/core/messages-store.js +94 -20
- package/src/core/routines-store.js +3 -1
- package/src/daemon/api.js +3 -3
- package/src/daemon/index.js +38 -2
- package/src/daemon/plugins/telegram.js +32 -2
- package/src/daemon/routines.js +64 -2
- package/src/daemon/super-agent-tools/helpers.js +120 -0
- package/src/daemon/super-agent-tools/index.js +56 -0
- package/src/daemon/super-agent-tools/tools/add-project.js +36 -0
- package/src/daemon/super-agent-tools/tools/call-agent.js +45 -0
- package/src/daemon/super-agent-tools/tools/call-mcp.js +30 -0
- package/src/daemon/super-agent-tools/tools/call-runtime.js +107 -0
- package/src/daemon/super-agent-tools/tools/edit-file.js +44 -0
- package/src/daemon/super-agent-tools/tools/import-agent.js +48 -0
- package/src/daemon/super-agent-tools/tools/list-agents.js +36 -0
- package/src/daemon/super-agent-tools/tools/list-files.js +38 -0
- package/src/daemon/super-agent-tools/tools/list-mcps.js +48 -0
- package/src/daemon/super-agent-tools/tools/list-projects.js +20 -0
- package/src/daemon/super-agent-tools/tools/list-vault-agents.js +18 -0
- package/src/daemon/super-agent-tools/tools/read-agent-memory.js +28 -0
- package/src/daemon/super-agent-tools/tools/read-file.js +33 -0
- package/src/daemon/super-agent-tools/tools/run-shell.js +86 -0
- package/src/daemon/super-agent-tools/tools/search-messages.js +34 -0
- package/src/daemon/super-agent-tools/tools/send-telegram.js +30 -0
- package/src/daemon/super-agent-tools/tools/set-identity.js +35 -0
- package/src/daemon/super-agent-tools/tools/set-permission-mode.js +32 -0
- package/src/daemon/super-agent-tools/tools/tail-messages.js +39 -0
- package/src/daemon/super-agent-tools/tools/write-file.js +33 -0
- package/src/daemon/super-agent-tools.js +1 -539
- package/src/daemon/super-agent.js +56 -7
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveProject } from "../helpers.js";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
name: "read_agent_memory",
|
|
7
|
+
schema: {
|
|
8
|
+
type: "function",
|
|
9
|
+
function: {
|
|
10
|
+
name: "read_agent_memory",
|
|
11
|
+
description: "Read an agent memory.md file from default or a project.",
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
project: { type: "string" },
|
|
16
|
+
agent: { type: "string", description: "agent slug" },
|
|
17
|
+
},
|
|
18
|
+
required: ["agent"],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
makeHandler: ({ projects }) => ({ project, agent }) => {
|
|
23
|
+
const p = resolveProject(projects, project);
|
|
24
|
+
const file = path.join(p.path, ".apc", "agents", agent, "memory.md");
|
|
25
|
+
if (!fs.existsSync(file)) return { error: `no memory.md for agent ${agent}` };
|
|
26
|
+
return { body: fs.readFileSync(file, "utf8") };
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { resolveProject, safePathJoin } from "../helpers.js";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: "read_file",
|
|
6
|
+
schema: {
|
|
7
|
+
type: "function",
|
|
8
|
+
function: {
|
|
9
|
+
name: "read_file",
|
|
10
|
+
description: "Read a text file inside default or a project. Returns first 64KB.",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
project: { type: "string" },
|
|
15
|
+
path: { type: "string", description: "relative path inside the project" },
|
|
16
|
+
},
|
|
17
|
+
required: ["path"],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
makeHandler: ({ projects }) => ({ project, path }) => {
|
|
22
|
+
if (!path) throw new Error("read_file: path required");
|
|
23
|
+
const p = resolveProject(projects, project);
|
|
24
|
+
const target = safePathJoin(p.path, path);
|
|
25
|
+
if (!fs.existsSync(target)) return { error: `file not found: ${path}` };
|
|
26
|
+
const stat = fs.statSync(target);
|
|
27
|
+
if (!stat.isFile()) return { error: `${path} is not a file` };
|
|
28
|
+
return {
|
|
29
|
+
content: fs.readFileSync(target, "utf8").slice(0, 64 * 1024),
|
|
30
|
+
truncated: stat.size > 64 * 1024,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { confirmedProperty, resolveProject, safePathJoin } from "../helpers.js";
|
|
3
|
+
|
|
4
|
+
function run(command, { cwd, timeoutMs }) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const child = spawn("sh", ["-lc", command], { cwd, env: process.env });
|
|
7
|
+
let stdout = "";
|
|
8
|
+
let stderr = "";
|
|
9
|
+
let timedOut = false;
|
|
10
|
+
const timer = setTimeout(() => {
|
|
11
|
+
timedOut = true;
|
|
12
|
+
child.kill("SIGTERM");
|
|
13
|
+
}, timeoutMs);
|
|
14
|
+
|
|
15
|
+
child.stdout.on("data", (d) => { stdout += d.toString(); });
|
|
16
|
+
child.stderr.on("data", (d) => { stderr += d.toString(); });
|
|
17
|
+
child.on("close", (code, signal) => {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
resolve({ code, signal, timedOut, stdout, stderr });
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isSafeShellCommand(command) {
|
|
25
|
+
const text = String(command || "").trim();
|
|
26
|
+
if (!text) return false;
|
|
27
|
+
if (/[`$<>]/.test(text)) return false;
|
|
28
|
+
if (/\b(rm|mv|cp|chmod|chown|mkdir|touch|tee|kill|pkill|npm\s+install|curl\s+-X|apx\s+routine\s+(add|remove|rm|enable|disable|run)|apx\s+config\s+set)\b/i.test(text)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const segments = text.split(/\s*(?:\||&&|\|\|)\s*/).filter(Boolean);
|
|
33
|
+
return segments.every((segment) => {
|
|
34
|
+
const cmd = segment.trim().split(/\s+/)[0];
|
|
35
|
+
if (["pwd", "ls", "find", "rg", "grep", "cat", "head", "tail", "sed", "wc", "date", "stat", "file", "du", "df", "whoami", "id", "uname", "echo"].includes(cmd)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (cmd === "docker") return /^docker\s+ps\b/.test(segment.trim());
|
|
39
|
+
if (cmd === "apx") {
|
|
40
|
+
return /^apx\s+(--help|-h|help|status|daemon\s+status|routine\s+(list|ls|get|show)\b|project\s+(list|ls)\b|agent\s+(list|ls)\b|config\s+(show|ls)\b)/.test(segment.trim());
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
name: "run_shell",
|
|
48
|
+
schema: {
|
|
49
|
+
type: "function",
|
|
50
|
+
function: {
|
|
51
|
+
name: "run_shell",
|
|
52
|
+
description: "Run a shell command in default or a project working directory. Direct command execution tool.",
|
|
53
|
+
parameters: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {
|
|
56
|
+
project: { type: "string" },
|
|
57
|
+
cwd: { type: "string", description: "relative working directory inside the selected project; default '.'" },
|
|
58
|
+
command: { type: "string" },
|
|
59
|
+
timeout_s: { type: "integer", description: "seconds before SIGTERM; default 60" },
|
|
60
|
+
confirmed: confirmedProperty("true only after explicit user confirmation for this exact shell command"),
|
|
61
|
+
},
|
|
62
|
+
required: ["command"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
makeHandler: ({ projects, requirePermission }) => async ({ project, cwd = ".", command, timeout_s = 60, confirmed = false }) => {
|
|
67
|
+
requirePermission("run_shell", { dangerous: !isSafeShellCommand(command), confirmed });
|
|
68
|
+
if (!command) throw new Error("run_shell: command required");
|
|
69
|
+
|
|
70
|
+
const p = resolveProject(projects, project);
|
|
71
|
+
const workingDir = safePathJoin(p.path, cwd);
|
|
72
|
+
const result = await run(command, {
|
|
73
|
+
cwd: workingDir,
|
|
74
|
+
timeoutMs: Math.max(1, Math.min(timeout_s, 600)) * 1000,
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
exit_code: result.code,
|
|
78
|
+
signal: result.signal,
|
|
79
|
+
timed_out: result.timedOut,
|
|
80
|
+
stdout: result.stdout.slice(0, 12000),
|
|
81
|
+
stderr: result.stderr.slice(0, 12000),
|
|
82
|
+
truncated: result.stdout.length > 12000 || result.stderr.length > 12000,
|
|
83
|
+
cwd: workingDir,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { searchProjectMessages } from "../../../core/messages-store.js";
|
|
2
|
+
import { resolveProject } from "../helpers.js";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: "search_messages",
|
|
6
|
+
schema: {
|
|
7
|
+
type: "function",
|
|
8
|
+
function: {
|
|
9
|
+
name: "search_messages",
|
|
10
|
+
description: "Full-text search inside project messages.",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
project: { type: "string" },
|
|
15
|
+
query: { type: "string" },
|
|
16
|
+
},
|
|
17
|
+
required: ["query"],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
makeHandler: ({ projects }) => ({ project, query }) => {
|
|
22
|
+
if (!query) throw new Error("search_messages: query required");
|
|
23
|
+
const p = resolveProject(projects, project);
|
|
24
|
+
return searchProjectMessages(p.path, query, 25).map((m) => ({
|
|
25
|
+
ts: m.ts,
|
|
26
|
+
channel: m.channel,
|
|
27
|
+
direction: m.direction,
|
|
28
|
+
type: m.type,
|
|
29
|
+
author: m.author,
|
|
30
|
+
actor_id: m.actor_id,
|
|
31
|
+
body: m.body,
|
|
32
|
+
}));
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { confirmedProperty } from "../helpers.js";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "send_telegram",
|
|
5
|
+
schema: {
|
|
6
|
+
type: "function",
|
|
7
|
+
function: {
|
|
8
|
+
name: "send_telegram",
|
|
9
|
+
description: "Send a Telegram message via the daemon's Telegram plugin.",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
channel: { type: "string", description: "telegram channel name; omit for default" },
|
|
14
|
+
chat_id: { type: "string", description: "destination chat id; omit to use channel default" },
|
|
15
|
+
text: { type: "string" },
|
|
16
|
+
confirmed: confirmedProperty("true only after explicit user confirmation for this exact outbound message"),
|
|
17
|
+
},
|
|
18
|
+
required: ["text"],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
makeHandler: ({ plugins, requirePermission }) => async ({ channel, chat_id, text, confirmed = false }) => {
|
|
23
|
+
requirePermission("send_telegram", { dangerous: true, confirmed });
|
|
24
|
+
if (!plugins) throw new Error("plugins unavailable");
|
|
25
|
+
const telegram = plugins.get("telegram");
|
|
26
|
+
if (!telegram) throw new Error("telegram plugin not loaded");
|
|
27
|
+
const result = await telegram.send({ channel, chat_id, text, author: "apx" });
|
|
28
|
+
return { ok: true, message_id: result.message_id };
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { readIdentity, writeIdentity } from "../../../core/identity.js";
|
|
2
|
+
import { confirmedProperty } from "../helpers.js";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: "set_identity",
|
|
6
|
+
schema: {
|
|
7
|
+
type: "function",
|
|
8
|
+
function: {
|
|
9
|
+
name: "set_identity",
|
|
10
|
+
description: "Update daemon identity fields. Persists to ~/.apx/identity.json.",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
agent_name: { type: "string", description: "new agent name" },
|
|
15
|
+
owner_name: { type: "string", description: "owner name" },
|
|
16
|
+
personality: { type: "string", description: "comma-separated personality traits" },
|
|
17
|
+
language: { type: "string", description: "preferred language" },
|
|
18
|
+
confirmed: confirmedProperty("true only after explicit user confirmation for this exact identity update"),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
makeHandler: ({ requirePermission }) => ({ agent_name, owner_name, personality, language, confirmed = false } = {}) => {
|
|
24
|
+
requirePermission("set_identity", { dangerous: true, confirmed });
|
|
25
|
+
const fields = {};
|
|
26
|
+
if (agent_name) fields.agent_name = agent_name;
|
|
27
|
+
if (owner_name) fields.owner_name = owner_name;
|
|
28
|
+
if (personality) fields.personality = personality;
|
|
29
|
+
if (language) fields.language = language;
|
|
30
|
+
if (Object.keys(fields).length === 0) {
|
|
31
|
+
return { ok: true, identity: readIdentity() };
|
|
32
|
+
}
|
|
33
|
+
return { ok: true, identity: writeIdentity(fields) };
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readConfig, writeConfig } from "../../../core/config.js";
|
|
2
|
+
import { confirmedProperty } from "../helpers.js";
|
|
3
|
+
|
|
4
|
+
const MODES = new Set(["total", "automatico", "permiso"]);
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
name: "set_permission_mode",
|
|
8
|
+
schema: {
|
|
9
|
+
type: "function",
|
|
10
|
+
function: {
|
|
11
|
+
name: "set_permission_mode",
|
|
12
|
+
description: "Set the super-agent permission mode in ~/.apx/config.json. Modes: total, automatico, permiso.",
|
|
13
|
+
parameters: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
mode: { type: "string", enum: ["total", "automatico", "permiso"] },
|
|
17
|
+
confirmed: confirmedProperty("true only after explicit user confirmation for this exact permission-mode change"),
|
|
18
|
+
},
|
|
19
|
+
required: ["mode"],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
makeHandler: ({ requirePermission }) => ({ mode, confirmed = false }) => {
|
|
24
|
+
requirePermission("set_permission_mode", { dangerous: true, confirmed });
|
|
25
|
+
if (!MODES.has(mode)) throw new Error("mode must be total, automatico, or permiso");
|
|
26
|
+
const cfg = readConfig();
|
|
27
|
+
cfg.super_agent = cfg.super_agent || {};
|
|
28
|
+
cfg.super_agent.permission_mode = mode;
|
|
29
|
+
writeConfig(cfg);
|
|
30
|
+
return { ok: true, mode };
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readProjectMessages } from "../../../core/messages-store.js";
|
|
2
|
+
import { resolveProject } from "../helpers.js";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: "tail_messages",
|
|
6
|
+
schema: {
|
|
7
|
+
type: "function",
|
|
8
|
+
function: {
|
|
9
|
+
name: "tail_messages",
|
|
10
|
+
description: "Tail project messages. Optional filter by channel and/or agent slug.",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
project: { type: "string" },
|
|
15
|
+
channel: { type: "string", description: "e.g. telegram, engine, a2a, runtime, heartbeat" },
|
|
16
|
+
agent: { type: "string", description: "agent slug" },
|
|
17
|
+
limit: { type: "integer", description: "max rows; default 20" },
|
|
18
|
+
},
|
|
19
|
+
required: [],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
makeHandler: ({ projects }) => ({ project, channel, agent, limit = 20 } = {}) => {
|
|
24
|
+
const p = resolveProject(projects, project);
|
|
25
|
+
return readProjectMessages(p.path, {
|
|
26
|
+
channel,
|
|
27
|
+
agent_slug: agent,
|
|
28
|
+
limit: Math.min(limit, 100),
|
|
29
|
+
}).map((m) => ({
|
|
30
|
+
ts: m.ts,
|
|
31
|
+
channel: m.channel,
|
|
32
|
+
direction: m.direction,
|
|
33
|
+
type: m.type,
|
|
34
|
+
author: m.author,
|
|
35
|
+
actor_id: m.actor_id,
|
|
36
|
+
body: m.body,
|
|
37
|
+
}));
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { confirmedProperty, resolveProject, safePathJoin } from "../helpers.js";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
name: "write_file",
|
|
7
|
+
schema: {
|
|
8
|
+
type: "function",
|
|
9
|
+
function: {
|
|
10
|
+
name: "write_file",
|
|
11
|
+
description: "Create or overwrite a UTF-8 text file inside default or a project.",
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
project: { type: "string" },
|
|
16
|
+
path: { type: "string", description: "relative path inside the project" },
|
|
17
|
+
content: { type: "string" },
|
|
18
|
+
confirmed: confirmedProperty("true only after explicit user confirmation for this exact file write"),
|
|
19
|
+
},
|
|
20
|
+
required: ["path", "content"],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
makeHandler: ({ projects, requirePermission }) => ({ project, path: sub, content, confirmed = false }) => {
|
|
25
|
+
requirePermission("write_file", { dangerous: true, confirmed });
|
|
26
|
+
if (!sub) throw new Error("write_file: path required");
|
|
27
|
+
const p = resolveProject(projects, project);
|
|
28
|
+
const target = safePathJoin(p.path, sub);
|
|
29
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
30
|
+
fs.writeFileSync(target, content, "utf8");
|
|
31
|
+
return { ok: true, path: target, bytes: Buffer.byteLength(content, "utf8") };
|
|
32
|
+
},
|
|
33
|
+
};
|