@roll-agent/octopus-agent 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/README.md +11 -7
  2. package/{octopus_sponge_skill → octopus_skill}/__init__.py +1 -1
  3. package/package.json +4 -7
  4. package/pyproject.toml +2 -2
  5. package/scripts/start-octopus-agent.js +112 -0
  6. package/src/{octopus_sponge_skill → octopus_skill}/_version.py +1 -1
  7. package/src/{octopus_sponge_skill → octopus_skill}/main.py +1 -1
  8. package/bin/check-python.js +0 -117
  9. package/bin/start-roll-server.js +0 -109
  10. /package/src/{octopus_sponge_skill → octopus_skill}/__init__.py +0 -0
  11. /package/src/{octopus_sponge_skill → octopus_skill}/__main__.py +0 -0
  12. /package/src/{octopus_sponge_skill → octopus_skill}/agent.py +0 -0
  13. /package/src/{octopus_sponge_skill → octopus_skill}/audit_logger.py +0 -0
  14. /package/src/{octopus_sponge_skill → octopus_skill}/config.py +0 -0
  15. /package/src/{octopus_sponge_skill → octopus_skill}/context.py +0 -0
  16. /package/src/{octopus_sponge_skill → octopus_skill}/device_info.py +0 -0
  17. /package/src/{octopus_sponge_skill → octopus_skill}/llm_sql_generator.py +0 -0
  18. /package/src/{octopus_sponge_skill → octopus_skill}/mcp_client.py +0 -0
  19. /package/src/{octopus_sponge_skill/roll_server.py → octopus_skill/octopus_run.py} +0 -0
  20. /package/src/{octopus_sponge_skill → octopus_skill}/prompt_builder.py +0 -0
  21. /package/src/{octopus_sponge_skill → octopus_skill}/query_sql_cache.py +0 -0
  22. /package/src/{octopus_sponge_skill → octopus_skill}/result_renderer.py +0 -0
  23. /package/src/{octopus_sponge_skill → octopus_skill}/schema_cache.py +0 -0
  24. /package/src/{octopus_sponge_skill → octopus_skill}/schema_context_retriever.py +0 -0
  25. /package/src/{octopus_sponge_skill → octopus_skill}/sql_generator.py +0 -0
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  ## 本地运行
14
14
 
15
15
  ```bash
16
- python -m octopus_sponge_skill "查询我能看到的品牌列表"
16
+ python -m octopus_skill "查询我能看到的品牌列表"
17
17
  ```
18
18
 
19
19
  运行参数由 Agent 内置;用户本地只需要配置 Sponge MCP Server 地址和 Token。
@@ -31,9 +31,15 @@ roll agent install @roll-agent/octopus-agent
31
31
  roll run octopus-agent diagnostic_status --json
32
32
  ```
33
33
 
34
- 该 npm package(npm 包)直接包含 Python 源码;`roll agent install` 不会再从 PyPI 下载 `octopus-sponge-skill`。
35
- 安装机器需要 Python 3.11+。Windows 默认检查 `python --version`,macOS/Linux 默认检查 `python3 --version`。
36
- 安装阶段会执行 Python 环境检查;没有 Python 3.11+ 时,Windows 会尝试通过 winget 自动安装,macOS 会尝试通过 Homebrew 自动安装,Linux 会提示手动安装。
34
+ 该 npm package(npm 包)直接包含 Python 源码;`roll agent install` 不会再从 PyPI 下载 `octopus-skill`。
35
+ 安装机器上需要有 Python 3.11+。Agent 启动时会自动尝试 `python3`、`python`、`py -3.11`、`py -3`。
36
+ 如果 Python 命令不在这些名称里,可以配置 `OCTOPUS_PYTHON_COMMAND`(Python 命令),例如:
37
+
38
+ ```powershell
39
+ roll config set agents.env.octopus-agent.OCTOPUS_PYTHON_COMMAND "py -3.11"
40
+ ```
41
+
42
+ Windows 用户只要安装 Python 3.11+,通常不需要额外创建 `python3` 别名。
37
43
 
38
44
  ### 本地源码注册
39
45
 
@@ -85,14 +91,12 @@ roll run octopus-agent query_sponge --json \
85
91
  "runtime": {"ownership": "on-demand", "transport": "stdio"},
86
92
  "start": {
87
93
  "command": "node",
88
- "args": ["bin/start-roll-server.js"]
94
+ "args": ["scripts/start-octopus-agent.js"]
89
95
  }
90
96
  }
91
97
  }
92
98
  ```
93
99
 
94
- `start-roll-server.js` 会按系统选择 Python 命令:Windows 优先 `python`,macOS/Linux 优先 `python3`;都不可用或版本低于 3.11 时会报错提示安装。
95
-
96
100
  环境变量可放到 `roll.config.yaml`:
97
101
 
98
102
  ```yaml
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from pathlib import Path
4
4
 
5
- _src_package = Path(__file__).resolve().parent.parent / "src" / "octopus_sponge_skill"
5
+ _src_package = Path(__file__).resolve().parent.parent / "src" / "octopus_skill"
6
6
  if _src_package.exists():
7
7
  __path__.append(str(_src_package))
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roll-agent/octopus-agent",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "丸子Agent(Octopus Agent)",
5
5
  "license": "UNLICENSED",
6
6
  "keywords": [
@@ -11,13 +11,10 @@
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
14
- "scripts": {
15
- "postinstall": "node bin/check-python.js"
16
- },
17
14
  "files": [
18
- "bin",
19
- "octopus_sponge_skill",
15
+ "octopus_skill",
20
16
  "src",
17
+ "scripts",
21
18
  "references",
22
19
  "SKILL.md",
23
20
  "pyproject.toml",
@@ -33,7 +30,7 @@
33
30
  "start": {
34
31
  "command": "node",
35
32
  "args": [
36
- "bin/start-roll-server.js"
33
+ "scripts/start-octopus-agent.js"
37
34
  ]
38
35
  }
39
36
  }
package/pyproject.toml CHANGED
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "octopus-skill"
3
- version = "0.0.6"
3
+ version = "0.0.8"
4
4
  description = "丸子Agent(Octopus Agent)"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
7
7
  dependencies = []
8
8
 
9
9
  [project.scripts]
10
- octopus-sponge = "octopus_sponge_skill.main:main"
10
+ octopus-agent = "octopus_skill.main:main"
11
11
 
12
12
  [build-system]
13
13
  requires = ["setuptools>=68"]
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawn, spawnSync } = require("node:child_process");
5
+
6
+ const MIN_MAJOR = 3;
7
+ const MIN_MINOR = 11;
8
+ const VERSION_CHECK = [
9
+ "import sys",
10
+ `raise SystemExit(0 if sys.version_info >= (${MIN_MAJOR}, ${MIN_MINOR}) else 1)`,
11
+ ].join("; ");
12
+
13
+ function splitCommand(value) {
14
+ const parts = [];
15
+ let current = "";
16
+ let quote = null;
17
+
18
+ for (let index = 0; index < value.length; index += 1) {
19
+ const char = value[index];
20
+ if ((char === '"' || char === "'") && quote === null) {
21
+ quote = char;
22
+ continue;
23
+ }
24
+ if (char === quote) {
25
+ quote = null;
26
+ continue;
27
+ }
28
+ if (/\s/.test(char) && quote === null) {
29
+ if (current) {
30
+ parts.push(current);
31
+ current = "";
32
+ }
33
+ continue;
34
+ }
35
+ current += char;
36
+ }
37
+
38
+ if (current) {
39
+ parts.push(current);
40
+ }
41
+ return parts;
42
+ }
43
+
44
+ function configuredCandidate() {
45
+ const value = process.env.OCTOPUS_PYTHON_COMMAND;
46
+ if (!value) {
47
+ return null;
48
+ }
49
+
50
+ const [command, ...args] = splitCommand(value);
51
+ if (!command) {
52
+ return null;
53
+ }
54
+ return { command, args, source: "OCTOPUS_PYTHON_COMMAND" };
55
+ }
56
+
57
+ function pythonCandidates() {
58
+ return [
59
+ configuredCandidate(),
60
+ { command: "python3", args: [], source: "python3" },
61
+ { command: "python", args: [], source: "python" },
62
+ { command: "py", args: ["-3.11"], source: "py -3.11" },
63
+ { command: "py", args: ["-3"], source: "py -3" },
64
+ ].filter(Boolean);
65
+ }
66
+
67
+ function isUsablePython(candidate) {
68
+ const result = spawnSync(candidate.command, [...candidate.args, "-c", VERSION_CHECK], {
69
+ encoding: "utf8",
70
+ stdio: "ignore",
71
+ });
72
+ return result.status === 0;
73
+ }
74
+
75
+ function findPython() {
76
+ return pythonCandidates().find(isUsablePython);
77
+ }
78
+
79
+ const python = findPython();
80
+ if (!python) {
81
+ console.error(
82
+ [
83
+ `Octopus Agent requires Python ${MIN_MAJOR}.${MIN_MINOR}+.`,
84
+ "Install Python 3.11+ and make one of these commands available:",
85
+ "python3, python, py -3.11, py -3",
86
+ "Or set OCTOPUS_PYTHON_COMMAND to the Python command.",
87
+ ].join("\n")
88
+ );
89
+ process.exit(1);
90
+ }
91
+
92
+ const child = spawn(
93
+ python.command,
94
+ [...python.args, "-m", "octopus_skill.octopus_run", ...process.argv.slice(2)],
95
+ {
96
+ stdio: "inherit",
97
+ windowsHide: true,
98
+ }
99
+ );
100
+
101
+ child.on("error", (error) => {
102
+ console.error(`Failed to start Python via ${python.source}: ${error.message}`);
103
+ process.exit(1);
104
+ });
105
+
106
+ child.on("exit", (code, signal) => {
107
+ if (signal) {
108
+ process.kill(process.pid, signal);
109
+ return;
110
+ }
111
+ process.exit(code ?? 0);
112
+ });
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.0.6"
3
+ __version__ = "0.0.8"
@@ -7,7 +7,7 @@ from .config import load_config_from_env
7
7
 
8
8
 
9
9
  def main() -> None:
10
- parser = argparse.ArgumentParser(prog="octopus-sponge")
10
+ parser = argparse.ArgumentParser(prog="octopus-agent")
11
11
  parser.add_argument("question")
12
12
  parser.add_argument("--session-id")
13
13
  args = parser.parse_args()
@@ -1,117 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { spawnSync } = require("child_process");
4
-
5
- const MIN_VERSION = [3, 11, 0];
6
-
7
- function pythonCandidates() {
8
- if (process.platform === "win32") {
9
- return [["python"], ["python3"]];
10
- }
11
- return [["python3"], ["python"]];
12
- }
13
-
14
- function parseVersion(output) {
15
- const match = String(output).match(/Python\s+(\d+)\.(\d+)\.(\d+)/);
16
- if (!match) {
17
- return null;
18
- }
19
- return match.slice(1).map((part) => Number(part));
20
- }
21
-
22
- function versionLabel(version) {
23
- return version.join(".");
24
- }
25
-
26
- function isSupported(version) {
27
- for (let index = 0; index < MIN_VERSION.length; index += 1) {
28
- if (version[index] > MIN_VERSION[index]) return true;
29
- if (version[index] < MIN_VERSION[index]) return false;
30
- }
31
- return true;
32
- }
33
-
34
- function commandLabel(command) {
35
- return command.join(" ");
36
- }
37
-
38
- function run(command, args, options = {}) {
39
- return spawnSync(command[0], [...command.slice(1), ...args], {
40
- encoding: "utf8",
41
- stdio: options.stdio || ["ignore", "pipe", "pipe"],
42
- });
43
- }
44
-
45
- function findPython() {
46
- const checked = [];
47
- for (const command of pythonCandidates()) {
48
- const result = run(command, ["--version"]);
49
- const output = `${result.stdout || ""}${result.stderr || ""}`;
50
- const version = parseVersion(output);
51
- if (result.status === 0 && version && isSupported(version)) {
52
- return { command, version, checked };
53
- }
54
- checked.push({
55
- command,
56
- reason: version
57
- ? `当前版本 ${versionLabel(version)},需要 ${versionLabel(MIN_VERSION)}+`
58
- : "未找到或无法读取版本",
59
- });
60
- }
61
- return { command: null, version: null, checked };
62
- }
63
-
64
- function installPython() {
65
- if (process.platform === "win32") {
66
- return run(["winget"], ["install", "--id", "Python.Python.3.11", "-e"], {
67
- stdio: "inherit",
68
- });
69
- }
70
- if (process.platform === "darwin") {
71
- return run(["brew"], ["install", "python@3.11"], { stdio: "inherit" });
72
- }
73
- return { status: 1 };
74
- }
75
-
76
- function printInstallHelp() {
77
- console.error("未找到 Python 3.11+,且自动安装失败。请手动安装后重试。");
78
- console.error("Windows: 安装后确认 `python --version` 可用。");
79
- console.error("macOS: 安装 Homebrew 后可执行 `brew install python@3.11`。");
80
- console.error("Linux: 请使用当前发行版的包管理器安装 Python 3.11+。");
81
- console.error("macOS/Linux: 安装后确认 `python3 --version` 可用。");
82
- }
83
-
84
- function main() {
85
- let result = findPython();
86
- if (result.command) {
87
- console.log(
88
- `Found Python ${versionLabel(result.version)}: ${commandLabel(
89
- result.command
90
- )}`
91
- );
92
- return;
93
- }
94
-
95
- for (const item of result.checked) {
96
- console.error(`${commandLabel(item.command)}: ${item.reason}`);
97
- }
98
-
99
- console.error("正在尝试自动安装 Python 3.11...");
100
- const installResult = installPython();
101
- if (installResult.status === 0) {
102
- result = findPython();
103
- if (result.command) {
104
- console.log(
105
- `Found Python ${versionLabel(result.version)}: ${commandLabel(
106
- result.command
107
- )}`
108
- );
109
- return;
110
- }
111
- }
112
-
113
- printInstallHelp();
114
- process.exit(1);
115
- }
116
-
117
- main();
@@ -1,109 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { spawn, spawnSync } = require("child_process");
4
-
5
- const MIN_VERSION = [3, 11, 0];
6
-
7
- function pythonCandidates() {
8
- if (process.platform === "win32") {
9
- return [["python"], ["python3"]];
10
- }
11
- return [["python3"], ["python"]];
12
- }
13
-
14
- function parseVersion(output) {
15
- const match = String(output).match(/Python\s+(\d+)\.(\d+)\.(\d+)/);
16
- if (!match) {
17
- return null;
18
- }
19
- return match.slice(1).map((part) => Number(part));
20
- }
21
-
22
- function versionLabel(version) {
23
- return version.join(".");
24
- }
25
-
26
- function isSupported(version) {
27
- for (let index = 0; index < MIN_VERSION.length; index += 1) {
28
- if (version[index] > MIN_VERSION[index]) return true;
29
- if (version[index] < MIN_VERSION[index]) return false;
30
- }
31
- return true;
32
- }
33
-
34
- function commandLabel(command) {
35
- return command.join(" ");
36
- }
37
-
38
- function findPython() {
39
- const checked = [];
40
- for (const command of pythonCandidates()) {
41
- const result = spawnSync(command[0], [...command.slice(1), "--version"], {
42
- encoding: "utf8",
43
- stdio: ["ignore", "pipe", "pipe"],
44
- });
45
- const output = `${result.stdout || ""}${result.stderr || ""}`;
46
- const version = parseVersion(output);
47
- if (result.status === 0 && version && isSupported(version)) {
48
- return { command, version, checked };
49
- }
50
- checked.push({
51
- command,
52
- reason: version
53
- ? `当前版本 ${versionLabel(version)},需要 ${versionLabel(MIN_VERSION)}+`
54
- : "未找到或无法读取版本",
55
- });
56
- }
57
- return { command: null, version: null, checked };
58
- }
59
-
60
- function printPythonError(checked) {
61
- for (const item of checked) {
62
- console.error(`${commandLabel(item.command)}: ${item.reason}`);
63
- }
64
- console.error("未找到 Python 3.11+,无法启动 octopus-agent。");
65
- console.error("Windows: 请安装 Python 3.11+,并确认 `python --version` 可用。");
66
- console.error(
67
- "macOS/Linux: 请安装 Python 3.11+,并确认 `python3 --version` 可用。"
68
- );
69
- }
70
-
71
- function main() {
72
- const passthroughArgs = process.argv.slice(2);
73
- const checkOnly = passthroughArgs[0] === "--check";
74
- const serverArgs = checkOnly ? [] : passthroughArgs;
75
- const result = findPython();
76
-
77
- if (!result.command) {
78
- printPythonError(result.checked);
79
- process.exit(1);
80
- }
81
-
82
- if (checkOnly) {
83
- console.log(
84
- `${commandLabel(result.command)} ${versionLabel(result.version)}`
85
- );
86
- return;
87
- }
88
-
89
- const child = spawn(
90
- result.command[0],
91
- [...result.command.slice(1), "-m", "octopus_sponge_skill.roll_server", ...serverArgs],
92
- { stdio: "inherit" }
93
- );
94
-
95
- child.on("exit", (code, signal) => {
96
- if (signal) {
97
- process.kill(process.pid, signal);
98
- return;
99
- }
100
- process.exit(code || 0);
101
- });
102
-
103
- child.on("error", (error) => {
104
- console.error(`启动 Python 失败: ${error.message}`);
105
- process.exit(1);
106
- });
107
- }
108
-
109
- main();