dsh-plugin-codegraph-tree-sitter 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/lib/extract.d.ts +70 -0
- package/lib/extract.js +296 -0
- package/lib/git-hooks.d.ts +52 -0
- package/lib/git-hooks.js +75 -0
- package/lib/gitignore.d.ts +58 -0
- package/lib/gitignore.js +107 -0
- package/lib/grammar.d.ts +27 -0
- package/lib/grammar.js +51 -0
- package/lib/index.d.ts +112 -0
- package/lib/index.js +203 -0
- package/lib/invariant.d.ts +16 -0
- package/lib/invariant.js +25 -0
- package/lib/languages.d.ts +62 -0
- package/lib/languages.js +107 -0
- package/lib/resolve.d.ts +89 -0
- package/lib/resolve.js +218 -0
- package/lib/schema.d.ts +35 -0
- package/lib/schema.js +126 -0
- package/lib/walk.d.ts +57 -0
- package/lib/walk.js +146 -0
- package/lib/watch-policy.d.ts +49 -0
- package/lib/watch-policy.js +64 -0
- package/lib/watcher.d.ts +95 -0
- package/lib/watcher.js +299 -0
- package/lib/worktree.d.ts +41 -0
- package/lib/worktree.js +63 -0
- package/package.json +64 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree diagnostics: is a given root a linked `git worktree`, and if so, where is the main
|
|
3
|
+
* repository it was created from?
|
|
4
|
+
*
|
|
5
|
+
* This is a diagnostic, not a bug fix. The reference implementation's original incident here was
|
|
6
|
+
* index resolution walking *up* from a linked worktree and finding the main repository's
|
|
7
|
+
* `.codegraph/`, silently querying the wrong graph. This package has no such code path —
|
|
8
|
+
* `databasePath()` is always `join(projectRoot, '.codegraph/codegraph.db')`, and `walkAndExtract`
|
|
9
|
+
* never looks outside the `projectRoot` it was given. If a caller ever *does* end up pointed at the
|
|
10
|
+
* wrong root, the bug is almost certainly in how the host resolves a session's working directory, not
|
|
11
|
+
* in this package — this module exists to make that distinction diagnosable, not to route around it.
|
|
12
|
+
* @module dsh-plugin-codegraph-tree-sitter/worktree
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Runs one git command and returns its stdout, throwing on any non-zero exit, missing `git` binary,
|
|
16
|
+
* or timeout. Indirection over `execFileSync` so tests never fork a real process.
|
|
17
|
+
*/
|
|
18
|
+
export type GitExec = (args: readonly string[], cwd: string) => string;
|
|
19
|
+
/** The real `git`-backed {@link GitExec}. Array arguments, no shell, a hard timeout. */
|
|
20
|
+
export declare const execGit: GitExec;
|
|
21
|
+
/** What `detectWorktree` learned about one root. */
|
|
22
|
+
export interface WorktreeInfo {
|
|
23
|
+
/** Whether `root` is a linked worktree rather than the main working tree (or a lone clone). */
|
|
24
|
+
readonly isWorktree: boolean;
|
|
25
|
+
/** This worktree's own top-level directory (`git rev-parse --show-toplevel` from `root`). */
|
|
26
|
+
readonly toplevel: string;
|
|
27
|
+
/** The main repository's working directory, present only when {@link isWorktree} is `true`. */
|
|
28
|
+
readonly mainRepoRoot?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether `root` sits inside a linked `git worktree`, and the main repository's root when it does.
|
|
32
|
+
*
|
|
33
|
+
* Not a git repository, `git` missing from `PATH`, or the probe timing out are all reported the same
|
|
34
|
+
* way as "not a worktree" — `undefined`, never a thrown error — matching this package's existing
|
|
35
|
+
* `canIndex`/`indexes` idiom of "a failed probe is a negative answer, not a failure to report."
|
|
36
|
+
* @param root - absolute path to probe.
|
|
37
|
+
* @param exec - the git-invoking primitive; defaults to the real `git` binary.
|
|
38
|
+
* @returns worktree diagnostics, or `undefined` when `root` isn't inside a (usable) git repository.
|
|
39
|
+
*/
|
|
40
|
+
export declare function detectWorktree(root: string, exec?: GitExec): WorktreeInfo | undefined;
|
|
41
|
+
//# sourceMappingURL=worktree.d.ts.map
|
package/lib/worktree.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree diagnostics: is a given root a linked `git worktree`, and if so, where is the main
|
|
3
|
+
* repository it was created from?
|
|
4
|
+
*
|
|
5
|
+
* This is a diagnostic, not a bug fix. The reference implementation's original incident here was
|
|
6
|
+
* index resolution walking *up* from a linked worktree and finding the main repository's
|
|
7
|
+
* `.codegraph/`, silently querying the wrong graph. This package has no such code path —
|
|
8
|
+
* `databasePath()` is always `join(projectRoot, '.codegraph/codegraph.db')`, and `walkAndExtract`
|
|
9
|
+
* never looks outside the `projectRoot` it was given. If a caller ever *does* end up pointed at the
|
|
10
|
+
* wrong root, the bug is almost certainly in how the host resolves a session's working directory, not
|
|
11
|
+
* in this package — this module exists to make that distinction diagnosable, not to route around it.
|
|
12
|
+
* @module dsh-plugin-codegraph-tree-sitter/worktree
|
|
13
|
+
*/
|
|
14
|
+
import { execFileSync } from 'node:child_process';
|
|
15
|
+
import { dirname, resolve } from 'node:path';
|
|
16
|
+
/** The real `git`-backed {@link GitExec}. Array arguments, no shell, a hard timeout. */
|
|
17
|
+
export const execGit = (args, cwd) => execFileSync('git', [...args], { cwd, encoding: 'utf8', timeout: 2_000 });
|
|
18
|
+
/** Memoized per root: git diagnostics are cheap to answer wrong (a stale worktree list) but not free. */
|
|
19
|
+
const cache = new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Whether `root` sits inside a linked `git worktree`, and the main repository's root when it does.
|
|
22
|
+
*
|
|
23
|
+
* Not a git repository, `git` missing from `PATH`, or the probe timing out are all reported the same
|
|
24
|
+
* way as "not a worktree" — `undefined`, never a thrown error — matching this package's existing
|
|
25
|
+
* `canIndex`/`indexes` idiom of "a failed probe is a negative answer, not a failure to report."
|
|
26
|
+
* @param root - absolute path to probe.
|
|
27
|
+
* @param exec - the git-invoking primitive; defaults to the real `git` binary.
|
|
28
|
+
* @returns worktree diagnostics, or `undefined` when `root` isn't inside a (usable) git repository.
|
|
29
|
+
*/
|
|
30
|
+
export function detectWorktree(root, exec = execGit) {
|
|
31
|
+
if (cache.has(root))
|
|
32
|
+
return cache.get(root);
|
|
33
|
+
const info = probeWorktree(root, exec);
|
|
34
|
+
cache.set(root, info);
|
|
35
|
+
return info;
|
|
36
|
+
}
|
|
37
|
+
function probeWorktree(root, exec) {
|
|
38
|
+
let output;
|
|
39
|
+
try {
|
|
40
|
+
// One call, not three: `git rev-parse` answers every query in the order given, so a single
|
|
41
|
+
// process fork either answers all three questions or fails all three the same way.
|
|
42
|
+
output = exec(['rev-parse', '--show-toplevel', '--git-dir', '--git-common-dir'], root);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const lines = output.split('\n');
|
|
48
|
+
const toplevelLine = lines[0];
|
|
49
|
+
const gitDirLine = lines[1];
|
|
50
|
+
const commonDirLine = lines[2];
|
|
51
|
+
if (toplevelLine === undefined || gitDirLine === undefined || commonDirLine === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
// `git rev-parse` reports these relative to `root` (the cwd it ran in) unless they point outside
|
|
54
|
+
// that tree entirely, as `--git-common-dir` does from inside a linked worktree — `resolve` is a
|
|
55
|
+
// no-op on an already-absolute path either way.
|
|
56
|
+
const toplevel = resolve(root, toplevelLine.trim());
|
|
57
|
+
const gitDir = resolve(root, gitDirLine.trim());
|
|
58
|
+
const commonDir = resolve(root, commonDirLine.trim());
|
|
59
|
+
if (gitDir === commonDir)
|
|
60
|
+
return { isWorktree: false, toplevel };
|
|
61
|
+
return { isWorktree: true, toplevel, mainRepoRoot: dirname(commonDir) };
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=worktree.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-plugin-codegraph-tree-sitter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Self-built code-graph indexer for DeepSeek Harness — parses a workspace with web-tree-sitter and writes schema version 4 to .codegraph/codegraph.db, the same on-disk format the codegraph CLI writes, so no external indexer is required",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh",
|
|
7
|
+
"dsh-plugin",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"cordis",
|
|
10
|
+
"cordis-plugin",
|
|
11
|
+
"codegraph",
|
|
12
|
+
"code-graph",
|
|
13
|
+
"tree-sitter",
|
|
14
|
+
"call-graph",
|
|
15
|
+
"static-analysis",
|
|
16
|
+
"code-intelligence",
|
|
17
|
+
"ai-agent"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "CC ZHAO",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/CC19990113/dsh-plugin-codegraph.git",
|
|
24
|
+
"directory": "packages/tree-sitter"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/CC19990113/dsh-plugin-codegraph#readme",
|
|
27
|
+
"bugs": "https://github.com/CC19990113/dsh-plugin-codegraph/issues",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "lib/index.js",
|
|
30
|
+
"types": "lib/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./lib/index.d.ts",
|
|
34
|
+
"default": "./lib/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./invariant": {
|
|
37
|
+
"types": "./lib/invariant.d.ts",
|
|
38
|
+
"default": "./lib/invariant.js"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"lib/**/*.js",
|
|
44
|
+
"lib/**/*.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@deepseek-ai/schemastery": "^3.18.1",
|
|
52
|
+
"tree-sitter-wasms": "^0.1.13",
|
|
53
|
+
"web-tree-sitter": "^0.25.10",
|
|
54
|
+
"dsh-plugin-codegraph-service": "^0.1.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@deepseek-ai/cordis": ">=4.0.1",
|
|
58
|
+
"@deepseek-ai/dsh-invariants": ">=0.1.0-rc.6"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
62
|
+
"@deepseek-ai/dsh-invariants": "0.1.0-rc.6"
|
|
63
|
+
}
|
|
64
|
+
}
|