Skip to main content
Glama

twining_why

Check what decisions constrain a file before modifying it. View rationale and alternatives to avoid contradicting prior choices.

Instructions

Before modifying a file, check what decisions constrain it. Shows rationale and alternatives so you don't contradict prior choices.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scopeYesFile path, module name, or symbol to query

Implementation Reference

  • Registers the 'twining_why' MCP tool with scope input and delegates to engine.why()
    // twining_why — Retrieve decision chain for a scope or file
    server.registerTool(
      "twining_why",
      {
        description:
          "Before modifying a file, check what decisions constrain it. Shows rationale and alternatives so you don't contradict prior choices.",
        inputSchema: {
          scope: z
            .string()
            .describe("File path, module name, or symbol to query"),
        },
      },
      async (args) => {
        try {
          const result = await engine.why(args.scope);
          return toolResult(result);
        } catch (e) {
          return toolError(
            e instanceof Error ? e.message : "Unknown error",
            "INTERNAL_ERROR",
          );
        }
      },
    );
  • Core handler logic: queries DecisionStore.getByScope(scope) then maps results to return decisions with rationale, alternatives count, and active/provisional counts
    /** Retrieve decision chain for a scope or file. */
    async why(scope: string): Promise<{
      decisions: Array<{
        id: string;
        summary: string;
        rationale: string;
        confidence: string;
        status: string;
        timestamp: string;
        alternatives_count: number;
        commit_hashes: string[];
      }>;
      active_count: number;
      provisional_count: number;
    }> {
      const decisions = await this.decisionStore.getByScope(scope);
    
      const mapped = decisions.map((d) => ({
        id: d.id,
        summary: d.summary,
        rationale: d.rationale,
        confidence: d.confidence,
        status: d.status,
        timestamp: d.timestamp,
        alternatives_count: d.alternatives.length,
        commit_hashes: d.commit_hashes ?? [],
      }));
    
      const active_count = decisions.filter((d) => d.status === "active").length;
      const provisional_count = decisions.filter(
        (d) => d.status === "provisional",
      ).length;
    
      return { decisions: mapped, active_count, provisional_count };
    }
  • Storage helper that queries the decision index by scope prefix-match, affected files, or affected symbols, then loads full decision JSON files
    /** Get all decisions matching a scope (prefix match or affected files/symbols match). */
    async getByScope(scope: string): Promise<Decision[]> {
      const index = await this.getIndex();
    
      const matching = index.filter(
        (entry) =>
          entry.scope.startsWith(scope) ||
          scope.startsWith(entry.scope) ||
          entry.affected_files.some(
            (f) => f.startsWith(scope) || scope.startsWith(f),
          ) ||
          entry.affected_symbols.some((s) => s === scope),
      );
    
      // Load full decision files for matches
      const decisions: Decision[] = [];
      for (const entry of matching) {
        const decision = await this.get(entry.id);
        if (decision) decisions.push(decision);
      }
    
      // Sort by timestamp descending, then by ID descending (ULID is monotonic)
      decisions.sort(
        (a, b) =>
          b.timestamp.localeCompare(a.timestamp) ||
          b.id.localeCompare(a.id),
      );
    
      return decisions;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It implies a read-only operation ('check,' 'shows rationale') without mentioning side effects. It is transparent about its behavior, but could explicitly state it does not modify state.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loaded with the key context ('Before modifying a file'), and every sentence adds value. No redundant or wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given one parameter, no output schema, and no annotations, the description effectively covers the tool's purpose, usage context, and what it shows. It could specify the return format or note error conditions, but it is sufficient for an agent to decide to invoke it.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has one parameter (scope) with full description. The description adds meaning by explaining that scope is used to query 'what decisions constrain it' and the output includes 'rationale and alternatives,' going beyond the schema's parameter description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Before modifying a file, check what decisions constrain it. Shows rationale and alternatives so you don't contradict prior choices.' It uses a specific verb (check, shows) and resource (decisions constraining a file), distinguishing it from siblings like twining_add_entity or twining_post.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides a clear context for use: 'Before modifying a file.' This implies when to apply the tool. However, it does not explicitly exclude scenarios or compare to alternatives like twining_graph_query or twining_neighbors, which could serve similar query purposes.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daveangulo/twining-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server