@fuxi-ailabs/dsh-ecat 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +168 -2
- package/assets/skills/ecat-refine/SKILL.md +126 -0
- package/assets/skills/ecat-refine/config.claudecode.yaml +101 -0
- package/assets/skills/ecat-refine/config.deveco.yaml +109 -0
- package/assets/skills/ecat-refine/config.dsh.yaml +104 -0
- package/assets/skills/ecat-refine/config.opencode.yaml +115 -0
- package/assets/skills/ecat-refine/scripts/_cli_path.py +119 -0
- package/assets/skills/ecat-refine/scripts/_proc.py +82 -0
- package/assets/skills/ecat-refine/scripts/preflight.py +372 -0
- package/assets/skills/ecat-refine/scripts/start.py +136 -0
- package/assets/skills/ecat-refine/scripts/stop.py +65 -0
- package/assets/skills/ecat-refine/scripts/watch.py +267 -0
- package/assets/skills/ecat-setup/SKILL.md +220 -0
- package/assets/skills/ecat-setup/references/plugin-design.md +111 -0
- package/assets/skills/ecat-setup/scripts/_profile.py +104 -0
- package/assets/skills/ecat-setup/scripts/check.py +394 -0
- package/assets/skills/ecat-setup/scripts/plugins.py +478 -0
- package/assets/skills/ecat-setup/scripts/seeds.py +244 -0
- package/assets/skills/ecat-setup/scripts/setup.py +543 -0
- package/assets/wheels/ecat-0.1.0-py3-none-any.whl +0 -0
- package/cordis.patch.yml +12 -0
- package/icon.svg +6 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +58 -6
- package/src/client.js +102 -0
- package/src/ecat.js +212 -0
- package/src/plugin.js +375 -0
- package/src/probe_deps.py +128 -0
- package/src/proc.js +64 -0
- package/src/skills.js +108 -0
- package/src/venv.js +117 -0
- package/src/web-app.css +224 -0
- package/src/web-app.js +476 -0
- package/src/web-page.html +13 -0
- package/src/web.js +723 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# ─── opencode 变体 ───────────────────────────────────────────────────────────
|
|
2
|
+
# 与 config.claude-code.yaml 的差异只有四处,全部因为 opencode 走
|
|
3
|
+
# @ai-sdk/openai-compatible 而不是 Anthropic 兼容层:
|
|
4
|
+
# runtime claude_code → opencode
|
|
5
|
+
# base_url .../anthropic → 裸 OpenAI 端点(/anthropic 是给 claude CLI 的)
|
|
6
|
+
# api_key_env ANTHROPIC_AUTH_TOKEN → DEEPSEEK_API_KEY(AI SDK 认的标准槽位)
|
|
7
|
+
# model 去掉 [1m] 之类的 Claude Code 上下文档位后缀
|
|
8
|
+
# 已知降级:loop.generator_compact_interval 无效(opencode 无 compact 能力)。
|
|
9
|
+
# ─── Identity ────────────────────────────────────────────────────────────────
|
|
10
|
+
project: my-android-app
|
|
11
|
+
work_dir: .
|
|
12
|
+
|
|
13
|
+
# ─── Source / Target paths ───────────────────────────────────────────────────
|
|
14
|
+
# `target` is required; `source` is optional (single-tree tasks omit it).
|
|
15
|
+
paths:
|
|
16
|
+
source: ./Android_code/AIPPT
|
|
17
|
+
target: ./aippt_cc_glm_0705
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# ─── Agents ──────────────────────────────────────────────────────────────────
|
|
21
|
+
# Each agent can use a different runtime, provider, model, and base_url.
|
|
22
|
+
# base_url: set to your provider's OpenAI-compatible endpoint, or null for default.
|
|
23
|
+
# api_key_env: the NAME of the env var in .env (not the key itself).
|
|
24
|
+
|
|
25
|
+
generator:
|
|
26
|
+
runtime: opencode # claude_code | opencode | deveco_code | dsh
|
|
27
|
+
model: deepseek-v4-flash # any model your provider supports
|
|
28
|
+
provider: deepseek
|
|
29
|
+
base_url: https://api.deepseek.com # e.g. https://api.deepseek.com/v1
|
|
30
|
+
api_key_env: DEEPSEEK_API_KEY
|
|
31
|
+
config_dir: .ecat/agents/generator
|
|
32
|
+
timeout_s: 5400
|
|
33
|
+
extra_args: []
|
|
34
|
+
resume_session: true
|
|
35
|
+
|
|
36
|
+
discriminator:
|
|
37
|
+
runtime: opencode
|
|
38
|
+
model: deepseek-v4-flash
|
|
39
|
+
provider: deepseek
|
|
40
|
+
base_url: https://api.deepseek.com
|
|
41
|
+
api_key_env: DEEPSEEK_API_KEY
|
|
42
|
+
config_dir: .ecat/agents/discriminator
|
|
43
|
+
timeout_s: 3600
|
|
44
|
+
extra_args: []
|
|
45
|
+
evolution_write_paths:
|
|
46
|
+
- .ecat/agents/generator/skills
|
|
47
|
+
- .ecat/agents/generator/memory
|
|
48
|
+
|
|
49
|
+
# ─── Adversarial loop ────────────────────────────────────────────────────────
|
|
50
|
+
loop:
|
|
51
|
+
max_iterations: 300
|
|
52
|
+
entropy_threshold: 0.01
|
|
53
|
+
# stable_iters_to_stop: H 需连续 N 轮低于 entropy_threshold 才提前退出(防单轮"安静"过早收敛)。默认 2。
|
|
54
|
+
stable_iters_to_stop: 2
|
|
55
|
+
# regression_tolerance: 相邻两轮之间的回归容忍度。
|
|
56
|
+
# 如果本轮 H 比上轮 H 增加超过此值,判定为"回归"(代码质量变差)。
|
|
57
|
+
# revert_on_regression=true 时会 git checkout 撤销本轮 Generator 的改动。
|
|
58
|
+
# 作用:防止单次迭代引入破坏性变更。
|
|
59
|
+
regression_tolerance: 0.1
|
|
60
|
+
revert_on_regression: true
|
|
61
|
+
|
|
62
|
+
# oscillation_guard: 检测循环是否陷入"震荡"(反复修改同一问题无法收敛)。
|
|
63
|
+
# window: 回看最近 N 轮的 H 值序列。
|
|
64
|
+
# min_delta: 如果最近 window 轮中相邻两轮的 H 变化绝对值都 < min_delta,
|
|
65
|
+
# 说明 Generator 在原地打转,触发提前终止。
|
|
66
|
+
# 作用:避免浪费 token 在无效迭代上。
|
|
67
|
+
oscillation_guard:
|
|
68
|
+
enabled: true
|
|
69
|
+
window: 5
|
|
70
|
+
min_delta: 0.02
|
|
71
|
+
|
|
72
|
+
generator_compact_interval: 15
|
|
73
|
+
# max_items_per_iter: 每轮传给生成器的 work-list 最大条目数。
|
|
74
|
+
# 调小可缩短每轮耗时但需更多轮次收敛;调大每轮改动更多但速度变慢。默认 25。
|
|
75
|
+
max_items_per_iter: 50
|
|
76
|
+
|
|
77
|
+
# ─── Entropy plugin set ───────────────────────────────────────────────────────
|
|
78
|
+
# Every dimension listed in weights must be registered by a plugin in the
|
|
79
|
+
# selected set; a weight with no plugin is silently ignored, so the dimension
|
|
80
|
+
# never scores and the Generator never gets work for it.
|
|
81
|
+
entropy:
|
|
82
|
+
plugin_set: example
|
|
83
|
+
# judge_max_issues: 每个 agentic judge 子代理最多上报的问题数。
|
|
84
|
+
# 调小让 judge 更早停止探索文件,加快判别器;调大获取更多细节。默认 10。
|
|
85
|
+
judge_max_issues: 20
|
|
86
|
+
weights:
|
|
87
|
+
compile: 0.30
|
|
88
|
+
feature_parity: 0.35
|
|
89
|
+
|
|
90
|
+
# hallucination: 0.10
|
|
91
|
+
|
|
92
|
+
# node_align: 0.0
|
|
93
|
+
# ui_align: 0.0
|
|
94
|
+
# runtime_liveness: 0.0
|
|
95
|
+
|
|
96
|
+
# ─── Retry ────────────────────────────────────────────────────────────────────
|
|
97
|
+
retry:
|
|
98
|
+
max_attempts: 3
|
|
99
|
+
base_delay_s: 2
|
|
100
|
+
max_delay_s: 30
|
|
101
|
+
jitter: true
|
|
102
|
+
|
|
103
|
+
# ─── Phase gates ─────────────────────────────────────────────────────────────
|
|
104
|
+
features:
|
|
105
|
+
memory_evolution: false
|
|
106
|
+
skill_evolution: false
|
|
107
|
+
multi_discriminator: false
|
|
108
|
+
in_loop_intervention: false
|
|
109
|
+
|
|
110
|
+
# ─── Reporting ───────────────────────────────────────────────────────────────
|
|
111
|
+
reporting:
|
|
112
|
+
chart_format: png
|
|
113
|
+
chart_on_each_iter: true
|
|
114
|
+
keep_run_artifacts: -1
|
|
115
|
+
log_level: info
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""定位 agent CLI(claude / opencode),必要时把它所在目录补进 PATH。
|
|
2
|
+
|
|
3
|
+
为什么需要:npm 全局安装常常不进 PATH。实测这台机器上 `opencode-ai@1.14.39` 装在
|
|
4
|
+
`%APPDATA%\\npm`,`shutil.which("opencode")` 找不到,而 ECAT 起子进程时用的是继承来的
|
|
5
|
+
PATH —— 于是配置写了 `runtime: opencode` 也跑不起来,报错还在几十秒后才出现。
|
|
6
|
+
|
|
7
|
+
**只改子进程的环境变量,不动用户的 shell profile 或系统环境**。skill 的职责是让这次
|
|
8
|
+
run 跑起来,不是永久改用户机器。
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import shutil
|
|
14
|
+
import subprocess
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
# 各平台的常见安装位置。npm 全局前缀单独探测(下方 _npm_bin),因为它可被用户改过。
|
|
18
|
+
_CANDIDATE_DIRS: dict[str, list[str]] = {
|
|
19
|
+
"nt": [
|
|
20
|
+
r"%APPDATA%\npm", # npm -g(Windows 默认)
|
|
21
|
+
r"%LOCALAPPDATA%\Programs\opencode",
|
|
22
|
+
r"%USERPROFILE%\.opencode\bin",
|
|
23
|
+
r"%USERPROFILE%\.local\bin",
|
|
24
|
+
r"%LOCALAPPDATA%\Programs\claude",
|
|
25
|
+
],
|
|
26
|
+
"posix": [
|
|
27
|
+
"~/.opencode/bin", # opencode 官方安装脚本
|
|
28
|
+
"~/.local/bin",
|
|
29
|
+
"~/.bun/bin",
|
|
30
|
+
"/opt/homebrew/bin", # macOS Apple Silicon
|
|
31
|
+
"/usr/local/bin", # macOS Intel / Linux
|
|
32
|
+
"~/.npm-global/bin",
|
|
33
|
+
"~/.claude/local",
|
|
34
|
+
],
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _expand(d: str) -> Path:
|
|
39
|
+
return Path(os.path.expandvars(os.path.expanduser(d)))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _npm_bin() -> Path | None:
|
|
43
|
+
"""npm 全局前缀下的可执行目录;npm 不在或超时就返回 None。"""
|
|
44
|
+
npm = shutil.which("npm") or shutil.which("npm.cmd")
|
|
45
|
+
if not npm:
|
|
46
|
+
return None
|
|
47
|
+
try:
|
|
48
|
+
out = subprocess.run([npm, "prefix", "-g"], capture_output=True, text=True,
|
|
49
|
+
timeout=20).stdout.strip()
|
|
50
|
+
except (OSError, subprocess.SubprocessError):
|
|
51
|
+
return None
|
|
52
|
+
if not out:
|
|
53
|
+
return None
|
|
54
|
+
prefix = Path(out)
|
|
55
|
+
# Windows 的 npm 前缀本身就放 .cmd;POSIX 放在 prefix/bin
|
|
56
|
+
return prefix if os.name == "nt" else prefix / "bin"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def find_cli(name: str, path: str | None = None) -> tuple[Path | None, bool]:
|
|
60
|
+
"""返回 (可执行文件路径, 是否在给定 PATH 上)。找不到返回 (None, False)。
|
|
61
|
+
|
|
62
|
+
*path* 是可选的自定义 PATH 串(默认用当前进程的 PATH)。start.py 传入的是
|
|
63
|
+
`ensure_on_path` 加过目录的 child_env,这样"体检报告的 ecat"和"启动执行的 ecat"
|
|
64
|
+
解析的是同一个环境。
|
|
65
|
+
"""
|
|
66
|
+
on_path = shutil.which(name, path=path) if path is not None else shutil.which(name)
|
|
67
|
+
if on_path:
|
|
68
|
+
return Path(on_path), True
|
|
69
|
+
|
|
70
|
+
dirs = [_expand(d) for d in _CANDIDATE_DIRS["nt" if os.name == "nt" else "posix"]]
|
|
71
|
+
npm = _npm_bin()
|
|
72
|
+
if npm:
|
|
73
|
+
dirs.insert(0, npm)
|
|
74
|
+
|
|
75
|
+
# Windows 上 .exe 优先:`CreateProcess` 只补 .exe,`.cmd` 必须经 cmd /c 才能跑
|
|
76
|
+
# (见 cli_command)。若这里先返回 .cmd,start.py 的裸命令会解析到另一个 exe。
|
|
77
|
+
names = [f"{name}.exe", f"{name}.cmd", f"{name}.bat", name] if os.name == "nt" else [name]
|
|
78
|
+
for d in dirs:
|
|
79
|
+
if not d.is_dir():
|
|
80
|
+
continue
|
|
81
|
+
for n in names:
|
|
82
|
+
p = d / n
|
|
83
|
+
if p.is_file():
|
|
84
|
+
return p, False
|
|
85
|
+
return None, False
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def cli_command(path: str | Path, *args: str) -> list[str]:
|
|
89
|
+
"""构造执行 *path* 的 argv。
|
|
90
|
+
|
|
91
|
+
Windows 的 `CreateProcess` 不能直接跑 `.cmd/.bat`(只补 `.exe`),必须显式经
|
|
92
|
+
`cmd /c`;start.py 与 preflight 共用这个函数,保证"预检认为可用"与"实际能启动"
|
|
93
|
+
指向同一个入口。
|
|
94
|
+
"""
|
|
95
|
+
p = Path(path)
|
|
96
|
+
if os.name == "nt" and p.suffix.lower() in (".cmd", ".bat"):
|
|
97
|
+
return ["cmd", "/c", str(p), *args]
|
|
98
|
+
return [str(p), *args]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def ensure_on_path(names: list[str], env: dict[str, str] | None = None) -> tuple[dict[str, str], list[str]]:
|
|
102
|
+
"""把 *names* 里不在 PATH 上、但能在已知位置找到的 CLI,其目录前置进 PATH。
|
|
103
|
+
|
|
104
|
+
返回 (新的 env 副本, 人类可读的说明列表)。原 env 不被修改。
|
|
105
|
+
"""
|
|
106
|
+
out = dict(env if env is not None else os.environ)
|
|
107
|
+
notes: list[str] = []
|
|
108
|
+
added: list[str] = []
|
|
109
|
+
for name in names:
|
|
110
|
+
path, on_path = find_cli(name)
|
|
111
|
+
if path is None or on_path:
|
|
112
|
+
continue
|
|
113
|
+
d = str(path.parent)
|
|
114
|
+
if d not in added:
|
|
115
|
+
added.append(d)
|
|
116
|
+
notes.append(f"{name}: {path}(已注入 PATH)")
|
|
117
|
+
if added:
|
|
118
|
+
out["PATH"] = os.pathsep.join(added + [out.get("PATH", "")]).rstrip(os.pathsep)
|
|
119
|
+
return out, notes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""跨平台的进程存活判定与进程树终止。start/stop/watch 共用。
|
|
2
|
+
|
|
3
|
+
两件事在三个平台上都不能想当然:
|
|
4
|
+
|
|
5
|
+
1. **存活判定**。`os.kill(pid, 0)` 是 POSIX 惯用法,但 CPython 在 Windows 上把 signal
|
|
6
|
+
参数(除 CTRL_C_EVENT/CTRL_BREAK_EVENT 外)交给 TerminateProcess——文档写明"任何其它
|
|
7
|
+
值都会导致进程被无条件杀死"。实测 Python 3.11.13 上 sig=0 并未杀掉进程,但这是版本
|
|
8
|
+
相关的实现细节,监控脚本不该赌它。优先用 psutil(ECAT 本身就依赖它)。
|
|
9
|
+
|
|
10
|
+
2. **进程树终止**。只杀父进程会留下 `claude` 子进程继续跑,占着 API 配额和模拟器。
|
|
11
|
+
POSIX 的 `pgrep -P` 在 Windows(含 Git Bash)不存在,所以不能用 shell 遍历。
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import contextlib
|
|
16
|
+
import os
|
|
17
|
+
import subprocess
|
|
18
|
+
import time
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
import psutil
|
|
22
|
+
except ImportError: # 没装也要能用,只是判定弱一些
|
|
23
|
+
psutil = None # type: ignore[assignment]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def pid_alive(pid: int) -> bool:
|
|
27
|
+
if psutil is not None:
|
|
28
|
+
try:
|
|
29
|
+
p = psutil.Process(pid)
|
|
30
|
+
return p.is_running() and p.status() != psutil.STATUS_ZOMBIE
|
|
31
|
+
except psutil.Error:
|
|
32
|
+
return False
|
|
33
|
+
if os.name == "nt":
|
|
34
|
+
# 不用 os.kill:见模块 docstring
|
|
35
|
+
out = subprocess.run(["tasklist", "/FI", f"PID eq {pid}", "/NH"],
|
|
36
|
+
capture_output=True, text=True).stdout
|
|
37
|
+
return str(pid) in out
|
|
38
|
+
try:
|
|
39
|
+
os.kill(pid, 0)
|
|
40
|
+
except ProcessLookupError:
|
|
41
|
+
return False
|
|
42
|
+
except PermissionError:
|
|
43
|
+
return True
|
|
44
|
+
return True
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def kill_tree(pid: int, grace: int = 20) -> str:
|
|
48
|
+
"""先让整棵树优雅退出(ecat 要写 run.log 和图表),超时再强杀。返回一句人话结果。"""
|
|
49
|
+
if psutil is not None:
|
|
50
|
+
try:
|
|
51
|
+
root = psutil.Process(pid)
|
|
52
|
+
except psutil.Error:
|
|
53
|
+
return "进程已不在"
|
|
54
|
+
procs = root.children(recursive=True) + [root]
|
|
55
|
+
for p in procs:
|
|
56
|
+
with contextlib.suppress(psutil.Error):
|
|
57
|
+
p.terminate()
|
|
58
|
+
gone, alive = psutil.wait_procs(procs, timeout=grace)
|
|
59
|
+
for p in alive:
|
|
60
|
+
with contextlib.suppress(psutil.Error):
|
|
61
|
+
p.kill()
|
|
62
|
+
if alive:
|
|
63
|
+
psutil.wait_procs(alive, timeout=5)
|
|
64
|
+
return f"{len(gone)} 个优雅退出,{len(alive)} 个强杀"
|
|
65
|
+
return f"{len(gone)} 个进程优雅退出"
|
|
66
|
+
|
|
67
|
+
if os.name == "nt":
|
|
68
|
+
subprocess.run(["taskkill", "/T", "/F", "/PID", str(pid)],
|
|
69
|
+
capture_output=True, text=True)
|
|
70
|
+
return "taskkill /T /F(无 psutil,直接强杀整棵树)"
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
os.kill(pid, 15)
|
|
74
|
+
except OSError:
|
|
75
|
+
return "进程已不在"
|
|
76
|
+
for _ in range(grace):
|
|
77
|
+
if not pid_alive(pid):
|
|
78
|
+
return "优雅退出"
|
|
79
|
+
time.sleep(1)
|
|
80
|
+
with contextlib.suppress(OSError):
|
|
81
|
+
os.kill(pid, 9)
|
|
82
|
+
return "超时后强杀(无 psutil,子进程可能残留)"
|