skills/aligncoder-aligning-retrieval-target/SKILL.md
Repository-level code completion using AlignCoder's query enhancement and aligned retrieval technique. Generates candidate completions to build an enhanced query that bridges the semantic gap between unfinished code and the target completion, then retrieves precisely relevant cross-file context. Use this skill when the user says: - "Complete this code using context from other files in the repo" - "Help me finish this function using the rest of the codebase" - "Use cross-file context to complete this code" - "I need repo-aware code completion for this partial implementation" - "Retrieve relevant code from the repository to help complete this" - "What would go here based on how similar code works in this project?"
npx skillsauth add ndpvt-web/arxiv-claude-skills aligncoder-aligning-retrieval-targetInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill enables Claude to perform high-quality repository-level code completion by applying AlignCoder's core insight: when completing code, the initial unfinished code (the "query") is semantically distant from the target completion, making naive retrieval of cross-file context ineffective. AlignCoder solves this by first generating multiple candidate completions to construct an enhanced query that contains key tokens related to the target, then using that enriched signal to retrieve precisely relevant code snippets from the repository. This two-phase retrieve-then-refine approach produces dramatically better completions than single-pass retrieval.
The Alignment Problem. Traditional RAG-based code completion retrieves cross-file snippets using the unfinished code as the search query. But the unfinished code is semantically closer to the prefix of the target, not the completion itself. For example, if you need to complete generator., the unfinished code mentions generator but not get_accept_token — the actual method to call. This semantic gap causes retrieval to return snippets similar to the context rather than snippets relevant to the completion.
Query Enhancement via Candidate Completions. AlignCoder addresses this by generating multiple candidate completions (typically 4) using a coarse initial retrieval pass. These candidates — even if individually imperfect — collectively contain key tokens that overlap with the true target. By concatenating these candidates with the original unfinished code, AlignCoder constructs an enhanced query that is much closer to the target in embedding space. This enhanced query is then used for a second, fine-grained retrieval pass that fetches genuinely relevant cross-file context (e.g., class definitions, method signatures, related implementations).
Two-Type Codebase Construction. The repository is indexed into two snippet types: (1) base code snippets created by splitting files at blank lines and aggregating into fixed-length chunks, and (2) dependency snippets extracted by parsing import statements and collecting the signatures (not full implementations) of imported functions, classes, and methods. This dual representation ensures retrieval can surface both usage patterns and API definitions.
Parse the unfinished code and identify the completion point. Determine exactly where the cursor is, what the surrounding context looks like, and what imports/dependencies are declared at the top of the current file.
Extract dependency information from imports. Parse the import statements in the current file to identify which modules, classes, and functions are referenced. Use this to prioritize which files in the repository are likely relevant.
Build the retrieval codebase from the repository. Index the repo into two snippet pools:
Perform coarse-grained retrieval using lexical matching (BM25). Use the unfinished code as a query to retrieve the top-k most lexically similar snippets from the combined snippet pool. This initial pass provides rough context.
Generate multiple candidate completions (n=4). Using the coarse-retrieved context concatenated with the unfinished code, generate 4 diverse candidate completions. Use higher temperature (0.8) and nucleus sampling (top-p 0.95) to ensure diversity — the goal is to cover different plausible completions so that collectively they contain key tokens from the true target.
Construct the enhanced query. Concatenate the original unfinished code with all 4 candidate completions. This enhanced query now contains tokens that are semantically aligned with the target completion, bridging the gap that made initial retrieval imprecise.
Perform fine-grained retrieval using the enhanced query. Search the snippet pool again using the enhanced query with semantic similarity (embedding-based). The candidate completion tokens steer retrieval toward snippets that define the APIs, patterns, or types actually needed for the completion.
Assemble the final prompt. Combine the fine-grained retrieved snippets (as cross-file context) with the original unfinished code. Place retrieved snippets before the unfinished code so the model sees the relevant definitions first.
Generate the final completion. Produce the target completion from this enriched prompt. The model now has both the unfinished code and precisely relevant cross-file context.
Validate the completion against repository conventions. Check that the generated code uses correct method names, argument orders, and types as defined in the retrieved snippets. Fix any inconsistencies.
Example 1: Completing a method call on an imported class
User: Complete this code — I know the ExLlamaGenerator class is defined
elsewhere in the repo but I don't remember the exact method names.
# Current file: inference.py
from model.generator import ExLlamaGenerator
def run_inference(gen: ExLlamaGenerator, input_ids):
gen.settings.temperature = 0.7
token = gen. # <-- complete here
Approach:
ExLlamaGenerator comes from model/generator.pymodel/generator.py, extract class
signature and method signatures for ExLlamaGeneratorExLlamaGeneratorgen.get_accept_token(input_ids),
gen.generate_token(input_ids), gen.sample_token(input_ids),
gen.get_next_token(input_ids)get_accept_token, generate_tokendef get_accept_token(self, input_ids) -> torch.Tensorgen.get_accept_token(input_ids)Output:
token = gen.get_accept_token(input_ids)
Example 2: Completing a configuration pattern used elsewhere in the project
User: I'm adding a new endpoint to this FastAPI app. Complete the route
handler based on how other endpoints are structured in this repo.
# Current file: api/routes/users.py
from api.deps import get_db, get_current_user
from api.schemas.user import UserResponse
@router.get("/users/{user_id}")
async def get_user(
user_id: int,
# <-- complete the rest of this function signature and body
Approach:
get_db, get_current_user from api/deps.py,
UserResponse from api/schemas/user.pyapi/deps.py (get function signatures)
and api/schemas/user.py (get UserResponse fields)api/routes/ directorydb: Session = Depends(get_db), current_user = Depends(get_current_user),
raise HTTPException(status_code=404)Depends() injection pattern used across the repoget_item() that shows
the exact dependency injection pattern and error handling conventionOutput:
@router.get("/users/{user_id}", response_model=UserResponse)
async def get_user(
user_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
user = db.query(UserModel).filter(UserModel.id == user_id).first()
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user
Example 3: Completing a test that follows the repo's testing patterns
User: Add a test for the new `calculate_discount` function. Follow the
patterns used in the existing test files.
# Current file: tests/test_pricing.py
from pricing.discounts import calculate_discount
from tests.fixtures import sample_order, premium_customer
class TestCalculateDiscount:
def test_premium_customer_discount(self):
# <-- complete here
Approach:
calculate_discount signature and sample_order/
premium_customer fixture definitionscalculate_discount, fields of
fixture objectstests/ directoryassert, fixture field names,
expected discount values — aligning with the test patternTestCalculateShipping which shows
exact assertion pattern: arrange fixtures, call function, assert resultOutput:
def test_premium_customer_discount(self):
order = sample_order(subtotal=100.00)
customer = premium_customer()
discount = calculate_discount(order, customer)
assert discount.percentage == 15.0
assert discount.amount == 15.00
AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion — Jiang et al., ASE 2025. Key sections: Section 3 (Approach) for the query enhancement mechanism and AlignRetriever training; Section 4.4 for ablation studies showing the contribution of each component; Figure 2 for the end-to-end pipeline diagram.
development
Audit LLM-based automatic short answer grading (ASAG) systems for adversarial vulnerabilities using token-level and prompt-level attack strategies from the GradingAttack framework. Triggers: 'test grading robustness', 'adversarial attack on grading', 'audit LLM grader', 'red-team answer grading', 'ASAG vulnerability assessment', 'grading fairness attack'
development
Build structured information-seeking agents that decompose complex queries into multi-turn search-and-browse workflows, aggregate results from multiple web sources, and return answers in typed structured formats (items, sets, lists, tables). Applies the GISA benchmark's ReAct-based agent architecture and evaluation methodology. Trigger phrases: "build an information-seeking agent", "search agent pipeline", "multi-turn web research agent", "structured web search workflow", "aggregate information from multiple sources", "web research with structured output"
data-ai
Optimize LLM prompts using GFlowPO's iterative generate-evaluate-refine loop with diversity-preserving exploration and dynamic memory. Use when: 'optimize this prompt', 'find a better prompt for this task', 'prompt engineering with examples', 'auto-tune my system prompt', 'improve prompt accuracy', 'generate prompt variations'.
development
Constrain LLM generation with executable Pydantic schemas and multi-agent pipelines to produce structurally valid, domain-rich artifacts. Uses ontology-as-grammar to eliminate hallucinated structures while preserving creative output. Trigger phrases: "generate a valid game design", "schema-constrained generation", "build a multi-agent pipeline with Pydantic validation", "ontology-driven content generation", "structured creative generation with DSPy", "generate artifacts that pass domain validation".