@hunyed15/codecgc 0.1.6 → 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/codexmcp/src/codexmcp/server.py +32 -26
- package/geminimcp/src/geminimcp/server.py +22 -14
- 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
|
@@ -1,135 +1,11 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"web/**",
|
|
13
|
-
"frontend/**",
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
DEFAULT_BACKEND_PATHS = [
|
|
17
|
-
"apps/api/**",
|
|
18
|
-
"server/**",
|
|
19
|
-
"src/server/**",
|
|
20
|
-
"src/services/**",
|
|
21
|
-
"src/repositories/**",
|
|
22
|
-
"backend/**",
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
DEFAULT_SHARED_PATHS = [
|
|
26
|
-
"packages/shared/**",
|
|
27
|
-
"src/shared/**",
|
|
28
|
-
"src/lib/**",
|
|
29
|
-
"src/types/**",
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
DEFAULT_RULES = {
|
|
33
|
-
"frontend_executor": "geminimcp",
|
|
34
|
-
"backend_executor": "codexmcp",
|
|
35
|
-
"shared_policy": "split-first",
|
|
36
|
-
"claude_role": "plan-review-accept-only",
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _render_list_block(name: str, items: list[str]) -> list[str]:
|
|
41
|
-
lines = [f"{name}:"]
|
|
42
|
-
for item in items:
|
|
43
|
-
lines.append(f' - "{item}"')
|
|
44
|
-
return lines
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def _render_rules_block() -> list[str]:
|
|
48
|
-
lines = ["rules:"]
|
|
49
|
-
for key, value in DEFAULT_RULES.items():
|
|
50
|
-
lines.append(f' {key}: "{value}"')
|
|
51
|
-
return lines
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def render_default_routing_yaml() -> str:
|
|
55
|
-
lines: list[str] = [
|
|
56
|
-
"version: 1",
|
|
57
|
-
"",
|
|
58
|
-
*_render_list_block("frontend_paths", DEFAULT_FRONTEND_PATHS),
|
|
59
|
-
"",
|
|
60
|
-
*_render_list_block("custom_frontend_paths", []),
|
|
61
|
-
"",
|
|
62
|
-
*_render_list_block("backend_paths", DEFAULT_BACKEND_PATHS),
|
|
63
|
-
"",
|
|
64
|
-
*_render_list_block("custom_backend_paths", []),
|
|
65
|
-
"",
|
|
66
|
-
*_render_list_block("shared_paths", DEFAULT_SHARED_PATHS),
|
|
67
|
-
"",
|
|
68
|
-
*_render_rules_block(),
|
|
69
|
-
"",
|
|
70
|
-
]
|
|
71
|
-
return "\n".join(lines)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def _normalize_line_endings(text: str) -> str:
|
|
75
|
-
return text.replace("\r\n", "\n").replace("\r", "\n")
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _extract_list_block(lines: list[str], block_name: str) -> list[str]:
|
|
79
|
-
items: list[str] = []
|
|
80
|
-
inside = False
|
|
81
|
-
for line in lines:
|
|
82
|
-
stripped = line.strip()
|
|
83
|
-
if not inside:
|
|
84
|
-
if stripped == f"{block_name}:":
|
|
85
|
-
inside = True
|
|
86
|
-
continue
|
|
87
|
-
|
|
88
|
-
if line and not line.startswith(" "):
|
|
89
|
-
break
|
|
90
|
-
if stripped.startswith("- "):
|
|
91
|
-
value = stripped[2:].strip()
|
|
92
|
-
if len(value) >= 2 and value[0] == value[-1] and value[0] in {'"', "'"}:
|
|
93
|
-
value = value[1:-1]
|
|
94
|
-
if value:
|
|
95
|
-
items.append(value)
|
|
96
|
-
return items
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def merge_routing_template(existing_text: str) -> str:
|
|
100
|
-
if not existing_text.strip():
|
|
101
|
-
return render_default_routing_yaml()
|
|
102
|
-
|
|
103
|
-
lines = _normalize_line_endings(existing_text).split("\n")
|
|
104
|
-
custom_frontend = _extract_list_block(lines, "custom_frontend_paths")
|
|
105
|
-
custom_backend = _extract_list_block(lines, "custom_backend_paths")
|
|
106
|
-
|
|
107
|
-
merged = render_default_routing_yaml().split("\n")
|
|
108
|
-
output: list[str] = []
|
|
109
|
-
current_block = ""
|
|
110
|
-
|
|
111
|
-
for line in merged:
|
|
112
|
-
stripped = line.strip()
|
|
113
|
-
output.append(line)
|
|
114
|
-
if stripped == "custom_frontend_paths:":
|
|
115
|
-
current_block = "custom_frontend_paths"
|
|
116
|
-
for item in custom_frontend:
|
|
117
|
-
output.append(f' - "{item}"')
|
|
118
|
-
continue
|
|
119
|
-
if stripped == "custom_backend_paths:":
|
|
120
|
-
current_block = "custom_backend_paths"
|
|
121
|
-
for item in custom_backend:
|
|
122
|
-
output.append(f' - "{item}"')
|
|
123
|
-
continue
|
|
124
|
-
if stripped.endswith(":") and stripped not in {"custom_frontend_paths:", "custom_backend_paths:"}:
|
|
125
|
-
current_block = stripped[:-1]
|
|
126
|
-
|
|
127
|
-
return "\n".join(output).rstrip() + "\n"
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def sync_workspace_routing_file(target_path: Path) -> Path:
|
|
131
|
-
existing_text = target_path.read_text(encoding="utf-8") if target_path.exists() else ""
|
|
132
|
-
merged_text = merge_routing_template(existing_text)
|
|
133
|
-
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
134
|
-
target_path.write_text(merged_text, encoding="utf-8")
|
|
135
|
-
return target_path
|
|
1
|
+
from codecgc_runtime.routing_template import DEFAULT_BACKEND_PATHS
|
|
2
|
+
from codecgc_runtime.routing_template import DEFAULT_BACKEND_TEST_PATHS
|
|
3
|
+
from codecgc_runtime.routing_template import DEFAULT_DOCS_PATHS
|
|
4
|
+
from codecgc_runtime.routing_template import DEFAULT_FRONTEND_PATHS
|
|
5
|
+
from codecgc_runtime.routing_template import DEFAULT_FRONTEND_TEST_PATHS
|
|
6
|
+
from codecgc_runtime.routing_template import DEFAULT_ORCHESTRATION_PATHS
|
|
7
|
+
from codecgc_runtime.routing_template import DEFAULT_RULES
|
|
8
|
+
from codecgc_runtime.routing_template import DEFAULT_SHARED_PATHS
|
|
9
|
+
from codecgc_runtime.routing_template import merge_routing_template
|
|
10
|
+
from codecgc_runtime.routing_template import render_default_routing_yaml
|
|
11
|
+
from codecgc_runtime.routing_template import sync_workspace_routing_file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Shared CodeCGC runtime helpers."""
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from .paths import PROJECT_ROOT
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
CODECGC_ROOT = PROJECT_ROOT / "codecgc"
|
|
9
|
+
PRODUCT_ROOT = CODECGC_ROOT
|
|
10
|
+
FIXTURE_ROOT = CODECGC_ROOT / "fixtures"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def normalize_artifact_class(value: str | None) -> str:
|
|
14
|
+
cleaned = str(value or "product").strip().lower()
|
|
15
|
+
return "fixture" if cleaned == "fixture" else "product"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def flow_root(flow: str, artifact_class: str) -> Path:
|
|
19
|
+
base = FIXTURE_ROOT if normalize_artifact_class(artifact_class) == "fixture" else PRODUCT_ROOT
|
|
20
|
+
return base / ("features" if flow == "feature" else "issues")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def execution_root(artifact_class: str) -> Path:
|
|
24
|
+
base = FIXTURE_ROOT if normalize_artifact_class(artifact_class) == "fixture" else PRODUCT_ROOT
|
|
25
|
+
return base / "execution"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def discover_flow_directory(flow: str, slug: str, artifact_class: str = "auto") -> tuple[str, Path] | None:
|
|
29
|
+
classes = (
|
|
30
|
+
[normalize_artifact_class(artifact_class)]
|
|
31
|
+
if artifact_class in {"product", "fixture"}
|
|
32
|
+
else ["product", "fixture"]
|
|
33
|
+
)
|
|
34
|
+
for candidate_class in classes:
|
|
35
|
+
directory = flow_root(flow, candidate_class) / slug
|
|
36
|
+
if directory.exists():
|
|
37
|
+
return candidate_class, directory
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def artifact_output_root(artifact_class: str) -> Path:
|
|
42
|
+
return FIXTURE_ROOT if normalize_artifact_class(artifact_class) == "fixture" else PRODUCT_ROOT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def configure_utf8_stdio() -> None:
|
|
9
|
+
for stream_name in ("stdout", "stderr"):
|
|
10
|
+
stream = getattr(sys, stream_name, None)
|
|
11
|
+
if stream is None:
|
|
12
|
+
continue
|
|
13
|
+
reconfigure = getattr(stream, "reconfigure", None)
|
|
14
|
+
if callable(reconfigure):
|
|
15
|
+
try:
|
|
16
|
+
reconfigure(encoding="utf-8", errors="replace")
|
|
17
|
+
except Exception:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def print_json(payload: dict[str, Any], *, file: Any | None = None) -> None:
|
|
22
|
+
target = file or sys.stdout
|
|
23
|
+
text = json.dumps(payload, ensure_ascii=False, indent=2)
|
|
24
|
+
target.write(text)
|
|
25
|
+
target.write("\n")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def render_summary_block(title: str, base_lines: list[str], next_actions: list[str]) -> str:
|
|
29
|
+
lines = [title, *base_lines]
|
|
30
|
+
unique_actions: list[str] = []
|
|
31
|
+
seen: set[str] = set()
|
|
32
|
+
for item in next_actions:
|
|
33
|
+
normalized = str(item).strip()
|
|
34
|
+
if not normalized or normalized in seen:
|
|
35
|
+
continue
|
|
36
|
+
seen.add(normalized)
|
|
37
|
+
unique_actions.append(normalized)
|
|
38
|
+
|
|
39
|
+
if unique_actions:
|
|
40
|
+
lines.append(f"- 下一步: {unique_actions[0]}")
|
|
41
|
+
for item in unique_actions[1:]:
|
|
42
|
+
lines.append(f"- 备选后续: {item}")
|
|
43
|
+
else:
|
|
44
|
+
lines.append("- 下一步: 无")
|
|
45
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .paths import PACKAGE_ROOT
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
WORKSPACE = PACKAGE_ROOT
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def resolve_python_command() -> str:
|
|
14
|
+
override = os.environ.get("CODECGC_PYTHON_COMMAND", "").strip()
|
|
15
|
+
if override:
|
|
16
|
+
return override
|
|
17
|
+
return sys.executable
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def build_executor_registry() -> dict[str, dict[str, Any]]:
|
|
21
|
+
python_command = resolve_python_command()
|
|
22
|
+
return {
|
|
23
|
+
"backend": {
|
|
24
|
+
"target": "backend",
|
|
25
|
+
"mcp_server_name": "codex",
|
|
26
|
+
"routing_executor": "codexmcp",
|
|
27
|
+
"tool_name": "implement_backend_task",
|
|
28
|
+
"python_module": "codexmcp.cli",
|
|
29
|
+
"pythonpath": str(WORKSPACE / "codexmcp" / "src"),
|
|
30
|
+
"python_command": python_command,
|
|
31
|
+
},
|
|
32
|
+
"frontend": {
|
|
33
|
+
"target": "frontend",
|
|
34
|
+
"mcp_server_name": "gemini",
|
|
35
|
+
"routing_executor": "geminimcp",
|
|
36
|
+
"tool_name": "implement_frontend_task",
|
|
37
|
+
"python_module": "geminimcp.cli",
|
|
38
|
+
"pythonpath": str(WORKSPACE / "geminimcp" / "src"),
|
|
39
|
+
"python_command": python_command,
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_executor_config(target: str) -> dict[str, Any]:
|
|
45
|
+
registry = build_executor_registry()
|
|
46
|
+
if target not in registry:
|
|
47
|
+
raise ValueError(f"Unsupported target: {target}")
|
|
48
|
+
return registry[target]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def build_executor_env(target: str) -> dict[str, str]:
|
|
52
|
+
env = dict(os.environ)
|
|
53
|
+
config = get_executor_config(target)
|
|
54
|
+
env["PYTHONPATH"] = str(config["pythonpath"])
|
|
55
|
+
return env
|
|
@@ -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
|