Commit graph

458 commits

Author SHA1 Message Date
abhigyanpatwari
d6878dcec6 fix(web): resolve Vercel build errors from security hardening PR
- ProcessFlowModal: revert import from non-existent @/lib/lucide-icons back to lucide-react
- embedding-pipeline: remove extra argument in executeQuery call (signature only accepts 1 arg)

Both issues were introduced in PR #475 (web-security-hardening).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 19:21:37 +05:30
Gergő Magyar
519dc3eccc
Merge pull request #475 from jreakin/fix/web-security-hardening
fix(web): Cypher injection guards, DOMPurify SVG, readOnly executeQuery
2026-03-23 13:21:03 +00:00
Gergo Magyar
ffabe857a3 fix(docs): update symbol and relationship counts in AGENTS.md and CLAUDE.md 2026-03-23 11:15:56 +00:00
jreakin
57e087de49 fix(web): strip quoted strings before readOnly keyword check
The readOnly guard was matching keywords inside string literals,
blocking legitimate queries like WHERE n.name CONTAINS "delete".
Now strips single/double-quoted strings before checking, so only
actual Cypher write keywords outside strings are blocked.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 05:09:44 -05:00
jreakin
fc6c114570 fix(web): MermaidDiagram XSS, isSafeId allows @, rawMermaid typed
- Add DOMPurify.sanitize() to MermaidDiagram.tsx dangerouslySetInnerHTML
  (was rendering AI-generated SVG unsanitized — the highest-risk surface)
- Add @ to isSafeId regex for scoped npm packages (@angular/core, etc.)
- Add rawMermaid to ProcessData interface, remove (process as any) casts
- Update security tests: @scope/pkg now accepted, @angular/core added

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 05:01:57 -05:00
Gergo Magyar
43d866c802 chore: bump version to 1.4.8, update CHANGELOG.md 2026-03-23 09:53:43 +00:00
Gergő Magyar
6b0c566392
Merge pull request #461 from ShunsukeHayashi/fix/python-import-alias-417
fix(ingestion): resolve Python import-alias CALLS edges
2026-03-23 09:46:39 +00:00
jreakin
96181fba05 fix: pass readOnly=false for CREATE_VECTOR_INDEX in embedding pipeline
The readOnly=true default on executeQuery blocks queries containing
CREATE, which includes CALL CREATE_VECTOR_INDEX. The embedding pipeline
needs write access for this setup step.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 04:45:09 -05:00
jreakin
208ade9b11 fix: add / back to isSafeId — node IDs contain file paths
Node IDs are generated as Label:filePath (e.g., Function:src/foo.ts:bar),
so forward slashes are expected in legitimate IDs. The over-tightened
regex was dropping all path-based IDs from Cypher queries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 04:45:09 -05:00
jreakin
9f14edc226 fix(web): security hardening — Cypher injection, XSS, readOnly, prepared statements
- DOMPurify.sanitize() on mermaid SVG in ProcessFlowModal
- validLabel()/validRelType() guards on all Cypher interpolation in tools.ts
- isSafeId() strict regex in ProcessesPanel (no spaces/slashes/metacharacters)
- executeQuery defaults readOnly=true (rejects CREATE/DELETE/DROP/etc.)
- Singleton promise for initLbug (prevents concurrent init races)
- Prepared statements for relation inserts (batched by label pair)
- executeWithReusedStatement for enrichment updates
- try/finally on all PreparedStatement cleanup
- 99 security guard tests (validLabel, validRelType, isSafeId, readOnly regex)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 04:45:09 -05:00
Gergo Magyar
cb1293b718 fix(python): route module aliases directly to moduleAliasMap in import processor
`import models as m` aliases were stored in namedImportMap (a symbol-binding
map) then cross-referenced in pipeline.ts — semantic misuse and inefficient.

Refactored: NamedBinding gains `isModuleAlias` flag. applyImportResult routes
tagged bindings directly to moduleAliasMap at import time. Removes the
pipeline.ts post-processing loop entirely.

Added test fixture and 5 integration tests for `import X as Y` with
multi-module disambiguation (both models.py and auth.py export User).
2026-03-23 09:36:33 +00:00
Gergő Magyar
6c9b6eb0f6
Merge pull request #474 from jreakin/fix/web-lbug-server-highlights
fix(web): LadybugDB getAllRows, loadServerGraph, BM25, highlight clearing
2026-03-23 09:36:27 +00:00
jreakin
3558cb8a7f chore: simplify prepare script, remove scripts/prepare.cjs
.husky/pre-commit is committed to the repo — developers get the hook
by cloning, not by running npm install. prepare only needs to build
TypeScript for npm publish/pack.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 04:18:02 -05:00
Shunsuke Hayashi
9f2d1780d5 fix(ingestion): resolve Python import-alias CALLS edges (#417)
`import numpy as np` and `from models import User as U` previously
generated no CALLS edges because:

1. `import_statement` with an `aliased_import` child was not captured
   by the tree-sitter query for Python imports.
2. `extractPythonNamedBindings()` only handled `import_from_statement`,
   ignoring plain `import X as Y` forms.

Changes:
- `tree-sitter-queries.ts`: add query pattern for
  `(import_statement name: (aliased_import name: (dotted_name)))` so
  the import path is captured before named-binding extraction runs.
- `named-binding-extraction.ts`: extend `extractPythonNamedBindings()`
  to handle `import_statement` nodes carrying `aliased_import` children.
  Records `{ local: "np", exported: "numpy" }` so call-sites using the
  alias resolve to the real module.
- `test/fixtures/lang-resolution/python-alias-imports/`: update fixtures
  used by `python.test.ts` to exercise `from models import User as U`.

Existing tests in `test/integration/resolvers/python.test.ts`
(suite "Python alias import resolution") cover this path.
2026-03-23 09:17:43 +00:00
Gergő Magyar
a57550815f
Merge pull request #463 from ShunsukeHayashi/fix/python-calls-zero-337
fix(python): resolve module-qualified constructor calls — 0 CALLS edges (Issue #337)
2026-03-23 08:59:21 +00:00
jreakin
ee78ebe64a test: add positive and negative tests for all 4 bug fixes
16 tests covering the data structures and logic underlying each fix:

createKnowledgeGraph (loadServerGraph data flow):
  + nodes stored correctly via addNode
  + relationships stored correctly via addRelationship
  + deduplication by ID
  + nodeCount reflects unique count
  - empty graph has zero counts
  - relationships with non-existent nodes still stored

loadServerGraph data flow:
  + server data reconstructs into valid KnowledgeGraph
  + fileContents Map built from server entries
  - empty server data produces empty graph
  - fileContents replaces (not accumulates) on reload

BM25 index argument type:
  + Map<string, string> has entries() for BM25
  - KnowledgeGraph does NOT have entries() (the original bug)

Highlight clearing:
  + clearing Set produces empty set
  + independent highlight sources cleared separately
  - clearing highlights doesn't affect node selection
  - toggling AI ON doesn't clear process highlights

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 03:48:27 -05:00
Gergo Magyar
141f864181 refactor: use boolean[] for O(1) per-chunk synthesis guard
Replace Set<number> + flatMap with a simple boolean array indexed by
chunk — cleaner data structure for sequential integer keys.
2026-03-23 08:47:21 +00:00
jreakin
01fa5bf98e fix: address review — stale progress, cross-platform prepare, DEV log
- Clear progress after handleServerConnect in both auto-connect and
  DropZone paths (fixes frozen progress bar on StatusBar)
- Replace shell-based prepare script with Node scripts/prepare.cjs
  for Windows cmd.exe compatibility
- Gate LadybugDB load warning behind import.meta.env.DEV (consistent
  with finalizePipeline's silent catch)
- Remove misleading "parallel" comment (fetch is sequential after connect)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 03:26:32 -05:00
Gergo Magyar
bbd95457df test(python): strengthen module-import tests, un-skip match/case, add perf guard
- Rewrite Issue #337 test suite: 5 tests → 19 tests with exact node/edge
  counts, sourceFilePath guards, negative tests, method call disambiguation
  (u.save(), a.login(), v.verify()), HAS_METHOD verification, and
  cross-module collision assertions
- Un-skip 2 match/case as-pattern tests (they pass now) and remove leftover
  DEBUG test
- Add per-chunk language guard for synthesizeWildcardImportBindings — skips
  full graph traversal for TS/JS-only chunks, avoiding O(chunks × graph_size)
- Rename fixture method check → verify to avoid BUILT_IN_NAMES noise filter
- Expand fixture with method calls on constructor-inferred receivers
- Fix stale comment referencing only "Go package imports"
2026-03-23 08:25:46 +00:00
jreakin
d43cc691f0 chore: switch from .githooks to husky for pre-commit hooks
Per maintainer request. Husky is activated via `cd .. && husky` in the
prepare script. The pre-commit hook mirrors CI: typecheck + unit tests
for both packages when relevant files are staged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 03:18:04 -05:00
Shunsuke Hayashi
f90aabf9a8 fix(python): resolve module-qualified calls via moduleAliasMap
Previously, Python was added to WILDCARD_IMPORT_LANGUAGES which expanded
all exported symbols into namedImportMap using first-seen wins. This caused
`auth.User()` to incorrectly resolve to `models.py:User` when both modules
exported a class named User.

Root cause: Python `import models` is a namespace import, not wildcard
symbol expansion. Expanding all symbols produces ambiguous bindings that
cannot be disambiguated later.

Fix:
- Remove Python from WILDCARD_IMPORT_LANGUAGES
- Add ModuleAliasMap (callerFile → alias → sourceFile) to ResolutionContext
- In synthesizeWildcardImportBindings, build moduleAliasMap for Python
  using the filename stem as the module alias
- In resolveCallTarget, add module-alias disambiguation step: when multiple
  candidates survive filtering and the receiver name matches a module alias,
  narrow candidates to the aliased file

Result: `models.User()` → models.py:User, `auth.User()` → auth.py:User
even when both modules export a class named User.

Adds regression test for the ambiguity case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:33:06 +09:00
jreakin
beb5574d38 chore: add pre-commit hook for typecheck + unit tests
Adds .githooks/pre-commit mirroring CI checks:
- gitnexus-web/: tsc -b --noEmit + vitest run (if web files staged)
- gitnexus/: tsc --noEmit + vitest run --project default (if CLI files staged)

Activated via git config core.hooksPath in the prepare script.
Skip with git commit --no-verify.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 02:31:02 -05:00
jreakin
d48903cce6 fix(web): LadybugDB getAllRows, loadServerGraph, BM25, highlight clearing
- Replace result.getAll() with result.getAllRows() across lbug-adapter
  (getAll doesn't exist in LadybugDB WASM v0.15.1)
- Add loadServerGraph worker method that pipes server data through
  initLbug/loadGraphToLbug for in-browser querying
- Extract finalizePipeline helper (shared by runPipeline, runPipelineFromFiles)
- Fix buildBM25Index called with graph object instead of fileContents Map
- Fix 'Turn off all highlights' to clear sigma selection, AI tool/citation
  highlights, and blast radius

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 02:25:59 -05:00
Zander Raycraft
a3fac2f672
Merge pull request #395 from zm2231/feat/http-embedding-backend 2026-03-22 21:47:53 -05:00
zm2231
9954f6fdfd fix: timeout detection, always-on dim validation, test hardening
- Fix timeout detection: AbortSignal.timeout() throws TimeoutError, not
  AbortError. Timeouts are no longer retried (30s fail, not 93s).
- Validate embedding dimensions in both httpEmbed and httpEmbedQuery
  against config.dimensions or the 384d schema default. When DIMS is
  unset, the error says 'Set GITNEXUS_EMBEDDING_DIMS=N' to guide users.
- Centralize test env var cleanup in afterEach via savedEnv snapshot.
- Test mocks use 384d vectors matching schema default.
- 4 new tests: timeout not retried, network retry success, query path
  dim mismatch, unset-dims hint. 23 total, all pass.
2026-03-22 20:21:08 -04:00
B. Lawrence Sharma
90ca43f851
feat(ui): ship HelpPanel — because great tools don't make you google how to use them (#465)
* remove friction in onboarding by correcting typo

* Revert "remove friction in onboarding by correcting typo"

This reverts commit 07dec38c2c.

* feat(ui): add HelpPanel component with tabbed reference, node legend, AI query guide, and dual Mac/Windows keyboard shortcuts

* feat(ui): add HelpPanel component with tabbed reference, node legend, AI query guide, and dual Mac/Windows keyboard shortcuts

* made changes based on the suggestions

* minor fix
2026-03-23 03:25:01 +05:30
Zander Raycraft
0a200a51cb
Merge pull request #400 from JayceeB1/fix/server-mode-worker-hydration
closes issue #398
2026-03-22 14:28:05 -05:00
JayceeB1
c87cb81892 fix: await server connect hydration flow 2026-03-22 19:54:37 +01:00
Zander Raycraft
b8ab23a838
Merge pull request #464 from zander-raycraft/main
update method for labeling prs
2026-03-22 12:06:32 -05:00
Zander Raycraft
e70a6d80c0
Merge pull request #10 from zander-raycraft/gh/issue-pr-filter
redoing auto labeling using z score instead of clustering lowkey the …
2026-03-22 12:05:35 -05:00
Shunsuke Hayashi
cd1c0ff7dc fix(python): resolve module-qualified constructor calls (Issue #337)
Python repos were producing 0 CALLS edges for module-qualified constructor
calls like `models.User()` where `import models` is a bare module import.

Root causes:
1. `SupportedLanguages.Python` was absent from `WILDCARD_IMPORT_LANGUAGES`,
   so `synthesizeWildcardImportBindings` never ran for Python files — bare
   module imports never received per-symbol namedImportMap bindings.

2. Synthesis only ran in the Phase 14 pre-pass, after all chunks had already
   been call-resolved. When `models.User()` was processed in Phase 3+4,
   `namedImportMap` was empty for Python → Tier 2a-named fell through to
   Tier 2a which found both `models.py:User` and `auth.py:User` (ambiguous).

3. `filterCallableCandidates` with `callForm='member'` excluded `Class` nodes
   (only `CALLABLE_SYMBOL_TYPES` = Function/Method/Constructor/…). With 2
   ambiguous Class candidates both were dropped, producing 0 CALLS edges.

Fixes:
- Add `SupportedLanguages.Python` to `WILDCARD_IMPORT_LANGUAGES` so that
  `import models` expands to per-symbol namedImportMap entries (first-seen
  semantics: `User→models.py:User`, `Admin→auth.py:Admin`).

- Call `synthesizeWildcardImportBindings` inline in the chunk loop, after
  `processImportsFromExtracted` but BEFORE `processCallsFromExtracted`. This
  ensures Tier 2a-named can disambiguate `module.ClassName()` at initial
  call-resolution time. The Phase 14 pre-pass remains as a final safety net.

- Add a fallback in `resolveCallTarget`: if `callForm='member'` yields 0
  filtered candidates, retry with `callForm='constructor'`. This handles the
  case where a module-qualified class instantiation (e.g. `models.User()`)
  is syntactically an attribute-access call but semantically a constructor
  call. The fallback only triggers for 0-candidate member calls, so it
  cannot over-eagerly promote normal member calls.

Tests: add `python-module-import` fixture (models.py/auth.py/app.py) with
4 regression tests covering IMPORTS edges, name-collision disambiguation
for `models.User()`, and `auth.Admin()`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 00:26:00 +09:00
Gergő Magyar
907440cf0b
Merge pull request #427 from ShunsukeHayashi/fix/impact-confidence-412 2026-03-22 10:11:11 +00:00
Gergő Magyar
843c561e9b
Merge pull request #425 from ShunsukeHayashi/fix/db-lock-325 2026-03-22 09:40:25 +00:00
Gergő Magyar
4c8be50cb1
Merge pull request #424 from ShunsukeHayashi/fix/lan-cors-390 2026-03-22 09:39:42 +00:00
Shunsuke Hayashi
d07a69c3b1 fix(server): allow private/LAN network origins in CORS (#390)
Allow RFC 1918 private network ranges in the CORS origin allowlist so
users running GitNexus on their home or office LAN can access the web UI
from another device on the same network.

Permitted private ranges:
  10.0.0.0/8      (10.x.x.x)
  172.16.0.0/12   (172.16.x.x – 172.31.x.x)
  192.168.0.0/16  (192.168.x.x)

The origin check is extracted into an exported isAllowedOrigin() helper
so it can be unit-tested in isolation.  A new test file covers:
  - No origin (curl / server-to-server)
  - localhost and 127.0.0.1 variants
  - All three RFC 1918 ranges including boundary values
  - The deployed gitnexus.vercel.app site
  - Public / untrusted origins that must be rejected

The server bind address (127.0.0.1 by default) is unchanged; this PR
only affects which cross-origin browser requests are accepted.

Closes #390
2026-03-22 18:28:21 +09:00
Shunsuke Hayashi
d206bf6772 fix(ingestion): calculate confidence per resolution tier for heritage/MRO edges (#412)
Instead of hardcoding confidence: 1.0, compute it at ingestion time using
the same resolution tier system that CALLS edges already use.

Heritage edges (EXTENDS, IMPLEMENTS):
- resolveHeritageId now returns { id, confidence } using TIER_CONFIDENCE
- Same-file → 0.95, import-scoped → 0.9, global → 0.5
- Edge confidence = geometric mean of source and target confidence
  (principled for partially-correlated cross-scope estimates, per
  Dillig et al. POPL 2011 and Dempster-Shafer theory)

MRO edges (OVERRIDES):
- MRO-ordered → 0.9, class method wins → 0.95
- Single interface → 0.85, ambiguous/unresolved → 0.5

IMPORTS and CONTAINS intentionally keep 1.0 (deterministic).

Closes #412
2026-03-22 18:23:40 +09:00
Shunsuke Hayashi
03156935cb fix(lbug): retry on DB lock with session-safe cleanup (#325)
When LadybugDB throws a BUSY/lock error (e.g. CLI and server running
concurrently), withLbugDb retries up to 3 times with linear backoff.

Addresses review feedback:

1. **Race condition fix**: Connection cleanup (close + state reset) now
   runs inside runWithSessionLock, preventing another operation from
   acquiring the lock between cleanup steps and having its connection
   closed from under it.

2. **Tests call withLbugDb directly**: Replaced simulateWithRetry helper
   with tests that invoke the real withLbugDb implementation, catching
   regressions in retry count, backoff, and lock interaction.

Closes #325
2026-03-22 18:21:21 +09:00
Gergő Magyar
22b5fce19e
Merge pull request #426 from ShunsukeHayashi/fix/no-git-folder-384 2026-03-22 08:46:47 +00:00
Shunsuke Hayashi
09e3609376 fix(analyze): address review — rename --no-git to --skip-git, fix stale cache
Addresses all review items from @magyargergo and Copilot:

1. **Rename --no-git to --skip-git**: Commander.js treats --no-X flags
   as negation of --X (stores as options.git = false, not options.noGit).
   --skip-git maps correctly to options.skipGit.

2. **Fix false " Already up to date\ on non-git folders**: When
 currentCommit is empty string, skip the cache check — we cannot
 detect changes without git, so always rebuild.

3. **Replace isGitRepo() with hasGitDir()**: Use filesystem check
 (statSync on .git) instead of shelling out to git CLI. Consistent,
 faster, and works when git is not installed.

4. **Fix misleading warning**: Message now only fires when .git
 directory is actually absent (not when git CLI fails).

5. **Add CLI integration tests**: Verify Commander maps --skip-git
 correctly and that non-git folders are rejected without the flag.
2026-03-22 17:40:02 +09:00
Shunsuke Hayashi
f0f384aab7 fix(analyze): address Copilot review — ESM import, CLI option, .gitignore guard
- Replace require(" fs\) with ESM-compatible top-level import (statSync)
- Register --no-git option in Commander CLI definition
- Use hasGitDir() instead of isGitRepo() for .gitignore update guard
 to match the PR intent (filesystem check vs git CLI invocation)
2026-03-22 16:24:21 +09:00
Gergő Magyar
ef8b252bcc
Merge pull request #428 from ShunsukeHayashi/fix/cypher-schema-docs-411 2026-03-22 06:21:40 +00:00
Gergő Magyar
92a1086697
Merge pull request #300 from jim80net/fix/onnxruntime-cuda-provider 2026-03-22 05:58:55 +00:00
Shunsuke Hayashi
b272c6864c docs(schema): add Community and Process node properties to cypher tool description (#411)
The cypher tool description and schema resource omit Community and Process
node properties, causing agents to write failing queries on first attempt.

Added property listings sourced from the actual LadybugDB schema definitions:
- Community: heuristicLabel, cohesion, symbolCount, keywords, description, enrichedBy
- Process: heuristicLabel, processType, stepCount, communities, entryPointId, terminalId

Closes #411
2026-03-22 13:32:12 +09:00
Zander Raycraft
4031562f6b redoing auto labeling using z score instead of clustering lowkey the method 2026-03-21 23:21:23 -05:00
Shunsuke Hayashi
4dffd81b12 fix(analyze): allow indexing folders without a .git directory (#384)
Previously gitnexus analyze exited with an error on any directory that
lacked a .git entry, making it impossible to index generated code,
vendored libraries, or monorepo sub-trees that are not git roots.

Changes:

storage/git.ts
  - Add hasGitDir(dirPath): boolean — a lightweight synchronous check for
    the presence of a .git file or directory.  Works for git worktrees
    (.git file pointing at the real repo) as well as standard repos.

cli/analyze.ts
  - Add noGit?: boolean to AnalyzeOptions.
  - When the explicit inputPath resolves to a non-git folder (or the cwd
    is not inside any git repo), respect --no-git instead of hard-failing.
  - Print an actionable tip pointing at --no-git when git is absent and the
    flag was not supplied.
  - currentCommit defaults to an empty string for non-git folders so the
    up-to-date check still functions (empty string never matches a real
    commit hash, so the index is always rebuilt).
  - Skip addToGitignore() when no .git is present — there is nothing to
    update and the function would create a stale .gitignore at the root.

Git-dependent features that remain disabled for non-git folders:
  - Incremental update (always rebuilds from scratch)
  - Commit tracking in metadata
  - .gitignore update

Closes #384
2026-03-22 13:20:02 +09:00
Zander Raycraft
b75e380bd0
Merge pull request #421 from zander-raycraft/main
workflow: triage reporting
2026-03-21 21:33:47 -05:00
Zander Raycraft
24421c2db1
Merge pull request #9 from zander-raycraft/gh/issue-pr-filter
token trunking
2026-03-21 20:16:10 -05:00
Zander Raycraft
e6eaf08382 token trunking 2026-03-21 20:15:50 -05:00
Zander Raycraft
f409fb7525
Merge pull request #7 from zander-raycraft/gh/issue-pr-filter
updated mahalanobis threshold to be multi-dim aware
2026-03-21 20:07:19 -05:00
Zander Raycraft
cc2b13e332 updated mahalanobis threshold to be multi-dim aware 2026-03-21 20:06:29 -05:00