@ohos-cpf/3rdloop 0.0.1
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 +425 -0
- package/bin/3rdloop.mjs +48 -0
- package/lib/cli.js +741 -0
- package/lib/config.js +318 -0
- package/lib/doctor.js +114 -0
- package/lib/exit-codes.js +31 -0
- package/lib/opencode.js +156 -0
- package/lib/orch.js +427 -0
- package/lib/queries.js +264 -0
- package/lib/runner.js +979 -0
- package/lib/step.js +326 -0
- package/lib/ui.js +223 -0
- package/lib/workflow.js +291 -0
- package/lib/workflows.js +132 -0
- package/package.json +50 -0
- package/vendor/Server/Agent/SkillSelector/README.md +344 -0
- package/vendor/Server/Agent/SkillSelector/core/Agent.js +207 -0
- package/vendor/Server/Agent/SkillSelector/index.js +14 -0
- package/vendor/Server/Agent/SkillSelector/llm/llmClient.js +313 -0
- package/vendor/Server/Agent/SkillSelector/llm/prompts.js +161 -0
- package/vendor/Server/Agent/SkillSelector/llm/reactSteps.js +144 -0
- package/vendor/Server/Agent/SkillSelector/matcher/fuzzyMatcher.js +433 -0
- package/vendor/Server/Agent/SkillSelector/scanner/skillScanner.js +382 -0
- package/vendor/Server/Agent/SkillSelector/types.js +63 -0
- package/vendor/Server/Agent/SkillSelector/utils/actionWords.js +60 -0
- package/vendor/Server/Brain/AnalysisStrategies.js +422 -0
- package/vendor/Server/Brain/Brain.js +686 -0
- package/vendor/Server/Brain/DecompositionStrategies.js +621 -0
- package/vendor/Server/Brain/PlanPersistence.js +196 -0
- package/vendor/Server/Brain/SkillExecutor.js +251 -0
- package/vendor/Server/Brain/index.js +11 -0
- package/vendor/Server/CLI/cli.js +243 -0
- package/vendor/Server/CLI/opencode/index.js +804 -0
- package/vendor/Server/CLI/opencode.js +5 -0
- package/vendor/Server/DbUse/MessageArchive.js +61 -0
- package/vendor/Server/DbUse/StorageManager.js +107 -0
- package/vendor/Server/DbUse/adapters/BaseAdapter.js +94 -0
- package/vendor/Server/DbUse/adapters/FileAdapter.js +138 -0
- package/vendor/Server/DbUse/adapters/JsonAdapter.js +138 -0
- package/vendor/Server/DbUse/adapters/JsonlAdapter.js +114 -0
- package/vendor/Server/DbUse/adapters/SqliteAdapter.js +157 -0
- package/vendor/Server/DbUse/index.js +160 -0
- package/vendor/Server/DbUse/stores/SessionStore.js +279 -0
- package/vendor/Server/DbUse/stores/TaskExecutionStore.js +133 -0
- package/vendor/Server/DbUse/stores/TaskRegistryStore.js +262 -0
- package/vendor/Server/DbUse/stores/TaskStepStore.js +279 -0
- package/vendor/Server/FlexRunner/FlexRunner.js +1759 -0
- package/vendor/Server/FlexRunner/index.js +12 -0
- package/vendor/Server/Knowledge/KnowledgeImporter.js +523 -0
- package/vendor/Server/Knowledge/KnowledgeManager.js +341 -0
- package/vendor/Server/Knowledge/index.js +33 -0
- package/vendor/Server/LoopEngine/LoopEngine.js +1133 -0
- package/vendor/Server/LoopEngine/index.js +11 -0
- package/vendor/Server/Orchestrator/Orchestrator.js +1425 -0
- package/vendor/Server/Orchestrator/StepNode.js +312 -0
- package/vendor/Server/Orchestrator/index.js +13 -0
- package/vendor/Server/Routes/controllers/BrainController.js +241 -0
- package/vendor/Server/Routes/controllers/FlexRunnerController.js +1125 -0
- package/vendor/Server/Routes/controllers/HealthController.js +44 -0
- package/vendor/Server/Routes/controllers/KnowledgeImportController.js +355 -0
- package/vendor/Server/Routes/controllers/LoopEngineController.js +788 -0
- package/vendor/Server/Routes/controllers/OrchestratorController.js +911 -0
- package/vendor/Server/Routes/controllers/StatsController.js +57 -0
- package/vendor/Server/Routes/controllers/StreamController.js +67 -0
- package/vendor/Server/Routes/library/logger.js +179 -0
- package/vendor/Server/Routes/library/zipArchive.js +172 -0
- package/vendor/Server/Routes/router/Router.js +204 -0
- package/vendor/Server/Routes/routes/brain.js +47 -0
- package/vendor/Server/Routes/routes/flexrunner.js +72 -0
- package/vendor/Server/Routes/routes/health.js +28 -0
- package/vendor/Server/Routes/routes/index.js +57 -0
- package/vendor/Server/Routes/routes/knowledge.js +55 -0
- package/vendor/Server/Routes/routes/loopengine.js +58 -0
- package/vendor/Server/Routes/routes/orchestrator.js +61 -0
- package/vendor/Server/Routes/routes/registry.js +98 -0
- package/vendor/Server/Routes/routes/stats.js +23 -0
- package/vendor/Server/Routes/routes/stream.js +30 -0
- package/vendor/Server/Routes/server.js +202 -0
- package/vendor/Server/Routes/sse/SseHub.js +308 -0
- package/vendor/Server/Skills/acceptance-check/SKILL.md +174 -0
- package/vendor/Server/Skills/acceptance-check/references/PHASE1_ARTIFACT_COLLECTION.md +52 -0
- package/vendor/Server/Skills/acceptance-check/references/PHASE2_CRITERIA_EVALUATION.md +77 -0
- package/vendor/Server/Skills/arkts-code-check/SKILL.md +314 -0
- package/vendor/Server/Skills/arkts-code-check/references/CODE_CHECK_GUIDE.md +160 -0
- package/vendor/Server/Skills/arkts-code-check/references/FILE_TYPE_GUIDE.md +29 -0
- package/vendor/Server/Skills/arkts-code-check/references/PHASE1_INFO_COLLECTION.md +222 -0
- package/vendor/Server/Skills/arkts-code-check/references/REPORT_TEMPLATE.md +220 -0
- package/vendor/Server/Skills/arkts-library-compile-validate/SKILL.md +329 -0
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/build.ps1 +93 -0
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/code-linter.cjs +433 -0
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/migrate.cjs +851 -0
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/ohpm-switch.cjs +789 -0
- package/vendor/Server/Skills/arkts-library-demo-code/SKILL.md +291 -0
- package/vendor/Server/Skills/arkts-library-demo-code/references/API_SIGNATURE_CHECKS.md +68 -0
- package/vendor/Server/Skills/arkts-library-demo-code/references/BUILD_VALIDATION.md +184 -0
- package/vendor/Server/Skills/arkts-library-demo-code/references/CODE_STANDARDS.md +337 -0
- package/vendor/Server/Skills/arkts-library-demo-code/references/EXAMPLES.md +400 -0
- package/vendor/Server/Skills/arkts-library-demo-code/references/SYSTEM_API_LOOKUP.md +99 -0
- package/vendor/Server/Skills/arkts-library-demo-code/references/TEMPLATE.md +544 -0
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/build.ps1 +93 -0
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/code-linter.cjs +433 -0
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/migrate.cjs +851 -0
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/ohpm-switch.cjs +789 -0
- package/vendor/Server/Skills/arkts-library-demo-coverage/SKILL.md +174 -0
- package/vendor/Server/Skills/arkts-library-demo-scenario/SKILL.md +321 -0
- package/vendor/Server/Skills/arkts-library-demo-scenario/references/EXAMPLES.md +100 -0
- package/vendor/Server/Skills/arkts-library-demo-scenario/references/TEMPLATE.md +185 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/SKILL.md +234 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/assets/REPORT_TEMPLATE.md +103 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/CHECK_DIMENSIONS.md +89 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/COMPLIANCE_CHECKLIST.md +62 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/KB_QUERY_GUIDE.md +108 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/MCP_TOOL_DISCOVERY.md +124 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/REPORT_TEMPLATE.md +90 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/SCORING_FORMULA.md +57 -0
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/scripts/validate-skill.cjs +259 -0
- package/vendor/Server/Skills/arkts-library-interface-spec/SKILL.md +97 -0
- package/vendor/Server/Skills/arkts-library-memory-leak-check/SKILL.md +392 -0
- package/vendor/Server/Skills/arkts-library-source-clone/SKILL.md +113 -0
- package/vendor/Server/Skills/arkts-library-stability-check/SKILL.md +313 -0
- package/vendor/Server/Skills/arkts-library-stability-check/assets/REPORT_TEMPLATE.md +154 -0
- package/vendor/Server/Skills/arkts-library-stability-check/references/CHECKLIST.md +166 -0
- package/vendor/Server/Skills/arkts-library-stability-check/references/CODE_EXAMPLES.md +309 -0
- package/vendor/Server/Skills/arkts-library-stability-check/references/SCORING_RULES.md +90 -0
- package/vendor/Server/Skills/arkts-library-stability-check/scripts/validate-skill.cjs +282 -0
- package/vendor/Server/Skills/arkts-library-test-coverage-check/SKILL.md +361 -0
- package/vendor/Server/Skills/arkts-library-test-coverage-check/assets/REPORT_TEMPLATE.md +146 -0
- package/vendor/Server/Skills/arkts-library-test-coverage-check/references/CHECKLIST.md +253 -0
- package/vendor/Server/Skills/arkts-library-test-coverage-check/references/MCP_TOOL_USAGE.md +115 -0
- package/vendor/Server/Skills/arkts-library-test-coverage-check/scripts/validate-skill.cjs +263 -0
- package/vendor/Server/Skills/arkts-library-xts-code/SKILL.md +455 -0
- package/vendor/Server/Skills/arkts-library-xts-code/assets/report-template.md +60 -0
- package/vendor/Server/Skills/arkts-library-xts-code/references/ACCESS_MODIFIER_PRECHECK.md +76 -0
- package/vendor/Server/Skills/arkts-library-xts-code/references/BUILD_VERIFICATION.md +200 -0
- package/vendor/Server/Skills/arkts-library-xts-code/references/CODE_STANDARDS.md +519 -0
- package/vendor/Server/Skills/arkts-library-xts-code/references/SUBAGENT_PROMPT_TEMPLATE.md +276 -0
- package/vendor/Server/Skills/arkts-library-xts-code/references/SYSTEM_API_LOOKUP.md +93 -0
- package/vendor/Server/Skills/arkts-library-xts-code/references/XTS_TEMPLATE.md +767 -0
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/build.ps1 +93 -0
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/code-linter.cjs +433 -0
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/migrate.cjs +851 -0
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/ohpm-switch.cjs +789 -0
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/precheck-access-modifiers.cjs +221 -0
- package/vendor/Server/Skills/arkts-library-xts-code-fix/SKILL.md +229 -0
- package/vendor/Server/Skills/arkts-library-xts-coverage/SKILL.md +97 -0
- package/vendor/Server/Skills/arkts-library-xts-doc/SKILL.md +194 -0
- package/vendor/Server/Skills/arkts-library-xts-doc/references/EXAMPLES.md +576 -0
- package/vendor/Server/Skills/arkts-library-xts-doc/references/TEMPLATE.md +575 -0
- package/vendor/Server/Skills/arkts-library-xts-doc/references/TESTABILITY_GUIDE.md +182 -0
- package/vendor/Server/Skills/arkts-library-xts-execution/SKILL.md +491 -0
- package/vendor/Server/Skills/arkts-library-xts-execution/references/error-fixing-examples.md +217 -0
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/build.ps1 +93 -0
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/code-linter.cjs +433 -0
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/migrate.cjs +851 -0
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/ohpm-switch.cjs +789 -0
- package/vendor/Server/Skills/flutter-code-check/SKILL.md +299 -0
- package/vendor/Server/Skills/flutter-code-check/assets/OUTPUT_TEMPLATE.md +312 -0
- package/vendor/Server/Skills/flutter-code-check/references/CHECKLIST.md +190 -0
- package/vendor/Server/Skills/flutter-code-check/references/PLATFORMS.md +134 -0
- package/vendor/Server/Skills/flutter-code-check/scripts/validate-skill.cjs +259 -0
- package/vendor/Server/Skills/flutter-interface/README.md +75 -0
- package/vendor/Server/Skills/flutter-interface/SKILL.md +291 -0
- package/vendor/Server/Skills/flutter-interface/references/EXAMPLES.md +336 -0
- package/vendor/Server/Skills/flutter-interface/references/GIT_CLONE_GUIDE.md +190 -0
- package/vendor/Server/Skills/flutter-interface/references/SCRIPT_REFERENCE.md +258 -0
- package/vendor/Server/Skills/flutter-interface/references/TEMPLATE.md +254 -0
- package/vendor/Server/Skills/flutter-library-consistency-check/SKILL.md +518 -0
- package/vendor/Server/Skills/flutter-library-consistency-check/references/CHECKLIST.md +382 -0
- package/vendor/Server/Skills/flutter-library-consistency-check/references/FUNCTION_COMPARISON_GUIDE.md +342 -0
- package/vendor/Server/Skills/flutter-library-consistency-check/references/PLATFORM_LIMITATION_GUIDE.md +71 -0
- package/vendor/Server/Skills/flutter-library-documentation-quality-check/SKILL.md +519 -0
- package/vendor/Server/Skills/flutter-library-documentation-quality-check/references/CHECKLIST.md +407 -0
- package/vendor/Server/Skills/flutter-library-memory-leak-check/SKILL.md +653 -0
- package/vendor/Server/Skills/flutter-library-memory-leak-check/references/CHECKLIST.md +397 -0
- package/vendor/Server/Skills/flutter-library-stability-check/SKILL.md +745 -0
- package/vendor/Server/Skills/flutter-library-stability-check/references/CHECKLIST.md +721 -0
- package/vendor/Server/Skills/flutter-library-test-coverage-check/SKILL.md +414 -0
- package/vendor/Server/Skills/flutter-library-test-coverage-check/assets/REPORT_TEMPLATE.md +150 -0
- package/vendor/Server/Skills/flutter-library-test-coverage-check/references/CHECKLIST.md +304 -0
- package/vendor/Server/Skills/flutter-library-test-coverage-check/references/SCORING_RULES.md +265 -0
- package/vendor/Server/Skills/flutter-library-test-coverage-check/references/SCRIPT_USAGE.md +286 -0
- package/vendor/Server/Skills/knowledge-import/SKILL.md +383 -0
- package/vendor/Server/Skills/knowledge-import/references/MCP_TOOL_USAGE.md +165 -0
- package/vendor/Server/Skills/knowledge-import/references/SKILL_LOCATOR_GUIDE.md +91 -0
- package/vendor/Server/Skills/knowledge-import/references/SKILL_OPTIMIZATION_GUIDE.md +127 -0
- package/vendor/Server/Skills/ohos-lib-pr-push/SKILL.md +301 -0
- package/vendor/Server/Skills/ohos-lib-pr-push/assets/PR_ISSUE_TEMPLATE.md +105 -0
- package/vendor/Server/Skills/ohos-lib-pr-push/references/GITCODE_API.md +127 -0
- package/vendor/Server/Skills/ohos-lib-pr-push/scripts/gitcode-api.cjs +208 -0
- package/vendor/Server/Skills/rn-code-check/SKILL.md +321 -0
- package/vendor/Server/Skills/rn-code-check/references/API-GUIDE.md +235 -0
- package/vendor/Server/Skills/rn-code-check/references/CHECKLIST.md +189 -0
- package/vendor/Server/Skills/rn-code-check/references/REPORT-TEMPLATE.md +247 -0
- package/vendor/Server/Skills/rn-lib-add-example/SKILL.md +198 -0
- package/vendor/Server/Skills/rn-lib-add-example/references/APP_RENAME_GUIDE.md +40 -0
- package/vendor/Server/Skills/rn-lib-add-example/references/SHELL_ADAPTATION_CHECKLIST.md +78 -0
- package/vendor/Server/Skills/rn-lib-add-example/references/TEMPLATE_REPO_GUIDE.md +70 -0
- package/vendor/Server/Skills/rn-lib-add-example/references/VERIFICATION_GUIDE.md +47 -0
- package/vendor/Server/Skills/rn-lib-add-example/scripts/create-example.cjs +252 -0
- package/vendor/Server/Skills/rn-lib-update-doc/SKILL.md +176 -0
- package/vendor/Server/Skills/rn-lib-update-doc/config.json +5 -0
- package/vendor/Server/Skills/rn-lib-update-doc/references/changelog-template.md +35 -0
- package/vendor/Server/Skills/rn-lib-update-doc/references/format-diff.md +137 -0
- package/vendor/Server/Skills/rn-lib-update-doc/references/link-registry.json +33 -0
- package/vendor/Server/Skills/rn-lib-update-doc/references/model-0.4.2-overview.md +40 -0
- package/vendor/Server/Skills/rn-lib-update-doc/references/model-0.4.2.md +429 -0
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/detect-readme-format.cjs +105 -0
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/find-usage-doc.cjs +90 -0
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/link-verify.cjs +213 -0
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-changelog.cjs +73 -0
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-package-meta.cjs +258 -0
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-readme-links.cjs +341 -0
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/resolve-usage-docs.cjs +67 -0
- package/vendor/Server/Skills/rn-library-consistency-check/SKILL.md +299 -0
- package/vendor/Server/Skills/rn-library-consistency-check/assets/REPORT_TEMPLATE.md +293 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/ARKTS_COMPONENT_CHECK_GUIDE.md +857 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/ARKTS_TURBOMODULE_CHECK_GUIDE.md +856 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/CHECKLIST.md +157 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/CPP_COMPONENT_CHECK_GUIDE.md +801 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/CPP_TURBOMODULE_CHECK_GUIDE.md +684 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/FUNCTION_COMPARISON_GUIDE.md +233 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/NATIVE_COMPONENT_IDENTIFICATION.md +1373 -0
- package/vendor/Server/Skills/rn-library-consistency-check/references/SCORING_STANDARD.md +220 -0
- package/vendor/Server/Skills/rn-library-consistency-check/scripts/validate-skill.py +245 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/SKILL.md +263 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/MODEL.md +414 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/MODEL_en.md +413 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/REPORT_TEMPLATE.md +311 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/CHECK_CHECKLIST.md +355 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/CROSS_VALIDATION_GUIDE.md +115 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/DOC_COLLECTION_GUIDE.md +139 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/EXAMPLES.md +586 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/GOTCHAS.md +57 -0
- package/vendor/Server/Skills/rn-library-documentation-quality-check/scripts/validate-skill.py +259 -0
- package/vendor/Server/Skills/rn-library-interface-analyzer/SKILL.md +301 -0
- package/vendor/Server/Skills/rn-library-interface-analyzer/assets/REPORT_TEMPLATE.md +148 -0
- package/vendor/Server/Skills/rn-library-interface-analyzer/references/DOC_ANNOTATION_GUIDE.md +118 -0
- package/vendor/Server/Skills/rn-library-interface-analyzer/references/SCRIPT_USAGE_GUIDE.md +168 -0
- package/vendor/Server/Skills/rn-library-interface-analyzer/references/URL_PARSING_RULES.md +176 -0
- package/vendor/Server/Skills/rn-library-issue-generalizer/SKILL.md +274 -0
- package/vendor/Server/Skills/rn-library-issue-generalizer/assets/case-template.md +45 -0
- package/vendor/Server/Skills/rn-library-issue-generalizer/assets/rule-template.md +25 -0
- package/vendor/Server/Skills/rn-library-issue-generalizer/references/PR_FETCH_GUIDE.md +61 -0
- package/vendor/Server/Skills/rn-library-issue-generalizer/references/RULE_TEMPLATE_GUIDE.md +165 -0
- package/vendor/Server/Skills/rn-library-issue-generalizer/scripts/fetch-pr-info.py +239 -0
- package/vendor/Server/Skills/rn-library-known-issue-check/SKILL.md +263 -0
- package/vendor/Server/Skills/rn-library-known-issue-check/assets/REPORT_TEMPLATE.md +96 -0
- package/vendor/Server/Skills/rn-library-known-issue-check/references/COMPLIANCE_CHECKLIST.md +58 -0
- package/vendor/Server/Skills/rn-library-known-issue-check/references/INSPECTION_GUIDE.md +99 -0
- package/vendor/Server/Skills/rn-library-known-issue-check/references/PRESCREEN_GUIDE.md +64 -0
- package/vendor/Server/Skills/rn-library-known-issue-check/references/SOURCE_PREP_GUIDE.md +75 -0
- package/vendor/Server/Skills/rn-library-known-issue-check/scripts/validate-known-issue-report.py +164 -0
- package/vendor/Server/Skills/rn-library-memory-leak-check/SKILL.md +339 -0
- package/vendor/Server/Skills/rn-library-memory-leak-check/assets/REPORT_TEMPLATE.md +83 -0
- package/vendor/Server/Skills/rn-library-memory-leak-check/references/CHECKLIST.md +859 -0
- package/vendor/Server/Skills/rn-library-memory-leak-check/references/HARMONY_CODE_PATTERNS.md +122 -0
- package/vendor/Server/Skills/rn-library-memory-leak-check/scripts/scan_harmony_code.py +279 -0
- package/vendor/Server/Skills/rn-library-stability-check/SKILL.md +273 -0
- package/vendor/Server/Skills/rn-library-stability-check/assets/REPORT_TEMPLATE.md +129 -0
- package/vendor/Server/Skills/rn-library-stability-check/references/CHECKLIST.md +581 -0
- package/vendor/Server/Skills/rn-library-stability-check/references/SCORING_RULES.md +138 -0
- package/vendor/Server/Skills/rn-library-stability-check/scripts/scan-harmony-code.py +168 -0
- package/vendor/Server/Skills/rn-library-test-coverage-check/SKILL.md +506 -0
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/CHECKLIST.md +280 -0
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/DEMO_LOCATION.md +221 -0
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/REPORT_TEMPLATE.md +209 -0
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/SCRIPT_USAGE.md +325 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/SKILL.md +279 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/assets/TEST_FILE_TEMPLATES.md +404 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/BUILD_TROUBLESHOOTING.md +185 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/BUILD_WORKFLOW.md +265 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/COMMON_CONFIG.md +189 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/CONFIG_GUIDE.md +203 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/COVERAGE_ANALYZER.md +147 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/DESIGN_DOC_GUIDE.md +148 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/GENERATION_FLOW.md +165 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/GENERATION_STRATEGY.md +195 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/HARMONY_SCANNER.md +249 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/JEST_FRAMEWORK.md +235 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/PLATFORM_COMPAT.md +161 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/RN_TEST_PATTERNS.md +413 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/SOURCE_PARSER.md +235 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/TEST_CONVENTIONS.md +245 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/TROUBLESHOOTING.md +282 -0
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/USAGE_GUIDE.md +251 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/SKILL.md +469 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/assets/CPTF_TEST_TEMPLATE.md +310 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/assets/DEMO_PAGE_TEMPLATE.md +303 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/CPTF_TEST_GENERATION_GUIDE.md +421 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/DEMO_GENERATION_GUIDE.md +358 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/QUALITY_CHECKLIST.md +114 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/SPEC_PARSING_GUIDE.md +274 -0
- package/vendor/Server/Skills/rnoh-cptf-api-test/scripts/validate-rnoh-cptf-api-test.sh +185 -0
- package/vendor/Server/Skills/rnoh-cptf-demo-test/SKILL.md +191 -0
- package/vendor/Server/Skills/rnoh-cptf-demo-test/assets/TEST_TEMPLATE.md +216 -0
- package/vendor/Server/Skills/rnoh-cptf-demo-test/references/CPTF_SETUP.md +107 -0
- package/vendor/Server/Skills/rnoh-cptf-demo-test/references/DEMO_ANALYSIS.md +120 -0
- package/vendor/Server/Skills/rnoh-cptf-demo-test/scripts/validate-rnoh-cptf-test.sh +108 -0
- package/vendor/Server/Skills/rnoh-cptf-test-run/SKILL.md +237 -0
- package/vendor/Server/Skills/rnoh-cptf-test-run/references/DEBUG_PLAYBOOK.md +261 -0
- package/vendor/Server/Skills/rnoh-cptf-test-run/scripts/validate-run-env.sh +112 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/SKILL.md +498 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/adapt-checklist.md +270 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/api-migration-checklist.md +164 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/common-compile-errors.md +556 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/deveco-cli-tools.md +459 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/edge-cases.md +65 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/har-tgz-build.md +512 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/version-compat-matrix.md +132 -0
- package/vendor/Server/Skills/rnoh-lib-code-adapt/scripts/auto-integrate.sh +424 -0
- package/vendor/Server/Skills/rnoh-lib-demo-coverage/SKILL.md +137 -0
- package/vendor/Server/Skills/rnoh-lib-demo-create/SKILL.md +306 -0
- package/vendor/Server/Skills/rnoh-lib-demo-create/assets/DEMO_PAGE_TEMPLATE.md +485 -0
- package/vendor/Server/Skills/rnoh-lib-demo-create/assets/INDEX_TEMPLATE.md +172 -0
- package/vendor/Server/Skills/rnoh-lib-demo-create/references/DEMO_CODE_RULES.md +422 -0
- package/vendor/Server/Skills/rnoh-lib-demo-create/references/QUALITY_CHECKLIST.md +95 -0
- package/vendor/Server/Skills/rnoh-lib-demo-create/references/SOURCE_EXPLORATION.md +169 -0
- package/vendor/Server/Skills/rnoh-lib-demo-doc/SKILL.md +554 -0
- package/vendor/Server/Skills/rnoh-lib-demo-doc/assets/DEMO_DOC_TEMPLATE.md +106 -0
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/COVERAGE_INCREMENTAL.md +216 -0
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/DEMO_DESIGN_RULES.md +413 -0
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/OUTPUT_FORMAT.md +269 -0
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/QUALITY_CHECKLIST.md +98 -0
- package/vendor/Server/Skills/rnoh-lib-func-test/SKILL.md +337 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/SKILL.md +722 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/assets/PORT_REPORT_TEMPLATE.md +219 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/references/DEMO_PORTING_GUIDE.md +345 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/references/PORT_VERIFICATION.md +269 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/references/RNT_PROJECT_STRUCTURE.md +173 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/analyze-demo-deps.cjs +267 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/detect-rnoh-version.cjs +174 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/find-rnt-demo.sh +111 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/port-demo.sh +186 -0
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/read-lib-meta.cjs +150 -0
- package/vendor/Server/Skills/rnoh-lib-test-align/SKILL.md +296 -0
- package/vendor/Server/Skills/rnoh-lib-test-align/references/jest-troubleshooting.md +371 -0
- package/vendor/Server/Skills/rnoh-lib-test-align/references/port-test-demo-guide.md +212 -0
- package/vendor/Server/Skills/rnoh-lib-test-align/references/runtime-troubleshooting.md +345 -0
- package/vendor/Server/Skills/rnoh-lib-test-align/references/unit-test-template.md +223 -0
- package/vendor/Server/Skills/rnoh-lib-test-align/scripts/port-test-demo.sh +1053 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/SKILL.md +255 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/references/OHOS_ADAPTATION.md +77 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/references/OHOS_API_LOOKUP.md +224 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/references/script-reference.md +174 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/detect-upstream-version.js +967 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/generate-diff.js +1798 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/package.json +5 -0
- package/vendor/Server/Skills/rnoh-lib-version-diff/templates/report-template.md +137 -0
- package/vendor/Server/Skills/rnoh-lib-xts-coverage/SKILL.md +145 -0
- package/vendor/Server/Skills/skill-generator/SKILL.md +365 -0
- package/vendor/Server/Skills/skill-generator/assets/SKILL_TEMPLATE.md +183 -0
- package/vendor/Server/Skills/skill-generator/references/COMPLIANCE_CHECKLIST.md +82 -0
- package/vendor/Server/Skills/skill-generator/references/KB_QUERY_GUIDE.md +110 -0
- package/vendor/Server/Skills/skill-generator/references/MCP_TOOL_DISCOVERY.md +122 -0
- package/vendor/Server/Skills/skill-generator/references/SKILL_SPEC.md +121 -0
- package/vendor/Server/Skills/skill-generator/scripts/validate-skill.cjs +259 -0
- package/vendor/Server/Skills/task-analysis/SKILL.md +234 -0
- package/vendor/Server/Skills/task-analysis/assets/OUTPUT_EXAMPLES.md +160 -0
- package/vendor/Server/Skills/task-analysis/references/ACCEPTANCE_CRITERIA_GUIDE.md +190 -0
- package/vendor/Server/Skills/task-analysis/references/ANALYSIS_SCHEMA.md +224 -0
- package/vendor/Server/Skills/task-analysis/references/INTEGRATION_CONTEXT.md +162 -0
- package/vendor/Server/Skills/task-analysis/references/LESSONS_LEARNED.md +55 -0
- package/vendor/Server/Skills/task-analysis/references/REPLAN_CONTEXT_GUIDE.md +126 -0
- package/vendor/Server/Skills/task-analysis/scripts/validate-analysis-output.sh +256 -0
- package/vendor/Server/Skills/task-decomposition/SKILL.md +529 -0
- package/vendor/Server/Skills/task-decomposition/assets/OUTPUT_EXAMPLES.md +451 -0
- package/vendor/Server/Skills/task-decomposition/references/ACCEPTANCE_CRITERIA_GUIDE.md +179 -0
- package/vendor/Server/Skills/task-decomposition/references/DEPENDENCY_GRAPH_GUIDE.md +152 -0
- package/vendor/Server/Skills/task-decomposition/references/INTEGRATION_CONTEXT.md +175 -0
- package/vendor/Server/Skills/task-decomposition/references/REPLAN_CONTEXT_GUIDE.md +195 -0
- package/vendor/Server/Skills/task-decomposition/references/TASK_DECOMPOSITION_TEMPLATES.md +226 -0
- package/vendor/Server/Skills/task-decomposition/scripts/list-available-skills.cjs +263 -0
- package/vendor/Server/Skills/task-decomposition/scripts/skill-blacklist.json +29 -0
- package/vendor/Server/Skills/task-decomposition/scripts/validate-decomposition-output.cjs +376 -0
- package/vendor/Server/Skills/task-decomposition/scripts/validate-param-consistency.cjs +259 -0
- package/vendor/Server/Skills/task-decomposition/scripts/validate-specified-skills.cjs +216 -0
- package/vendor/Server/Skills/task-decomposition/scripts/validate-step-graph.cjs +425 -0
- package/vendor/Server/Skills/tpc-cpp-check/SKILL.md +427 -0
- package/vendor/Server/Skills/tpc-cpp-check/references/CHECKLIST.md +214 -0
- package/vendor/Server/Skills/tpc-cpp-check/references/HPKBUILD_GUIDE.md +235 -0
- package/vendor/Server/Skills/tpc-cpp-check/references/REPORT_TEMPLATE.md +250 -0
- package/vendor/Server/TestCheck/TestCheck.js +775 -0
- package/vendor/Server/TestCheck/index.js +11 -0
- package/vendor/Server/library/McpToolGuide.js +280 -0
- package/vendor/Server/library/StatsService.js +127 -0
- package/vendor/Server/library/cstTime.js +16 -0
- package/vendor/Server/package.json +17 -0
- package/vendor/VERSION +3 -0
- package/workflows/pr-check.mjs +106 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlanPersistence —— 拆解计划持久化与历史加载
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* - 持久化 BrainPlan 到文件系统(按轮次独立保存 + 最新快照)
|
|
6
|
+
* - 按 planId / taskId / taskId+loopCount 加载计划
|
|
7
|
+
* - 加载某个 Task 下所有轮次的历史计划
|
|
8
|
+
* - 列出所有历史计划(去重)
|
|
9
|
+
*
|
|
10
|
+
* 设计原则:
|
|
11
|
+
* - 持有 storage 引用,不持有 Brain 的业务状态
|
|
12
|
+
* - 无状态工具类,所有操作基于 storage 文件系统
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export class PlanPersistence {
|
|
16
|
+
/**
|
|
17
|
+
* @param {object} deps
|
|
18
|
+
* @param {object} deps.storage - 存储门面(createStorage() 返回值)
|
|
19
|
+
*/
|
|
20
|
+
constructor({ storage }) {
|
|
21
|
+
this.storage = storage;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 持久化拆解计划到文件系统。
|
|
26
|
+
*
|
|
27
|
+
* 多轮循环持久化策略:
|
|
28
|
+
* - brain_loop{n}.json — 每轮独立保存,完整保留历史
|
|
29
|
+
* - brain.json — 最新快照,方便快速加载最新计划
|
|
30
|
+
*
|
|
31
|
+
* 目录结构:
|
|
32
|
+
* db/task/{taskId}/
|
|
33
|
+
* ├── brain_loop0.json ← 第 0 轮初始拆解
|
|
34
|
+
* ├── brain_loop1.json ← 第 1 轮重规划
|
|
35
|
+
* ├── brain.json ← 最新计划快照(= 最后一轮的 brain_loop{n})
|
|
36
|
+
* ├── testcheck_loop0.json ← 第 0 轮审核结果(TestCheck 写入)
|
|
37
|
+
* ├── testcheck_loop1.json ← 第 1 轮审核结果
|
|
38
|
+
* ├── stepid_1_loop0.json ← 第 0 轮步骤执行记录(FlexRunner 写入)
|
|
39
|
+
* ├── stepid_1_loop1.json ← 第 1 轮步骤执行记录
|
|
40
|
+
* └── ...
|
|
41
|
+
*
|
|
42
|
+
* @param {BrainPlan} plan
|
|
43
|
+
*/
|
|
44
|
+
async persistPlan(plan) {
|
|
45
|
+
try {
|
|
46
|
+
const json = this.storage.json('task');
|
|
47
|
+
const loopCount = plan.loopCount ?? 0;
|
|
48
|
+
|
|
49
|
+
// 按轮次独立保存(完整保留历史)
|
|
50
|
+
await json.write(`${plan.taskId}/brain_loop${loopCount}`, plan);
|
|
51
|
+
|
|
52
|
+
// 同时写入最新快照(兼容已有 loadPlan / listPlans 逻辑)
|
|
53
|
+
await json.write(`${plan.taskId}/brain`, plan);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.warn(`[Brain] 持久化计划失败: ${err.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 从文件系统加载历史计划。
|
|
61
|
+
*
|
|
62
|
+
* 支持三种加载方式:
|
|
63
|
+
* - 按 planId 遍历查找(回退路径,兼容旧调用)
|
|
64
|
+
* - 按 taskId 加载最新计划(options.taskId,读取 brain.json 快照)
|
|
65
|
+
* - 按 taskId + loopCount 加载指定轮次计划(options.taskId + options.loopCount)
|
|
66
|
+
*
|
|
67
|
+
* @param {string} planId
|
|
68
|
+
* @param {object} [options]
|
|
69
|
+
* @param {string} [options.taskId] - 直接按 taskId 加载,避免遍历
|
|
70
|
+
* @param {number} [options.loopCount] - 指定轮次(0=首轮, 1+=重规划轮)
|
|
71
|
+
* @param {Map<string, BrainPlan>} [plansCache] - Brain 内存缓存(可选)
|
|
72
|
+
* @returns {Promise<BrainPlan|null>}
|
|
73
|
+
*/
|
|
74
|
+
async loadPlan(planId, options = {}, plansCache = null) {
|
|
75
|
+
// 先从内存查找
|
|
76
|
+
if (plansCache) {
|
|
77
|
+
const cached = plansCache.get(planId);
|
|
78
|
+
if (cached) return cached;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const json = this.storage.json('task');
|
|
83
|
+
|
|
84
|
+
// 快速路径:直接按 taskId 读取
|
|
85
|
+
if (options.taskId) {
|
|
86
|
+
let plan;
|
|
87
|
+
if (options.loopCount != null) {
|
|
88
|
+
// 加载指定轮次
|
|
89
|
+
plan = await json.read(`${options.taskId}/brain_loop${options.loopCount}`);
|
|
90
|
+
} else {
|
|
91
|
+
// 加载最新快照
|
|
92
|
+
plan = await json.read(`${options.taskId}/brain`);
|
|
93
|
+
}
|
|
94
|
+
if (plan && plansCache) {
|
|
95
|
+
plansCache.set(plan.planId, plan);
|
|
96
|
+
}
|
|
97
|
+
return plan;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 回退路径:遍历 db/task/ 子目录查找匹配 planId 的计划
|
|
101
|
+
// 同时检查 brain.json(快照)和 brain_loop{n}.json(历史轮次)
|
|
102
|
+
const entries = await json.list();
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
const isBrainFile = entry.key.endsWith('/brain') ||
|
|
105
|
+
/\/brain_loop\d+$/.test(entry.key);
|
|
106
|
+
if (isBrainFile && entry.data?.planId === planId) {
|
|
107
|
+
if (plansCache) {
|
|
108
|
+
plansCache.set(planId, entry.data);
|
|
109
|
+
}
|
|
110
|
+
return entry.data;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 加载某个 Task 下所有轮次的拆解计划(按轮次排序)。
|
|
121
|
+
*
|
|
122
|
+
* 扫描 db/task/{taskId}/brain_loop{n}.json 文件,返回按 loopCount 升序排列的计划数组。
|
|
123
|
+
*
|
|
124
|
+
* @param {string} taskId
|
|
125
|
+
* @returns {Promise<Array<BrainPlan>>}
|
|
126
|
+
*/
|
|
127
|
+
async loadPlanHistory(taskId) {
|
|
128
|
+
try {
|
|
129
|
+
const json = this.storage.json('task');
|
|
130
|
+
const entries = await json.list();
|
|
131
|
+
const plans = entries
|
|
132
|
+
.filter(e => {
|
|
133
|
+
if (!e.key.startsWith(`${taskId}/brain_loop`) || !e.data) return false;
|
|
134
|
+
return /^brain_loop\d+$/.test(e.key.slice(taskId.length + 1));
|
|
135
|
+
})
|
|
136
|
+
.map(e => {
|
|
137
|
+
const match = e.key.match(/brain_loop(\d+)$/);
|
|
138
|
+
return { loop: match ? parseInt(match[1], 10) : 0, plan: e.data };
|
|
139
|
+
})
|
|
140
|
+
.sort((a, b) => a.loop - b.loop);
|
|
141
|
+
return plans.map(p => p.plan);
|
|
142
|
+
} catch {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 列出所有历史计划。
|
|
149
|
+
*
|
|
150
|
+
* 遍历 db/task/ 下所有子目录的 brain.json 和 brain_loop{n}.json 文件,
|
|
151
|
+
* 按 planId 去重(brain.json 与 brain_loop{n}.json 内容相同时只保留一份)。
|
|
152
|
+
*
|
|
153
|
+
* @param {Map<string, BrainPlan>} [plansCache] - Brain 内存缓存(可选,合并未落盘的计划)
|
|
154
|
+
* @returns {Promise<Array>}
|
|
155
|
+
*/
|
|
156
|
+
async listPlans(plansCache = null) {
|
|
157
|
+
try {
|
|
158
|
+
const json = this.storage.json('task');
|
|
159
|
+
const entries = await json.list();
|
|
160
|
+
const rawPlans = entries
|
|
161
|
+
.filter(e => {
|
|
162
|
+
if (!e.data) return false;
|
|
163
|
+
return e.key.endsWith('/brain') ||
|
|
164
|
+
/\/brain_loop\d+$/.test(e.key);
|
|
165
|
+
})
|
|
166
|
+
.map(e => e.data);
|
|
167
|
+
|
|
168
|
+
// 按 planId 去重(brain.json 快照与 brain_loop{n}.json 内容相同)
|
|
169
|
+
const seen = new Set();
|
|
170
|
+
const plans = [];
|
|
171
|
+
for (const plan of rawPlans) {
|
|
172
|
+
if (plan.planId && !seen.has(plan.planId)) {
|
|
173
|
+
seen.add(plan.planId);
|
|
174
|
+
plans.push(plan);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 合并内存中的计划(可能尚未落盘)
|
|
179
|
+
if (plansCache) {
|
|
180
|
+
for (const [id, plan] of plansCache) {
|
|
181
|
+
if (!seen.has(id)) {
|
|
182
|
+
seen.add(id);
|
|
183
|
+
plans.push(plan);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return plans.sort((a, b) =>
|
|
188
|
+
new Date(b.createdAt) - new Date(a.createdAt)
|
|
189
|
+
);
|
|
190
|
+
} catch {
|
|
191
|
+
return plansCache ? Array.from(plansCache.values()) : [];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export default PlanPersistence;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillExecutor —— opencode CLI SKILL 执行引擎
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* - 惰性加载 CLIController(避免测试时加载重依赖)
|
|
6
|
+
* - 通过 opencode CLI 创建 Session、发送 prompt、轮询完成
|
|
7
|
+
* - 读取 SKILL 结果文件,解析 JSON
|
|
8
|
+
*
|
|
9
|
+
* 设计原则:
|
|
10
|
+
* - 无状态工具类,不持有 Brain 的业务状态
|
|
11
|
+
* - 所有方法接收参数而非访问实例属性(除 _cli 缓存外)
|
|
12
|
+
* - 可独立单元测试
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
|
|
18
|
+
// CLIController 为惰性加载:测试中通过 deps 注入 mock 时不需要加载重依赖(@opencode-ai/sdk 等)。
|
|
19
|
+
let _CLIController = null;
|
|
20
|
+
|
|
21
|
+
async function _loadCLIController() {
|
|
22
|
+
if (!_CLIController) {
|
|
23
|
+
const mod = await import('../CLI/cli.js');
|
|
24
|
+
_CLIController = mod.CLIController;
|
|
25
|
+
}
|
|
26
|
+
return _CLIController;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 轮询间隔(ms) */
|
|
30
|
+
const POLL_INTERVAL_MS = 5000;
|
|
31
|
+
/** 轮询超时(ms),单次 SKILL 执行最多等待 10 分钟 */
|
|
32
|
+
const POLL_TIMEOUT_MS = 30 * 60 * 1000;
|
|
33
|
+
|
|
34
|
+
/** SKILL 轮询终止专用错误(由 abortSignal.isAborted 检测触发) */
|
|
35
|
+
export class SKILL_ABORTED_ERROR extends Error {
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} [message]
|
|
38
|
+
*/
|
|
39
|
+
constructor(message = 'SKILL 执行被终止') {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = 'SkillAbortedError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { POLL_INTERVAL_MS, POLL_TIMEOUT_MS };
|
|
46
|
+
|
|
47
|
+
export class SkillExecutor {
|
|
48
|
+
/**
|
|
49
|
+
* @param {object} [deps]
|
|
50
|
+
* @param {object} [deps.cli] - CLIController 实例(可选,不传则惰性加载)
|
|
51
|
+
*/
|
|
52
|
+
constructor(deps = {}) {
|
|
53
|
+
this._cli = deps.cli || null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 获取 CLIController 实例(惰性加载)。
|
|
58
|
+
*
|
|
59
|
+
* @returns {Promise<object>} CLIController 实例
|
|
60
|
+
*/
|
|
61
|
+
async getCLI() {
|
|
62
|
+
if (!this._cli) {
|
|
63
|
+
const CLIController = await _loadCLIController();
|
|
64
|
+
this._cli = new CLIController('opencode');
|
|
65
|
+
}
|
|
66
|
+
return this._cli;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 通过 opencode CLI 执行 SKILL。
|
|
71
|
+
*
|
|
72
|
+
* 流程:
|
|
73
|
+
* 1. 健康检查
|
|
74
|
+
* 2. 构建 prompt(含任务描述、SKILL 目录、输出路径、上下文信息)
|
|
75
|
+
* 3. 创建 Session(指定 cwd = workDir)并发送 prompt
|
|
76
|
+
* 4. 轮询等待 Session 完成
|
|
77
|
+
* 5. 读取结果文件,解析 JSON
|
|
78
|
+
*
|
|
79
|
+
* @param {string} skillDir - SKILL 目录绝对路径
|
|
80
|
+
* @param {string} workDir - 工作目录(Session 的 cwd)
|
|
81
|
+
* @param {string} resultFilePath - 结果文件输出路径
|
|
82
|
+
* @param {string} title - Session 标题
|
|
83
|
+
* @param {Array<string>} contextSections - prompt 中的上下文段落列表
|
|
84
|
+
* @param {object} [abortSignal] - 终止信号 { isAborted: () => boolean, onSessionCreated: (sid) => void }
|
|
85
|
+
* @returns {Promise<{success: boolean, json: object|null, raw: string, sessionId: string}>}
|
|
86
|
+
*/
|
|
87
|
+
async invokeSkill(skillDir, workDir, resultFilePath, title, contextSections, abortSignal = null) {
|
|
88
|
+
const cli = await this.getCLI();
|
|
89
|
+
|
|
90
|
+
// ── 1. 健康检查 ──
|
|
91
|
+
const health = await cli.checkHealth();
|
|
92
|
+
if (health.status !== 'ok') {
|
|
93
|
+
throw new Error(`opencode 服务不可用: ${health.message || 'health check failed'}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ── 1b. 确保工作目录存在 ──
|
|
97
|
+
// opencode 在 promptAsync 时会 realPath 检查 session 的 directory,
|
|
98
|
+
// 如果目录不存在会静默失败(返回 204 但不处理,tokens=0+0)。
|
|
99
|
+
// 必须在创建 session 之前创建工作目录。
|
|
100
|
+
if (workDir) {
|
|
101
|
+
fs.mkdirSync(workDir, { recursive: true });
|
|
102
|
+
}
|
|
103
|
+
// 确保结果文件的父目录也存在
|
|
104
|
+
if (resultFilePath) {
|
|
105
|
+
const resultDir = path.dirname(resultFilePath);
|
|
106
|
+
fs.mkdirSync(resultDir, { recursive: true });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── 2. 构建 prompt ──
|
|
110
|
+
const prompt = this.buildSkillPrompt(skillDir, workDir, resultFilePath, contextSections);
|
|
111
|
+
|
|
112
|
+
// ── 3. 创建 Session 并发送 prompt ──
|
|
113
|
+
// const { sessionId } = await cli.startSession(title, prompt, { cwd: workDir });
|
|
114
|
+
const { sessionId } = await cli.startSession(title, prompt);
|
|
115
|
+
|
|
116
|
+
// 通知上层登记 sessionId(abortLoop 可据此远程中止 opencode session)
|
|
117
|
+
if (abortSignal && typeof abortSignal.onSessionCreated === 'function') {
|
|
118
|
+
try {
|
|
119
|
+
abortSignal.onSessionCreated(sessionId);
|
|
120
|
+
} catch { /* 回调异常不影响主流程 */ }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Session 创建后终止标志已置位(终止发生在 startSession 过程中)→ 立即中止并退出
|
|
124
|
+
if (abortSignal && typeof abortSignal.isAborted === 'function' && abortSignal.isAborted()) {
|
|
125
|
+
try {
|
|
126
|
+
await cli.abortSession(sessionId);
|
|
127
|
+
} catch { /* 已自然结束 */ }
|
|
128
|
+
throw new SKILL_ABORTED_ERROR(`SKILL 执行被终止(session ${sessionId} 创建后即中止)`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ── 4. 轮询等待完成 ──
|
|
132
|
+
const completed = await this.pollSession(cli, sessionId, abortSignal);
|
|
133
|
+
if (!completed) {
|
|
134
|
+
throw new Error(`SKILL 执行超时(Session ${sessionId} 未在 ${POLL_TIMEOUT_MS / 1000}s 内完成)`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ── 5. 读取结果文件 ──
|
|
138
|
+
const result = await this.readSkillResult(resultFilePath);
|
|
139
|
+
// 将 sessionId 透传给调用方,供 Brain 记录到 plan 中
|
|
140
|
+
result.sessionId = sessionId;
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 构建 SKILL 执行 prompt。
|
|
146
|
+
*
|
|
147
|
+
* @param {string} skillDir - SKILL 目录路径
|
|
148
|
+
* @param {string} workDir - 工作目录
|
|
149
|
+
* @param {string} resultFilePath - 结果文件输出路径
|
|
150
|
+
* @param {Array<string>} contextSections - 上下文段落
|
|
151
|
+
* @returns {string}
|
|
152
|
+
*/
|
|
153
|
+
buildSkillPrompt(skillDir, workDir, resultFilePath, contextSections) {
|
|
154
|
+
const parts = [];
|
|
155
|
+
|
|
156
|
+
// SKILL 目录(告诉 opencode 读取并遵循该 SKILL 的指令)
|
|
157
|
+
parts.push(`## SKILL 目录\n${skillDir}`);
|
|
158
|
+
parts.push('请读取上述 SKILL 目录中的 SKILL.md 文件,并严格按照其中的指令执行任务。');
|
|
159
|
+
|
|
160
|
+
// 工作目录
|
|
161
|
+
if (workDir) {
|
|
162
|
+
parts.push(`## 工作目录\n${workDir}\n\n所有文件操作请在此目录下执行。`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 结果文件输出路径
|
|
166
|
+
parts.push(`## 结果文件输出路径\n${resultFilePath}`);
|
|
167
|
+
parts.push('执行完成后,请将结果写入上述路径。结果文件为纯 JSON 格式,不要追加任何额外内容。');
|
|
168
|
+
|
|
169
|
+
// 上下文段落
|
|
170
|
+
for (const section of contextSections) {
|
|
171
|
+
if (section) parts.push(section);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
parts.push('请按照 SKILL 中的指令执行,确保输出结果格式正确、字段完整。');
|
|
175
|
+
|
|
176
|
+
return parts.join('\n\n');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 轮询 opencode Session 状态,直到完成或超时。
|
|
181
|
+
*
|
|
182
|
+
* @param {object} cli - CLIController 实例
|
|
183
|
+
* @param {string} sessionId - Session ID
|
|
184
|
+
* @param {object} [abortSignal] - 终止信号 { isAborted: () => boolean };
|
|
185
|
+
* 置位时在下一轮询周期抛 SKILL_ABORTED_ERROR 退出
|
|
186
|
+
* @returns {Promise<boolean>} 是否完成
|
|
187
|
+
*/
|
|
188
|
+
async pollSession(cli, sessionId, abortSignal = null) {
|
|
189
|
+
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
190
|
+
|
|
191
|
+
while (Date.now() < deadline) {
|
|
192
|
+
// 终止检查:比超时检查优先,确保终止请求即时生效
|
|
193
|
+
if (abortSignal && typeof abortSignal.isAborted === 'function' && abortSignal.isAborted()) {
|
|
194
|
+
// 远程中止 opencode session(尽力而为),阻止其继续在后台运行
|
|
195
|
+
try {
|
|
196
|
+
await cli.abortSession(sessionId);
|
|
197
|
+
} catch { /* 已自然结束 */ }
|
|
198
|
+
throw new SKILL_ABORTED_ERROR(`SKILL 执行被终止(session ${sessionId})`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
await this.sleep(POLL_INTERVAL_MS);
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
const { status } = await cli.checkSessionStatus(sessionId);
|
|
205
|
+
if (status === 'completed') return true;
|
|
206
|
+
if (status === 'error') return false;
|
|
207
|
+
} catch (err) {
|
|
208
|
+
console.warn(`[SkillExecutor] 轮询 Session 状态失败: ${err.message}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 读取 SKILL 执行结果文件,解析 JSON。
|
|
216
|
+
*
|
|
217
|
+
* 结果文件格式:纯 JSON(不含 markdown 代码块标记或执行状态字段)。
|
|
218
|
+
*
|
|
219
|
+
* @param {string} resultFilePath - 结果文件路径
|
|
220
|
+
* @returns {Promise<{success: boolean, json: object|null, raw: string}>}
|
|
221
|
+
*/
|
|
222
|
+
async readSkillResult(resultFilePath) {
|
|
223
|
+
const raw = await fs.readFileSync(resultFilePath, 'utf-8');
|
|
224
|
+
|
|
225
|
+
// 提取 JSON 部分(首个 { 到末个 })
|
|
226
|
+
const jsonStart = raw.indexOf('{');
|
|
227
|
+
const jsonEnd = raw.lastIndexOf('}');
|
|
228
|
+
let json = null;
|
|
229
|
+
|
|
230
|
+
if (jsonStart !== -1 && jsonEnd !== -1 && jsonEnd > jsonStart) {
|
|
231
|
+
const jsonStr = raw.substring(jsonStart, jsonEnd + 1);
|
|
232
|
+
json = JSON.parse(jsonStr);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// JSON 解析成功即视为执行成功
|
|
236
|
+
const success = json !== null;
|
|
237
|
+
|
|
238
|
+
return { success, json, raw };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Promise 版 sleep。
|
|
243
|
+
* @param {number} ms
|
|
244
|
+
* @returns {Promise<void>}
|
|
245
|
+
*/
|
|
246
|
+
sleep(ms) {
|
|
247
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export default SkillExecutor;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brain 模块统一导出
|
|
3
|
+
*
|
|
4
|
+
* 外部使用:
|
|
5
|
+
* import { Brain, BrainStatus } from './Brain/index.js';
|
|
6
|
+
* const brain = new Brain({ sseHub, storage });
|
|
7
|
+
* const plan = await brain.planTask('对 libcurl 进行鸿蒙化分析');
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { Brain, BrainStatus } from './Brain.js';
|
|
11
|
+
export { default } from './Brain.js';
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import OpenCodeCLI from './opencode/index.js';
|
|
2
|
+
import { StatsService } from '../library/StatsService.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 通用 CLI 控制类
|
|
6
|
+
*
|
|
7
|
+
* 封装 opencode-cli,对外暴露统一的 Session 管理接口。
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const cli = new CLIController('opencode', { host: 'localhost', port: '4096' });
|
|
11
|
+
*
|
|
12
|
+
* // 通用接口
|
|
13
|
+
* await cli.checkHealth();
|
|
14
|
+
* const { sessionId } = await cli.startSession('任务标题', '初始提示词');
|
|
15
|
+
* await cli.sendMessage(sessionId, '继续消息');
|
|
16
|
+
* const status = await cli.checkSessionStatus(sessionId);
|
|
17
|
+
* const sessions = await cli.listSessions();
|
|
18
|
+
* const session = await cli.getSession(sessionId);
|
|
19
|
+
* await cli.abortSession(sessionId);
|
|
20
|
+
* await cli.deleteSession(sessionId);
|
|
21
|
+
*/
|
|
22
|
+
class CLIController {
|
|
23
|
+
/**
|
|
24
|
+
* @param {'opencode'} type - CLI 类型
|
|
25
|
+
* @param {object} [options={}] - 传递给对应适配器的配置项
|
|
26
|
+
*
|
|
27
|
+
* opencode 选项:
|
|
28
|
+
* options.host {string} - 服务主机(默认 localhost)
|
|
29
|
+
* options.port {string} - 服务端口(默认 4096)
|
|
30
|
+
* options.baseUrl {string} - 完整 URL,优先级高于 host/port
|
|
31
|
+
*
|
|
32
|
+
* 公共选项:
|
|
33
|
+
* options.archive - MessageArchive 实例(消息存档与卡死检测),不传则适配器内部自建
|
|
34
|
+
*/
|
|
35
|
+
constructor(type = 'opencode', options = {}) {
|
|
36
|
+
this.type = type;
|
|
37
|
+
|
|
38
|
+
switch (type) {
|
|
39
|
+
case 'opencode':
|
|
40
|
+
this.adapter = new OpenCodeCLI(options);
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(
|
|
44
|
+
`不支持的 CLI 类型: "${type}",可选值为 'opencode'`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ─── 运行状态检查 ──────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 检查 CLI 服务是否正常运行
|
|
53
|
+
* @returns {Promise<{ status: 'ok'|'error'|'disabled', message: string }>}
|
|
54
|
+
*/
|
|
55
|
+
async checkHealth() {
|
|
56
|
+
return this.adapter.checkHealth();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ─── Session 管理 ──────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 获取所有 Session
|
|
63
|
+
* @returns {Promise<Array<object>>}
|
|
64
|
+
*/
|
|
65
|
+
async listSessions() {
|
|
66
|
+
return this.adapter.listSessions();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 获取指定 Session
|
|
71
|
+
* @param {string} sessionId
|
|
72
|
+
* @returns {Promise<object>}
|
|
73
|
+
*/
|
|
74
|
+
async getSession(sessionId) {
|
|
75
|
+
return this.adapter.getSession(sessionId);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 删除 Session
|
|
80
|
+
* @param {string} sessionId
|
|
81
|
+
* @returns {Promise<object>}
|
|
82
|
+
*/
|
|
83
|
+
async deleteSession(sessionId) {
|
|
84
|
+
return this.adapter.deleteSession(sessionId);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 终止 Session(中断正在运行的任务或进程)
|
|
89
|
+
* @param {string} sessionId
|
|
90
|
+
* @returns {Promise<object>}
|
|
91
|
+
*/
|
|
92
|
+
async abortSession(sessionId) {
|
|
93
|
+
return this.adapter.abortSession(sessionId);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 向 Session 发送消息
|
|
98
|
+
* @param {string} sessionId
|
|
99
|
+
* @param {string} message
|
|
100
|
+
* @returns {Promise<{ success: boolean, response?: string }>}
|
|
101
|
+
*/
|
|
102
|
+
async sendMessage(sessionId, message) {
|
|
103
|
+
return this.adapter.sendMessage(sessionId, message);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 向 Session 发送消息并同步等待 AI 回复完成
|
|
108
|
+
*
|
|
109
|
+
* 发送消息后阻塞等待 AI 生成完整回复,然后返回回复内容。
|
|
110
|
+
* 与 sendMessage(异步 fire-and-forget)不同,此方法会等到 AI 回复完成。
|
|
111
|
+
*
|
|
112
|
+
* @param {string} sessionId
|
|
113
|
+
* @param {string} message
|
|
114
|
+
* @returns {Promise<{ success: boolean, response: object|string, content: string }>}
|
|
115
|
+
*/
|
|
116
|
+
async sendAndWaitMessage(sessionId, message) {
|
|
117
|
+
return this.adapter.sendAndWaitMessage(sessionId, message);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 向 Session 注入提示词/上下文(不触发 AI 响应)
|
|
122
|
+
*
|
|
123
|
+
* 利用 opencode SDK 的 noReply: true 能力,将文本注入对话历史
|
|
124
|
+
* 但不触发 AI 生成回复。适用于对话过程中动态补充上下文、规则、指令。
|
|
125
|
+
*
|
|
126
|
+
* 向 Session 注入上下文(不触发 AI 响应,基于 opencode noReply 模式)。
|
|
127
|
+
*
|
|
128
|
+
* @param {string} sessionId
|
|
129
|
+
* @param {string} message - 要注入的提示词/上下文
|
|
130
|
+
* @returns {Promise<{ success: boolean }>}
|
|
131
|
+
*/
|
|
132
|
+
async injectPrompt(sessionId, message) {
|
|
133
|
+
return this.adapter.injectPrompt(sessionId, message);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 创建新 Session,可选附带初始提示词
|
|
138
|
+
* @param {string} title - Session 标题
|
|
139
|
+
* @param {string} [prompt] - 初始提示词(可选)
|
|
140
|
+
* @param {object} [options]
|
|
141
|
+
* @param {string} [options.cwd] - 工作目录(指定后 opencode session 的文件操作在此目录下执行)
|
|
142
|
+
* @returns {Promise<{ sessionId: string, action: string, message: string }>}
|
|
143
|
+
*/
|
|
144
|
+
async startSession(title, prompt, options = {}) {
|
|
145
|
+
// 记录 Session 调用次数(异步执行,不影响主流程)
|
|
146
|
+
StatsService.incrementSessionCount().catch(err => {
|
|
147
|
+
// 统计失败不影响正常业务,仅记录日志
|
|
148
|
+
console.warn('[CLIController] Session 统计记录失败:', err.message);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return this.adapter.startSession(title, prompt, options);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 查询 Session 当前状态
|
|
156
|
+
* @param {string} sessionId
|
|
157
|
+
* @returns {Promise<{ status: string, lastMessage?: object }>}
|
|
158
|
+
*/
|
|
159
|
+
async checkSessionStatus(sessionId) {
|
|
160
|
+
return this.adapter.checkSessionStatus(sessionId);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 获取 Session 消息历史
|
|
165
|
+
* @param {string} sessionId
|
|
166
|
+
* @returns {Promise<Array<object>>}
|
|
167
|
+
*/
|
|
168
|
+
async getSessionMessages(sessionId) {
|
|
169
|
+
return this.adapter.getSessionMessages(sessionId);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 读取本地已归档的消息(持久化文件,不请求远端,用于事后审计/对比)
|
|
174
|
+
* @param {string} sessionId
|
|
175
|
+
* @returns {Promise<Array<object>>}
|
|
176
|
+
*/
|
|
177
|
+
async getArchivedMessages(sessionId) {
|
|
178
|
+
return this.adapter.getArchivedMessages(sessionId);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 实时查看当前对话消息(运行中安全调用,不写入存档)
|
|
183
|
+
*
|
|
184
|
+
* 从远端 / 内存拉取当前已有消息并转为精简格式返回。
|
|
185
|
+
* 适用于对话进行中查看 "目前聊了什么",不影响后续归档去重。
|
|
186
|
+
*
|
|
187
|
+
* @param {string} sessionId
|
|
188
|
+
* @returns {Promise<Array<{id?,role,content,finish?,timestamp?}>>}
|
|
189
|
+
*/
|
|
190
|
+
async getLiveMessages(sessionId) {
|
|
191
|
+
return this.adapter.getLiveMessages(sessionId);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 导出完整对话(合并远端 + 本地,支持运行中 / 已结束)
|
|
196
|
+
*
|
|
197
|
+
* @param {string} sessionId
|
|
198
|
+
* @param {object} [opts]
|
|
199
|
+
* @param {'json'|'markdown'} [opts.format='json'] - 导出格式
|
|
200
|
+
* @returns {Promise<object|string>}
|
|
201
|
+
*/
|
|
202
|
+
async exportSession(sessionId, opts) {
|
|
203
|
+
return this.adapter.exportSession(sessionId, opts);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 读取本地存档元信息(含 lastResponseAt / archivedCount / status 等,用于卡死判断)
|
|
208
|
+
* @param {string} sessionId
|
|
209
|
+
* @returns {Promise<object>}
|
|
210
|
+
*/
|
|
211
|
+
async getArchiveMeta(sessionId) {
|
|
212
|
+
return this.adapter.getArchiveMeta(sessionId);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 列出所有本地已存档的 Session(基于存档文件)
|
|
217
|
+
* @returns {Promise<Array<object>>}
|
|
218
|
+
*/
|
|
219
|
+
async listArchivedSessions() {
|
|
220
|
+
return this.adapter.archive.listSessions();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ─── 元信息 ────────────────────────────────────────────────────────────────
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 返回当前使用的 CLI 类型
|
|
227
|
+
* @returns {'opencode'}
|
|
228
|
+
*/
|
|
229
|
+
getType() {
|
|
230
|
+
return this.type;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 返回底层适配器实例(供高级用途)
|
|
235
|
+
* @returns {OpenCodeCLI}
|
|
236
|
+
*/
|
|
237
|
+
getAdapter() {
|
|
238
|
+
return this.adapter;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { CLIController, OpenCodeCLI };
|
|
243
|
+
export default CLIController;
|