@claudiu.ceia/astkit 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 +393 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/src/app.d.ts +1 -0
- package/dist/src/app.js +41 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +4 -0
- package/dist/src/code-rank/code-rank.d.ts +9 -0
- package/dist/src/code-rank/code-rank.js +71 -0
- package/dist/src/code-rank/index.d.ts +1 -0
- package/dist/src/code-rank/index.js +1 -0
- package/dist/src/code-rank/rank.d.ts +29 -0
- package/dist/src/code-rank/rank.js +185 -0
- package/dist/src/common/input.d.ts +5 -0
- package/dist/src/common/input.js +25 -0
- package/dist/src/nav/declarations.d.ts +19 -0
- package/dist/src/nav/declarations.js +106 -0
- package/dist/src/nav/definition.d.ts +14 -0
- package/dist/src/nav/definition.js +62 -0
- package/dist/src/nav/location.d.ts +6 -0
- package/dist/src/nav/location.js +35 -0
- package/dist/src/nav/references.d.ts +19 -0
- package/dist/src/nav/references.js +75 -0
- package/dist/src/patch/patch.d.ts +27 -0
- package/dist/src/patch/patch.js +345 -0
- package/dist/src/pattern/balance.d.ts +1 -0
- package/dist/src/pattern/balance.js +25 -0
- package/dist/src/pattern/index.d.ts +5 -0
- package/dist/src/pattern/index.js +4 -0
- package/dist/src/pattern/match.d.ts +2 -0
- package/dist/src/pattern/match.js +141 -0
- package/dist/src/pattern/render.d.ts +1 -0
- package/dist/src/pattern/render.js +32 -0
- package/dist/src/pattern/syntax.d.ts +3 -0
- package/dist/src/pattern/syntax.js +87 -0
- package/dist/src/pattern/types.d.ts +27 -0
- package/dist/src/pattern/types.js +1 -0
- package/dist/src/search/search.d.ts +16 -0
- package/dist/src/search/search.js +207 -0
- package/dist/src/service.d.ts +16 -0
- package/dist/src/service.js +72 -0
- package/dist/src/sgrep/index.d.ts +5 -0
- package/dist/src/sgrep/index.js +3 -0
- package/dist/src/sgrep/isomorphisms/expand.d.ts +2 -0
- package/dist/src/sgrep/isomorphisms/expand.js +51 -0
- package/dist/src/sgrep/isomorphisms/index.d.ts +3 -0
- package/dist/src/sgrep/isomorphisms/index.js +2 -0
- package/dist/src/sgrep/isomorphisms/registry.d.ts +2 -0
- package/dist/src/sgrep/isomorphisms/registry.js +8 -0
- package/dist/src/sgrep/isomorphisms/rules/commutative-binary.d.ts +2 -0
- package/dist/src/sgrep/isomorphisms/rules/commutative-binary.js +51 -0
- package/dist/src/sgrep/isomorphisms/rules/object-literal-property-order.d.ts +2 -0
- package/dist/src/sgrep/isomorphisms/rules/object-literal-property-order.js +82 -0
- package/dist/src/sgrep/isomorphisms/rules/redundant-parentheses.d.ts +2 -0
- package/dist/src/sgrep/isomorphisms/rules/redundant-parentheses.js +43 -0
- package/dist/src/sgrep/isomorphisms/template-ast.d.ts +2 -0
- package/dist/src/sgrep/isomorphisms/template-ast.js +59 -0
- package/dist/src/sgrep/isomorphisms/types.d.ts +15 -0
- package/dist/src/sgrep/isomorphisms/types.js +0 -0
- package/dist/src/sgrep/phases/output.d.ts +9 -0
- package/dist/src/sgrep/phases/output.js +11 -0
- package/dist/src/sgrep/phases/parse.d.ts +10 -0
- package/dist/src/sgrep/phases/parse.js +11 -0
- package/dist/src/sgrep/phases/search.d.ts +11 -0
- package/dist/src/sgrep/phases/search.js +111 -0
- package/dist/src/sgrep/sgrep.d.ts +3 -0
- package/dist/src/sgrep/sgrep.js +17 -0
- package/dist/src/sgrep/types.d.ts +32 -0
- package/dist/src/sgrep/types.js +3 -0
- package/dist/src/spatch/files.d.ts +7 -0
- package/dist/src/spatch/files.js +51 -0
- package/dist/src/spatch/index.d.ts +3 -0
- package/dist/src/spatch/index.js +2 -0
- package/dist/src/spatch/patch-document.d.ts +9 -0
- package/dist/src/spatch/patch-document.js +64 -0
- package/dist/src/spatch/phases/output.d.ts +9 -0
- package/dist/src/spatch/phases/output.js +15 -0
- package/dist/src/spatch/phases/parse.d.ts +11 -0
- package/dist/src/spatch/phases/parse.js +16 -0
- package/dist/src/spatch/phases/rewrite.d.ts +14 -0
- package/dist/src/spatch/phases/rewrite.js +111 -0
- package/dist/src/spatch/spatch.d.ts +3 -0
- package/dist/src/spatch/spatch.js +17 -0
- package/dist/src/spatch/template.d.ts +2 -0
- package/dist/src/spatch/template.js +1 -0
- package/dist/src/spatch/text.d.ts +5 -0
- package/dist/src/spatch/text.js +35 -0
- package/dist/src/spatch/types.d.ts +40 -0
- package/dist/src/spatch/types.js +20 -0
- package/package.json +66 -0
- package/skills/astkit-tooling/SKILL.md +101 -0
- package/skills/astkit-tooling/agents/openai.yaml +4 -0
- package/skills/astkit-tooling/references/cognitive-model.md +61 -0
- package/skills/astkit-tooling/references/non-goals.md +11 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { compileTemplate, findTemplateMatches, renderTemplate } from "../pattern/index.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function createLineStarts(text) {
|
|
2
|
+
const starts = [0];
|
|
3
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
4
|
+
if (text[index] === "\n") {
|
|
5
|
+
starts.push(index + 1);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return starts;
|
|
9
|
+
}
|
|
10
|
+
export function toLineCharacter(lineStarts, index) {
|
|
11
|
+
if (lineStarts.length === 0) {
|
|
12
|
+
return { line: 1, character: Math.max(index + 1, 1) };
|
|
13
|
+
}
|
|
14
|
+
let low = 0;
|
|
15
|
+
let high = lineStarts.length - 1;
|
|
16
|
+
while (low <= high) {
|
|
17
|
+
const middle = Math.floor((low + high) / 2);
|
|
18
|
+
const start = lineStarts[middle] ?? 0;
|
|
19
|
+
const nextStart = lineStarts[middle + 1] ?? Number.POSITIVE_INFINITY;
|
|
20
|
+
if (start <= index && index < nextStart) {
|
|
21
|
+
return { line: middle + 1, character: index - start + 1 };
|
|
22
|
+
}
|
|
23
|
+
if (index < start) {
|
|
24
|
+
high = middle - 1;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
low = middle + 1;
|
|
28
|
+
}
|
|
29
|
+
const fallback = lineStarts[lineStarts.length - 1] ?? 0;
|
|
30
|
+
const line = Math.max(lineStarts.length, 1);
|
|
31
|
+
return {
|
|
32
|
+
line,
|
|
33
|
+
character: Math.max(index - fallback + 1, 1),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const DEFAULT_PATCHABLE_EXTENSIONS: readonly [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
2
|
+
export declare const DEFAULT_EXCLUDED_DIRECTORIES: readonly [".git", "node_modules", ".next", ".turbo", "dist", "build", "coverage", "out"];
|
|
3
|
+
export type SpatchOptions = {
|
|
4
|
+
scope?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
extensions?: readonly string[];
|
|
8
|
+
excludedDirectories?: readonly string[];
|
|
9
|
+
encoding?: BufferEncoding;
|
|
10
|
+
};
|
|
11
|
+
export type SpatchOccurrence = {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
line: number;
|
|
15
|
+
character: number;
|
|
16
|
+
matched: string;
|
|
17
|
+
replacement: string;
|
|
18
|
+
captures: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
export type SpatchFileResult = {
|
|
21
|
+
file: string;
|
|
22
|
+
matchCount: number;
|
|
23
|
+
replacementCount: number;
|
|
24
|
+
changed: boolean;
|
|
25
|
+
byteDelta: number;
|
|
26
|
+
occurrences: SpatchOccurrence[];
|
|
27
|
+
};
|
|
28
|
+
export type SpatchResult = {
|
|
29
|
+
dryRun: boolean;
|
|
30
|
+
scope: string;
|
|
31
|
+
pattern: string;
|
|
32
|
+
replacement: string;
|
|
33
|
+
filesScanned: number;
|
|
34
|
+
filesMatched: number;
|
|
35
|
+
filesChanged: number;
|
|
36
|
+
totalMatches: number;
|
|
37
|
+
totalReplacements: number;
|
|
38
|
+
elapsedMs: number;
|
|
39
|
+
files: SpatchFileResult[];
|
|
40
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const DEFAULT_PATCHABLE_EXTENSIONS = [
|
|
2
|
+
".ts",
|
|
3
|
+
".tsx",
|
|
4
|
+
".mts",
|
|
5
|
+
".cts",
|
|
6
|
+
".js",
|
|
7
|
+
".jsx",
|
|
8
|
+
".mjs",
|
|
9
|
+
".cjs",
|
|
10
|
+
];
|
|
11
|
+
export const DEFAULT_EXCLUDED_DIRECTORIES = [
|
|
12
|
+
".git",
|
|
13
|
+
"node_modules",
|
|
14
|
+
".next",
|
|
15
|
+
".turbo",
|
|
16
|
+
"dist",
|
|
17
|
+
"build",
|
|
18
|
+
"coverage",
|
|
19
|
+
"out",
|
|
20
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@claudiu.ceia/astkit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Structural navigation, search, and rewrite tooling for TypeScript/JavaScript repositories.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ClaudiuCeia/astkit.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/ClaudiuCeia/astkit/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/ClaudiuCeia/astkit#readme",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"astkit": "./dist/src/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"skills/astkit-tooling"
|
|
31
|
+
],
|
|
32
|
+
"keywords": [
|
|
33
|
+
"typescript",
|
|
34
|
+
"javascript",
|
|
35
|
+
"ast",
|
|
36
|
+
"codemod",
|
|
37
|
+
"code-search",
|
|
38
|
+
"code-navigation",
|
|
39
|
+
"llm-tools"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"astkit": "bun run src/cli.ts",
|
|
46
|
+
"dev": "bun src/cli.ts",
|
|
47
|
+
"build": "tsc -p tsconfig.build.json",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"test": "bun test",
|
|
50
|
+
"prepack": "npm run build",
|
|
51
|
+
"pack:check": "npm_config_cache=.npm-cache npm pack --dry-run",
|
|
52
|
+
"skill:install": "npx skills add ./skills/astkit-tooling -a codex -y"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/bun": "latest",
|
|
56
|
+
"typescript": "^5.9.3"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@claudiu-ceia/combine": "npm:@jsr/claudiu-ceia__combine",
|
|
60
|
+
"@stricli/core": "^1.2.5",
|
|
61
|
+
"chalk": "^5.6.2"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"typescript": "^5"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: astkit-tooling
|
|
3
|
+
description: Use when a TypeScript/JavaScript task needs symbol navigation (`nav declarations|definition|references`), structural pattern search (`search`), structural rewrites (`patch`), or reference-based blast-radius estimation (`code-rank`). Prefer for compact, scoped repository analysis and migration work; do not use for runtime-path proofs, correctness guarantees, or replacing compiler/tests.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# astkit tooling
|
|
7
|
+
|
|
8
|
+
Use `astkit` for token-efficient repository exploration and structural edits in TS/JS projects.
|
|
9
|
+
Keep scope narrow first, expand only when evidence is insufficient.
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
1. Confirm tool availability.
|
|
14
|
+
- `astkit --help`
|
|
15
|
+
- or `npx astkit --help`
|
|
16
|
+
- or `bunx astkit --help`
|
|
17
|
+
|
|
18
|
+
2. Start with one focused operation.
|
|
19
|
+
- `astkit nav declarations <file>`
|
|
20
|
+
- `astkit nav definition <file:line:character>`
|
|
21
|
+
- `astkit nav references <file:line:character>`
|
|
22
|
+
- `astkit search '<pattern>' <scope> --json`
|
|
23
|
+
- `astkit patch --dry-run '<patch-document>' <scope>`
|
|
24
|
+
- `astkit code-rank <scope> --limit 25 --json`
|
|
25
|
+
|
|
26
|
+
3. Expand scope only if needed.
|
|
27
|
+
|
|
28
|
+
## Working Workflow
|
|
29
|
+
|
|
30
|
+
1. Map contracts before implementation details.
|
|
31
|
+
- Use `nav declarations` and `nav definition` first.
|
|
32
|
+
- Treat signatures/docs as intended contracts until contradicted by evidence.
|
|
33
|
+
|
|
34
|
+
2. Clarify behavior from usage.
|
|
35
|
+
- Use `nav references` to inspect representative callsites.
|
|
36
|
+
- Prefer usage patterns over deep source reading for initial understanding.
|
|
37
|
+
|
|
38
|
+
3. Estimate blast radius before edits.
|
|
39
|
+
- Use `code-rank` and references to identify high-impact symbols.
|
|
40
|
+
- Prefer localized changes when task scope is localized.
|
|
41
|
+
|
|
42
|
+
4. Rewrite with structural tools.
|
|
43
|
+
- Use `search` to find candidate shapes.
|
|
44
|
+
- Use `patch --dry-run` before writing changes.
|
|
45
|
+
- Use `patch --interactive` for high-risk or broad rewrites.
|
|
46
|
+
|
|
47
|
+
5. Re-check and validate.
|
|
48
|
+
- Re-run focused `search`/`nav references` on touched symbols.
|
|
49
|
+
- Validate with `tsc` and relevant tests when available.
|
|
50
|
+
|
|
51
|
+
## Safe Rewrite Workflow
|
|
52
|
+
|
|
53
|
+
1. Find candidate sites.
|
|
54
|
+
- `astkit search '<pattern>' <scope> --json`
|
|
55
|
+
|
|
56
|
+
2. Preview rewrite.
|
|
57
|
+
- `astkit patch --dry-run '<patch-document>' <scope>`
|
|
58
|
+
|
|
59
|
+
3. Apply rewrite.
|
|
60
|
+
- `astkit patch '<patch-document>' <scope>`
|
|
61
|
+
- Use `--interactive` for high-risk or broad edits.
|
|
62
|
+
|
|
63
|
+
4. Re-check surfaced contracts.
|
|
64
|
+
- Re-run focused `search` queries and `nav references` on touched symbols.
|
|
65
|
+
|
|
66
|
+
5. Validate with compiler and tests.
|
|
67
|
+
- Run `tsc` diagnostics.
|
|
68
|
+
- Run focused tests for touched behavior.
|
|
69
|
+
|
|
70
|
+
## Reporting Contract
|
|
71
|
+
|
|
72
|
+
When reporting findings, include:
|
|
73
|
+
|
|
74
|
+
- system boundaries and entry points
|
|
75
|
+
- invariants/contracts with explicit status (`observed` vs `inferred`)
|
|
76
|
+
- definition/reference flow summary
|
|
77
|
+
- change hotspots/dependency hubs
|
|
78
|
+
- suggested edits with blast-radius notes
|
|
79
|
+
- validation status and remaining gaps
|
|
80
|
+
|
|
81
|
+
Keep output concise and include file paths/spans where possible.
|
|
82
|
+
|
|
83
|
+
## Guardrails
|
|
84
|
+
|
|
85
|
+
- Structural similarity does not imply behavioral equivalence.
|
|
86
|
+
- Structural rewrites reduce accidental matches but do not guarantee correctness.
|
|
87
|
+
- Reference ranking approximates impact, not runtime criticality.
|
|
88
|
+
- No matches do not prove absence of behavior.
|
|
89
|
+
- Do not use this skill as a substitute for compiler diagnostics or tests.
|
|
90
|
+
|
|
91
|
+
## Common Failure Modes
|
|
92
|
+
|
|
93
|
+
- Too many matches: narrow scope, add delimiters, add regex constraints.
|
|
94
|
+
- No matches: verify pattern shape, scope, and `--no-isomorphisms` usage.
|
|
95
|
+
- Rewrite too broad: switch to `--interactive` and re-run dry-run first.
|
|
96
|
+
- Unclear impact: inspect `nav references` and `code-rank` before applying.
|
|
97
|
+
|
|
98
|
+
## References
|
|
99
|
+
|
|
100
|
+
- `./references/cognitive-model.md`
|
|
101
|
+
- `./references/non-goals.md`
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Repository Comprehension Model
|
|
2
|
+
|
|
3
|
+
Use this vocabulary when building repository summaries and implementation plans.
|
|
4
|
+
|
|
5
|
+
## System Boundaries and Entry Points
|
|
6
|
+
|
|
7
|
+
Capture:
|
|
8
|
+
- subsystem boundaries
|
|
9
|
+
- external interfaces
|
|
10
|
+
- entry points (HTTP handlers, queue consumers, CLI commands)
|
|
11
|
+
|
|
12
|
+
Prioritize purpose and responsibility over local implementation detail.
|
|
13
|
+
|
|
14
|
+
## Invariants and Contracts
|
|
15
|
+
|
|
16
|
+
Track rules that appear to remain stable across edits.
|
|
17
|
+
Examples:
|
|
18
|
+
- idempotency requirements
|
|
19
|
+
- authentication/authorization preconditions
|
|
20
|
+
- non-blocking or latency constraints
|
|
21
|
+
- schema or API compatibility contracts
|
|
22
|
+
|
|
23
|
+
Treat these as working hypotheses and re-check them after structural rewrites.
|
|
24
|
+
|
|
25
|
+
## Control Flow and Data Flow
|
|
26
|
+
|
|
27
|
+
Start from definitions and references, then inspect local implementation where needed.
|
|
28
|
+
Use navigation queries to map how symbols and values move across boundaries.
|
|
29
|
+
This gives a practical flow model, not whole-program path analysis.
|
|
30
|
+
|
|
31
|
+
## Change Hotspots and Dependency Hubs
|
|
32
|
+
|
|
33
|
+
Use recognized maintenance signals:
|
|
34
|
+
- change hotspots: areas with frequent edits and defect risk
|
|
35
|
+
- dependency hubs: symbols/modules with high fan-in or centrality
|
|
36
|
+
- blast radius: expected impact surface of a change
|
|
37
|
+
|
|
38
|
+
Use `code-rank` as an initial signal, then validate with local code inspection.
|
|
39
|
+
|
|
40
|
+
## Cognitive Load and Working Set
|
|
41
|
+
|
|
42
|
+
Treat active reasoning capacity as limited.
|
|
43
|
+
Keep in the working set:
|
|
44
|
+
- boundaries
|
|
45
|
+
- invariants
|
|
46
|
+
- flow skeleton
|
|
47
|
+
- top hotspots/hubs
|
|
48
|
+
|
|
49
|
+
Treat as recoverable on demand through tools:
|
|
50
|
+
- boilerplate
|
|
51
|
+
- generated code
|
|
52
|
+
- straightforward adapters
|
|
53
|
+
- low-signal implementation details
|
|
54
|
+
|
|
55
|
+
## Practical Heuristics
|
|
56
|
+
|
|
57
|
+
- Prefer design intent over mechanism detail.
|
|
58
|
+
- Track invariants and contracts, not full function bodies.
|
|
59
|
+
- Follow definition/reference links before deep local reading.
|
|
60
|
+
- Prioritize high-impact hotspots and dependency hubs.
|
|
61
|
+
- Defer low-signal code until required by a concrete task.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Non-Goals
|
|
2
|
+
|
|
3
|
+
`astkit` is not designed to:
|
|
4
|
+
|
|
5
|
+
- infer developer intent from naming or style alone
|
|
6
|
+
- model full runtime behavior across dynamic dispatch and I/O
|
|
7
|
+
- guarantee that structural rewrites preserve behavior
|
|
8
|
+
- replace compiler diagnostics, linters, or test suites
|
|
9
|
+
- decide whether a refactor should be applied without human review
|
|
10
|
+
- rank runtime criticality from references alone
|
|
11
|
+
- treat missing matches as proof that a pattern is absent
|