Initial commit

This commit is contained in:
ada
2026-05-25 05:47:28 +00:00
commit 4d6495ffda
97 changed files with 13403 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env node
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import process from 'node:process';
const action = process.env.TOOLBOX_ACTION;
if (action === 'describe') {
process.stdout.write(
[
'name: check-types',
'description: Run TypeScript compiler to check for type errors',
'dir: string The workspace directory',
].join('\n')
);
} else if (action === 'execute') {
const input = fs.readFileSync(0, 'utf-8');
let dir = '.';
const lines = input.split('\n');
for (const line of lines) {
if (line.startsWith('dir: ')) {
dir = line.substring(5).trim();
}
}
const result = spawnSync('npx', ['tsc', '--noEmit'], {
cwd: dir,
stdio: 'inherit',
shell: true
});
process.exit(result.status ?? 1);
}
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env node
import ts from 'typescript';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
const action = process.env.TOOLBOX_ACTION;
if (action === 'describe') {
process.stdout.write(
[
'name: hover',
'description: Get type information at a specific position',
'dir: string The workspace directory',
'file: string The absolute path to the file',
'line: number The line number (1-based)',
'col: number The column number (1-based)',
].join('\n')
);
} else if (action === 'execute') {
try {
const input = fs.readFileSync(0, 'utf-8');
const params = parseInput(input);
if (!params.dir || !params.file || !params.line || !params.col) {
console.error('Missing required parameters (dir, file, line, col)');
process.exit(1);
}
const configPath = ts.findConfigFile(params.dir, ts.sys.fileExists, 'tsconfig.json');
if (!configPath) {
console.error('Could not find tsconfig.json in ' + params.dir);
process.exit(1);
}
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
const parsedConfig = ts.parseJsonConfigFileContent(
configFile.config,
ts.sys,
path.dirname(configPath)
);
const servicesHost = {
getScriptFileNames: () => parsedConfig.fileNames,
getScriptVersion: () => '0',
getScriptSnapshot: (fileName) => {
if (!fs.existsSync(fileName)) {
return undefined;
}
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString());
},
getCurrentDirectory: () => params.dir,
getCompilationSettings: () => parsedConfig.options,
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
fileExists: ts.sys.fileExists,
readFile: ts.sys.readFile,
readDirectory: ts.sys.readDirectory,
directoryExists: ts.sys.directoryExists,
getDirectories: ts.sys.getDirectories,
};
const service = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
const filePath = params.file;
let sourceFile = service.getProgram().getSourceFile(filePath);
if (!sourceFile) {
console.error(`File not found in program: ${filePath}`);
process.exit(1);
}
const line = Number(params.line);
const col = Number(params.col);
const position = sourceFile.getPositionOfLineAndCharacter(line - 1, col - 1);
const info = service.getQuickInfoAtPosition(filePath, position);
if (info) {
const display = ts.displayPartsToString(info.displayParts);
const doc = ts.displayPartsToString(info.documentation);
console.log('```typescript');
console.log(display);
console.log('```');
if (doc) {
console.log(doc);
}
} else {
console.log('No info available at this position');
}
} catch (e) {
console.error(e);
process.exit(1);
}
}
function parseInput(input) {
const params = {};
const lines = input.split('\n');
for (const line of lines) {
const idx = line.indexOf(': ');
if (idx !== -1) {
const key = line.substring(0, idx).trim();
const value = line.substring(idx + 2).trim();
params[key] = value;
}
}
return params;
}
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env node
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import process from 'node:process';
const action = process.env.TOOLBOX_ACTION;
if (action === 'describe') {
process.stdout.write(
[
'name: run-tests',
'description: Run Vitest tests',
'dir: string The workspace directory',
].join('\n')
);
} else if (action === 'execute') {
const input = fs.readFileSync(0, 'utf-8');
let dir = '.';
const lines = input.split('\n');
for (const line of lines) {
if (line.startsWith('dir: ')) {
dir = line.substring(5).trim();
}
}
const result = spawnSync('npx', ['vitest', 'run'], {
cwd: dir,
stdio: 'inherit',
shell: true
});
process.exit(result.status ?? 1);
}