Add secrets to the vscode extension context. (#3881)

* Add secrets to the vscode extension context.

Add a secrets store backed by a file.
Compile the standalone distribtion during `npm run pretest`

* Fix type

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* Remove logging

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
This commit is contained in:
Sarah Fortuneandellipsis-dev[bot] authored and GitHub committed 2025-05-28 15:02:21 -07:00
1 parent a4200869c9
commit a6fbdcb5c1
2 files changed
+49 -9

No files matched your search

+1 -1
View File
@@ -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",
+48 -8
View File
@@ -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<string, string>()
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),