myai-tools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17465 -0
- package/dist/tools/ast-grep/cli.d.ts +15 -0
- package/dist/tools/ast-grep/constants.d.ts +18 -0
- package/dist/tools/ast-grep/downloader.d.ts +5 -0
- package/dist/tools/ast-grep/index.d.ts +10 -0
- package/dist/tools/ast-grep/tools.d.ts +3 -0
- package/dist/tools/ast-grep/types.d.ts +30 -0
- package/dist/tools/ast-grep/utils.d.ts +4 -0
- package/dist/tools/grep/cli.d.ts +3 -0
- package/dist/tools/grep/constants.d.ts +18 -0
- package/dist/tools/grep/downloader.d.ts +3 -0
- package/dist/tools/grep/index.d.ts +5 -0
- package/dist/tools/grep/tools.d.ts +2 -0
- package/dist/tools/grep/types.d.ts +35 -0
- package/dist/tools/grep/utils.d.ts +2 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/lsp/client.d.ts +42 -0
- package/dist/tools/lsp/config.d.ts +4 -0
- package/dist/tools/lsp/constants.d.ts +8 -0
- package/dist/tools/lsp/index.d.ts +3 -0
- package/dist/tools/lsp/tools.d.ts +5 -0
- package/dist/tools/lsp/types.d.ts +28 -0
- package/dist/tools/lsp/utils.d.ts +21 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/zip-extractor.d.ts +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CliLanguage, SgResult } from './types';
|
|
2
|
+
export interface RunOptions {
|
|
3
|
+
pattern: string;
|
|
4
|
+
lang: CliLanguage;
|
|
5
|
+
paths?: string[];
|
|
6
|
+
globs?: string[];
|
|
7
|
+
rewrite?: string;
|
|
8
|
+
context?: number;
|
|
9
|
+
updateAll?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function getAstGrepPath(): Promise<string | null>;
|
|
12
|
+
export declare function startBackgroundInit(): void;
|
|
13
|
+
export declare function runSg(options: RunOptions): Promise<SgResult>;
|
|
14
|
+
export declare function isCliAvailable(): boolean;
|
|
15
|
+
export declare function ensureCliAvailable(): Promise<boolean>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CLI_LANGUAGES } from './types';
|
|
2
|
+
export declare function findSgCliPathSync(): string | null;
|
|
3
|
+
export declare function getSgCliPath(): string;
|
|
4
|
+
export declare function setSgCliPath(path: string): void;
|
|
5
|
+
export { CLI_LANGUAGES };
|
|
6
|
+
export declare const DEFAULT_TIMEOUT_MS = 300000;
|
|
7
|
+
export declare const DEFAULT_MAX_OUTPUT_BYTES: number;
|
|
8
|
+
export declare const DEFAULT_MAX_MATCHES = 500;
|
|
9
|
+
export declare const LANG_EXTENSIONS: Record<string, string[]>;
|
|
10
|
+
export interface EnvironmentCheckResult {
|
|
11
|
+
cli: {
|
|
12
|
+
available: boolean;
|
|
13
|
+
path: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare function checkEnvironment(): EnvironmentCheckResult;
|
|
18
|
+
export declare function formatEnvironmentCheck(result: EnvironmentCheckResult): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getCacheDir(): string;
|
|
2
|
+
export declare function getBinaryName(): string;
|
|
3
|
+
export declare function getCachedBinaryPath(): string | null;
|
|
4
|
+
export declare function downloadAstGrep(version?: string): Promise<string | null>;
|
|
5
|
+
export declare function ensureAstGrepBinary(): Promise<string | null>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToolDefinition } from '@opencode-ai/plugin';
|
|
2
|
+
import { ast_grep_replace, ast_grep_search } from './tools';
|
|
3
|
+
export declare const builtinTools: Record<string, ToolDefinition>;
|
|
4
|
+
export { ast_grep_search, ast_grep_replace };
|
|
5
|
+
export { ensureCliAvailable, getAstGrepPath, isCliAvailable, startBackgroundInit, } from './cli';
|
|
6
|
+
export type { EnvironmentCheckResult } from './constants';
|
|
7
|
+
export { checkEnvironment, formatEnvironmentCheck } from './constants';
|
|
8
|
+
export { ensureAstGrepBinary, getCacheDir, getCachedBinaryPath, } from './downloader';
|
|
9
|
+
export type { CliLanguage, CliMatch, SgResult } from './types';
|
|
10
|
+
export { CLI_LANGUAGES } from './types';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const CLI_LANGUAGES: readonly ["bash", "c", "cpp", "csharp", "css", "elixir", "go", "haskell", "html", "java", "javascript", "json", "kotlin", "lua", "nix", "php", "python", "ruby", "rust", "scala", "solidity", "swift", "typescript", "tsx", "yaml"];
|
|
2
|
+
export type CliLanguage = (typeof CLI_LANGUAGES)[number];
|
|
3
|
+
export interface CliMatch {
|
|
4
|
+
file: string;
|
|
5
|
+
range: {
|
|
6
|
+
byteOffset: {
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
};
|
|
10
|
+
start: {
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
};
|
|
14
|
+
end: {
|
|
15
|
+
line: number;
|
|
16
|
+
column: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
lines: string;
|
|
20
|
+
text: string;
|
|
21
|
+
replacement?: string;
|
|
22
|
+
language: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SgResult {
|
|
25
|
+
matches: CliMatch[];
|
|
26
|
+
totalMatches: number;
|
|
27
|
+
truncated: boolean;
|
|
28
|
+
truncatedReason?: 'timeout' | 'max_output_bytes' | 'max_matches';
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CliLanguage, SgResult } from './types';
|
|
2
|
+
export declare function formatSearchResult(result: SgResult): string;
|
|
3
|
+
export declare function formatReplaceResult(result: SgResult, isDryRun: boolean): string;
|
|
4
|
+
export declare function getEmptyResultHint(pattern: string, lang: CliLanguage): string | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type GrepBackend = 'rg' | 'grep';
|
|
2
|
+
interface ResolvedCli {
|
|
3
|
+
path: string;
|
|
4
|
+
backend: GrepBackend;
|
|
5
|
+
}
|
|
6
|
+
export declare function getDataDir(): string;
|
|
7
|
+
export declare function resolveGrepCli(): ResolvedCli;
|
|
8
|
+
export declare function resolveGrepCliWithAutoInstall(): Promise<ResolvedCli>;
|
|
9
|
+
export declare const DEFAULT_MAX_DEPTH = 20;
|
|
10
|
+
export declare const DEFAULT_MAX_FILESIZE = "10M";
|
|
11
|
+
export declare const DEFAULT_MAX_COUNT = 500;
|
|
12
|
+
export declare const DEFAULT_MAX_COLUMNS = 1000;
|
|
13
|
+
export declare const DEFAULT_CONTEXT = 2;
|
|
14
|
+
export declare const DEFAULT_TIMEOUT_MS = 300000;
|
|
15
|
+
export declare const DEFAULT_MAX_OUTPUT_BYTES: number;
|
|
16
|
+
export declare const RG_SAFETY_FLAGS: readonly ["--no-follow", "--color=never", "--no-heading", "--line-number", "--with-filename"];
|
|
17
|
+
export declare const GREP_SAFETY_FLAGS: readonly ["-n", "-H", "--color=never"];
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { runRg, runRgCount } from './cli';
|
|
2
|
+
export { resolveGrepCli, resolveGrepCliWithAutoInstall } from './constants';
|
|
3
|
+
export { downloadAndInstallRipgrep, getInstalledRipgrepPath, } from './downloader';
|
|
4
|
+
export { grep } from './tools';
|
|
5
|
+
export type { CountResult, GrepMatch, GrepOptions, GrepResult } from './types';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface GrepMatch {
|
|
2
|
+
file: string;
|
|
3
|
+
line: number;
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
export interface GrepResult {
|
|
7
|
+
matches: GrepMatch[];
|
|
8
|
+
totalMatches: number;
|
|
9
|
+
filesSearched: number;
|
|
10
|
+
truncated: boolean;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CountResult {
|
|
14
|
+
file: string;
|
|
15
|
+
count: number;
|
|
16
|
+
}
|
|
17
|
+
export interface GrepOptions {
|
|
18
|
+
pattern: string;
|
|
19
|
+
paths?: string[];
|
|
20
|
+
globs?: string[];
|
|
21
|
+
excludeGlobs?: string[];
|
|
22
|
+
context?: number;
|
|
23
|
+
caseSensitive?: boolean;
|
|
24
|
+
wholeWord?: boolean;
|
|
25
|
+
fixedStrings?: boolean;
|
|
26
|
+
multiline?: boolean;
|
|
27
|
+
hidden?: boolean;
|
|
28
|
+
noIgnore?: boolean;
|
|
29
|
+
fileType?: string[];
|
|
30
|
+
maxDepth?: number;
|
|
31
|
+
maxFilesize?: string;
|
|
32
|
+
maxCount?: number;
|
|
33
|
+
maxColumns?: number;
|
|
34
|
+
timeout?: number;
|
|
35
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Diagnostic, ResolvedServer } from './types';
|
|
2
|
+
declare class LSPServerManager {
|
|
3
|
+
private static instance;
|
|
4
|
+
private clients;
|
|
5
|
+
private cleanupInterval;
|
|
6
|
+
private readonly IDLE_TIMEOUT;
|
|
7
|
+
private constructor();
|
|
8
|
+
private registerProcessCleanup;
|
|
9
|
+
static getInstance(): LSPServerManager;
|
|
10
|
+
private getKey;
|
|
11
|
+
private startCleanupTimer;
|
|
12
|
+
private cleanupIdleClients;
|
|
13
|
+
getClient(root: string, server: ResolvedServer): Promise<LSPClient>;
|
|
14
|
+
releaseClient(root: string, serverId: string): void;
|
|
15
|
+
isServerInitializing(root: string, serverId: string): boolean;
|
|
16
|
+
stopAll(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare const lspManager: LSPServerManager;
|
|
19
|
+
export declare class LSPClient {
|
|
20
|
+
private root;
|
|
21
|
+
private server;
|
|
22
|
+
private proc;
|
|
23
|
+
private connection;
|
|
24
|
+
private openedFiles;
|
|
25
|
+
private stderrBuffer;
|
|
26
|
+
private processExited;
|
|
27
|
+
private diagnosticsStore;
|
|
28
|
+
constructor(root: string, server: ResolvedServer);
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
private startStderrReading;
|
|
31
|
+
initialize(): Promise<void>;
|
|
32
|
+
openFile(filePath: string): Promise<void>;
|
|
33
|
+
definition(filePath: string, line: number, character: number): Promise<unknown>;
|
|
34
|
+
references(filePath: string, line: number, character: number, includeDeclaration?: boolean): Promise<unknown>;
|
|
35
|
+
diagnostics(filePath: string): Promise<{
|
|
36
|
+
items: Diagnostic[];
|
|
37
|
+
}>;
|
|
38
|
+
rename(filePath: string, line: number, character: number, newName: string): Promise<unknown>;
|
|
39
|
+
isAlive(): boolean;
|
|
40
|
+
stop(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LSPServerConfig } from './types';
|
|
2
|
+
export declare const SYMBOL_KIND_MAP: Record<number, string>;
|
|
3
|
+
export declare const SEVERITY_MAP: Record<number, string>;
|
|
4
|
+
export declare const DEFAULT_MAX_REFERENCES = 200;
|
|
5
|
+
export declare const DEFAULT_MAX_DIAGNOSTICS = 200;
|
|
6
|
+
export declare const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, 'id'>>;
|
|
7
|
+
export declare const LSP_INSTALL_HINTS: Record<string, string>;
|
|
8
|
+
export declare const EXT_TO_LANG: Record<string, string>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ToolDefinition } from '@opencode-ai/plugin/tool';
|
|
2
|
+
export declare const lsp_goto_definition: ToolDefinition;
|
|
3
|
+
export declare const lsp_find_references: ToolDefinition;
|
|
4
|
+
export declare const lsp_diagnostics: ToolDefinition;
|
|
5
|
+
export declare const lsp_rename: ToolDefinition;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CreateFile, DeleteFile, Diagnostic, DocumentSymbol, Location, LocationLink, Position, Range, RenameFile, SymbolInformation as SymbolInfo, TextDocumentEdit, TextDocumentIdentifier, TextEdit, VersionedTextDocumentIdentifier, WorkspaceEdit } from 'vscode-languageserver-protocol';
|
|
2
|
+
export interface LSPServerConfig {
|
|
3
|
+
id: string;
|
|
4
|
+
command: string[];
|
|
5
|
+
extensions: string[];
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
env?: Record<string, string>;
|
|
8
|
+
initialization?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface ResolvedServer {
|
|
11
|
+
id: string;
|
|
12
|
+
command: string[];
|
|
13
|
+
extensions: string[];
|
|
14
|
+
env?: Record<string, string>;
|
|
15
|
+
initialization?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export type ServerLookupResult = {
|
|
18
|
+
status: 'found';
|
|
19
|
+
server: ResolvedServer;
|
|
20
|
+
} | {
|
|
21
|
+
status: 'not_configured';
|
|
22
|
+
extension: string;
|
|
23
|
+
} | {
|
|
24
|
+
status: 'not_installed';
|
|
25
|
+
server: ResolvedServer;
|
|
26
|
+
installHint: string;
|
|
27
|
+
};
|
|
28
|
+
export type { Position, Range, Location, LocationLink, Diagnostic, TextDocumentIdentifier, VersionedTextDocumentIdentifier, TextEdit, TextDocumentEdit, CreateFile, RenameFile, DeleteFile, WorkspaceEdit, SymbolInfo, DocumentSymbol, };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LSPClient } from './client';
|
|
2
|
+
import type { Diagnostic, Location, LocationLink, ServerLookupResult, WorkspaceEdit } from './types';
|
|
3
|
+
export declare function findWorkspaceRoot(filePath: string): string;
|
|
4
|
+
export declare function uriToPath(uri: string): string;
|
|
5
|
+
export declare function formatServerLookupError(result: Exclude<ServerLookupResult, {
|
|
6
|
+
status: 'found';
|
|
7
|
+
}>): string;
|
|
8
|
+
export declare function withLspClient<T>(filePath: string, fn: (client: LSPClient) => Promise<T>): Promise<T>;
|
|
9
|
+
export declare function formatLocation(loc: Location | LocationLink): string;
|
|
10
|
+
export declare function formatSymbolKind(kind: number): string;
|
|
11
|
+
export declare function formatSeverity(severity: number | undefined): string;
|
|
12
|
+
export declare function formatDiagnostic(diag: Diagnostic): string;
|
|
13
|
+
export declare function filterDiagnosticsBySeverity(diagnostics: Diagnostic[], severityFilter?: 'error' | 'warning' | 'information' | 'hint' | 'all'): Diagnostic[];
|
|
14
|
+
export interface ApplyResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
filesModified: string[];
|
|
17
|
+
totalEdits: number;
|
|
18
|
+
errors: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function applyWorkspaceEdit(edit: WorkspaceEdit | null): ApplyResult;
|
|
21
|
+
export declare function formatApplyResult(result: ApplyResult): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { extractZip } from './zip-extractor';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractZip(archivePath: string, destDir: string): Promise<void>;
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "myai-tools",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Standalone OpenCode plugin with grep, ast-grep, and LSP tools",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/alvinunreal/oh-my-opencode-slim.git",
|
|
18
|
+
"directory": "packages/myai-tools"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/alvinunreal/oh-my-opencode-slim/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/alvinunreal/oh-my-opencode-slim/tree/master/packages/myai-tools#readme",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"opencode",
|
|
29
|
+
"opencode-plugin",
|
|
30
|
+
"custom-tools",
|
|
31
|
+
"grep",
|
|
32
|
+
"ast-grep",
|
|
33
|
+
"lsp"
|
|
34
|
+
],
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "bun build src/index.ts --outdir dist --target bun --format esm && tsc --emitDeclarationOnly",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"test": "bun test",
|
|
44
|
+
"prepublishOnly": "bun run typecheck && bun run test && bun run build",
|
|
45
|
+
"pack:dry-run": "npm pack --dry-run"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@ast-grep/cli": "^0.40.0",
|
|
49
|
+
"@opencode-ai/plugin": "^1.1.19",
|
|
50
|
+
"vscode-jsonrpc": "^8.2.0",
|
|
51
|
+
"vscode-languageserver-protocol": "^3.17.5"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"bun-types": "latest",
|
|
55
|
+
"typescript": "^5.7.3"
|
|
56
|
+
},
|
|
57
|
+
"trustedDependencies": [
|
|
58
|
+
"@ast-grep/cli"
|
|
59
|
+
]
|
|
60
|
+
}
|