CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | /**
* Block G4 — Gluecron VS Code extension.
*
* Commands:
* gluecron.explainFile — call `/api/v1/ai/explain-file` + show in a hover
* gluecron.openOnWeb — opens the current file on the Gluecron web UI
* gluecron.searchSemantic — quickPick -> /api/v1/search/semantic
* gluecron.generateTests — scaffold a failing test via /api/v1/ai/tests
*
* We keep this file zero-runtime-dependencies besides `vscode`. Everything
* else is pure stdlib + fetch.
*/
import * as vscode from "vscode";
import { execSync } from "node:child_process";
import { basename, relative } from "node:path";
function getHost(): string {
return (
vscode.workspace.getConfiguration("gluecron").get<string>("host") ||
"http://localhost:3000"
);
}
function getToken(): string {
return (
vscode.workspace.getConfiguration("gluecron").get<string>("token") || ""
);
}
async function api<T = any>(path: string, init?: RequestInit): Promise<T> {
const url = getHost().replace(/\/+$/, "") + path;
const token = getToken();
const res = await fetch(url, {
...init,
headers: {
"content-type": "application/json",
accept: "application/json",
...(token ? { authorization: `Bearer ${token}` } : {}),
...(init?.headers || {}),
},
});
const text = await res.text();
if (!res.ok) throw new Error(`[${res.status}] ${text.slice(0, 200)}`);
try {
return JSON.parse(text) as T;
} catch {
return text as unknown as T;
}
}
/**
* Inspect the current workspace for a git remote whose URL matches a Gluecron
* host. Returns `{ owner, repo }` if found.
*/
export function detectGlueRepo(cwd: string, host: string): {
owner: string;
repo: string;
} | null {
try {
const url = execSync("git config --get remote.origin.url", {
cwd,
encoding: "utf8",
}).trim();
if (!url) return null;
// host-agnostic parsing — look for /:owner/:repo at end
const cleaned = url
.replace(/^https?:\/\/[^/]+\//, "")
.replace(/^git@[^:]+:/, "")
.replace(/\.git$/, "");
const [owner, repo] = cleaned.split("/").filter(Boolean);
if (!owner || !repo) return null;
return { owner, repo };
} catch {
return null;
}
}
export function buildWebUrl(
host: string,
owner: string,
repo: string,
relPath: string,
line?: number
): string {
const base = `${host.replace(/\/+$/, "")}/${owner}/${repo}/blob/main/${relPath}`;
return line ? `${base}#L${line + 1}` : base;
}
export function activate(context: vscode.ExtensionContext) {
const output = vscode.window.createOutputChannel("Gluecron");
output.appendLine("Gluecron activated.");
context.subscriptions.push(
vscode.commands.registerCommand("gluecron.openOnWeb", async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showInformationMessage("No active editor");
return;
}
const folder = vscode.workspace.getWorkspaceFolder(editor.document.uri);
if (!folder) {
vscode.window.showWarningMessage("File is not in a workspace");
return;
}
const cwd = folder.uri.fsPath;
const rel = relative(cwd, editor.document.uri.fsPath);
const repo = detectGlueRepo(cwd, getHost());
if (!repo) {
vscode.window.showWarningMessage("No Gluecron remote detected");
return;
}
const url = buildWebUrl(
getHost(),
repo.owner,
repo.repo,
rel,
editor.selection.active.line
);
vscode.env.openExternal(vscode.Uri.parse(url));
})
);
context.subscriptions.push(
vscode.commands.registerCommand("gluecron.explainFile", async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) return;
const content = editor.document.getText();
const path = basename(editor.document.fileName);
output.show(true);
output.appendLine(`Explaining ${path}...`);
try {
const res = await api<{ explanation?: string }>(
`/api/copilot/completions`,
{
method: "POST",
body: JSON.stringify({
prompt: `Explain this file in 3-5 bullet points:\n\n${content.slice(
0,
8000
)}`,
max_tokens: 400,
}),
}
);
output.appendLine(res.explanation || JSON.stringify(res, null, 2));
} catch (err) {
output.appendLine(`error: ${(err as Error).message}`);
}
})
);
context.subscriptions.push(
vscode.commands.registerCommand("gluecron.searchSemantic", async () => {
const q = await vscode.window.showInputBox({
prompt: "Semantic search across repo",
placeHolder: "how does auth work?",
});
if (!q) return;
const folder = vscode.workspace.workspaceFolders?.[0];
if (!folder) return;
const repo = detectGlueRepo(folder.uri.fsPath, getHost());
if (!repo) return;
const res = await api<{ results?: Array<{ path: string; score: number }> }>(
`/api/graphql`,
{
method: "POST",
body: JSON.stringify({
query: `{ search(q:"${q.replace(/"/g, "'")}", limit:10) { name ownerUsername } }`,
}),
}
);
output.show(true);
output.appendLine(JSON.stringify(res, null, 2));
})
);
context.subscriptions.push(
vscode.commands.registerCommand("gluecron.generateTests", async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) return;
const folder = vscode.workspace.getWorkspaceFolder(editor.document.uri);
if (!folder) return;
const repo = detectGlueRepo(folder.uri.fsPath, getHost());
if (!repo) return;
const rel = relative(folder.uri.fsPath, editor.document.uri.fsPath);
try {
const res = await api(
`/${repo.owner}/${repo.repo}/ai/tests?format=raw&path=${encodeURIComponent(
rel
)}`
);
const doc = await vscode.workspace.openTextDocument({
content: typeof res === "string" ? res : JSON.stringify(res, null, 2),
language: editor.document.languageId,
});
vscode.window.showTextDocument(doc);
} catch (err) {
vscode.window.showErrorMessage(
`Gluecron test generation failed: ${(err as Error).message}`
);
}
})
);
}
export function deactivate() {
// nothing to clean up
}
|