delphi-code 0.1.0__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.
@@ -0,0 +1,22 @@
1
+ import os
2
+ import sys
3
+
4
+ for name in (
5
+ "COCOINDEX_DISABLE_USAGE_TRACKING", "HF_HUB_OFFLINE", "TRANSFORMERS_OFFLINE",
6
+ "HF_DATASETS_OFFLINE", "HF_HUB_DISABLE_TELEMETRY", "DO_NOT_TRACK",
7
+ "HF_HUB_DISABLE_PROGRESS_BARS",
8
+ ):
9
+ os.environ[name] = "1"
10
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
11
+ os.environ["COCOINDEX_MAX_INFLIGHT_COMPONENTS"] = "1"
12
+
13
+
14
+ def _deny_network(event, args):
15
+ if event in {"socket.getaddrinfo", "socket.gethostbyname", "socket.gethostbyaddr"}:
16
+ raise RuntimeError("Offline policy blocked a DNS lookup")
17
+ if event in {"socket.connect", "socket.connect_ex", "socket.bind", "socket.sendto"}:
18
+ if getattr(args[0], "family", None) in (2, 10, 30):
19
+ raise RuntimeError("Offline policy blocked an Internet socket operation")
20
+
21
+
22
+ sys.addaudithook(_deny_network)
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ main()
delphi_code/cli.py ADDED
@@ -0,0 +1,282 @@
1
+ import argparse
2
+ import asyncio
3
+ from contextlib import contextmanager, redirect_stdout
4
+ import fcntl
5
+ import hashlib
6
+ from importlib.metadata import version
7
+ import json
8
+ import os
9
+ from pathlib import Path
10
+ import shlex
11
+ import sqlite3
12
+ import sys
13
+ import tempfile
14
+ from datetime import datetime, timezone
15
+
16
+ from .model import Failure, embed, inspect_model, load_model
17
+ from .paths import index_root, model_directory
18
+
19
+
20
+ class Parser(argparse.ArgumentParser):
21
+ def error(self, message):
22
+ raise Failure("usage", message, 2)
23
+
24
+
25
+ def arguments():
26
+ parser = Parser(prog="delphi-code", description="Offline local code search")
27
+ commands = parser.add_subparsers(dest="command", required=True)
28
+ for name in ("index", "search", "status", "doctor"):
29
+ command = commands.add_parser(name)
30
+ command.add_argument("--project", "-p", default=None if name == "search" else str(Path.cwd()), help="Project path or indexed name; search defaults to all indexes")
31
+ if name != "status":
32
+ command.add_argument("--model", default=os.environ.get("DELPHI_CODE_MODEL") or model_directory())
33
+ if name in {"index", "search"}:
34
+ command.add_argument("--path", action="append", default=[], help="Project-relative glob; repeat for alternatives")
35
+ command.add_argument("--language", action="append", default=[])
36
+ if name == "index":
37
+ command.add_argument("--ignore", action="append", default=[])
38
+ command.add_argument("--max-bytes", type=int, default=1_048_576)
39
+ if name == "search":
40
+ command.add_argument("query")
41
+ command.add_argument("--limit", type=int, default=10)
42
+ setup = commands.add_parser("setup", help="Download or import the pinned model and check the installation")
43
+ setup.add_argument("--from", dest="source", help="Import a prepared MiniLM model without network access")
44
+ setup.add_argument("--model", default=os.environ.get("DELPHI_CODE_MODEL") or model_directory(), help="Model destination")
45
+ return parser.parse_args()
46
+
47
+
48
+ def index_directory(project):
49
+ identity = hashlib.sha256(os.fsencode(project.resolve())).hexdigest()
50
+ return index_root() / identity
51
+
52
+
53
+ def resolve_project(value):
54
+ raw = str(value)
55
+ if raw not in {".", ".."} and "/" not in raw and not raw.startswith("~"):
56
+ matches = set()
57
+ for manifest in index_root().glob("*/manifest.json"):
58
+ try:
59
+ info = json.loads(manifest.read_text())
60
+ except (OSError, ValueError):
61
+ continue
62
+ if not isinstance(info, dict) or not isinstance(info.get("project"), str):
63
+ continue
64
+ project = Path(info["project"])
65
+ if project.is_absolute() and project.name == raw and index_directory(project) == manifest.parent:
66
+ matches.add(project.resolve())
67
+ if len(matches) > 1:
68
+ choices = ", ".join(str(path) for path in sorted(matches))
69
+ raise Failure("project_ambiguous", f"Multiple indexed projects named {raw}: {choices}. Use an explicit path.", 2)
70
+ if matches:
71
+ return matches.pop()
72
+ return Path(value).expanduser().resolve()
73
+
74
+
75
+ @contextmanager
76
+ def database(path):
77
+ import sqlite_vec
78
+
79
+ db = sqlite3.connect(path.as_uri() + "?mode=ro", uri=True)
80
+ try:
81
+ db.enable_load_extension(True)
82
+ sqlite_vec.load(db)
83
+ db.enable_load_extension(False)
84
+ db.row_factory = sqlite3.Row
85
+ yield db
86
+ finally:
87
+ db.close()
88
+
89
+
90
+ @contextmanager
91
+ def locked(state, exclusive):
92
+ if exclusive:
93
+ state.mkdir(parents=True, exist_ok=True)
94
+ if not state.is_dir():
95
+ raise Failure("index_missing", "No index exists; run index first", 4)
96
+ try:
97
+ with (state / "lock").open("a" if exclusive else "r") as lock:
98
+ try:
99
+ fcntl.flock(lock, (fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH) | fcntl.LOCK_NB)
100
+ except BlockingIOError as exc:
101
+ raise Failure("index_busy", "Another command is updating this project", 5) from exc
102
+ yield
103
+ except FileNotFoundError as exc:
104
+ raise Failure("index_missing", "No index exists; run index first", 4) from exc
105
+
106
+
107
+ def metadata(state):
108
+ if not (state / "manifest.json").is_file():
109
+ raise Failure("index_missing", "No completed index exists; run index first", 4)
110
+ result = json.loads((state / "manifest.json").read_text())
111
+ if result.get("schema_version") != 1:
112
+ raise Failure("index_incompatible", "Unsupported index version", 4)
113
+ return result
114
+
115
+
116
+ def write_metadata(state, data):
117
+ temporary = state / "manifest.tmp"
118
+ temporary.write_text(json.dumps(data, sort_keys=True) + "\n")
119
+ temporary.replace(state / "manifest.json")
120
+
121
+
122
+ def counts(state):
123
+ with database(state / "vectors.sqlite") as db:
124
+ row = db.execute("SELECT count(*) AS chunks, count(DISTINCT path) AS files FROM passages").fetchone()
125
+ return dict(row)
126
+
127
+
128
+ def execute(args):
129
+ if args.command == "setup":
130
+ from .setup import provision
131
+
132
+ return provision(args)
133
+ if args.command == "search" and (not args.query.strip() or not 1 <= args.limit <= 1000):
134
+ raise Failure("usage", "Query must be nonempty and --limit must be between 1 and 1000", 2)
135
+ if args.command == "search" and args.project is None:
136
+ return search_all(args)
137
+ project = resolve_project(args.project)
138
+ if not project.is_dir():
139
+ raise Failure("project_missing", f"Project directory does not exist: {project}", 2)
140
+ state = index_directory(project)
141
+ if args.command in {"search", "status"} and not state.is_dir():
142
+ raise Failure("index_missing", f"No index exists; run delphi-code index -p {shlex.quote(str(project))}", 4)
143
+ if args.command == "status":
144
+ with locked(state, False):
145
+ info = metadata(state)
146
+ return {"project": str(project), "index_directory": str(state), **info, **(counts(state) if info["ready"] else {})}
147
+ if args.command == "index" and args.max_bytes < 1:
148
+ raise Failure("usage", "--max-bytes must be positive", 2)
149
+ model_path, identity = inspect_model(args.model)
150
+ if not hasattr(sqlite3.Connection, "enable_load_extension"):
151
+ raise Failure("sqlite_extensions_unavailable", "This Python disables SQLite extension loading; provision a Python build with loadable SQLite extensions", 3)
152
+ if args.command == "doctor":
153
+ import cocoindex
154
+ import sqlite_vec
155
+
156
+ from .indexing import check_storage
157
+
158
+ with tempfile.TemporaryDirectory(prefix="delphi-code-doctor-") as scratch:
159
+ asyncio.run(check_storage(Path(scratch)))
160
+ model = load_model(model_path)
161
+ vector = embed(model, ["local code search"])[0]
162
+ db = sqlite3.connect(":memory:")
163
+ try:
164
+ db.enable_load_extension(True)
165
+ sqlite_vec.load(db)
166
+ db.enable_load_extension(False)
167
+ distance = db.execute("SELECT vec_distance_L2(?, ?)", (vector.tobytes(), vector.tobytes())).fetchone()[0]
168
+ finally:
169
+ db.close()
170
+ return {
171
+ "project": str(project), "index_directory": str(state), "model": str(model_path), "model_sha256": identity,
172
+ "dimensions": len(vector), "self_distance": distance, "device": "cpu",
173
+ "cocoindex_storage": "ok", "offline": True, "network_guard": "python_audit", "sqlite": sqlite3.sqlite_version,
174
+ "dependencies": {name: version(name) for name in ("cocoindex", "sqlite-vec", "sentence-transformers", "torch")},
175
+ }
176
+ with locked(state, args.command == "index"):
177
+ previous = metadata(state) if (state / "manifest.json").exists() else None
178
+ if previous and previous["model_sha256"] != identity:
179
+ raise Failure("model_mismatch", f"Model assets differ from the index; restore the original model or move {state} aside and reindex", 4)
180
+ if args.command == "index":
181
+ from .files import collect
182
+ from .indexing import run
183
+
184
+ model = load_model(model_path)
185
+ sources, skipped = collect(project, args.path, args.language, args.ignore, model_path, args.max_bytes)
186
+ info = {
187
+ "schema_version": 1, "project": str(project), "ready": False, "model": str(model_path), "model_sha256": identity,
188
+ "paths": args.path, "languages": args.language, "ignores": args.ignore,
189
+ "max_bytes": args.max_bytes,
190
+ }
191
+ write_metadata(state, info)
192
+ stats = asyncio.run(run(state, sources, model, identity))
193
+ info.update(ready=True, indexed_at=datetime.now(timezone.utc).isoformat())
194
+ total = counts(state)
195
+ write_metadata(state, info)
196
+ return {"project": str(project), "index_directory": str(state), **total, "skipped": skipped, "incremental": stats}
197
+ if previous is None:
198
+ raise Failure("index_missing", "Run index first", 4)
199
+ if not previous["ready"]:
200
+ raise Failure("index_incomplete", "Last index did not complete; run index again before searching", 4)
201
+ model = load_model(model_path)
202
+ vector = embed(model, [args.query])[0].tobytes()
203
+ return {"project": str(project), "index_directory": str(state), "query": args.query,
204
+ "results": search_rows(state, args, vector)}
205
+
206
+
207
+ def search_rows(state, args, vector):
208
+ conditions, parameters = [], [vector]
209
+ if args.language:
210
+ conditions.append("language IN (" + ",".join("?" for _ in args.language) + ")")
211
+ parameters.extend(args.language)
212
+ if args.path:
213
+ conditions.append("(" + " OR ".join("path_matches(path, ?)" for _ in args.path) + ")")
214
+ parameters.extend(args.path)
215
+ where = " WHERE " + " AND ".join(conditions) if conditions else ""
216
+ with database(state / "vectors.sqlite") as db:
217
+ import fnmatch
218
+
219
+ db.create_function("path_matches", 2, fnmatch.fnmatchcase, deterministic=True)
220
+ rows = db.execute(
221
+ "SELECT path, language, text, start_line, end_line, vec_distance_L2(vector, ?) AS distance "
222
+ "FROM passages" + where + " ORDER BY distance, path, start_line, id LIMIT ?",
223
+ [*parameters, args.limit],
224
+ ).fetchall()
225
+ return [
226
+ {**dict(row), "score": max(-1.0, min(1.0, 1.0 - row["distance"] ** 2 / 2.0))} for row in rows
227
+ ]
228
+
229
+
230
+ def search_all(args):
231
+ states = sorted(path for path in index_root().glob("*") if path.is_dir())
232
+ if not states:
233
+ raise Failure("index_missing", "No indexes exist; run delphi-code index -p /absolute/path/to/project first", 4)
234
+ model_path, identity = inspect_model(args.model)
235
+ if not hasattr(sqlite3.Connection, "enable_load_extension"):
236
+ raise Failure("sqlite_extensions_unavailable", "This Python disables SQLite extension loading; provision a Python build with loadable SQLite extensions", 3)
237
+ model = load_model(model_path)
238
+ vector = embed(model, [args.query])[0].tobytes()
239
+ results, projects = [], []
240
+ for state in states:
241
+ try:
242
+ with locked(state, False):
243
+ info = metadata(state)
244
+ project = Path(info.get("project", ""))
245
+ if not project.is_absolute() or index_directory(project) != state:
246
+ raise Failure("index_incompatible", "Index has no valid project identity", 4)
247
+ if not info.get("ready"):
248
+ raise Failure("index_incomplete", "Last index did not complete; run index again", 4)
249
+ if info.get("model_sha256") != identity:
250
+ raise Failure("model_mismatch", "Index uses different model assets; select a compatible project with --project", 4)
251
+ results.extend({**row, "project": str(project)} for row in search_rows(state, args, vector))
252
+ projects.append(str(project))
253
+ except Failure as exc:
254
+ raise Failure(exc.code, f"{state}: {exc}", exc.exit_code) from exc
255
+ results.sort(key=lambda row: (row["distance"], row["project"], row["path"], row["start_line"], row["end_line"], row["text"]))
256
+ return {"project": None, "projects": sorted(projects), "query": args.query, "results": results[:args.limit]}
257
+
258
+
259
+ def main():
260
+ command = None
261
+ exit_code = 0
262
+ try:
263
+ args = arguments()
264
+ command = args.command
265
+ with redirect_stdout(sys.stderr):
266
+ result = execute(args)
267
+ payload = {"schema_version": 1, "ok": True, "command": command, "data": result}
268
+ except Exception as exc:
269
+ if os.environ.get("DELPHI_CODE_DEBUG") == "1":
270
+ import traceback
271
+
272
+ traceback.print_exc(file=sys.stderr)
273
+ failure = exc if isinstance(exc, Failure) else Failure(
274
+ "dependency_missing" if isinstance(exc, ModuleNotFoundError) else "runtime_error",
275
+ str(exc), 3 if isinstance(exc, ModuleNotFoundError) else 5,
276
+ )
277
+ exit_code = failure.exit_code
278
+ print(f"delphi-code: {failure}", file=sys.stderr)
279
+ payload = {"schema_version": 1, "ok": False, "command": command,
280
+ "error": {"code": failure.code, "message": str(failure)}}
281
+ print(json.dumps(payload, ensure_ascii=False, sort_keys=True, allow_nan=False))
282
+ raise SystemExit(exit_code)
@@ -0,0 +1,26 @@
1
+ import json
2
+ from pathlib import Path
3
+ import ssl
4
+ import sys
5
+ from urllib.request import urlopen
6
+
7
+
8
+ def main():
9
+ from huggingface_hub import snapshot_download
10
+
11
+ manifest = json.loads(Path(__file__).with_name("model_provenance.json").read_text())
12
+ destination = Path(sys.argv[1])
13
+ snapshot_download(
14
+ manifest["repository"], revision=manifest["revision"], local_dir=destination,
15
+ allow_patterns=list(manifest["sha256"]),
16
+ )
17
+ if not (destination / "LICENSE").exists():
18
+ import certifi
19
+
20
+ context = ssl.create_default_context(cafile=certifi.where())
21
+ with urlopen("https://www.apache.org/licenses/LICENSE-2.0.txt", timeout=60, context=context) as response:
22
+ (destination / "LICENSE").write_bytes(response.read())
23
+
24
+
25
+ if __name__ == "__main__":
26
+ main()
delphi_code/files.py ADDED
@@ -0,0 +1,64 @@
1
+ import fnmatch
2
+
3
+ from pathspec import GitIgnoreSpec
4
+
5
+ DEFAULT_EXCLUDES = {".git", ".delphi-code", ".venv", "venv", "node_modules", "__pycache__", ".models"}
6
+
7
+
8
+ def selected(path, language, paths, languages):
9
+ return (not paths or any(fnmatch.fnmatchcase(path, pattern) for pattern in paths)) and (
10
+ not languages or language in languages
11
+ )
12
+
13
+
14
+ def collect(root, paths, languages, ignores, model_root, max_bytes):
15
+ from cocoindex.ops.text import detect_code_language
16
+
17
+ found = {}
18
+ skipped = 0
19
+ extra = GitIgnoreSpec.from_lines(ignores)
20
+
21
+ def walk(directory, inherited):
22
+ nonlocal skipped
23
+ rules = list(inherited)
24
+ for name in (".gitignore", ".delphi-codeignore"):
25
+ rule_file = directory / name
26
+ if rule_file.is_file() and not rule_file.is_symlink():
27
+ rules.append((directory, GitIgnoreSpec.from_lines(rule_file.read_text().splitlines())))
28
+ for entry in sorted(directory.iterdir()):
29
+ relative = entry.relative_to(root).as_posix()
30
+ if entry.is_symlink():
31
+ skipped += 1
32
+ continue
33
+ is_dir = entry.is_dir()
34
+ if entry.name in DEFAULT_EXCLUDES or entry == model_root:
35
+ skipped += 1
36
+ continue
37
+ ignored = False
38
+ for base, spec in rules:
39
+ match = spec.check_file(entry.relative_to(base).as_posix() + ("/" if is_dir else ""))
40
+ if match.include is not None:
41
+ ignored = match.include
42
+ if ignored or extra.match_file(relative + ("/" if is_dir else "")):
43
+ skipped += 1
44
+ continue
45
+ if is_dir:
46
+ walk(entry, rules)
47
+ elif entry.is_file():
48
+ language = detect_code_language(filename=entry.name) or "text"
49
+ if not selected(relative, language, paths, languages):
50
+ continue
51
+ with entry.open("rb") as stream:
52
+ data = stream.read(max_bytes + 1)
53
+ if len(data) > max_bytes or b"\0" in data:
54
+ skipped += 1
55
+ continue
56
+ try:
57
+ content = data.decode("utf-8")
58
+ except UnicodeDecodeError:
59
+ skipped += 1
60
+ continue
61
+ if content.strip():
62
+ found[relative] = (relative, language, content)
63
+ walk(root, [])
64
+ return found, skipped
@@ -0,0 +1,78 @@
1
+ from dataclasses import dataclass
2
+
3
+ import cocoindex as coco
4
+ import numpy as np
5
+ from numpy.typing import NDArray
6
+ from cocoindex.connectors import sqlite
7
+ from cocoindex.ops.text import RecursiveSplitter
8
+ from cocoindex.resources.id import IdGenerator
9
+ from cocoindex.resources.schema import VectorSchema
10
+
11
+ from .model import Failure, embed
12
+
13
+ MODEL = coco.ContextKey("local_model")
14
+ DATABASE = coco.ContextKey("vector_database")
15
+
16
+
17
+ @dataclass
18
+ class Passage:
19
+ id: int
20
+ path: str
21
+ language: str
22
+ text: str
23
+ start_line: int
24
+ end_line: int
25
+ vector: NDArray[np.float32]
26
+
27
+
28
+ @coco.fn(memo=True)
29
+ async def ingest(source: tuple[str, str, str], target: sqlite.TableTarget[Passage], identity: str):
30
+ path, language, text = source
31
+ pieces = RecursiveSplitter().split(text, chunk_size=900, min_chunk_size=180, chunk_overlap=100, language=language)
32
+ vectors = embed(coco.use_context(MODEL), [piece.text for piece in pieces])
33
+ ids = IdGenerator()
34
+ for piece, vector in zip(pieces, vectors):
35
+ end_line = piece.end.line - (1 if piece.end.column == 1 and piece.end.line > piece.start.line else 0)
36
+ target.declare_row(row=Passage(
37
+ await ids.next_id((piece.start.char_offset, piece.text)), path, language,
38
+ piece.text, piece.start.line, end_line, vector,
39
+ ))
40
+
41
+
42
+ @coco.fn
43
+ async def build(sources: dict[str, tuple[str, str, str]], identity: str, dimensions: int):
44
+ schema = await sqlite.TableSchema.from_class(
45
+ Passage, primary_key=["id"], column_overrides={"vector": VectorSchema(np.dtype("float32"), dimensions)},
46
+ )
47
+ target = await sqlite.mount_table_target(
48
+ db=DATABASE, table_name="passages", table_schema=schema,
49
+ virtual_table_def=sqlite.Vec0TableDef(auxiliary_columns=["path", "language", "text", "start_line", "end_line"]),
50
+ )
51
+ await coco.mount_each(ingest, sources.items(), target, identity)
52
+
53
+
54
+ async def run(state, sources, model, identity):
55
+ provider = coco.ContextProvider()
56
+ provider.provide(MODEL, model)
57
+ connection = sqlite.connect(state / "vectors.sqlite", load_vec=True)
58
+ provider.provide(DATABASE, connection)
59
+ environment = storage_environment(state, provider)
60
+ app = coco.App(coco.AppConfig(name="delphi-code", environment=environment), build, sources, identity, model.get_embedding_dimension())
61
+ handle = app.update()
62
+ await handle
63
+ stats = handle.stats()
64
+ group = stats.by_component.get("ingest") if stats else None
65
+ return dict(group._asdict()) if group else {}
66
+
67
+
68
+ def storage_environment(state, provider=None):
69
+ try:
70
+ return coco.Environment(coco.Settings(db_path=state / "incremental"), context_provider=provider)
71
+ except RuntimeError as exc:
72
+ if "Operation not permitted" in str(exc):
73
+ raise Failure("sandbox_storage_denied", "Sandbox denied CocoIndex storage initialization; use a sandbox allowing its native storage operations while keeping network access denied", 3) from exc
74
+ raise
75
+
76
+
77
+ async def check_storage(state):
78
+ storage_environment(state)
delphi_code/model.py ADDED
@@ -0,0 +1,64 @@
1
+ import hashlib
2
+ import json
3
+ import shlex
4
+ from pathlib import Path
5
+
6
+
7
+ class Failure(Exception):
8
+ def __init__(self, code, message, exit_code=3):
9
+ super().__init__(message)
10
+ self.code = code
11
+ self.exit_code = exit_code
12
+
13
+
14
+ def inspect_model(value):
15
+ if not value:
16
+ raise Failure("model_missing", "Supply --model /absolute/local/model or DELPHI_CODE_MODEL")
17
+ root = Path(value).expanduser().resolve()
18
+ if not root.is_dir() or not (root / "modules.json").is_file():
19
+ raise Failure("model_missing", f"Local SentenceTransformers assets missing: {root}. Run delphi-code setup --model {shlex.quote(str(root))}, or set --model /local/model or DELPHI_CODE_MODEL to prepared assets; downloads are never automatic.")
20
+ modules = json.loads((root / "modules.json").read_text())
21
+ allowed = {"sentence_transformers.models.Transformer", "sentence_transformers.models.Pooling", "sentence_transformers.models.Normalize", "sentence_transformers.models.Dense"}
22
+ if not isinstance(modules, list) or not modules:
23
+ raise Failure("model_invalid", "modules.json must contain a nonempty module list")
24
+ for module in modules:
25
+ if module.get("type") not in allowed:
26
+ raise Failure("model_invalid", f"Unsupported model module: {module.get('type')}")
27
+ folder = (root / module.get("path", "")).resolve()
28
+ if not folder.is_relative_to(root) or (not folder.is_dir() and module["type"] != "sentence_transformers.models.Normalize"):
29
+ raise Failure("model_missing", "A model module directory is missing or outside the model")
30
+ if not list(root.rglob("*.safetensors")):
31
+ raise Failure("model_missing", "Model requires local safetensors weights; pickle weights are unsupported")
32
+ digest = hashlib.sha256()
33
+ for path in sorted(root.rglob("*")):
34
+ relative = path.relative_to(root)
35
+ if ".cache" in relative.parts or path.name in {"README.md", "LICENSE", "provenance.json"}:
36
+ continue
37
+ if path.is_file():
38
+ digest.update(relative.as_posix().encode() + b"\0")
39
+ with path.open("rb") as stream:
40
+ for block in iter(lambda: stream.read(1024 * 1024), b""):
41
+ digest.update(block)
42
+ return root, digest.hexdigest()
43
+
44
+
45
+ def load_model(root):
46
+ from sentence_transformers import SentenceTransformer
47
+
48
+ try:
49
+ return SentenceTransformer(
50
+ str(root), device="cpu", local_files_only=True, trust_remote_code=False,
51
+ model_kwargs={"use_safetensors": True, "local_files_only": True},
52
+ )
53
+ except Exception as exc:
54
+ raise Failure("model_invalid", f"Cannot load local model assets at {root}: {exc}") from exc
55
+
56
+
57
+ def embed(model, texts):
58
+ import numpy as np
59
+
60
+ result = model.encode(texts, normalize_embeddings=True, show_progress_bar=False, convert_to_numpy=True)
61
+ result = np.asarray(result, dtype=np.float32)
62
+ if not np.isfinite(result).all() or (np.linalg.norm(result, axis=-1) == 0).any():
63
+ raise Failure("embedding_invalid", "Model produced invalid or zero embeddings")
64
+ return result
@@ -0,0 +1,20 @@
1
+ {
2
+ "repository": "sentence-transformers/all-MiniLM-L6-v2",
3
+ "revision": "1110a243fdf4706b3f48f1d95db1a4f5529b4d41",
4
+ "license": "Apache-2.0",
5
+ "sha256": {
6
+ "1_Pooling/config.json": "4be450dde3b0273bb9787637cfbd28fe04a7ba6ab9d36ac48e92b11e350ffc23",
7
+ "README.md": "dcd602d2fd35c203a247304a06fec6654a12f7941b739f9221a064fe8dc3b7f0",
8
+ "config.json": "953f9c0d463486b10a6871cc2fd59f223b2c70184f49815e7efbcab5d8908b41",
9
+ "config_sentence_transformers.json": "061ca9d39661d6c6d6de5ba27f79a1cd5770ea247f8d46412a68a498dc5ac9f3",
10
+ "data_config.json": "32edcb108fc2516b920734a862ae0692bcae1c5d45d5f8d972cb0d53434a4c54",
11
+ "model.safetensors": "53aa51172d142c89d9012cce15ae4d6cc0ca6895895114379cacb4fab128d9db",
12
+ "modules.json": "84e40c8e006c9b1d6c122e02cba9b02458120b5fb0c87b746c41e0207cf642cf",
13
+ "sentence_bert_config.json": "fc1993fde0a95c24ec6c022539d41cf6e2f7c9721e5415d6fb6897472a9cd4b7",
14
+ "special_tokens_map.json": "303df45a03609e4ead04bc3dc1536d0ab19b5358db685b6f3da123d05ec200e3",
15
+ "tokenizer.json": "be50c3628f2bf5bb5e3a7f17b1f74611b2561a3a27eeab05e5aa30f411572037",
16
+ "tokenizer_config.json": "acb92769e8195aabd29b7b2137a9e6d6e25c476a4f15aa4355c233426c61576b",
17
+ "vocab.txt": "07eced375cec144d27c900241f3e339478dec958f92fddbc551f295c992038a3",
18
+ "LICENSE": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"
19
+ }
20
+ }
delphi_code/paths.py ADDED
@@ -0,0 +1,18 @@
1
+ import os
2
+ from pathlib import Path
3
+ import sys
4
+
5
+
6
+ def data_directory():
7
+ if sys.platform == "darwin":
8
+ return Path.home() / "Library/Application Support/delphi-code"
9
+ return Path(os.environ.get("XDG_DATA_HOME") or Path.home() / ".local/share").expanduser().resolve() / "delphi-code"
10
+
11
+
12
+ def model_directory():
13
+ return data_directory() / "models/all-MiniLM-L6-v2"
14
+
15
+
16
+ def index_root():
17
+ return Path(os.environ.get("DELPHI_CODE_INDEX_ROOT") or data_directory() / "indexes").expanduser().resolve()
18
+
delphi_code/setup.py ADDED
@@ -0,0 +1,93 @@
1
+ import argparse
2
+ import fcntl
3
+ import hashlib
4
+ import json
5
+ import os
6
+ from pathlib import Path
7
+ import shlex
8
+ import shutil
9
+ import subprocess
10
+ import sys
11
+ import tempfile
12
+
13
+ from .model import Failure
14
+ from .paths import index_root
15
+
16
+
17
+ def verify_assets(root):
18
+ manifest = json.loads(Path(__file__).with_name("model_provenance.json").read_text())
19
+ for name, expected in manifest["sha256"].items():
20
+ path = root / name
21
+ if not path.is_file() or path.is_symlink():
22
+ raise Failure("model_invalid", f"Missing or linked model asset: {path}")
23
+ with path.open("rb") as stream:
24
+ actual = hashlib.file_digest(stream, "sha256").hexdigest()
25
+ if actual != expected:
26
+ raise Failure("model_invalid", f"Model asset checksum mismatch: {path}")
27
+ allowed = set(manifest["sha256"]) | {"provenance.json"}
28
+ for path in root.rglob("*"):
29
+ if ".cache" not in path.relative_to(root).parts and path.is_file() and path.relative_to(root).as_posix() not in allowed:
30
+ raise Failure("model_invalid", f"Unexpected model asset: {path}")
31
+ return manifest
32
+
33
+
34
+ def download(destination):
35
+ offline_flags = {"HF_HUB_OFFLINE", "TRANSFORMERS_OFFLINE", "HF_DATASETS_OFFLINE"}
36
+ env = {name: value for name, value in os.environ.items() if name not in offline_flags}
37
+ result = subprocess.run(
38
+ [sys.executable, str(Path(__file__).with_name("download.py")), str(destination)],
39
+ env=env, stdout=sys.stderr, stderr=sys.stderr,
40
+ )
41
+ if result.returncode:
42
+ raise Failure("setup_download_failed", "Model download failed; check connectivity and rerun delphi-code setup, or use delphi-code setup --from /path/to/model", 3)
43
+
44
+
45
+ def diagnose(model):
46
+ from .cli import execute
47
+
48
+ root = index_root()
49
+ root.mkdir(parents=True, exist_ok=True)
50
+ with tempfile.TemporaryFile(dir=root):
51
+ pass
52
+ with tempfile.TemporaryDirectory(prefix=".setup-probe-", dir=root.parent) as scratch:
53
+ from .indexing import check_storage
54
+ import asyncio
55
+
56
+ asyncio.run(check_storage(Path(scratch)))
57
+ return execute(argparse.Namespace(command="doctor", project=str(Path.cwd()), model=str(model)))
58
+
59
+
60
+ def provision(args):
61
+ destination = Path(args.model).expanduser().resolve()
62
+ source = Path(args.source).expanduser().resolve() if args.source else None
63
+ destination.parent.mkdir(parents=True, exist_ok=True)
64
+ with (destination.parent / f".{destination.name}.setup.lock").open("a") as lock:
65
+ try:
66
+ fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
67
+ except BlockingIOError as exc:
68
+ raise Failure("setup_busy", "Another setup is running for this model; retry when it finishes", 5) from exc
69
+ if destination.exists():
70
+ try:
71
+ verify_assets(destination)
72
+ except Failure as exc:
73
+ raise Failure(exc.code, f"{exc}. Existing assets were preserved. Move {destination} aside, then rerun delphi-code setup --model {shlex.quote(str(destination))}", 3) from exc
74
+ diagnostics = diagnose(destination)
75
+ reused = True
76
+ else:
77
+ with tempfile.TemporaryDirectory(prefix=f".{destination.name}-", dir=destination.parent) as temporary:
78
+ staged = Path(temporary) / "model"
79
+ if source:
80
+ verify_assets(source)
81
+ shutil.copytree(source, staged, ignore=shutil.ignore_patterns(".cache"))
82
+ else:
83
+ staged.mkdir()
84
+ print("Downloading the pinned MiniLM model…", file=sys.stderr)
85
+ download(staged)
86
+ manifest = verify_assets(staged)
87
+ (staged / "provenance.json").write_text(json.dumps(manifest, indent=2) + "\n")
88
+ diagnostics = diagnose(staged)
89
+ staged.rename(destination)
90
+ diagnostics["model"] = str(destination)
91
+ reused = False
92
+ return {"model": str(destination), "index_root": str(index_root()), "reused": reused,
93
+ "diagnostics": diagnostics}
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: delphi-code
3
+ Version: 0.1.0
4
+ Summary: Offline local code search for agents
5
+ Author: Mark Dorofeev
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/DorofeevMark/delphi-code
8
+ Project-URL: Issues, https://github.com/DorofeevMark/delphi-code/issues
9
+ Keywords: code-search,semantic-search,embeddings,offline,cli,agents
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: MacOS
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Software Development
17
+ Classifier: Topic :: Text Processing :: Indexing
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ License-File: THIRD_PARTY_NOTICES.md
22
+ Requires-Dist: cocoindex==1.0.24
23
+ Requires-Dist: sqlite-vec==0.1.9
24
+ Requires-Dist: sentence-transformers==6.1.0
25
+ Requires-Dist: numpy==2.5.3
26
+ Requires-Dist: pathspec==0.12.1
27
+ Requires-Dist: certifi
28
+ Dynamic: license-file
29
+
30
+ # Delphi Code
31
+
32
+ Offline semantic code search for agents. Delphi Code is a small Python CLI that indexes local source trees with a local embedding model and answers natural-language queries with JSON. It runs one command at a time, with no daemon, server, account, cloud embedding provider, or runtime downloads.
33
+
34
+ ## Quick start
35
+
36
+ ```sh
37
+ uv tool install --python 3.12 --managed-python delphi-code
38
+ delphi-code setup
39
+ delphi-code index -p /absolute/path/to/project
40
+ delphi-code search 'where are user passwords checked?'
41
+ ```
42
+
43
+ `setup` downloads and verifies the pinned embedding model once. After that, every command runs fully offline. Without `-p`, `search` looks through every indexed project.
44
+
45
+ ## Requirements
46
+
47
+ - macOS 14 or later on arm64 (the tested target). Linux has not yet been verified; Windows is not supported by the current file locking implementation.
48
+ - CPython 3.12 with SQLite loadable extensions. Some python.org macOS builds disable that feature; `--managed-python` makes uv use its own Python build, which supports it. `doctor` reports this explicitly.
49
+ - CPU inference; no GPU is needed.
50
+
51
+ ## Installation
52
+
53
+ From PyPI, as in the quick start:
54
+
55
+ ```sh
56
+ uv tool install --python 3.12 --managed-python delphi-code
57
+ delphi-code setup
58
+ ```
59
+
60
+ From a checkout, with uv:
61
+
62
+ ```sh
63
+ uv tool install --python 3.12 --managed-python /absolute/path/to/delphi-code
64
+ delphi-code setup
65
+ ```
66
+
67
+ From a checkout, with the pinned dependency versions and a Python 3.12 build that supports SQLite extensions:
68
+
69
+ ```sh
70
+ python3.12 -m venv .venv
71
+ .venv/bin/python -m pip install -r requirements-lock.txt
72
+ .venv/bin/python -m pip install --no-deps --no-build-isolation .
73
+ .venv/bin/delphi-code setup
74
+ ```
75
+
76
+ `requirements-lock.txt` records the tested macOS environment, not a cross-platform lock.
77
+
78
+ ### Model setup
79
+
80
+ `setup` downloads the pinned [all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) revision in a separate process. It validates every file against bundled SHA-256 hashes and runs local embedding, SQLite, and native-storage diagnostics before moving the model into place.
81
+
82
+ - Running `setup` again verifies and reuses valid assets.
83
+ - Concurrent setup for the same destination fails clearly.
84
+ - Failed downloads or diagnostics never leave a partial model behind; invalid existing models are preserved with recovery instructions.
85
+ - `setup --model /absolute/path` or `DELPHI_CODE_MODEL` selects a different destination.
86
+
87
+ For an offline installation, install dependencies from a wheelhouse prepared for the target platform, then import a complete prepared MiniLM directory, including its license and model card:
88
+
89
+ ```sh
90
+ delphi-code setup --from /absolute/path/to/all-MiniLM-L6-v2
91
+ ```
92
+
93
+ `setup` provisions the pinned MiniLM model only. Other models can be used at runtime through `--model` or `DELPHI_CODE_MODEL` (see Models below). `index`, `search`, `status`, and `doctor` never download anything.
94
+
95
+ ## Commands
96
+
97
+ ```sh
98
+ delphi-code doctor -p /path/to/project
99
+ delphi-code index -p /path/to/project
100
+ delphi-code search -p /path/to/project 'where are user passwords checked?'
101
+ delphi-code search -p /path/to/project 'parse configuration' --language python --path 'src/*' --limit 5
102
+ delphi-code status -p /path/to/project
103
+ ```
104
+
105
+ - **`index`** builds or incrementally updates a project's index.
106
+ - **`search`** runs a natural-language query. Without `-p`, it searches every stored index.
107
+ - **`status`** reports stored index state. It needs no model and does not rescan source files to detect staleness.
108
+ - **`doctor`** checks the model, SQLite extensions, and native storage, then runs a real local embedding and vector distance calculation.
109
+ - **`setup`** provisions the model (see above).
110
+
111
+ `python -m delphi_code` works as an alternative to the `delphi-code` executable.
112
+
113
+ ### Selecting a project
114
+
115
+ - `--project` / `-p` accepts a path, resolved relative to the current working directory. The project root is explicit; it is not inferred from Git.
116
+ - After a project has been indexed once, its folder name works too, for example `delphi-code search -p myapp 'parse config'`. A bare name selects the uniquely matching indexed project; duplicate names produce an error listing their paths. Use `./name` or an absolute path to select a directory explicitly.
117
+ - Without `--project`, `search` searches all stored indexes; other commands use the current directory.
118
+
119
+ ### Searching across projects
120
+
121
+ Cross-project search returns a single globally ranked list, with the full `project` path on each result. The query is embedded once, `--limit` applies to the combined list, and path/language filters apply within every index. All indexes must be readable, complete, and built with the selected model: a busy, broken, or incompatible index produces an error rather than silently partial results. Use `-p` to narrow the search when needed.
122
+
123
+ ## Output
124
+
125
+ Each command writes one JSON object to stdout with `schema_version`, `ok`, `command`, and either `data` or `error`. Progress and library diagnostics go to stderr; argument help is plain text.
126
+
127
+ ```json
128
+ {
129
+ "command": "search",
130
+ "ok": true,
131
+ "schema_version": 1,
132
+ "data": {
133
+ "project": "/Users/me/src/delphi-code",
134
+ "index_directory": "/Users/me/Library/Application Support/delphi-code/indexes/3a3565ee…",
135
+ "query": "where is the model checksum verified?",
136
+ "results": [
137
+ {
138
+ "path": "delphi_code/setup.py",
139
+ "language": "python",
140
+ "start_line": 17,
141
+ "end_line": 31,
142
+ "distance": 1.1042553186416626,
143
+ "score": 0.3903100956258001,
144
+ "text": "def verify_assets(root):\n manifest = json.loads(…"
145
+ }
146
+ ]
147
+ }
148
+ }
149
+ ```
150
+
151
+ Search results contain project-relative paths, language, inclusive 1-based line ranges, the original chunk text, Euclidean distance, and cosine similarity score. Lower distance and higher score mean closer matches; scores are not probabilities. Equal distances use stable path/line/id ordering.
152
+
153
+ | Exit code | Meaning |
154
+ |---|---|
155
+ | 0 | Success, including a search with no matches |
156
+ | 2 | Invalid arguments or project |
157
+ | 3 | Missing or incompatible model or runtime assets |
158
+ | 4 | Missing, incomplete, or incompatible index |
159
+ | 5 | Busy index or operational failure |
160
+
161
+ ## Indexing and filters
162
+
163
+ ### What gets indexed
164
+
165
+ - Nested `.gitignore` and `.delphi-codeignore` files apply with Git-style patterns and negation; an ignored parent directory is not traversed. `.delphi-codeignore` follows `.gitignore` within each directory.
166
+ - Repeated `--ignore` patterns add another exclusion layer.
167
+ - Git's global ignore file and `.git/info/exclude` are not read.
168
+ - Built-in exclusions: `.git`, `.delphi-code`, `.venv`, `venv`, `node_modules`, `__pycache__`, `.models`, and the selected model directory.
169
+ - Symlinks, binary or non-UTF-8 files, blank files, and files over `--max-bytes` (default 1 MiB) are skipped.
170
+ - Unknown languages are indexed as `text`.
171
+
172
+ ### Filters
173
+
174
+ Repeated `--path` globs are alternatives over project-relative POSIX paths (`*` can match `/`). Repeated `--language` values are alternatives using CocoIndex language names such as `python`, `rust`, and `typescript`. Path and language filters combine with AND.
175
+
176
+ - On `index`, filters define the entire indexed set for that run, and previously indexed files outside it are removed. Running `index` without filters returns to the full selection.
177
+ - On `search`, filters restrict results before ranking, so a matching result cannot be lost behind unfiltered top-k candidates.
178
+
179
+ ### Incremental updates
180
+
181
+ CocoIndex memoizes each file's content-dependent work and maintains the exported SQLite vec0 rows. Changed contents are detected even when timestamps are unchanged, and deleted or newly excluded files have their rows removed. Every candidate file is read on each `index` run, but unchanged files skip chunking and embedding. The selected file contents are held in memory during indexing.
182
+
183
+ ### Chunking and search
184
+
185
+ The code splitter targets 900-byte chunks with overlap. Embeddings are normalized SentenceTransformers outputs computed on the CPU, with the same model configuration for indexing and queries. The model's token limit can truncate long chunks.
186
+
187
+ Search is an exact sqlite-vec distance scan over the filtered rows, not an approximate-nearest-neighbor index. That keeps results exact and suits small codebases.
188
+
189
+ ## Models
190
+
191
+ The default model is MiniLM: a small, general-purpose model that keeps the tool fast and light, not one tuned for code retrieval. Any local SentenceTransformers model can be used through `--model /absolute/local/model` or `DELPHI_CODE_MODEL`, provided that it:
192
+
193
+ - uses only Transformer, Pooling, Normalize, and Dense modules;
194
+ - stores its weights as safetensors (pickle weights and custom model code are not supported);
195
+ - is trusted and stays unchanged while a command runs.
196
+
197
+ Models with asymmetric query/document instructions are not specially configured. Each index records a hash of the full model assets, so searching an index with different weights or configuration fails with a clear error instead of returning wrong results.
198
+
199
+ ## Storage
200
+
201
+ Models and indexes live outside the installation, so reinstalling or upgrading leaves them intact:
202
+
203
+ - macOS: `~/Library/Application Support/delphi-code/`
204
+ - Linux: `$XDG_DATA_HOME/delphi-code/`, or `~/.local/share/delphi-code/`
205
+
206
+ The default model is under `models/all-MiniLM-L6-v2/` and indexes are under `indexes/`. `DELPHI_CODE_INDEX_ROOT` overrides the index location.
207
+
208
+ Each project has one index at `indexes/<sha256 of the resolved project path>/`, independent of the working directory. It holds CocoIndex's incremental state, the SQLite vector table, and a manifest recording the project path; command output includes this `index_directory`.
209
+
210
+ - A file lock prevents reads during updates and concurrent writers.
211
+ - An interrupted or failed update leaves the index marked `ready: false`, and search refuses it until indexing succeeds. There is no fallback to a last good snapshot.
212
+ - Moving a project changes its index identity.
213
+ - To switch model assets or rebuild incompatible state, move that `index_directory` aside and run `index` again.
214
+
215
+ ## Offline guarantees
216
+
217
+ Before any third-party import, the CLI disables CocoIndex usage tracking and Hugging Face telemetry, and sets the Hub and Transformers offline flags. Models load only from an existing local directory with `local_files_only=True`, `trust_remote_code=False`, and safetensors weights.
218
+
219
+ A Python audit hook also rejects Internet socket operations and DNS lookups. This is defense in depth, not OS isolation: it does not cover native extensions. For an OS-level boundary on macOS, run commands under a sandbox that denies networking:
220
+
221
+ ```sh
222
+ /usr/bin/sandbox-exec -p '(version 1)(allow default)(deny network*)' \
223
+ delphi-code index -p /path/to/project
224
+ ```
225
+
226
+ Delphi Code needs read access to source and model files, write access to its user index directory, threads, SQLite extensions, and CocoIndex's LMDB memory maps. It needs no network access. Some stricter sandboxes deny CocoIndex's native storage initialization with `EPERM`; `doctor` probes for this and reports `sandbox_storage_denied`. The application never escalates its own permissions. `doctor` reports the Python guard only; it does not claim that an external OS sandbox is active.
227
+
228
+ ## Development
229
+
230
+ See [CONTRIBUTING.md](https://github.com/DorofeevMark/delphi-code/blob/main/CONTRIBUTING.md) for running the tests and publishing releases.
231
+
232
+ ## License
233
+
234
+ Apache-2.0. See [THIRD_PARTY_NOTICES.md](https://github.com/DorofeevMark/delphi-code/blob/main/THIRD_PARTY_NOTICES.md) for dependency and model provenance and redistribution notes. The package does not bundle dependencies or model weights; the model's asset hashes are recorded in [MODEL_PROVENANCE.json](https://github.com/DorofeevMark/delphi-code/blob/main/MODEL_PROVENANCE.json).
@@ -0,0 +1,17 @@
1
+ delphi_code/__init__.py,sha256=xrNnp0mxD69Wu1SSZqAF-psqnVlxI8MYGuEwhRWjKgo,813
2
+ delphi_code/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
+ delphi_code/cli.py,sha256=_SScVmVLqaGLdbFKwsvq5Dmdojuj_DeELWNSwK2yWqI,13259
4
+ delphi_code/download.py,sha256=ZE19wC8XvaT5NxzsY-_yrra7FVmvu7GJB5_Yg0zd2a8,809
5
+ delphi_code/files.py,sha256=qoHV3RgirI0OZsIDiND5h-nui6By26rDggtH9zX4RJg,2489
6
+ delphi_code/indexing.py,sha256=9KFpwt7cZNIp3aqfeNtMLDdXtR_V00bQA1MUDJsWdPA,3033
7
+ delphi_code/model.py,sha256=ydGkPRp2MFNoYuKl12fRe5IldEmiuCHm6jqpebD6Zug,3105
8
+ delphi_code/model_provenance.json,sha256=9fPASR9vJZXuKIdFWmc6Rc0A_I2OQnyOm6Ihytn9ab8,1370
9
+ delphi_code/paths.py,sha256=nfiu1bbljv7ZTjQmafH05g1WVnF1xDxuicpKK4mO8ug,509
10
+ delphi_code/setup.py,sha256=uNDufY0cCI4ywtyS1lZ-fHkSNOmeRJrR1RuvlABPJe8,4061
11
+ delphi_code-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ delphi_code-0.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md,sha256=7UBHSW7RAHFxx3BG1GtsQ7a_bb1Si9TG2JL4HFvz774,2302
13
+ delphi_code-0.1.0.dist-info/METADATA,sha256=j_yDdNdQ2ilTTL5_PQYW6jU3v29v_BDpllfEOjDIENo,12852
14
+ delphi_code-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
15
+ delphi_code-0.1.0.dist-info/entry_points.txt,sha256=2UhlG66g8QmTYZko1fdwaZ5ziVY75sBPZeeSLk0fdJo,53
16
+ delphi_code-0.1.0.dist-info/top_level.txt,sha256=duf6zGKXk5n7vYW2b6IKVKfvZwLbXwp3yTiuTt62l2M,12
17
+ delphi_code-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ delphi-code = delphi_code.cli:main
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,18 @@
1
+ # Third-party notices and provenance
2
+
3
+ Delphi Code's original application code uses the repository's Apache-2.0 license. It was implemented independently after inspecting a local reference implementation's behavior and library integration; no reference source, documentation, or branding is included. Its Python package declares dependencies but does not bundle their code, a Python interpreter, or model weights. Dependencies and models retain their own licenses and notices in their separately installed distributions.
4
+
5
+ ## Dependencies
6
+
7
+ The tested direct dependencies are CocoIndex 1.0.24 (Apache-2.0), sqlite-vec 0.1.9 (MIT or Apache-2.0), SentenceTransformers 6.1.0 (Apache-2.0), NumPy 2.5.3 (BSD and bundled component notices), and pathspec 0.12.1 (MPL-2.0). They were installed from PyPI without modification. Exact transitive dependency versions are recorded in `requirements-lock.txt`; this version freeze does not authenticate wheel contents.
8
+
9
+ For a release that bundles dependencies, collect their licenses and notices from the actual release environment with `scripts/collect_notices.py`. During online preparation, `scripts/prepare_notices.py` retrieves supplemental upstream license texts omitted from the tested wheels. Both write to `build/third_party/`. Review the collection against the release contents, include required native-library and interpreter notices, and meet applicable source-availability obligations. The generated collection is excluded from the application package and source repository.
10
+
11
+ ## Test model
12
+
13
+ - Repository: [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/tree/1110a243fdf4706b3f48f1d95db1a4f5529b4d41)
14
+ - Revision: `1110a243fdf4706b3f48f1d95db1a4f5529b4d41`
15
+ - Declared model license: Apache-2.0, as recorded in its upstream model card.
16
+ - Asset hashes: `MODEL_PROVENANCE.json`.
17
+
18
+ The provisioned model directory under `.models/` retains its upstream model card, Apache license text, and provenance manifest alongside the weights. The pinned repository has no separate LICENSE file, so `scripts/prepare_model.py` supplies the canonical Apache text alongside the model card's declaration. Preserve these records when distributing the model. Replacement models require their own provenance and license review.
@@ -0,0 +1 @@
1
+ delphi_code