@hunyed15/codecgc 0.1.7 → 0.1.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.
- package/.claude/hooks/route-edit.ps1 +58 -57
- package/INSTALLATION.md +117 -484
- package/README.md +118 -150
- package/bin/cgc-external-status.js +4 -0
- package/bin/cgc-start.js +4 -0
- package/bin/codecgc.js +141 -20
- package/codecgc/compound/codecgc-capability-matrix.md +37 -0
- package/codecgc/reference/README.md +69 -0
- package/codecgc/reference/maintainer-guide.md +93 -0
- package/codecgc/reference/mcp-tool-surface.md +112 -0
- package/codecgc/reference/onboarding.md +69 -0
- package/codecgc/reference/operation-guide.md +29 -23
- package/codecgc/reference/path-contract.md +53 -0
- package/codecgc/reference/policy-routing.md +57 -0
- package/codecgc/reference/project-structure.md +80 -0
- package/codecgc/reference/quickstart.md +108 -0
- package/codecgc/reference/real-workflow-loop.md +123 -0
- package/codecgc/reference/recovery-loop.md +109 -0
- package/codecgc/reference/release-maintenance-playbook.md +4 -1
- package/codecgc/reference/troubleshooting.md +112 -0
- package/codecgc/roadmap/codecgc-release-maintenance/delivery-plan.md +49 -0
- package/codecgc/roadmap/codecgc-release-maintenance/overview.md +41 -0
- package/codecgc/roadmap/codecgc-release-maintenance/phases.md +84 -0
- package/codecgcmcp/README.md +57 -11
- package/codecgcmcp/src/codecgcmcp/server.py +164 -26
- package/model-routing.yaml +31 -6
- package/package.json +11 -4
- package/scripts/audit_codecgc_external_capabilities.py +83 -4
- package/scripts/audit_codecgc_historical_audits.py +42 -2
- package/scripts/audit_codecgc_package_runtime.py +73 -4
- package/scripts/audit_codecgc_release_readiness.py +55 -3
- package/scripts/audit_codecgc_workflow_history.py +8 -5
- package/scripts/build_codecgc_task.py +62 -45
- package/scripts/codecgc_artifact_roots.py +8 -40
- package/scripts/codecgc_console_io.py +3 -45
- package/scripts/codecgc_executor_registry.py +4 -54
- package/scripts/codecgc_path_contract.py +7 -0
- package/scripts/codecgc_policy.py +275 -0
- package/scripts/codecgc_routing_paths.py +3 -16
- package/scripts/codecgc_routing_template.py +11 -135
- package/scripts/codecgc_runtime/__init__.py +1 -0
- package/scripts/codecgc_runtime/artifacts.py +42 -0
- package/scripts/codecgc_runtime/console.py +45 -0
- package/scripts/codecgc_runtime/executor_registry.py +55 -0
- package/scripts/codecgc_runtime/mcp_config.py +72 -0
- package/scripts/codecgc_runtime/path_contract.py +123 -0
- package/scripts/codecgc_runtime/paths.py +22 -0
- package/scripts/codecgc_runtime/routing_paths.py +16 -0
- package/scripts/codecgc_runtime/routing_template.py +169 -0
- package/scripts/codecgc_runtime/workflow_runtime.py +72 -0
- package/scripts/codecgc_runtime_paths.py +3 -22
- package/scripts/codecgc_step_control.py +3 -2
- package/scripts/codecgc_workflow_runtime.py +3 -71
- package/scripts/entry_codecgc_workflow.py +4 -0
- package/scripts/install_codecgc.py +490 -21
- package/scripts/normalize_codecgc_audits.py +5 -3
- package/scripts/postinstall_codecgc.js +6 -56
- package/scripts/review_codecgc_workflow.py +6 -3
- package/scripts/route_codecgc_workflow.py +67 -36
- package/scripts/run_codecgc_build.py +28 -0
- package/scripts/run_codecgc_fix.py +28 -0
- package/scripts/run_codecgc_task.py +5 -2
- package/scripts/run_codecgc_test.py +28 -0
- package/scripts/sync_codecgc_mcp_config.py +4 -54
- package/scripts/write_codecgc_review.py +7 -3
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .executor_registry import build_executor_registry
|
|
9
|
+
from .paths import PACKAGE_ROOT
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
WORKSPACE = PACKAGE_ROOT
|
|
13
|
+
MCP_CONFIG_PATH = WORKSPACE / ".mcp.json"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def build_runtime_pythonpath(*extra_paths: Path) -> str:
|
|
17
|
+
paths = [str(WORKSPACE / "scripts"), *(str(path) for path in extra_paths)]
|
|
18
|
+
return os.pathsep.join(paths)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _with_workspace_env(env: dict[str, str], workspace_root: Path | None) -> dict[str, str]:
|
|
22
|
+
if workspace_root is None:
|
|
23
|
+
return env
|
|
24
|
+
enriched = dict(env)
|
|
25
|
+
enriched["CODECGC_WORKSPACE_ROOT"] = str(workspace_root.expanduser().resolve())
|
|
26
|
+
return enriched
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def build_mcp_config(workspace_root: Path | None = None) -> dict[str, Any]:
|
|
30
|
+
registry = build_executor_registry()
|
|
31
|
+
servers: dict[str, dict[str, Any]] = {}
|
|
32
|
+
|
|
33
|
+
servers["codecgc"] = {
|
|
34
|
+
"command": str(next(iter(registry.values()))["python_command"]),
|
|
35
|
+
"args": ["-m", "codecgcmcp.cli"],
|
|
36
|
+
"env": _with_workspace_env(
|
|
37
|
+
{
|
|
38
|
+
"PYTHONPATH": build_runtime_pythonpath(WORKSPACE / "codecgcmcp" / "src"),
|
|
39
|
+
},
|
|
40
|
+
workspace_root,
|
|
41
|
+
),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for config in registry.values():
|
|
45
|
+
servers[str(config["mcp_server_name"])] = {
|
|
46
|
+
"command": str(config["python_command"]),
|
|
47
|
+
"args": ["-m", str(config["python_module"])],
|
|
48
|
+
"env": _with_workspace_env(
|
|
49
|
+
{
|
|
50
|
+
"PYTHONPATH": build_runtime_pythonpath(
|
|
51
|
+
WORKSPACE / "codecgcmcp" / "src",
|
|
52
|
+
Path(str(config["pythonpath"])),
|
|
53
|
+
),
|
|
54
|
+
},
|
|
55
|
+
workspace_root,
|
|
56
|
+
),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {"mcpServers": servers}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def write_mcp_config(target_path: Path, workspace_root: Path | None = None) -> Path:
|
|
63
|
+
config = build_mcp_config(workspace_root)
|
|
64
|
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
target_path.write_text(json.dumps(config, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
66
|
+
return target_path
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def main() -> int:
|
|
70
|
+
write_mcp_config(MCP_CONFIG_PATH, WORKSPACE)
|
|
71
|
+
print(json.dumps({"success": True, "path": str(MCP_CONFIG_PATH)}, ensure_ascii=False, indent=2))
|
|
72
|
+
return 0
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .paths import PROJECT_ROOT
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def normalize_path_text(path_text: str) -> str:
|
|
10
|
+
return str(path_text or "").replace("\\", "/").strip()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def is_project_relative_path(path_text: str) -> bool:
|
|
14
|
+
normalized = normalize_path_text(path_text)
|
|
15
|
+
if not normalized:
|
|
16
|
+
return False
|
|
17
|
+
if normalized.startswith(("/", "~")):
|
|
18
|
+
return False
|
|
19
|
+
if re.match(r"^[A-Za-z]:/", normalized):
|
|
20
|
+
return False
|
|
21
|
+
return True
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _relative_to_project(path: Path, project_root: Path) -> str | None:
|
|
25
|
+
try:
|
|
26
|
+
return path.resolve().relative_to(project_root.resolve()).as_posix()
|
|
27
|
+
except ValueError:
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _legacy_project_suffix(path_text: str) -> str | None:
|
|
32
|
+
normalized = normalize_path_text(path_text)
|
|
33
|
+
if not normalized:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
for marker in ("/CodeCGC/release/", "/CodeCGC/", "/CodeCCG/release/", "/CodeCCG/"):
|
|
37
|
+
if marker in normalized:
|
|
38
|
+
return normalized.split(marker, 1)[1].lstrip("/")
|
|
39
|
+
|
|
40
|
+
if normalized.endswith(("/CodeCGC/release", "/CodeCGC", "/CodeCCG/release", "/CodeCCG")):
|
|
41
|
+
return "."
|
|
42
|
+
|
|
43
|
+
basename = normalized.rsplit("/", 1)[-1]
|
|
44
|
+
if basename == "model-routing.yaml":
|
|
45
|
+
return "model-routing.yaml"
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def to_project_relative_path(
|
|
50
|
+
path_value: str | Path,
|
|
51
|
+
project_root: Path = PROJECT_ROOT,
|
|
52
|
+
*,
|
|
53
|
+
allow_legacy_suffix: bool = True,
|
|
54
|
+
) -> str:
|
|
55
|
+
path_text = normalize_path_text(str(path_value))
|
|
56
|
+
if not path_text:
|
|
57
|
+
return ""
|
|
58
|
+
if path_text == ".":
|
|
59
|
+
return "."
|
|
60
|
+
|
|
61
|
+
path = Path(path_text)
|
|
62
|
+
if path.is_absolute():
|
|
63
|
+
relative = _relative_to_project(path, project_root)
|
|
64
|
+
if relative is not None:
|
|
65
|
+
return relative or "."
|
|
66
|
+
|
|
67
|
+
if allow_legacy_suffix:
|
|
68
|
+
legacy_suffix = _legacy_project_suffix(path_text)
|
|
69
|
+
if legacy_suffix is not None:
|
|
70
|
+
return legacy_suffix or "."
|
|
71
|
+
|
|
72
|
+
return path_text
|
|
73
|
+
|
|
74
|
+
normalized = path_text
|
|
75
|
+
while normalized.startswith("./"):
|
|
76
|
+
normalized = normalized[2:]
|
|
77
|
+
return normalized or "."
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def resolve_project_path(path_value: str | Path, project_root: Path = PROJECT_ROOT) -> Path:
|
|
81
|
+
path_text = normalize_path_text(str(path_value))
|
|
82
|
+
if not path_text or path_text == ".":
|
|
83
|
+
return project_root.resolve()
|
|
84
|
+
|
|
85
|
+
path = Path(path_text)
|
|
86
|
+
if path.is_absolute():
|
|
87
|
+
relative = _relative_to_project(path, project_root)
|
|
88
|
+
if relative is not None:
|
|
89
|
+
return (project_root / relative).resolve()
|
|
90
|
+
|
|
91
|
+
legacy_suffix = _legacy_project_suffix(path_text)
|
|
92
|
+
if legacy_suffix is not None:
|
|
93
|
+
return (project_root / legacy_suffix).resolve()
|
|
94
|
+
|
|
95
|
+
return path.resolve()
|
|
96
|
+
|
|
97
|
+
return (project_root / path_text).resolve()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def normalize_persisted_project_path(path_value: str | Path, project_root: Path = PROJECT_ROOT) -> str:
|
|
101
|
+
return to_project_relative_path(path_value, project_root)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def normalize_source_contract(source: object, project_root: Path = PROJECT_ROOT) -> object:
|
|
105
|
+
if not isinstance(source, dict):
|
|
106
|
+
return source
|
|
107
|
+
normalized = dict(source)
|
|
108
|
+
artifact_file = normalized.get("artifact_file")
|
|
109
|
+
if isinstance(artifact_file, str) and artifact_file.strip():
|
|
110
|
+
normalized["artifact_file"] = normalize_persisted_project_path(artifact_file, project_root)
|
|
111
|
+
return normalized
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def normalize_audit_path_fields(record: dict, project_root: Path = PROJECT_ROOT) -> dict:
|
|
115
|
+
normalized = dict(record)
|
|
116
|
+
for key in ("routing_file", "cd"):
|
|
117
|
+
value = normalized.get(key)
|
|
118
|
+
if isinstance(value, str) and value.strip():
|
|
119
|
+
normalized[key] = normalize_persisted_project_path(value, project_root)
|
|
120
|
+
|
|
121
|
+
source = normalized.get("source")
|
|
122
|
+
normalized["source"] = normalize_source_contract(source, project_root)
|
|
123
|
+
return normalized
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
PACKAGE_ROOT = Path(__file__).resolve().parents[2]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def resolve_workspace_root(override_workspace: str = "") -> Path:
|
|
11
|
+
explicit = str(override_workspace or "").strip()
|
|
12
|
+
if explicit:
|
|
13
|
+
return Path(explicit).expanduser().resolve()
|
|
14
|
+
|
|
15
|
+
configured = os.environ.get("CODECGC_WORKSPACE_ROOT", "").strip()
|
|
16
|
+
if configured:
|
|
17
|
+
return Path(configured).expanduser().resolve()
|
|
18
|
+
|
|
19
|
+
return Path.cwd().resolve()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
PROJECT_ROOT = resolve_workspace_root()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from .paths import PACKAGE_ROOT
|
|
6
|
+
from .paths import PROJECT_ROOT
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
PACKAGE_ROUTING_FILE = PACKAGE_ROOT / "model-routing.yaml"
|
|
10
|
+
PROJECT_ROUTING_FILE = PROJECT_ROOT / "model-routing.yaml"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def resolve_active_routing_file() -> Path:
|
|
14
|
+
if PROJECT_ROUTING_FILE.exists():
|
|
15
|
+
return PROJECT_ROUTING_FILE
|
|
16
|
+
return PACKAGE_ROUTING_FILE
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import yaml
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
DEFAULT_FRONTEND_PATHS = [
|
|
9
|
+
"apps/web/**",
|
|
10
|
+
"src/components/**",
|
|
11
|
+
"src/pages/**",
|
|
12
|
+
"src/app/**",
|
|
13
|
+
"src/styles/**",
|
|
14
|
+
"web/**",
|
|
15
|
+
"frontend/**",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
DEFAULT_BACKEND_PATHS = [
|
|
19
|
+
"apps/api/**",
|
|
20
|
+
"server/**",
|
|
21
|
+
"src/server/**",
|
|
22
|
+
"src/services/**",
|
|
23
|
+
"src/repositories/**",
|
|
24
|
+
"backend/**",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
DEFAULT_SHARED_PATHS = [
|
|
28
|
+
"packages/shared/**",
|
|
29
|
+
"src/shared/**",
|
|
30
|
+
"src/lib/**",
|
|
31
|
+
"src/types/**",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
DEFAULT_ORCHESTRATION_PATHS = [
|
|
35
|
+
"codecgc/**",
|
|
36
|
+
".claude/commands/**",
|
|
37
|
+
".claude/settings.json",
|
|
38
|
+
".mcp.json",
|
|
39
|
+
"model-routing.yaml",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
DEFAULT_DOCS_PATHS = [
|
|
43
|
+
"README.md",
|
|
44
|
+
"INSTALLATION.md",
|
|
45
|
+
"docs/**",
|
|
46
|
+
"CHANGELOG.md",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
DEFAULT_BACKEND_TEST_PATHS = [
|
|
50
|
+
"apps/api/*.test.*",
|
|
51
|
+
"apps/api/*.spec.*",
|
|
52
|
+
"apps/api/**/*.test.*",
|
|
53
|
+
"apps/api/**/*.spec.*",
|
|
54
|
+
"tests/backend/**",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
DEFAULT_FRONTEND_TEST_PATHS = [
|
|
58
|
+
"apps/web/*.test.*",
|
|
59
|
+
"apps/web/*.spec.*",
|
|
60
|
+
"apps/web/**/*.test.*",
|
|
61
|
+
"apps/web/**/*.spec.*",
|
|
62
|
+
"tests/frontend/**",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
DEFAULT_RULES = {
|
|
66
|
+
"claude_allowed_owners": ["orchestration", "docs"],
|
|
67
|
+
"backend_executor": "codexmcp",
|
|
68
|
+
"frontend_executor": "geminimcp",
|
|
69
|
+
"shared_policy": "split-first",
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _render_list_block(name: str, items: list[str]) -> list[str]:
|
|
74
|
+
lines = [f"{name}:"]
|
|
75
|
+
for item in items:
|
|
76
|
+
lines.append(f' - "{item}"')
|
|
77
|
+
return lines
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _render_nested_list_block(name: str, groups: dict[str, list[str]]) -> list[str]:
|
|
81
|
+
lines = [f"{name}:"]
|
|
82
|
+
for group_name, items in groups.items():
|
|
83
|
+
lines.append(f" {group_name}:")
|
|
84
|
+
for item in items:
|
|
85
|
+
lines.append(f' - "{item}"')
|
|
86
|
+
return lines
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _render_rules_block() -> list[str]:
|
|
90
|
+
lines = ["rules:"]
|
|
91
|
+
for key, value in DEFAULT_RULES.items():
|
|
92
|
+
if isinstance(value, list):
|
|
93
|
+
lines.append(f" {key}:")
|
|
94
|
+
lines.extend(f' - "{item}"' for item in value)
|
|
95
|
+
else:
|
|
96
|
+
lines.append(f' {key}: "{value}"')
|
|
97
|
+
return lines
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def render_default_routing_yaml() -> str:
|
|
101
|
+
lines: list[str] = [
|
|
102
|
+
"version: 2",
|
|
103
|
+
"",
|
|
104
|
+
*_render_list_block("orchestration_paths", DEFAULT_ORCHESTRATION_PATHS),
|
|
105
|
+
"",
|
|
106
|
+
*_render_list_block("docs_paths", DEFAULT_DOCS_PATHS),
|
|
107
|
+
"",
|
|
108
|
+
*_render_list_block("frontend_paths", DEFAULT_FRONTEND_PATHS),
|
|
109
|
+
"",
|
|
110
|
+
*_render_list_block("backend_paths", DEFAULT_BACKEND_PATHS),
|
|
111
|
+
"",
|
|
112
|
+
*_render_nested_list_block(
|
|
113
|
+
"test_paths",
|
|
114
|
+
{
|
|
115
|
+
"frontend": DEFAULT_FRONTEND_TEST_PATHS,
|
|
116
|
+
"backend": DEFAULT_BACKEND_TEST_PATHS,
|
|
117
|
+
},
|
|
118
|
+
),
|
|
119
|
+
"",
|
|
120
|
+
*_render_list_block("shared_paths", DEFAULT_SHARED_PATHS),
|
|
121
|
+
"",
|
|
122
|
+
*_render_rules_block(),
|
|
123
|
+
"",
|
|
124
|
+
]
|
|
125
|
+
return "\n".join(lines)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _normalize_line_endings(text: str) -> str:
|
|
129
|
+
return text.replace("\r\n", "\n").replace("\r", "\n")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _extract_list_block(lines: list[str], block_name: str) -> list[str]:
|
|
133
|
+
items: list[str] = []
|
|
134
|
+
inside = False
|
|
135
|
+
for line in lines:
|
|
136
|
+
stripped = line.strip()
|
|
137
|
+
if not inside:
|
|
138
|
+
if stripped == f"{block_name}:":
|
|
139
|
+
inside = True
|
|
140
|
+
continue
|
|
141
|
+
|
|
142
|
+
if line and not line.startswith(" "):
|
|
143
|
+
break
|
|
144
|
+
if stripped.startswith("- "):
|
|
145
|
+
value = stripped[2:].strip()
|
|
146
|
+
if len(value) >= 2 and value[0] == value[-1] and value[0] in {'"', "'"}:
|
|
147
|
+
value = value[1:-1]
|
|
148
|
+
if value:
|
|
149
|
+
items.append(value)
|
|
150
|
+
return items
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def merge_routing_template(existing_text: str) -> str:
|
|
154
|
+
if existing_text.strip():
|
|
155
|
+
try:
|
|
156
|
+
data = yaml.safe_load(existing_text)
|
|
157
|
+
except yaml.YAMLError:
|
|
158
|
+
data = None
|
|
159
|
+
if isinstance(data, dict) and int(data.get("version", 0) or 0) == 2:
|
|
160
|
+
return _normalize_line_endings(existing_text).rstrip() + "\n"
|
|
161
|
+
return render_default_routing_yaml()
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def sync_workspace_routing_file(target_path: Path) -> Path:
|
|
165
|
+
existing_text = target_path.read_text(encoding="utf-8") if target_path.exists() else ""
|
|
166
|
+
merged_text = merge_routing_template(existing_text)
|
|
167
|
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
168
|
+
target_path.write_text(merged_text, encoding="utf-8")
|
|
169
|
+
return target_path
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .paths import PACKAGE_ROOT
|
|
10
|
+
from .paths import PROJECT_ROOT
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
WORKSPACE = PACKAGE_ROOT
|
|
14
|
+
PROJECT_WORKSPACE = PROJECT_ROOT
|
|
15
|
+
SCRIPTS_DIR = WORKSPACE / "scripts"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def build_script_command(script_name: str, *args: str) -> list[str]:
|
|
19
|
+
return [sys.executable, str(SCRIPTS_DIR / script_name), *args]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def parse_json_text(text: str) -> dict[str, Any]:
|
|
23
|
+
stripped = text.strip()
|
|
24
|
+
if not stripped:
|
|
25
|
+
raise ValueError("Command produced no JSON output.")
|
|
26
|
+
return json.loads(stripped)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def run_json_script(script_name: str, *args: str) -> dict[str, Any]:
|
|
30
|
+
command = build_script_command(script_name, *args)
|
|
31
|
+
|
|
32
|
+
env = os.environ.copy()
|
|
33
|
+
env["CODECGC_WORKSPACE_ROOT"] = str(PROJECT_WORKSPACE)
|
|
34
|
+
|
|
35
|
+
completed = subprocess.run(
|
|
36
|
+
command,
|
|
37
|
+
cwd=PROJECT_WORKSPACE,
|
|
38
|
+
stdin=subprocess.DEVNULL,
|
|
39
|
+
capture_output=True,
|
|
40
|
+
text=True,
|
|
41
|
+
encoding="utf-8",
|
|
42
|
+
errors="replace",
|
|
43
|
+
env=env,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
stdout = completed.stdout.strip()
|
|
47
|
+
stderr = completed.stderr.strip()
|
|
48
|
+
|
|
49
|
+
if completed.returncode == 0:
|
|
50
|
+
if not stdout:
|
|
51
|
+
return {"success": True}
|
|
52
|
+
return parse_json_text(stdout)
|
|
53
|
+
|
|
54
|
+
for candidate in (stdout, stderr):
|
|
55
|
+
if not candidate:
|
|
56
|
+
continue
|
|
57
|
+
try:
|
|
58
|
+
parsed = parse_json_text(candidate)
|
|
59
|
+
except Exception:
|
|
60
|
+
continue
|
|
61
|
+
if isinstance(parsed, dict):
|
|
62
|
+
parsed.setdefault("success", False)
|
|
63
|
+
parsed.setdefault("returncode", completed.returncode)
|
|
64
|
+
return parsed
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
"success": False,
|
|
68
|
+
"returncode": completed.returncode,
|
|
69
|
+
"stdout": stdout,
|
|
70
|
+
"stderr": stderr,
|
|
71
|
+
"error": f"{script_name} failed with exit code {completed.returncode}.",
|
|
72
|
+
}
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
PACKAGE_ROOT = Path(__file__).resolve().parents[1]
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def resolve_workspace_root(override_workspace: str = "") -> Path:
|
|
11
|
-
explicit = str(override_workspace or "").strip()
|
|
12
|
-
if explicit:
|
|
13
|
-
return Path(explicit).expanduser().resolve()
|
|
14
|
-
|
|
15
|
-
configured = os.environ.get("CODECGC_WORKSPACE_ROOT", "").strip()
|
|
16
|
-
if configured:
|
|
17
|
-
return Path(configured).expanduser().resolve()
|
|
18
|
-
|
|
19
|
-
return Path.cwd().resolve()
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
PROJECT_ROOT = resolve_workspace_root()
|
|
1
|
+
from codecgc_runtime.paths import PACKAGE_ROOT
|
|
2
|
+
from codecgc_runtime.paths import PROJECT_ROOT
|
|
3
|
+
from codecgc_runtime.paths import resolve_workspace_root
|
|
@@ -34,9 +34,8 @@ def is_executable_codecgc_block(codecgc: Any) -> bool:
|
|
|
34
34
|
if any(is_placeholder_path(path) for path in target_paths):
|
|
35
35
|
return False
|
|
36
36
|
|
|
37
|
-
task_id = str(codecgc.get("task_id", "")).strip()
|
|
38
37
|
task_summary = str(codecgc.get("task_summary", "")).strip()
|
|
39
|
-
return bool(
|
|
38
|
+
return bool(task_summary)
|
|
40
39
|
|
|
41
40
|
|
|
42
41
|
def is_test_codecgc_block(codecgc: Any) -> bool:
|
|
@@ -87,6 +86,7 @@ def select_next_executable_step(checklist_path: Path) -> dict[str, Any]:
|
|
|
87
86
|
"task_id": str(codecgc.get("task_id", "")),
|
|
88
87
|
"action": str(step.get("action", "")),
|
|
89
88
|
"kind": str(codecgc.get("kind", "")),
|
|
89
|
+
"step_type": str(codecgc.get("step_type", "")),
|
|
90
90
|
"target_paths": codecgc.get("target_paths", []),
|
|
91
91
|
"task_summary": str(codecgc.get("task_summary", "")),
|
|
92
92
|
"artifact_type": resolve_artifact_type(data),
|
|
@@ -107,6 +107,7 @@ def get_step_metadata(checklist_path: Path, step_number: int) -> dict[str, Any]:
|
|
|
107
107
|
"task_id": str(codecgc.get("task_id", "")),
|
|
108
108
|
"action": str(step.get("action", "")) if isinstance(step, dict) else "",
|
|
109
109
|
"kind": str(codecgc.get("kind", "")),
|
|
110
|
+
"step_type": str(codecgc.get("step_type", "")),
|
|
110
111
|
"target_paths": codecgc.get("target_paths", []),
|
|
111
112
|
"task_summary": str(codecgc.get("task_summary", "")),
|
|
112
113
|
"artifact_type": resolve_artifact_type(data),
|
|
@@ -1,71 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import sys
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from typing import Any
|
|
7
|
-
|
|
8
|
-
from codecgc_runtime_paths import PACKAGE_ROOT
|
|
9
|
-
from codecgc_runtime_paths import PROJECT_ROOT
|
|
10
|
-
|
|
11
|
-
WORKSPACE = PACKAGE_ROOT
|
|
12
|
-
PROJECT_WORKSPACE = PROJECT_ROOT
|
|
13
|
-
SCRIPTS_DIR = WORKSPACE / "scripts"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def build_script_command(script_name: str, *args: str) -> list[str]:
|
|
17
|
-
return [sys.executable, str(SCRIPTS_DIR / script_name), *args]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def parse_json_text(text: str) -> dict[str, Any]:
|
|
21
|
-
stripped = text.strip()
|
|
22
|
-
if not stripped:
|
|
23
|
-
raise ValueError("Command produced no JSON output.")
|
|
24
|
-
return json.loads(stripped)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def run_json_script(script_name: str, *args: str) -> dict[str, Any]:
|
|
28
|
-
command = build_script_command(script_name, *args)
|
|
29
|
-
|
|
30
|
-
# 设置环境变量,确保子进程使用正确的工作目录
|
|
31
|
-
env = os.environ.copy()
|
|
32
|
-
env["CODECGC_WORKSPACE_ROOT"] = str(PROJECT_WORKSPACE)
|
|
33
|
-
|
|
34
|
-
completed = subprocess.run(
|
|
35
|
-
command,
|
|
36
|
-
cwd=PROJECT_WORKSPACE,
|
|
37
|
-
stdin=subprocess.DEVNULL,
|
|
38
|
-
capture_output=True,
|
|
39
|
-
text=True,
|
|
40
|
-
encoding="utf-8",
|
|
41
|
-
errors="replace",
|
|
42
|
-
env=env, # 传递环境变量
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
stdout = completed.stdout.strip()
|
|
46
|
-
stderr = completed.stderr.strip()
|
|
47
|
-
|
|
48
|
-
if completed.returncode == 0:
|
|
49
|
-
if not stdout:
|
|
50
|
-
return {"success": True}
|
|
51
|
-
return parse_json_text(stdout)
|
|
52
|
-
|
|
53
|
-
for candidate in (stdout, stderr):
|
|
54
|
-
if not candidate:
|
|
55
|
-
continue
|
|
56
|
-
try:
|
|
57
|
-
parsed = parse_json_text(candidate)
|
|
58
|
-
except Exception:
|
|
59
|
-
continue
|
|
60
|
-
if isinstance(parsed, dict):
|
|
61
|
-
parsed.setdefault("success", False)
|
|
62
|
-
parsed.setdefault("returncode", completed.returncode)
|
|
63
|
-
return parsed
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
"success": False,
|
|
67
|
-
"returncode": completed.returncode,
|
|
68
|
-
"stdout": stdout,
|
|
69
|
-
"stderr": stderr,
|
|
70
|
-
"error": f"{script_name} failed with exit code {completed.returncode}.",
|
|
71
|
-
}
|
|
1
|
+
from codecgc_runtime.workflow_runtime import build_script_command
|
|
2
|
+
from codecgc_runtime.workflow_runtime import parse_json_text
|
|
3
|
+
from codecgc_runtime.workflow_runtime import run_json_script
|
|
@@ -3033,6 +3033,10 @@ def run_existing_mode(args: argparse.Namespace, explain_only: bool) -> dict[str,
|
|
|
3033
3033
|
"dispatched": False,
|
|
3034
3034
|
"dispatch_result": None,
|
|
3035
3035
|
}
|
|
3036
|
+
if matches_command(recommended_command, "cgc-plan") and isinstance(route.get("replan_payload"), dict):
|
|
3037
|
+
merged_replan_payload = dict(replan_payload)
|
|
3038
|
+
merged_replan_payload.update(route.get("replan_payload", {}))
|
|
3039
|
+
result["replan_payload"] = merged_replan_payload
|
|
3036
3040
|
if explain_only or not effective_auto_dispatch:
|
|
3037
3041
|
result["next"] = build_user_facing_next(result)
|
|
3038
3042
|
result["human_summary"] = build_existing_mode_human_summary(result)
|