awgraph 1.0.0__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.
awgraph-1.0.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
awgraph-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,141 @@
1
+ Metadata-Version: 2.4
2
+ Name: awgraph
3
+ Version: 1.0.0
4
+ Summary: Semantic Python code graph — AST indexing, call graphs, and hybrid search for Python codebases.
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/Aitherium/awgraph
7
+ Project-URL: Documentation, https://github.com/Aitherium/awgraph#readme
8
+ Project-URL: Repository, https://github.com/Aitherium/awgraph.git
9
+ Project-URL: Issues, https://github.com/Aitherium/awgraph/issues
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: httpx>=0.25.0
14
+ Provides-Extra: numpy
15
+ Requires-Dist: numpy>=1.21.0; extra == "numpy"
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=7.0; extra == "dev"
18
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # awgraph — the code graph your agent reads instead of grepping
22
+
23
+ An agent asked to fix a bug does not know which files matter, so it greps, opens
24
+ whatever matched, and spends most of its context window on code it will not
25
+ change. awgraph indexes the repository into a graph of symbols — functions,
26
+ methods, classes, their calls and callers — and answers a natural-language task
27
+ with the handful of chunks that task actually needs.
28
+
29
+ ```bash
30
+ pip install awgraph
31
+ ```
32
+
33
+ Python 3.10+. Nothing else is required to index and query.
34
+
35
+ ## What it costs, measured
36
+
37
+ The interesting question is not "is a graph better than grep" — it is *what does
38
+ each cost*. Measured on a corpus of real commits, where the task is a commit
39
+ message with the answer filenames stripped out and the truth is the set of files
40
+ that commit actually modified:
41
+
42
+ | retriever | recall@10 | context tokens per task |
43
+ |---|---|---|
44
+ | ranked multi-term grep | 0.933 | 351,369 |
45
+ | **awgraph** | **0.800** | **1,503** |
46
+
47
+ **86% of grep's recall for 0.43% of the context — a 234x reduction.**
48
+
49
+ Read that honestly: **grep still wins on recall.** awgraph is not a better
50
+ *finder*; it is a dramatically cheaper one, and on a long agent loop the context
51
+ budget is usually what runs out first. If you need maximum recall and cost is no
52
+ object, grep. If you are paying per token across thousands of turns, this is a
53
+ different order of magnitude.
54
+
55
+ Caveats, because a benchmark without them is marketing: n=15 tasks, and only
56
+ 33.3% of chunks carried embeddings on that run, so the semantic half was working
57
+ at partial strength — the recall number understates it.
58
+
59
+ A naive fusion (run the graph, fall back to grep when it returns few files) was
60
+ also measured: it reaches grep's 0.933 recall at 352,872 tokens — *more* than
61
+ grep alone, because the fallback fires on nearly every task and pays both bills.
62
+ Reported because it did not work; a smarter trigger is future work.
63
+
64
+ ## Setup: index once, embed lazily
65
+
66
+ Two costs, and only one of them scales with repo size.
67
+
68
+ | step | 2,400 chunks | 43,730 chunks |
69
+ |---|---|---|
70
+ | parse + index | 49.8s | 75.5s |
71
+ | embed (CPU) | — | ~97 min at ~450 vectors/min |
72
+
73
+ **Indexing is close to size-insensitive** — 27x the files for 1.5x the time,
74
+ because parsing runs across workers. Embedding is the part that hurts on CPU, so
75
+ it is optional, cached and incremental: re-indexing reuses stored vectors and
76
+ only embeds what changed.
77
+
78
+ Without any embedding backend, queries fall back to keyword scoring and still
79
+ work. **That fallback is silent by design and dangerous by nature** — a graph
80
+ with no vectors looks like a working graph that is merely worse. Check coverage
81
+ rather than assuming it:
82
+
83
+ ```python
84
+ embedded = sum(1 for c in graph.chunks.values() if c.embedding is not None)
85
+ print(f"{embedded}/{len(graph.chunks)} chunks carry vectors")
86
+ ```
87
+
88
+ ## Use it
89
+
90
+ ```python
91
+ import asyncio
92
+ from awgraph import CodeGraph
93
+
94
+ async def main():
95
+ graph = CodeGraph(root_path="/abs/path/to/repo", auto_index=False)
96
+ await graph.index_codebase("/abs/path/to/repo") # absolute path required
97
+
98
+ for chunk in await graph.hybrid_query("retry with exponential backoff", max_results=5):
99
+ print(chunk.name, chunk.source_path, chunk.start_line)
100
+
101
+ asyncio.run(main())
102
+ ```
103
+
104
+ `index_codebase` needs an **absolute** path. Given a relative one it walks
105
+ nothing, indexes zero chunks, and returns successfully — so assert on
106
+ `len(graph.chunks)` rather than on the absence of an exception.
107
+
108
+ The query does not need to contain the symbol name. Asking for "backoff policy
109
+ for flaky calls" against a class documented as *"Backoff policy for flaky
110
+ calls"* returns it by meaning, not by string match.
111
+
112
+ ## Where it sits
113
+
114
+ Three packages, three different questions about the same repository:
115
+
116
+ - **[awgit](https://github.com/Aitherium/awgit)** — semantic version control.
117
+ Stable node ids, semantic edit-ops, leases so concurrent agents do not
118
+ overwrite each other, stacked commits with one PR each. It knows **what
119
+ changed and who is editing it**.
120
+ - **awgraph** — code intelligence. Symbols, call paths, dependencies, blast
121
+ radius. It knows **what the code is and what depends on what**.
122
+ - **[aither-adk](https://github.com/Aitherium/aither-adk)** — the agent runtime
123
+ that consumes both.
124
+
125
+ The seam is the useful part: awgit tells you a commit touched
126
+ `RetryPolicy.next_delay`; awgraph tells you what calls it and which tests cover
127
+ it; the agent reads that instead of the repository.
128
+
129
+ ## Related work
130
+
131
+ [GitNexus](https://github.com/abhigyanpatwari/GitNexus) is the closest analogue
132
+ and worth reading. Its recommended mode augments grep with graph context rather
133
+ than replacing grep — a conclusion these measurements independently reach. Note
134
+ its licence is PolyForm Noncommercial (source-available, commercial use
135
+ forbidden), where awgraph is Apache 2.0. Its published figures measure SWE-bench
136
+ task resolution; the numbers above measure retrieval recall. Those are different
137
+ axes and should not be compared directly.
138
+
139
+ ## Licence
140
+
141
+ Apache 2.0.
@@ -0,0 +1,121 @@
1
+ # awgraph — the code graph your agent reads instead of grepping
2
+
3
+ An agent asked to fix a bug does not know which files matter, so it greps, opens
4
+ whatever matched, and spends most of its context window on code it will not
5
+ change. awgraph indexes the repository into a graph of symbols — functions,
6
+ methods, classes, their calls and callers — and answers a natural-language task
7
+ with the handful of chunks that task actually needs.
8
+
9
+ ```bash
10
+ pip install awgraph
11
+ ```
12
+
13
+ Python 3.10+. Nothing else is required to index and query.
14
+
15
+ ## What it costs, measured
16
+
17
+ The interesting question is not "is a graph better than grep" — it is *what does
18
+ each cost*. Measured on a corpus of real commits, where the task is a commit
19
+ message with the answer filenames stripped out and the truth is the set of files
20
+ that commit actually modified:
21
+
22
+ | retriever | recall@10 | context tokens per task |
23
+ |---|---|---|
24
+ | ranked multi-term grep | 0.933 | 351,369 |
25
+ | **awgraph** | **0.800** | **1,503** |
26
+
27
+ **86% of grep's recall for 0.43% of the context — a 234x reduction.**
28
+
29
+ Read that honestly: **grep still wins on recall.** awgraph is not a better
30
+ *finder*; it is a dramatically cheaper one, and on a long agent loop the context
31
+ budget is usually what runs out first. If you need maximum recall and cost is no
32
+ object, grep. If you are paying per token across thousands of turns, this is a
33
+ different order of magnitude.
34
+
35
+ Caveats, because a benchmark without them is marketing: n=15 tasks, and only
36
+ 33.3% of chunks carried embeddings on that run, so the semantic half was working
37
+ at partial strength — the recall number understates it.
38
+
39
+ A naive fusion (run the graph, fall back to grep when it returns few files) was
40
+ also measured: it reaches grep's 0.933 recall at 352,872 tokens — *more* than
41
+ grep alone, because the fallback fires on nearly every task and pays both bills.
42
+ Reported because it did not work; a smarter trigger is future work.
43
+
44
+ ## Setup: index once, embed lazily
45
+
46
+ Two costs, and only one of them scales with repo size.
47
+
48
+ | step | 2,400 chunks | 43,730 chunks |
49
+ |---|---|---|
50
+ | parse + index | 49.8s | 75.5s |
51
+ | embed (CPU) | — | ~97 min at ~450 vectors/min |
52
+
53
+ **Indexing is close to size-insensitive** — 27x the files for 1.5x the time,
54
+ because parsing runs across workers. Embedding is the part that hurts on CPU, so
55
+ it is optional, cached and incremental: re-indexing reuses stored vectors and
56
+ only embeds what changed.
57
+
58
+ Without any embedding backend, queries fall back to keyword scoring and still
59
+ work. **That fallback is silent by design and dangerous by nature** — a graph
60
+ with no vectors looks like a working graph that is merely worse. Check coverage
61
+ rather than assuming it:
62
+
63
+ ```python
64
+ embedded = sum(1 for c in graph.chunks.values() if c.embedding is not None)
65
+ print(f"{embedded}/{len(graph.chunks)} chunks carry vectors")
66
+ ```
67
+
68
+ ## Use it
69
+
70
+ ```python
71
+ import asyncio
72
+ from awgraph import CodeGraph
73
+
74
+ async def main():
75
+ graph = CodeGraph(root_path="/abs/path/to/repo", auto_index=False)
76
+ await graph.index_codebase("/abs/path/to/repo") # absolute path required
77
+
78
+ for chunk in await graph.hybrid_query("retry with exponential backoff", max_results=5):
79
+ print(chunk.name, chunk.source_path, chunk.start_line)
80
+
81
+ asyncio.run(main())
82
+ ```
83
+
84
+ `index_codebase` needs an **absolute** path. Given a relative one it walks
85
+ nothing, indexes zero chunks, and returns successfully — so assert on
86
+ `len(graph.chunks)` rather than on the absence of an exception.
87
+
88
+ The query does not need to contain the symbol name. Asking for "backoff policy
89
+ for flaky calls" against a class documented as *"Backoff policy for flaky
90
+ calls"* returns it by meaning, not by string match.
91
+
92
+ ## Where it sits
93
+
94
+ Three packages, three different questions about the same repository:
95
+
96
+ - **[awgit](https://github.com/Aitherium/awgit)** — semantic version control.
97
+ Stable node ids, semantic edit-ops, leases so concurrent agents do not
98
+ overwrite each other, stacked commits with one PR each. It knows **what
99
+ changed and who is editing it**.
100
+ - **awgraph** — code intelligence. Symbols, call paths, dependencies, blast
101
+ radius. It knows **what the code is and what depends on what**.
102
+ - **[aither-adk](https://github.com/Aitherium/aither-adk)** — the agent runtime
103
+ that consumes both.
104
+
105
+ The seam is the useful part: awgit tells you a commit touched
106
+ `RetryPolicy.next_delay`; awgraph tells you what calls it and which tests cover
107
+ it; the agent reads that instead of the repository.
108
+
109
+ ## Related work
110
+
111
+ [GitNexus](https://github.com/abhigyanpatwari/GitNexus) is the closest analogue
112
+ and worth reading. Its recommended mode augments grep with graph context rather
113
+ than replacing grep — a conclusion these measurements independently reach. Note
114
+ its licence is PolyForm Noncommercial (source-available, commercial use
115
+ forbidden), where awgraph is Apache 2.0. Its published figures measure SWE-bench
116
+ task resolution; the numbers above measure retrieval recall. Those are different
117
+ axes and should not be compared directly.
118
+
119
+ ## Licence
120
+
121
+ Apache 2.0.
@@ -0,0 +1,70 @@
1
+ """awgraph — Semantic Python Code Graph.
2
+
3
+ A lightweight, portable Python AST indexer with call graphs, embeddings support,
4
+ and hybrid keyword+semantic search. Originally developed as part of AitherOS's
5
+ CodeGraph faculty, now available as a public package.
6
+
7
+ ## What it does
8
+
9
+ - Real AST parsing (not regex)
10
+ - Extracts functions, classes, and methods into chunks
11
+ - Builds call graphs (what calls what, what's called by what)
12
+ - Hybrid search: keyword (FTS5) + semantic (embeddings)
13
+ - SQLite storage with WAL mode for concurrent access
14
+ - Optional NumPy for fast vector operations
15
+
16
+ ## What it doesn't do
17
+
18
+ - PDFs, web pages, or "universal" anything — just Python code
19
+ - Embeddings by default — bring your own or use plugin hooks
20
+ - Network access by default — embeddings API must be provided externally
21
+ - Persistence across instances — in-memory by design; SQLite for durability
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ from awgraph import CodeGraph
27
+
28
+ # Create an indexer
29
+ graph = CodeGraph()
30
+
31
+ # Index a directory
32
+ await graph.index_codebase("/path/to/code")
33
+
34
+ # Query
35
+ chunks = await graph.query("rate limiter", limit=10)
36
+
37
+ for chunk in chunks:
38
+ print(f"{chunk.name}: {chunk.calls}")
39
+ ```
40
+
41
+ ## Architecture
42
+
43
+ - **graph.py**: CodeGraph engine, AST parsing, call graphs, chunking
44
+ - **store.py**: SQLite+FTS5 backend for storage and search
45
+ - **registry.py**: Multi-root manager for indexing external repos
46
+ - **base.py**: Minimal faculty graph base class
47
+ - **logging.py**: Standard Python logging shim
48
+ - **degradation.py**: Optional dependency tracking
49
+
50
+ Plugin support via awgraph.plugins (not yet public).
51
+ """
52
+
53
+ from __future__ import annotations
54
+
55
+ from awgraph.graph import CodeGraph, CodeChunk
56
+ from awgraph.registry import CodeGraphRegistry, get_codegraph_registry
57
+ from awgraph.store import CodeGraphStore
58
+ from awgraph.base import BaseFacultyGraph, GraphSyncConfig
59
+
60
+ __version__ = "1.0.0"
61
+
62
+ __all__ = [
63
+ "CodeGraph",
64
+ "CodeChunk",
65
+ "CodeGraphRegistry",
66
+ "CodeGraphStore",
67
+ "BaseFacultyGraph",
68
+ "GraphSyncConfig",
69
+ "get_codegraph_registry",
70
+ ]
@@ -0,0 +1,139 @@
1
+ """
2
+ Minimal base class for awgraph.
3
+
4
+ Provides the core interface a faculty graph implements, without the AitherOS
5
+ integrations (sync, provenance, integrity). This is what the public package
6
+ exposes.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from dataclasses import dataclass
12
+ from typing import Any, Dict, List
13
+
14
+
15
+ @dataclass
16
+ class GraphSyncConfig:
17
+ """Stub for compatibility; sync is not available in the public package."""
18
+ enabled: bool = False
19
+ domain: str = ""
20
+ batch_size: int = 20
21
+ flush_interval: float = 5.0
22
+ source_graph: str = ""
23
+ provenance: bool = False
24
+ provenance_node_type: str = "claim"
25
+
26
+
27
+ class BaseFacultyGraph:
28
+ """
29
+ Minimal base class for a faculty graph.
30
+
31
+ In AitherOS, this also provides sync to AitherKnowledgeGraph, provenance
32
+ emission, and integrity tracking. The public package drops those features,
33
+ keeping only the core interface: query(), stats(), and graph_query().
34
+ """
35
+
36
+ _sync_config: GraphSyncConfig = GraphSyncConfig()
37
+ _scope_level: str = "platform"
38
+
39
+ def __init__(self):
40
+ self._sync_config = GraphSyncConfig()
41
+
42
+ def _queue_sync(self, node_data: Dict[str, Any], tenant_id: str = "platform") -> None:
43
+ """No-op: sync to AitherKnowledgeGraph is not available in public package."""
44
+ pass
45
+
46
+ def _queue_deletion(self, node_id: str, tenant_id: str = "platform") -> None:
47
+ """No-op: sync is not available in public package."""
48
+ pass
49
+
50
+ # SYNC on purpose: every call site is `self._flush_to_bus()` with no await.
51
+ # Declaring it async made each call return a coroutine nobody awaits, which
52
+ # Python reports only as a RuntimeWarning — so the no-op would have looked
53
+ # like it ran while doing nothing, in a package whose whole promise is that
54
+ # the stub is inert rather than silently broken.
55
+ def _flush_to_bus(self, *args: Any, **kwargs: Any) -> None:
56
+ """No-op: there is no event bus in the standalone package.
57
+
58
+ This one is not decoration. Indexing calls it, so omitting it made the
59
+ package import cleanly and then die with AttributeError on the FIRST
60
+ index_codebase() call — the shape where a vendored package looks fine to
61
+ every import check and is broken for the person who pip-installed it.
62
+ An import test cannot catch this; only actually indexing something can.
63
+
64
+ Subclasses in a host application may override it to re-attach their own
65
+ event plumbing; nothing here needs to know that they exist.
66
+ """
67
+ return None
68
+
69
+ def _emit_provenance(
70
+ self,
71
+ node_id: str,
72
+ name: str,
73
+ properties: Dict[str, Any],
74
+ tenant_id: str = "platform",
75
+ ) -> None:
76
+ """No-op: provenance emission is not available in public package."""
77
+ pass
78
+
79
+ def graph_stats(self) -> Dict[str, Any]:
80
+ """Inventory: how many nodes does this graph hold?
81
+
82
+ Subclasses may override. Default derives counts from public attributes.
83
+ """
84
+ entities: Dict[str, int] = {}
85
+ for name, val in vars(self).items():
86
+ if name.startswith("_") or name.startswith("by_"):
87
+ continue
88
+ if not isinstance(val, (dict, list, set, tuple)):
89
+ continue
90
+ entities[name] = len(val)
91
+ return {"nodes": sum(entities.values()), "containers": entities}
92
+
93
+ async def graph_query(
94
+ self, text: str, limit: int = 10,
95
+ ) -> List[Dict[str, Any]]:
96
+ """Uniform cross-graph query.
97
+
98
+ Adapts this graph's search() or query() method by parameter name.
99
+ Subclasses may override for a better native path.
100
+ """
101
+ import asyncio
102
+ import inspect
103
+
104
+ fn = getattr(self, "search", None) or getattr(self, "query", None)
105
+ if not callable(fn):
106
+ return []
107
+
108
+ try:
109
+ sig = inspect.signature(fn)
110
+ except (TypeError, ValueError):
111
+ return []
112
+
113
+ # Bind by parameter name (not position)
114
+ kwargs = {}
115
+ for p in sig.parameters.values():
116
+ if p.name in ("query", "query_str", "text", "prompt", "search"):
117
+ kwargs[p.name] = text
118
+ elif p.name in ("limit", "max_results", "top_k", "k"):
119
+ kwargs[p.name] = limit
120
+
121
+ # Call sync or async
122
+ try:
123
+ if asyncio.iscoroutinefunction(fn):
124
+ return await fn(**kwargs)
125
+ else:
126
+ loop = asyncio.get_event_loop()
127
+ return await loop.run_in_executor(None, fn, **kwargs)
128
+ except TypeError:
129
+ # Fall back to no kwargs if binding failed
130
+ try:
131
+ if asyncio.iscoroutinefunction(fn):
132
+ return await fn(text, limit)
133
+ else:
134
+ loop = asyncio.get_event_loop()
135
+ return await loop.run_in_executor(None, lambda: fn(text, limit))
136
+ except Exception:
137
+ return []
138
+ except Exception:
139
+ return []