chore: include pre-built dist for github install
This commit is contained in:
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
export type SessionInjectedRulesCache = {
|
||||
contentHashes: Set<string>;
|
||||
realPaths: Set<string>;
|
||||
};
|
||||
export declare function createSessionCacheStore(): {
|
||||
getSessionCache: (sessionID: string) => SessionInjectedRulesCache;
|
||||
clearSessionCache: (sessionID: string) => void;
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
export declare const RULES_INJECTOR_STORAGE: string;
|
||||
export declare const PROJECT_MARKERS: string[];
|
||||
export declare const PROJECT_RULE_SUBDIRS: [string, string][];
|
||||
export declare const PROJECT_RULE_FILES: string[];
|
||||
export declare const GITHUB_INSTRUCTIONS_PATTERN: RegExp;
|
||||
export declare const USER_RULE_DIR = ".claude/rules";
|
||||
export declare const RULE_EXTENSIONS: string[];
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { findProjectRoot } from "./project-root-finder";
|
||||
export { calculateDistance } from "./rule-distance";
|
||||
export { findRuleFiles } from "./rule-file-finder";
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin";
|
||||
interface ToolExecuteInput {
|
||||
tool: string;
|
||||
sessionID: string;
|
||||
callID: string;
|
||||
}
|
||||
interface ToolExecuteOutput {
|
||||
title: string;
|
||||
output: string;
|
||||
metadata: unknown;
|
||||
}
|
||||
interface ToolExecuteBeforeOutput {
|
||||
args: unknown;
|
||||
}
|
||||
interface EventInput {
|
||||
event: {
|
||||
type: string;
|
||||
properties?: unknown;
|
||||
};
|
||||
}
|
||||
export declare function createRulesInjectorHook(ctx: PluginInput, modelCacheState?: {
|
||||
anthropicContext1MEnabled: boolean;
|
||||
}): {
|
||||
"tool.execute.before": (input: ToolExecuteInput, output: ToolExecuteBeforeOutput) => Promise<void>;
|
||||
"tool.execute.after": (input: ToolExecuteInput, output: ToolExecuteOutput) => Promise<void>;
|
||||
event: ({ event }: EventInput) => Promise<void>;
|
||||
};
|
||||
export {};
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export { createRulesInjectorHook } from "./hook";
|
||||
export { calculateDistance, findProjectRoot, findRuleFiles } from "./finder";
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import type { SessionInjectedRulesCache } from "./cache";
|
||||
type ToolExecuteOutput = {
|
||||
title: string;
|
||||
output: string;
|
||||
metadata: unknown;
|
||||
};
|
||||
type DynamicTruncator = {
|
||||
truncate: (sessionID: string, content: string) => Promise<{
|
||||
result: string;
|
||||
truncated: boolean;
|
||||
}>;
|
||||
};
|
||||
export declare function createRuleInjectionProcessor(deps: {
|
||||
workspaceDirectory: string;
|
||||
truncator: DynamicTruncator;
|
||||
getSessionCache: (sessionID: string) => SessionInjectedRulesCache;
|
||||
}): {
|
||||
processFilePathForInjection: (filePath: string, sessionID: string, output: ToolExecuteOutput) => Promise<void>;
|
||||
};
|
||||
export {};
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import type { RuleMetadata } from "./types";
|
||||
export interface MatchResult {
|
||||
applies: boolean;
|
||||
reason?: string;
|
||||
}
|
||||
/**
|
||||
* Check if a rule should apply to the current file based on metadata
|
||||
*/
|
||||
export declare function shouldApplyRule(metadata: RuleMetadata, currentFilePath: string, projectRoot: string | null): MatchResult;
|
||||
/**
|
||||
* Check if realPath already exists in cache (symlink deduplication)
|
||||
*/
|
||||
export declare function isDuplicateByRealPath(realPath: string, cache: Set<string>): boolean;
|
||||
/**
|
||||
* Create SHA-256 hash of content, truncated to 16 chars
|
||||
*/
|
||||
export declare function createContentHash(content: string): string;
|
||||
/**
|
||||
* Check if content hash already exists in cache
|
||||
*/
|
||||
export declare function isDuplicateByContentHash(hash: string, cache: Set<string>): boolean;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export interface ToolExecuteOutputShape {
|
||||
title: string;
|
||||
metadata: unknown;
|
||||
}
|
||||
export declare function getRuleInjectionFilePath(output: ToolExecuteOutputShape): string | null;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import type { RuleMetadata } from "./types";
|
||||
export interface RuleFrontmatterResult {
|
||||
metadata: RuleMetadata;
|
||||
body: string;
|
||||
}
|
||||
/**
|
||||
* Parse YAML frontmatter from rule file content
|
||||
* Supports:
|
||||
* - Single string: globs: "**\/*.py"
|
||||
* - Inline array: globs: ["**\/*.py", "src/**\/*.ts"]
|
||||
* - Multi-line array:
|
||||
* globs:
|
||||
* - "**\/*.py"
|
||||
* - "src/**\/*.ts"
|
||||
* - Comma-separated: globs: "**\/*.py, src/**\/*.ts"
|
||||
* - Claude Code 'paths' field (alias for globs)
|
||||
*/
|
||||
export declare function parseRuleFrontmatter(content: string): RuleFrontmatterResult;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Find project root by walking up from startPath.
|
||||
* Checks for PROJECT_MARKERS (.git, pyproject.toml, package.json, etc.)
|
||||
*
|
||||
* @param startPath - Starting path to search from (file or directory)
|
||||
* @returns Project root path or null if not found
|
||||
*/
|
||||
export declare function findProjectRoot(startPath: string): string | null;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Calculate directory distance between a rule file and current file.
|
||||
* Distance is based on common ancestor within project root.
|
||||
*
|
||||
* @param rulePath - Path to the rule file
|
||||
* @param currentFile - Path to the current file being edited
|
||||
* @param projectRoot - Project root for relative path calculation
|
||||
* @returns Distance (0 = same directory, higher = further)
|
||||
*/
|
||||
export declare function calculateDistance(rulePath: string, currentFile: string, projectRoot: string | null): number;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import type { RuleFileCandidate } from "./types";
|
||||
/**
|
||||
* Find all rule files for a given context.
|
||||
* Searches from currentFile upward to projectRoot for rule directories,
|
||||
* then user-level directory (~/.claude/rules).
|
||||
*
|
||||
* IMPORTANT: This searches EVERY directory from file to project root.
|
||||
* Not just the project root itself.
|
||||
*
|
||||
* @param projectRoot - Project root path (or null if outside any project)
|
||||
* @param homeDir - User home directory
|
||||
* @param currentFile - Current file being edited (for distance calculation)
|
||||
* @returns Array of rule file candidates sorted by distance
|
||||
*/
|
||||
export declare function findRuleFiles(projectRoot: string | null, homeDir: string, currentFile: string): RuleFileCandidate[];
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Recursively find all rule files (*.md, *.mdc) in a directory
|
||||
*
|
||||
* @param dir - Directory to search
|
||||
* @param results - Array to accumulate results
|
||||
*/
|
||||
export declare function findRuleFilesRecursive(dir: string, results: string[]): void;
|
||||
/**
|
||||
* Resolve symlinks safely with fallback to original path
|
||||
*
|
||||
* @param filePath - Path to resolve
|
||||
* @returns Real path or original path if resolution fails
|
||||
*/
|
||||
export declare function safeRealpathSync(filePath: string): string;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
export declare function loadInjectedRules(sessionID: string): {
|
||||
contentHashes: Set<string>;
|
||||
realPaths: Set<string>;
|
||||
};
|
||||
export declare function saveInjectedRules(sessionID: string, data: {
|
||||
contentHashes: Set<string>;
|
||||
realPaths: Set<string>;
|
||||
}): void;
|
||||
export declare function clearInjectedRules(sessionID: string): void;
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Rule file metadata (Claude Code style frontmatter)
|
||||
* Supports both Claude Code format (globs, paths) and GitHub Copilot format (applyTo)
|
||||
* @see https://docs.anthropic.com/en/docs/claude-code/settings#rule-files
|
||||
* @see https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot
|
||||
*/
|
||||
export interface RuleMetadata {
|
||||
description?: string;
|
||||
globs?: string | string[];
|
||||
alwaysApply?: boolean;
|
||||
}
|
||||
/**
|
||||
* Rule information with path context and content
|
||||
*/
|
||||
export interface RuleInfo {
|
||||
/** Absolute path to the rule file */
|
||||
path: string;
|
||||
/** Path relative to project root */
|
||||
relativePath: string;
|
||||
/** Directory distance from target file (0 = same dir) */
|
||||
distance: number;
|
||||
/** Rule file content (without frontmatter) */
|
||||
content: string;
|
||||
/** SHA-256 hash of content for deduplication */
|
||||
contentHash: string;
|
||||
/** Parsed frontmatter metadata */
|
||||
metadata: RuleMetadata;
|
||||
/** Why this rule matched (e.g., "alwaysApply", "glob: *.ts", "path match") */
|
||||
matchReason: string;
|
||||
/** Real path after symlink resolution (for duplicate detection) */
|
||||
realPath: string;
|
||||
}
|
||||
/**
|
||||
* Rule file candidate with discovery context
|
||||
*/
|
||||
export interface RuleFileCandidate {
|
||||
path: string;
|
||||
realPath: string;
|
||||
isGlobal: boolean;
|
||||
distance: number;
|
||||
/** Single-file rules (e.g., .github/copilot-instructions.md) always apply without frontmatter */
|
||||
isSingleFile?: boolean;
|
||||
}
|
||||
/**
|
||||
* Session storage for injected rules tracking
|
||||
*/
|
||||
export interface InjectedRulesData {
|
||||
sessionID: string;
|
||||
/** Content hashes of already injected rules */
|
||||
injectedHashes: string[];
|
||||
/** Real paths of already injected rules (for symlink deduplication) */
|
||||
injectedRealPaths: string[];
|
||||
updatedAt: number;
|
||||
}
|
||||
Reference in New Issue
Block a user