auryn-c 0.8.1__tar.gz

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,56 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Test/coverage artifacts
13
+ .coverage
14
+ .pytest_cache/
15
+ *.db
16
+
17
+ # Embedded-graph working dir written by `auryn quickstart` (e.g. quickstart/.auryn/)
18
+ .auryn/
19
+
20
+ # .NET build output (roslyn-extractor tool + C# test fixtures)
21
+ bin/
22
+ obj/
23
+
24
+ # Demo sample repos are generated by their setup.py / run_demo.py
25
+ demo/csharp-git/sample-repo/
26
+
27
+
28
+ # Stray FalkorDB/Redis snapshot (regenerated at runtime; never upload)
29
+ dump.rdb
30
+ *.rdb
31
+
32
+ # Deploy bundles (build artifacts)
33
+ auryn-plsql-deploy.zip
34
+ auryn-deploy.zip
35
+
36
+ # Agent-benchmark run outputs (per-run JSON logs, captured claude-config, transcripts)
37
+ benchmarks/agent/results/
38
+ benchmarks/agent/results-swe/
39
+ benchmarks/agent/results-corpus/
40
+ benchmarks/agent/results-abcd-easy/
41
+ benchmarks/agent/results-abcd-hard/
42
+ benchmarks/hook/results/
43
+ benchmarks/results/
44
+
45
+ # macOS Finder metadata
46
+ .DS_Store
47
+
48
+ # Local operator docs (client/prospect restore & VM setup) — never publish
49
+ RESTORE-*.md
50
+ INSTALL-ON-*.md
51
+
52
+ # Private, non-public hooks / work kept out of the open-source release
53
+ private/
54
+
55
+ # WIP demo not part of the public launch (kept local)
56
+ demo/auryn-tour/
auryn_c-0.8.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FalkorDB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
auryn_c-0.8.1/PKG-INFO ADDED
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.5
2
+ Name: auryn-c
3
+ Version: 0.8.1
4
+ Summary: C language plugin for Auryn: fast tree-sitter-c engine (functions/structs/unions/enums/typedefs/globals/macros/#includes/calls, no build config). A deep libclang engine (resolved types, header<->.c linking, cross-TU calls) is the planned second phase.
5
+ Author-email: Roi Lipman <roi.lipman@falkordb.com>
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: auryn-core
10
+ Requires-Dist: tree-sitter-c>=0.23.0
11
+ Requires-Dist: tree-sitter>=0.26.0
@@ -0,0 +1,23 @@
1
+ [project]
2
+ name = "auryn-c"
3
+ version = "0.8.1"
4
+ description = "C language plugin for Auryn: fast tree-sitter-c engine (functions/structs/unions/enums/typedefs/globals/macros/#includes/calls, no build config). A deep libclang engine (resolved types, header<->.c linking, cross-TU calls) is the planned second phase."
5
+ authors = [{ name = "Roi Lipman", email = "roi.lipman@falkordb.com" }]
6
+ requires-python = ">=3.12"
7
+ license = { text = "MIT" }
8
+ dependencies = [
9
+ "auryn-core",
10
+ "tree-sitter>=0.26.0",
11
+ "tree-sitter-c>=0.23.0",
12
+ ]
13
+
14
+ # Import-light lazy GitLanguage (no tree-sitter import at discovery). See core/registry.py.
15
+ [project.entry-points."auryn.languages"]
16
+ c = "auryn.ingestors.c.plugin"
17
+
18
+ [build-system]
19
+ requires = ["hatchling"]
20
+ build-backend = "hatchling.build"
21
+
22
+ [tool.hatch.build.targets.wheel]
23
+ packages = ["src/auryn"]
@@ -0,0 +1,6 @@
1
+ """The C language family. Registration is import-light: the `auryn.languages` entry
2
+ point targets the tiny `plugin` module (suffixes + a lazy GitLanguage), so file-based
3
+ discovery never imports tree-sitter. Fast engine = tree-sitter-c (no build config); a deep
4
+ libclang engine (resolved types, header<->.c linking, cross-TU calls) is the planned second
5
+ phase and slots in as the GitLanguage's `deep_sync`.
6
+ """
@@ -0,0 +1,327 @@
1
+ """parse_file(path) -> RawFile: the parallelizable phase-1 unit (pure function, no shared
2
+ state -- safe under a ProcessPoolExecutor; only picklable raw_model dataclasses are
3
+ returned, no tree-sitter node crosses the boundary). parse_source(source, path_label) holds
4
+ the logic and takes raw bytes, so a git blob can be parsed without touching disk.
5
+
6
+ Every node type / field name below was confirmed empirically against tree-sitter-c 0.24.2
7
+ (see the package's grammar probe), not assumed: top-level `preproc_include` (field `path`),
8
+ `preproc_def`/`preproc_function_def` (`name`), `type_definition` (`declarator`,`type`),
9
+ `struct_specifier`/`union_specifier`/`enum_specifier` (`name`,`body`), `declaration`
10
+ (`declarator` -> function_declarator = prototype, else a variable), and `function_definition`
11
+ (`declarator`=function_declarator, `type`, `body`). Names sit at the bottom of possibly
12
+ pointer/array-wrapped declarators, so `_name_of` descends the `declarator` field to the leaf
13
+ `identifier`/`field_identifier`/`type_identifier`."""
14
+
15
+ from __future__ import annotations
16
+
17
+ from pathlib import Path
18
+
19
+ from auryn.core.docstrings import leading_comment
20
+ from auryn.ingestors.c.grammar import new_parser
21
+ from auryn.ingestors.c.raw_model import (
22
+ RawEnum,
23
+ RawField,
24
+ RawFile,
25
+ RawFunction,
26
+ RawGlobal,
27
+ RawInclude,
28
+ RawMacro,
29
+ RawParameter,
30
+ RawRecord,
31
+ RawTypedef,
32
+ )
33
+
34
+ _NAME_LEAVES = {"identifier", "field_identifier", "type_identifier"}
35
+ _RECORD_KINDS = {"struct_specifier": "struct", "union_specifier": "union"}
36
+ # Wrappers that hold ordinary top-level declarations as children rather than being
37
+ # declarations themselves -- header guards / feature #ifs and `extern "C"` blocks. We treat
38
+ # their children as if they sat at file scope (recursively, since they nest). Without this a
39
+ # guarded header (`#ifndef FOO_H ... #endif`, i.e. almost every real .h) yields nothing.
40
+ _TRANSPARENT = {
41
+ "preproc_ifdef", "preproc_if", "preproc_elif", "preproc_else", "preproc_elifdef",
42
+ "preproc_elifndef", "linkage_specification",
43
+ }
44
+
45
+
46
+ def _iter_decls(node):
47
+ """Yield declaration-level nodes under `node`, flattening preprocessor-conditional and
48
+ linkage wrappers so guarded declarations are seen at file scope."""
49
+ for child in node.children:
50
+ if child.type in _TRANSPARENT:
51
+ yield from _iter_decls(child)
52
+ else:
53
+ yield child
54
+
55
+
56
+ def parse_file(path: str) -> RawFile:
57
+ return parse_source(Path(path).read_bytes(), path)
58
+
59
+
60
+ def parse_source(source: bytes, path_label: str) -> RawFile:
61
+ tree = new_parser().parse(source)
62
+ rf = RawFile(path=path_label)
63
+
64
+ def txt(node) -> str:
65
+ return source[node.start_byte : node.end_byte].decode("utf-8", "replace") if node else ""
66
+
67
+ def lines(node) -> tuple[int, int]:
68
+ # tree-sitter points are 0-based (row, col); expose 1-based inclusive line numbers.
69
+ return node.start_point[0] + 1, node.end_point[0] + 1
70
+
71
+ def name_of(decl) -> str:
72
+ """Descend a (possibly pointer/array/function/init/parenthesized) declarator to the
73
+ leaf name identifier."""
74
+ node = decl
75
+ seen = 0
76
+ while node is not None and seen < 64:
77
+ if node.type in _NAME_LEAVES:
78
+ return txt(node)
79
+ inner = node.child_by_field_name("declarator")
80
+ if inner is None:
81
+ # abstract declarator (unnamed param) or an unexpected shape
82
+ return ""
83
+ node = inner
84
+ seen += 1
85
+ return ""
86
+
87
+ def name_node_of(decl):
88
+ """Like name_of, but returns the leaf name NODE (or None) so callers can excise it."""
89
+ node = decl
90
+ seen = 0
91
+ while node is not None and seen < 64:
92
+ if node.type in _NAME_LEAVES:
93
+ return node
94
+ node = node.child_by_field_name("declarator")
95
+ seen += 1
96
+ return None
97
+
98
+ def written_type(container, name_node) -> str:
99
+ """The type exactly as written for a parameter/field: the whole declaration text minus
100
+ the identifier being declared. This keeps `const`, `*`, `[]`, and qualifiers that live
101
+ in the declarator (not in the `type` field) -- e.g. `const Widget *w` -> `const Widget *`,
102
+ `int buf[10]` -> `int [10]`."""
103
+ a, b = container.start_byte, container.end_byte
104
+ if name_node is not None and a <= name_node.start_byte and name_node.end_byte <= b:
105
+ piece = source[a : name_node.start_byte] + source[name_node.end_byte : b]
106
+ else:
107
+ piece = source[a:b]
108
+ # A field_declaration container carries the trailing `;`; a bitfield carries `: width`.
109
+ text = " ".join(piece.decode("utf-8", "replace").split()).strip()
110
+ text = text.rstrip(";").strip()
111
+ if ":" in text: # bitfield: keep the type, drop the width spec
112
+ text = text.split(":", 1)[0].strip()
113
+ return text
114
+
115
+ def signature_of(node, top_declarator) -> str:
116
+ """The function header exactly as written -- everything from the start of the declaration
117
+ (storage class + return type) through the end of the parameter list `)`, with the body (if
118
+ any) excluded. `top_declarator` ends at the `)` for both prototypes and definitions."""
119
+ if top_declarator is None:
120
+ return ""
121
+ a, b = node.start_byte, top_declarator.end_byte
122
+ return " ".join(source[a:b].decode("utf-8", "replace").split()).strip()
123
+
124
+ def find_function_declarator(decl):
125
+ """A function's name lives in a function_declarator, itself possibly wrapped by a
126
+ pointer_declarator (`char *f(void)`). Descend `declarator` fields to find it."""
127
+ node = decl
128
+ seen = 0
129
+ while node is not None and seen < 64:
130
+ if node.type == "function_declarator":
131
+ return node
132
+ node = node.child_by_field_name("declarator")
133
+ seen += 1
134
+ return None
135
+
136
+ def is_static(node) -> bool:
137
+ return any(
138
+ c.type == "storage_class_specifier" and txt(c) == "static" for c in node.children
139
+ )
140
+
141
+ def type_text(type_node) -> str:
142
+ return " ".join(txt(type_node).split()) if type_node else ""
143
+
144
+ def type_ref(type_node) -> str | None:
145
+ """The bare tag/typedef name a type names, if any (for REFERENCES); None for
146
+ primitives like int/char."""
147
+ if type_node is None:
148
+ return None
149
+ if type_node.type in _RECORD_KINDS or type_node.type == "enum_specifier":
150
+ n = type_node.child_by_field_name("name")
151
+ return txt(n) if n else None
152
+ if type_node.type == "type_identifier":
153
+ return txt(type_node)
154
+ return None
155
+
156
+ def parameters(func_declarator) -> list[RawParameter]:
157
+ plist = func_declarator.child_by_field_name("parameters")
158
+ out: list[RawParameter] = []
159
+ if plist is None:
160
+ return out
161
+ pos = 0
162
+ for p in plist.children:
163
+ if p.type != "parameter_declaration":
164
+ continue # skips '(', ')', ',', and variadic '...'
165
+ d = p.child_by_field_name("declarator")
166
+ nnode = name_node_of(d) if d is not None else None
167
+ pname = txt(nnode) if nnode is not None else ""
168
+ t_written = written_type(p, nnode) # precise: keeps const/*/[]
169
+ if t_written == "void" and d is None:
170
+ continue # `(void)` is "no parameters", not one void parameter
171
+ out.append(RawParameter(name=pname, type=t_written, position=pos))
172
+ pos += 1
173
+ return out
174
+
175
+ def collect_calls(body) -> list[str]:
176
+ names: list[str] = []
177
+ stack = list(body.children)
178
+ while stack:
179
+ n = stack.pop()
180
+ if n.type == "call_expression":
181
+ fn = n.child_by_field_name("function")
182
+ if fn is not None and fn.type == "identifier":
183
+ names.append(txt(fn))
184
+ stack.extend(n.children)
185
+ # de-dup, preserve order
186
+ seen: set[str] = set()
187
+ return [x for x in names if not (x in seen or seen.add(x))]
188
+
189
+ def record_from_specifier(spec, outer=None) -> RawRecord | None:
190
+ name_node = spec.child_by_field_name("name")
191
+ body = spec.child_by_field_name("body")
192
+ if name_node is None:
193
+ return None # anonymous struct/union -- no stable identity, skip
194
+ ls, le = lines(spec)
195
+ # A leading comment sits above the top-level struct specifier, OR -- when the record is
196
+ # defined inline in a typedef/declaration -- above that wrapping node (`outer`).
197
+ doc = leading_comment(spec, source) or (leading_comment(outer, source) if outer is not None else "")
198
+ rec = RawRecord(kind=_RECORD_KINDS[spec.type], name=txt(name_node), is_definition=body is not None,
199
+ source=txt(spec), doc=doc, line_start=ls, line_end=le)
200
+ if body is not None:
201
+ for fd in body.children:
202
+ if fd.type != "field_declaration":
203
+ continue
204
+ ftype = fd.child_by_field_name("type")
205
+ fdecl = fd.child_by_field_name("declarator")
206
+ nnode = name_node_of(fdecl) if fdecl is not None else None
207
+ fname = txt(nnode) if nnode is not None else ""
208
+ if fname:
209
+ fls, fle = lines(fd)
210
+ rec.fields.append(RawField(name=fname, type=written_type(fd, nnode), # precise: keeps *, [], const
211
+ type_ref=type_ref(ftype), line_start=fls, line_end=fle))
212
+ return rec
213
+
214
+ def enum_from_specifier(spec, outer=None) -> RawEnum | None:
215
+ name_node = spec.child_by_field_name("name")
216
+ body = spec.child_by_field_name("body")
217
+ if name_node is None:
218
+ return None
219
+ ls, le = lines(spec)
220
+ doc = leading_comment(spec, source) or (leading_comment(outer, source) if outer is not None else "")
221
+ en = RawEnum(name=txt(name_node), is_definition=body is not None, source=txt(spec), doc=doc, line_start=ls, line_end=le)
222
+ if body is not None:
223
+ for e in body.children:
224
+ if e.type == "enumerator":
225
+ en.members.append(txt(e.child_by_field_name("name")))
226
+ return en
227
+
228
+ def emit_inline_type(type_node, outer=None) -> None:
229
+ """A struct/union/enum specifier used inline in a typedef/declaration can itself
230
+ carry a body -- that's a definition of the tag, emitted alongside. `outer` is the
231
+ wrapping type_definition/declaration, so a doc comment above it is picked up."""
232
+ if type_node is None:
233
+ return
234
+ if type_node.type in _RECORD_KINDS:
235
+ rec = record_from_specifier(type_node, outer)
236
+ if rec is not None and rec.is_definition:
237
+ rf.records.append(rec)
238
+ elif type_node.type == "enum_specifier":
239
+ en = enum_from_specifier(type_node, outer)
240
+ if en is not None and en.is_definition:
241
+ rf.enums.append(en)
242
+
243
+ for child in _iter_decls(tree.root_node):
244
+ kind = child.type
245
+ if kind == "preproc_include":
246
+ p = child.child_by_field_name("path")
247
+ if p is not None:
248
+ is_system = p.type == "system_lib_string"
249
+ rf.includes.append(RawInclude(path=txt(p).strip('<>"'), is_system=is_system))
250
+ elif kind == "preproc_def":
251
+ ls, le = lines(child)
252
+ rf.macros.append(RawMacro(name=txt(child.child_by_field_name("name")), is_function_like=False,
253
+ source=txt(child).rstrip(), line_start=ls, line_end=le))
254
+ elif kind == "preproc_function_def":
255
+ ls, le = lines(child)
256
+ rf.macros.append(RawMacro(name=txt(child.child_by_field_name("name")), is_function_like=True,
257
+ source=txt(child).rstrip(), line_start=ls, line_end=le))
258
+ elif kind == "type_definition":
259
+ type_node = child.child_by_field_name("type")
260
+ decl = child.child_by_field_name("declarator")
261
+ alias = name_of(decl)
262
+ if alias:
263
+ ls, le = lines(child)
264
+ rf.typedefs.append(RawTypedef(name=alias, underlying=type_text(type_node),
265
+ underlying_ref=type_ref(type_node), source=txt(child),
266
+ doc=leading_comment(child, source),
267
+ line_start=ls, line_end=le))
268
+ emit_inline_type(type_node, child)
269
+ elif kind in _RECORD_KINDS:
270
+ rec = record_from_specifier(child)
271
+ if rec is not None:
272
+ rf.records.append(rec)
273
+ elif kind == "enum_specifier":
274
+ en = enum_from_specifier(child)
275
+ if en is not None:
276
+ rf.enums.append(en)
277
+ elif kind == "declaration":
278
+ decl = child.child_by_field_name("declarator")
279
+ fdecl = find_function_declarator(decl) if decl is not None else None
280
+ if fdecl is not None:
281
+ name = name_of(fdecl.child_by_field_name("declarator"))
282
+ if name:
283
+ ls, le = lines(child)
284
+ rf.functions.append(
285
+ RawFunction(
286
+ name=name,
287
+ return_type=type_text(child.child_by_field_name("type")),
288
+ params=parameters(fdecl),
289
+ is_static=is_static(child),
290
+ is_definition=False,
291
+ signature=signature_of(child, decl),
292
+ source=txt(child), doc=leading_comment(child, source),
293
+ line_start=ls, line_end=le,
294
+ )
295
+ )
296
+ else:
297
+ name = name_of(decl) if decl is not None else ""
298
+ if name:
299
+ ls, le = lines(child)
300
+ rf.globals.append(
301
+ RawGlobal(name=name, type=type_text(child.child_by_field_name("type")),
302
+ is_static=is_static(child), source=txt(child), line_start=ls, line_end=le)
303
+ )
304
+ emit_inline_type(child.child_by_field_name("type"), child)
305
+ elif kind == "function_definition":
306
+ decl = child.child_by_field_name("declarator")
307
+ fdecl = find_function_declarator(decl)
308
+ if fdecl is not None:
309
+ name = name_of(fdecl.child_by_field_name("declarator"))
310
+ if name:
311
+ body = child.child_by_field_name("body")
312
+ ls, le = lines(child)
313
+ rf.functions.append(
314
+ RawFunction(
315
+ name=name,
316
+ return_type=type_text(child.child_by_field_name("type")),
317
+ params=parameters(fdecl),
318
+ is_static=is_static(child),
319
+ is_definition=True,
320
+ calls=collect_calls(body) if body is not None else [],
321
+ signature=signature_of(child, decl),
322
+ source=txt(child), doc=leading_comment(child, source),
323
+ line_start=ls, line_end=le,
324
+ )
325
+ )
326
+
327
+ return rf
@@ -0,0 +1,183 @@
1
+ """Git-tracked (and directory) C ingestion: moves a project's C subgraph to a target
2
+ commit/tree by fully recomputing the target state and diffing it against the graph
3
+ (graph_sync.compute_delta) -- the same recompute-and-delta model as the C#/Python ingestors
4
+ (resolution is global, so a file-level diff can't tell which untouched files a linkage change
5
+ affects).
6
+
7
+ Fast engine only for now: tree-sitter-c streams each `.c`/`.h` blob (no disk materialization,
8
+ no build config) -> RawFile -> resolution.resolve(). A deep libclang pass would be added as
9
+ the GitLanguage's `deep_sync` (see plugin.py). Registered as the `c` GitLanguage for the
10
+ multi-language endpoint (core/ingest.py) in both ingest_repository (git) and ingest_directory
11
+ (local)."""
12
+
13
+ from __future__ import annotations
14
+
15
+ import itertools
16
+ import logging
17
+ import time
18
+ from dataclasses import dataclass
19
+
20
+ from auryn.core.parallel import parse_blobs_ordered
21
+ from auryn.core.graph_model import GraphNode
22
+ from auryn.core.graph_sync import stream_apply
23
+ from auryn.core.registry import LanguageIngestResult
24
+ from auryn.ingestors.c import resolution
25
+ from auryn.ingestors.c.file_parser import parse_source
26
+ from auryn.ingestors.c.ids import project_id
27
+ from auryn.ingestors.c.plugin import EXCLUDED_DIR_NAMES as _EXCLUDED_DIR_NAMES
28
+ from auryn.core.cpp_headers import HEADER_SUFFIX, is_cpp_header_blob
29
+ from auryn.ingestors.c.plugin import FILE_SUFFIXES as _FILE_SUFFIXES
30
+ from auryn.ingestors.c.schema import NODE_SCHEMAS
31
+
32
+ logger = logging.getLogger(__name__)
33
+
34
+
35
+ @dataclass
36
+ class SyncStats:
37
+ nodes_added: int = 0
38
+ nodes_updated: int = 0
39
+ nodes_removed: int = 0
40
+ edges_added: int = 0
41
+ edges_updated: int = 0
42
+ edges_removed: int = 0
43
+ commit_sha: str = ""
44
+ elapsed_seconds: float = 0.0
45
+ files_parsed: int = 0
46
+ files_cached: int = 0
47
+
48
+
49
+ def sync_at(writer, source, target_sha: str, project_name: str, repo_uri: str, ref: str | None) -> SyncStats:
50
+ """Recompute the whole C subgraph at `target_sha` and delta it onto the graph. `source`
51
+ is duck-typed (GitRepoCache or LocalDirectorySource): only list_files/read_blob used."""
52
+ started = time.monotonic()
53
+ proj_id = project_id(project_name)
54
+
55
+ writer.setup_schema(NODE_SCHEMAS) # brings the graph key into existence before the first read
56
+ current_sha = writer.get_property("Project", {"id": proj_id}, "commit_sha")
57
+ if current_sha == target_sha:
58
+ return SyncStats(commit_sha=target_sha, elapsed_seconds=time.monotonic() - started)
59
+
60
+ # Incremental resync (ADR 0005, authored-shared engine): when a prior graph already exists at a
61
+ # different, reachable commit, move it by processing only the git diff + its graph-derived blast
62
+ # radius (co-contributor + reverse-dep closures, provenance-scoped read-back, refcount
63
+ # delete-or-demote) instead of recomputing the whole tree -- see incremental.py. Any failure (old
64
+ # commit unreachable, non-diffable source, plain dir) falls back to the full recompute below.
65
+ if current_sha and current_sha != target_sha:
66
+ incr = _route(writer, source, target_sha, ref, current_sha,
67
+ project_name=project_name, repo_uri=repo_uri)
68
+ if incr is not None:
69
+ return _finish(writer, proj_id, source, incr)
70
+
71
+ # `.h` is ambiguous (C vs C++ header); a C++ header must go to the C++ ingestor, not here -- the C
72
+ # grammar can't parse `class`/`namespace`/`template` and would lose the whole class (see
73
+ # core.cpp_headers). Skip the C++-classified `.h`; everything C-compatible stays with C.
74
+ entries = [
75
+ (path, blob_sha)
76
+ for suffix in _FILE_SUFFIXES
77
+ for path, blob_sha in source.list_files(target_sha, suffix, set(_EXCLUDED_DIR_NAMES))
78
+ if not (suffix == HEADER_SUFFIX and is_cpp_header_blob(source.read_blob(blob_sha)))
79
+ ]
80
+ files = parse_blobs_ordered(
81
+ entries, source.read_blob, parse_source,
82
+ preload=["auryn.ingestors.c.file_parser"], logger=logger,
83
+ )
84
+
85
+ project_node = GraphNode(
86
+ "Project", {"id": proj_id}, {"name": project_name, "repo_uri": repo_uri, "commit_sha": target_sha, "ref": ref}
87
+ )
88
+
89
+ def make_target(): # re-iterable: stream_apply runs it once for nodes, once for edges
90
+ return itertools.chain([project_node], resolution.resolve(files, proj_id))
91
+
92
+ return _finish(writer, proj_id, source,
93
+ _apply(writer, proj_id, make_target, target_sha, started, files_parsed=len(files)))
94
+
95
+
96
+ def _route(writer, source, target_sha, ref, current_sha, *, project_name, repo_uri) -> "SyncStats | None":
97
+ """Attempt an incremental resync via the shared engine's git routing (working-tree or bare-clone
98
+ producer); return SyncStats or None to fall back to the full recompute. C's C_SPEC sets
99
+ `provenance_rels`, so route_incremental dispatches to the authored-shared engine."""
100
+ from auryn.core.incremental_scoped import route_incremental
101
+ from auryn.ingestors.c.incremental import C_SPEC
102
+
103
+ s = route_incremental(
104
+ writer, C_SPEC, source, target_sha, ref, current_sha,
105
+ project_name=project_name, repo_uri=repo_uri, logger=logger,
106
+ )
107
+ if s is None:
108
+ return None
109
+ return SyncStats(
110
+ nodes_added=s.nodes_added, nodes_updated=s.nodes_updated, nodes_removed=s.nodes_removed,
111
+ edges_added=s.edges_added, edges_updated=s.edges_updated, edges_removed=s.edges_removed,
112
+ commit_sha=s.commit_sha, elapsed_seconds=s.elapsed_seconds,
113
+ files_parsed=s.files_parsed, files_cached=s.files_cached,
114
+ )
115
+
116
+
117
+ def _finish(writer, proj_id: str, source, result: SyncStats) -> SyncStats:
118
+ """After any non-short-circuit sync, record the working-tree base for the next save-triggered
119
+ incremental resync (a no-op for git/plain-dir sources)."""
120
+ from auryn.core.incremental_scoped import stamp_worktree
121
+ from auryn.core.local_source import WorkingTreeSource
122
+
123
+ if isinstance(source, WorkingTreeSource):
124
+ stamp_worktree(writer, proj_id, source, _FILE_SUFFIXES)
125
+ return result
126
+
127
+
128
+ def _apply(writer, proj_id: str, make_target, target_sha: str, started: float, files_parsed: int) -> SyncStats:
129
+ # Cross-repo reconciliation (ADR 0004): fold placeholder<->definer pairs among the linkages
130
+ # this ingest touched -- targeted index seeks, no scan. No-op unless the graph holds >1 repo.
131
+ from auryn.core.linkage import reconcile_linkages
132
+
133
+ # stream_apply writes the delta without materialising the target graph, and returns the
134
+ # linkage strings collected inline (see graph_sync.stream_apply / core.linkage).
135
+ labels = [s.label for s in NODE_SCHEMAS]
136
+ stats, reals, placeholders = stream_apply(writer, proj_id, labels, make_target)
137
+ reconcile_linkages(writer, reals, placeholders)
138
+
139
+ return SyncStats(
140
+ nodes_added=stats.nodes_added,
141
+ nodes_updated=stats.nodes_updated,
142
+ nodes_removed=stats.nodes_removed,
143
+ edges_added=stats.edges_added,
144
+ edges_updated=stats.edges_updated,
145
+ edges_removed=stats.edges_removed,
146
+ commit_sha=target_sha,
147
+ elapsed_seconds=time.monotonic() - started,
148
+ files_parsed=files_parsed,
149
+ files_cached=0,
150
+ )
151
+
152
+
153
+ def _git_language_sync(
154
+ writer,
155
+ source,
156
+ target_sha: str,
157
+ *,
158
+ repo_uri: str,
159
+ project_name: str,
160
+ solution_name: str | None,
161
+ ref: str | None,
162
+ cache_root=None,
163
+ ) -> LanguageIngestResult:
164
+ """GitLanguage adapter for the multi-language endpoint (C has no solution/cache knobs --
165
+ accepted for the shared interface and ignored)."""
166
+ s = sync_at(writer, source, target_sha, project_name=project_name, repo_uri=repo_uri, ref=ref)
167
+ return LanguageIngestResult(
168
+ nodes_added=s.nodes_added,
169
+ nodes_updated=s.nodes_updated,
170
+ nodes_removed=s.nodes_removed,
171
+ edges_added=s.edges_added,
172
+ edges_updated=s.edges_updated,
173
+ edges_removed=s.edges_removed,
174
+ files_parsed=s.files_parsed,
175
+ files_cached=s.files_cached,
176
+ commit_sha=s.commit_sha,
177
+ elapsed_seconds=s.elapsed_seconds,
178
+ )
179
+
180
+
181
+ # The GitLanguage is registered by the import-light plugin.py (the entry-point target), whose
182
+ # lazy `sync` thunk calls `_git_language_sync` above -- so importing this tree-sitter engine
183
+ # module is deferred until a source actually contains C files.
@@ -0,0 +1,14 @@
1
+ """tree-sitter-c Language/Parser setup, in one place so file_parser.py and tests always get
2
+ the exact same configured parser. Like tree-sitter-c-sharp, tree-sitter-c ships a pre-built
3
+ PyPI package -- no codegen/vendoring (contrast PL/SQL's vendored ANTLR grammar)."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import tree_sitter_c as tsc
8
+ from tree_sitter import Language, Parser
9
+
10
+ LANGUAGE = Language(tsc.language())
11
+
12
+
13
+ def new_parser() -> Parser:
14
+ return Parser(LANGUAGE)