@octocodeai/octocode-tools-core 16.3.0 → 16.6.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/README.md +564 -0
- package/dist/config.d.ts +7 -0
- package/dist/direct.js +39 -41
- package/dist/errors/pathUtils.d.ts +1 -1
- package/dist/github/directoryFetch.d.ts +2 -1
- package/dist/github/githubAPI.d.ts +32 -1
- package/dist/github/history.d.ts +3 -0
- package/dist/github/prTransformation.d.ts +1 -1
- package/dist/github/repoStructureRecursive.d.ts +6 -0
- package/dist/index.d.ts +16 -30
- package/dist/index.js +44 -46
- package/dist/oql/adapters/compile.d.ts +25 -0
- package/dist/oql/adapters/github.d.ts +3 -0
- package/dist/oql/adapters/local.d.ts +7 -0
- package/dist/oql/adapters/materialize.d.ts +11 -0
- package/dist/oql/adapters/pagination.d.ts +21 -0
- package/dist/oql/adapters/researchTargets.d.ts +50 -0
- package/dist/oql/adapters/resultMap.d.ts +20 -0
- package/dist/oql/adapters/ruleYaml.d.ts +11 -0
- package/dist/oql/adapters/runner.d.ts +14 -0
- package/dist/oql/adapters/v2.d.ts +32 -0
- package/dist/oql/capabilities.d.ts +31 -0
- package/dist/oql/defaults.d.ts +26 -0
- package/dist/oql/diagnostics.d.ts +25 -0
- package/dist/oql/diffLanes.d.ts +29 -0
- package/dist/oql/envelope.d.ts +19 -0
- package/dist/oql/features.d.ts +7 -0
- package/dist/oql/index.d.ts +26 -0
- package/dist/oql/index.js +49 -0
- package/dist/oql/normalize.d.ts +5 -0
- package/dist/oql/planner.d.ts +7 -0
- package/dist/oql/research/analyze.d.ts +134 -0
- package/dist/oql/research/packets.d.ts +80 -0
- package/dist/oql/run.d.ts +32 -0
- package/dist/oql/schema.d.ts +1018 -0
- package/dist/oql/schemeText.d.ts +138 -0
- package/dist/oql/shorthand.d.ts +177 -0
- package/dist/oql/targetParams.d.ts +20 -0
- package/dist/oql/transformers/contract.d.ts +19 -0
- package/dist/oql/transformers/github/code.d.ts +17 -0
- package/dist/oql/transformers/github/common.d.ts +8 -0
- package/dist/oql/transformers/language.d.ts +1 -0
- package/dist/oql/transformers/registry.d.ts +16 -0
- package/dist/oql/transformers/types.d.ts +11 -0
- package/dist/oql/types.d.ts +633 -0
- package/dist/oql/v2params.d.ts +22 -0
- package/dist/providers/providerQueries.d.ts +9 -0
- package/dist/providers/providerResults.d.ts +2 -0
- package/dist/providers/types.d.ts +1 -1
- package/dist/schema.d.ts +13 -0
- package/dist/schema.js +8 -0
- package/dist/scheme/coreSchemas.d.ts +5 -5
- package/dist/scheme/fields.d.ts +6 -6
- package/dist/serverConfig.d.ts +1 -2
- package/dist/session.d.ts +2 -24
- package/dist/shared/config/defaults.d.ts +14 -0
- package/dist/shared/config/index.d.ts +9 -0
- package/dist/shared/config/index.js +9 -0
- package/dist/shared/config/loader.d.ts +7 -0
- package/dist/shared/config/resolver.d.ts +2 -0
- package/dist/shared/config/resolverCache.d.ts +12 -0
- package/dist/shared/config/resolverSections.d.ts +10 -0
- package/dist/shared/config/runtimeSurface.d.ts +21 -0
- package/dist/shared/config/schemas.d.ts +11 -0
- package/dist/shared/config/types.d.ts +92 -0
- package/dist/shared/config/validator.d.ts +2 -0
- package/dist/shared/credentials/constants.d.ts +2 -0
- package/dist/shared/credentials/credentialCache.d.ts +13 -0
- package/dist/shared/credentials/credentialEncryption.d.ts +10 -0
- package/dist/shared/credentials/credentialUtils.d.ts +4 -0
- package/dist/shared/credentials/envTokens.d.ts +9 -0
- package/dist/shared/credentials/ghCli.d.ts +1 -0
- package/dist/shared/credentials/index.d.ts +3 -0
- package/dist/shared/credentials/index.js +8 -0
- package/dist/shared/credentials/schemas.d.ts +22 -0
- package/dist/shared/credentials/storage.d.ts +30 -0
- package/dist/shared/credentials/testing.d.ts +2 -0
- package/dist/shared/credentials/testing.js +8 -0
- package/dist/shared/credentials/tokenRefresh.d.ts +24 -0
- package/dist/shared/credentials/tokenResolution.d.ts +30 -0
- package/dist/shared/credentials/types.d.ts +28 -0
- package/dist/shared/fs-utils.d.ts +2 -0
- package/dist/shared/fs-utils.js +8 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/languageSelectors.d.ts +23 -0
- package/dist/shared/paths.d.ts +31 -0
- package/dist/shared/paths.js +8 -0
- package/dist/shared/platform/index.d.ts +1 -0
- package/dist/shared/platform/index.js +8 -0
- package/dist/shared/platform/platform.d.ts +8 -0
- package/dist/shared/session/index.d.ts +5 -0
- package/dist/shared/session/index.js +8 -0
- package/dist/shared/session/schemas.d.ts +103 -0
- package/dist/shared/session/sessionCache.d.ts +9 -0
- package/dist/shared/session/sessionDiskIO.d.ts +6 -0
- package/dist/shared/session/statsDefaults.d.ts +4 -0
- package/dist/shared/session/storage.d.ts +20 -0
- package/dist/shared/session/types.d.ts +53 -0
- package/dist/tools/directToolCatalog.d.ts +15 -56
- package/dist/tools/directToolCatalog.exec.d.ts +11 -0
- package/dist/tools/directToolCatalog.meta.d.ts +82 -0
- package/dist/tools/github_clone_repo/cache.d.ts +5 -1
- package/dist/tools/github_clone_repo/scheme.d.ts +56 -9
- package/dist/tools/github_clone_repo/types.d.ts +3 -1
- package/dist/tools/github_fetch_content/scheme.d.ts +112 -4
- package/dist/tools/github_fetch_content/types.d.ts +39 -0
- package/dist/tools/github_search_code/scheme.d.ts +6 -6
- package/dist/tools/github_search_pull_requests/contentResponse.d.ts +0 -1
- package/dist/tools/github_search_pull_requests/execution.d.ts +1 -11
- package/dist/tools/github_search_pull_requests/scheme.d.ts +6 -2
- package/dist/tools/github_search_repos/scheme.d.ts +7 -6
- package/dist/tools/github_view_repo_structure/execution.d.ts +0 -9
- package/dist/tools/github_view_repo_structure/scheme.d.ts +10 -6
- package/dist/tools/local_binary_inspect/archiveOps.d.ts +2 -0
- package/dist/tools/local_binary_inspect/binaryInspector.d.ts +48 -7
- package/dist/tools/local_binary_inspect/binaryOps.d.ts +16 -7
- package/dist/tools/local_binary_inspect/scheme.d.ts +10 -7
- package/dist/tools/local_fetch_content/scheme.d.ts +2 -2
- package/dist/tools/local_find_files/scheme.d.ts +2 -2
- package/dist/tools/local_ripgrep/lspBoost.d.ts +54 -0
- package/dist/tools/local_ripgrep/rankingProfile.d.ts +113 -0
- package/dist/tools/local_ripgrep/ripgrepResultBuilder.d.ts +10 -1
- package/dist/tools/local_ripgrep/scheme.d.ts +29 -4
- package/dist/tools/local_ripgrep/structuralSearch.d.ts +3 -4
- package/dist/tools/local_view_structure/scheme.d.ts +2 -2
- package/dist/tools/local_view_structure/structureFilters.d.ts +1 -3
- package/dist/tools/local_view_structure/structureResponse.d.ts +1 -0
- package/dist/tools/lsp/semantic_content/scheme.d.ts +174 -10
- package/dist/tools/lsp/shared/callHierarchyTraversal.d.ts +2 -2
- package/dist/tools/lsp/shared/resolveSymbolAnchor.d.ts +2 -2
- package/dist/tools/lsp/shared/semanticTypes.d.ts +36 -6
- package/dist/tools/oql_search/execution.d.ts +7 -0
- package/dist/tools/package_search/execution.d.ts +10 -0
- package/dist/tools/package_search/scheme.d.ts +9 -7
- package/dist/tools/providerMappers.d.ts +24 -5
- package/dist/tools/toolConfig.d.ts +1 -0
- package/dist/tools/toolMetadata/proxies.d.ts +0 -6
- package/dist/tools/toolNames.d.ts +2 -0
- package/dist/tools/utils.d.ts +3 -7
- package/dist/types/bulk.d.ts +0 -2
- package/dist/types/execution.d.ts +1 -2
- package/dist/types/server.d.ts +0 -1
- package/dist/types/session.d.ts +0 -19
- package/dist/types/toolResults.d.ts +2 -3
- package/dist/utils/contextUtils.d.ts +49 -2
- package/dist/utils/core/lines.d.ts +16 -0
- package/dist/utils/core/types.d.ts +12 -1
- package/dist/utils/file/filters.d.ts +2 -11
- package/dist/utils/markdownOutline.d.ts +10 -0
- package/dist/utils/parsers/diff.d.ts +18 -0
- package/dist/utils/response/error.d.ts +38 -4
- package/dist/utils/response/groupedFinalizer.d.ts +0 -25
- package/package.json +51 -14
- package/dist/commands/BaseCommandBuilder.d.ts +0 -14
- package/dist/commands/FindCommandBuilder.d.ts +0 -23
- package/dist/commands/LsCommandBuilder.d.ts +0 -15
- package/dist/commands/RipgrepCommandBuilder.d.ts +0 -27
- package/dist/hints/dynamic.d.ts +0 -6
- package/dist/hints/index.d.ts +0 -2
- package/dist/hints/types.d.ts +0 -1
- package/dist/tools/github_clone_repo/hints.d.ts +0 -2
- package/dist/tools/github_fetch_content/hints.d.ts +0 -2
- package/dist/tools/github_search_code/hints.d.ts +0 -2
- package/dist/tools/github_search_pull_requests/hints.d.ts +0 -2
- package/dist/tools/github_search_repos/hints.d.ts +0 -2
- package/dist/tools/github_view_repo_structure/hints.d.ts +0 -2
- package/dist/tools/local_fetch_content/hints.d.ts +0 -2
- package/dist/tools/local_find_files/hints.d.ts +0 -2
- package/dist/tools/local_ripgrep/grepFallbackExecutor.d.ts +0 -3
- package/dist/tools/local_ripgrep/hints.d.ts +0 -2
- package/dist/tools/local_ripgrep/ripgrepParser.d.ts +0 -9
- package/dist/tools/local_view_structure/hints.d.ts +0 -2
- package/dist/tools/local_view_structure/structureParser.d.ts +0 -3
- package/dist/tools/local_view_structure/structureWalker.d.ts +0 -24
- package/dist/tools/lsp/semantic_content/hints.d.ts +0 -4
- package/dist/tools/package_search/hints.d.ts +0 -2
- package/dist/types/metadata.d.ts +0 -69
- package/dist/utils/exec/commandAvailability.d.ts +0 -19
- package/dist/utils/exec/ripgrepBinary.d.ts +0 -3
- package/dist/utils/pagination/outputSizeLimit.d.ts +0 -16
- package/dist/utils/response/structuredPagination.d.ts +0 -9
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { StoredCredentials, StoreResult, DeleteResult } from './types.js';
|
|
2
|
+
import { invalidateCredentialsCache, _getCacheStats, _resetCredentialsCache } from './credentialCache.js';
|
|
3
|
+
import { OCTOCODE_DIR, CREDENTIALS_FILE, KEY_FILE, encrypt, decrypt, ensureOctocodeDir, readCredentialsStore, writeCredentialsStore } from './credentialEncryption.js';
|
|
4
|
+
import { type RefreshResult, type TokenWithRefreshResult } from './tokenRefresh.js';
|
|
5
|
+
import { resolveToken, type ResolvedToken, resolveTokenWithRefresh, type ResolvedTokenWithRefresh, resolveTokenFull, type FullTokenResolution, type GhCliTokenGetter, resetTokenResolution } from './tokenResolution.js';
|
|
6
|
+
import { getTokenFromEnv, getEnvTokenSource, hasEnvToken, ENV_TOKEN_VARS } from './envTokens.js';
|
|
7
|
+
import { isTokenExpired, isRefreshTokenExpired } from './credentialUtils.js';
|
|
8
|
+
export { getTokenFromEnv, getEnvTokenSource, hasEnvToken, ENV_TOKEN_VARS };
|
|
9
|
+
export declare function storeCredentials(credentials: StoredCredentials): Promise<StoreResult>;
|
|
10
|
+
export interface GetCredentialsOptions {
|
|
11
|
+
bypassCache?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function getCredentials(hostname?: string, options?: GetCredentialsOptions): Promise<StoredCredentials | null>;
|
|
14
|
+
export declare function getCredentialsSync(hostname?: string): StoredCredentials | null;
|
|
15
|
+
export declare function deleteCredentials(hostname?: string): Promise<DeleteResult>;
|
|
16
|
+
export declare function listStoredHosts(): Promise<string[]>;
|
|
17
|
+
export declare function listStoredHostsSync(): string[];
|
|
18
|
+
export declare function hasCredentials(hostname?: string): Promise<boolean>;
|
|
19
|
+
export declare function hasCredentialsSync(hostname?: string): boolean;
|
|
20
|
+
export declare function updateToken(hostname: string, token: StoredCredentials['token']): Promise<boolean>;
|
|
21
|
+
export declare function getCredentialsFilePath(): string;
|
|
22
|
+
export declare function getToken(hostname?: string): Promise<string | null>;
|
|
23
|
+
export declare function getTokenSync(hostname?: string): string | null;
|
|
24
|
+
export { invalidateCredentialsCache, _getCacheStats, _resetCredentialsCache };
|
|
25
|
+
export { encrypt, decrypt, ensureOctocodeDir, readCredentialsStore, writeCredentialsStore, OCTOCODE_DIR, CREDENTIALS_FILE, KEY_FILE, };
|
|
26
|
+
export declare function refreshAuthToken(hostname?: string, clientId?: string): Promise<RefreshResult>;
|
|
27
|
+
export declare function getTokenWithRefresh(hostname?: string, clientId?: string): Promise<TokenWithRefreshResult>;
|
|
28
|
+
export type { RefreshResult, TokenWithRefreshResult };
|
|
29
|
+
export { resolveToken, resolveTokenWithRefresh, resolveTokenFull, resetTokenResolution, type ResolvedToken, type ResolvedTokenWithRefresh, type FullTokenResolution, type GhCliTokenGetter, };
|
|
30
|
+
export { isTokenExpired, isRefreshTokenExpired };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __createRequire } from 'module';
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
4
|
+
import { dirname as __dirname_fn } from 'path';
|
|
5
|
+
const require = __createRequire(import.meta.url);
|
|
6
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = __dirname_fn(__filename);
|
|
8
|
+
function o(e){return e.toLowerCase().replace(/^https?:\/\//,"").replace(/\/$/,"")}function s(e){if(!e.token.expiresAt)return!1;let n=new Date(e.token.expiresAt);if(isNaN(n.getTime()))return!0;let t=new Date;return n.getTime()-t.getTime()<300*1e3}var r=new Map,i=300*1e3;function l(e){let n=o(e),t=r.get(n);return!t||Date.now()-t.cachedAt>=i?!1:t.credentials?!s(t.credentials):!0}function a(){let e=Date.now();return{size:r.size,entries:Array.from(r.entries()).map(([n,t])=>({hostname:n,age:e-t.cachedAt,valid:l(n)}))}}function u(){r.clear()}import{execFile as g}from"child_process";var c=null;function f(){c=null}export{a as _getCacheStats,u as _resetCredentialsCache,f as resetTokenResolution};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { OAuthToken, StoredCredentials } from './types.js';
|
|
2
|
+
export interface RefreshResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
username?: string;
|
|
5
|
+
hostname?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
}
|
|
8
|
+
type GetCredentialsFn = (hostname?: string) => Promise<StoredCredentials | null>;
|
|
9
|
+
type UpdateTokenFn = (hostname: string, token: OAuthToken) => Promise<boolean>;
|
|
10
|
+
export declare function refreshAuthToken(deps: {
|
|
11
|
+
getCredentials: GetCredentialsFn;
|
|
12
|
+
updateToken: UpdateTokenFn;
|
|
13
|
+
}, hostname?: string, clientId?: string): Promise<RefreshResult>;
|
|
14
|
+
export interface TokenWithRefreshResult {
|
|
15
|
+
token: string | null;
|
|
16
|
+
source: 'stored' | 'refreshed' | 'none';
|
|
17
|
+
username?: string;
|
|
18
|
+
refreshError?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function getTokenWithRefresh(deps: {
|
|
21
|
+
getCredentials: GetCredentialsFn;
|
|
22
|
+
updateToken: UpdateTokenFn;
|
|
23
|
+
}, hostname?: string, clientId?: string): Promise<TokenWithRefreshResult>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TokenSource } from './types.js';
|
|
2
|
+
import type { TokenWithRefreshResult } from './tokenRefresh.js';
|
|
3
|
+
interface StorageDeps {
|
|
4
|
+
getTokenWithRefresh: (hostname?: string, clientId?: string) => Promise<TokenWithRefreshResult>;
|
|
5
|
+
}
|
|
6
|
+
export declare function initTokenResolution(deps: StorageDeps): void;
|
|
7
|
+
export declare function resetTokenResolution(): void;
|
|
8
|
+
export interface FullTokenResolution {
|
|
9
|
+
token: string;
|
|
10
|
+
source: TokenSource | 'gh-cli';
|
|
11
|
+
wasRefreshed?: boolean;
|
|
12
|
+
username?: string;
|
|
13
|
+
}
|
|
14
|
+
export type GhCliTokenGetter = (hostname?: string) => string | null | Promise<string | null>;
|
|
15
|
+
export declare function resolveTokenFull(options?: {
|
|
16
|
+
hostname?: string;
|
|
17
|
+
clientId?: string;
|
|
18
|
+
getGhCliToken?: GhCliTokenGetter;
|
|
19
|
+
}): Promise<FullTokenResolution | null>;
|
|
20
|
+
export interface ResolvedToken {
|
|
21
|
+
token: string;
|
|
22
|
+
source: TokenSource;
|
|
23
|
+
}
|
|
24
|
+
export declare function resolveToken(hostname?: string): Promise<ResolvedToken | null>;
|
|
25
|
+
export interface ResolvedTokenWithRefresh extends ResolvedToken {
|
|
26
|
+
wasRefreshed?: boolean;
|
|
27
|
+
username?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function resolveTokenWithRefresh(hostname?: string, clientId?: string): Promise<ResolvedTokenWithRefresh | null>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface OAuthToken {
|
|
2
|
+
token: string;
|
|
3
|
+
tokenType: 'oauth';
|
|
4
|
+
scopes?: string[];
|
|
5
|
+
refreshToken?: string;
|
|
6
|
+
expiresAt?: string;
|
|
7
|
+
refreshTokenExpiresAt?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface StoredCredentials {
|
|
10
|
+
hostname: string;
|
|
11
|
+
username: string;
|
|
12
|
+
token: OAuthToken;
|
|
13
|
+
gitProtocol: 'ssh' | 'https';
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface StoreResult {
|
|
18
|
+
success: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface DeleteResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
deletedFromFile: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface CredentialsStore {
|
|
25
|
+
version: number;
|
|
26
|
+
credentials: Record<string, StoredCredentials>;
|
|
27
|
+
}
|
|
28
|
+
export type TokenSource = 'env:OCTOCODE_TOKEN' | 'env:GH_TOKEN' | 'env:GITHUB_TOKEN' | 'octocode-storage' | 'gh-cli' | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __createRequire } from 'module';
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
4
|
+
import { dirname as __dirname_fn } from 'path';
|
|
5
|
+
const require = __createRequire(import.meta.url);
|
|
6
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = __dirname_fn(__filename);
|
|
8
|
+
import{existsSync as f,readdirSync as u,lstatSync as l}from"node:fs";import{join as m}from"node:path";function a(n){if(!f(n))return 0;let r=0,t=[n];for(;t.length>0;){let e=t.pop(),o;try{o=u(e)}catch{continue}for(let s of o){let c=m(e,s);try{let i=l(c);if(i.isSymbolicLink())continue;i.isDirectory()?t.push(c):i.isFile()&&(r+=i.size)}catch{}}}return r}function d(n){if(n<1024)return`${n} B`;let r=n/1024;if(r<1024)return`${r.toFixed(1)} KB`;let t=r/1024;return t<1024?`${t.toFixed(1)} MB`:`${(t/1024).toFixed(2)} GB`}export{d as formatBytes,a as getDirectorySizeBytes};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type OqlLanguageSelectorKind = 'extension' | 'language' | 'unknown';
|
|
2
|
+
export type OqlLanguageSelector = {
|
|
3
|
+
raw: string;
|
|
4
|
+
normalized: string;
|
|
5
|
+
kind: OqlLanguageSelectorKind;
|
|
6
|
+
canonicalLanguage?: string;
|
|
7
|
+
extension?: string;
|
|
8
|
+
extensions?: readonly string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function classifyLanguageSelector(raw: string | undefined): OqlLanguageSelector | undefined;
|
|
11
|
+
export type GithubCodeLanguageParams = {
|
|
12
|
+
language?: string;
|
|
13
|
+
extension?: string;
|
|
14
|
+
};
|
|
15
|
+
export type LocalSearchLanguageParams = {
|
|
16
|
+
langType?: string;
|
|
17
|
+
include?: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare function toGithubCodeLanguageParams(raw: string | undefined): GithubCodeLanguageParams;
|
|
20
|
+
export declare function toLocalSearchLanguageParams(raw: string | undefined): LocalSearchLanguageParams;
|
|
21
|
+
export declare function toLocalFileLanguageGlobs(raw: string | undefined): string[];
|
|
22
|
+
export declare function toStructuralSearchIncludeGlobs(raw: string | undefined): string[] | undefined;
|
|
23
|
+
export declare function toGithubRepositoryLanguage(raw: string | undefined): string | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Octocode's home directory. Fixed per platform — there is no override env var:
|
|
3
|
+
* - macOS: `~/.octocode`
|
|
4
|
+
* - Linux: `${XDG_CONFIG_HOME:-~/.config}/.octocode`
|
|
5
|
+
* - Windows: `%APPDATA%\.octocode`
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDefaultOctocodeHome(): string;
|
|
8
|
+
export declare const OCTOCODE_HOME: string;
|
|
9
|
+
export declare const paths: {
|
|
10
|
+
readonly home: string;
|
|
11
|
+
readonly config: string;
|
|
12
|
+
readonly credentials: string;
|
|
13
|
+
readonly key: string;
|
|
14
|
+
readonly session: string;
|
|
15
|
+
readonly stats: string;
|
|
16
|
+
readonly tmp: string;
|
|
17
|
+
readonly clone: string;
|
|
18
|
+
readonly tree: string;
|
|
19
|
+
readonly binary: string;
|
|
20
|
+
readonly repos: string;
|
|
21
|
+
readonly unzip: string;
|
|
22
|
+
readonly cliConfig: string;
|
|
23
|
+
readonly lspConfig: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function ensureHome(): void;
|
|
26
|
+
export declare function ensureRepos(): void;
|
|
27
|
+
export declare function ensureTmp(): void;
|
|
28
|
+
export declare function ensureClone(): void;
|
|
29
|
+
export declare function ensureTree(): void;
|
|
30
|
+
export declare function ensureBinary(): void;
|
|
31
|
+
export declare function ensureUnzip(): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __createRequire } from 'module';
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
4
|
+
import { dirname as __dirname_fn } from 'path';
|
|
5
|
+
const require = __createRequire(import.meta.url);
|
|
6
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = __dirname_fn(__filename);
|
|
8
|
+
import{existsSync as n,mkdirSync as i}from"node:fs";import{join as e}from"node:path";import p from"node:os";import g from"node:path";var c=p.platform()==="win32",f=p.platform()==="darwin",x=p.platform()==="linux",r=p.homedir();function m(){return c?process.env.APPDATA||g.join(r,"AppData","Roaming"):r}var d=".octocode",s=448;function v(l){let a=process.env[l];return a&&a.trim().length>0?a:void 0}function A(){return c?e(m(),d):f?e(r,d):e(v("XDG_CONFIG_HOME")??e(r,".config"),d)}var t=A(),o={home:t,config:e(t,".octocoderc"),credentials:e(t,"credentials.json"),key:e(t,".key"),session:e(t,"session.json"),stats:e(t,"stats.json"),tmp:e(t,"tmp"),clone:e(t,"tmp","clone"),tree:e(t,"tmp","tree"),binary:e(t,"tmp","binary"),repos:e(t,"tmp","clone"),unzip:e(t,"tmp","unzip"),cliConfig:e(t,"config.json"),lspConfig:e(t,"lsp-servers.json")};function h(){n(o.home)||i(o.home,{recursive:!0,mode:s})}function z(){D()}function u(){h(),n(o.tmp)||i(o.tmp,{recursive:!0,mode:s})}function D(){u(),n(o.clone)||i(o.clone,{recursive:!0,mode:s})}function N(){u(),n(o.tree)||i(o.tree,{recursive:!0,mode:s})}function T(){u(),n(o.binary)||i(o.binary,{recursive:!0,mode:s})}function _(){u(),n(o.unzip)||i(o.unzip,{recursive:!0,mode:s})}export{t as OCTOCODE_HOME,T as ensureBinary,D as ensureClone,h as ensureHome,z as ensureRepos,u as ensureTmp,N as ensureTree,_ as ensureUnzip,A as getDefaultOctocodeHome,o as paths};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isWindows, isMac, isLinux, HOME, getAppDataPath, getLocalAppDataPath, getPlatformName, getArchitecture, } from './platform.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __createRequire } from 'module';
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
4
|
+
import { dirname as __dirname_fn } from 'path';
|
|
5
|
+
const require = __createRequire(import.meta.url);
|
|
6
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = __dirname_fn(__filename);
|
|
8
|
+
import t from"node:os";import n from"node:path";var o=t.platform()==="win32",e=t.platform()==="darwin",a=t.platform()==="linux",r=t.homedir();function i(){return o?process.env.APPDATA||n.join(r,"AppData","Roaming"):r}function p(){return o?process.env.LOCALAPPDATA||n.join(r,"AppData","Local"):r}function s(){return e?"macOS":o?"Windows":a?"Linux":t.platform()}function c(){return t.arch()}export{r as HOME,i as getAppDataPath,c as getArchitecture,p as getLocalAppDataPath,s as getPlatformName,a as isLinux,e as isMac,o as isWindows};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const isWindows: boolean;
|
|
2
|
+
export declare const isMac: boolean;
|
|
3
|
+
export declare const isLinux: boolean;
|
|
4
|
+
export declare const HOME: string;
|
|
5
|
+
export declare function getAppDataPath(): string;
|
|
6
|
+
export declare function getLocalAppDataPath(): string;
|
|
7
|
+
export declare function getPlatformName(): string;
|
|
8
|
+
export declare function getArchitecture(): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { GitHubCacheHitStats, PersistedStats, PersistedSession, SessionStats, SessionTotalUsageStats, SessionUpdateResult, SessionOptions, StatsCounterMap, ToolCharSavingsStats, } from './types.js';
|
|
2
|
+
export { SESSION_FILE, STATS_FILE } from './storage.js';
|
|
3
|
+
export { readSession, writeSession, getOrCreateSession, getSessionId, deleteSession, flushSession, flushSessionSync, } from './storage.js';
|
|
4
|
+
export { updateSessionStats, incrementToolCalls, incrementErrors, incrementRateLimits, incrementRateLimitByProvider, incrementToolCharSavings, incrementGitHubCacheHits, incrementGitHubCacheRateLimits, incrementPackageRegistryFailures, resetSessionStats, } from './storage.js';
|
|
5
|
+
export { _resetSessionState } from './storage.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __createRequire } from 'module';
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
4
|
+
import { dirname as __dirname_fn } from 'path';
|
|
5
|
+
const require = __createRequire(import.meta.url);
|
|
6
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = __dirname_fn(__filename);
|
|
8
|
+
import{randomUUID as pt}from"node:crypto";import{existsSync as J,readFileSync as ye,writeFileSync as st,unlinkSync as nt,renameSync as ot}from"node:fs";function h(e){return e.toLowerCase().replace(/^https?:\/\//,"").replace(/\/$/,"")}function P(e){if(!e.token.expiresAt)return!1;let t=new Date(e.token.expiresAt);if(isNaN(t.getTime()))return!0;let r=new Date;return t.getTime()-r.getTime()<300*1e3}function z(e){if(!e.token.refreshTokenExpiresAt)return!1;let t=new Date(e.token.refreshTokenExpiresAt);return isNaN(t.getTime())?!0:new Date>=t}var E=new Map,Ae=300*1e3;function we(e){let t=h(e),r=E.get(t);return!r||Date.now()-r.cachedAt>=Ae?!1:r.credentials?!P(r.credentials):!0}function ee(e){e?E.delete(h(e)):E.clear()}function te(e){let t=h(e);if(we(t))return E.get(t).credentials}function re(e,t){let r=h(e);E.set(r,{credentials:t,cachedAt:Date.now()})}import{existsSync as oe,readFileSync as ie,writeFileSync as ae,unlinkSync as Xt,statSync as je,chmodSync as Ue}from"node:fs";import{createCipheriv as Me,createDecipheriv as Be,randomBytes as ce}from"node:crypto";import{existsSync as He,mkdirSync as De}from"node:fs";import{join as c}from"node:path";import _ from"node:os";import Oe from"node:path";var I=_.platform()==="win32",W=_.platform()==="darwin",Le=_.platform()==="linux",T=_.homedir();function K(){return I?process.env.APPDATA||Oe.join(T,"AppData","Roaming"):T}var V=".octocode",Fe=448;function _e(e){let t=process.env[e];return t&&t.trim().length>0?t:void 0}function Ie(){return I?c(K(),V):W?c(T,V):c(_e("XDG_CONFIG_HOME")??c(T,".config"),V)}var u=Ie(),f={home:u,config:c(u,".octocoderc"),credentials:c(u,"credentials.json"),key:c(u,".key"),session:c(u,"session.json"),stats:c(u,"stats.json"),tmp:c(u,"tmp"),clone:c(u,"tmp","clone"),tree:c(u,"tmp","tree"),binary:c(u,"tmp","binary"),repos:c(u,"tmp","clone"),unzip:c(u,"tmp","unzip"),cliConfig:c(u,"config.json"),lspConfig:c(u,"lsp-servers.json")};function se(){He(f.home)||De(f.home,{recursive:!0,mode:Fe})}import{z as a}from"zod";var Ne=a.object({token:a.string(),tokenType:a.literal("oauth"),scopes:a.array(a.string()).optional(),refreshToken:a.string().optional(),expiresAt:a.string().optional(),refreshTokenExpiresAt:a.string().optional()}),Ge=a.object({hostname:a.string(),username:a.string(),token:Ne,gitProtocol:a.enum(["ssh","https"]),createdAt:a.string(),updatedAt:a.string()}),ne=a.object({version:a.number(),credentials:a.record(a.string(),Ge)});var ze=f.home,N=f.credentials,k=f.key,ue="aes-256-gcm",We=16;function x(){se()}function le(){if(x(),oe(k))return je(k).mode&511&63&&Ue(k,384),Buffer.from(ie(k,"utf8"),"hex");let e=ce(32);return ae(k,e.toString("hex"),{mode:384}),e}function fe(e){let t=le(),r=ce(We),s=Me(ue,t,r),n=s.update(e,"utf8","hex");n+=s.final("hex");let i=s.getAuthTag();return`${r.toString("hex")}:${i.toString("hex")}:${n}`}function pe(e){let t=le(),[r,s,n]=e.split(":");if(!r||!s||!n)throw new Error("Invalid encrypted data format");let i=Buffer.from(r,"hex"),C=Buffer.from(s,"hex"),m=Be(ue,t,i);m.setAuthTag(C);let Q=m.update(n,"hex","utf8");return Q+=m.final("utf8"),Q}function $(){if(x(),!oe(N))return{version:1,credentials:{}};try{let e=ie(N,"utf8"),t=pe(e),r=JSON.parse(t),s=ne.safeParse(r);return s.success?s.data:{version:1,credentials:{}}}catch{return{version:1,credentials:{}}}}function de(e){x();let t=fe(JSON.stringify(e,null,2));ae(N,t,{mode:384})}import{refreshToken as Ke}from"@octokit/oauth-methods";import{request as Ve}from"@octokit/request";var G="178c6fc778ccc68e1d6a",A="github.com";function $e(e){return e.replace(/\b(ghp_|gho_|ghu_|ghs_|ghr_)[a-zA-Z0-9]{36,}\b/g,"***MASKED***").replace(/\b[a-zA-Z0-9]{40,}\b/g,"***MASKED***")}function Je(e){return e==="github.com"||e===A?"https://api.github.com":`https://${e}/api/v3`}async function me(e,t=A,r=G){let s=await e.getCredentials(t);if(!s)return{success:!1,error:`Not logged in to ${t}`};if(!s.token.refreshToken)return{success:!1,error:"Token does not support refresh (OAuth App tokens do not expire)"};if(z(s))return{success:!1,error:"Refresh token has expired. Please login again."};try{let n=await Ke({clientType:"github-app",clientId:r,clientSecret:"",refreshToken:s.token.refreshToken,request:Ve.defaults({baseUrl:Je(t)})}),i={token:n.authentication.token,tokenType:"oauth",refreshToken:n.authentication.refreshToken,expiresAt:n.authentication.expiresAt,refreshTokenExpiresAt:n.authentication.refreshTokenExpiresAt};return await e.updateToken(t,i),{success:!0,username:s.username,hostname:t}}catch(n){return{success:!1,error:n instanceof Error?$e(n.message):"Token refresh failed"}}}async function he(e,t=A,r=G){let s=await e.getCredentials(t);if(!s||!s.token)return{token:null,source:"none"};if(!P(s))return{token:s.token.token,source:"stored",username:s.username};if(s.token.refreshToken){let n=await me(e,t,r);if(n.success){let i=await e.getCredentials(t);if(i?.token.token)return{token:i.token.token,source:"refreshed",username:i.username}}return{token:null,source:"none",refreshError:n.error}}return{token:null,source:"none",refreshError:"Token expired and no refresh token available"}}import{execFile as fr}from"child_process";var qe=null;function Se(e){qe=e}async function Ye(e){let t=h(e.hostname),r={...e,hostname:t,updatedAt:new Date().toISOString()};try{let s=$();return s.credentials[t]=r,de(s),ee(t),{success:!0}}catch{throw new Error("Failed to store credentials")}}async function ge(e="github.com",t){let r=h(e);if(!t?.bypassCache){let i=te(r);if(i!==void 0)return i}let n=$().credentials[r]||null;return re(r,n),n}async function Ze(e,t){let r=await ge(e);return r?(r.token=t,r.updatedAt=new Date().toISOString(),await Ye(r),!0):!1}async function Xe(e,t){return he({getCredentials:ge,updateToken:Ze},e,t)}Se({getTokenWithRefresh:Xe});import{z as o}from"zod";var Qe=o.object({rawChars:o.number(),responseChars:o.number(),savedChars:o.number(),calls:o.number()}),et=o.object({hits:o.record(o.string(),o.number()).default({}),rateLimits:o.number().default(0)}),j=o.record(o.string(),o.number()).default({}),tt=o.object({toolCalls:o.number(),errors:o.number(),rateLimits:o.number(),rateLimitsByProvider:j,rawChars:o.number(),responseChars:o.number(),savedChars:o.number(),charSavingsCalls:o.number(),githubCacheHits:o.number(),githubCacheRateLimits:o.number(),packageRegistryFailures:o.number().default(0),packageRegistryFailuresByRegistry:j}),U=o.object({toolCalls:o.number(),errors:o.number(),rateLimits:o.number(),rateLimitsByProvider:j,charsSavedByTool:o.record(o.string(),Qe).default({}),githubCacheHits:et.default({hits:{},rateLimits:0}),packageRegistryFailures:j,totalUsage:tt.optional()}),Ce=o.object({version:o.literal(1),sessionId:o.string(),createdAt:o.string(),lastActiveAt:o.string(),stats:U.optional()}),Te=o.object({version:o.literal(1),stats:U});function ke(e){return Object.values(e).reduce((t,r)=>t+r,0)}function rt(e){let t=e.charsSavedByTool??{},r=e.githubCacheHits??{hits:{},rateLimits:0},s=e.rateLimitsByProvider??{},n=e.packageRegistryFailures??{},i=Object.values(t).reduce((C,m)=>({rawChars:C.rawChars+m.rawChars,responseChars:C.responseChars+m.responseChars,savedChars:C.savedChars+m.savedChars,charSavingsCalls:C.charSavingsCalls+m.calls}),{rawChars:0,responseChars:0,savedChars:0,charSavingsCalls:0});return{toolCalls:e.toolCalls,errors:e.errors,rateLimits:e.rateLimits,rateLimitsByProvider:s,...i,githubCacheHits:ke(r.hits),githubCacheRateLimits:r.rateLimits,packageRegistryFailures:ke(n),packageRegistryFailuresByRegistry:n}}function p(e){let t={...e,rateLimitsByProvider:e.rateLimitsByProvider??{},charsSavedByTool:e.charsSavedByTool??{},githubCacheHits:e.githubCacheHits??{hits:{},rateLimits:0},packageRegistryFailures:e.packageRegistryFailures??{}};return{...t,totalUsage:rt(t)}}function w(){return p({toolCalls:0,errors:0,rateLimits:0,rateLimitsByProvider:{},charsSavedByTool:{},githubCacheHits:{hits:{},rateLimits:0},packageRegistryFailures:{}})}var y=f.session,v=f.stats;function xe(e,t){let r=`${e}.tmp`;st(r,JSON.stringify(t,null,2),{mode:384}),ot(r,e)}function it(e){let{stats:t,...r}=e;return r}function at(e){let t=JSON.parse(e),r=Te.safeParse(t);if(r.success)return p(r.data.stats);let s=U.safeParse(t);return s.success?p(s.data):null}function ct(e){let t=e?p(e):w();if(!J(v))return t;try{let r=ye(v,"utf8"),s=at(r);return s||t}catch{return t}}function M(e){x(),xe(v,{version:e.version,stats:p(e.stats)}),xe(y,it(e))}function ve(){if(!J(y))return null;try{let e=ye(y,"utf8"),t=JSON.parse(e),r=Ce.safeParse(t);return r.success?{...r.data,stats:ct(r.data.stats)}:null}catch{return null}}function Re(){let e=!1;for(let t of[y,v])if(J(t))try{nt(t),e=!0}catch{return!1}return e}var ut=6e4,l=null,S=!1,R=null,q=!1,O=null,L=null,H=null,B=!1;function lt(){q||(q=!0,O=()=>{D()},L=()=>{D()},H=()=>{D()},process.on("exit",O),process.on("SIGINT",L),process.on("SIGTERM",H))}function Y(){O&&(process.removeListener("exit",O),O=null),L&&(process.removeListener("SIGINT",L),L=null),H&&(process.removeListener("SIGTERM",H),H=null),q=!1}function ft(){R||(R=setInterval(()=>{S&&l&&(M(l),S=!1)},ut),R.unref())}function Z(){R&&(clearInterval(R),R=null)}function b(){if(l)return l;let e=ve();return e&&(l=e),e}function g(e){l=e,S=!0,lt(),ft()}function F(){S&&l&&(M(l),S=!1)}function D(){if(!B&&S&&l){B=!0;try{M(l),S=!1}catch{}finally{B=!1}}}function X(){l=null,S=!1,B=!1}function be(){X(),Z(),Y()}var dt=1;function mt(e){return p(e)}function ht(e,t){if(!t)return e;let r={...e};for(let[s,n]of Object.entries(t)){let i=r[s]??{rawChars:0,responseChars:0,savedChars:0,calls:0};r[s]={rawChars:i.rawChars+n.rawChars,responseChars:i.responseChars+n.responseChars,savedChars:i.savedChars+n.savedChars,calls:i.calls+n.calls}}return r}function Pe(e,t){if(!t)return e;let r={...e};for(let[s,n]of Object.entries(t))r[s]=(r[s]??0)+n;return r}function St(e,t){if(!t)return e;let r={...e.hits};for(let[s,n]of Object.entries(t.hits??{}))r[s]=(r[s]??0)+n;return{hits:r,rateLimits:e.rateLimits+(t.rateLimits??0)}}function Ee(){let e=new Date().toISOString();return{version:dt,sessionId:pt(),createdAt:e,lastActiveAt:e,stats:w()}}function gt(){return b()}function Ct(e){g(e)}function Tt(){F()}function kt(){D()}function xt(e){if(e?.forceNew){let s=Ee();return g(s),F(),s}let t=b();if(t){let s={...t,lastActiveAt:new Date().toISOString()};return g(s),F(),s}let r=Ee();return g(r),F(),r}function yt(){return b()?.sessionId??null}function d(e){let t=b();if(!t)return{success:!1,session:null};let r=mt(t.stats),s=p({toolCalls:r.toolCalls+(e.toolCalls??0),errors:r.errors+(e.errors??0),rateLimits:r.rateLimits+(e.rateLimits??0),rateLimitsByProvider:Pe(r.rateLimitsByProvider,e.rateLimitsByProvider),charsSavedByTool:ht(r.charsSavedByTool,e.charsSavedByTool),githubCacheHits:St(r.githubCacheHits,e.githubCacheHits),packageRegistryFailures:Pe(r.packageRegistryFailures,e.packageRegistryFailures)}),n={...t,lastActiveAt:new Date().toISOString(),stats:s};return g(n),{success:!0,session:n}}function vt(e=1){return d({toolCalls:e})}function Rt(e=1){return d({errors:e})}function bt(e=1){return d({rateLimits:e})}function Pt(e,t=1){return d({rateLimits:t,rateLimitsByProvider:{[e]:t}})}function Et(e,t,r){let s=Number.isFinite(t)?Math.max(0,t):0,n=Number.isFinite(r)?Math.max(0,r):0;return d({charsSavedByTool:{[e]:{rawChars:s,responseChars:n,savedChars:Math.max(0,s-n),calls:1}}})}function At(e,t=1){return d({githubCacheHits:{hits:{[e]:t},rateLimits:0}})}function wt(e=1){return d({githubCacheHits:{hits:{},rateLimits:e}})}function Ot(e,t=1){return d({packageRegistryFailures:{[e]:t}})}function Lt(){let e=b();if(!e)return{success:!1,session:null};let t={...e,lastActiveAt:new Date().toISOString(),stats:w()};return g(t),{success:!0,session:t}}function Ht(){return X(),Z(),Y(),Re()}function Dt(){be()}export{y as SESSION_FILE,v as STATS_FILE,Dt as _resetSessionState,Ht as deleteSession,Tt as flushSession,kt as flushSessionSync,xt as getOrCreateSession,yt as getSessionId,Rt as incrementErrors,At as incrementGitHubCacheHits,wt as incrementGitHubCacheRateLimits,Ot as incrementPackageRegistryFailures,Pt as incrementRateLimitByProvider,bt as incrementRateLimits,vt as incrementToolCalls,Et as incrementToolCharSavings,gt as readSession,Lt as resetSessionStats,d as updateSessionStats,Ct as writeSession};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const SessionStatsSchema: z.ZodObject<{
|
|
3
|
+
toolCalls: z.ZodNumber;
|
|
4
|
+
errors: z.ZodNumber;
|
|
5
|
+
rateLimits: z.ZodNumber;
|
|
6
|
+
rateLimitsByProvider: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
7
|
+
charsSavedByTool: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
8
|
+
rawChars: z.ZodNumber;
|
|
9
|
+
responseChars: z.ZodNumber;
|
|
10
|
+
savedChars: z.ZodNumber;
|
|
11
|
+
calls: z.ZodNumber;
|
|
12
|
+
}, z.core.$strip>>>;
|
|
13
|
+
githubCacheHits: z.ZodDefault<z.ZodObject<{
|
|
14
|
+
hits: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
15
|
+
rateLimits: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
packageRegistryFailures: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
18
|
+
totalUsage: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
toolCalls: z.ZodNumber;
|
|
20
|
+
errors: z.ZodNumber;
|
|
21
|
+
rateLimits: z.ZodNumber;
|
|
22
|
+
rateLimitsByProvider: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
23
|
+
rawChars: z.ZodNumber;
|
|
24
|
+
responseChars: z.ZodNumber;
|
|
25
|
+
savedChars: z.ZodNumber;
|
|
26
|
+
charSavingsCalls: z.ZodNumber;
|
|
27
|
+
githubCacheHits: z.ZodNumber;
|
|
28
|
+
githubCacheRateLimits: z.ZodNumber;
|
|
29
|
+
packageRegistryFailures: z.ZodDefault<z.ZodNumber>;
|
|
30
|
+
packageRegistryFailuresByRegistry: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
31
|
+
}, z.core.$strip>>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export declare const PersistedSessionSchema: z.ZodObject<{
|
|
34
|
+
version: z.ZodLiteral<1>;
|
|
35
|
+
sessionId: z.ZodString;
|
|
36
|
+
createdAt: z.ZodString;
|
|
37
|
+
lastActiveAt: z.ZodString;
|
|
38
|
+
stats: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
toolCalls: z.ZodNumber;
|
|
40
|
+
errors: z.ZodNumber;
|
|
41
|
+
rateLimits: z.ZodNumber;
|
|
42
|
+
rateLimitsByProvider: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
43
|
+
charsSavedByTool: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
44
|
+
rawChars: z.ZodNumber;
|
|
45
|
+
responseChars: z.ZodNumber;
|
|
46
|
+
savedChars: z.ZodNumber;
|
|
47
|
+
calls: z.ZodNumber;
|
|
48
|
+
}, z.core.$strip>>>;
|
|
49
|
+
githubCacheHits: z.ZodDefault<z.ZodObject<{
|
|
50
|
+
hits: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
51
|
+
rateLimits: z.ZodDefault<z.ZodNumber>;
|
|
52
|
+
}, z.core.$strip>>;
|
|
53
|
+
packageRegistryFailures: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
54
|
+
totalUsage: z.ZodOptional<z.ZodObject<{
|
|
55
|
+
toolCalls: z.ZodNumber;
|
|
56
|
+
errors: z.ZodNumber;
|
|
57
|
+
rateLimits: z.ZodNumber;
|
|
58
|
+
rateLimitsByProvider: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
59
|
+
rawChars: z.ZodNumber;
|
|
60
|
+
responseChars: z.ZodNumber;
|
|
61
|
+
savedChars: z.ZodNumber;
|
|
62
|
+
charSavingsCalls: z.ZodNumber;
|
|
63
|
+
githubCacheHits: z.ZodNumber;
|
|
64
|
+
githubCacheRateLimits: z.ZodNumber;
|
|
65
|
+
packageRegistryFailures: z.ZodDefault<z.ZodNumber>;
|
|
66
|
+
packageRegistryFailuresByRegistry: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
67
|
+
}, z.core.$strip>>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
export declare const PersistedStatsSchema: z.ZodObject<{
|
|
71
|
+
version: z.ZodLiteral<1>;
|
|
72
|
+
stats: z.ZodObject<{
|
|
73
|
+
toolCalls: z.ZodNumber;
|
|
74
|
+
errors: z.ZodNumber;
|
|
75
|
+
rateLimits: z.ZodNumber;
|
|
76
|
+
rateLimitsByProvider: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
77
|
+
charsSavedByTool: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
78
|
+
rawChars: z.ZodNumber;
|
|
79
|
+
responseChars: z.ZodNumber;
|
|
80
|
+
savedChars: z.ZodNumber;
|
|
81
|
+
calls: z.ZodNumber;
|
|
82
|
+
}, z.core.$strip>>>;
|
|
83
|
+
githubCacheHits: z.ZodDefault<z.ZodObject<{
|
|
84
|
+
hits: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
85
|
+
rateLimits: z.ZodDefault<z.ZodNumber>;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
packageRegistryFailures: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
88
|
+
totalUsage: z.ZodOptional<z.ZodObject<{
|
|
89
|
+
toolCalls: z.ZodNumber;
|
|
90
|
+
errors: z.ZodNumber;
|
|
91
|
+
rateLimits: z.ZodNumber;
|
|
92
|
+
rateLimitsByProvider: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
93
|
+
rawChars: z.ZodNumber;
|
|
94
|
+
responseChars: z.ZodNumber;
|
|
95
|
+
savedChars: z.ZodNumber;
|
|
96
|
+
charSavingsCalls: z.ZodNumber;
|
|
97
|
+
githubCacheHits: z.ZodNumber;
|
|
98
|
+
githubCacheRateLimits: z.ZodNumber;
|
|
99
|
+
packageRegistryFailures: z.ZodDefault<z.ZodNumber>;
|
|
100
|
+
packageRegistryFailuresByRegistry: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
101
|
+
}, z.core.$strip>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PersistedSession } from './types.js';
|
|
2
|
+
export declare function unregisterExitHandlers(): void;
|
|
3
|
+
export declare function stopFlushTimer(): void;
|
|
4
|
+
export declare function readSession(): PersistedSession | null;
|
|
5
|
+
export declare function writeSession(session: PersistedSession): void;
|
|
6
|
+
export declare function flushSession(): void;
|
|
7
|
+
export declare function flushSessionSync(): void;
|
|
8
|
+
export declare function clearCache(): void;
|
|
9
|
+
export declare function resetCacheState(): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PersistedSession } from './types.js';
|
|
2
|
+
export declare const SESSION_FILE: string;
|
|
3
|
+
export declare const STATS_FILE: string;
|
|
4
|
+
export declare function writeSessionToDisk(session: PersistedSession): void;
|
|
5
|
+
export declare function readSessionFromDisk(): PersistedSession | null;
|
|
6
|
+
export declare function deleteSessionFile(): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SessionStats, SessionTotalUsageStats } from './types.js';
|
|
2
|
+
export declare function calculateTotalUsageStats(stats: SessionStats): SessionTotalUsageStats;
|
|
3
|
+
export declare function withDerivedUsageTotals(stats: SessionStats): SessionStats;
|
|
4
|
+
export declare function createDefaultStats(): SessionStats;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PersistedSession, SessionStats, SessionUpdateResult, SessionOptions } from './types.js';
|
|
2
|
+
export declare function readSession(): PersistedSession | null;
|
|
3
|
+
export declare function writeSession(session: PersistedSession): void;
|
|
4
|
+
export declare function flushSession(): void;
|
|
5
|
+
export declare function flushSessionSync(): void;
|
|
6
|
+
export declare function getOrCreateSession(options?: SessionOptions): PersistedSession;
|
|
7
|
+
export declare function getSessionId(): string | null;
|
|
8
|
+
export declare function updateSessionStats(updates: Partial<SessionStats>): SessionUpdateResult;
|
|
9
|
+
export declare function incrementToolCalls(count?: number): SessionUpdateResult;
|
|
10
|
+
export declare function incrementErrors(count?: number): SessionUpdateResult;
|
|
11
|
+
export declare function incrementRateLimits(count?: number): SessionUpdateResult;
|
|
12
|
+
export declare function incrementRateLimitByProvider(provider: string, count?: number): SessionUpdateResult;
|
|
13
|
+
export declare function incrementToolCharSavings(toolName: string, rawChars: number, responseChars: number): SessionUpdateResult;
|
|
14
|
+
export declare function incrementGitHubCacheHits(cacheName: string, count?: number): SessionUpdateResult;
|
|
15
|
+
export declare function incrementGitHubCacheRateLimits(count?: number): SessionUpdateResult;
|
|
16
|
+
export declare function incrementPackageRegistryFailures(registry: string, count?: number): SessionUpdateResult;
|
|
17
|
+
export declare function resetSessionStats(): SessionUpdateResult;
|
|
18
|
+
export declare function deleteSession(): boolean;
|
|
19
|
+
export declare function _resetSessionState(): void;
|
|
20
|
+
export { SESSION_FILE, STATS_FILE } from './sessionDiskIO.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface ToolCharSavingsStats {
|
|
2
|
+
rawChars: number;
|
|
3
|
+
responseChars: number;
|
|
4
|
+
savedChars: number;
|
|
5
|
+
calls: number;
|
|
6
|
+
}
|
|
7
|
+
export interface GitHubCacheHitStats {
|
|
8
|
+
hits: Record<string, number>;
|
|
9
|
+
rateLimits: number;
|
|
10
|
+
}
|
|
11
|
+
export type StatsCounterMap = Record<string, number>;
|
|
12
|
+
export interface SessionTotalUsageStats {
|
|
13
|
+
toolCalls: number;
|
|
14
|
+
errors: number;
|
|
15
|
+
rateLimits: number;
|
|
16
|
+
rateLimitsByProvider: StatsCounterMap;
|
|
17
|
+
rawChars: number;
|
|
18
|
+
responseChars: number;
|
|
19
|
+
savedChars: number;
|
|
20
|
+
charSavingsCalls: number;
|
|
21
|
+
githubCacheHits: number;
|
|
22
|
+
githubCacheRateLimits: number;
|
|
23
|
+
packageRegistryFailures: number;
|
|
24
|
+
packageRegistryFailuresByRegistry: StatsCounterMap;
|
|
25
|
+
}
|
|
26
|
+
export interface SessionStats {
|
|
27
|
+
toolCalls: number;
|
|
28
|
+
errors: number;
|
|
29
|
+
rateLimits: number;
|
|
30
|
+
rateLimitsByProvider?: StatsCounterMap;
|
|
31
|
+
charsSavedByTool?: Record<string, ToolCharSavingsStats>;
|
|
32
|
+
githubCacheHits?: GitHubCacheHitStats;
|
|
33
|
+
packageRegistryFailures?: StatsCounterMap;
|
|
34
|
+
totalUsage?: SessionTotalUsageStats;
|
|
35
|
+
}
|
|
36
|
+
export interface PersistedSession {
|
|
37
|
+
version: 1;
|
|
38
|
+
sessionId: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
lastActiveAt: string;
|
|
41
|
+
stats: SessionStats;
|
|
42
|
+
}
|
|
43
|
+
export interface PersistedStats {
|
|
44
|
+
version: 1;
|
|
45
|
+
stats: SessionStats;
|
|
46
|
+
}
|
|
47
|
+
export interface SessionUpdateResult {
|
|
48
|
+
success: boolean;
|
|
49
|
+
session: PersistedSession | null;
|
|
50
|
+
}
|
|
51
|
+
export interface SessionOptions {
|
|
52
|
+
forceNew?: boolean;
|
|
53
|
+
}
|
|
@@ -1,56 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type: string;
|
|
17
|
-
/** Numeric bounds and default, e.g. "1-100, default 30" — surfaced inline so
|
|
18
|
-
* agents see the full constraint without fetching the raw JSON schema. */
|
|
19
|
-
constraints?: string;
|
|
20
|
-
description?: string;
|
|
21
|
-
}
|
|
22
|
-
export interface DirectToolOutputField {
|
|
23
|
-
name: string;
|
|
24
|
-
type: string;
|
|
25
|
-
optional?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export interface DirectToolMetadata {
|
|
28
|
-
tools?: Record<string, {
|
|
29
|
-
description?: string;
|
|
30
|
-
schema?: Record<string, string>;
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
export interface PrepareDirectToolInputOptions {
|
|
34
|
-
sourceLabel?: string;
|
|
35
|
-
onUnknownFields?: (unknownFields: string[], queryIndex: number) => void;
|
|
36
|
-
}
|
|
37
|
-
export declare class DirectToolInputError extends Error {
|
|
38
|
-
readonly details: string[];
|
|
39
|
-
constructor(message: string, details?: string[]);
|
|
40
|
-
}
|
|
41
|
-
export declare const DIRECT_TOOL_DEFINITIONS: DirectToolDefinition[];
|
|
42
|
-
export declare function findDirectToolDefinition(name: string): DirectToolDefinition | undefined;
|
|
43
|
-
export declare function getDirectToolCategory(toolName: string): DirectToolCategory;
|
|
44
|
-
export declare function sortDirectToolNames(toolNames: string[]): string[];
|
|
45
|
-
export declare function formatDirectToolSchemaText(toolName: string): string;
|
|
46
|
-
export declare function formatDirectToolMetadataSchemaText(schema: Record<string, string> | undefined): string;
|
|
47
|
-
export declare function getDirectToolAutoFilledFields(toolName: string): string[];
|
|
48
|
-
export declare function getDirectToolOutputFields(): DirectToolOutputField[];
|
|
49
|
-
export declare function formatDirectToolOutputSchemaText(): string;
|
|
50
|
-
export declare function getDirectToolDescription(toolName: string, metadata?: DirectToolMetadata | null): string;
|
|
51
|
-
export declare function getDirectToolDisplayFields(toolName: string): DirectToolDisplayField[];
|
|
52
|
-
export declare function buildDirectToolExampleQuery(toolName: string): Record<string, unknown>;
|
|
53
|
-
export declare function prepareDirectToolInputFromJsonText(toolName: string, inputText: string | undefined, options?: PrepareDirectToolInputOptions): DirectToolInput | null;
|
|
54
|
-
export declare function prepareDirectToolInput(toolName: string, rawPayload: unknown, options?: PrepareDirectToolInputOptions): DirectToolInput;
|
|
55
|
-
export declare function formatDirectToolValidationIssues(error: z.ZodError): string[];
|
|
56
|
-
export declare function executeDirectTool(name: string, input: unknown): Promise<CallToolResult>;
|
|
1
|
+
/**
|
|
2
|
+
* Direct-tool catalog barrel (P3). The catalog is split so the schema/help path
|
|
3
|
+
* never loads the native engine:
|
|
4
|
+
* - `directToolCatalog.meta.ts` — engine-free definitions, schema text,
|
|
5
|
+
* display fields, input preparation (also exposed via the `/schema` subpath).
|
|
6
|
+
* - `directToolCatalog.exec.ts` — `executeDirectTool` + the engine/runtime.
|
|
7
|
+
*
|
|
8
|
+
* This barrel preserves the historical `@octocodeai/octocode-tools-core/direct`
|
|
9
|
+
* surface (meta + executeDirectTool). Importing it still eagerly loads the engine
|
|
10
|
+
* (via the exec module) — execution consumers want that. Pure schema/help/
|
|
11
|
+
* `--scheme`/`context` callers must import from `/schema` (meta only) instead, so
|
|
12
|
+
* they run on engine-less runtimes.
|
|
13
|
+
*/
|
|
14
|
+
export * from './directToolCatalog.meta.js';
|
|
15
|
+
export { executeDirectTool } from './directToolCatalog.exec.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct-tool EXECUTION path (P3). This module imports the engine (native LSP
|
|
3
|
+
* client pool) and every tool's execution function via `ALL_TOOLS`, so it is the
|
|
4
|
+
* one that loads the native `.node` addon at eval. It is reached only when a tool
|
|
5
|
+
* actually runs — schema/help/`--scheme`/`context` use `directToolCatalog.meta.ts`
|
|
6
|
+
* (and the `@octocodeai/octocode-tools-core/schema` subpath), which is engine-free.
|
|
7
|
+
*/
|
|
8
|
+
import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import { DirectToolInputError } from './directToolCatalog.meta.js';
|
|
10
|
+
export declare function executeDirectTool(name: string, input: unknown): Promise<CallToolResult>;
|
|
11
|
+
export { DirectToolInputError };
|