featuregraph-cli 0.1.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.
Files changed (52) hide show
  1. featuregraph_cli-0.1.0/.github/workflows/ci.yml +26 -0
  2. featuregraph_cli-0.1.0/.gitignore +34 -0
  3. featuregraph_cli-0.1.0/.serena/.gitignore +2 -0
  4. featuregraph_cli-0.1.0/.serena/project.local.yml +5 -0
  5. featuregraph_cli-0.1.0/.serena/project.yml +187 -0
  6. featuregraph_cli-0.1.0/LICENSE +21 -0
  7. featuregraph_cli-0.1.0/PKG-INFO +338 -0
  8. featuregraph_cli-0.1.0/README.md +312 -0
  9. featuregraph_cli-0.1.0/examples/fastapi-react-demo/README.md +18 -0
  10. featuregraph_cli-0.1.0/examples/fastapi-react-demo/api/auth.py +8 -0
  11. featuregraph_cli-0.1.0/examples/fastapi-react-demo/api/billing.py +8 -0
  12. featuregraph_cli-0.1.0/examples/fastapi-react-demo/api/routes.py +37 -0
  13. featuregraph_cli-0.1.0/examples/fastapi-react-demo/web/BillingCard.tsx +8 -0
  14. featuregraph_cli-0.1.0/featuregraph/__init__.py +6 -0
  15. featuregraph_cli-0.1.0/featuregraph/cli.py +758 -0
  16. featuregraph_cli-0.1.0/featuregraph/core/annotator.py +491 -0
  17. featuregraph_cli-0.1.0/featuregraph/core/dependency_resolver.py +480 -0
  18. featuregraph_cli-0.1.0/featuregraph/core/graph.py +123 -0
  19. featuregraph_cli-0.1.0/featuregraph/core/lexmask.py +264 -0
  20. featuregraph_cli-0.1.0/featuregraph/core/parser_generic.py +233 -0
  21. featuregraph_cli-0.1.0/featuregraph/core/parser_protocol.py +18 -0
  22. featuregraph_cli-0.1.0/featuregraph/core/parser_py.py +243 -0
  23. featuregraph_cli-0.1.0/featuregraph/core/parser_ts.py +350 -0
  24. featuregraph_cli-0.1.0/featuregraph/core/scanner.py +429 -0
  25. featuregraph_cli-0.1.0/featuregraph/core/tags.py +51 -0
  26. featuregraph_cli-0.1.0/featuregraph/formatters/json_formatter.py +164 -0
  27. featuregraph_cli-0.1.0/featuregraph/formatters/markdown_formatter.py +110 -0
  28. featuregraph_cli-0.1.0/featuregraph/hooks/git_hook.py +82 -0
  29. featuregraph_cli-0.1.0/featuregraph/skills/__init__.py +3 -0
  30. featuregraph_cli-0.1.0/featuregraph/skills/featuregraph/SKILL.md +211 -0
  31. featuregraph_cli-0.1.0/featuregraph/skills/skill_manager.py +51 -0
  32. featuregraph_cli-0.1.0/pyproject.toml +66 -0
  33. featuregraph_cli-0.1.0/tests/test_annotator.py +133 -0
  34. featuregraph_cli-0.1.0/tests/test_cjs_coverage.py +141 -0
  35. featuregraph_cli-0.1.0/tests/test_cli_json.py +123 -0
  36. featuregraph_cli-0.1.0/tests/test_dependency_resolver.py +166 -0
  37. featuregraph_cli-0.1.0/tests/test_freshness_manifest.py +255 -0
  38. featuregraph_cli-0.1.0/tests/test_git_hook.py +107 -0
  39. featuregraph_cli-0.1.0/tests/test_haiku_audit_fixes.py +231 -0
  40. featuregraph_cli-0.1.0/tests/test_ignored_files.py +70 -0
  41. featuregraph_cli-0.1.0/tests/test_lexmask.py +259 -0
  42. featuregraph_cli-0.1.0/tests/test_markdown_formatter.py +57 -0
  43. featuregraph_cli-0.1.0/tests/test_mega_patch_phase2.py +482 -0
  44. featuregraph_cli-0.1.0/tests/test_mega_patch_phase3.py +550 -0
  45. featuregraph_cli-0.1.0/tests/test_parser_generic.py +71 -0
  46. featuregraph_cli-0.1.0/tests/test_parser_ts.py +43 -0
  47. featuregraph_cli-0.1.0/tests/test_phantom_tags.py +71 -0
  48. featuregraph_cli-0.1.0/tests/test_python_coverage.py +210 -0
  49. featuregraph_cli-0.1.0/tests/test_scanner.py +61 -0
  50. featuregraph_cli-0.1.0/tests/test_scanner_warnings.py +143 -0
  51. featuregraph_cli-0.1.0/tests/test_skills.py +56 -0
  52. featuregraph_cli-0.1.0/tests/test_symbol_ids.py +103 -0
@@ -0,0 +1,26 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - name: install
20
+ run: pip install -e ".[dev]"
21
+ - name: lint
22
+ run: ruff check featuregraph tests
23
+ - name: test
24
+ run: python -m pytest -q
25
+ - name: featuregraph gate
26
+ run: featuregraph check --rescan --strict
@@ -0,0 +1,34 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ .Python
6
+ build/
7
+ develop-eggs/
8
+ dist/
9
+ downloads/
10
+ eggs/
11
+ .eggs/
12
+ lib/
13
+ lib64/
14
+ parts/
15
+ sdist/
16
+ var/
17
+ wheels/
18
+ *.egg-info/
19
+ .installed.cfg
20
+ *.egg
21
+ .venv
22
+ venv/
23
+ .pytest_cache/
24
+
25
+ # FeatureGraph generated artifacts (per-project, not in tool repo)
26
+ .featuregraph/
27
+ FEATURE_INDEX.json
28
+ SYSTEM_FEATURE_GRAPH.md
29
+ AGENTS.md
30
+ .featureignore
31
+
32
+ # Local artifacts (scratch graphs, demo recordings)
33
+ graphify-out/
34
+ demo/
@@ -0,0 +1,2 @@
1
+ /cache
2
+ /project.local.yml
@@ -0,0 +1,5 @@
1
+ # This file allows you to locally override settings in project.yml for development purposes.
2
+ #
3
+ # Use the same keys as in project.yml here. Any setting you specify will override the corresponding
4
+ # setting in project.yml, allowing you to customise the configuration for your local development environment
5
+ # without affecting the project configuration in project.yml (which is intended to be versioned).
@@ -0,0 +1,187 @@
1
+ # the name by which the project can be referenced within Serena/when chatting with the LLM.
2
+ project_name: "featuregraph"
3
+
4
+ # list of language servers to start when using the LSP backend; choose from:
5
+ # ada al angular ansible astro
6
+ # bash bsl clojure cpp cpp_ccls
7
+ # crystal csharp csharp_omnisharp cue dart
8
+ # deno elixir elm erlang fortran
9
+ # fsharp gdscript gleam go groovy
10
+ # haskell haxe hlsl html java
11
+ # json julia julia_fatou kotlin latex
12
+ # lean4 lua lua_emmylua luau markdown
13
+ # matlab msl nextflow nix ocaml
14
+ # pascal perl php php_devsense php_phpactor
15
+ # php_phpantom powershell python python_basedpyright python_jedi
16
+ # python_pyrefly python_ty qml r rego
17
+ # ruby ruby_solargraph rust scala scss
18
+ # solidity svelte swift systemverilog terraform
19
+ # toml typescript typescript_tsgo typescript_vts vue
20
+ # vbnet wolfram yaml zig
21
+ # (This list may be outdated; generated with scripts/print_language_list.py;
22
+ # For the current list, see values of the LanguageServerId enum here:
23
+ # https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py)
24
+ # For some languages, there are several alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
25
+ # Note:
26
+ # - For C, use cpp
27
+ # - For JavaScript, use typescript
28
+ # - For Angular projects, use angular (subsumes typescript+html; requires `npm install` in the project root)
29
+ # - For Astro projects, use astro (subsumes typescript/javascript for .astro projects; requires npm)
30
+ # - For Svelte projects, use svelte (subsumes typescript/javascript for .svelte projects; requires npm)
31
+ # - For Deno projects, use deno (serves the same .ts/.js files as typescript; requires the deno CLI on PATH)
32
+ # - For SCSS / Sass / plain CSS, use scss (some-sass-language-server handles all three)
33
+ # - For Free Pascal/Lazarus, use pascal
34
+ # - External Python adapters may add further registered IDs; install the adapter package first
35
+ # and then use its ID here, for example: example
36
+ # Special requirements:
37
+ # Some language servers require additional setup/installations.
38
+ # See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
39
+ # When using multiple language servers, the first language server that supports a given file will be used for that file.
40
+ # The first language server is the default language and the respective language server will be used as a fallback.
41
+ # Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
42
+ language_servers:
43
+ - python
44
+
45
+ # the encoding used by text files in the project
46
+ # For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
47
+ encoding: "utf-8"
48
+
49
+ # optional shell command to run before the language backend (LSP or JetBrains) is initialised.
50
+ # the command runs in the project root directory and is only executed if the project is trusted
51
+ # (see trusted_project_path_patterns in the global configuration).
52
+ # serena waits for the command to exit: a non-zero exit code is logged as an error but does not
53
+ # abort activation. a per-project timeout (activation_command_timeout, default 180s) is the safety
54
+ # backstop for non-terminating commands; on expiry the process is killed and activation continues.
55
+ # example: activation_command: "npx nx run-many -t build"
56
+ activation_command:
57
+
58
+ # maximum time in seconds to wait for activation_command to complete before killing it (default 180s).
59
+ # must be a positive number.
60
+ activation_command_timeout: 180.0
61
+
62
+ # line ending convention to use when writing source files.
63
+ # Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
64
+ # This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
65
+ line_ending:
66
+
67
+ # The language backend to use for this project.
68
+ # If not set, the global setting from serena_config.yml is used.
69
+ # Valid values: LSP, JetBrains
70
+ # Note: the backend is fixed at startup. If a project with a different backend
71
+ # is activated post-init, an error will be returned.
72
+ language_backend:
73
+
74
+ # The interface through which the agent (LLM) accesses Serena's functionality (overrides the global setting).
75
+ # Valid values: tools, REPL (see the global configuration for details); leave empty to use the global setting.
76
+ # Note: the interface is fixed at startup. If a project is activated post-init, its setting is not applied.
77
+ agent_interface:
78
+
79
+ # whether to use project's .gitignore files to ignore files
80
+ ignore_all_files_in_gitignore: true
81
+
82
+ # advanced configuration option allowing to configure language server-specific options.
83
+ # Maps the language key to the options.
84
+ # The settings are considered only if the project is trusted (see global configuration to define trusted projects).
85
+ # See https://oraios.github.io/serena/02-usage/050_configuration.html#language-server-specific-settings
86
+ ls_specific_settings: {}
87
+
88
+ # list of workspace folder paths (LSP backend only).
89
+ # These folders will be used to build up Serena's symbol index.
90
+ # Paths must be within the project root and should thus be relative to the project root.
91
+ # Furthermore, the paths should not be filtered by ignore settings.
92
+ # Default setting: The entire project root folder (".") is considered.
93
+ # In (large) monorepos, this can be used to index only subfolders of the project root, e.g.
94
+ # ls_workspace_folders:
95
+ # - "./subproject1"
96
+ # - "./subproject2"
97
+ ls_workspace_folders:
98
+ - "."
99
+
100
+ # list of additional workspace folder paths for cross-package reference support.
101
+ # Paths can be absolute or relative to the project root.
102
+ # Each folder is registered as an LSP workspace folder, enabling language servers to discover
103
+ # symbols and references across package boundaries, but these folders are not indexed by Serena,
104
+ # i.e. the respective symbols will not be found using Serena's symbol search tools.
105
+ # Example:
106
+ # additional_workspace_folders:
107
+ # - ../sibling-package
108
+ # - ../shared-lib
109
+ ls_additional_workspace_folders: []
110
+
111
+ # list of additional paths to ignore in this project.
112
+ # Same syntax as gitignore, so you can use * and **.
113
+ # Important: quote patterns that start with `*`, otherwise YAML treats them as aliases.
114
+ # Example:
115
+ # ignored_paths:
116
+ # - "examples/**"
117
+ # - ".worktrees/**"
118
+ # - "**/bin/**"
119
+ # - "**/obj/**"
120
+ # Note: global ignored_paths from serena_config.yml are also applied additively.
121
+ ignored_paths: []
122
+
123
+ # whether the project is in read-only mode
124
+ # If set to true, all editing tools will be disabled and attempts to use them will result in an error
125
+ # Added on 2025-04-18
126
+ read_only: false
127
+
128
+ # list of tool names to exclude.
129
+ # This extends the existing exclusions (e.g. from the global configuration)
130
+ # Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
131
+ excluded_tools: []
132
+
133
+ # list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).
134
+ # This extends the existing inclusions (e.g. from the global configuration).
135
+ # Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
136
+ included_optional_tools: []
137
+
138
+ # fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
139
+ # This cannot be combined with non-empty excluded_tools or included_optional_tools.
140
+ # Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
141
+ fixed_tools: []
142
+
143
+ # list of APIs (facades or facade methods, e.g. "lsp" or "lsp.find_symbol") to exclude from the REPL.
144
+ # This extends the existing exclusions (e.g. from the global configuration).
145
+ excluded_apis: []
146
+
147
+ # list of APIs (facades or facade methods, e.g. "lsp" or "lsp.get_diagnostics_for_symbol") to include in the REPL
148
+ # that would otherwise be disabled (particularly optional methods, which are disabled by default).
149
+ # This extends the existing inclusions (e.g. from the global configuration).
150
+ included_apis: []
151
+
152
+ # list of mode names that are to be activated by default, overriding the setting in the global configuration.
153
+ # The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
154
+ # If the setting is undefined/empty, the default_modes from the global configuration (serena_config.yml) apply.
155
+ # Otherwise, this overrides the setting from the global configuration (serena_config.yml).
156
+ # Therefore, you can set this to [] if you do not want the default modes defined in the global config to apply
157
+ # for this project.
158
+ # This setting can, in turn, be overridden by CLI parameters (--mode).
159
+ # See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
160
+ default_modes:
161
+
162
+ # list of mode names to be activated additionally for this project, e.g. ["query-projects"]
163
+ # The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
164
+ # See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
165
+ added_modes:
166
+
167
+ # initial prompt for the project. It will always be given to the LLM upon activating the project
168
+ # (contrary to the memories, which are loaded on demand).
169
+ initial_prompt: ""
170
+
171
+ # time budget (seconds) per tool call for the retrieval of additional symbol information
172
+ # such as docstrings or parameter information.
173
+ # This overrides the corresponding setting in the global configuration; see the documentation there.
174
+ # If null or missing, use the setting from the global configuration.
175
+ symbol_info_budget:
176
+
177
+ # list of regex patterns which, when matched, mark a memory entry as read‑only.
178
+ # Extends the list from the global configuration, merging the two lists.
179
+ read_only_memory_patterns: []
180
+
181
+ # list of regex patterns for memories to completely ignore.
182
+ # Matching memories will not appear in list_memories or activate_project output
183
+ # and cannot be accessed via read_memory or write_memory.
184
+ # To access ignored memory files, use the read_file tool on the raw file path.
185
+ # Extends the list from the global configuration, merging the two lists.
186
+ # Example: ["_archive/.*", "_episodes/.*"]
187
+ ignored_memory_patterns: []
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ProximaLink / Pakheria
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.
@@ -0,0 +1,338 @@
1
+ Metadata-Version: 2.5
2
+ Name: featuregraph-cli
3
+ Version: 0.1.0
4
+ Summary: Token-efficient, AST-indexed feature topology map for AI coding agents to eliminate AI amnesia.
5
+ Project-URL: Homepage, https://github.com/Pakheria/featuregraph
6
+ Project-URL: Repository, https://github.com/Pakheria/featuregraph.git
7
+ Project-URL: Issues, https://github.com/Pakheria/featuregraph/issues
8
+ Author-email: ProximaLink <faizan@proximalink.pk>, Pakheria <faizan@proximalink.pk>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agentic-ai,ai,antigravity,ast,claude-code,code-indexing,context-window,cursor,feature-graph,llm,polyglot-ast,token-optimization
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Code Generators
20
+ Classifier: Topic :: Software Development :: Documentation
21
+ Requires-Python: >=3.10
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=8.0; extra == 'dev'
24
+ Requires-Dist: ruff>=0.6; extra == 'dev'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # FeatureGraph ⚡
28
+
29
+ > **AST-indexed feature topology maps for AI coding agents: exact line spans, inferred call edges, and a contract gate for changes. Zero runtime dependencies.**
30
+
31
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
32
+ [![Python Version](https://img.shields.io/badge/Python-3.10%2B-blue)](pyproject.toml)
33
+ [![GitHub Repository](https://img.shields.io/badge/GitHub-Pakheria%2Ffeaturegraph-black?logo=github)](https://github.com/Pakheria/featuregraph)
34
+
35
+ ![FeatureGraph Demo — impact & strict security gate](assets/demo.gif)
36
+
37
+ ---
38
+
39
+ ## 🎯 The Problem
40
+
41
+ 1. **No caller visibility:** An AI coding agent editing a function cannot see who calls it across files. Unreferenced-looking helpers and security gates get deleted, and downstream callers break.
42
+ 2. **Context spend:** Pasting whole files every turn costs tokens and pushes relevant code out of the window.
43
+ 3. **Coarse graphs:** Many graph tools produce file-level nodes, so the agent still has to open the file.
44
+ 4. **No change gate:** Nothing tells the agent which endpoints, auth boundaries, invariants, and tests a change touches.
45
+
46
+ FeatureGraph addresses these with a small index of named features, exact line ranges, deterministic call edges, and two commands built for the edit loop: `impact` and `check`.
47
+
48
+ ---
49
+
50
+ ## ⚡ How It Works
51
+
52
+ ```text
53
+ AI Coding Agent / Developer
54
+ │
55
+ ▼
56
+ [1. Read .featuregraph/manifest.json] ──> Tier-1: category -> feature names
57
+ │
58
+ ▼
59
+ [2. Read categories/<category>.json] ──> Tier-2: exact #Lstart-Lend per feature
60
+ │
61
+ ▼
62
+ [3. Edit only that span] ──> impact <id> first, impact --diff after
63
+ │
64
+ ▼
65
+ [4. Commit] ──> pre-commit hook rescans the index
66
+ ```
67
+
68
+ The index is generated in two passes:
69
+
70
+ 1. **Symbol indexing:** parse every supported file, map tagged declarations to feature IDs, and assign deterministic symbol IDs (bare when unique, path-qualified on collision).
71
+ 2. **Dependency inference:** walk each feature's span, collect call sites, decorators, class bases, dependency-injection arguments, imports, JSX tags, and inheritance, then wire `depends_on` / `called_by`.
72
+
73
+ Inference is textual/AST based, not a full type-checker. It resolves names by path affinity (same file > same directory > longest shared path); equally-near candidates are all kept rather than dropping the edge.
74
+
75
+ ---
76
+
77
+ ## 📦 Index Layout
78
+
79
+ | Artifact | Contents |
80
+ | :--- | :--- |
81
+ | `.featuregraph/manifest.json` | Tier-1 directory: category -> feature IDs and names, plus `_meta` |
82
+ | `.featuregraph/categories/<category>.json` | Tier-2 map: locations (`file`, `lines`), dependencies, contract tags |
83
+ | `.featuregraph/index.json` | Full graph (`features` + `_meta`) |
84
+ | `.featuregraph/graph.md` | Markdown table and Mermaid dependency diagram |
85
+ | `.featuregraph/unindexed.json` | Files that failed to parse (Python AST syntax errors, brace-unbalanced JS/TS files, or read errors) |
86
+ | `AGENTS.md` | Agent short-circuit directive (read the manifest first) |
87
+ | `.git/hooks/pre-commit` | Rescans and stages `.featuregraph/` when it is not gitignored |
88
+
89
+ `_meta.tree_hash` is a SHA-256 over sorted `(relative path, file bytes)` plus `.featureignore`. Content hashing means a `touch` or a checkout without edits is a no-op, and a same-size edit is still detected. `query`/`search` refuse stale results unless `--force` is passed.
90
+
91
+ `_meta.status` is `ok` (everything parsed), `partial` (some files yielded no named symbols), or `empty` (no features). A Python AST syntax error or a brace-unbalanced JS/TS file is the only thing that makes the manifest unreliable, reported as `unparsed_syntax_errors > 0`. Files indexed at file granularity (tests, scripts, configs) are reported separately as `_meta.file_level_files` and do not invalidate the manifest.
92
+
93
+ ---
94
+
95
+ ## 🧠 Dependency Resolution
96
+
97
+ - **Python:** AST call sites, decorator references, class bases, and dependency-injection wrappers (`Depends`, `Security`, `Body`, `Header`, `Cookie`). Import aliases (`import x as y`, `from m import a as b`) resolve to the original symbol.
98
+ - **TypeScript / JavaScript:** call sites, JSX component tags, `extends`/`implements`, ES `import` bindings, and CommonJS `require()` bindings from the code-only view (strings and comments masked).
99
+ - **Other languages:** call sites, inheritance, and route patterns from a lexed code-only view.
100
+ - **Manual edges:** `@depends [ID]` / `@depends_on [ID]` add explicit edges; dangling references are reported as `unresolved_depends`.
101
+ - **Containment guard:** a tagged method inside a tagged class does not create a fake class <-> method cycle from overlapping spans alone.
102
+
103
+ Isolated features (no dependencies, no callers) are listed in `graph.md` for dead-code review.
104
+
105
+ ---
106
+
107
+ ## 🏷️ Tag Rules & Coverage
108
+
109
+ Tags count only on a **real comment line**. Every parser, the annotator, and dependency inference share one lexical mask, so a tag inside a string, template literal, or Python docstring can never create a feature. Real comment lines are honoured in every language, including `//`, `#`, and `/* ... */`.
110
+
111
+ | Language | Tag placement | Symbol window |
112
+ | :--- | :--- | :--- |
113
+ | Python | Comment above `def` / `class` | 6 lines above |
114
+ | TypeScript / JS | Comment above the export | 6 lines below the tag |
115
+ | Go, Rust, Java, C#, PHP, Ruby, Swift, Dart, Shell | Comment above the declaration | 6 lines below the tag |
116
+
117
+ ### Line spans
118
+
119
+ - **Python:** exact, from the AST (`lineno`..`end_lineno`).
120
+ - **TypeScript / JS:** the tag attaches to the export within 6 lines below it. The end line is found by brace-matching from the declaration's opening brace on the masked view, so braces in strings, comments, and template literals cannot close the block early. `const X = () => (` JSX arrows track balanced parentheses the same way. A fixed 35-line fallback is used only when no block brace is found (single-line or unbraced expressions).
121
+ - **Other languages:** brace matching (or `def`/`end` counting for Ruby) from the declaration.
122
+
123
+ ### Untagged coverage
124
+
125
+ | Source | Auto feature IDs |
126
+ | :--- | :--- |
127
+ | Untagged `.js` | `CJS-<path>-<symbol>` for classes, functions, arrow functions, class/prototype methods, and `exports`/`module.exports` members |
128
+ | Untagged `.ts` / `.tsx` / `.jsx` | `TS-<path>-<symbol>` for exported declarations |
129
+ | Untagged Django `models.py` (or any class with a Django model base) | `MODEL-<path>-<symbol>` |
130
+ | Untagged Django `settings.py` (`UPPER_CASE` names) | `CONFIG-<path>-<symbol>`; sensitive key names (`SECRET`, `PASSWORD`, `TOKEN`, `API_KEY`, `PRIVATE_KEY`, `DATABASE_URL`, `CREDENTIAL`) are redacted and never emit values |
131
+ | Any supported file with no named symbols | `FILE-<path>` file-level entry (counted in `_meta.file_level_files`) |
132
+
133
+ Tagged files keep tag-only behavior, so adding explicit tags never churns existing IDs or inferred edges.
134
+
135
+ `featuregraph annotate` suggests tags for un-annotated symbols, refuses insertion points that are not code, writes atomically, and re-parses every write; a tag that would not round-trip restores the original file.
136
+
137
+ ---
138
+
139
+ ## 🔐 Contract Tags & Anti-Slop Workflow
140
+
141
+ Three additional comment-only tags describe the contracts a change must not break:
142
+
143
+ ```python
144
+ # @feature [BILLING-CHARGE] Charge endpoint
145
+ # @boundary [auth, tenant]
146
+ # @invariant Amounts stay in integer cents; never charge twice for one idempotency key.
147
+ # @test tests/test_billing.py::test_charge_is_idempotent, tests/test_billing.py::test_amount_rounding
148
+ @router.post("/charge")
149
+ def charge(...):
150
+ ...
151
+ ```
152
+
153
+ - `@boundary [a, b]` — security boundary the feature sits behind. Normalised lowercase, stored as `boundaries`.
154
+ - `@invariant <text>` — repeatable rule to preserve. Stored under `invariants`.
155
+ - `@test <path>::<nodeid>` — repeatable test selector (single value or comma/space separated list). Stored under `tests`.
156
+
157
+ Empty values are omitted from the JSON. `featuregraph impact` reports them; `featuregraph check --strict` enforces boundaries on endpoints.
158
+
159
+ **Before editing shared code:**
160
+
161
+ ```bash
162
+ featuregraph impact <feature_id> # callers, endpoints, boundaries, invariants, tests
163
+ ```
164
+
165
+ **After editing:**
166
+
167
+ ```bash
168
+ featuregraph impact --diff # verify the blast radius of the change
169
+ featuregraph check --strict
170
+ ```
171
+
172
+ Prints `touched` features, transitive `downstream` callers, `affected_endpoints`, `boundaries` crossed, `invariants` to preserve, and `tests` to run. Add `--json` for agents, or `--staged` to inspect staged changes instead of the working tree.
173
+
174
+ **Before declaring a task complete:**
175
+
176
+ ```bash
177
+ featuregraph check --strict
178
+ ```
179
+
180
+ Exit 0 = pass, exit 1 = fail. Always fails when the index is missing, corrupt, or stale, or when there are syntax errors, unresolved `@depends`, or duplicate feature IDs. `--strict` also fails on dependency cycles and on any endpoint (`ROUTE-*` / `type: endpoint`) with no `@boundary` and no dependency on an `auth`/`admin`/`tenant`/`internal` guarded feature. Mark intentionally public routes `@boundary [public]`.
181
+
182
+ ---
183
+
184
+ ## 🚨 Scan Warnings
185
+
186
+ Warnings are aggregated to one line each per scan:
187
+
188
+ ```bash
189
+ ⚠ 6 file(s) with no parseable features (untagged, unreadable, or syntax error): src/legacy.py, … (+3 more)
190
+ ⚠ 1 unresolved @depends reference(s) — no such feature: DANGLE-01 → GHOST-77
191
+ ```
192
+
193
+ ### Symbol IDs & collisions
194
+
195
+ A tagged location's symbol ID is its bare symbol when unique (`validate_token`) and a deterministic path prefix on collision (`web.app.layout` vs `web.app.docs.layout`; if the directory still repeats, the full path is used). Explicit `@feature [ID]` tags remain the canonical feature ID.
196
+
197
+ `query`, `search`, and `impact` accept a feature ID, a qualified symbol ID, or an unambiguous bare symbol. An ambiguous bare name exits 1 and lists the candidate qualified IDs.
198
+
199
+ ---
200
+
201
+ ## ⚡ Fast AST Feature Search
202
+
203
+ ```bash
204
+ featuregraph search "parser"
205
+ # Output gives exact file paths and surgical #Lstart-Lend ranges:
206
+ # • featuregraph/core/parser_py.py #L10-L95 (PythonFeatureParser)
207
+
208
+ featuregraph query web.app.docs.layout # qualified symbol ID
209
+ featuregraph query layout # ambiguous -> exit 1 + candidate IDs
210
+ ```
211
+
212
+ ---
213
+
214
+ ## 🚀 Installation & Quickstart
215
+
216
+ ### 1. Install via pip / uv (direct from GitHub)
217
+ ```bash
218
+ pip install git+https://github.com/Pakheria/featuregraph.git
219
+
220
+ # Or install as an isolated CLI tool:
221
+ uv tool install git+https://github.com/Pakheria/featuregraph.git
222
+ ```
223
+
224
+ ### 2. Initialize in Your Repository
225
+ ```bash
226
+ cd your-project
227
+ featuregraph init
228
+ ```
229
+
230
+ This command:
231
+ - scans the codebase and writes `.featuregraph/manifest.json`, `.featuregraph/categories/`, `.featuregraph/index.json`, `.featuregraph/graph.md`
232
+ - creates or extends the **`AGENTS.md`** short-circuit directive
233
+ - installs the workspace agent skill at `.agents/skills/featuregraph/SKILL.md`
234
+ - installs `.git/hooks/pre-commit` when no foreign pre-commit hook exists
235
+
236
+ The hook rescans on commit, skips when unstaged or untracked changes are present, and stages `.featuregraph/` only when `git check-ignore` says it is not ignored. It never force-adds a gitignored directory.
237
+
238
+ ### 3. Install Global Agent Skills
239
+ ```bash
240
+ featuregraph skill --global
241
+ ```
242
+
243
+ Targets: `~/.agents`, `~/.gemini/config`, `~/.claude/skills`, `~/.cursor/skills`, `~/.config/opencode/skills`.
244
+
245
+ ---
246
+
247
+ ## 🌐 Multi-Language Support
248
+
249
+ | Language | Extensions | Comment style |
250
+ | :--- | :--- | :--- |
251
+ | **Python** | `.py` | `# @feature [ID] Name` |
252
+ | **TypeScript / JavaScript** | `.ts`, `.tsx`, `.js`, `.jsx` | `// @feature [ID] Name` |
253
+ | **Go** | `.go` | `// @feature [ID] Name` |
254
+ | **Rust** | `.rs` | `// @feature [ID] Name` |
255
+ | **Java / Kotlin** | `.java`, `.kt`, `.kts` | `// @feature [ID] Name` |
256
+ | **C# / .NET** | `.cs` | `// @feature [ID] Name` |
257
+ | **C / C++** | `.c`, `.cpp`, `.cc`, `.h`, `.hpp` | `// @feature [ID] Name` |
258
+ | **PHP** | `.php` | `// @feature [ID] Name` |
259
+ | **Ruby** | `.rb` | `# @feature [ID] Name` |
260
+ | **Swift / Dart** | `.swift`, `.dart` | `// @feature [ID] Name` |
261
+ | **Shell** | `.sh`, `.bash`, `.zsh` | `# @feature [ID] Name` |
262
+
263
+ Go double-quoted strings honour backslash escapes; backtick raw strings do not. The lexer handles both, so `\"` inside a Go string never leaks a fake comment.
264
+
265
+ ---
266
+
267
+ ## 🛠️ CLI Reference
268
+
269
+ ```bash
270
+ featuregraph --help
271
+
272
+ # Initialize repo, pre-commit hook, AGENTS.md directive and workspace skill
273
+ featuregraph init
274
+
275
+ # Auto-suggest and write @feature tags for un-annotated symbols
276
+ featuregraph annotate --dry-run
277
+ featuregraph annotate --yes
278
+ featuregraph annotate --dir ./src --limit 50 --yes
279
+
280
+ # Scan codebase, infer call edges, rebuild the 2-tier index
281
+ featuregraph scan
282
+ featuregraph scan --dir ./my-project --json index.json --md GRAPH.md --quiet
283
+
284
+ # Query exact lines and dependencies for a feature or symbol ID
285
+ featuregraph query AUTH-01
286
+ featuregraph query AUTH-01 --json
287
+ featuregraph search "parser" --dir ./app --json
288
+
289
+ # Blast radius: impact <feature_id> before editing, impact --diff after
290
+ featuregraph impact AUTH-01
291
+ featuregraph impact --diff
292
+ featuregraph impact --staged --json
293
+
294
+ # Enforcement gate (exit 0 = pass, 1 = fail)
295
+ featuregraph check
296
+ featuregraph check --strict
297
+ featuregraph check --strict --rescan --json
298
+
299
+ # Agent skills
300
+ featuregraph skill --install
301
+ featuregraph skill --global
302
+ featuregraph skill --show
303
+
304
+ # Pre-commit hook
305
+ featuregraph hook --install
306
+ featuregraph hook --uninstall
307
+ ```
308
+
309
+ ---
310
+
311
+ ## 🤖 AI Agent Integration Protocol
312
+
313
+ 1. **Auto-discovery:** agents find the `/featuregraph` skill in `.agents/skills/` or their global config.
314
+ 2. **Short-circuit directive:** `AGENTS.md` tells the agent to read `.featuregraph/manifest.json` instead of walking the tree.
315
+ 3. **Exact slices:** the agent reads only the target `#Lstart-Lend` span.
316
+ 4. **Impact before and after edit:** `featuregraph impact <feature_id>` names the callers, endpoints, boundaries, invariants, and tests at risk before editing; `featuregraph impact --diff` verifies the blast radius afterwards.
317
+ 5. **Gate before done:** `featuregraph check --strict` plus the reported tests.
318
+
319
+ ---
320
+
321
+ ## 🔄 CI Gate (GitHub Actions)
322
+
323
+ Drop FeatureGraph into pull requests to block stale indexes, broken `@depends`, cycles, and unguarded endpoints:
324
+
325
+ ```yaml
326
+ - name: FeatureGraph security gate
327
+ run: |
328
+ pip install git+https://github.com/Pakheria/featuregraph.git
329
+ featuregraph check --rescan --strict
330
+ ```
331
+
332
+ Want to try `impact` and `check --strict` in 10 seconds? See [`examples/fastapi-react-demo/`](examples/fastapi-react-demo/README.md).
333
+
334
+ ---
335
+
336
+ ## 📄 License
337
+
338
+ MIT © [ProximaLink](https://proximalink.pk) / [Pakheria](https://github.com/Pakheria)