kodit 0.1.4__py3-none-any.whl → 0.1.6__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.

Potentially problematic release.


This version of kodit might be problematic. Click here for more details.

@@ -0,0 +1,48 @@
1
+ """Generate snippets from a file."""
2
+
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+
6
+ from kodit.snippets.languages import detect_language
7
+ from kodit.snippets.method_snippets import MethodSnippets
8
+
9
+
10
+ @dataclass
11
+ class Snippet:
12
+ """A snippet of code."""
13
+
14
+ text: str
15
+
16
+
17
+ class SnippetService:
18
+ """Factory for generating snippets from a file.
19
+
20
+ This is required because there's going to be multiple ways to generate snippets.
21
+ """
22
+
23
+ def __init__(self) -> None:
24
+ """Initialize the snippet factory."""
25
+ self.language_dir = Path(__file__).parent / "languages"
26
+
27
+ def snippets_for_file(self, file_path: Path) -> list[Snippet]:
28
+ """Generate snippets from a file."""
29
+ language = detect_language(file_path)
30
+
31
+ try:
32
+ query_path = self.language_dir / f"{language}.scm"
33
+ with query_path.open() as f:
34
+ query = f.read()
35
+ except Exception as e:
36
+ msg = f"Unsupported language: {file_path}"
37
+ raise ValueError(msg) from e
38
+
39
+ method_analser = MethodSnippets(language, query)
40
+
41
+ try:
42
+ file_bytes = file_path.read_bytes()
43
+ except Exception as e:
44
+ msg = f"Failed to read file: {file_path}"
45
+ raise ValueError(msg) from e
46
+
47
+ method_snippets = method_analser.extract(file_bytes)
48
+ return [Snippet(text=snippet) for snippet in method_snippets]
kodit/sources/service.py CHANGED
@@ -18,12 +18,9 @@ import structlog
18
18
  from tqdm import tqdm
19
19
  from uritools import isuri, urisplit
20
20
 
21
- from kodit.config import DATA_DIR
22
21
  from kodit.sources.models import File, Source
23
22
  from kodit.sources.repository import SourceRepository
24
23
 
25
- CLONE_DIR = DATA_DIR / "clones"
26
-
27
24
 
28
25
  class SourceView(pydantic.BaseModel):
29
26
  """View model for displaying source information.
@@ -53,13 +50,14 @@ class SourceService:
53
50
  SourceRepository), and provides a clean API for source management.
54
51
  """
55
52
 
56
- def __init__(self, repository: SourceRepository) -> None:
53
+ def __init__(self, clone_dir: Path, repository: SourceRepository) -> None:
57
54
  """Initialize the source service.
58
55
 
59
56
  Args:
60
57
  repository: The repository instance to use for database operations.
61
58
 
62
59
  """
60
+ self.clone_dir = clone_dir
63
61
  self.repository = repository
64
62
  self.log = structlog.get_logger(__name__)
65
63
 
@@ -129,7 +127,7 @@ class SourceService:
129
127
  raise ValueError(msg)
130
128
 
131
129
  # Clone into a local directory
132
- clone_path = CLONE_DIR / directory.as_posix().replace("/", "_")
130
+ clone_path = self.clone_dir / directory.as_posix().replace("/", "_")
133
131
  clone_path.mkdir(parents=True, exist_ok=True)
134
132
 
135
133
  # Copy all files recursively, preserving directory structure, ignoring hidden
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kodit
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Code indexing for better AI code generation
5
5
  Project-URL: Homepage, https://docs.helixml.tech/kodit/
6
6
  Project-URL: Documentation, https://docs.helixml.tech/kodit/
@@ -22,18 +22,22 @@ Requires-Dist: aiosqlite>=0.20.0
22
22
  Requires-Dist: alembic>=1.15.2
23
23
  Requires-Dist: asgi-correlation-id>=4.3.4
24
24
  Requires-Dist: better-exceptions>=0.3.3
25
+ Requires-Dist: bm25s[core]>=0.2.12
25
26
  Requires-Dist: click>=8.1.8
26
27
  Requires-Dist: colorama>=0.4.6
27
28
  Requires-Dist: dotenv>=0.9.9
28
29
  Requires-Dist: fastapi[standard]>=0.115.12
30
+ Requires-Dist: fastmcp>=2.3.3
29
31
  Requires-Dist: httpx-retries>=0.3.2
30
32
  Requires-Dist: httpx>=0.28.1
31
- Requires-Dist: mcp>=1.6.0
32
33
  Requires-Dist: posthog>=4.0.1
34
+ Requires-Dist: pydantic-settings>=2.9.1
33
35
  Requires-Dist: pytable-formatter>=0.1.1
34
36
  Requires-Dist: sqlalchemy[asyncio]>=2.0.40
35
37
  Requires-Dist: structlog>=25.3.0
36
38
  Requires-Dist: tdqm>=0.0.1
39
+ Requires-Dist: tree-sitter-language-pack>=0.7.3
40
+ Requires-Dist: tree-sitter>=0.24.0
37
41
  Requires-Dist: uritools>=5.0.0
38
42
  Description-Content-Type: text/markdown
39
43
 
@@ -0,0 +1,40 @@
1
+ kodit/.gitignore,sha256=ztkjgRwL9Uud1OEi36hGQeDGk3OLK1NfDEO8YqGYy8o,11
2
+ kodit/__init__.py,sha256=aEKHYninUq1yh6jaNfvJBYg-6fenpN132nJt1UU6Jxs,59
3
+ kodit/_version.py,sha256=ESbJO0YD7TYfOUv_WDIJJgWELGepEWsoyhqVifEcXPA,511
4
+ kodit/app.py,sha256=Mr5BFHOHx5zppwjC4XPWVvHjwgl1yrKbUjTWXKubJQM,891
5
+ kodit/cli.py,sha256=CNewAn4aCDBbBRKfTaO5hosklCySvJM7afDN04h3lvY,8307
6
+ kodit/config.py,sha256=nlm9U-nVx5riH2SrU1XY4XcCMhQK4DrwO_1H8bPOBjA,2927
7
+ kodit/database.py,sha256=vtTlmrXHyHJH3Ek-twZTCqEjB0jun-NncALFze2fqhA,2350
8
+ kodit/logging.py,sha256=cFEQXWI27LzWScSxly9ApwkbBDamUG17pA-jEfVakXQ,5316
9
+ kodit/mcp.py,sha256=PxTHVPlIErrruFKzmEPIWZjN6cfEhcQmj6nOU9EsBy4,4905
10
+ kodit/middleware.py,sha256=I6FOkqG9-8RH5kR1-0ZoQWfE4qLCB8lZYv8H_OCH29o,2714
11
+ kodit/alembic/README,sha256=ISVtAOvqvKk_5ThM5ioJE-lMkvf9IbknFUFVU_vPma4,58
12
+ kodit/alembic/__init__.py,sha256=lP5MuwlyWRMO6UcDWnQcQ3G-GYHcFb6rl9gYPHJ1sjo,40
13
+ kodit/alembic/env.py,sha256=kcQiglu2KpNTAf37CsKVs_HXxOe6S7sXJ00pHGSCqno,2414
14
+ kodit/alembic/script.py.mako,sha256=zWziKtiwYKEWuwPV_HBNHwa9LCT45_bi01-uSNFaOOE,703
15
+ kodit/alembic/versions/85155663351e_initial.py,sha256=Cg7zlF871o9ShV5rQMQ1v7hRV7fI59veDY9cjtTrs-8,3306
16
+ kodit/alembic/versions/__init__.py,sha256=9-lHzptItTzq_fomdIRBegQNm4Znx6pVjwD4MiqRIdo,36
17
+ kodit/bm25/__init__.py,sha256=j8zyriNWhbwE5Lbybzg1hQAhANlU9mKHWw4beeUR6og,19
18
+ kodit/bm25/bm25.py,sha256=3wyNRSrTaYqV7s4R1D6X0NpCf22PuFK2_uc8YapzYLE,2263
19
+ kodit/indexing/__init__.py,sha256=cPyi2Iej3G1JFWlWr7X80_UrsMaTu5W5rBwgif1B3xo,75
20
+ kodit/indexing/models.py,sha256=sZIhGwvL4Dw0QTWFxrjfWctSLkAoDT6fv5DlGz8-Fr8,1258
21
+ kodit/indexing/repository.py,sha256=kvAlNfMSQYboF0TB1huw2qoBdLJ4UsEPiM7ZG-e6rrg,4300
22
+ kodit/indexing/service.py,sha256=eopx_IZeaUjCI-5LeSqZq7W7m76JZsDcVvOFhLquHpI,5426
23
+ kodit/retreival/__init__.py,sha256=33PhJU-3gtsqYq6A1UkaLNKbev_Zee9Lq6dYC59-CsA,69
24
+ kodit/retreival/repository.py,sha256=1lqGgJHsBmvMGMzEYa-hrdXg2q7rqtYPl1cvBb7jMRE,3119
25
+ kodit/retreival/service.py,sha256=9wvURtPPJVvPUWNIC2waIrJMxcm1Ka1J_xDEOEedAFU,2007
26
+ kodit/snippets/__init__.py,sha256=-2coNoCRjTixU9KcP6alpmt7zqf37tCRWH3D7FPJ8dg,48
27
+ kodit/snippets/method_snippets.py,sha256=EVHhSNWahAC5nSXv9fWVFJY2yq25goHdCSCuENC07F8,4145
28
+ kodit/snippets/snippets.py,sha256=QumvhltWoxXw41SyKb-RbSvAr3m6V3lUy9n0AI8jcto,1409
29
+ kodit/snippets/languages/__init__.py,sha256=Bj5KKZSls2MQ8ZY1S_nHg447MgGZW-2WZM-oq6vjwwA,1187
30
+ kodit/snippets/languages/csharp.scm,sha256=gbBN4RiV1FBuTJF6orSnDFi8H9JwTw-d4piLJYsWUsc,222
31
+ kodit/snippets/languages/python.scm,sha256=ee85R9PBzwye3IMTE7-iVoKWd_ViU3EJISTyrFGrVeo,429
32
+ kodit/sources/__init__.py,sha256=1NTZyPdjThVQpZO1Mp1ColVsS7sqYanOVLqnoqV9Ipo,83
33
+ kodit/sources/models.py,sha256=xb42CaNDO1CUB8SIW-xXMrB6Ji8cFw-yeJ550xBEg9Q,2398
34
+ kodit/sources/repository.py,sha256=mGJrHWH6Uo8YABdoojHFbzaf_jW-2ywJpAHIa1gnc3U,3401
35
+ kodit/sources/service.py,sha256=cBCxnOQKwGNi2e13_3Vue8MylAaUxb9XG4IgM636la0,6712
36
+ kodit-0.1.6.dist-info/METADATA,sha256=1HHbQJLVCV6-1Kim8-_pwXq_HmSYUgBLObA_Q3Ck2l8,2181
37
+ kodit-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
+ kodit-0.1.6.dist-info/entry_points.txt,sha256=hoTn-1aKyTItjnY91fnO-rV5uaWQLQ-Vi7V5et2IbHY,40
39
+ kodit-0.1.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
40
+ kodit-0.1.6.dist-info/RECORD,,
kodit/sse.py DELETED
@@ -1,61 +0,0 @@
1
- """Server-Sent Events (SSE) implementation for kodit."""
2
-
3
- from collections.abc import Coroutine
4
- from typing import Any
5
-
6
- from fastapi import Request
7
- from mcp.server.fastmcp import FastMCP
8
- from mcp.server.session import ServerSession
9
- from mcp.server.sse import SseServerTransport
10
- from starlette.applications import Starlette
11
- from starlette.routing import Mount, Route
12
-
13
- ####################################################################################
14
- # Temporary monkeypatch which avoids crashing when a POST message is received
15
- # before a connection has been initialized, e.g: after a deployment.
16
- old__received_request = ServerSession._received_request # noqa: SLF001
17
-
18
-
19
- async def _received_request(self: ServerSession, *args: Any, **kwargs: Any) -> None:
20
- """Handle a received request, catching RuntimeError to avoid crashes.
21
-
22
- This is a temporary monkeypatch to avoid crashing when a POST message is
23
- received before a connection has been initialized, e.g: after a deployment.
24
- """
25
- try:
26
- return await old__received_request(self, *args, **kwargs)
27
- except RuntimeError:
28
- pass
29
-
30
-
31
- # pylint: disable-next=protected-access
32
- ServerSession._received_request = _received_request # noqa: SLF001
33
- ####################################################################################
34
-
35
-
36
- def create_sse_server(mcp: FastMCP) -> Starlette:
37
- """Create a Starlette app that handles SSE connections and message handling."""
38
- transport = SseServerTransport("/messages/")
39
-
40
- # Define handler functions
41
- async def handle_sse(request: Request) -> Coroutine[Any, Any, None]:
42
- """Handle SSE connections."""
43
- async with transport.connect_sse(
44
- request.scope,
45
- request.receive,
46
- request._send, # noqa: SLF001
47
- ) as streams:
48
- await mcp._mcp_server.run( # noqa: SLF001
49
- streams[0],
50
- streams[1],
51
- mcp._mcp_server.create_initialization_options(), # noqa: SLF001
52
- )
53
-
54
- # Create Starlette routes for SSE and message handling
55
- routes = [
56
- Route("/sse/", endpoint=handle_sse),
57
- Mount("/messages/", app=transport.handle_post_message),
58
- ]
59
-
60
- # Create a Starlette app
61
- return Starlette(routes=routes)
@@ -1,33 +0,0 @@
1
- kodit/.gitignore,sha256=ztkjgRwL9Uud1OEi36hGQeDGk3OLK1NfDEO8YqGYy8o,11
2
- kodit/__init__.py,sha256=aEKHYninUq1yh6jaNfvJBYg-6fenpN132nJt1UU6Jxs,59
3
- kodit/_version.py,sha256=hcPkC9vIGgfrKK6ft7ysLT7iOCjpFmCBmyKLmXiaZ1g,511
4
- kodit/app.py,sha256=FBAeeOz2CICvVN_27iMq9wEF9y8d1IDl0WmkEnM_M_U,699
5
- kodit/cli.py,sha256=C8fos0wkUH3AJAf_yVBDEYKAgqNfGbKQiVBCGRqZITQ,5644
6
- kodit/config.py,sha256=Wq9MlxOnOA3p9mgIzsq-s7N57_GFVIOMML-4GFINmqE,104
7
- kodit/database.py,sha256=4gkgf3d8ZBrW5ZXQ6yO16f3jFXSbqa6UiPBz1g_teJE,2521
8
- kodit/logging.py,sha256=dQr4YXVH8_B52V0wXbBrn_HvH4QpO-fsi0C3JPWzn0Y,5022
9
- kodit/mcp.py,sha256=Fi5e8r-6Ec3sHSe7jlIHpnUPsG0-t-Cw7_rwbKtcRAk,3521
10
- kodit/middleware.py,sha256=NHLrqq20ZtPTE9esX9HD3z7EKi56_QTFxBlkdq0JDzQ,2138
11
- kodit/sse.py,sha256=UgwXJUeFq5D5S9KYKVVg4m6P0-_QHnJOCRRQB8XNR-M,2259
12
- kodit/alembic/README,sha256=ISVtAOvqvKk_5ThM5ioJE-lMkvf9IbknFUFVU_vPma4,58
13
- kodit/alembic/__init__.py,sha256=lP5MuwlyWRMO6UcDWnQcQ3G-GYHcFb6rl9gYPHJ1sjo,40
14
- kodit/alembic/env.py,sha256=WnmwmN6wKEThI17b-VPDkRq-nKfmaT6nRLabc2VM1oM,2390
15
- kodit/alembic/script.py.mako,sha256=zWziKtiwYKEWuwPV_HBNHwa9LCT45_bi01-uSNFaOOE,703
16
- kodit/alembic/versions/85155663351e_initial.py,sha256=Cg7zlF871o9ShV5rQMQ1v7hRV7fI59veDY9cjtTrs-8,3306
17
- kodit/alembic/versions/__init__.py,sha256=9-lHzptItTzq_fomdIRBegQNm4Znx6pVjwD4MiqRIdo,36
18
- kodit/indexing/__init__.py,sha256=cPyi2Iej3G1JFWlWr7X80_UrsMaTu5W5rBwgif1B3xo,75
19
- kodit/indexing/models.py,sha256=sZIhGwvL4Dw0QTWFxrjfWctSLkAoDT6fv5DlGz8-Fr8,1258
20
- kodit/indexing/repository.py,sha256=GeRpgRNOZunEKtzkkqkJWlOaR8cpGMX4rI_puDdB8WY,4006
21
- kodit/indexing/service.py,sha256=jdQMOsm8kYTlNybxSs2xisRxZRQISlmRQDfLtoqkpjg,4951
22
- kodit/retreival/__init__.py,sha256=33PhJU-3gtsqYq6A1UkaLNKbev_Zee9Lq6dYC59-CsA,69
23
- kodit/retreival/repository.py,sha256=WJQiePfeuwnj8Vy6dqF4bhNhsWqH9VspjN2zlvYQWvY,2273
24
- kodit/retreival/service.py,sha256=Iy9IBLhohQmypeOs0hDEjgr1hsr0xtaiMqjIzykFWrY,727
25
- kodit/sources/__init__.py,sha256=1NTZyPdjThVQpZO1Mp1ColVsS7sqYanOVLqnoqV9Ipo,83
26
- kodit/sources/models.py,sha256=xb42CaNDO1CUB8SIW-xXMrB6Ji8cFw-yeJ550xBEg9Q,2398
27
- kodit/sources/repository.py,sha256=mGJrHWH6Uo8YABdoojHFbzaf_jW-2ywJpAHIa1gnc3U,3401
28
- kodit/sources/service.py,sha256=khrz3UH6hNTYwXMFosGc46trcb8Sm0dTPwvptbgRgwM,6722
29
- kodit-0.1.4.dist-info/METADATA,sha256=QOoPAs68hrp4m_RYvCamYIrznlMIl79faJeq2Rzn-zw,2019
30
- kodit-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
31
- kodit-0.1.4.dist-info/entry_points.txt,sha256=hoTn-1aKyTItjnY91fnO-rV5uaWQLQ-Vi7V5et2IbHY,40
32
- kodit-0.1.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
33
- kodit-0.1.4.dist-info/RECORD,,
File without changes