@roll-agent/octopus-agent 0.0.7 → 0.0.9

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 +128 -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 -85
  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、macOS、Linux 都会检查 `python --version` 和 `python3 --version`,任意一个可用即可。
36
- 安装阶段只执行 Python 环境检查;没有 Python 3.11+ 时会提示手动安装,不会自动安装。
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.7",
3
+ "version": "0.0.9",
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.7"
3
+ version = "0.0.9"
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,128 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawn, spawnSync } = require("node:child_process");
5
+ const path = require("node:path");
6
+
7
+ const MIN_MAJOR = 3;
8
+ const MIN_MINOR = 11;
9
+ const VERSION_CHECK = [
10
+ "import sys",
11
+ `raise SystemExit(0 if sys.version_info >= (${MIN_MAJOR}, ${MIN_MINOR}) else 1)`,
12
+ ].join("; ");
13
+
14
+ function splitCommand(value) {
15
+ const parts = [];
16
+ let current = "";
17
+ let quote = null;
18
+
19
+ for (let index = 0; index < value.length; index += 1) {
20
+ const char = value[index];
21
+ if ((char === '"' || char === "'") && quote === null) {
22
+ quote = char;
23
+ continue;
24
+ }
25
+ if (char === quote) {
26
+ quote = null;
27
+ continue;
28
+ }
29
+ if (/\s/.test(char) && quote === null) {
30
+ if (current) {
31
+ parts.push(current);
32
+ current = "";
33
+ }
34
+ continue;
35
+ }
36
+ current += char;
37
+ }
38
+
39
+ if (current) {
40
+ parts.push(current);
41
+ }
42
+ return parts;
43
+ }
44
+
45
+ function configuredCandidate() {
46
+ const value = process.env.OCTOPUS_PYTHON_COMMAND;
47
+ if (!value) {
48
+ return null;
49
+ }
50
+
51
+ const [command, ...args] = splitCommand(value);
52
+ if (!command) {
53
+ return null;
54
+ }
55
+ return { command, args, source: "OCTOPUS_PYTHON_COMMAND" };
56
+ }
57
+
58
+ function pythonCandidates() {
59
+ return [
60
+ configuredCandidate(),
61
+ { command: "python3", args: [], source: "python3" },
62
+ { command: "python", args: [], source: "python" },
63
+ { command: "py", args: ["-3.11"], source: "py -3.11" },
64
+ { command: "py", args: ["-3"], source: "py -3" },
65
+ ].filter(Boolean);
66
+ }
67
+
68
+ function isUsablePython(candidate) {
69
+ const result = spawnSync(candidate.command, [...candidate.args, "-c", VERSION_CHECK], {
70
+ encoding: "utf8",
71
+ stdio: "ignore",
72
+ });
73
+ return result.status === 0;
74
+ }
75
+
76
+ function findPython() {
77
+ return pythonCandidates().find(isUsablePython);
78
+ }
79
+
80
+ const python = findPython();
81
+ if (!python) {
82
+ console.error(
83
+ [
84
+ `Octopus Agent requires Python ${MIN_MAJOR}.${MIN_MINOR}+.`,
85
+ "Install Python 3.11+ and make one of these commands available:",
86
+ "python3, python, py -3.11, py -3",
87
+ "Or set OCTOPUS_PYTHON_COMMAND to the Python command.",
88
+ ].join("\n")
89
+ );
90
+ process.exit(1);
91
+ }
92
+
93
+ const packageRoot = path.resolve(__dirname, "..");
94
+
95
+ function buildPythonPath() {
96
+ return [
97
+ path.join(packageRoot, "src"),
98
+ packageRoot,
99
+ ...(process.env.PYTHONPATH ? process.env.PYTHONPATH.split(path.delimiter).filter(Boolean) : []),
100
+ ].join(path.delimiter);
101
+ }
102
+
103
+ const child = spawn(
104
+ python.command,
105
+ [...python.args, "-m", "octopus_skill.octopus_run", ...process.argv.slice(2)],
106
+ {
107
+ cwd: packageRoot,
108
+ env: {
109
+ ...process.env,
110
+ PYTHONPATH: buildPythonPath(),
111
+ },
112
+ stdio: "inherit",
113
+ windowsHide: true,
114
+ }
115
+ );
116
+
117
+ child.on("error", (error) => {
118
+ console.error(`Failed to start Python via ${python.source}: ${error.message}`);
119
+ process.exit(1);
120
+ });
121
+
122
+ child.on("exit", (code, signal) => {
123
+ if (signal) {
124
+ process.kill(process.pid, signal);
125
+ return;
126
+ }
127
+ process.exit(code ?? 0);
128
+ });
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.0.7"
3
+ __version__ = "0.0.9"
@@ -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,85 +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
- return [["python"], ["python3"]];
9
- }
10
-
11
- function parseVersion(output) {
12
- const match = String(output).match(/Python\s+(\d+)\.(\d+)\.(\d+)/);
13
- if (!match) {
14
- return null;
15
- }
16
- return match.slice(1).map((part) => Number(part));
17
- }
18
-
19
- function versionLabel(version) {
20
- return version.join(".");
21
- }
22
-
23
- function isSupported(version) {
24
- for (let index = 0; index < MIN_VERSION.length; index += 1) {
25
- if (version[index] > MIN_VERSION[index]) return true;
26
- if (version[index] < MIN_VERSION[index]) return false;
27
- }
28
- return true;
29
- }
30
-
31
- function commandLabel(command) {
32
- return command.join(" ");
33
- }
34
-
35
- function run(command, args, options = {}) {
36
- return spawnSync(command[0], [...command.slice(1), ...args], {
37
- encoding: "utf8",
38
- stdio: options.stdio || ["ignore", "pipe", "pipe"],
39
- });
40
- }
41
-
42
- function findPython() {
43
- const checked = [];
44
- for (const command of pythonCandidates()) {
45
- const result = run(command, ["--version"]);
46
- const output = `${result.stdout || ""}${result.stderr || ""}`;
47
- const version = parseVersion(output);
48
- if (result.status === 0 && version && isSupported(version)) {
49
- return { command, version, checked };
50
- }
51
- checked.push({
52
- command,
53
- reason: version
54
- ? `当前版本 ${versionLabel(version)},需要 ${versionLabel(MIN_VERSION)}+`
55
- : "未找到或无法读取版本",
56
- });
57
- }
58
- return { command: null, version: null, checked };
59
- }
60
-
61
- function printInstallHelp() {
62
- console.error("未找到 Python 3.11+。请手动安装后重试。");
63
- console.error("Windows/macOS/Linux: 安装后确认 `python --version` 或 `python3 --version` 可用。");
64
- }
65
-
66
- function main() {
67
- let result = findPython();
68
- if (result.command) {
69
- console.log(
70
- `Found Python ${versionLabel(result.version)}: ${commandLabel(
71
- result.command
72
- )}`
73
- );
74
- return;
75
- }
76
-
77
- for (const item of result.checked) {
78
- console.error(`${commandLabel(item.command)}: ${item.reason}`);
79
- }
80
-
81
- printInstallHelp();
82
- process.exit(1);
83
- }
84
-
85
- 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();