kcode-pi 0.1.0
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/README.md +358 -0
- package/dist/cli/kcode.d.ts +15 -0
- package/dist/cli/kcode.js +153 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +7 -0
- package/docs/KCODE_DISTRIBUTION.md +91 -0
- package/extensions/kingdee-harness.ts +180 -0
- package/extensions/kingdee-header.ts +122 -0
- package/extensions/kingdee-tools.ts +379 -0
- package/knowledge/.backup/v1.0.0/version.json +10 -0
- package/knowledge/cangqiong/product-notes.md +15 -0
- package/knowledge/common/business-flows.md +115 -0
- package/knowledge/common/config-guides.md +110 -0
- package/knowledge/common/error-patterns.md +170 -0
- package/knowledge/common/implementation.md +144 -0
- package/knowledge/cosmic/hard-constraints.md +38 -0
- package/knowledge/cosmic/ksql-datafix.md +34 -0
- package/knowledge/cosmic/platform-baseline.md +32 -0
- package/knowledge/cosmic/plugin-decision-matrix.md +40 -0
- package/knowledge/cosmic/review-checklist.md +40 -0
- package/knowledge/cosmic/unittest.md +35 -0
- package/knowledge/enterprise/api-reference.md +186 -0
- package/knowledge/enterprise/code-patterns.md +217 -0
- package/knowledge/enterprise/plugin-lifecycle.md +188 -0
- package/knowledge/enterprise/tables.json +159 -0
- package/knowledge/flagship/api-reference.md +237 -0
- package/knowledge/flagship/code-patterns.md +246 -0
- package/knowledge/flagship/cosmic-platform-note.md +15 -0
- package/knowledge/flagship/plugin-lifecycle.md +248 -0
- package/knowledge/flagship/tables.json +159 -0
- package/knowledge/version.json +10 -0
- package/knowledge/xinghan/product-notes.md +15 -0
- package/package.json +71 -0
- package/prompts/kd-discuss.md +11 -0
- package/prompts/kd-execute.md +12 -0
- package/prompts/kd-plan.md +12 -0
- package/prompts/kd-ship.md +12 -0
- package/prompts/kd-spec.md +12 -0
- package/prompts/kd-verify.md +12 -0
- package/skills/kd-check/SKILL.md +26 -0
- package/skills/kd-cosmic-dev/SKILL.md +82 -0
- package/skills/kd-cosmic-review/SKILL.md +90 -0
- package/skills/kd-cosmic-unittest/SKILL.md +92 -0
- package/skills/kd-debug/SKILL.md +30 -0
- package/skills/kd-discuss/SKILL.md +24 -0
- package/skills/kd-execute/SKILL.md +22 -0
- package/skills/kd-gen/SKILL.md +34 -0
- package/skills/kd-ksql/SKILL.md +86 -0
- package/skills/kd-plan/SKILL.md +24 -0
- package/skills/kd-ship/SKILL.md +22 -0
- package/skills/kd-spec/SKILL.md +24 -0
- package/skills/kd-verify/SKILL.md +22 -0
- package/themes/kcode-dark.json +81 -0
- package/vendor/kingdee-skills/cosmic-unittest/SKILL.md +788 -0
- package/vendor/kingdee-skills/cosmic-unittest/author-cache.json +5 -0
- package/vendor/kingdee-skills/cosmic-unittest/cosmic-unittest-skill-overview.html +746 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/business-test.md +205 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/common-test.md +257 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/formplugin-test.md +560 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/op-plugin-test.md +231 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/validator-test.md +232 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/business-helper.md +184 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/common-module.md +355 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/convert-plugin.md +130 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/formplugin.md +235 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/op-plugin.md +226 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/validator.md +206 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/SKILL.md +674 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/advanced-scenario-checklist.md +307 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/algox-performance-checklist.md +129 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/coding-standard-checklist.md +491 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/cosmic-api-checklist.md +285 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-access-checklist.md +261 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-transaction-checklist.md +390 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/domain-logic-checklist.md +295 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/form-plugin-checklist.md +508 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/infra-checklist.md +254 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ksql-checklist.md +305 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/lifecycle-checklist.md +298 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/operation-plugin-checklist.md +442 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/test-mock-checklist.md +120 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ui-performance-checklist.md +320 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/pattern-matcher.py +336 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/review-score-calculator.py +121 -0
- package/vendor/kingdee-skills/ok-cosmic/CHANGELOG.md +295 -0
- package/vendor/kingdee-skills/ok-cosmic/README.md +460 -0
- package/vendor/kingdee-skills/ok-cosmic/SKILL.md +287 -0
- package/vendor/kingdee-skills/ok-cosmic/agents/openai.yaml +17 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BatchImportPluginTemplate.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BillPlugInTemplate.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ConvertPlugInTemplate.java +255 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/FormPluginTemplate.java +597 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/IWorkflowPluginTemplate.java +91 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ListPluginTemplate.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpPluginTemplate.java +201 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpenApiControllerTemplate.java +103 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/PrintPluginTemplate.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportFormPluginTemplate.java +257 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportListDataPluginTemplate.java +70 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/StandardTreeListPluginTemplate.java +130 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TaskTemplate.java +80 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TreeListPluginTemplate.java +152 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/WriteBackPlugInTemplate.java +286 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/attachment/AttachmentUploadBindSample.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/BotpTracePushSample.java +168 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/SampleConvertPlugin.java +223 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/cache/SampleCacheUsage.java +218 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/concurrent/SampleThreadPoolBatch.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectCrudSample.java +205 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectOpsSample.java +100 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/BeforeOperationConfirmSample.java +217 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ConfirmDialogSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/EntryRowCalculateSample.java +116 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/F7FilterSample.java +134 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/GetAndSetValueSample.java +176 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/HyperlinkJumpSample.java +124 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/OpenBillModalSample.java +253 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ReturnParentDataSample.java +295 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/TreeControlSample.java +140 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ViewControlOpsSample.java +132 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPluginBasicSample.java +170 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPreOpenFilterSample.java +68 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/message/MessageNotifySample.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/SampleMQConsumer.java +198 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/sample_mq.xml +15 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OpAddValidatorsSample.java +137 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OperationOptionBridgeSample.java +228 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/package-info.java +19 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BaseDataQuerySample.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BatchQuerySample.java +368 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/DataSetQueryStatSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportFormPlugin.java +179 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportListDataPlugin.java +616 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/snippets-guide.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/task/ScheduleTaskSample.java +160 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/workflow/SampleWorkflowPlugin.java +302 -0
- package/vendor/kingdee-skills/ok-cosmic/manifest.json +78 -0
- package/vendor/kingdee-skills/ok-cosmic/ok-cosmic-intro.html +903 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/attachment-api.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/botp-convert.md +98 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/dynamic-object.md +113 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/entity-metadata.md +123 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/event-lifecycle.md +184 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/flex-prop.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/form-utils.md +133 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/operate-chain.md +159 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/plugin-base.md +218 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/query-dataset.md +149 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/request-context.md +88 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/view-handler.md +157 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-bill.md +76 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-botp.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-form.md +165 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-import.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-list.md +227 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-openapi.md +112 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-operation.md +135 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-print.md +65 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-data.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-form.md +90 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-task.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-tree-list.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-workflow.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-writeback.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-algo.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-cache.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-model-svc.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-object.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-entity-model.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-exception.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-file.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-id.md +47 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-lock.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-log.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-network-control.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-orm-access.md +78 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-request-context.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-threadpool.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-tx.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-utils.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/requirements.txt +2 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/a-layer-rules.json +24 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/anti-patterns.md +48 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/cheat-sheet.md +256 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/coding-preferences.md +140 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/constraints.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/decision-matrix.md +222 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/intent-routing.md +94 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/platform-baseline.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/post-check.md +109 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/config_loader.py +204 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-api-knowledge.py +910 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-basedata-query.py +359 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-config-check.py +181 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-extpoints-query.py +389 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-form-metadata.py +856 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-check.py +262 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-lint.py +293 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/__init__.py +2 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/base.py +393 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/resource_check.py +176 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/scene_check.py +375 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/style_check.py +434 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/verify_check.py +36 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/route_client.py +186 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/script_utils.py +40 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/sqlite_cache.py +142 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-commons.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-features.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic-docs.db +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic.json +13 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-mac.sh +18 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-windows.bat +53 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup.jar +0 -0
- package/vendor/kingdee-skills/ok-ksql/SKILL.md +81 -0
- package/vendor/kingdee-skills/ok-ksql/agents/openai.yaml +7 -0
- package/vendor/kingdee-skills/ok-ksql/manifest.json +14 -0
- package/vendor/kingdee-skills/ok-ksql/references/ksql-datafix.md +452 -0
- package/vendor/kingdee-skills/ok-ksql/scripts/ksql_lint.py +363 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# SPDX-License-Identifier: NOASSERTION
|
|
3
|
+
"""
|
|
4
|
+
config_loader.py — Shared configuration loader for ok-cosmic scripts.
|
|
5
|
+
|
|
6
|
+
Provides shared helpers to:
|
|
7
|
+
1. Locate and parse ``ok-cosmic.json``
|
|
8
|
+
2. Validate Step 0 required content
|
|
9
|
+
3. Inject resolved config path metadata for downstream scripts
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
17
|
+
|
|
18
|
+
# Windows console encoding fix (shared by all scripts)
|
|
19
|
+
if os.name == "nt":
|
|
20
|
+
try:
|
|
21
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
22
|
+
sys.stderr.reconfigure(encoding="utf-8")
|
|
23
|
+
except Exception:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
Issue = Dict[str, str]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def resolve_project_config_path(config_path: Optional[str] = None) -> Path:
|
|
31
|
+
"""Resolve ``ok-cosmic.json`` path from CLI input or current working directory."""
|
|
32
|
+
return Path(config_path).expanduser() if config_path else Path.cwd() / "ok-cosmic.json"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def read_project_config(config_path: Optional[str] = None) -> Tuple[Path, Dict[str, Any]]:
|
|
36
|
+
"""
|
|
37
|
+
Read and parse ``ok-cosmic.json`` without mutating the payload.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
- resolved absolute config path
|
|
41
|
+
- raw JSON object as dict
|
|
42
|
+
"""
|
|
43
|
+
target_path = resolve_project_config_path(config_path)
|
|
44
|
+
|
|
45
|
+
if not target_path.is_file():
|
|
46
|
+
raise FileNotFoundError(
|
|
47
|
+
f"找不到配置文件: {target_path}。请确保文件存在或通过 --config 参数指定正确路径。"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
with target_path.open("r", encoding="utf-8") as f:
|
|
52
|
+
data = json.load(f)
|
|
53
|
+
except FileNotFoundError:
|
|
54
|
+
raise
|
|
55
|
+
except json.JSONDecodeError as e:
|
|
56
|
+
raise RuntimeError(
|
|
57
|
+
f"加载配置文件 {target_path} 失败: JSON 解析错误,第 {e.lineno} 行第 {e.colno} 列: {e.msg}"
|
|
58
|
+
) from e
|
|
59
|
+
except Exception as e:
|
|
60
|
+
raise RuntimeError(f"加载配置文件 {target_path} 失败: {e}") from e
|
|
61
|
+
|
|
62
|
+
if not isinstance(data, dict):
|
|
63
|
+
raise ValueError(f"配置文件格式错误: {target_path} 必须包含有效的 JSON 对象")
|
|
64
|
+
|
|
65
|
+
return target_path.resolve(), data
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _add_issue(issues: List[Issue], level: str, key: str, message: str) -> None:
|
|
69
|
+
issues.append({"level": level, "key": key, "message": message})
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _is_positive_number(value: Any) -> bool:
|
|
73
|
+
try:
|
|
74
|
+
return float(value) > 0
|
|
75
|
+
except (TypeError, ValueError):
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _resolve_child_path(base_dir: Path, raw_path: str) -> Path:
|
|
80
|
+
expanded = Path(os.path.expanduser(raw_path))
|
|
81
|
+
if expanded.is_absolute():
|
|
82
|
+
return expanded.resolve()
|
|
83
|
+
return (base_dir / expanded).resolve()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def validate_project_config(config: Dict[str, Any], config_path: Optional[str] = None) -> List[Issue]:
|
|
87
|
+
"""
|
|
88
|
+
Validate ``ok-cosmic.json`` content for Step 0 preflight.
|
|
89
|
+
|
|
90
|
+
Validation levels:
|
|
91
|
+
- ERROR: should stop before running skill scripts
|
|
92
|
+
- WARNING: non-blocking but means some capabilities are unavailable
|
|
93
|
+
"""
|
|
94
|
+
issues: List[Issue] = []
|
|
95
|
+
raw_config_path = config_path or str(config.get("__config_path__", "")).strip()
|
|
96
|
+
base_dir = (
|
|
97
|
+
Path(raw_config_path).expanduser().resolve().parent
|
|
98
|
+
if raw_config_path
|
|
99
|
+
else Path.cwd()
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
graph_config = config.get("graph")
|
|
103
|
+
if graph_config is None:
|
|
104
|
+
_add_issue(issues, "ERROR", "graph", "缺少 `graph` 配置对象。")
|
|
105
|
+
elif not isinstance(graph_config, dict):
|
|
106
|
+
_add_issue(issues, "ERROR", "graph", "`graph` 必须是 JSON 对象。")
|
|
107
|
+
else:
|
|
108
|
+
db_path = str(graph_config.get("dbPath", "")).strip()
|
|
109
|
+
if not db_path:
|
|
110
|
+
_add_issue(issues, "ERROR", "graph.dbPath", "缺少必填项 `graph.dbPath`。")
|
|
111
|
+
else:
|
|
112
|
+
resolved_db_path = _resolve_child_path(base_dir, db_path)
|
|
113
|
+
if not resolved_db_path.exists():
|
|
114
|
+
_add_issue(
|
|
115
|
+
issues,
|
|
116
|
+
"WARNING",
|
|
117
|
+
"graph.dbPath",
|
|
118
|
+
f"`graph.dbPath` 指向的文件不存在: {resolved_db_path}",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
route_env_available = bool(os.getenv("COSMIC_ROUTE_API") or os.getenv("COSMIC_RUNTIME_ROUTE_API"))
|
|
122
|
+
route_config = config.get("route")
|
|
123
|
+
route_api_url = ""
|
|
124
|
+
if route_config is not None:
|
|
125
|
+
if not isinstance(route_config, dict):
|
|
126
|
+
_add_issue(issues, "ERROR", "route", "`route` 必须是 JSON 对象。")
|
|
127
|
+
else:
|
|
128
|
+
route_api_url = str(route_config.get("apiUrl", "")).strip()
|
|
129
|
+
if not route_api_url and not route_env_available:
|
|
130
|
+
_add_issue(
|
|
131
|
+
issues,
|
|
132
|
+
"WARNING",
|
|
133
|
+
"route.apiUrl",
|
|
134
|
+
"`route.apiUrl` 为空,统一路由在线查询将不可用。",
|
|
135
|
+
)
|
|
136
|
+
if "timeoutSeconds" in route_config and not _is_positive_number(route_config.get("timeoutSeconds")):
|
|
137
|
+
_add_issue(
|
|
138
|
+
issues,
|
|
139
|
+
"ERROR",
|
|
140
|
+
"route.timeoutSeconds",
|
|
141
|
+
"`route.timeoutSeconds` 必须是大于 0 的数字。",
|
|
142
|
+
)
|
|
143
|
+
if "openApiSign" in route_config and not isinstance(route_config.get("openApiSign"), str):
|
|
144
|
+
_add_issue(
|
|
145
|
+
issues,
|
|
146
|
+
"ERROR",
|
|
147
|
+
"route.openApiSign",
|
|
148
|
+
"`route.openApiSign` 必须是字符串。",
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
if route_config is None and not route_env_available:
|
|
152
|
+
_add_issue(
|
|
153
|
+
issues,
|
|
154
|
+
"WARNING",
|
|
155
|
+
"route",
|
|
156
|
+
"缺少 `route` 配置节,三个在线查询脚本将无法通过统一路由查询。",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
extension_repos = config.get("extensionRepos")
|
|
160
|
+
if extension_repos is not None:
|
|
161
|
+
if not isinstance(extension_repos, list):
|
|
162
|
+
_add_issue(issues, "ERROR", "extensionRepos", "`extensionRepos` 必须是字符串数组。")
|
|
163
|
+
else:
|
|
164
|
+
for idx, raw_path in enumerate(extension_repos):
|
|
165
|
+
key = f"extensionRepos[{idx}]"
|
|
166
|
+
if not isinstance(raw_path, str) or not raw_path.strip():
|
|
167
|
+
_add_issue(
|
|
168
|
+
issues,
|
|
169
|
+
"ERROR",
|
|
170
|
+
key,
|
|
171
|
+
f"`{key}` 必须是非空字符串路径。",
|
|
172
|
+
)
|
|
173
|
+
continue
|
|
174
|
+
resolved_repo = _resolve_child_path(base_dir, raw_path.strip())
|
|
175
|
+
if not resolved_repo.is_dir():
|
|
176
|
+
_add_issue(
|
|
177
|
+
issues,
|
|
178
|
+
"WARNING",
|
|
179
|
+
key,
|
|
180
|
+
f"扩展代码库路径不存在或不是目录: {resolved_repo}",
|
|
181
|
+
)
|
|
182
|
+
else:
|
|
183
|
+
_add_issue(
|
|
184
|
+
issues,
|
|
185
|
+
"OK",
|
|
186
|
+
key,
|
|
187
|
+
f"扩展代码库: {resolved_repo}",
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
return issues
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def load_project_config(config_path: Optional[str] = None) -> Dict[str, Any]:
|
|
194
|
+
"""
|
|
195
|
+
Load project-level config from provided path or current working directory.
|
|
196
|
+
|
|
197
|
+
Returns a dict with two injected keys for downstream consumers:
|
|
198
|
+
- ``__config_path__``: absolute path to the resolved config file
|
|
199
|
+
- ``__config_dir__``: absolute path to the parent directory of the config file
|
|
200
|
+
"""
|
|
201
|
+
resolved, data = read_project_config(config_path)
|
|
202
|
+
data.setdefault("__config_path__", str(resolved))
|
|
203
|
+
data.setdefault("__config_dir__", str(resolved.parent))
|
|
204
|
+
return data
|