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,40 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# SPDX-License-Identifier: NOASSERTION
|
|
3
|
+
"""Small CLI helpers shared by ok-cosmic scripts."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Callable, Optional
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FriendlyArgumentParser(argparse.ArgumentParser):
|
|
13
|
+
"""ArgumentParser that reports concise failures instead of dumping usage."""
|
|
14
|
+
|
|
15
|
+
def error(self, message: str) -> None:
|
|
16
|
+
self.exit(1, f"✖️ 参数错误: {message}\n提示: 使用 --help 查看参数。\n")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def run_cli(main_func: Callable[[], Optional[int]]) -> int:
|
|
20
|
+
"""Run a CLI entrypoint and convert uncaught exceptions to failure text."""
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
result = main_func()
|
|
24
|
+
if isinstance(result, int):
|
|
25
|
+
return result
|
|
26
|
+
return 0
|
|
27
|
+
except SystemExit as e:
|
|
28
|
+
code = e.code
|
|
29
|
+
if code is None:
|
|
30
|
+
return 0
|
|
31
|
+
if isinstance(code, int):
|
|
32
|
+
return code
|
|
33
|
+
print(f"✖️ 执行失败: {code}", file=sys.stderr)
|
|
34
|
+
return 1
|
|
35
|
+
except KeyboardInterrupt:
|
|
36
|
+
print("✖️ 执行已取消", file=sys.stderr)
|
|
37
|
+
return 130
|
|
38
|
+
except Exception as e:
|
|
39
|
+
print(f"✖️ 执行失败: {e}", file=sys.stderr)
|
|
40
|
+
return 1
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# SPDX-License-Identifier: NOASSERTION
|
|
3
|
+
"""Shared SQLite JSON cache helpers for ok-cosmic scripts."""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import sqlite3
|
|
9
|
+
import sys
|
|
10
|
+
import time
|
|
11
|
+
from typing import Any, Dict, Iterable, Optional, Sequence
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
IDENTIFIER_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def resolve_graph_db_path(config: Dict[str, Any], missing_message: str) -> str:
|
|
18
|
+
"""Resolve graph.dbPath relative to ok-cosmic.json's directory."""
|
|
19
|
+
graph_config = config.get("graph", {})
|
|
20
|
+
if not isinstance(graph_config, dict):
|
|
21
|
+
graph_config = {}
|
|
22
|
+
|
|
23
|
+
db_path = str(graph_config.get("dbPath", "")).strip()
|
|
24
|
+
if not db_path:
|
|
25
|
+
raise ValueError(missing_message)
|
|
26
|
+
|
|
27
|
+
raw_db_path = os.path.expanduser(db_path)
|
|
28
|
+
if os.path.isabs(raw_db_path):
|
|
29
|
+
return os.path.normpath(raw_db_path)
|
|
30
|
+
|
|
31
|
+
base_dir = str(config.get("__config_dir__", "")).strip() or os.getcwd()
|
|
32
|
+
return os.path.normpath(os.path.abspath(os.path.join(base_dir, raw_db_path)))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _validate_identifier(value: str, label: str) -> str:
|
|
36
|
+
if not IDENTIFIER_RE.match(value):
|
|
37
|
+
raise ValueError(f"{label} 不是安全的 SQLite 标识符: {value}")
|
|
38
|
+
return value
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class JsonSqliteCache:
|
|
42
|
+
"""Small SQLite cache storing JSON payload + updated_at with TTL."""
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
db_path: str,
|
|
47
|
+
*,
|
|
48
|
+
table_name: str,
|
|
49
|
+
key_column: str,
|
|
50
|
+
create_sql: str,
|
|
51
|
+
ttl: int = 600,
|
|
52
|
+
check_same_thread: bool = True,
|
|
53
|
+
init_error_message: str = "初始化缓存表失败",
|
|
54
|
+
write_error_message: str = "写入缓存失败",
|
|
55
|
+
):
|
|
56
|
+
self.db_path = db_path
|
|
57
|
+
self.table_name = _validate_identifier(table_name, "table_name")
|
|
58
|
+
self.key_column = _validate_identifier(key_column, "key_column")
|
|
59
|
+
self.ttl = ttl
|
|
60
|
+
self.init_error_message = init_error_message
|
|
61
|
+
self.write_error_message = write_error_message
|
|
62
|
+
self._conn = sqlite3.connect(self.db_path, check_same_thread=check_same_thread)
|
|
63
|
+
self._conn.execute("PRAGMA journal_mode=WAL")
|
|
64
|
+
self._conn.execute("PRAGMA busy_timeout=5000")
|
|
65
|
+
self._conn.row_factory = sqlite3.Row
|
|
66
|
+
self._init_db(create_sql)
|
|
67
|
+
|
|
68
|
+
def _init_db(self, create_sql: str) -> None:
|
|
69
|
+
try:
|
|
70
|
+
self._conn.execute(create_sql)
|
|
71
|
+
self._conn.commit()
|
|
72
|
+
except Exception as e:
|
|
73
|
+
print(f" (DEBUG) {self.init_error_message}: {e}", file=sys.stderr)
|
|
74
|
+
|
|
75
|
+
def get(self, key: str) -> Optional[Dict[str, Any]]:
|
|
76
|
+
try:
|
|
77
|
+
row = self._conn.execute(
|
|
78
|
+
f"SELECT payload, updated_at FROM {self.table_name} WHERE {self.key_column} = ?",
|
|
79
|
+
(key,),
|
|
80
|
+
).fetchone()
|
|
81
|
+
if not row or (time.time() - row["updated_at"] > self.ttl):
|
|
82
|
+
return None
|
|
83
|
+
return json.loads(row["payload"])
|
|
84
|
+
except Exception:
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
def set_payload(
|
|
88
|
+
self,
|
|
89
|
+
key: str,
|
|
90
|
+
payload: Dict[str, Any],
|
|
91
|
+
*,
|
|
92
|
+
extra_columns: Optional[Sequence[str]] = None,
|
|
93
|
+
extra_values: Optional[Sequence[Any]] = None,
|
|
94
|
+
) -> None:
|
|
95
|
+
extra_columns = tuple(extra_columns or ())
|
|
96
|
+
extra_values = tuple(extra_values or ())
|
|
97
|
+
if len(extra_columns) != len(extra_values):
|
|
98
|
+
raise ValueError("extra_columns 和 extra_values 数量不一致")
|
|
99
|
+
for column in extra_columns:
|
|
100
|
+
_validate_identifier(column, "extra_column")
|
|
101
|
+
|
|
102
|
+
columns = (self.key_column, *extra_columns, "payload", "updated_at")
|
|
103
|
+
placeholders = ", ".join("?" for _ in columns)
|
|
104
|
+
column_sql = ", ".join(columns)
|
|
105
|
+
values = (
|
|
106
|
+
key,
|
|
107
|
+
*extra_values,
|
|
108
|
+
json.dumps(payload, ensure_ascii=False),
|
|
109
|
+
int(time.time()),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
self._conn.execute(
|
|
114
|
+
f"""
|
|
115
|
+
INSERT OR REPLACE INTO {self.table_name}
|
|
116
|
+
({column_sql})
|
|
117
|
+
VALUES ({placeholders})
|
|
118
|
+
""",
|
|
119
|
+
values,
|
|
120
|
+
)
|
|
121
|
+
self._conn.commit()
|
|
122
|
+
except Exception as e:
|
|
123
|
+
print(f" (DEBUG) {self.write_error_message}: {e}", file=sys.stderr)
|
|
124
|
+
|
|
125
|
+
def remove(self, key: str) -> None:
|
|
126
|
+
try:
|
|
127
|
+
self._conn.execute(
|
|
128
|
+
f"DELETE FROM {self.table_name} WHERE {self.key_column} = ?",
|
|
129
|
+
(key,),
|
|
130
|
+
)
|
|
131
|
+
self._conn.commit()
|
|
132
|
+
except Exception:
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
def close(self) -> None:
|
|
136
|
+
try:
|
|
137
|
+
self._conn.close()
|
|
138
|
+
except Exception:
|
|
139
|
+
pass
|
|
140
|
+
|
|
141
|
+
def __del__(self):
|
|
142
|
+
self.close()
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ok-cosmic-knowledge 离线 API 知识图谱构建工具
|
|
3
|
+
# 用法: ./setup-mac.sh [参数]
|
|
4
|
+
|
|
5
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
6
|
+
JAR_FILE="$SCRIPT_DIR/setup.jar"
|
|
7
|
+
|
|
8
|
+
if ! command -v java &> /dev/null; then
|
|
9
|
+
echo "错误: 未找到 java 命令,请安装 JDK 8+"
|
|
10
|
+
exit 1
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
if [ ! -f "$JAR_FILE" ]; then
|
|
14
|
+
echo "请确认发布包完整,或重新获取包含 setup.jar 的安装包"
|
|
15
|
+
exit 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
java -jar "$JAR_FILE" "$@"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal
|
|
3
|
+
REM ok-cosmic-knowledge 离线 API 知识图谱构建工具
|
|
4
|
+
REM 用法: setup-windows.bat [参数]
|
|
5
|
+
|
|
6
|
+
chcp 65001 >nul 2>nul
|
|
7
|
+
|
|
8
|
+
set "SCRIPT_DIR=%~dp0"
|
|
9
|
+
set "JAR_FILE=%SCRIPT_DIR%setup.jar"
|
|
10
|
+
set "EXIT_CODE=0"
|
|
11
|
+
set "PAUSE_ON_EXIT="
|
|
12
|
+
|
|
13
|
+
REM Explorer 双击通常通过 cmd.exe /c 启动,执行结束后窗口会立即关闭。
|
|
14
|
+
echo %CMDCMDLINE% | findstr /I /C:" /c " >nul && set "PAUSE_ON_EXIT=1"
|
|
15
|
+
|
|
16
|
+
if not exist "%JAR_FILE%" (
|
|
17
|
+
echo 错误: setup.jar 文件不存在: "%JAR_FILE%"
|
|
18
|
+
echo 请确认发布包完整,或重新获取包含 setup.jar 的安装包
|
|
19
|
+
set "EXIT_CODE=1"
|
|
20
|
+
goto end
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
where java >nul 2>nul
|
|
24
|
+
if errorlevel 1 (
|
|
25
|
+
echo 错误: 未找到 java 命令,请先安装 JRE/JDK 并配置 PATH。
|
|
26
|
+
set "EXIT_CODE=1"
|
|
27
|
+
goto end
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
pushd "%SCRIPT_DIR%" >nul 2>nul
|
|
31
|
+
if errorlevel 1 (
|
|
32
|
+
echo 错误: 无法进入脚本目录: "%SCRIPT_DIR%"
|
|
33
|
+
set "EXIT_CODE=1"
|
|
34
|
+
goto end
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
java -jar "%JAR_FILE%" %*
|
|
38
|
+
set "EXIT_CODE=%ERRORLEVEL%"
|
|
39
|
+
popd >nul
|
|
40
|
+
|
|
41
|
+
:end
|
|
42
|
+
if defined PAUSE_ON_EXIT (
|
|
43
|
+
echo.
|
|
44
|
+
if "%EXIT_CODE%"=="0" (
|
|
45
|
+
echo 执行完成,按任意键关闭窗口...
|
|
46
|
+
) else (
|
|
47
|
+
echo 执行失败,退出码: %EXIT_CODE%
|
|
48
|
+
echo 按任意键关闭窗口...
|
|
49
|
+
)
|
|
50
|
+
pause >nul
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
exit /b %EXIT_CODE%
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "ok-ksql"
|
|
3
|
+
description: "金蝶云苍穹 KSQL/SQL 数据修复与批量数据变更 Skill。适用于数据库执行脚本、历史数据修复、批量更新、字段回填、影响范围查询、备份和回滚;默认生成 PostgreSQL 语法,生成前必须依赖 $ok-cosmic 的元数据能力验证表名和字段名,不生成 Java。"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# KSQL 数据修复
|
|
7
|
+
|
|
8
|
+
用于生成数据库执行的 KSQL/SQL 数据修复、批量数据变更、历史数据修复、字段回填、影响范围查询、备份和回滚脚本。
|
|
9
|
+
|
|
10
|
+
## 路径约定
|
|
11
|
+
|
|
12
|
+
- `<SKILL_ROOT>` = 当前 `SKILL.md` 所在目录(即 `skills/ok-ksql/`)
|
|
13
|
+
- `<SKILL_ROOT>/scripts/ksql_lint.py` = 最终 SQL 静态检查脚本。
|
|
14
|
+
|
|
15
|
+
## 依赖关系
|
|
16
|
+
|
|
17
|
+
- 本 Skill 不自带、不复制、不生成元数据脚本。
|
|
18
|
+
- 表名、`dbKey`、字段类型、枚举/状态值、基础资料落库字段确认,统一依赖 `$ok-cosmic` 的元数据查询能力。
|
|
19
|
+
- 如果 `$ok-cosmic` 不可用,且用户也没有提供已确认的元数据结果,必须停止并列出待确认项。
|
|
20
|
+
|
|
21
|
+
## 必读规则
|
|
22
|
+
|
|
23
|
+
处理任何 KSQL/SQL 数据修复请求时,必须先完整读取 [references/ksql-datafix.md](references/ksql-datafix.md),并按其中“确认卡片”模板输出。
|
|
24
|
+
|
|
25
|
+
## 辅助脚本
|
|
26
|
+
|
|
27
|
+
- 最终 SQL 文件生成后,优先运行 `python3 <SKILL_ROOT>/scripts/ksql_lint.py <SQL文件>` 做静态检查。
|
|
28
|
+
- 若 lint 输出 `ERROR`,必须修复 SQL 后再交付;若输出 `WARN`,必须按偏好修复或在结果中说明保留原因。
|
|
29
|
+
- `ksql_lint.py` 会检查高风险项:无 `WHERE` 的 `UPDATE/DELETE`、非备份场景 `SELECT *`、备份语句/备份表命名、时间戳一致性、`EXISTS` 偏好、`NULL` 判断和 PostgreSQL 多表更新风格。
|
|
30
|
+
|
|
31
|
+
## Step 0. 依赖预检
|
|
32
|
+
|
|
33
|
+
1. 先使用 `$ok-cosmic` 完成其 Step 0 配置预检。
|
|
34
|
+
2. 若 `$ok-cosmic` 预检返回 `ERROR`,不得生成最终 KSQL;只说明缺失配置,并把需要用户补齐的信息列入“待确认项”。
|
|
35
|
+
3. 生成最终 KSQL 前,必须通过 `$ok-cosmic` 的元数据能力确认表名和字段名;具体命令以 `$ok-cosmic` 的脚本路由为准。
|
|
36
|
+
|
|
37
|
+
## 工作流硬约束
|
|
38
|
+
|
|
39
|
+
1. 先拆解自然语言意图,明确目标对象、操作类型、目标字段、条件字段、新值来源和风险边界。
|
|
40
|
+
2. 必须通过 `$ok-cosmic` 元数据能力(`cosmic-form-metadata.py --sql`)精确确认每个单据的表名和每个数据库字段名;用户给中文或英文都必须查。
|
|
41
|
+
3. 写 SQL 前必须先判断所有参与表的 `dbName` 是否一致;一致才按普通单库 SQL 处理,不一致就是分库/跨库场景。
|
|
42
|
+
4. 分库/跨库场景不得直接生成普通更新 SQL;必须先让用户确认 dblink / postgres_fdw / 导出导入临时表等处理方式。
|
|
43
|
+
5. 所有表名、`dbKey`、`dbName`、枚举值、状态值、基础资料落库字段全部确认后,才允许生成最终 KSQL。
|
|
44
|
+
6. 任一字段、表名或 `dbName` 未确认时,只输出待确认项,不生成最终 KSQL。
|
|
45
|
+
7. 每条 `update` 前必须先写对应查询语句,查询条件和关联范围必须与 `update` 保持一致。
|
|
46
|
+
8. 备份必须使用 `select * into` 做整表备份;备份语句不加 `where`;备份表名必须以 `bak_` 开头、以当前生成时间 `yyyyMMddHHmm` 结尾,精确到分钟。
|
|
47
|
+
9. 查询/验证语句禁止 `select *`;备份语句例外且必须 `select * into`。
|
|
48
|
+
10. 禁止无 `where` 的 `update` / `delete`。
|
|
49
|
+
11. 单据主键一般是 `fid`;分录表主键一般是 `fentryid`;分录表一般通过 `fid` 与单据主表关联。
|
|
50
|
+
12. 本 Skill 只生成数据库执行脚本,不生成 Java 插件代码。
|
|
51
|
+
13. 所有确认卡片均为 `✔️` 后,最终必须在用户桌面生成 SQL 文本文件;任一卡片为 `✖️` 时,不生成文件。
|
|
52
|
+
14. 默认使用 PostgreSQL 语法生成 SQL;除非用户明确指定其他数据库方言,否则不要输出其他方言写法。
|
|
53
|
+
15. SQL 可读性偏好:成员关系/半连接条件默认使用 `IN`(值列表或子查询),避免使用 `EXISTS`;只有 `IN` 会改变语义或无法表达时才保留 `EXISTS`,并说明原因。
|
|
54
|
+
16. 最终 SQL 文件生成后必须尽量运行 `ksql_lint.py`;如因环境限制无法运行,最终回复中说明未运行原因。
|
|
55
|
+
|
|
56
|
+
## 输出要求
|
|
57
|
+
|
|
58
|
+
最终输出必须使用确认卡片形式,并包含:
|
|
59
|
+
|
|
60
|
+
1. 意图拆解
|
|
61
|
+
2. 元数据确认
|
|
62
|
+
3. 待确认项
|
|
63
|
+
4. 影响范围查询
|
|
64
|
+
5. 备份语句
|
|
65
|
+
6. 更新前确认查询
|
|
66
|
+
7. 正式执行语句
|
|
67
|
+
8. 执行后验证语句
|
|
68
|
+
9. 回滚语句
|
|
69
|
+
10. 风险点与执行顺序
|
|
70
|
+
11. 桌面文件产物
|
|
71
|
+
|
|
72
|
+
所有确认卡片均为 `✔️` 后,才允许输出最终 KSQL,并在用户桌面生成 `.txt` 文件;任一卡片为 `✖️` 时,停止并说明需要补充的信息。
|
|
73
|
+
|
|
74
|
+
## 桌面文件产物
|
|
75
|
+
|
|
76
|
+
- 路径:`~/Desktop/ksql_<业务缩写>_<当前生成时间yyyyMMddHHmm>.txt`
|
|
77
|
+
- 内容:完整 SQL 执行脚本,至少包含影响范围查询、整表备份、更新前确认查询、正式执行语句、执行后验证语句和回滚语句。
|
|
78
|
+
- 时间:文件名里的分钟必须取当前生成时间,与备份表名时间戳保持一致。
|
|
79
|
+
- 风格:SQL 文件使用 `-- ============================================` 分隔章节;文件开头写业务标题、关键条件和执行前提醒;SQL 关键字大写;文件末尾补充“字段映射(来自元数据)”。
|
|
80
|
+
- 禁止:待确认项非空、任一确认卡片为 `✖️` 时,不得创建桌面文件。
|
|
81
|
+
- 检查:文件生成后运行 `python3 <SKILL_ROOT>/scripts/ksql_lint.py <SQL文件>`,无 `ERROR` 后再交付。
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ok-ksql",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "金蝶云苍穹 KSQL/SQL 数据修复与批量数据变更 Skill,默认生成 PostgreSQL 语法,依赖 ok-cosmic 元数据能力,面向数据库执行脚本生成、影响范围确认、备份、验证和回滚。",
|
|
5
|
+
"author": "Cosmic",
|
|
6
|
+
"references": [
|
|
7
|
+
"references/"
|
|
8
|
+
],
|
|
9
|
+
"ignore": [
|
|
10
|
+
".DS_Store",
|
|
11
|
+
"__pycache__/",
|
|
12
|
+
"*.pyc"
|
|
13
|
+
]
|
|
14
|
+
}
|