agentengine-sdk-python 0.8.0__py3-none-any.whl → 0.8.2__py3-none-any.whl
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.
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/METADATA +43 -7
- agentengine_sdk_python-0.8.2.dist-info/RECORD +778 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/WHEEL +1 -1
- ksadk/a2a/__init__.py +2 -0
- ksadk/a2a/_space_client_events.py +381 -0
- ksadk/a2a/bootstrap.py +0 -2
- ksadk/a2a/card.py +6 -111
- ksadk/a2a/control_plane.py +239 -1
- ksadk/a2a/event_adapter.py +156 -64
- ksadk/a2a/executor.py +195 -172
- ksadk/a2a/routes.py +12 -5
- ksadk/a2a/server.py +1 -8
- ksadk/a2a/service_env.py +33 -0
- ksadk/a2a/space_client.py +43 -349
- ksadk/a2a_card.py +101 -0
- ksadk/a2ui/core.py +222 -53
- ksadk/agui/_agent_helpers.py +243 -0
- ksadk/agui/a2ui_projection.py +12 -5
- ksadk/agui/agent.py +474 -275
- ksadk/agui/config.py +11 -5
- ksadk/agui/routes.py +7 -15
- ksadk/api/client.py +530 -40
- ksadk/api/environment.py +27 -0
- ksadk/builders/code_builder.py +352 -53
- ksadk/builders/container_builder.py +71 -44
- ksadk/builders/framework_requirements.py +2 -1
- ksadk/builders/ks3_uploader.py +2 -2
- ksadk/builders/managed_runtime_builder.py +60 -28
- ksadk/cli/__init__.py +25 -0
- ksadk/cli/cmd_a2a.py +18 -31
- ksadk/cli/cmd_create.py +13 -26
- ksadk/cli/cmd_dashboard.py +15 -1
- ksadk/cli/cmd_deploy.py +28 -3
- ksadk/cli/cmd_eval.py +443 -0
- ksadk/cli/cmd_evalset.py +284 -0
- ksadk/cli/cmd_files.py +5 -1
- ksadk/cli/cmd_hermes.py +137 -163
- ksadk/cli/cmd_invoke.py +28 -38
- ksadk/cli/cmd_launch.py +12 -0
- ksadk/cli/cmd_managed_runtime.py +95 -0
- ksadk/cli/cmd_observe.py +85 -0
- ksadk/cli/cmd_openclaw.py +85 -479
- ksadk/cli/cmd_replay.py +28 -4
- ksadk/cli/cmd_run.py +29 -67
- ksadk/cli/cmd_studio.py +201 -0
- ksadk/cli/cmd_web.py +15 -6
- ksadk/cli/dry_run.py +2 -1
- ksadk/cli/env_options.py +83 -0
- ksadk/cli/global_options.py +3 -1
- ksadk/cli/hermes_env.py +151 -0
- ksadk/cli/invoke_payload.py +49 -0
- ksadk/cli/network_options.py +7 -5
- ksadk/cli/openclaw_env.py +458 -0
- ksadk/cli/runtime_bootstrap.py +51 -0
- ksadk/cli/ui.py +6 -0
- ksadk/cli/workflow_common.py +5 -5
- ksadk/codex/__init__.py +3 -3
- ksadk/codex/client.py +833 -49
- ksadk/codex/phase.py +1 -1
- ksadk/codex/runtime.py +720 -127
- ksadk/common/kop_client.py +232 -0
- ksadk/configs/__init__.py +1 -3
- ksadk/configs/env_registry.py +244 -45
- ksadk/configs/env_registry_pcm.py +181 -0
- ksadk/configs/env_var_spec.py +18 -0
- ksadk/configs/global_config.py +6 -1
- ksadk/configs/settings.py +5 -108
- ksadk/context_engine/__init__.py +98 -0
- ksadk/context_engine/assembler.py +176 -0
- ksadk/context_engine/baseline.py +419 -0
- ksadk/context_engine/cache_observability.py +228 -0
- ksadk/context_engine/capabilities.py +443 -0
- ksadk/context_engine/contributors.py +344 -0
- ksadk/context_engine/hosted_pipeline.py +417 -0
- ksadk/context_engine/models.py +117 -0
- ksadk/context_engine/planner.py +698 -0
- ksadk/context_engine/policies.py +319 -0
- ksadk/context_engine/projection.py +31 -0
- ksadk/context_engine/shadow_plan.py +266 -0
- ksadk/context_engine/tokenizer.py +164 -0
- ksadk/conversations/__init__.py +85 -94
- ksadk/conversations/context.py +126 -6
- ksadk/conversations/message_projection.py +292 -28
- ksadk/conversations/model_context.py +49 -3
- ksadk/conversations/runtime_compaction.py +207 -5
- ksadk/conversations/runtime_input.py +193 -3
- ksadk/conversations/runtime_invocation.py +81 -3
- ksadk/conversations/runtime_observability.py +157 -4
- ksadk/conversations/runtime_payloads.py +42 -0
- ksadk/conversations/runtime_preparation.py +280 -2
- ksadk/conversations/runtime_resume.py +71 -32
- ksadk/conversations/runtime_stream_events.py +94 -9
- ksadk/conversations/runtime_streaming.py +175 -22
- ksadk/conversations/semantic_summary.py +311 -1
- ksadk/conversations/session_lock.py +51 -0
- ksadk/deployment/env_forward.py +72 -0
- ksadk/deployment/managed_runtime.py +38 -0
- ksadk/deployment/manager.py +24 -8
- ksadk/deployment/providers/serverless.py +228 -92
- ksadk/evaluation/__init__.py +116 -0
- ksadk/evaluation/a2a_adapter.py +452 -0
- ksadk/evaluation/adapters.py +67 -0
- ksadk/evaluation/agent_eval_client.py +395 -0
- ksadk/evaluation/cloud_binding.py +80 -0
- ksadk/evaluation/cloud_converter.py +194 -0
- ksadk/evaluation/cloud_service.py +199 -0
- ksadk/evaluation/contracts.py +478 -0
- ksadk/evaluation/evalset.py +351 -0
- ksadk/evaluation/evaluators.py +627 -0
- ksadk/evaluation/evidence.py +258 -0
- ksadk/evaluation/executor.py +143 -0
- ksadk/evaluation/local_adapter.py +550 -0
- ksadk/evaluation/service_env.py +27 -0
- ksadk/evaluation/storage.py +68 -0
- ksadk/evaluation/studio_build_adapter.py +253 -0
- ksadk/evaluation/target.py +82 -0
- ksadk/events/__init__.py +13 -13
- ksadk/events/_v1_compat/__init__.py +1 -0
- ksadk/events/_v1_compat/models.py +299 -0
- ksadk/events/_v1_compat/parser.py +247 -0
- ksadk/events/_v1_compat/projection.py +753 -0
- ksadk/events/adapters/__init__.py +34 -0
- ksadk/events/adapters/_a2a_snapshot.py +622 -0
- ksadk/events/adapters/_a2a_support.py +275 -0
- ksadk/events/adapters/_codex_interactions.py +375 -0
- ksadk/events/adapters/_codex_items.py +801 -0
- ksadk/events/adapters/_codex_validators.py +311 -0
- ksadk/events/adapters/_langgraph_support.py +785 -0
- ksadk/events/adapters/a2a.py +841 -0
- ksadk/events/adapters/adk.py +503 -0
- ksadk/events/adapters/codex.py +717 -0
- ksadk/events/adapters/langgraph.py +745 -0
- ksadk/events/canonical.py +440 -0
- ksadk/events/canonical_replay.py +497 -0
- ksadk/events/canonical_store.py +468 -0
- ksadk/events/cold_recovery.py +257 -0
- ksadk/events/content.py +89 -0
- ksadk/events/identity.py +86 -0
- ksadk/events/pipeline.py +455 -0
- ksadk/events/projections.py +66 -0
- ksadk/events/reducer.py +661 -0
- ksadk/events/replay.py +3 -36
- ksadk/events/runtime_event.py +20 -256
- ksadk/events/session_event.py +324 -0
- ksadk/events/store.py +3 -316
- ksadk/events/v1_compat.py +41 -0
- ksadk/harness/__init__.py +3 -2
- ksadk/harness/app.py +114 -123
- ksadk/harness/config.py +1 -1
- ksadk/harness/runtime.py +467 -0
- ksadk/hermes_terminal.py +5 -0
- ksadk/identity/resolver.py +4 -3
- ksadk/interaction/__init__.py +28 -0
- ksadk/interaction/contracts.py +136 -0
- ksadk/interaction/ledger.py +189 -0
- ksadk/interaction/provider.py +122 -0
- ksadk/interaction/providers/__init__.py +52 -0
- ksadk/interaction/providers/adk.py +40 -0
- ksadk/interaction/providers/codex.py +94 -0
- ksadk/interaction/providers/langgraph.py +58 -0
- ksadk/kernel/__init__.py +117 -0
- ksadk/kernel/authorization.py +258 -0
- ksadk/kernel/bootstrap.py +1074 -0
- ksadk/kernel/contract_fingerprints.py +61 -0
- ksadk/kernel/contracts.py +362 -0
- ksadk/kernel/control.py +219 -0
- ksadk/kernel/errors.py +79 -0
- ksadk/kernel/ingress.py +1102 -0
- ksadk/kernel/mapping.py +111 -0
- ksadk/kernel/memory_store.py +1133 -0
- ksadk/kernel/postgres_store.py +1756 -0
- ksadk/kernel/recovery.py +452 -0
- ksadk/kernel/runtime_identity.py +103 -0
- ksadk/kernel/sql/001_agent_kernel.sql +120 -0
- ksadk/kernel/sqlite_store.py +1410 -0
- ksadk/kernel/state.py +145 -0
- ksadk/kernel/store.py +232 -0
- ksadk/kernel/worker.py +953 -0
- ksadk/knowledge_base/client.py +22 -4
- ksadk/knowledge_base/service.py +32 -5
- ksadk/managed_a2a_card.py +160 -0
- ksadk/managed_runtime.py +16 -9
- ksadk/memory/__init__.py +61 -0
- ksadk/memory/adk/backends/base_ltm_backend.py +96 -1
- ksadk/memory/adk/backends/http_ltm_backend.py +14 -5
- ksadk/memory/adk/backends/inmemory_ltm_backend.py +136 -3
- ksadk/memory/adk/backends/sdk_ltm_backend.py +394 -5
- ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
- ksadk/memory/adk/long_term_memory.py +3 -2
- ksadk/memory/coordinator.py +461 -0
- ksadk/memory/events.py +202 -0
- ksadk/memory/extraction.py +228 -0
- ksadk/memory/ltm_backend_factory.py +16 -3
- ksadk/memory/models.py +316 -0
- ksadk/memory/policy.py +215 -0
- ksadk/memory/provider.py +47 -0
- ksadk/memory/provider_adapter.py +159 -0
- ksadk/memory/provider_resolver.py +71 -0
- ksadk/memory/providers/__init__.py +5 -0
- ksadk/memory/providers/local_sqlite.py +490 -0
- ksadk/memory/resolved_policy.py +145 -0
- ksadk/memory/service.py +198 -8
- ksadk/memory/tool.py +4 -0
- ksadk/model_proxy/bootstrap.py +16 -9
- ksadk/model_proxy/config.py +22 -1
- ksadk/model_proxy/detect.py +202 -9
- ksadk/model_proxy/namespace.py +67 -15
- ksadk/model_proxy/server.py +168 -6
- ksadk/model_proxy/transform.py +105 -3
- ksadk/observability/__init__.py +25 -0
- ksadk/observability/session_log.py +420 -0
- ksadk/observability/trajectory.py +105 -0
- ksadk/prompts/__init__.py +71 -0
- ksadk/prompts/compiler.py +215 -0
- ksadk/prompts/models.py +82 -0
- ksadk/prompts/projection.py +89 -0
- ksadk/prompts/resolved.py +137 -0
- ksadk/prompts/sources.py +233 -0
- ksadk/runners/_langgraph_runner_streams.py +822 -0
- ksadk/runners/adk_runner.py +14 -31
- ksadk/runners/base_runner.py +44 -3
- ksadk/runners/factory.py +3 -3
- ksadk/runners/langgraph_runner.py +252 -433
- ksadk/runners/utils/__init__.py +0 -10
- ksadk/runners/utils/loader.py +16 -0
- ksadk/runtime/__init__.py +67 -41
- ksadk/runtime/_runner_adapter/__init__.py +1 -0
- ksadk/runtime/_runner_adapter/stream_mapping.py +788 -0
- ksadk/runtime/adapter.py +199 -16
- ksadk/runtime/conversation_execution.py +687 -0
- ksadk/runtime/executor.py +392 -0
- ksadk/runtime/factory.py +342 -0
- ksadk/runtime/framework_adapters.py +6 -12
- ksadk/runtime/hosted_finalizer.py +268 -0
- ksadk/runtime/launch.py +61 -0
- ksadk/runtime/preprocessing.py +49 -14
- ksadk/runtime/runner_adapter.py +330 -391
- ksadk/runtime/runner_loading.py +36 -0
- ksadk/runtime/usage.py +33 -0
- ksadk/sandbox/backends/e2b.py +36 -3
- ksadk/server/__init__.py +39 -4
- ksadk/server/app.py +18 -492
- ksadk/server/composition.py +36 -2
- ksadk/server/factory.py +210 -149
- ksadk/server/routes/common.py +15 -46
- ksadk/server/routes/control.py +13 -9
- ksadk/server/routes/kernel_ingress.py +258 -0
- ksadk/server/routes/misc.py +10 -33
- ksadk/server/routes/models.py +14 -6
- ksadk/server/routes/openai_compat.py +129 -27
- ksadk/server/routes/projection.py +84 -16
- ksadk/server/routes/run.py +347 -460
- ksadk/server/routes/sessions.py +37 -40
- ksadk/server/routes/streaming.py +52 -7
- ksadk/server/routes/workspace.py +54 -21
- ksadk/server/static/assets/{ArtifactsPanel-Cjnqt-8W.js → ArtifactsPanel-DSU1sWD_.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-BqyqZfuB.js → CodeBlock-DOH6MVcn.js} +4 -4
- ksadk/server/static/assets/{MathMessageMarkdown-BpH7jiFM.js → MathMessageMarkdown-BL8my1R2.js} +4 -4
- ksadk/server/static/assets/MathMessageMarkdown-BorAY7qD.css +1 -0
- ksadk/server/static/assets/MermaidBlock-Dz4IP-Tx.js +312 -0
- ksadk/server/static/assets/NativeTerminalPanel-DUrK0JpZ.js +1 -0
- ksadk/server/static/assets/abnfDiagram-VCTEODGH-g20pFzNV.js +1 -0
- ksadk/server/static/assets/arc-C4FzinUA.js +1 -0
- ksadk/server/static/assets/architecture-7GRP2DOG-DjKratdf.js +1 -0
- ksadk/server/static/assets/architectureDiagram-5GKGNRK7-DpIqL5h4.js +36 -0
- ksadk/server/static/assets/blockDiagram-NRAW4CY4-BjkljTNz.js +129 -0
- ksadk/server/static/assets/c4Diagram-UCG6FXSJ-Dk_ieq2X.js +38 -0
- ksadk/server/static/assets/channel-4cQHKtx1.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-DmgWkESh.js +1 -0
- ksadk/server/static/assets/{chunk-FMBD7UC4-BGhvzDYt.js → chunk-5VM5RSS4-BVHAchFb.js} +1 -1
- ksadk/server/static/assets/{chunk-ND2GUHAM-D98vPd-E.js → chunk-F27PBJKO-C-ipQzuS.js} +1 -1
- ksadk/server/static/assets/chunk-G27WJ6UU-C2EyJbIK.js +231 -0
- ksadk/server/static/assets/{chunk-4BX2VUAB-CsWIQRhc.js → chunk-JWPE2WC7-vYvVJb_M.js} +1 -1
- ksadk/server/static/assets/chunk-LCL6LL3I-BcI6ysPT.js +206 -0
- ksadk/server/static/assets/chunk-POPQ4Y6H-C030x_Z1.js +1 -0
- ksadk/server/static/assets/chunk-RHFEMEQ7-yyGpsz4n.js +168 -0
- ksadk/server/static/assets/chunk-SVP7TREG-BLTlmMU7.js +88 -0
- ksadk/server/static/assets/chunk-XXDRQBXY-C_32ArgP.js +1 -0
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DLFd9Xi0.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DLFd9Xi0.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-S5V4N54A-CX3yotHq.js → cose-bilkent-JH36ORCC-9YQYwdl0.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-DjEM48Qp.js +1 -0
- ksadk/server/static/assets/cynefinDiagram-5FMLGOSQ-ErLF5N13.js +62 -0
- ksadk/server/static/assets/cytoscape.esm-CyCl8rPi.js +321 -0
- ksadk/server/static/assets/dagre-3AP2YEHR-DFiQF-6f.js +4 -0
- ksadk/server/static/assets/dagre-BuhGnRI1.js +1 -0
- ksadk/server/static/assets/diagram-S7CK7UJ4-Bt1v8-GC.js +30 -0
- ksadk/server/static/assets/diagram-UQ7AKVKN-DSCxJdBK.js +41 -0
- ksadk/server/static/assets/diagram-VSXAHHWV-DHfYwp_9.js +3 -0
- ksadk/server/static/assets/diagram-VX7I27RA-DdzD-4Le.js +24 -0
- ksadk/server/static/assets/diagram-Z3DM3KII-Du-nAJ9F.js +24 -0
- ksadk/server/static/assets/{dist-D82mtD2s.js → dist-8hqcx0sU.js} +1 -1
- ksadk/server/static/assets/dist-B7seoj3d.js +1 -0
- ksadk/server/static/assets/{dist-DHn6nBzr.js → dist-BE7bu-DL.js} +1 -1
- ksadk/server/static/assets/{dist-eoW6tZXA.js → dist-BVDffZ0U.js} +1 -1
- ksadk/server/static/assets/{dist-C2xjE7cO.js → dist-BX8z72IC.js} +1 -1
- ksadk/server/static/assets/{dist-CgF3fj15.js → dist-Bf2M8m3N.js} +1 -1
- ksadk/server/static/assets/{dist-Bs-jQcRX.js → dist-BjU6y-A2.js} +1 -1
- ksadk/server/static/assets/{dist-Djgl2wVZ.js → dist-BytlxIDT.js} +1 -1
- ksadk/server/static/assets/{dist-CVQRZjPu.js → dist-CSh_DE14.js} +1 -1
- ksadk/server/static/assets/{dist-6CVKuTAe.js → dist-CXYYBw3_.js} +1 -1
- ksadk/server/static/assets/{dist-DlzCRy0S.js → dist-C_wsv-Qd.js} +1 -1
- ksadk/server/static/assets/{dist-DF06ORQo.js → dist-ClxGviKw.js} +1 -1
- ksadk/server/static/assets/{dist-Cf23NY4L.js → dist-CttYUqzS.js} +1 -1
- ksadk/server/static/assets/{dist-ivOya1LD.js → dist-DNp6rLRA.js} +1 -1
- ksadk/server/static/assets/{dist-BibcG1V9.js → dist-DUX-id_F.js} +1 -1
- ksadk/server/static/assets/{dist-BUHRxvDG.js → dist-DmldrHd_.js} +1 -1
- ksadk/server/static/assets/{dist-BZ9n9AjO.js → dist-DnfXs8Vn.js} +2 -2
- ksadk/server/static/assets/{dist-DqNnNFrw.js → dist-Dq9gLD7L.js} +1 -1
- ksadk/server/static/assets/{dist-CGcp2ex8.js → dist-W-TIVntx.js} +1 -1
- ksadk/server/static/assets/{dist-Cwt7koer.js → dist-dDdADKFA.js} +1 -1
- ksadk/server/static/assets/{dist-C7-3jInC.js → dist-dydu68Fl.js} +1 -1
- ksadk/server/static/assets/{dist-C99THtIA.js → dist-ngtN0DJB.js} +1 -1
- ksadk/server/static/assets/ebnfDiagram-PWID7BFC-Da9C9NO1.js +1 -0
- ksadk/server/static/assets/erDiagram-SSCWMZ5O-EAGqqR79.js +99 -0
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-CMgMaJrC.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-BBKL0x3P.js +1 -0
- ksadk/server/static/assets/ganttDiagram-EL5Y4UJY-DqJsKb59.js +292 -0
- ksadk/server/static/assets/gitGraph-4MIJSDKK-Dw63mrhw.js +1 -0
- ksadk/server/static/assets/gitGraphDiagram-WWUBYQGX-B6g4dtDi.js +106 -0
- ksadk/server/static/assets/index-8ipRcQ-M.js +240 -0
- ksadk/server/static/assets/index-ByFCqjlh.css +2 -0
- ksadk/server/static/assets/info-A6RAGUB7-B6iAblII.js +1 -0
- ksadk/server/static/assets/infoDiagram-RXCK75RN-Djm_nbd5.js +2 -0
- ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-DLOHGvWw.js → ishikawaDiagram-5VMMS53U-DWya9SG2.js} +6 -6
- ksadk/server/static/assets/{journeyDiagram-JHISSGLW-BIzKeejT.js → journeyDiagram-EYS64GPL-DutxhSNI.js} +6 -6
- ksadk/server/static/assets/{kanban-definition-UN3LZRKU-BWHoFSw2.js → kanban-definition-3QL26DDD-DJdOF8Fm.js} +10 -10
- ksadk/server/static/assets/katex-vFWytM5c.js +257 -0
- ksadk/server/static/assets/{linear-CvMBw9cA.js → linear-BHjG8b-J.js} +1 -1
- ksadk/server/static/assets/mermaid-parser.core-KGSy4jWT.js +166 -0
- ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-CSAQxEAe.js → mindmap-definition-FBJOCRG2-9-HC88D4.js} +29 -29
- ksadk/server/static/assets/packet-AYTQ26CC-BOYAipuq.js +1 -0
- ksadk/server/static/assets/pegDiagram-XKGWAZYB-DrEZd4fD.js +1 -0
- ksadk/server/static/assets/pie-WAS4IAKB-Ctq0Kbku.js +1 -0
- ksadk/server/static/assets/pieDiagram-E7YTZNPT-DpjqOFFp.js +39 -0
- ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-CxIR4JXI.js → quadrantDiagram-AXDQQJYC-BiNhgOXX.js} +6 -6
- ksadk/server/static/assets/radar-RG4KPBEZ-DN0-ul_0.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-C6cC_to0.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-BimjIuRc.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CvY65ABq.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-D72Iq_Tv.js +1 -0
- ksadk/server/static/assets/railroadDiagram-O6MQD6OU-_Y3Ojg6G.js +1 -0
- ksadk/server/static/assets/requirementDiagram-EFPCY7ZU-DeCFdg9K.js +84 -0
- ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-DpGa6EAV.js → sankeyDiagram-P5KCCOFB-CPH75rhw.js} +7 -7
- ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-NTKNGGe5.js → sequenceDiagram-WJ2MYXX4-OEpQQdr4.js} +10 -10
- ksadk/server/static/assets/sizeCapture-X5ZJPWSS-heUErzhI.js +1 -0
- ksadk/server/static/assets/stateDiagram-HBIQ2CUA-DvA3jSMB.js +1 -0
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-BgQY03nz.js +1 -0
- ksadk/server/static/assets/swimlanes-XN3QIQJK-CR-dfN_t.js +1 -0
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-DLVw3q5Q.js +8 -0
- ksadk/server/static/assets/{timeline-definition-PNZ67QCA-jqoYs3jQ.js → timeline-definition-24CTP7MA-DAVJf1TX.js} +7 -7
- ksadk/server/static/assets/treeView-Q6P3EWNA-BMpO0wsB.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-Et0aqzU3.js +1 -0
- ksadk/server/static/assets/vennDiagram-4TSXK5OY-DwM8eDkh.js +34 -0
- ksadk/server/static/assets/wardley-WFR3VGLG-CbY0mhpl.js +1 -0
- ksadk/server/static/assets/wardleyDiagram-VM6X3IG4-DZL-Zz2t.js +78 -0
- ksadk/server/static/assets/xychartDiagram-S5SC5T6Z-Dy6Yh_hu.js +7 -0
- ksadk/server/static/index.html +2 -2
- ksadk/sessions/__init__.py +26 -9
- ksadk/sessions/_local_service_sync.py +688 -0
- ksadk/sessions/_local_tables.py +21 -0
- ksadk/sessions/_postgres_schema.py +305 -0
- ksadk/sessions/_postgres_tables.py +15 -0
- ksadk/sessions/base.py +80 -1
- ksadk/sessions/in_memory.py +53 -2
- ksadk/sessions/local_service.py +63 -604
- ksadk/sessions/postgres_service.py +58 -148
- ksadk/sessions/resilient.py +35 -1
- ksadk/skills/runtime/backends/e2b.py +1 -1
- ksadk/skills/service_client.py +13 -3
- ksadk/studio/__init__.py +5 -0
- ksadk/studio/agent_avatar_assets.py +120 -0
- ksadk/studio/agent_lifecycle.py +51 -0
- ksadk/studio/api.py +1598 -0
- ksadk/studio/api_catalog_routes.py +324 -0
- ksadk/studio/api_contracts.py +286 -0
- ksadk/studio/api_helpers.py +132 -0
- ksadk/studio/api_memory_routes.py +82 -0
- ksadk/studio/authoring.py +749 -0
- ksadk/studio/authoring_coordinator.py +1017 -0
- ksadk/studio/builder.py +397 -0
- ksadk/studio/capabilities.py +368 -0
- ksadk/studio/cloud.py +2099 -0
- ksadk/studio/codex_agent_service.py +694 -0
- ksadk/studio/codex_authoring.py +469 -0
- ksadk/studio/codex_builder.py +437 -0
- ksadk/studio/codex_manifest.py +307 -0
- ksadk/studio/codex_run.py +395 -0
- ksadk/studio/compiler.py +190 -0
- ksadk/studio/contracts.py +755 -0
- ksadk/studio/errors.py +47 -0
- ksadk/studio/event_store.py +214 -0
- ksadk/studio/framework_run.py +342 -0
- ksadk/studio/hosted_kernel.py +317 -0
- ksadk/studio/identifiers.py +33 -0
- ksadk/studio/manifest_resolver.py +131 -0
- ksadk/studio/mcp_runtime.py +229 -0
- ksadk/studio/model_client.py +629 -0
- ksadk/studio/model_profile_service.py +214 -0
- ksadk/studio/operations.py +275 -0
- ksadk/studio/otel_trace.py +1060 -0
- ksadk/studio/pagination.py +182 -0
- ksadk/studio/pcm_memory.py +85 -0
- ksadk/studio/python_tool_inspection.py +183 -0
- ksadk/studio/repository.py +327 -0
- ksadk/studio/resource_catalog.py +1260 -0
- ksadk/studio/run_service.py +1133 -0
- ksadk/studio/runtime_catalog.py +74 -0
- ksadk/studio/runtime_source.py +365 -0
- ksadk/studio/service.py +2249 -0
- ksadk/studio/shared_web.py +1004 -0
- ksadk/studio/skill_discovery.py +628 -0
- ksadk/studio/static/assets/PrismRenderer-IYN-ffww.js +3 -0
- ksadk/studio/static/assets/index-BLpcdrgW.css +1 -0
- ksadk/studio/static/assets/index-CYekR2Xv.js +260 -0
- ksadk/studio/static/assets/react-vendor-BNmTiJ-I.js +9 -0
- ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +1 -0
- ksadk/studio/static/index.html +15 -0
- ksadk/studio/templates.py +722 -0
- ksadk/studio/validator.py +265 -0
- ksadk/studio/workspace.py +135 -0
- ksadk/tools/gateway.py +9 -0
- ksadk/toolsets/__init__.py +27 -1
- ksadk/toolsets/a2a.py +426 -0
- ksadk/tracing/__init__.py +19 -21
- ksadk/tracing/setup.py +317 -403
- ksadk/tracing/span_utils.py +0 -44
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/registry.py +56 -56
- ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
- ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
- ksadk_runtime_common/workspace_files/router.py +8 -2
- agentengine_sdk_python-0.8.0.dist-info/RECORD +0 -578
- ksadk/a2a/card_builder.py +0 -64
- ksadk/a2a/client.py +0 -309
- ksadk/events/parser.py +0 -191
- ksadk/harness/runner.py +0 -211
- ksadk/runners/codex_runner.py +0 -132
- ksadk/runners/utils/langfuse.py +0 -230
- ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
- ksadk/server/static/assets/MermaidBlock-DWuxETaJ.js +0 -303
- ksadk/server/static/assets/NativeTerminalPanel-MDTopWMO.js +0 -1
- ksadk/server/static/assets/arc-CFKwSk_B.js +0 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-CynqOWjZ.js +0 -1
- ksadk/server/static/assets/architectureDiagram-3BPJPVTR-Dej8jX8c.js +0 -36
- ksadk/server/static/assets/blockDiagram-GPEHLZMM-1F64jqvy.js +0 -132
- ksadk/server/static/assets/c4Diagram-AAUBKEIU-9q7AUAKb.js +0 -10
- ksadk/server/static/assets/channel-iUGv2N24.js +0 -1
- ksadk/server/static/assets/chunk-2J33WTMH-6qgwJm7Q.js +0 -1
- ksadk/server/static/assets/chunk-55IACEB6-BK8paA20.js +0 -1
- ksadk/server/static/assets/chunk-727SXJPM-B-JEhy7h.js +0 -206
- ksadk/server/static/assets/chunk-AQP2D5EJ-DYBvMHAa.js +0 -231
- ksadk/server/static/assets/chunk-QZHKN3VN-YQIEXeF6.js +0 -1
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-CDAUuoXK.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-CDAUuoXK.js +0 -1
- ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
- ksadk/server/static/assets/dagre-BM42HDAG-C7TguAWo.js +0 -4
- ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
- ksadk/server/static/assets/diagram-2AECGRRQ-Dd17_kws.js +0 -43
- ksadk/server/static/assets/diagram-5GNKFQAL-DVIClIil.js +0 -10
- ksadk/server/static/assets/diagram-KO2AKTUF-Df_3gYQa.js +0 -3
- ksadk/server/static/assets/diagram-LMA3HP47-BhLk6ZtA.js +0 -24
- ksadk/server/static/assets/diagram-OG6HWLK6-D4GNGvuu.js +0 -24
- ksadk/server/static/assets/dist-DyvYLMW9.js +0 -1
- ksadk/server/static/assets/erDiagram-TEJ5UH35-CnfRcY2M.js +0 -85
- ksadk/server/static/assets/eventmodeling-FCH6USID-ChYO-ijM.js +0 -1
- ksadk/server/static/assets/flowDiagram-I6XJVG4X-DGaJjGNJ.js +0 -162
- ksadk/server/static/assets/ganttDiagram-6RSMTGT7-DpCoB2g9.js +0 -292
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BN_0Fk-j.js +0 -1
- ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-9IKVFBVT.js +0 -106
- ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
- ksadk/server/static/assets/index-QSwCHuB8.js +0 -177
- ksadk/server/static/assets/index-jOPmTOZH.css +0 -2
- ksadk/server/static/assets/info-J43DQDTF-Cp6o3vId.js +0 -1
- ksadk/server/static/assets/infoDiagram-5YYISTIA-CYIIsb8y.js +0 -2
- ksadk/server/static/assets/katex-DATssjp1.js +0 -265
- ksadk/server/static/assets/mermaid-parser.core-mGAcEwcq.js +0 -161
- ksadk/server/static/assets/packet-YPE3B663-wQzct3cT.js +0 -1
- ksadk/server/static/assets/pie-LRSECV5Y-BgTQiv-9.js +0 -1
- ksadk/server/static/assets/pieDiagram-4H26LBE5-By-ra07M.js +0 -30
- ksadk/server/static/assets/radar-GUYGQ44K-BIq5fXsn.js +0 -1
- ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DpW90iu3.js +0 -84
- ksadk/server/static/assets/stateDiagram-AJRCARHV-DGpd9yFG.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-B3o579IQ.js +0 -1
- ksadk/server/static/assets/treeView-BLDUP644-Dqi-E0EM.js +0 -1
- ksadk/server/static/assets/treemap-LRROVOQU-ClQP9CJ9.js +0 -1
- ksadk/server/static/assets/vennDiagram-CIIHVFJN-l3Z7-wbP.js +0 -34
- ksadk/server/static/assets/wardley-L42UT6IY-8XLvnNIs.js +0 -1
- ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-BR54GPmr.js +0 -78
- ksadk/server/static/assets/xychartDiagram-2RQKCTM6-SkiH8GsK.js +0 -7
- ksadk/tracing/exporters/langfuse_exporter.py +0 -460
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
"""Inspect/confirm workflow for workspace and allowlisted local Skill candidates."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import shutil
|
|
10
|
+
import stat
|
|
11
|
+
from datetime import datetime, timezone
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, cast
|
|
14
|
+
from uuid import uuid4
|
|
15
|
+
|
|
16
|
+
import yaml # type: ignore[import-untyped]
|
|
17
|
+
|
|
18
|
+
from ksadk.studio.capabilities import canonical_json, require_exact_version, sha256_digest
|
|
19
|
+
from ksadk.studio.errors import StudioError
|
|
20
|
+
from ksadk.studio.workspace import Workspace
|
|
21
|
+
|
|
22
|
+
MAX_SKILL_BYTES = 100 * 1024 * 1024
|
|
23
|
+
MAX_SKILL_FILES = 1000
|
|
24
|
+
MAX_PREVIEW_BYTES = 512 * 1024
|
|
25
|
+
SCRIPT_SUFFIXES = frozenset({".py", ".sh", ".js", ".ts", ".tsx", ".ps1", ".rb"})
|
|
26
|
+
TEXT_SUFFIXES = frozenset(
|
|
27
|
+
{".md", ".txt", ".yaml", ".yml", ".json", ".toml", ".ini", ".cfg", ".css", ".html", ".xml"}
|
|
28
|
+
)
|
|
29
|
+
EXCLUDED_PARTS = frozenset(
|
|
30
|
+
{".git", ".venv", "venv", "node_modules", "dist", "build", "__pycache__"}
|
|
31
|
+
)
|
|
32
|
+
WORKSPACE_SCAN_PATHS = ("skills", ".agents/skills", ".codex/skills", ".claude/skills")
|
|
33
|
+
USER_SKILL_ROOTS = {
|
|
34
|
+
"user:agents": ".agents/skills",
|
|
35
|
+
"user:codex": ".codex/skills",
|
|
36
|
+
"user:claude": ".claude/skills",
|
|
37
|
+
}
|
|
38
|
+
DEFAULT_SCAN_PATHS = (*WORKSPACE_SCAN_PATHS, *USER_SKILL_ROOTS)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def skill_slug(value: str) -> str:
|
|
42
|
+
slug = re.sub(r"[^a-z0-9]+", "-", value.strip().lower()).strip("-")
|
|
43
|
+
if not slug:
|
|
44
|
+
raise StudioError(
|
|
45
|
+
"RESOURCE_NAME_INVALID",
|
|
46
|
+
"Skill 名称必须至少包含一个字母或数字",
|
|
47
|
+
status_code=422,
|
|
48
|
+
)
|
|
49
|
+
return slug[:80]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class SkillDiscoveryService:
|
|
53
|
+
def __init__(self, workspace: Workspace) -> None:
|
|
54
|
+
self.workspace = workspace
|
|
55
|
+
|
|
56
|
+
def discover(self, *, scan_paths: list[str] | None = None) -> dict[str, Any]:
|
|
57
|
+
requested = scan_paths or list(DEFAULT_SCAN_PATHS)
|
|
58
|
+
candidates: list[dict[str, Any]] = []
|
|
59
|
+
seen: set[str] = set()
|
|
60
|
+
seen_real: set[Path] = set()
|
|
61
|
+
for raw in requested:
|
|
62
|
+
root, source, display_root = self._resolve_scan_root(str(raw))
|
|
63
|
+
if not root.exists():
|
|
64
|
+
continue
|
|
65
|
+
if not root.is_dir() or root.is_symlink():
|
|
66
|
+
raise StudioError(
|
|
67
|
+
"SKILL_DISCOVERY_PATH_INVALID",
|
|
68
|
+
"Skill 扫描路径必须是工作区内的普通目录",
|
|
69
|
+
status_code=422,
|
|
70
|
+
details={"path": str(raw)},
|
|
71
|
+
)
|
|
72
|
+
manifests = self._scan_manifests(root)
|
|
73
|
+
for manifest in sorted(set(manifests), key=lambda item: item.as_posix()):
|
|
74
|
+
directory = manifest.parent
|
|
75
|
+
relative = self._candidate_relative(directory, source=source, root=root)
|
|
76
|
+
identity = f"{source}:{relative}"
|
|
77
|
+
if identity in seen or (
|
|
78
|
+
source == "workspace" and relative.startswith("capabilities/skills/")
|
|
79
|
+
):
|
|
80
|
+
continue
|
|
81
|
+
seen.add(identity)
|
|
82
|
+
real = directory.resolve()
|
|
83
|
+
if real in seen_real:
|
|
84
|
+
continue
|
|
85
|
+
seen_real.add(real)
|
|
86
|
+
candidates.append(
|
|
87
|
+
self.inspect_candidate(
|
|
88
|
+
directory,
|
|
89
|
+
source=source,
|
|
90
|
+
root=root,
|
|
91
|
+
display_root=display_root,
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
candidates.sort(key=lambda item: (item.get("name", ""), item["path"]))
|
|
95
|
+
token = f"skd_{uuid4().hex}"
|
|
96
|
+
record = {
|
|
97
|
+
"format": "agentkit.skill-discovery/v1",
|
|
98
|
+
"inspectionToken": token,
|
|
99
|
+
"scanPaths": [str(item) for item in requested],
|
|
100
|
+
"candidates": candidates,
|
|
101
|
+
"requiresConfirmation": True,
|
|
102
|
+
}
|
|
103
|
+
self.workspace.atomic_write_text(
|
|
104
|
+
self._record_path(token),
|
|
105
|
+
json.dumps(record, ensure_ascii=False, sort_keys=True, indent=2) + "\n",
|
|
106
|
+
)
|
|
107
|
+
return record
|
|
108
|
+
|
|
109
|
+
def commit(
|
|
110
|
+
self,
|
|
111
|
+
inspection_token: str,
|
|
112
|
+
candidate_id: str,
|
|
113
|
+
*,
|
|
114
|
+
overwrite: bool = False,
|
|
115
|
+
) -> tuple[str, str]:
|
|
116
|
+
record_path = self._record_path(inspection_token, validate=True)
|
|
117
|
+
try:
|
|
118
|
+
record = json.loads(record_path.read_text(encoding="utf-8"))
|
|
119
|
+
except (OSError, ValueError) as exc:
|
|
120
|
+
raise StudioError(
|
|
121
|
+
"SKILL_DISCOVERY_NOT_FOUND",
|
|
122
|
+
"Skill 发现记录不存在或已失效",
|
|
123
|
+
status_code=404,
|
|
124
|
+
) from exc
|
|
125
|
+
candidate = next(
|
|
126
|
+
(
|
|
127
|
+
item
|
|
128
|
+
for item in record.get("candidates") or []
|
|
129
|
+
if item.get("candidateId") == candidate_id
|
|
130
|
+
),
|
|
131
|
+
None,
|
|
132
|
+
)
|
|
133
|
+
if not isinstance(candidate, dict):
|
|
134
|
+
raise StudioError(
|
|
135
|
+
"SKILL_CANDIDATE_NOT_FOUND",
|
|
136
|
+
"Skill 候选不属于该发现记录",
|
|
137
|
+
status_code=404,
|
|
138
|
+
)
|
|
139
|
+
if candidate.get("status") not in {"ready", "conflict"}:
|
|
140
|
+
raise StudioError(
|
|
141
|
+
"SKILL_DISCOVERY_INVALID",
|
|
142
|
+
"无效 Skill 候选不能导入",
|
|
143
|
+
status_code=422,
|
|
144
|
+
details={"candidateId": candidate_id},
|
|
145
|
+
)
|
|
146
|
+
source, source_kind, source_root, display_root = self._resolve_candidate_directory(
|
|
147
|
+
candidate
|
|
148
|
+
)
|
|
149
|
+
current = self.inspect_candidate(
|
|
150
|
+
source,
|
|
151
|
+
source=source_kind,
|
|
152
|
+
root=source_root,
|
|
153
|
+
display_root=display_root,
|
|
154
|
+
)
|
|
155
|
+
if current.get("digest") != candidate.get("digest"):
|
|
156
|
+
raise StudioError(
|
|
157
|
+
"SKILL_CANDIDATE_CHANGED",
|
|
158
|
+
"Skill 候选在确认前发生变化,请重新扫描",
|
|
159
|
+
status_code=409,
|
|
160
|
+
)
|
|
161
|
+
slug = skill_slug(str(candidate["name"]))
|
|
162
|
+
destination = self.workspace.resolve(Path("capabilities/skills") / slug)
|
|
163
|
+
if destination.exists() and not overwrite:
|
|
164
|
+
raise StudioError(
|
|
165
|
+
"SKILL_IMPORT_CONFLICT",
|
|
166
|
+
"同名 Skill 已安装,必须确认覆盖或取消",
|
|
167
|
+
status_code=409,
|
|
168
|
+
details={
|
|
169
|
+
"candidateId": candidate_id,
|
|
170
|
+
"destination": self.workspace.relative(destination),
|
|
171
|
+
},
|
|
172
|
+
)
|
|
173
|
+
staging = self.workspace.resolve(
|
|
174
|
+
Path(".agentkit/cache") / f".skill-{slug}-{uuid4().hex}.tmp"
|
|
175
|
+
)
|
|
176
|
+
shutil.copytree(
|
|
177
|
+
source,
|
|
178
|
+
staging,
|
|
179
|
+
symlinks=False,
|
|
180
|
+
ignore=shutil.ignore_patterns("__pycache__", "*.pyc", ".DS_Store"),
|
|
181
|
+
)
|
|
182
|
+
self.workspace.atomic_write_yaml(
|
|
183
|
+
staging / "skill.yaml",
|
|
184
|
+
{
|
|
185
|
+
"name": slug,
|
|
186
|
+
"displayName": candidate["displayName"],
|
|
187
|
+
"description": candidate["description"],
|
|
188
|
+
"version": candidate["version"],
|
|
189
|
+
"instructionsFile": "SKILL.md",
|
|
190
|
+
"sourceDigest": candidate["digest"],
|
|
191
|
+
},
|
|
192
|
+
)
|
|
193
|
+
try:
|
|
194
|
+
if destination.exists():
|
|
195
|
+
timestamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ")
|
|
196
|
+
trash = self.workspace.resolve(
|
|
197
|
+
Path(".agentkit/trash/skills") / f"{slug}-{timestamp}"
|
|
198
|
+
)
|
|
199
|
+
trash.parent.mkdir(parents=True, exist_ok=True)
|
|
200
|
+
shutil.move(str(destination), str(trash))
|
|
201
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
202
|
+
shutil.move(str(staging), str(destination))
|
|
203
|
+
finally:
|
|
204
|
+
shutil.rmtree(staging, ignore_errors=True)
|
|
205
|
+
remaining = [
|
|
206
|
+
item
|
|
207
|
+
for item in record.get("candidates") or []
|
|
208
|
+
if item.get("candidateId") != candidate_id
|
|
209
|
+
]
|
|
210
|
+
if any(item.get("status") in {"ready", "conflict"} for item in remaining):
|
|
211
|
+
record["candidates"] = remaining
|
|
212
|
+
self.workspace.atomic_write_text(
|
|
213
|
+
record_path,
|
|
214
|
+
json.dumps(record, ensure_ascii=False, sort_keys=True, indent=2) + "\n",
|
|
215
|
+
)
|
|
216
|
+
else:
|
|
217
|
+
record_path.unlink(missing_ok=True)
|
|
218
|
+
return slug, str(candidate["version"])
|
|
219
|
+
|
|
220
|
+
def preview_candidate(
|
|
221
|
+
self,
|
|
222
|
+
inspection_token: str,
|
|
223
|
+
candidate_id: str,
|
|
224
|
+
*,
|
|
225
|
+
path: str | None = None,
|
|
226
|
+
) -> dict[str, Any]:
|
|
227
|
+
candidate = self._candidate_from_record(inspection_token, candidate_id)
|
|
228
|
+
directory, _, _, _ = self._resolve_candidate_directory(candidate)
|
|
229
|
+
return self.preview_directory(directory, path=path)
|
|
230
|
+
|
|
231
|
+
def preview_directory(
|
|
232
|
+
self,
|
|
233
|
+
directory: Path,
|
|
234
|
+
*,
|
|
235
|
+
path: str | None = None,
|
|
236
|
+
) -> dict[str, Any]:
|
|
237
|
+
resolved = directory.resolve(strict=True)
|
|
238
|
+
files, total_bytes = self._safe_directory(resolved, display_path=directory.name)
|
|
239
|
+
entries = [
|
|
240
|
+
{
|
|
241
|
+
"path": relative,
|
|
242
|
+
"size": (resolved / relative).stat().st_size,
|
|
243
|
+
"kind": self._preview_kind(relative),
|
|
244
|
+
}
|
|
245
|
+
for relative in files
|
|
246
|
+
]
|
|
247
|
+
if path is None:
|
|
248
|
+
return {"files": entries, "fileCount": len(entries), "totalBytes": total_bytes}
|
|
249
|
+
|
|
250
|
+
requested = Path(path)
|
|
251
|
+
if requested.is_absolute() or ".." in requested.parts:
|
|
252
|
+
raise StudioError(
|
|
253
|
+
"SKILL_PREVIEW_PATH_INVALID",
|
|
254
|
+
"Skill 预览路径必须是 Skill 内的相对路径",
|
|
255
|
+
status_code=422,
|
|
256
|
+
details={"path": path},
|
|
257
|
+
)
|
|
258
|
+
target = (resolved / requested).resolve(strict=True)
|
|
259
|
+
try:
|
|
260
|
+
target.relative_to(resolved)
|
|
261
|
+
except ValueError as exc:
|
|
262
|
+
raise StudioError(
|
|
263
|
+
"SKILL_PREVIEW_PATH_FORBIDDEN",
|
|
264
|
+
"Skill 预览文件不在候选目录中",
|
|
265
|
+
status_code=403,
|
|
266
|
+
details={"path": path},
|
|
267
|
+
) from exc
|
|
268
|
+
if not target.is_file() or target.is_symlink():
|
|
269
|
+
raise StudioError(
|
|
270
|
+
"SKILL_PREVIEW_FILE_INVALID",
|
|
271
|
+
"Skill 预览仅支持普通文件",
|
|
272
|
+
status_code=422,
|
|
273
|
+
details={"path": path},
|
|
274
|
+
)
|
|
275
|
+
relative = target.relative_to(resolved).as_posix()
|
|
276
|
+
if relative not in files:
|
|
277
|
+
raise StudioError(
|
|
278
|
+
"SKILL_PREVIEW_FILE_INVALID",
|
|
279
|
+
"Skill 预览文件未通过安全检查",
|
|
280
|
+
status_code=422,
|
|
281
|
+
details={"path": path},
|
|
282
|
+
)
|
|
283
|
+
content = target.read_bytes()
|
|
284
|
+
kind = self._preview_kind(relative)
|
|
285
|
+
if kind == "binary":
|
|
286
|
+
return {
|
|
287
|
+
"path": relative,
|
|
288
|
+
"size": len(content),
|
|
289
|
+
"kind": kind,
|
|
290
|
+
"content": None,
|
|
291
|
+
"truncated": False,
|
|
292
|
+
}
|
|
293
|
+
truncated = len(content) > MAX_PREVIEW_BYTES
|
|
294
|
+
text = content[:MAX_PREVIEW_BYTES].decode("utf-8", errors="replace")
|
|
295
|
+
return {
|
|
296
|
+
"path": relative,
|
|
297
|
+
"size": len(content),
|
|
298
|
+
"kind": kind,
|
|
299
|
+
"content": text,
|
|
300
|
+
"truncated": truncated,
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
def _candidate_from_record(
|
|
304
|
+
self,
|
|
305
|
+
inspection_token: str,
|
|
306
|
+
candidate_id: str,
|
|
307
|
+
) -> dict[str, Any]:
|
|
308
|
+
record_path = self._record_path(inspection_token, validate=True)
|
|
309
|
+
try:
|
|
310
|
+
record = json.loads(record_path.read_text(encoding="utf-8"))
|
|
311
|
+
except (OSError, ValueError) as exc:
|
|
312
|
+
raise StudioError(
|
|
313
|
+
"SKILL_DISCOVERY_NOT_FOUND",
|
|
314
|
+
"Skill 发现记录不存在或已失效",
|
|
315
|
+
status_code=404,
|
|
316
|
+
) from exc
|
|
317
|
+
candidate = next(
|
|
318
|
+
(
|
|
319
|
+
item
|
|
320
|
+
for item in record.get("candidates") or []
|
|
321
|
+
if item.get("candidateId") == candidate_id
|
|
322
|
+
),
|
|
323
|
+
None,
|
|
324
|
+
)
|
|
325
|
+
if not isinstance(candidate, dict):
|
|
326
|
+
raise StudioError(
|
|
327
|
+
"SKILL_CANDIDATE_NOT_FOUND",
|
|
328
|
+
"Skill 候选不属于该发现记录",
|
|
329
|
+
status_code=404,
|
|
330
|
+
)
|
|
331
|
+
return candidate
|
|
332
|
+
|
|
333
|
+
def inspect_candidate(
|
|
334
|
+
self,
|
|
335
|
+
directory: Path,
|
|
336
|
+
*,
|
|
337
|
+
source: str = "workspace",
|
|
338
|
+
root: Path | None = None,
|
|
339
|
+
display_root: str | None = None,
|
|
340
|
+
) -> dict[str, Any]:
|
|
341
|
+
resolved_root = root or self.workspace.root
|
|
342
|
+
relative = self._candidate_relative(directory, source=source, root=resolved_root)
|
|
343
|
+
display_path = self._display_candidate_path(
|
|
344
|
+
relative,
|
|
345
|
+
source=source,
|
|
346
|
+
display_root=display_root,
|
|
347
|
+
)
|
|
348
|
+
candidate_id = (
|
|
349
|
+
"skill_" + hashlib.sha256(f"{source}:{relative}".encode("utf-8")).hexdigest()[:16]
|
|
350
|
+
)
|
|
351
|
+
try:
|
|
352
|
+
files, total_bytes = self._safe_directory(directory, display_path=display_path)
|
|
353
|
+
metadata = self._frontmatter((directory / "SKILL.md").read_text(encoding="utf-8"))
|
|
354
|
+
name = str(metadata["name"])
|
|
355
|
+
slug = skill_slug(name)
|
|
356
|
+
version = str(metadata.get("version") or "1.0.0")
|
|
357
|
+
require_exact_version(version, field="SKILL.md.version")
|
|
358
|
+
digest = self._directory_digest(directory, files)
|
|
359
|
+
destination = self.workspace.resolve(Path("capabilities/skills") / slug)
|
|
360
|
+
scripts = [
|
|
361
|
+
path
|
|
362
|
+
for path in files
|
|
363
|
+
if Path(path).suffix.lower() in {".py", ".sh", ".js", ".ts", ".ps1"}
|
|
364
|
+
]
|
|
365
|
+
text = (directory / "SKILL.md").read_text(encoding="utf-8").lower()
|
|
366
|
+
network_markers = [
|
|
367
|
+
marker
|
|
368
|
+
for marker in ("http://", "https://", "curl ", "wget ", "network")
|
|
369
|
+
if marker in text
|
|
370
|
+
]
|
|
371
|
+
return {
|
|
372
|
+
"candidateId": candidate_id,
|
|
373
|
+
"path": display_path,
|
|
374
|
+
"source": source,
|
|
375
|
+
"relativePath": relative,
|
|
376
|
+
"name": slug,
|
|
377
|
+
"displayName": name,
|
|
378
|
+
"description": str(metadata["description"]),
|
|
379
|
+
"version": version,
|
|
380
|
+
"digest": digest,
|
|
381
|
+
"status": "conflict" if destination.exists() else "ready",
|
|
382
|
+
"fileCount": len(files),
|
|
383
|
+
"totalBytes": total_bytes,
|
|
384
|
+
"risk": {
|
|
385
|
+
"containsScripts": bool(scripts),
|
|
386
|
+
"scripts": scripts,
|
|
387
|
+
"networkMarkers": network_markers,
|
|
388
|
+
"requiresReview": bool(scripts or network_markers),
|
|
389
|
+
},
|
|
390
|
+
"diagnostics": [],
|
|
391
|
+
}
|
|
392
|
+
except (StudioError, OSError, UnicodeDecodeError) as exc:
|
|
393
|
+
return {
|
|
394
|
+
"candidateId": candidate_id,
|
|
395
|
+
"path": display_path,
|
|
396
|
+
"source": source,
|
|
397
|
+
"relativePath": relative,
|
|
398
|
+
"name": directory.name,
|
|
399
|
+
"displayName": directory.name,
|
|
400
|
+
"description": "",
|
|
401
|
+
"version": "",
|
|
402
|
+
"digest": "",
|
|
403
|
+
"status": "invalid",
|
|
404
|
+
"risk": {"requiresReview": True},
|
|
405
|
+
"diagnostics": [
|
|
406
|
+
{
|
|
407
|
+
"code": getattr(exc, "code", "SKILL_DISCOVERY_INVALID"),
|
|
408
|
+
"message": getattr(exc, "message", str(exc)),
|
|
409
|
+
}
|
|
410
|
+
],
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
def _safe_directory(self, directory: Path, *, display_path: str) -> tuple[list[str], int]:
|
|
414
|
+
files: list[str] = []
|
|
415
|
+
total_bytes = 0
|
|
416
|
+
for path in sorted(directory.rglob("*"), key=lambda item: item.as_posix()):
|
|
417
|
+
relative = path.relative_to(directory)
|
|
418
|
+
if any(part in EXCLUDED_PARTS for part in relative.parts):
|
|
419
|
+
continue
|
|
420
|
+
if path.is_symlink():
|
|
421
|
+
raise StudioError(
|
|
422
|
+
"SKILL_DISCOVERY_UNSAFE",
|
|
423
|
+
"Skill 候选包含软链接",
|
|
424
|
+
status_code=422,
|
|
425
|
+
details={"path": display_path},
|
|
426
|
+
)
|
|
427
|
+
if not path.is_file():
|
|
428
|
+
continue
|
|
429
|
+
if not stat.S_ISREG(path.stat().st_mode):
|
|
430
|
+
raise StudioError(
|
|
431
|
+
"SKILL_DISCOVERY_UNSAFE",
|
|
432
|
+
"Skill 候选包含非常规文件",
|
|
433
|
+
status_code=422,
|
|
434
|
+
)
|
|
435
|
+
files.append(relative.as_posix())
|
|
436
|
+
total_bytes += path.stat().st_size
|
|
437
|
+
if len(files) > MAX_SKILL_FILES or total_bytes > MAX_SKILL_BYTES:
|
|
438
|
+
raise StudioError(
|
|
439
|
+
"SKILL_DISCOVERY_TOO_LARGE",
|
|
440
|
+
"Skill 候选文件数或总大小超限",
|
|
441
|
+
status_code=422,
|
|
442
|
+
)
|
|
443
|
+
if files.count("SKILL.md") != 1:
|
|
444
|
+
raise StudioError(
|
|
445
|
+
"SKILL_MANIFEST_REQUIRED",
|
|
446
|
+
"Skill 候选根目录必须且只能包含一个 SKILL.md",
|
|
447
|
+
status_code=422,
|
|
448
|
+
)
|
|
449
|
+
return files, total_bytes
|
|
450
|
+
|
|
451
|
+
def _resolve_scan_root(self, raw: str) -> tuple[Path, str, str]:
|
|
452
|
+
token = raw.strip()
|
|
453
|
+
user_roots = self._user_skill_roots()
|
|
454
|
+
if token in user_roots:
|
|
455
|
+
root, display = user_roots[token]
|
|
456
|
+
return root, token, display
|
|
457
|
+
if token.startswith("~") or Path(token).is_absolute():
|
|
458
|
+
expanded = Path(token).expanduser().resolve()
|
|
459
|
+
for source, (root, display) in user_roots.items():
|
|
460
|
+
try:
|
|
461
|
+
expanded.relative_to(root)
|
|
462
|
+
except ValueError:
|
|
463
|
+
continue
|
|
464
|
+
return expanded, source, display
|
|
465
|
+
raise StudioError(
|
|
466
|
+
"SKILL_DISCOVERY_PATH_FORBIDDEN",
|
|
467
|
+
"仅允许扫描工作区目录或预置的本地 Skill 目录",
|
|
468
|
+
status_code=403,
|
|
469
|
+
details={"path": raw},
|
|
470
|
+
)
|
|
471
|
+
root = self.workspace.resolve(token)
|
|
472
|
+
return root, "workspace", self.workspace.relative(root)
|
|
473
|
+
|
|
474
|
+
def _resolve_candidate_directory(
|
|
475
|
+
self,
|
|
476
|
+
candidate: dict[str, Any],
|
|
477
|
+
) -> tuple[Path, str, Path, str]:
|
|
478
|
+
source = str(candidate.get("source") or "workspace")
|
|
479
|
+
relative = str(candidate.get("relativePath") or candidate.get("path") or "")
|
|
480
|
+
if source == "workspace":
|
|
481
|
+
directory = self.workspace.resolve(relative, must_exist=True)
|
|
482
|
+
return directory, source, self.workspace.root, ""
|
|
483
|
+
configured = self._user_skill_roots().get(source)
|
|
484
|
+
if configured is None:
|
|
485
|
+
raise StudioError(
|
|
486
|
+
"SKILL_DISCOVERY_PATH_FORBIDDEN",
|
|
487
|
+
"Skill 候选来源不在允许的本地目录中",
|
|
488
|
+
status_code=403,
|
|
489
|
+
)
|
|
490
|
+
root, _display_root = configured
|
|
491
|
+
directory = (root / relative).resolve(strict=True)
|
|
492
|
+
for allowed_source, (
|
|
493
|
+
allowed_root,
|
|
494
|
+
allowed_display_root,
|
|
495
|
+
) in self._user_skill_roots().items():
|
|
496
|
+
try:
|
|
497
|
+
directory.relative_to(allowed_root)
|
|
498
|
+
except ValueError:
|
|
499
|
+
continue
|
|
500
|
+
return directory, allowed_source, allowed_root, allowed_display_root
|
|
501
|
+
raise StudioError(
|
|
502
|
+
"SKILL_DISCOVERY_PATH_FORBIDDEN",
|
|
503
|
+
"Skill 候选路径不在允许的本地目录中",
|
|
504
|
+
status_code=403,
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
def _candidate_relative(self, directory: Path, *, source: str, root: Path) -> str:
|
|
508
|
+
if source == "workspace":
|
|
509
|
+
return self.workspace.relative(directory)
|
|
510
|
+
configured = self._user_skill_roots().get(source)
|
|
511
|
+
source_root = configured[0] if configured is not None else root
|
|
512
|
+
try:
|
|
513
|
+
return directory.relative_to(source_root).as_posix()
|
|
514
|
+
except ValueError:
|
|
515
|
+
return directory.resolve().relative_to(source_root).as_posix()
|
|
516
|
+
|
|
517
|
+
@staticmethod
|
|
518
|
+
def _scan_manifests(root: Path) -> list[Path]:
|
|
519
|
+
"""递归查找 SKILL.md;跟随目录软链(用户技能常通过软链挂载),并防循环。"""
|
|
520
|
+
manifests: list[Path] = []
|
|
521
|
+
if (root / "SKILL.md").is_file():
|
|
522
|
+
manifests.append(root / "SKILL.md")
|
|
523
|
+
visited: set[str] = set()
|
|
524
|
+
for dirpath, dirnames, filenames in os.walk(root, followlinks=True):
|
|
525
|
+
real = os.path.realpath(dirpath)
|
|
526
|
+
if real in visited:
|
|
527
|
+
dirnames[:] = []
|
|
528
|
+
continue
|
|
529
|
+
visited.add(real)
|
|
530
|
+
dirnames[:] = [d for d in dirnames if d not in EXCLUDED_PARTS]
|
|
531
|
+
if dirpath == str(root):
|
|
532
|
+
continue
|
|
533
|
+
if "SKILL.md" in filenames:
|
|
534
|
+
manifests.append(Path(dirpath) / "SKILL.md")
|
|
535
|
+
return manifests
|
|
536
|
+
|
|
537
|
+
def _display_candidate_path(
|
|
538
|
+
self,
|
|
539
|
+
relative: str,
|
|
540
|
+
*,
|
|
541
|
+
source: str,
|
|
542
|
+
display_root: str | None,
|
|
543
|
+
) -> str:
|
|
544
|
+
if source == "workspace":
|
|
545
|
+
return relative
|
|
546
|
+
root = display_root or source
|
|
547
|
+
return root if relative == "." else f"{root}/{relative}"
|
|
548
|
+
|
|
549
|
+
@staticmethod
|
|
550
|
+
def _user_skill_roots() -> dict[str, tuple[Path, str]]:
|
|
551
|
+
home = Path.home()
|
|
552
|
+
return {
|
|
553
|
+
source: ((home / relative).resolve(), f"~/{relative}")
|
|
554
|
+
for source, relative in USER_SKILL_ROOTS.items()
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
@staticmethod
|
|
558
|
+
def _directory_digest(directory: Path, files: list[str]) -> str:
|
|
559
|
+
entries = []
|
|
560
|
+
for relative in files:
|
|
561
|
+
content = (directory / relative).read_bytes()
|
|
562
|
+
entries.append(
|
|
563
|
+
{
|
|
564
|
+
"path": relative,
|
|
565
|
+
"sha256": hashlib.sha256(content).hexdigest(),
|
|
566
|
+
"size": len(content),
|
|
567
|
+
}
|
|
568
|
+
)
|
|
569
|
+
return sha256_digest(canonical_json(entries))
|
|
570
|
+
|
|
571
|
+
@staticmethod
|
|
572
|
+
def _preview_kind(relative: str) -> str:
|
|
573
|
+
path = Path(relative)
|
|
574
|
+
suffix = path.suffix.lower()
|
|
575
|
+
if suffix == ".md":
|
|
576
|
+
return "markdown"
|
|
577
|
+
if suffix in SCRIPT_SUFFIXES:
|
|
578
|
+
return "script"
|
|
579
|
+
if suffix in TEXT_SUFFIXES or not suffix:
|
|
580
|
+
return "text"
|
|
581
|
+
return "binary"
|
|
582
|
+
|
|
583
|
+
@staticmethod
|
|
584
|
+
def _frontmatter(content: str) -> dict[str, Any]:
|
|
585
|
+
if not content.startswith("---\n"):
|
|
586
|
+
raise StudioError(
|
|
587
|
+
"SKILL_MANIFEST_INVALID",
|
|
588
|
+
"SKILL.md 必须包含 YAML frontmatter",
|
|
589
|
+
status_code=422,
|
|
590
|
+
)
|
|
591
|
+
parts = content.split("\n---\n", 1)
|
|
592
|
+
if len(parts) != 2:
|
|
593
|
+
raise StudioError(
|
|
594
|
+
"SKILL_MANIFEST_INVALID",
|
|
595
|
+
"SKILL.md frontmatter 未闭合",
|
|
596
|
+
status_code=422,
|
|
597
|
+
)
|
|
598
|
+
try:
|
|
599
|
+
payload = yaml.safe_load(parts[0][4:]) or {}
|
|
600
|
+
except yaml.YAMLError as exc:
|
|
601
|
+
raise StudioError(
|
|
602
|
+
"SKILL_MANIFEST_INVALID",
|
|
603
|
+
"SKILL.md frontmatter 无法解析",
|
|
604
|
+
status_code=422,
|
|
605
|
+
) from exc
|
|
606
|
+
if (
|
|
607
|
+
not isinstance(payload, dict)
|
|
608
|
+
or not payload.get("name")
|
|
609
|
+
or not payload.get("description")
|
|
610
|
+
):
|
|
611
|
+
raise StudioError(
|
|
612
|
+
"SKILL_MANIFEST_INVALID",
|
|
613
|
+
"SKILL.md frontmatter 必须包含 name 和 description",
|
|
614
|
+
status_code=422,
|
|
615
|
+
)
|
|
616
|
+
return cast(dict[str, Any], payload)
|
|
617
|
+
|
|
618
|
+
def _record_path(self, token: str, *, validate: bool = False) -> Path:
|
|
619
|
+
if validate and not re.fullmatch(r"skd_[0-9a-f]{32}", token):
|
|
620
|
+
raise StudioError(
|
|
621
|
+
"SKILL_DISCOVERY_NOT_FOUND",
|
|
622
|
+
"Skill 发现记录不存在或已失效",
|
|
623
|
+
status_code=404,
|
|
624
|
+
)
|
|
625
|
+
return self.workspace.resolve(Path(".agentkit/skill-discoveries") / f"{token}.json")
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
__all__ = ["SkillDiscoveryService"]
|