Skip to content

Commit f456792

Browse files
Improve the Chartsmith VS Code Extension (#91)
* improve the chartsmith extension * clean up debug * clean up debug * re-add tsconfig * fix missing extension config * re-add tsconfig * remove changelog * re-add main.go * fix apiURL in fileContent module * remove demo content generation in dev mode * remove www endpoint and just use api endpoint * Revert "remove www endpoint and just use api endpoint" This reverts commit 6a3bf73. * update DEVELOPMENT.MD * fix description for apiEndpoint * remove unneeded commands from the palette * make first user an admin user * remove individual file content route * remove run-postgres make target * use env var for postgres uri for schemahero * update ARCHITECTURE.md * cleanup makefile * remove validateBearerToken use findSession * Remove deprecated individual file endpoint functions * Remove deprecated individual file endpoint functions * remove mock tests * consolidate endpoints to api endpoint * fix missing diff buttons * remove debug code * disable check-env * disable check-env
1 parent b4d8fdc commit f456792

Some content is hidden

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

44 files changed

+6518
-2658
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ bin
33
.aider*
44
test-results/
55
.envrc
6+
.specstory/

ARCHITECTURE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ It's made for both the developer working on it and for AI models to read and app
99
- We have a Postres/pgvector database and Centrifugo for realtime notifications.
1010
- The intent is to keep this system design and avoid new databases, queues, components. Simplicity matters.
1111

12+
## API Design Principles
13+
- Prefer consolidated data endpoints over granular ones to minimize API calls and database load
14+
- Structure API routes using Next.js's file-based routing with resource-oriented paths
15+
- Implement consistent authentication and error handling patterns across endpoints
16+
- Return complete data objects rather than fragments to reduce follow-up requests
17+
- Prioritize server-side data processing over client-side assembly of multiple API calls
18+
19+
1220
# Subprojects
1321
- See chartsmith-app/ARCHITECTURE.md for the architecture principles for the front end.
1422

CONTRIBUTING.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,18 @@ NEXT_PUBLIC_API_ENDPOINT=http://localhost:3000/api
8282
```
8383
This deploys the Schemahero migrations to set up the database schema.
8484

85-
6. **Terminal 4: Claude Integration**
85+
6. **Terminal 4: Bootstrap Chart Data**
86+
```bash
87+
make bootstrap
88+
```
89+
This is a **critical step** that initializes the chart data in the database. Without this step, the application won't have the necessary template data to function properly.
90+
91+
7. **Admin Access**
92+
93+
The first user to log in will automatically be granted admin privileges and bypass the waitlist.
94+
You can log in at: http://localhost:3000/login?test-auth=true
95+
96+
8. **Terminal 5: Claude Integration (optional)**
8697
```bash
8798
# Use Claude for development assistance
8899
```
@@ -94,7 +105,6 @@ NEXT_PUBLIC_API_ENDPOINT=http://localhost:3000/api
94105
make run-worker
95106
```
96107

97-
98108
### Troubleshooting
99109

100110
If you encounter any issues:
@@ -103,6 +113,15 @@ If you encounter any issues:
103113
2. Verify all required secrets are properly configured
104114
3. Check that Schemahero is installed and accessible in your PATH
105115
4. Make sure all dependencies are installed (both Go and npm packages)
116+
5. If you get an error `ERROR: type "vector" does not exist` when running `make schema`, you can manually enable the PGVector extension:
117+
```bash
118+
docker exec -it chartsmith-dev-postgres-1 psql -U postgres -d chartsmith -c "CREATE EXTENSION IF NOT EXISTS vector;"
119+
```
120+
Or simply run the Make target that handles this:
121+
```bash
122+
make pgvector
123+
```
124+
After enabling the extension, run `make schema` again (though it now automatically runs the pgvector target as a prerequisite).
106125

107126
### Development Workflow
108127

@@ -118,6 +137,17 @@ If you encounter any issues:
118137
- The frontend runs on the default Next.js port
119138
- The worker runs on a separate process
120139

140+
## VS Code Extension Development
141+
142+
For detailed instructions on developing the VS Code extension, see [chartsmith-extension/DEVELOPMENT.md](chartsmith-extension/DEVELOPMENT.md).
143+
144+
This guide covers:
145+
- Building and installing the extension from a VSIX file
146+
- Configuring endpoints for local development
147+
- Enabling development mode
148+
- Debugging with the developer console
149+
- Testing extension features with built-in commands
150+
121151
## Release
122152

123153
All releases are automated using various Dagger functions.

Makefile

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,110 @@
1-
21
WORKER_BINARY_NAME=chartsmith-worker
32
WORKER_BUILD_DIR=bin
43

54
GOOS?=$(shell go env GOOS)
65
GOARCH?=$(shell go env GOARCH)
76

8-
.PHONY: run-postgres
9-
run-postgres:
10-
docker run -d --name chartsmith-postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=chartsmith -p 5432:5432 postgres:16
7+
# =============================================================================
8+
# REQUIRED ENVIRONMENT VARIABLES (must be exported by the user)
9+
# =============================================================================
10+
# The following variables MUST be exported before running commands like:
11+
# - make run-worker
12+
# - make bootstrap
13+
# - make run-debug-console
14+
#
15+
# Required variables:
16+
# - ANTHROPIC_API_KEY - API key for Anthropic services
17+
# - GROQ_API_KEY - API key for Groq services
18+
# - VOYAGE_API_KEY - API key for Voyage services
19+
# - CHARTSMITH_PG_URI - PostgreSQL connection string
20+
# - CHARTSMITH_CENTRIFUGO_ADDRESS - Centrifugo service address
21+
# - CHARTSMITH_CENTRIFUGO_API_KEY - API key for Centrifugo
22+
# - GOOGLE_CLIENT_ID - Google OAuth client ID
23+
# - GOOGLE_CLIENT_SECRET - Google OAuth client secret
24+
#
25+
# Example:
26+
# export ANTHROPIC_API_KEY=your-key
27+
# export GROQ_API_KEY=your-key
28+
# export VOYAGE_API_KEY=your-key
29+
# export CHARTSMITH_PG_URI=postgresql://postgres:password@localhost:5432/chartsmith?sslmode=disable
30+
# export CHARTSMITH_CENTRIFUGO_ADDRESS=http://localhost:8000/api
31+
# export CHARTSMITH_CENTRIFUGO_API_KEY=api_key
32+
# export GOOGLE_CLIENT_ID=your-id
33+
# export GOOGLE_CLIENT_SECRET=your-secret
34+
# make run-worker
35+
# =============================================================================
36+
37+
# Environment variables checker helper function
38+
define check_env_var
39+
@if [ -z "$(shell printenv $(1))" ]; then \
40+
echo "Error: $(1) environment variable is not set"; \
41+
echo "Please set this in your shell environment:"; \
42+
echo " export $(1)='your-$(1)-value'"; \
43+
echo ""; \
44+
echo "See CONTRIBUTING.md for more information about required environment variables."; \
45+
exit 1; \
46+
fi
47+
endef
48+
49+
# Check required environment variables
50+
.PHONY: check-env
51+
check-env:
52+
$(call check_env_var,ANTHROPIC_API_KEY)
53+
$(call check_env_var,GROQ_API_KEY)
54+
$(call check_env_var,VOYAGE_API_KEY)
55+
$(call check_env_var,CHARTSMITH_PG_URI)
56+
$(call check_env_var,CHARTSMITH_CENTRIFUGO_ADDRESS)
57+
$(call check_env_var,CHARTSMITH_CENTRIFUGO_API_KEY)
58+
$(call check_env_var,GOOGLE_CLIENT_ID)
59+
$(call check_env_var,GOOGLE_CLIENT_SECRET)
60+
@echo "All required environment variables are set"
61+
62+
# =============================================================================
63+
# DATABASE COMMANDS
64+
# =============================================================================
65+
66+
.PHONY: pgvector
67+
pgvector:
68+
@echo "Ensuring pgvector extension is enabled..."
69+
@PG_CONTAINER=$$(docker ps --format '{{.Names}}' | grep postgres | head -n1); \
70+
if [ -z "$$PG_CONTAINER" ]; then \
71+
echo "Error: No running Postgres container found"; \
72+
echo "Make sure to start the development environment first:"; \
73+
echo " cd hack/chartsmith-dev && docker compose up -d"; \
74+
exit 1; \
75+
fi; \
76+
echo "Using Postgres container: $$PG_CONTAINER"; \
77+
docker exec -i $$PG_CONTAINER psql -U postgres -d chartsmith -c "CREATE EXTENSION IF NOT EXISTS vector;"; \
78+
echo "PGVector extension enabled"
1179

1280
.PHONY: schema
13-
schema:
81+
schema: pgvector
82+
@echo "Running schema commands..."
1483
rm -rf ./db/generated-schema
1584
mkdir -p ./db/generated-schema/tables
16-
schemahero plan --driver postgres --uri $(CHARTSMITH_PG_URI) --spec-file ./db/schema/tables --spec-type table --out ./db/generated-schema/tables
17-
schemahero apply --driver postgres --uri $(CHARTSMITH_PG_URI) --ddl ./db/generated-schema/tables
85+
schemahero plan --driver postgres --uri "$(CHARTSMITH_PG_URI)" --spec-file ./db/schema/tables --spec-type table --out ./db/generated-schema/tables
86+
schemahero apply --driver postgres --uri "$(CHARTSMITH_PG_URI)" --ddl ./db/generated-schema/tables
87+
88+
# =============================================================================
89+
# DEVELOPMENT COMMANDS
90+
# =============================================================================
1891

1992
.PHONY: build
2093
build:
2194
@echo "Building $(WORKER_BINARY_NAME)..."
2295
@mkdir -p $(WORKER_BUILD_DIR)
2396
@go build -o $(WORKER_BUILD_DIR)/$(WORKER_BINARY_NAME) main.go
2497

98+
# Requires: ANTHROPIC_API_KEY, GROQ_API_KEY, VOYAGE_API_KEY
2599
.PHONY: run-worker
26100
run-worker: build
27-
@echo "Running $(WORKER_BINARY_NAME)..."
28-
@./$(WORKER_BUILD_DIR)/$(WORKER_BINARY_NAME) run --
101+
@echo "Running $(WORKER_BINARY_NAME) with environment variables from shell..."
102+
./$(WORKER_BUILD_DIR)/$(WORKER_BINARY_NAME) run --
29103

30104
.PHONY: bootstrap
31105
bootstrap: build
32106
@echo "Bootstrapping chart..."
33-
@./$(WORKER_BUILD_DIR)/$(WORKER_BINARY_NAME) bootstrap \
107+
./$(WORKER_BUILD_DIR)/$(WORKER_BINARY_NAME) bootstrap \
34108
--force
35109

36110
.PHONY: test-data
@@ -49,22 +123,30 @@ integration-test: build
49123
@echo "Running integration tests..."
50124
@./$(WORKER_BUILD_DIR)/$(WORKER_BINARY_NAME) integration
51125

126+
# =============================================================================
127+
# CI/CD AND DEPLOYMENT COMMANDS
128+
# =============================================================================
129+
52130
.PHONY: validate
53131
validate:
54132
dagger call validate \
55133
--op-service-account env:OP_SERVICE_ACCOUNT \
56134
--progress plain
57135

58-
.POHNY: okteto-dev
136+
.PHONY: okteto-dev
59137
okteto-dev:
60138
@go mod download -x
61139
@make build
62140
@printf "\n\n To build and run this project, run: \n\n # make run-worker\n # make run-debug-console\n\n"
63141

142+
# Requires: ANTHROPIC_API_KEY, GROQ_API_KEY, VOYAGE_API_KEY
64143
.PHONY: run-debug-console
65144
run-debug-console:
66-
DB_URI="postgres://postgres:password@localhost:5432/chartsmith?sslmode=disable" go run main.go debug-console
145+
@echo "Running debug console with environment variables from shell..."
146+
@# We set DB_URI to maintain compatibility with existing code
147+
export DB_URI=$(CHARTSMITH_PG_URI) && go run main.go debug-console
67148

149+
# Requires: GITHUB_TOKEN, OP_SERVICE_ACCOUNT_PRODUCTION
68150
.PHONY: release
69151
release:
70152
dagger call release \
@@ -73,6 +155,7 @@ release:
73155
--op-service-account env:OP_SERVICE_ACCOUNT_PRODUCTION \
74156
--progress plain
75157

158+
# Requires: GITHUB_TOKEN, OP_SERVICE_ACCOUNT_PRODUCTION
76159
.PHONY: replicated
77160
replicated:
78161
dagger call release \
@@ -85,6 +168,7 @@ replicated:
85168
--op-service-account env:OP_SERVICE_ACCOUNT_PRODUCTION \
86169
--progress plain
87170

171+
# Requires: REPLICATED_API_TOKEN
88172
.PHONY: replicated-dev
89173
replicated-dev:
90174
dagger call release-dev-replicated \
@@ -93,6 +177,7 @@ replicated-dev:
93177
--api-token env:REPLICATED_API_TOKEN \
94178
--progress plain
95179

180+
# Requires: GITHUB_TOKEN, OP_SERVICE_ACCOUNT_PRODUCTION
96181
.PHONY: production
97182
production:
98183
dagger call release \

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,18 @@ Build Better Helm Charts
66

77
Chartsmith is an AI-powered tool that helps you build better Helm charts.
88

9+
## Development
10+
11+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup instructions.
12+
13+
## Authentication
14+
15+
### Extension Authentication
16+
17+
The VS Code extension authenticates using a token-based mechanism:
18+
19+
1. When a user clicks "Login" in the extension, it opens a browser window to the authentication page
20+
2. After successful authentication, the app generates an extension token and sends it to the extension
21+
3. The extension stores this token and uses it for API requests with a Bearer token header
22+
4. Token validation happens via the `/api/auth/status` endpoint
23+

chartsmith-app/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,20 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next
3434
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
3535

3636
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
37+
38+
## Authentication
39+
40+
### Extension Authentication
41+
42+
The VS Code extension authenticates using a token-based mechanism:
43+
44+
1. When a user clicks "Login" in the extension, it opens a browser window to the authentication page
45+
2. After successful authentication, the app generates an extension token and sends it to the extension
46+
3. The extension stores this token and uses it for API requests with a Bearer token header
47+
4. Token validation happens via the `/api/auth/status` endpoint
48+
49+
To test extension authentication:
50+
```bash
51+
# Run the auth status test script
52+
./test-auth-status.sh <your-token>
53+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { NextResponse } from 'next/server';
2+
import { findSession } from '@/lib/auth/session';
3+
4+
export async function GET(request: Request) {
5+
try {
6+
// Get token from authorization header
7+
const authHeader = request.headers.get('authorization');
8+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
9+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
10+
}
11+
12+
const token = authHeader.substring(7); // Remove 'Bearer ' prefix
13+
14+
// Find session using the token
15+
const session = await findSession(token);
16+
if (!session) {
17+
return NextResponse.redirect(new URL('/login', request.url));
18+
}
19+
20+
// Return complete user info and success status
21+
return NextResponse.json({
22+
user: session.user,
23+
isAuthenticated: true
24+
});
25+
} catch (error) {
26+
console.error('Error in auth status endpoint:', error);
27+
return NextResponse.redirect(new URL('/login', request.url));
28+
}
29+
}

chartsmith-app/app/login-with-test-auth/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ export default function TestAuthPage() {
6969
</Card>
7070
</div>
7171
);
72-
}
72+
}

0 commit comments

Comments
 (0)