Fix discover, improve LLM heuristics, add integration tests
- discover.ts: Fix ignore package path handling for root '.' directories, add .pi-map.md to default ignore list - llm-extract.ts: Fix export regex to only match line-start exports and handle 'export async function', fix root package role to 'Project root' - init.ts: Minor cleanup - .gitignore: Add .pi-map.md - tests: 6 integration tests covering init, patch (small/large packages), validate (missing, orphaned, stale-signature detection) All 14 tests pass. TypeScript compiles clean.
This commit is contained in:
@@ -4,3 +4,4 @@ coverage/
|
||||
*.log
|
||||
.DS_Store
|
||||
.env
|
||||
.pi-map.md
|
||||
|
||||
Generated
+504
@@ -21,6 +21,7 @@
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"tsx": "^4.22.4",
|
||||
"typescript": "^5.3.0",
|
||||
"vitest": "^1.0.0"
|
||||
}
|
||||
@@ -314,6 +315,23 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/netbsd-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-CR/RYotgtCKwtftMwJlUU7xCVNg3lMYZ0RzTmAHSfLCXw3NtZtNpswLEj/Kkf6kEL3Gw+BpOekRX0BYCtklhUw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"netbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/netbsd-x64": {
|
||||
"version": "0.21.5",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.21.5.tgz",
|
||||
@@ -331,6 +349,23 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/openbsd-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-cXb5vApOsRsxsEl4mcZ1XY3D4DzcoMxR/nnc4IyqYs0rTI8ZKmW6kyyg+11Z8yvgMfAEldKzP7AdP64HnSC/6g==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"openbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/openbsd-x64": {
|
||||
"version": "0.21.5",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.21.5.tgz",
|
||||
@@ -348,6 +383,23 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/openharmony-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-FLGfyizszcef5C3YtoyQDACyg95+dndv79i2EekILBofh5wpCa1KuBqOWKrEHZg3zrL3t5ouE5jgr94vA+Wb2w==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"openharmony"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/sunos-x64": {
|
||||
"version": "0.21.5",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.21.5.tgz",
|
||||
@@ -3298,6 +3350,458 @@
|
||||
"typescript": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx": {
|
||||
"version": "4.22.4",
|
||||
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.22.4.tgz",
|
||||
"integrity": "sha512-X8EX+XV4QR5xCsrgxaED954zTDfY8KqlDtskKEL0cHhyS/P8b4IFOvGDQpsC9Q1XnLq915wEfwwY/zzskCtmhg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"esbuild": "~0.28.0"
|
||||
},
|
||||
"bin": {
|
||||
"tsx": "dist/cli.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fsevents": "~2.3.3"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/aix-ppc64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.0.tgz",
|
||||
"integrity": "sha512-lhRUCeuOyJQURhTxl4WkpFTjIsbDayJHih5kZC1giwE+MhIzAb7mEsQMqMf18rHLsrb5qI1tafG20mLxEWcWlA==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"aix"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/android-arm": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.0.tgz",
|
||||
"integrity": "sha512-wqh0ByljabXLKHeWXYLqoJ5jKC4XBaw6Hk08OfMrCRd2nP2ZQ5eleDZC41XHyCNgktBGYMbqnrJKq/K/lzPMSQ==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/android-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-+WzIXQOSaGs33tLEgYPYe/yQHf0WTU0X42Jca3y8NWMbUVhp7rUnw+vAsRC/QiDrdD31IszMrZy+qwPOPjd+rw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/android-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-+VJggoaKhk2VNNqVL7f6S189UzShHC/mR9EE8rDdSkdpN0KflSwWY/gWjDrNxxisg8Fp1ZCD9jLMo4m0OUfeUA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/darwin-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-0T+A9WZm+bZ84nZBtk1ckYsOvyA3x7e2Acj1KdVfV4/2tdG4fzUp91YHx+GArWLtwqp77pBXVCPn2We7Letr0Q==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/darwin-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-fyzLm/DLDl/84OCfp2f/XQ4flmORsjU7VKt8HLjvIXChJoFFOIL6pLJPH4Yhd1n1gGFF9mPwtlN5Wf82DZs+LQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/freebsd-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-l9GeW5UZBT9k9brBYI+0WDffcRxgHQD8ShN2Ur4xWq/NFzUKm3k5lsH4PdaRgb2w7mI9u61nr2gI2mLI27Nh3Q==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/freebsd-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-BXoQai/A0wPO6Es3yFJ7APCiKGc1tdAEOgeTNy3SsB491S3aHn4S4r3e976eUnPdU+NbdtmBuLncYir2tMU9Nw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-arm": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.0.tgz",
|
||||
"integrity": "sha512-CjaaREJagqJp7iTaNQjjidaNbCKYcd4IDkzbwwxtSvjI7NZm79qiHc8HqciMddQ6CKvJT6aBd8lO9kN/ZudLlw==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-RVyzfb3FWsGA55n6WY0MEIEPURL1FcbhFE6BffZEMEekfCzCIMtB5yyDcFnVbTnwk+CLAgTujmV/Lgvih56W+A==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-ia32": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.0.tgz",
|
||||
"integrity": "sha512-KBnSTt1kxl9x70q+ydterVdl+Cn0H18ngRMRCEQfrbqdUuntQQ0LoMZv47uB97NljZFzY6HcfqEZ2SAyIUTQBQ==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-loong64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.0.tgz",
|
||||
"integrity": "sha512-zpSlUce1mnxzgBADvxKXX5sl8aYQHo2ezvMNI8I0lbblJtp8V4odlm3Yzlj7gPyt3T8ReksE6bK+pT3WD+aJRg==",
|
||||
"cpu": [
|
||||
"loong64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-mips64el": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.0.tgz",
|
||||
"integrity": "sha512-2jIfP6mmjkdmeTlsX/9vmdmhBmKADrWqN7zcdtHIeNSCH1SqIoNI63cYsjQR8J+wGa4Y5izRcSHSm8K3QWmk3w==",
|
||||
"cpu": [
|
||||
"mips64el"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-ppc64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.0.tgz",
|
||||
"integrity": "sha512-bc0FE9wWeC0WBm49IQMPSPILRocGTQt3j5KPCA8os6VprfuJ7KD+5PzESSrJ6GmPIPJK965ZJHTUlSA6GNYEhg==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-riscv64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.0.tgz",
|
||||
"integrity": "sha512-SQPZOwoTTT/HXFXQJG/vBX8sOFagGqvZyXcgLA3NhIqcBv1BJU1d46c0rGcrij2B56Z2rNiSLaZOYW5cUk7yLQ==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-s390x": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.0.tgz",
|
||||
"integrity": "sha512-SCfR0HN8CEEjnYnySJTd2cw0k9OHB/YFzt5zgJEwa+wL/T/raGWYMBqwDNAC6dqFKmJYZoQBRfHjgwLHGSrn3Q==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/linux-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-us0dSb9iFxIi8srnpl931Nvs65it/Jd2a2K3qs7fz2WfGPHqzfzZTfec7oxZJRNPXPnNYZtanmRc4AL/JwVzHQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/netbsd-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-nU1yhmYutL+fQ71Kxnhg8uEOdC0pwEW9entHykTgEbna2pw2dkbFSMeqjjyHZoCmt8SBkOSvV+yNmm94aUrrqw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"netbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/openbsd-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-8wZM2qqtv9UP3mzy7HiGYNH/zjTA355mpeuA+859TyR+e+Tc08IHYpLJuMsfpDJwoLo1ikIJI8jC3GFjnRClzA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"openbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/sunos-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-1ZgjUoEdHZZl/YlV76TSCz9Hqj9h9YmMGAgAPYd+q4SicWNX3G5GCyx9uhQWSLcbvPW8Ni7lj4gDa1T40akdlw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"sunos"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/win32-arm64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.0.tgz",
|
||||
"integrity": "sha512-Q9StnDmQ/enxnpxCCLSg0oo4+34B9TdXpuyPeTedN/6+iXBJ4J+zwfQI28u/Jl40nOYAxGoNi7mFP40RUtkmUA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/win32-ia32": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.0.tgz",
|
||||
"integrity": "sha512-zF3ag/gfiCe6U2iczcRzSYJKH1DCI+ByzSENHlM2FcDbEeo5Zd2C86Aq0tKUYAJJ1obRP84ymxIAksZUcdztHA==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/@esbuild/win32-x64": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.0.tgz",
|
||||
"integrity": "sha512-pEl1bO9mfAmIC+tW5btTmrKaujg3zGtUmWNdCw/xs70FBjwAL3o9OEKNHvNmnyylD6ubxUERiEhdsL0xBQ9efw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tsx/node_modules/esbuild": {
|
||||
"version": "0.28.0",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.0.tgz",
|
||||
"integrity": "sha512-sNR9MHpXSUV/XB4zmsFKN+QgVG82Cc7+/aaxJ8Adi8hyOac+EXptIp45QBPaVyX3N70664wRbTcLTOemCAnyqw==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"esbuild": "bin/esbuild"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@esbuild/aix-ppc64": "0.28.0",
|
||||
"@esbuild/android-arm": "0.28.0",
|
||||
"@esbuild/android-arm64": "0.28.0",
|
||||
"@esbuild/android-x64": "0.28.0",
|
||||
"@esbuild/darwin-arm64": "0.28.0",
|
||||
"@esbuild/darwin-x64": "0.28.0",
|
||||
"@esbuild/freebsd-arm64": "0.28.0",
|
||||
"@esbuild/freebsd-x64": "0.28.0",
|
||||
"@esbuild/linux-arm": "0.28.0",
|
||||
"@esbuild/linux-arm64": "0.28.0",
|
||||
"@esbuild/linux-ia32": "0.28.0",
|
||||
"@esbuild/linux-loong64": "0.28.0",
|
||||
"@esbuild/linux-mips64el": "0.28.0",
|
||||
"@esbuild/linux-ppc64": "0.28.0",
|
||||
"@esbuild/linux-riscv64": "0.28.0",
|
||||
"@esbuild/linux-s390x": "0.28.0",
|
||||
"@esbuild/linux-x64": "0.28.0",
|
||||
"@esbuild/netbsd-arm64": "0.28.0",
|
||||
"@esbuild/netbsd-x64": "0.28.0",
|
||||
"@esbuild/openbsd-arm64": "0.28.0",
|
||||
"@esbuild/openbsd-x64": "0.28.0",
|
||||
"@esbuild/openharmony-arm64": "0.28.0",
|
||||
"@esbuild/sunos-x64": "0.28.0",
|
||||
"@esbuild/win32-arm64": "0.28.0",
|
||||
"@esbuild/win32-ia32": "0.28.0",
|
||||
"@esbuild/win32-x64": "0.28.0"
|
||||
}
|
||||
},
|
||||
"node_modules/type-check": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
|
||||
|
||||
+7
-6
@@ -25,15 +25,16 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"typescript": "^5.3.0",
|
||||
"vitest": "^1.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0"
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"tsx": "^4.22.4",
|
||||
"typescript": "^5.3.0",
|
||||
"vitest": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ignore": "^5.3.0",
|
||||
"tree-sitter": "^0.21.0",
|
||||
"tree-sitter-typescript": "^0.21.0",
|
||||
"ignore": "^5.3.0"
|
||||
"tree-sitter-typescript": "^0.21.0"
|
||||
}
|
||||
}
|
||||
|
||||
+32
-7
@@ -69,7 +69,11 @@ function extractExportsFromTree(tree: Tree, langName: string): string[] {
|
||||
const root = tree.rootNode;
|
||||
|
||||
function visit(node: SyntaxNode) {
|
||||
if (langName === "typescript" || langName === "tsx" || langName === "javascript") {
|
||||
if (
|
||||
langName === "typescript" ||
|
||||
langName === "tsx" ||
|
||||
langName === "javascript"
|
||||
) {
|
||||
if (node.type === "export_statement") {
|
||||
// export function foo
|
||||
// export class Foo
|
||||
@@ -97,7 +101,10 @@ function extractExportsFromTree(tree: Tree, langName: string): string[] {
|
||||
}
|
||||
}
|
||||
} else if (langName === "python") {
|
||||
if (node.type === "function_definition" || node.type === "class_definition") {
|
||||
if (
|
||||
node.type === "function_definition" ||
|
||||
node.type === "class_definition"
|
||||
) {
|
||||
const nameNode = node.childForFieldName?.("name");
|
||||
if (nameNode) exports.push(nameNode.text);
|
||||
}
|
||||
@@ -114,7 +121,11 @@ function extractExportsFromTree(tree: Tree, langName: string): string[] {
|
||||
}
|
||||
}
|
||||
} else if (langName === "rust") {
|
||||
if (node.type === "function_item" || node.type === "struct_item" || node.type === "enum_item") {
|
||||
if (
|
||||
node.type === "function_item" ||
|
||||
node.type === "struct_item" ||
|
||||
node.type === "enum_item"
|
||||
) {
|
||||
const nameNode = node.childForFieldName?.("name");
|
||||
if (nameNode) exports.push(nameNode.text);
|
||||
}
|
||||
@@ -135,8 +146,15 @@ function extractDepsFromTree(tree: Tree, langName: string): string[] {
|
||||
const root = tree.rootNode;
|
||||
|
||||
function visit(node: SyntaxNode) {
|
||||
if (langName === "typescript" || langName === "tsx" || langName === "javascript") {
|
||||
if (node.type === "import_statement" || node.type === "import_declaration") {
|
||||
if (
|
||||
langName === "typescript" ||
|
||||
langName === "tsx" ||
|
||||
langName === "javascript"
|
||||
) {
|
||||
if (
|
||||
node.type === "import_statement" ||
|
||||
node.type === "import_declaration"
|
||||
) {
|
||||
const source = node.childForFieldName?.("source");
|
||||
if (source) {
|
||||
const text = source.text;
|
||||
@@ -158,7 +176,10 @@ function extractDepsFromTree(tree: Tree, langName: string): string[] {
|
||||
}
|
||||
}
|
||||
} else if (langName === "python") {
|
||||
if (node.type === "import_statement" || node.type === "import_from_statement") {
|
||||
if (
|
||||
node.type === "import_statement" ||
|
||||
node.type === "import_from_statement"
|
||||
) {
|
||||
const nameNode = node.childForFieldName?.("name");
|
||||
if (nameNode) deps.push(nameNode.text);
|
||||
}
|
||||
@@ -185,7 +206,11 @@ function extractDepsFromTree(tree: Tree, langName: string): string[] {
|
||||
}
|
||||
|
||||
function findIdentifier(node: SyntaxNode): SyntaxNode | null {
|
||||
if (node.type === "identifier" || node.type === "type_identifier" || node.type === "property_identifier") {
|
||||
if (
|
||||
node.type === "identifier" ||
|
||||
node.type === "type_identifier" ||
|
||||
node.type === "property_identifier"
|
||||
) {
|
||||
return node;
|
||||
}
|
||||
for (let i = 0; i < node.childCount; i++) {
|
||||
|
||||
+4
-2
@@ -13,6 +13,7 @@ const DEFAULT_IGNORE = [
|
||||
"__pycache__",
|
||||
".DS_Store",
|
||||
"*.log",
|
||||
".pi-map.md",
|
||||
];
|
||||
|
||||
export interface DirectoryEntry {
|
||||
@@ -35,14 +36,15 @@ export function discoverProject(rootPath: string): DirectoryEntry[] {
|
||||
|
||||
function walk(dir: string) {
|
||||
const relDir = relative(rootPath, dir) || ".";
|
||||
if (ig.ignores(relDir)) return;
|
||||
// The ignore package doesn't accept "." — skip check for root
|
||||
if (relDir !== "." && ig.ignores(relDir.replace(/^\.\//, ""))) return;
|
||||
|
||||
const items = readdirSync(dir);
|
||||
const files: string[] = [];
|
||||
const subdirs: string[] = [];
|
||||
|
||||
for (const item of items) {
|
||||
const relPath = join(relDir, item);
|
||||
const relPath = join(relDir, item).replace(/^\.\//, "");
|
||||
if (ig.ignores(relPath)) continue;
|
||||
|
||||
const fullPath = join(dir, item);
|
||||
|
||||
+5
-1
@@ -1,5 +1,9 @@
|
||||
import { discoverProject, type DirectoryEntry } from "./discover.js";
|
||||
import { renderPackageMap, type PackageMapData, type FileEntry } from "./format.js";
|
||||
import {
|
||||
renderPackageMap,
|
||||
type PackageMapData,
|
||||
type FileEntry,
|
||||
} from "./format.js";
|
||||
import { extractFileLLM, extractPackageLLM } from "./llm-extract.js";
|
||||
import { extractFileAST } from "./ast-extract.js";
|
||||
import { mergeFileData } from "./merge.js";
|
||||
|
||||
+45
-14
@@ -41,7 +41,7 @@ const FILE_TYPE_PURPOSES: Record<string, string> = {
|
||||
".ini": "Configuration",
|
||||
".env": "Environment config",
|
||||
".dockerfile": "Docker image definition",
|
||||
"dockerfile": "Docker image definition",
|
||||
dockerfile: "Docker image definition",
|
||||
".sql": "Database schema/queries",
|
||||
".css": "Stylesheet",
|
||||
".scss": "SCSS stylesheet",
|
||||
@@ -77,13 +77,19 @@ export async function extractFileLLM(filePath: string): Promise<LLMFileData> {
|
||||
return result;
|
||||
}
|
||||
|
||||
function extractExports(content: string, ext: string, _filename: string): string[] {
|
||||
function extractExports(
|
||||
content: string,
|
||||
ext: string,
|
||||
_filename: string,
|
||||
): string[] {
|
||||
const exports: string[] = [];
|
||||
|
||||
if ([".ts", ".tsx", ".js", ".jsx", ".mjs"].includes(ext)) {
|
||||
// ES module exports
|
||||
// ES module exports — only match at start of line (after optional whitespace)
|
||||
// Handles: export function foo, export async function foo, export class Foo,
|
||||
// export const foo, export { foo, bar }, export default foo
|
||||
const exportRegex =
|
||||
/export\s+(?:default\s+)?(?:function\s+|class\s+|const\s+|let\s+|var\s+|interface\s+|type\s+|enum\s+)?([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
||||
/(?:^|\n)\s*export\s+(?:default\s+)?(?:async\s+)?(?:function\s+|class\s+|const\s+|let\s+|var\s+|interface\s+|type\s+|enum\s+)?([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
||||
let match: RegExpExecArray | null;
|
||||
match = exportRegex.exec(content);
|
||||
while (match !== null) {
|
||||
@@ -92,16 +98,22 @@ function extractExports(content: string, ext: string, _filename: string): string
|
||||
}
|
||||
|
||||
// Named export destructuring: export { foo, bar }
|
||||
const namedExportRegex = /export\s*\{\s*([^}]+)\s*\}/g;
|
||||
const namedExportRegex = /(?:^|\n)\s*export\s*\{\s*([^}]+)\s*\}/g;
|
||||
match = namedExportRegex.exec(content);
|
||||
while (match !== null) {
|
||||
const names = match[1].split(",").map((s) => s.trim().split(/\s+as\s+/)[0].trim());
|
||||
const names = match[1].split(",").map((s) =>
|
||||
s
|
||||
.trim()
|
||||
.split(/\s+as\s+/)[0]
|
||||
.trim(),
|
||||
);
|
||||
exports.push(...names);
|
||||
match = namedExportRegex.exec(content);
|
||||
}
|
||||
} else if (ext === ".py") {
|
||||
// Python exports (top-level functions/classes)
|
||||
const pyRegex = /^(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)|class\s+([A-Za-z_][A-Za-z0-9_]*)/gm;
|
||||
const pyRegex =
|
||||
/^(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)|class\s+([A-Za-z_][A-Za-z0-9_]*)/gm;
|
||||
let match: RegExpExecArray | null = pyRegex.exec(content);
|
||||
while (match !== null) {
|
||||
exports.push(match[1] || match[2]);
|
||||
@@ -117,7 +129,8 @@ function extractExports(content: string, ext: string, _filename: string): string
|
||||
}
|
||||
} else if (ext === ".rs") {
|
||||
// Rust exports (pub items)
|
||||
const rsRegex = /pub\s+(?:fn|struct|enum|trait|type|const|static|use)\s+([A-Za-z_][A-Za-z0-9_]*)/g;
|
||||
const rsRegex =
|
||||
/pub\s+(?:fn|struct|enum|trait|type|const|static|use)\s+([A-Za-z_][A-Za-z0-9_]*)/g;
|
||||
let match: RegExpExecArray | null = rsRegex.exec(content);
|
||||
while (match !== null) {
|
||||
exports.push(match[1]);
|
||||
@@ -199,7 +212,12 @@ function generatePurpose(
|
||||
if (/service/.test(name)) return "Service layer";
|
||||
if (/model/.test(name)) return "Data model";
|
||||
if (/schema/.test(name)) return "Data schema";
|
||||
if (/component/.test(name) || /\.tsx$/.test(name) || /\.vue$/.test(name) || /\.svelte$/.test(name)) {
|
||||
if (
|
||||
/component/.test(name) ||
|
||||
/\.tsx$/.test(name) ||
|
||||
/\.vue$/.test(name) ||
|
||||
/\.svelte$/.test(name)
|
||||
) {
|
||||
return "UI component";
|
||||
}
|
||||
if (/hook|use[A-Z]/.test(name)) return "React hook";
|
||||
@@ -216,7 +234,10 @@ function generatePurpose(
|
||||
}
|
||||
|
||||
// Fallback to file type
|
||||
return FILE_TYPE_PURPOSES[ext] || (ext ? `${ext.slice(1).toUpperCase()} file` : `${name} file`);
|
||||
return (
|
||||
FILE_TYPE_PURPOSES[ext] ||
|
||||
(ext ? `${ext.slice(1).toUpperCase()} file` : `${name} file`)
|
||||
);
|
||||
}
|
||||
|
||||
export async function extractPackageLLM(
|
||||
@@ -226,7 +247,7 @@ export async function extractPackageLLM(
|
||||
const dirName = basename(relativePath);
|
||||
|
||||
// Infer role from directory name
|
||||
let role = `Package ${dirName}`;
|
||||
let role = dirName === "." ? "Project root" : `Package ${dirName}`;
|
||||
if (dirName === "src" || dirName === "lib" || dirName === "source") {
|
||||
role = "Source code";
|
||||
} else if (dirName === "test" || dirName === "tests" || dirName === "spec") {
|
||||
@@ -235,7 +256,11 @@ export async function extractPackageLLM(
|
||||
role = "Documentation";
|
||||
} else if (dirName === "config" || dirName === "configuration") {
|
||||
role = "Configuration";
|
||||
} else if (dirName === "utils" || dirName === "helpers" || dirName === "util") {
|
||||
} else if (
|
||||
dirName === "utils" ||
|
||||
dirName === "helpers" ||
|
||||
dirName === "util"
|
||||
) {
|
||||
role = "Utility functions";
|
||||
} else if (dirName === "types" || dirName === "type") {
|
||||
role = "Type definitions";
|
||||
@@ -245,7 +270,11 @@ export async function extractPackageLLM(
|
||||
role = "Custom hooks";
|
||||
} else if (dirName === "api" || dirName === "apis") {
|
||||
role = "API endpoints/handlers";
|
||||
} else if (dirName === "db" || dirName === "database" || dirName === "models") {
|
||||
} else if (
|
||||
dirName === "db" ||
|
||||
dirName === "database" ||
|
||||
dirName === "models"
|
||||
) {
|
||||
role = "Database layer";
|
||||
} else if (dirName === "auth" || dirName === "authentication") {
|
||||
role = "Authentication layer";
|
||||
@@ -255,7 +284,9 @@ export async function extractPackageLLM(
|
||||
const purposes = fileData.map((f) => f.purpose);
|
||||
const hasTests = purposes.some((p) => p.includes("Test"));
|
||||
const hasTypes = purposes.some((p) => p.includes("Type"));
|
||||
const hasComponents = purposes.some((p) => p.includes("component") || p.includes("Component"));
|
||||
const hasComponents = purposes.some(
|
||||
(p) => p.includes("component") || p.includes("Component"),
|
||||
);
|
||||
const hasUtils = purposes.some((p) => p.includes("Utility"));
|
||||
|
||||
let arch = "";
|
||||
|
||||
+16
-4
@@ -1,5 +1,9 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { renderPackageMap, parsePackageMap, type PackageMapData } from "../src/format.js";
|
||||
import {
|
||||
renderPackageMap,
|
||||
parsePackageMap,
|
||||
type PackageMapData,
|
||||
} from "../src/format.js";
|
||||
|
||||
const sampleData: PackageMapData = {
|
||||
path: "pkg/auth",
|
||||
@@ -34,7 +38,9 @@ describe("format", () => {
|
||||
expect(output).toContain("# pkg/auth");
|
||||
expect(output).toContain("## role");
|
||||
expect(output).toContain("## files");
|
||||
expect(output).toContain("- tokens.ts | JWT gen/val | exp: issueToken, verifyToken, refreshToken | dep: crypto/hmac, db/sessions");
|
||||
expect(output).toContain(
|
||||
"- tokens.ts | JWT gen/val | exp: issueToken, verifyToken, refreshToken | dep: crypto/hmac, db/sessions",
|
||||
);
|
||||
expect(output).toContain("## arch");
|
||||
expect(output).toContain("## dirty");
|
||||
expect(output).toContain("-");
|
||||
@@ -53,7 +59,11 @@ describe("format", () => {
|
||||
const tokens = parsed.files.find((f) => f.name === "tokens.ts");
|
||||
expect(tokens).toBeDefined();
|
||||
expect(tokens!.purpose).toBe("JWT gen/val");
|
||||
expect(tokens!.exports).toEqual(["issueToken", "verifyToken", "refreshToken"]);
|
||||
expect(tokens!.exports).toEqual([
|
||||
"issueToken",
|
||||
"verifyToken",
|
||||
"refreshToken",
|
||||
]);
|
||||
expect(tokens!.deps).toEqual(["crypto/hmac", "db/sessions"]);
|
||||
});
|
||||
|
||||
@@ -61,7 +71,9 @@ describe("format", () => {
|
||||
const data: PackageMapData = {
|
||||
path: "pkg/utils",
|
||||
role: "Utilities",
|
||||
files: [{ name: "helpers.ts", purpose: "Helpers", exports: [], deps: [] }],
|
||||
files: [
|
||||
{ name: "helpers.ts", purpose: "Helpers", exports: [], deps: [] },
|
||||
],
|
||||
arch: "Shared helpers",
|
||||
dirty: "2024-01-01: patched",
|
||||
};
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||
import { mkdtempSync, writeFileSync, mkdirSync, rmSync, readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { tmpdir } from "os";
|
||||
import { initProject } from "../src/init.js";
|
||||
import { patchFile } from "../src/patch.js";
|
||||
import { validateMaps } from "../src/validate.js";
|
||||
|
||||
describe("integration", () => {
|
||||
let dir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
dir = mkdtempSync(join(tmpdir(), "pi-map-int-"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
it("init creates .pi-map.md files", async () => {
|
||||
mkdirSync(join(dir, "src"));
|
||||
writeFileSync(
|
||||
join(dir, "src", "index.ts"),
|
||||
`export function foo() {}\n`,
|
||||
);
|
||||
await initProject(dir);
|
||||
|
||||
const map = readFileSync(join(dir, "src", ".pi-map.md"), "utf8");
|
||||
expect(map).toContain("# src");
|
||||
expect(map).toContain("foo");
|
||||
});
|
||||
|
||||
it("patch updates a file entry", async () => {
|
||||
mkdirSync(join(dir, "src"));
|
||||
writeFileSync(
|
||||
join(dir, "src", "index.ts"),
|
||||
`export function foo() {}\n`,
|
||||
);
|
||||
writeFileSync(
|
||||
join(dir, "src", "utils.ts"),
|
||||
`export const bar = 1;\n`,
|
||||
);
|
||||
await initProject(dir);
|
||||
|
||||
// Modify a file
|
||||
writeFileSync(
|
||||
join(dir, "src", "index.ts"),
|
||||
`export function foo() {}\nexport function baz() {}\n`,
|
||||
);
|
||||
await patchFile(join(dir, "src", "index.ts"));
|
||||
|
||||
const map = readFileSync(join(dir, "src", ".pi-map.md"), "utf8");
|
||||
expect(map).toContain("baz");
|
||||
});
|
||||
|
||||
it("patch adds dirty marker for large packages", async () => {
|
||||
mkdirSync(join(dir, "src"));
|
||||
// Create 11 files so it's a "large" package
|
||||
for (let i = 0; i < 11; i++) {
|
||||
writeFileSync(
|
||||
join(dir, "src", `file${i}.ts`),
|
||||
`export const x${i} = ${i};\n`,
|
||||
);
|
||||
}
|
||||
await initProject(dir);
|
||||
|
||||
// Modify a file
|
||||
writeFileSync(
|
||||
join(dir, "src", "file0.ts"),
|
||||
`export const x0 = 0;\nexport const y = 99;\n`,
|
||||
);
|
||||
await patchFile(join(dir, "src", "file0.ts"));
|
||||
|
||||
const map = readFileSync(join(dir, "src", ".pi-map.md"), "utf8");
|
||||
expect(map).toContain("y");
|
||||
expect(map).toContain("dirty");
|
||||
expect(map).toContain("patched");
|
||||
});
|
||||
|
||||
it("validate detects new files", async () => {
|
||||
mkdirSync(join(dir, "src"));
|
||||
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\n`);
|
||||
await initProject(dir);
|
||||
|
||||
// Add new file
|
||||
writeFileSync(join(dir, "src", "b.ts"), `export const b = 2;\n`);
|
||||
|
||||
const result = await validateMaps(dir);
|
||||
expect(result.clean).toBe(false);
|
||||
expect(result.discrepancies.some((d) => d.type === "missing")).toBe(true);
|
||||
});
|
||||
|
||||
it("validate detects deleted files", async () => {
|
||||
mkdirSync(join(dir, "src"));
|
||||
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\n`);
|
||||
writeFileSync(join(dir, "src", "b.ts"), `export const b = 2;\n`);
|
||||
await initProject(dir);
|
||||
|
||||
// Delete a file
|
||||
rmSync(join(dir, "src", "b.ts"));
|
||||
|
||||
const result = await validateMaps(dir);
|
||||
expect(result.clean).toBe(false);
|
||||
expect(result.discrepancies.some((d) => d.type === "orphaned")).toBe(true);
|
||||
});
|
||||
|
||||
it("validate detects changed signatures", async () => {
|
||||
mkdirSync(join(dir, "src"));
|
||||
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\n`);
|
||||
await initProject(dir);
|
||||
|
||||
// Change exports
|
||||
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\nexport const c = 3;\n`);
|
||||
|
||||
const result = await validateMaps(dir);
|
||||
expect(result.clean).toBe(false);
|
||||
expect(result.discrepancies.some((d) => d.type === "stale-signature")).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user