codebuff-agent 2.1.74__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.
- codebuff_agent-2.1.74.data/data/etc/jupyter/jupyter_server_config.d/codebuff_agent.json +7 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/package.json +157 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/104.2b8f20f9d1ac2c9db01b.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/150.39fa98117cc8ca590465.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/166.386ff9b2c37ac865fdee.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/216.25cf81131bf7274dabf4.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/353.581bd1cb00746399b62e.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/367.575f9621b63c9a641aa9.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/421.11dac223a2c2da1b09f5.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/432.8513b4c6cc1d1232d165.js +2 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/432.8513b4c6cc1d1232d165.js.LICENSE.txt +19 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/439.ba5b5ef70ec6de214b8c.js +2 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/439.ba5b5ef70ec6de214b8c.js.LICENSE.txt +8 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/481.cc2dec9fa869d66f1407.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/487.0796e931d6e651482c14.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/49.d326f554b6f9ccde6580.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/541.26897ea32845659e36be.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/579.e569d3edd8391fd8fbb3.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/58.eb7cc679f7535cc8a2f1.js +2 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/58.eb7cc679f7535cc8a2f1.js.LICENSE.txt +8 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/666.d9bfdb23f98489d0a188.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/677.d266c39dbed33bc388b3.js +2 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/677.d266c39dbed33bc388b3.js.LICENSE.txt +8 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/68.26b6f59c8454adb17f20.js +204 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/694.4ac443814260057e68f7.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/791.61affb8d3480d3d60e0d.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/848.4d2db09cfbb09374b299.js +2 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/848.4d2db09cfbb09374b299.js.LICENSE.txt +9 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/868.5cfe7e1a348ec5af1b8c.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/97.ea559a5b8a9a09f17c6b.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/remoteEntry.5292fc9c6df7e7920cc8.js +1 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/style.js +4 -0
- codebuff_agent-2.1.74.data/data/share/jupyter/labextensions/codebuff/static/third-party-licenses.json +724 -0
- codebuff_agent-2.1.74.dist-info/METADATA +142 -0
- codebuff_agent-2.1.74.dist-info/RECORD +217 -0
- codebuff_agent-2.1.74.dist-info/WHEEL +4 -0
- codebuff_agent-2.1.74.dist-info/licenses/LICENSE +21 -0
- codebuff_core/__init__.py +153 -0
- codebuff_core/codebuff_config_defaults.json +64 -0
- codebuff_core/core/__init__.py +35 -0
- codebuff_core/core/code_validator.py +1238 -0
- codebuff_core/core/error_classifier.py +579 -0
- codebuff_core/core/exceptions.py +49 -0
- codebuff_core/data/tiktoken_cache/9b5ad71b2ce5302211f9c61530b329a4922fc6a4 +100256 -0
- codebuff_core/directory_policy.py +32 -0
- codebuff_core/factory.py +155 -0
- codebuff_core/interfaces.py +197 -0
- codebuff_core/knowledge/__init__.py +31 -0
- codebuff_core/knowledge/chunking.py +375 -0
- codebuff_core/knowledge/loader.py +339 -0
- codebuff_core/knowledge/watchdog_service.py +354 -0
- codebuff_core/legacy_paths.py +69 -0
- codebuff_core/llm/__init__.py +13 -0
- codebuff_core/llm/service.py +407 -0
- codebuff_core/managers/__init__.py +22 -0
- codebuff_core/managers/config_manager.py +690 -0
- codebuff_core/managers/remote_config.py +673 -0
- codebuff_core/managers/remote_skills.py +539 -0
- codebuff_core/managers/session_manager.py +255 -0
- codebuff_core/middleware/__init__.py +3 -0
- codebuff_core/middleware/error_recovery.py +394 -0
- codebuff_core/middleware/logging_utils.py +33 -0
- codebuff_core/models/__init__.py +111 -0
- codebuff_core/models/agent.py +306 -0
- codebuff_core/models/chat.py +57 -0
- codebuff_core/models/common.py +82 -0
- codebuff_core/models/rag.py +300 -0
- codebuff_core/platform_rules.py +127 -0
- codebuff_core/prompts/__init__.py +44 -0
- codebuff_core/prompts/auto_agent_prompts.py +1278 -0
- codebuff_core/services/__init__.py +30 -0
- codebuff_core/services/agent_service.py +345 -0
- codebuff_core/services/analytics_aggregate.py +837 -0
- codebuff_core/services/chat_service.py +898 -0
- codebuff_core/services/context_condenser.py +306 -0
- codebuff_core/services/pii_guardrail.py +393 -0
- codebuff_core/services/rag_chat_agent.py +2993 -0
- codebuff_core/services/rag_collections.py +2740 -0
- codebuff_core/services/rag_manager.py +890 -0
- codebuff_core/services/rag_service.py +145 -0
- codebuff_core/services/retriever.py +260 -0
- codebuff_core/services/vllm_embedding_service.py +290 -0
- codebuff_core/tests/__init__.py +1 -0
- codebuff_core/tests/conftest.py +81 -0
- codebuff_core/tests/test_error_recovery.py +647 -0
- codebuff_core/tests/test_factory.py +135 -0
- codebuff_core/tests/test_services.py +150 -0
- jupyter_ext/__init__.py +266 -0
- jupyter_ext/_version.py +4 -0
- jupyter_ext/agent/__init__.py +49 -0
- jupyter_ext/agent/agent_factory.py +2270 -0
- jupyter_ext/agent/ast_tools.py +451 -0
- jupyter_ext/agent/autofix_middleware.py +481 -0
- jupyter_ext/agent/background_procs.py +372 -0
- jupyter_ext/agent/code_history_middleware.py +211 -0
- jupyter_ext/agent/codex_autofix.py +160 -0
- jupyter_ext/agent/codex_bridge.py +3339 -0
- jupyter_ext/agent/codex_hooks.py +320 -0
- jupyter_ext/agent/codex_slash.py +685 -0
- jupyter_ext/agent/codex_threads.py +114 -0
- jupyter_ext/agent/content_injection.py +377 -0
- jupyter_ext/agent/continuation_middleware.py +548 -0
- jupyter_ext/agent/custom_skills.py +335 -0
- jupyter_ext/agent/file_diffs.py +99 -0
- jupyter_ext/agent/git_history.py +188 -0
- jupyter_ext/agent/guardrail_middleware.py +421 -0
- jupyter_ext/agent/json_repair_utils.py +54 -0
- jupyter_ext/agent/langchain_tools.py +2673 -0
- jupyter_ext/agent/mermaid_fixer.py +289 -0
- jupyter_ext/agent/mermaid_middleware.py +135 -0
- jupyter_ext/agent/middleware.py +359 -0
- jupyter_ext/agent/middleware_prompts.py +53 -0
- jupyter_ext/agent/observability.py +334 -0
- jupyter_ext/agent/patch_tool_calls.py +57 -0
- jupyter_ext/agent/prompts.py +112 -0
- jupyter_ext/agent/skill_middleware.py +257 -0
- jupyter_ext/agent/skills/airflow_dag_development.md +36 -0
- jupyter_ext/agent/skills/anomaly_detection.md +12 -0
- jupyter_ext/agent/skills/athena_sql.md +156 -0
- jupyter_ext/agent/skills/bdp_table_search.md +33 -0
- jupyter_ext/agent/skills/bigquery.md +65 -0
- jupyter_ext/agent/skills/bigquery_oracle.md +231 -0
- jupyter_ext/agent/skills/bigquery_tuning.md +307 -0
- jupyter_ext/agent/skills/classification_evaluation.md +11 -0
- jupyter_ext/agent/skills/clustering_analysis.md +12 -0
- jupyter_ext/agent/skills/comprehensive_eda.md +11 -0
- jupyter_ext/agent/skills/data_analysis.md +236 -0
- jupyter_ext/agent/skills/data_cleaning_pipeline.md +12 -0
- jupyter_ext/agent/skills/data_loading.md +158 -0
- jupyter_ext/agent/skills/data_quality_report.md +13 -0
- jupyter_ext/agent/skills/dimensionality_reduction.md +12 -0
- jupyter_ext/agent/skills/emr_script_development.md +17 -0
- jupyter_ext/agent/skills/experiment_tracking.md +13 -0
- jupyter_ext/agent/skills/feature_importance_analysis.md +10 -0
- jupyter_ext/agent/skills/hyperparameter_tuning.md +12 -0
- jupyter_ext/agent/skills/hypothesis_testing.md +12 -0
- jupyter_ext/agent/skills/imbalanced_data_handling.md +12 -0
- jupyter_ext/agent/skills/inference.md +392 -0
- jupyter_ext/agent/skills/lambda_function_development.md +19 -0
- jupyter_ext/agent/skills/model_comparison.md +11 -0
- jupyter_ext/agent/skills/model_explainability.md +12 -0
- jupyter_ext/agent/skills/model_training.md +318 -0
- jupyter_ext/agent/skills/pyspark.md +352 -0
- jupyter_ext/agent/skills/python_code_quality.md +35 -0
- jupyter_ext/agent/skills/regression_evaluation.md +12 -0
- jupyter_ext/agent/skills/spring_java_development.md +35 -0
- jupyter_ext/agent/skills/text_preprocessing.md +12 -0
- jupyter_ext/agent/skills/time_series_analysis.md +13 -0
- jupyter_ext/agent/skills/unit_testing.md +203 -0
- jupyter_ext/agent/todo_prompts.py +57 -0
- jupyter_ext/agent/tool_report.py +45 -0
- jupyter_ext/analytics_ingest.py +599 -0
- jupyter_ext/etc/jupyter/jupyter_server_config.d/codebuff_agent.json +7 -0
- jupyter_ext/handlers/__init__.py +8 -0
- jupyter_ext/handlers/analytics_handler.py +170 -0
- jupyter_ext/handlers/benchmark_handler.py +794 -0
- jupyter_ext/handlers/eda_benchmark_handler.py +1328 -0
- jupyter_ext/handlers/rag_admin_handler.py +689 -0
- jupyter_ext/handlers/websocket.py +497 -0
- jupyter_ext/http_handlers.py +8744 -0
- jupyter_ext/idle_monitor.py +346 -0
- jupyter_ext/labextension/package.json +157 -0
- jupyter_ext/labextension/static/104.2b8f20f9d1ac2c9db01b.js +1 -0
- jupyter_ext/labextension/static/150.39fa98117cc8ca590465.js +1 -0
- jupyter_ext/labextension/static/166.386ff9b2c37ac865fdee.js +1 -0
- jupyter_ext/labextension/static/216.25cf81131bf7274dabf4.js +1 -0
- jupyter_ext/labextension/static/353.581bd1cb00746399b62e.js +1 -0
- jupyter_ext/labextension/static/367.575f9621b63c9a641aa9.js +1 -0
- jupyter_ext/labextension/static/421.11dac223a2c2da1b09f5.js +1 -0
- jupyter_ext/labextension/static/432.8513b4c6cc1d1232d165.js +2 -0
- jupyter_ext/labextension/static/432.8513b4c6cc1d1232d165.js.LICENSE.txt +19 -0
- jupyter_ext/labextension/static/439.ba5b5ef70ec6de214b8c.js +2 -0
- jupyter_ext/labextension/static/439.ba5b5ef70ec6de214b8c.js.LICENSE.txt +8 -0
- jupyter_ext/labextension/static/481.cc2dec9fa869d66f1407.js +1 -0
- jupyter_ext/labextension/static/487.0796e931d6e651482c14.js +1 -0
- jupyter_ext/labextension/static/49.d326f554b6f9ccde6580.js +1 -0
- jupyter_ext/labextension/static/541.26897ea32845659e36be.js +1 -0
- jupyter_ext/labextension/static/579.e569d3edd8391fd8fbb3.js +1 -0
- jupyter_ext/labextension/static/58.eb7cc679f7535cc8a2f1.js +2 -0
- jupyter_ext/labextension/static/58.eb7cc679f7535cc8a2f1.js.LICENSE.txt +8 -0
- jupyter_ext/labextension/static/666.d9bfdb23f98489d0a188.js +1 -0
- jupyter_ext/labextension/static/677.d266c39dbed33bc388b3.js +2 -0
- jupyter_ext/labextension/static/677.d266c39dbed33bc388b3.js.LICENSE.txt +8 -0
- jupyter_ext/labextension/static/68.26b6f59c8454adb17f20.js +204 -0
- jupyter_ext/labextension/static/694.4ac443814260057e68f7.js +1 -0
- jupyter_ext/labextension/static/791.61affb8d3480d3d60e0d.js +1 -0
- jupyter_ext/labextension/static/848.4d2db09cfbb09374b299.js +2 -0
- jupyter_ext/labextension/static/848.4d2db09cfbb09374b299.js.LICENSE.txt +9 -0
- jupyter_ext/labextension/static/868.5cfe7e1a348ec5af1b8c.js +1 -0
- jupyter_ext/labextension/static/97.ea559a5b8a9a09f17c6b.js +1 -0
- jupyter_ext/labextension/static/remoteEntry.5292fc9c6df7e7920cc8.js +1 -0
- jupyter_ext/labextension/static/style.js +4 -0
- jupyter_ext/labextension/static/third-party-licenses.json +724 -0
- jupyter_ext/log_paths.py +113 -0
- jupyter_ext/resource_usage.py +519 -0
- jupyter_ext/secrets_bootstrap.py +116 -0
- jupyter_ext/team_access.py +105 -0
- jupyter_ext/tests/__init__.py +1 -0
- jupyter_ext/tests/test_context.py +234 -0
- jupyter_ext/tests/test_factory.py +563 -0
- jupyter_ext/tests/test_file_finder.py +139 -0
- jupyter_ext/tests/test_handlers.py +58 -0
- jupyter_ext/tests/test_mcp_selftest.py +204 -0
- jupyter_ext/tests/test_mermaid_fixer.py +272 -0
- jupyter_ext/tests/test_resource_tiers.py +298 -0
- jupyter_ext/tools/__init__.py +15 -0
- jupyter_ext/tools/base.py +90 -0
- jupyter_ext/tools/context.py +268 -0
- jupyter_ext/tools/dir_complete.py +86 -0
- jupyter_ext/tools/file_finder.py +303 -0
- jupyter_ext/tools/file_tools.py +244 -0
- jupyter_ext/tools/jupyter_tools.py +296 -0
- jupyter_ext/tools/registry.py +159 -0
- jupyter_ext/tools/search_tools.py +230 -0
- jupyter_ext/tools/security_tools.py +657 -0
- jupyter_ext/tools/shell_tools.py +109 -0
- jupyter_ext/tools/user_tools.py +132 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""๋ด์ฅ PostToolUse hook โ ๊ณ ์น ํ์ผ์ ruff/biome autofix ๋ฅผ ๋๋ฆฐ๋ค (์ด์ #145).
|
|
2
|
+
|
|
3
|
+
`codex_hooks.BUILTIN_HOOKS` ๊ฐ `python -m jupyter_ext.agent.codex_autofix` ๋ก ๋ถ๋ฅธ๋ค.
|
|
4
|
+
stdin ์ codex `PostToolUse` ํ์ด๋ก๋์ด๊ณ , ์ฌ์ฉ์ hooks.json ์ hook ๊ณผ ๊ฐ์ ๋ฌ๋ยท๊ฐ์
|
|
5
|
+
๊ท๊ฒฉ์ผ๋ก ๋๋ค. ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ง ์ด๋ค โ hook ์ ๋งค ํธ์ง๋ง๋ค ์ ํ๋ก์ธ์ค๋ก ๋ฌ๋ค.
|
|
6
|
+
|
|
7
|
+
| ํ์ผ | ๋๊ตฌ | ์กฐ๊ฑด |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `.py` `.pyi` | `ruff check --fix --unfixable F401` โ `ruff format` | ํญ์ (`ruff_command`) |
|
|
10
|
+
| JSยทTSยทJSONยทCSS | `biome check --write` | ํ์ผ๋ถํฐ ์ํฌ์คํ์ด์ค๊น์ง `biome.json(c)` ์ด ์์ ๋ |
|
|
11
|
+
|
|
12
|
+
- ruff ๋ PATH ์ ๊ฒ์ ๋จผ์ ์ฐ๊ณ , ์์ผ๋ฉด wheel ์ด ๊ฐ์ด ๊น ๊ฒ(`python -m ruff`)์ ์ด๋ค.
|
|
13
|
+
ruff ๋ `codebuff-agent` ์ ๋ฐํ์ ์์กด์ฑ์ด๋ค (์ด์ #145) โ ์๋ฒ๋ฅผ venv ํ์ฑ ์์ด
|
|
14
|
+
๋์ PATH ์ ์์ด๋ ๋๋ค.
|
|
15
|
+
- `write_file` ์ `.py` ๋ ๊ฑด๋๋ด๋ค. `langchain_tools` ๊ฐ ์ด๋ฏธ ruff ๋ฅผ ๋๋ฆฐ๋ค.
|
|
16
|
+
- biome ์ ์ค์ ๋๋ ํฐ๋ฆฌ์ `node_modules/.bin/biome` ๋๋ PATH ์ ๊ฒ๋ง ์ด๋ค.
|
|
17
|
+
`npx` ๋ก ๋ฐ์ ์ค์ง ์๋๋ค โ ํธ์ง ํ ๋ฒ์ ๋คํธ์ํฌ๋ฅผ ํ๋ฉด ์ ๋๋ค.
|
|
18
|
+
- ๋๊ตฌ๊ฐ ์์ผ๋ฉด `systemMessage` ๋ก ์๋ฆฐ๋ค (๋ธ๋ฆฌ์ง๊ฐ ์ธ์
๋น ํ ๋ฒ๋ง ๋์ด๋ค).
|
|
19
|
+
- ํญ์ exit 0 ์ด๋ค. ํฌ๋งท ์คํจ๊ฐ ํธ์ง์ ๋ง์ผ๋ฉด ์ ๋๋ค.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import importlib.util
|
|
25
|
+
import json
|
|
26
|
+
import os
|
|
27
|
+
import re
|
|
28
|
+
import shutil
|
|
29
|
+
import subprocess
|
|
30
|
+
import sys
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
from typing import Dict, List, Optional
|
|
33
|
+
|
|
34
|
+
PYTHON_SUFFIXES = {".py", ".pyi"}
|
|
35
|
+
BIOME_SUFFIXES = {
|
|
36
|
+
".js",
|
|
37
|
+
".jsx",
|
|
38
|
+
".mjs",
|
|
39
|
+
".cjs",
|
|
40
|
+
".ts",
|
|
41
|
+
".tsx",
|
|
42
|
+
".json",
|
|
43
|
+
".jsonc",
|
|
44
|
+
".css",
|
|
45
|
+
}
|
|
46
|
+
BIOME_CONFIGS = ("biome.json", "biome.jsonc")
|
|
47
|
+
#: `ruff check` ์ธ์. F401(์ ์ฐ์ธ import) ์ ๊ณ ์น์ง ์๋๋ค โ ์์ด์ ํธ๋ import ๋ฅผ ๋จผ์
|
|
48
|
+
#: ์ฐ๊ณ ์ฐ๋ ๊ณณ์ ๋ค์ ํธ์ง์ ์ฐ๋๋ฐ, ๊ทธ ์ฌ์ด์ ์ง์ฐ๋ฉด import ๊ฐ ์ฌ๋ผ์ง๋ค. `--unfixable` ์
|
|
49
|
+
#: ํ๋ก์ ํธ ์ค์ ์ unfixable ์ ๋ํด์ง๋ฏ๋ก ์ฌ์ฉ์ ์ค์ ์ ๋ฎ์ง ์๋๋ค
|
|
50
|
+
RUFF_FIX = ("check", "--fix", "--unfixable", "F401")
|
|
51
|
+
#: ํ ๋ช
๋ น์ ํ๋. ๋ด์ฅ hook ์ ์ฒด ํ๋(`codex_hooks.BUILTIN_TIMEOUT`) ์์ ๋์ด ๋ค์ด๊ฐ๋ค
|
|
52
|
+
STEP_TIMEOUT = 25
|
|
53
|
+
|
|
54
|
+
_PATCH_HEADER = re.compile(r"^\*\*\* (?:Add|Update) File: (.+)$", re.MULTILINE)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _target(payload: Dict, cwd: Path) -> Optional[Path]:
|
|
58
|
+
"""๊ณ ์น ํ์ผ์ ์ ๋๊ฒฝ๋ก. ์ํฌ์คํ์ด์ค ๋ฐ์ด๋ฉด None ์ด๋ค."""
|
|
59
|
+
tool_input = payload.get("tool_input") or {}
|
|
60
|
+
raw = tool_input.get("path")
|
|
61
|
+
if not raw:
|
|
62
|
+
m = _PATCH_HEADER.search(str(tool_input.get("command") or ""))
|
|
63
|
+
raw = m.group(1).strip() if m else ""
|
|
64
|
+
if not raw:
|
|
65
|
+
return None
|
|
66
|
+
path = (cwd / raw).resolve()
|
|
67
|
+
try:
|
|
68
|
+
path.relative_to(cwd)
|
|
69
|
+
except ValueError:
|
|
70
|
+
return None
|
|
71
|
+
return path if path.is_file() else None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def ruff_command() -> Optional[List[str]]:
|
|
75
|
+
"""ruff ๋ฅผ ๋ถ๋ฅด๋ ๋ช
๋ น ๋จธ๋ฆฌ. PATH โ wheel ์ด ๊น ๊ฒ ์์ด๊ณ , ๋ ๋ค ์์ผ๋ฉด None."""
|
|
76
|
+
found = shutil.which("ruff")
|
|
77
|
+
if found:
|
|
78
|
+
return [found]
|
|
79
|
+
if importlib.util.find_spec("ruff") is not None:
|
|
80
|
+
return [sys.executable, "-m", "ruff"]
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _run(cmd: List[str], cwd: Path) -> None:
|
|
85
|
+
try:
|
|
86
|
+
subprocess.run(cmd, cwd=cwd, capture_output=True, timeout=STEP_TIMEOUT)
|
|
87
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _biome(path: Path, cwd: Path) -> Optional[str]:
|
|
92
|
+
"""biome ์คํ ํ์ผ. ์ค์ ์ด ์์ผ๋ฉด ๋น ๋ฌธ์์ด, ์ค์ ์ ์๋๋ฐ ์คํ ํ์ผ์ด ์์ผ๋ฉด None."""
|
|
93
|
+
for d in [path.parent, *path.parent.parents]:
|
|
94
|
+
if any((d / name).is_file() for name in BIOME_CONFIGS):
|
|
95
|
+
local = d / "node_modules" / ".bin" / "biome"
|
|
96
|
+
if local.is_file() and os.access(local, os.X_OK):
|
|
97
|
+
return str(local)
|
|
98
|
+
return shutil.which("biome")
|
|
99
|
+
if d == cwd:
|
|
100
|
+
break
|
|
101
|
+
return ""
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def autofix(payload: Dict) -> Dict:
|
|
105
|
+
cwd = Path(payload.get("cwd") or os.getcwd()).resolve()
|
|
106
|
+
path = _target(payload, cwd)
|
|
107
|
+
if path is None:
|
|
108
|
+
return {}
|
|
109
|
+
suffix = path.suffix.lower()
|
|
110
|
+
tool = (payload.get("tool_input") or {}).get("codebuff_tool")
|
|
111
|
+
if suffix in PYTHON_SUFFIXES:
|
|
112
|
+
if tool == "write_file" and suffix == ".py":
|
|
113
|
+
return {}
|
|
114
|
+
ruff = ruff_command()
|
|
115
|
+
if not ruff:
|
|
116
|
+
return {"systemMessage": "ruff ๊ฐ ์์ด .py ์๋ ํฌ๋งท์ ๊ฑด๋๋๋๋ค"}
|
|
117
|
+
cmds = [[*ruff, *RUFF_FIX, str(path)], [*ruff, "format", str(path)]]
|
|
118
|
+
name = "ruff"
|
|
119
|
+
elif suffix in BIOME_SUFFIXES:
|
|
120
|
+
biome = _biome(path, cwd)
|
|
121
|
+
if biome == "":
|
|
122
|
+
return {}
|
|
123
|
+
if biome is None:
|
|
124
|
+
return {
|
|
125
|
+
"systemMessage": "biome ์ค์ ์ ์๋๋ฐ biome ์ด ์์ด ์๋ ํฌ๋งท์ ๊ฑด๋๋๋๋ค"
|
|
126
|
+
}
|
|
127
|
+
cmds = [[biome, "check", "--write", str(path)]]
|
|
128
|
+
name = "biome"
|
|
129
|
+
else:
|
|
130
|
+
return {}
|
|
131
|
+
before = path.read_bytes()
|
|
132
|
+
for cmd in cmds:
|
|
133
|
+
_run(cmd, cwd)
|
|
134
|
+
if path.read_bytes() == before:
|
|
135
|
+
return {}
|
|
136
|
+
rel = path.relative_to(cwd)
|
|
137
|
+
return {
|
|
138
|
+
"hookSpecificOutput": {
|
|
139
|
+
"hookEventName": "PostToolUse",
|
|
140
|
+
"additionalContext": (
|
|
141
|
+
f"autofix: {name} ๊ฐ {rel} ๋ฅผ ๊ณ ์ณค๋ค. ์ด ํ์ผ์ ๋ค์ edit_file ๋ก "
|
|
142
|
+
"๊ณ ์น๊ธฐ ์ ์ read_file ๋ก ์ ๋ด์ฉ์ ์ฝ๋๋ค."
|
|
143
|
+
),
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def main() -> int:
|
|
149
|
+
try:
|
|
150
|
+
payload = json.loads(sys.stdin.read() or "{}")
|
|
151
|
+
out = autofix(payload) if isinstance(payload, dict) else {}
|
|
152
|
+
except Exception as e: # noqa: BLE001 โ ํฌ๋งท ์คํจ๊ฐ ํธ์ง์ ๋ง์ผ๋ฉด ์ ๋๋ค
|
|
153
|
+
out = {"systemMessage": f"autofix ์คํจ: {e}"}
|
|
154
|
+
if out:
|
|
155
|
+
print(json.dumps(out, ensure_ascii=False))
|
|
156
|
+
return 0
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if __name__ == "__main__":
|
|
160
|
+
sys.exit(main())
|