dsh-plugin-opc 0.1.16 → 0.1.17
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/lib/client.js +38 -213
- package/lib/index.js +200 -79
- package/package.json +1 -1
- package/runtime/app_delivery/SKILL.md +1 -1
- package/runtime/app_delivery/references/contract.md +1 -0
- package/runtime/app_delivery/scripts/delivery.py +40 -8
- package/runtime/app_delivery_auth.py +29 -12
- package/runtime/app_delivery_migration.py +122 -34
- package/runtime/worker.py +16 -13
|
@@ -43,32 +43,49 @@ def resolve_authentication(contract):
|
|
|
43
43
|
item['auth'] = {**copy.deepcopy(best.get('auth', {})), 'evidence': best['evidence']}
|
|
44
44
|
auth = item.get('auth', {'type': 'unknown'})
|
|
45
45
|
if auth.get('type') == 'unknown':
|
|
46
|
-
|
|
46
|
+
evidence = item.get('evidence')
|
|
47
|
+
location = evidence[0] if isinstance(evidence, list) and evidence else ''
|
|
48
|
+
origin = f"。源码位置:{location}" if isinstance(location, str) and location else ""
|
|
49
|
+
label = item.get('method') if target == 'api' else '页面'
|
|
50
|
+
raise ValueError(f"认证尚未分析:{label or '接口'} {item['path']}{origin}。请读取该条目的实际登录、会话或权限代码,补齐对应的 auth 或 auth_rules。")
|
|
47
51
|
return contract
|
|
48
52
|
|
|
49
53
|
|
|
50
54
|
def validate_auth_evidence(source, proposal):
|
|
51
55
|
"""Check citations in the exact source snapshot the proposal describes."""
|
|
52
56
|
contract = proposal["contract"]
|
|
53
|
-
changes = {
|
|
57
|
+
changes = {
|
|
58
|
+
delivery.relative(source, change["path"]): change["content"]
|
|
59
|
+
for change in proposal.get("changes", [])
|
|
60
|
+
}
|
|
61
|
+
entries = [entry.get("evidence") if isinstance(entry, dict) else None
|
|
62
|
+
for entry in [*contract.get("auth_rules", []), *contract.get("auth_blockers", [])]]
|
|
63
|
+
# Older contracts put source citations on the route itself. When an
|
|
64
|
+
# explicit authentication citation is supplied, check that citation.
|
|
65
|
+
for collection in ("apis", "pages"):
|
|
66
|
+
for item in contract.get(collection, []):
|
|
67
|
+
entries.append(item.get("auth", {}).get("evidence", item.get("evidence")))
|
|
68
|
+
|
|
54
69
|
line_counts = {}
|
|
55
|
-
for
|
|
56
|
-
if not isinstance(
|
|
70
|
+
for citations in entries:
|
|
71
|
+
if not isinstance(citations, list) or not citations:
|
|
57
72
|
raise ValueError("认证证据必须是非空的 文件:行号 数组")
|
|
58
|
-
for evidence in
|
|
73
|
+
for evidence in citations:
|
|
59
74
|
match = re.fullmatch(r"(.+):(\d+)(?:-(\d+))?", evidence) if isinstance(evidence, str) else None
|
|
60
75
|
if not match:
|
|
61
76
|
raise ValueError("认证证据必须引用源码读取工具返回的 文件:行号")
|
|
62
77
|
path, start, end = match.groups()
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
content = changes.get(
|
|
66
|
-
if content is None
|
|
78
|
+
source_path = delivery.relative(source, path)
|
|
79
|
+
if source_path not in line_counts:
|
|
80
|
+
content = changes.get(source_path)
|
|
81
|
+
if content is None:
|
|
82
|
+
if not source_path.is_file():
|
|
83
|
+
raise ValueError(f"认证证据位置不存在:{evidence}。找不到文件 {path}" + delivery.source_path_hint(source, path))
|
|
67
84
|
content = delivery.text_of(source_path)
|
|
68
|
-
line_counts[
|
|
69
|
-
count = line_counts[
|
|
85
|
+
line_counts[source_path] = len(content.splitlines()) if content is not None else 0
|
|
86
|
+
count = line_counts[source_path]
|
|
70
87
|
if not 1 <= int(start) <= int(end or start) <= count:
|
|
71
|
-
location = "拟提交文件" if
|
|
88
|
+
location = "拟提交文件" if source_path in changes else "当前导入源码"
|
|
72
89
|
raise ValueError(
|
|
73
90
|
f"认证证据位置不存在:{evidence}。{location} {path} 共 {count} 行。"
|
|
74
91
|
"请只重读该文件的登录处理、会话读取或权限检查,用实际行号修正证据后重新提交。"
|
|
@@ -569,18 +569,57 @@ def _humanize_identifier(name: str, method: str = "GET", path: str = "") -> str:
|
|
|
569
569
|
return f"{n or '接口'} ({method.upper()} {path})"
|
|
570
570
|
|
|
571
571
|
|
|
572
|
-
|
|
573
|
-
"""
|
|
572
|
+
_NON_RUNTIME_SOURCE_DIRS = {
|
|
573
|
+
"__tests__", "testdata", "__fixtures__", "__mocks__", ".storybook",
|
|
574
|
+
}
|
|
575
|
+
_NON_RUNTIME_DIRS_OUTSIDE_ROUTES = {"test", "tests", "fixtures", "examples", "samples"}
|
|
576
|
+
_ROUTER_DIRS = {"app", "pages", "routes", "routers", "views", "controllers"}
|
|
577
|
+
_TEST_SOURCE_NAME = re.compile(
|
|
578
|
+
r"^(?:test_.*\.py|tests\.py|conftest\.py)$|_test\.(?:py|go)$|\.(?:spec|test)\.[cm]?[jt]sx?$",
|
|
579
|
+
re.I,
|
|
580
|
+
)
|
|
581
|
+
_DEMO_ONLY_TEXT = re.compile(
|
|
582
|
+
r"\bdemo[- ]only\b|\b(?:not|never) (?:for|use in) production\b|仅供演示|(?:不得|不可|不能)用于生产|不是生产",
|
|
583
|
+
re.I,
|
|
584
|
+
)
|
|
585
|
+
_DEMO_START_GUARD = re.compile(
|
|
586
|
+
r"""if\s*\(\s*!\s*process\.argv\.includes\(\s*['"]--(?:demo|fixture)['"]\s*\)\s*\)\s*(?:\{\s*)?(?:throw\b|process\.exit\s*\()"""
|
|
587
|
+
r"""|if\s+not\s+[\w.]+\.(?:demo|fixture)\s*:\s*(?:raise\b|[\w.]+\.(?:error|exit)\s*\()"""
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def _is_non_runtime_source(path: Path, rel_parts: tuple[str, ...]) -> bool:
|
|
592
|
+
folders = [part.casefold() for part in rel_parts[:-1]]
|
|
593
|
+
if any(part in _NON_RUNTIME_SOURCE_DIRS or part.endswith(("测试夹具", "验收夹具", "演示夹具")) for part in folders):
|
|
594
|
+
return True
|
|
595
|
+
if _TEST_SOURCE_NAME.search(path.name) or any(
|
|
596
|
+
part in _NON_RUNTIME_DIRS_OUTSIDE_ROUTES and (i == 0 or folders[i - 1] not in _ROUTER_DIRS)
|
|
597
|
+
for i, part in enumerate(folders)
|
|
598
|
+
):
|
|
599
|
+
return True
|
|
600
|
+
if path.suffix in {".py", ".js", ".mjs", ".cjs", ".ts"} and path.stat().st_size <= 500_000:
|
|
601
|
+
text = path.read_text(encoding="utf-8", errors="ignore")
|
|
602
|
+
# A demo flag alone is also used by real servers in optional development mode.
|
|
603
|
+
if _DEMO_START_GUARD.search(text) and _DEMO_ONLY_TEXT.search(text):
|
|
604
|
+
return True
|
|
605
|
+
return False
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def scan_app_routes_and_pages(source: Path, *, build_context: list[str] | None = None) -> dict:
|
|
609
|
+
"""Deterministically scan application sources for:
|
|
574
610
|
- All backend API endpoints (FastAPI, Flask, Express/Node, Go, etc.) with method, full path, parameters, request_body, auth, effect, and source line evidence.
|
|
575
611
|
- All frontend pages AND SPA sub-views/panels with path, purpose, and source line evidence.
|
|
576
612
|
- Runtime language, minimum version, syntax requirements (e.g. Python >=3.11 for StrEnum), and existing Dockerfile info.
|
|
577
613
|
"""
|
|
614
|
+
build_inputs = {delivery.relative(source, entry) for entry in (build_context or [])}
|
|
578
615
|
source_files: list[Path] = []
|
|
579
616
|
for p in sorted(source.rglob("*")):
|
|
580
617
|
if not p.is_file() or p.is_symlink():
|
|
581
618
|
continue
|
|
619
|
+
if build_inputs and p not in build_inputs and not build_inputs.intersection(p.parents):
|
|
620
|
+
continue
|
|
582
621
|
rel_parts = p.relative_to(source).parts
|
|
583
|
-
if any(part in delivery.EXCLUDED for part in rel_parts):
|
|
622
|
+
if any(part in delivery.EXCLUDED for part in rel_parts) or _is_non_runtime_source(p, rel_parts):
|
|
584
623
|
continue
|
|
585
624
|
source_files.append(p)
|
|
586
625
|
|
|
@@ -780,9 +819,20 @@ def _scan_openapi_specs(source: Path, files: list[Path]) -> list[dict]:
|
|
|
780
819
|
api_id = op_id if op_id and op_id[0].isalpha() else (raw_id if raw_id and raw_id[0].isalpha() else f"op-{raw_id or 'root'}")
|
|
781
820
|
|
|
782
821
|
params: list[dict] = []
|
|
822
|
+
request_body = None
|
|
783
823
|
for param in op.get("parameters") or []:
|
|
784
824
|
if isinstance(param, dict) and param.get("name"):
|
|
785
825
|
p_in = param.get("in", "query")
|
|
826
|
+
if p_in == "body":
|
|
827
|
+
consumes = op.get("consumes") or doc.get("consumes")
|
|
828
|
+
media = consumes[0] if isinstance(consumes, list) and consumes and isinstance(consumes[0], str) else "application/json"
|
|
829
|
+
request_body = {
|
|
830
|
+
"required": bool(param.get("required")),
|
|
831
|
+
"description": param.get("description") or "请求体",
|
|
832
|
+
"content_type": media,
|
|
833
|
+
"schema": param.get("schema") or {"type": "object"},
|
|
834
|
+
}
|
|
835
|
+
continue
|
|
786
836
|
params.append({
|
|
787
837
|
"name": param["name"],
|
|
788
838
|
"in": p_in,
|
|
@@ -792,6 +842,18 @@ def _scan_openapi_specs(source: Path, files: list[Path]) -> list[dict]:
|
|
|
792
842
|
"schema": param.get("schema") or {"type": param.get("type", "string")},
|
|
793
843
|
})
|
|
794
844
|
|
|
845
|
+
declared_body = op.get("requestBody")
|
|
846
|
+
content = declared_body.get("content") if isinstance(declared_body, dict) else None
|
|
847
|
+
if isinstance(content, dict) and content:
|
|
848
|
+
media = "application/json" if "application/json" in content else next(iter(content))
|
|
849
|
+
schema = content[media].get("schema") if isinstance(content[media], dict) else None
|
|
850
|
+
request_body = {
|
|
851
|
+
"required": bool(declared_body.get("required")),
|
|
852
|
+
"description": declared_body.get("description") or "请求体",
|
|
853
|
+
"content_type": media,
|
|
854
|
+
"schema": schema or {"type": "object"},
|
|
855
|
+
}
|
|
856
|
+
|
|
795
857
|
# Route discovery is not authentication analysis.
|
|
796
858
|
auth_obj = {"type": "unknown"}
|
|
797
859
|
|
|
@@ -803,7 +865,7 @@ def _scan_openapi_specs(source: Path, files: list[Path]) -> list[dict]:
|
|
|
803
865
|
"purpose": purpose,
|
|
804
866
|
"evidence": [f"{rel}:1"],
|
|
805
867
|
"parameters": params,
|
|
806
|
-
"request_body":
|
|
868
|
+
"request_body": request_body,
|
|
807
869
|
"responses": {"200": {"type": "object", "required": [], "properties": {"ok": {"type": "boolean"}}}},
|
|
808
870
|
"auth": auth_obj,
|
|
809
871
|
"effect": effect,
|
|
@@ -1208,6 +1270,16 @@ def _scan_js_ts_routes(source: Path, files: list[Path]) -> list[dict]:
|
|
|
1208
1270
|
# NestJS Controller decorators
|
|
1209
1271
|
nest_controller_re = re.compile(r"""@Controller\(\s*['"]?([^'"]*?)['"]?\s*\)[\s\S]*?class\s+([A-Za-z0-9_]+)""")
|
|
1210
1272
|
nest_method_re = re.compile(r"""@(Get|Post|Put|Patch|Delete)\(\s*['"]?([^'"]*?)['"]?\s*\)[\s\S]*?(?:async\s+)?([a-zA-Z0-9_]+)\s*\(""")
|
|
1273
|
+
nest_global_prefix_re = re.compile(r"""(?m)^\s*\w+\.setGlobalPrefix\(\s*(['"])([\w/-]+)\1\s*\)""")
|
|
1274
|
+
nest_prefixes: dict[Path, set[str]] = {}
|
|
1275
|
+
package_roots = {p.parent for p in files if p.name == "package.json"}
|
|
1276
|
+
for entry in files:
|
|
1277
|
+
if entry.name not in {"main.ts", "main.js"} or entry.stat().st_size > 500_000:
|
|
1278
|
+
continue
|
|
1279
|
+
content = entry.read_text(encoding="utf-8", errors="ignore")
|
|
1280
|
+
prefixes = {match.group(2).strip("/") for match in nest_global_prefix_re.finditer(content)}
|
|
1281
|
+
if "NestFactory" in content and prefixes:
|
|
1282
|
+
nest_prefixes.setdefault(entry.parent, set()).update(prefixes)
|
|
1211
1283
|
|
|
1212
1284
|
for p in files:
|
|
1213
1285
|
if p.suffix not in {".js", ".ts", ".mjs", ".cjs"} or p.stat().st_size > 500_000:
|
|
@@ -1257,10 +1329,19 @@ def _scan_js_ts_routes(source: Path, files: list[Path]) -> list[dict]:
|
|
|
1257
1329
|
if "@Controller" in content:
|
|
1258
1330
|
m_ctrl = nest_controller_re.search(content)
|
|
1259
1331
|
ctrl_prefix = m_ctrl.group(1).strip("/") if m_ctrl else ""
|
|
1332
|
+
global_prefix = ""
|
|
1333
|
+
for parent in p.parents:
|
|
1334
|
+
prefixes = nest_prefixes.get(parent)
|
|
1335
|
+
if prefixes:
|
|
1336
|
+
if len(prefixes) == 1:
|
|
1337
|
+
global_prefix = next(iter(prefixes))
|
|
1338
|
+
break
|
|
1339
|
+
if parent in package_roots or parent == source:
|
|
1340
|
+
break
|
|
1260
1341
|
for m in nest_method_re.finditer(content):
|
|
1261
|
-
mth, sub
|
|
1262
|
-
full = "/" + "/".join(
|
|
1263
|
-
routes.append(_make_js_route(mth, full, rel, 1))
|
|
1342
|
+
mth, sub = m.group(1).upper(), m.group(2).strip("/")
|
|
1343
|
+
full = "/" + "/".join(part for part in (global_prefix, ctrl_prefix, sub) if part)
|
|
1344
|
+
routes.append(_make_js_route(mth, full, rel, content.count("\n", 0, m.start()) + 1))
|
|
1264
1345
|
|
|
1265
1346
|
# Next.js App Router API routes (app/api/**/route.ts)
|
|
1266
1347
|
for p in files:
|
|
@@ -2048,9 +2129,15 @@ def _auto_adapt_persistent_file_storage(source: Path, slug: str, data: dict, pro
|
|
|
2048
2129
|
except Exception:
|
|
2049
2130
|
pass
|
|
2050
2131
|
workdir = "/app"
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2132
|
+
lines = df_text.splitlines()
|
|
2133
|
+
final_stage_start = next(
|
|
2134
|
+
(index for index in range(len(lines) - 1, -1, -1) if re.match(r"\s*FROM\s+", lines[index], re.I)),
|
|
2135
|
+
0,
|
|
2136
|
+
)
|
|
2137
|
+
final_stage = "\n".join(lines[final_stage_start:])
|
|
2138
|
+
workdirs = re.findall(r"(?im)^\s*WORKDIR\s+(/[A-Za-z0-9_./-]*)\s*(?:#.*)?$", final_stage)
|
|
2139
|
+
if workdirs:
|
|
2140
|
+
workdir = workdirs[-1].rstrip("/") or "/app"
|
|
2054
2141
|
|
|
2055
2142
|
# 2. Deterministically inspect local file storage & merge with any AI-declared mounts
|
|
2056
2143
|
scanned_storage = inspect_local_file_storage(source, slug=slug, workdir=workdir, has_migrations=False)
|
|
@@ -2100,37 +2187,35 @@ def _auto_adapt_persistent_file_storage(source: Path, slug: str, data: dict, pro
|
|
|
2100
2187
|
if (source / top_dir).exists() and top_dir not in build_ctx:
|
|
2101
2188
|
build_ctx.append(top_dir)
|
|
2102
2189
|
|
|
2103
|
-
# 4.
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
)
|
|
2190
|
+
# 4. Seed the actual volume destinations without replacing a custom startup.
|
|
2191
|
+
has_entrypoint = bool(re.search(r"(?im)^\s*ENTRYPOINT\s+", final_stage))
|
|
2192
|
+
if df_text and not has_entrypoint and ".opc-seed" not in final_stage and "opc-storage-init.sh" not in final_stage:
|
|
2193
|
+
seed_dir = f"{workdir}/.opc-seed"
|
|
2108
2194
|
cpaths_sh = " ".join(
|
|
2109
|
-
f'"{
|
|
2195
|
+
f'"{path}"' for path in (m["container_path"] for m in mounts)
|
|
2196
|
+
if re.fullmatch(r"/[A-Za-z0-9_./-]+", path) and ".." not in Path(path).parts
|
|
2197
|
+
and not (seed_dir == path.rstrip("/") or seed_dir.startswith(path.rstrip("/") + "/") or path.startswith(seed_dir + "/"))
|
|
2110
2198
|
)
|
|
2111
|
-
if
|
|
2112
|
-
|
|
2199
|
+
if cpaths_sh:
|
|
2200
|
+
init_script = f"{workdir}/.opc-seed/opc-storage-init.sh"
|
|
2113
2201
|
seed_snippet_lines = [
|
|
2114
2202
|
"# [OPC Persistent Storage] Backup initial seed data & hydrate external volume on startup",
|
|
2115
|
-
f
|
|
2116
|
-
f" && for d in {
|
|
2117
|
-
|
|
2118
|
-
|
|
2203
|
+
f'RUN mkdir -p "{seed_dir}" {cpaths_sh} \\',
|
|
2204
|
+
f" && i=0 && for d in {cpaths_sh}; do \\",
|
|
2205
|
+
" i=$((i+1)); \\",
|
|
2206
|
+
' if [ -n "$(ls -A "$d" 2>/dev/null)" ]; then \\',
|
|
2207
|
+
f' mkdir -p "{seed_dir}/$i" && cp -a "$d/." "{seed_dir}/$i/" || exit 1; \\',
|
|
2119
2208
|
" fi; \\",
|
|
2120
2209
|
" done \\",
|
|
2121
|
-
f" && printf '#!/bin/sh\\nset -e\\nfor d in {
|
|
2122
|
-
|
|
2210
|
+
f" && printf '#!/bin/sh\\nset -e\\ni=0\\nfor d in {cpaths_sh}; do\\n i=$((i+1))\\n mkdir -p \"$d\"\\n if [ -d \"{seed_dir}/$i\" ]; then\\n for f in \"{seed_dir}/$i\"/* \"{seed_dir}/$i\"/.[!.]*; do\\n [ -e \"$f\" ] || continue\\n bn=\"$(basename \"$f\")\"\\n [ -e \"$d/$bn\" ] || cp -a \"$f\" \"$d/$bn\"\\n done\\n fi\\ndone\\nexec \"$@\"\\n' > \"{init_script}\" \\",
|
|
2211
|
+
f' && chmod +x "{init_script}"',
|
|
2212
|
+
"ENTRYPOINT " + json.dumps([init_script]),
|
|
2123
2213
|
]
|
|
2124
|
-
if not has_entrypoint:
|
|
2125
|
-
seed_snippet_lines.append('ENTRYPOINT ["/opc-storage-init.sh"]')
|
|
2126
2214
|
seed_block = "\n".join(seed_snippet_lines)
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
stripped = lines[idx].strip().upper()
|
|
2132
|
-
if stripped.startswith("CMD ") or stripped.startswith("CMD[") or stripped.startswith("EXPOSE "):
|
|
2133
|
-
insert_idx = idx
|
|
2215
|
+
insert_idx = next(
|
|
2216
|
+
(index for index in range(len(lines) - 1, final_stage_start, -1) if re.match(r"\s*CMD(?:\s+|\[)", lines[index], re.I)),
|
|
2217
|
+
len(lines),
|
|
2218
|
+
)
|
|
2134
2219
|
updated_df = "\n".join(lines[:insert_idx] + [seed_block] + lines[insert_idx:]) + "\n"
|
|
2135
2220
|
mount_summary = "、".join(m["container_path"] for m in mounts)
|
|
2136
2221
|
if "Dockerfile" in changes_by_path:
|
|
@@ -2161,7 +2246,10 @@ def enrich_contract_and_discovery_report(source: Path, data: dict, proposal: dic
|
|
|
2161
2246
|
Step 2 Transformation Report (proposal['transformation_report']).
|
|
2162
2247
|
"""
|
|
2163
2248
|
contract = proposal.setdefault("contract", {})
|
|
2164
|
-
|
|
2249
|
+
build_context = contract.get("build_context")
|
|
2250
|
+
if not isinstance(build_context, list):
|
|
2251
|
+
build_context = None
|
|
2252
|
+
scan = scan_app_routes_and_pages(source, build_context=build_context)
|
|
2165
2253
|
sqlite_info = inspect_local_sqlite_files(source)
|
|
2166
2254
|
|
|
2167
2255
|
# 1. Merge any missing scanned APIs into contract['apis'] so 0 routes are omitted
|
package/runtime/worker.py
CHANGED
|
@@ -151,7 +151,7 @@ def resolve_and_enrich_proposal(
|
|
|
151
151
|
if cid and cid in draft_files:
|
|
152
152
|
staged = draft_files[cid]
|
|
153
153
|
if change.get("path") and staged.get("path") and change["path"] != staged["path"]:
|
|
154
|
-
raise ValueError("
|
|
154
|
+
raise ValueError(f"汇总提案的文件路径与分项提案不一致:{cid} 已对应 {staged['path']},本次提交 {change['path']}。请核对路径")
|
|
155
155
|
change = {**staged, **change}
|
|
156
156
|
elif not change.get("id") and change.get("path"):
|
|
157
157
|
by_path = next((v for v in draft_files.values() if isinstance(v, dict) and v.get("path") == change["path"]), None)
|
|
@@ -374,18 +374,20 @@ def main(body):
|
|
|
374
374
|
if action == "read":
|
|
375
375
|
source_dir = root / "review/source"
|
|
376
376
|
path = body["path"]
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
p = d.relative(source_dir, path)
|
|
378
|
+
change = None
|
|
379
|
+
if body.get("proposed"):
|
|
379
380
|
drafts = load_json_if_exists(root / "draft_files.json", {})
|
|
380
381
|
change = next((c for c in reversed(list(drafts.values())) if isinstance(c, dict) and c.get("path") == path), None)
|
|
381
|
-
|
|
382
|
-
|
|
382
|
+
proposed = change is not None and isinstance(change.get("content"), str)
|
|
383
|
+
if proposed:
|
|
383
384
|
content = change["content"]
|
|
384
385
|
else:
|
|
385
|
-
|
|
386
|
+
if not p.is_file():
|
|
387
|
+
raise ValueError(f"找不到源码或该路径的暂存稿:{path}" + d.source_path_hint(source_dir, path))
|
|
386
388
|
content = d.text_of(p)
|
|
387
389
|
if content is None:
|
|
388
|
-
return {"text": "Binary file"}
|
|
390
|
+
return {"path": path, "view": "proposed" if proposed else "original", "text": "Binary file"}
|
|
389
391
|
start = max(0, int(body.get("start", 1)) - 1)
|
|
390
392
|
lines = redact(content, path).splitlines()
|
|
391
393
|
excerpt = "\n".join(f"{i + start + 1}: {s[:400]}" for i, s in enumerate(lines[start:start+200]))
|
|
@@ -393,11 +395,13 @@ def main(body):
|
|
|
393
395
|
range_info = f"返回第 {start + 1}–{start + returned} 行" if returned else "所请求范围无内容"
|
|
394
396
|
location = "拟交付文件" if proposed else "原始源码"
|
|
395
397
|
excerpt = f"{location} {path} 共 {len(lines)} 行,{range_info}。\n{excerpt}"
|
|
398
|
+
if body.get("proposed") and not proposed:
|
|
399
|
+
excerpt = "该路径暂无暂存修改,以下为原始源码。\n" + excerpt
|
|
396
400
|
if not proposed:
|
|
397
401
|
fields = original_fields(source_dir, path)
|
|
398
402
|
if fields:
|
|
399
403
|
excerpt += "\nOriginal configuration references (metadata only; values stay local):\n" + json.dumps(fields, ensure_ascii=False)
|
|
400
|
-
return {"text": excerpt, "total_lines": len(lines)}
|
|
404
|
+
return {"path": path, "view": "proposed" if proposed else "original", "text": excerpt, "total_lines": len(lines)}
|
|
401
405
|
if action == "read_failed":
|
|
402
406
|
revision = body.get("revision", "")
|
|
403
407
|
d.require(isinstance(revision, str) and revision.isalnum(), "Invalid revision")
|
|
@@ -422,10 +426,9 @@ def main(body):
|
|
|
422
426
|
res = scan_app_routes_and_pages(root / "review/source")
|
|
423
427
|
d.save(root / "routes_scanned.json", {"scanned": True})
|
|
424
428
|
res["_auto_contract_enrichment"] = (
|
|
425
|
-
"
|
|
426
|
-
"
|
|
427
|
-
"
|
|
428
|
-
"也严禁把接口数量多或扫描问题写入 unresolved!"
|
|
429
|
+
"提交方案时,系统会按同一规则复核 build_context 内的接口与页面并合并进契约。"
|
|
430
|
+
"只提交需覆盖或补充的正式路由,不要把测试路径、演示入口和样例重新加进契约。"
|
|
431
|
+
"认证方式必须根据正式入口及中间件确认,扫描待核对项不用向用户提问。"
|
|
429
432
|
)
|
|
430
433
|
return res
|
|
431
434
|
if action == "inspect_local_storage":
|
|
@@ -459,7 +462,7 @@ def main(body):
|
|
|
459
462
|
drafts = load_json_if_exists(draft_path, {})
|
|
460
463
|
cid = change["id"]
|
|
461
464
|
if cid in drafts and drafts[cid].get("path") != change["path"]:
|
|
462
|
-
raise ValueError("同一修改 ID
|
|
465
|
+
raise ValueError(f"同一修改 ID 不能对应不同文件:{cid} 已对应 {drafts[cid]['path']},本次提交 {change['path']}。请核对路径")
|
|
463
466
|
drafts[cid] = change
|
|
464
467
|
save_draft_files(draft_path, drafts)
|
|
465
468
|
return {"staged": cid, "path": change["path"], "message": f"File proposal recorded: {cid}. Source is unchanged."}
|