Skip to content

Fix DreamMaker parent-relative #include paths (lstrip charset misuse) - #1978

Closed
Osamaali313 wants to merge 1 commit into
Graphify-Labs:v8from
Osamaali313:fix/dm-parent-relative-include
Closed

Osamaali313 wants to merge 1 commit into
Graphify-Labs:v8from
Osamaali313:fix/dm-parent-relative-include

Conversation

@Osamaali313

Copy link
Copy Markdown
Contributor

Problem

extract_dm normalizes DreamMaker #include paths with str.lstrip("./"):

norm = raw.replace("\\", "/").lstrip("./")
resolved = (path.parent / norm).resolve()

str.lstrip treats its argument as a set of characters, not a prefix. It's meant to drop a leading ./, but it strips every leading . and /, which destroys parent-relative includes:

raw lstrip("./") correct
../shared/base.dm shared/base.dm ❌ ../shared/base.dm
../../a.dm a.dm ❌ ../../a.dm
.hidden/x.dm hidden/x.dm ❌ .hidden/x.dm

(path.parent / norm).resolve() then points at the wrong directory, .exists() returns False, and what should be an internal imports_from edge to the real included file becomes a bogus external imports edge to a phantom node — silently losing the cross-file link in the knowledge graph.

Evidence (sibling proves intent)

The local-include resolver in extractors/bash.py does the same "resolve relative to the file's parent, emit imports_from if it exists on disk, else external imports" flow — but it resolves (path.parent / raw) from the raw path and never strips ... dm.py intends the identical resolution but corrupts the path first.

Fix

Strip only a literal leading ./ (re is already imported), preserving ../:

norm = re.sub(r"^\./", "", raw.replace("\\", "/"))

Reproduction

With a real sub/child.dm including ../shared/base.dm (and shared/base.dm on disk):

edge
before imports (external), target = phantom shared/base.dm ❌
after imports_from (internal), target = resolved shared/base.dm ✅

The ./-prefix and no-prefix cases are unaffected.

`extract_dm` normalized include paths with `raw.lstrip("./")`. `str.lstrip`
treats its argument as a *set of characters*, not a prefix, so it strips
every leading `.` and `/` — destroying parent-relative includes:

    "../shared/base.dm"  -> "shared/base.dm"
    "../../a.dm"         -> "a.dm"
    ".hidden/x.dm"       -> "hidden/x.dm"

`(path.parent / norm).resolve()` then points at the wrong directory,
`.exists()` returns False, and a correct internal `imports_from` edge to the
real included file becomes a bogus external `imports` edge to a phantom node,
silently losing the cross-file link.

The sibling local-include resolver in `extractors/bash.py` resolves
`(path.parent / raw)` from the raw path without stripping `..`, confirming
the intent. Strip only a literal leading `./` (re is already imported) so
`../` includes resolve correctly; the `./`-prefix and no-prefix cases are
unchanged.
Copilot AI review requested due to automatic review settings July 17, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

safishamsi added a commit that referenced this pull request Jul 18, 2026
@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 (ships in 0.9.19) in a038684, cherry-picked to preserve your authorship. Thanks @Osamaali313 — replaced the lstrip("./") character-set strip with a leading-./ prefix strip, so ../shared/base.dm and .hidden/x are no longer mangled.

@safishamsi safishamsi closed this Jul 18, 2026
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants