diff --git a/package.json b/package.json index c60e3049..187b2855 100644 --- a/package.json +++ b/package.json @@ -283,7 +283,7 @@ "postprotos": "prettier src/shared/proto src/core/controller webview-ui/src/services src/standalone/server-setup.ts --write --log-level silent", "compile-tests": "node ./scripts/build-tests.js", "watch-tests": "tsc -p . -w --outDir out", - "pretest": "npm run compile-tests && npm run compile && npm run lint", + "pretest": "npm run compile-tests && npm run compile && npm run compile-standalone && npm run lint", "check-types": "npm run protos && tsc --noEmit", "lint": "eslint src --ext ts && eslint webview-ui/src --ext ts", "format": "prettier . --check", diff --git a/src/standalone/vscode-context.ts b/src/standalone/vscode-context.ts index ce65782f..f15d9411 100644 --- a/src/standalone/vscode-context.ts +++ b/src/standalone/vscode-context.ts @@ -1,8 +1,13 @@ // @ts-nocheck import * as vscode from "vscode" +import * as fs from "fs" +import * as path from "path" + import open from "open" import { log } from "./utils" +const DATA_DIR = process.env.DATA_DIR ?? "." + function stubUri(path: string): vscode.Uri { console.log(`Using file path: ${path}`) return { @@ -46,6 +51,46 @@ function createMemento(): vscode.Memento { } } +class SecretStore { + // A simple key-value store for secrets backed by a JSON file. This is not secure, and it is not thread-safe. + private store = new Map() + private filePath: string + + constructor() { + this.filePath = path.join(DATA_DIR, "secrets.json") + this.load() + } + + private load(): void { + if (fs.existsSync(this.filePath)) { + const data = JSON.parse(fs.readFileSync(this.filePath, "utf-8")) + Object.entries(data).forEach(([k, v]) => { + if (typeof v === "string") { + this.store.set(k, v) + } + }) + } + } + + private save(): void { + fs.writeFileSync(this.filePath, JSON.stringify(Object.fromEntries(this.store), null, 2)) + } + + get(key: string): string | undefined { + return this.store.get(key) + } + + storeSecret(key: string, value: string): void { + this.store.set(key, value) + this.save() + } + + delete(key: string): void { + this.store.delete(key) + this.save() + } +} + const extensionContext: vscode.ExtensionContext = { extensionPath: "/tmp/vscode/extension", extensionUri: stubUri("/tmp/vscode/extension"), @@ -121,7 +166,7 @@ const extensionContext: vscode.ExtensionContext = { extensionMode: 1, // Development extension: { - id: "your.extension.id", + id: "saoudrizwan.claude-dev", isActive: true, extensionPath: "/tmp/vscode/extension", extensionUri: stubUri("/tmp/vscode/extension"), @@ -134,15 +179,10 @@ const extensionContext: vscode.ExtensionContext = { subscriptions: [], asAbsolutePath: (relPath) => `/tmp/vscode/extension/${relPath}`, - - secrets: { - store: async () => {}, - get: async () => undefined, - delete: async () => {}, - onDidChange: {}, - }, } +extensionContext.secrets = new SecretStore() + const outputChannel: vscode.OutputChannel = { append: (text) => process.stdout.write(text), appendLine: (line) => console.log(line),