Skip to content

Commit 5af12b4

Browse files
authored
Merge pull request #43 from knitli/feat-phase-zero
2 parents 1006828 + 413d3bf commit 5af12b4

File tree

206 files changed

+38728
-2741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+38728
-2741
lines changed

.cargo/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[unstable]
2+
codegen-backend = true
3+
4+
[profile.dev]
5+
codegen-backend = "cranelift"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SPDX-FileCopyrightText: 2025 Knitli Inc. <[email protected]>
2+
SPDX-FileContributor: Adam Poulemanos <[email protected]>
3+
4+
SPDX-License-Identifier: MIT OR Apache-2.0

.gitattributes

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2025 Knitli Inc. <[email protected]>
2+
# SPDX-FileContributor: Adam Poulemanos <[email protected]>
3+
# SPDX-License-Identifier: MIT OR Apache-2.0
4+
#
5+
# Set default behavior to automatically normalize line endings
6+
* text=auto
7+
8+
# Force most text files to always use LF
9+
*.astro text eol=lf
10+
*.css text eol=lf
11+
*.csv text eol=lf
12+
*.cts text eol=lf
13+
*.go text eol=lf
14+
*.html text eol=lf
15+
*.ini text eol=lf
16+
*.js text eol=lf
17+
*.json text eol=lf
18+
*.jsx text eol=lf
19+
*.md text eol=lf
20+
*.mdx text eol=lf
21+
*.mts text eol=lf
22+
*.pkl text eol=lf
23+
*.py text eol=lf
24+
*.rs text eol=lf
25+
*.sh text eol=lf
26+
*.svelte text eol=lf
27+
*.svg text eol=lf
28+
*.toml text eol=lf
29+
*.ts text eol=lf
30+
*.tsx text eol=lf
31+
*.txt text eol=lf
32+
*.xml text eol=lf
33+
*.yaml text eol=lf
34+
*.yml text eol=lf
35+
.git* text eol=LF
36+
LICENSE text eol=lf
37+
LICENSE* text eol=lf
38+
39+
# Force batch files to use CRLF (Windows scripts)
40+
*.bat text eol=crlf
41+
*.ps* text eol=crlf
42+
43+
# Treat these as binary (no line ending conversion)
44+
*.aac binary
45+
*.avif binary
46+
*.docx binary
47+
*.eot binary
48+
*.exe binary
49+
*.flac binary
50+
*.ico binary
51+
*.jpg binary
52+
*.m4a binary
53+
*.mp3 binary
54+
*.mp4 binary
55+
*.ogg binary
56+
*.otf binary
57+
*.pdf binary
58+
*.png binary
59+
*.pptx binary
60+
*.tar* binary
61+
*.ttf binary
62+
*.wav binary
63+
*.webm binary
64+
*.webp binary
65+
*.woff binary
66+
*.woff2 binary
67+
*.xlsx binary
68+
*.zip binary

.github/actionlint.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2025 Knitli Inc. <[email protected]>
2+
# SPDX-FileContributor: Adam Poulemanos <[email protected]>
3+
#
4+
# SPDX-License-Identifier: MIT OR Apache-2.0
5+
# ! Actionlint configuration file to ignore specific warnings
6+
paths:
7+
.github/workflows/cla.yml:
8+
ignore:
9+
- 'property "is_member" is not defined in object type {}'
10+
- >
11+
"github.event.pull_request.title" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions for more details
12+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
# SPDX-FileCopyrightText: 2025 Knitli Inc. <[email protected]>
3+
# SPDX-FileContributor: Adam Poulemanos <[email protected]>
4+
# SPDX-License-Identifier: MIT OR Apache-2.0
5+
description: 'Code Analysis'
6+
tools: ["codebase", "githubRepo", "context7", "sequential-thinking", "View", "GrepTool", "BatchTool", "GlobTool"]
7+
---
8+
# Expert Code Analyst
9+
10+
You're an experienced code analyst who specializes in identifying and resolving issues in codebases. Your primary focus is on improving code quality through best practices and identifying opportunities to refactor or restructure code to make it more flexible and easier to maintain.
11+
12+
## Instructions
13+
14+
The user will ask you to research specific code, modules, or packages within the codebase. They may ask for a specific analysis or aspect of the code to focus on, or they may request a broader overview of the codebase's structure and design and recommendations for improvements.
15+
16+
If you identify an opportunity to improve code quality:
17+
18+
- provide actionable suggestions and code examples to help the user implement the improvements.
19+
- Produce a report summarizing your findings with specific recommendations. The report should include specific recommendations and references to specific code snippets by line number and filename.
20+
- If the user requests a different result or output, then follow their instructions.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# SPDX-FileCopyrightText: 2025 Knitli Inc. <[email protected]>
3+
# SPDX-FileContributor: Adam Poulemanos <[email protected]>
4+
# SPDX-License-Identifier: MIT OR Apache-2.0
5+
description: 'Documentation Writer'
6+
tools: ["codebase", "githubRepo", "context7", "sequential-thinking", "View", "GrepTool", "BatchTool", "GlobTool"]
7+
---
8+
9+
# Your Role
10+
11+
## You Are an Expert Technical Writer
12+
13+
You are a very experienced developer and technical writer. You specialize in creating clear, comprehensive documentation for software projects. You use your deep engineering background to communicate complex ideas in a simple and easy to understand way. You use plain language and provide realistic and concrete examples when code might be difficult to understand. You write useful and informative documentation, including README, CONTRIBUTING, other guides, and in-code documentation for module, class/structs, and methods.
14+
15+
Your approach is to carefully consider what someone new to the project would need to know to understand and use the codebase quickly and easily. You don't assume readers have previous knowledge of the codebase, the libraries it uses, or the functionality it provides, and aim to briefly communicate this information.
16+
17+
## Instructions (unless the user instructs differently)
18+
19+
- Write all documentation in active voice and present tense.
20+
- Don't use filler words and phrases like "This function..." or "this module..."
21+
- **Use plain language**, and don't assume readers are familiar with very technical concepts.
22+
- Avoid technical terms and jargon, and explain them when you must use them.
23+
- Use analogies and examples to illustrate complex ideas.
24+
- Effectively use markdown formatting to emphasize and illustrate information, such as headers, bold/italic, tables.
25+
- Include code snippets and examples to clarify complex concepts.
26+
- Always consider the most likely audience for each piece of documentation, for example:
27+
- Documentation for Public APIs should focus on use cases, and provide practical information for using the API effectively.
28+
- Documentation for non-public or internal APIs should focus on implementation details and explaining the role of the API within the codebase.
29+
- Documentation for end-users should focus on how to use the software, including installation instructions, tutorials, and examples.
30+
- Consider a broad audience for README files and usage guides that may include non-technical users.
31+
- Write documentation that will be easy to maintain and update.
32+
- Respond with direct edits to files, and create them if they aren't there.
33+
- Keep code comments brief and follow idiomatic structure for quality Rust documentation.
34+
- Don't add unnecessary comments, like on functions that are self-explanatory (like a function `add_numbers` that takes two integers are input and returns an integer).
35+
- Use Rustdoc-style code linking to provide useful context to in-code documentation, but don't link to specific lines of code (this is very hard to maintain).
36+
- Save more robust comments for the most complex or important parts of the code, and use clear and realistic examples to illustrate difficult sections.
37+
- Provide clear and explanatory comments for every module, trait, and struct. Document functions and methods that are important or not obvious.
38+
- Focus on communicating the important concepts that a developer new to the code would need to use and work with the code effectively.

.github/dependabot.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1-
version: 2
2-
updates:
3-
- package-ecosystem: cargo
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: "08:00"
8-
open-pull-requests-limit: 10
1+
# SPDX-FileCopyrightText: 2025 Knitli Inc. <[email protected]>
2+
# SPDX-FileContributor: Adam Poulemanos <[email protected]>
3+
#
4+
# SPDX-License-Identifier: MIT OR Apache-2.0
5+
version: 2
6+
updates:
7+
- package-ecosystem: cargo
8+
dependency-type: all
9+
update-types:
10+
- version-update:semver-minor
11+
- version-update:semver-patch
12+
versioning-strategy: increase
13+
directory: "/"
14+
schedule:
15+
interval: daily
16+
time: "23:00"
17+
open-pull-requests-limit: 10
18+
commit-message:
19+
prefix: "deps"
20+
assignees:
21+
- codegen-sh[bot]
22+
reviewers:
23+
- codegen-sh[bot]
24+
labels:
25+
- "dependencies"
26+
rebase-strategy: auto
27+
- package-ecosystem: github-actions
28+
dependency-type: all
29+
update-types:
30+
- version-update:semver-major
31+
- version-update:semver-minor
32+
- version-update:semver-patch
33+
versioning-strategy: increase
34+
directory: "/.github/workflows"
35+
schedule:
36+
interval: daily
37+
time: "23:00"
38+
open-pull-requests-limit: 10
39+
commit-message:
40+
prefix: "deps"
41+
assignees:
42+
- codegen-sh[bot]
43+
reviewers:
44+
- codegen-sh[bot]
45+
labels:
46+
- "dependencies"
47+
rebase-strategy: auto

.github/dontusefornow.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2025 Knitli Inc. <[email protected]>
3+
SPDX-FileContributor: Adam Poulemanos <[email protected]>
4+
SPDX-License-Identifier: MIT OR Apache-2.0
5+
-->
6+
7+
# Copilot Instructions for Thread
8+
9+
## Project Overview
10+
11+
Thread is a Rust code analysis engine that provides intelligent context for AI assistants. The project is transitioning from vendored ast-grep CLI code to a multi-environment service architecture supporting CLI, cloud, WASM, and CI/CD deployments.
12+
13+
## Architecture Guidelines
14+
15+
### Service Layer Pattern
16+
The codebase follows a service abstraction pattern to support multiple environments:
17+
18+
```rust
19+
// Pure service functions (environment-agnostic)
20+
pub async fn scan_with_services(
21+
file_discovery: Arc<dyn FileDiscoveryService>,
22+
config_service: Arc<dyn ConfigurationService>,
23+
options: ScanOptions,
24+
) -> Result<ScanResults>
25+
```
26+
27+
### Crate Organization
28+
29+
- **ag-thread/**: Vendored ast-grep modules being refactored for service layers
30+
- **thread-core/**: Core traits, types, and errors (pure abstractions)
31+
- **thread-engine/**: Main analysis implementation using petgraph
32+
- **thread-parse/**: AST-grep integration and language detection
33+
- **Service-ready crates**: `ag-core`, `ag-search`, `ag-fix`, `ag-types`, `ag-label`
34+
- **Needs refactoring**: `ag-scan`, `ag-utils`, `ag-check-rule` (heavy CLI dependencies)
35+
36+
## Development Commands
37+
38+
Essential commands for this workspace:
39+
40+
```bash
41+
# Build all crates (except WASM)
42+
mise run build
43+
mise run b
44+
45+
# WASM builds
46+
mise run build-wasm # Development (single-threaded)
47+
mise run build-wasm-release # Production optimized
48+
49+
# Testing and quality
50+
mise run test # Tests with cargo nextest
51+
mise run lint # Full linting via hk run check
52+
mise run ci # All CI checks
53+
```
54+
55+
## Key Patterns to Follow
56+
57+
### 1. Service Trait Definitions
58+
When creating new services, follow the pattern from `ag-types`:
59+
60+
```rust
61+
#[async_trait]
62+
pub trait YourService: Send + Sync {
63+
async fn your_method(&self, input: &str) -> Result<Output>;
64+
}
65+
```
66+
67+
### 2. Environment-Agnostic Core Functions
68+
Avoid CLI dependencies in core logic:
69+
70+
```rust
71+
// ✅ Good: Pure function with injected services
72+
pub async fn analyze_with_services(
73+
content: String,
74+
services: &ServiceRegistry
75+
) -> Result<AnalysisResult>
76+
77+
// ❌ Avoid: Direct filesystem or terminal access
78+
pub fn analyze_files(paths: Vec<PathBuf>) -> Result<()>
79+
```
80+
81+
### 3. Multi-Environment Support
82+
Structure implementations for different environments:
83+
84+
```rust
85+
// CLI implementation
86+
impl YourService for CliYourService { /* uses std::fs */ }
87+
88+
// Cloud implementation
89+
impl YourService for CloudYourService { /* uses S3/HTTP */ }
90+
91+
// WASM implementation
92+
impl YourService for WasmYourService { /* uses fetch API */ }
93+
```
94+
95+
## CLI Dependencies Analysis Status
96+
97+
Refer to individual `CLI_DEPENDENCIES.md` files in each ag-thread crate:
98+
99+
- **Immediate attention needed**: `ag-scan/`, `ag-utils/` (heavy CLI dependencies)
100+
- **Service-ready**: `ag-core/`, `ag-search/`, `ag-fix/`, `ag-types/`, `ag-label/`
101+
- **Minor refactoring**: `ag-rule/`, `ag-check-rule/`
102+
103+
## Critical Abstractions
104+
105+
### File Operations
106+
Replace direct filesystem access with service traits:
107+
```rust
108+
// Instead of std::fs::read_to_string
109+
let content = file_service.read_file(path).await?;
110+
```
111+
112+
### Terminal I/O
113+
Replace direct terminal access with service traits:
114+
```rust
115+
// Instead of println! or crossterm
116+
output_service.write(&format!("Result: {}", result)).await?;
117+
```
118+
119+
### Configuration Loading
120+
Replace direct file config loading:
121+
```rust
122+
// Instead of reading YAML files directly
123+
let rules = config_service.load_rules(ConfigSource::Path(path)).await?;
124+
```
125+
126+
## Testing Strategy
127+
128+
- Use `cargo nextest -j 1` for parallel tests with race condition prevention
129+
- Mock service implementations for unit tests
130+
- Environment-specific integration tests for each service implementation
131+
- `RUST_BACKTRACE=1` enabled for debugging
132+
133+
## WASM Considerations
134+
135+
- Default builds are single-threaded for Cloudflare Workers compatibility
136+
- Core logic separated from filesystem operations for WASM portability
137+
- Multi-threaded builds available for browser environments (`--multi-threading`)
138+
139+
When working with WASM targets, ensure no direct filesystem or process dependencies in core libraries.
140+
141+
## Current Development Focus
142+
143+
**Week 1 Sprint**: Establishing service layer foundations
144+
- Refactoring `ag-scan` to use service abstractions
145+
- Creating `ag-services` crate with core trait definitions
146+
- Implementing CLI service adapters to maintain current functionality
147+
148+
The goal is to enable Thread to analyze code and provide AI-friendly context across all deployment environments while maintaining the performance and functionality of the original ast-grep implementation.

0 commit comments

Comments
 (0)