# types/tool.types.ts

> 76 lines of code and 15 definitions.

Tree: GovLab Quality
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/quality#file-quality-types-tool-types-ts
Source text: https://banes-lab.com/source/quality/types/tool.types.ts.txt

Listed in [types](https://banes-lab.com/api/source/quality/types.md), after [types/target.types.ts](https://banes-lab.com/source/quality/types/target.types.ts.md) and before [types/validation.types.ts](https://banes-lab.com/source/quality/types/validation.types.ts.md).

## Definitions

- `PrettierEmitPolicy` (interface_declaration, line 6, exported)
- `ProcessEnv` (type_alias_declaration, line 11, exported)
- `TerminationSignal` (type_alias_declaration, line 13, exported)
- `ToolSpawn` (type_alias_declaration, line 15, exported)
- `RunnerContext` (interface_declaration, line 17, exported)
- `Runner` (type_alias_declaration, line 29, exported)
- `ToolRunner` (interface_declaration, line 31, exported)
- `AdvisoryContext` (interface_declaration, line 37, exported)
- `ToolExit` (interface_declaration, line 47, exported)
- `CommandInvocation` (interface_declaration, line 53, exported)
- `AdvisoryToolSpec` (interface_declaration, line 58, exported)
- `SelectableToolSpec` (interface_declaration, line 67, exported)
- `ToolCall` (interface_declaration, line 77, exported)
- `ScanSpec` (interface_declaration, line 84, exported)
- `ScanOutcome` (type_alias_declaration, line 90, exported)

## Contained in

- [types](https://banes-lab.com/anatomy/quality/folder-quality-types.md)

## Source

```typescript
import type { ChildProcess, SpawnSyncReturns } from "node:child_process";
import type { Finding, FindingSeverity, RunResult } from "#types/finding.types";
import type { ConcernConfig } from "#types/concern.types";
import type process from "node:process";

export interface PrettierEmitPolicy {
    concerns?: ConcernConfig | undefined;
    base?: Record<string, unknown> | undefined;
}

export type ProcessEnv = typeof process.env;

export type TerminationSignal = NonNullable<ChildProcess["signalCode"]>;

export type ToolSpawn = SpawnSyncReturns<string>;

export interface RunnerContext {
    root: string;
    paths: string[];
    fix: boolean;
    ecosystem: string;
    languageId: string;
    elected?: boolean | undefined;
    dryRun?: boolean | undefined;
    backup?: boolean | undefined;
    env?: ProcessEnv | undefined;
}

export type Runner = (context: RunnerContext) => Promise<RunResult> | RunResult;

export interface ToolRunner {
    tool: string;
    ecosystems: readonly string[];
    run: Runner;
}

export interface AdvisoryContext {
    ecosystem: string;
    installHint: string;
    root: string;
    tool: string;
    failureSeverity?: FindingSeverity;
    gating?: boolean;
    notInstalledOutput?: string;
}

export interface ToolExit {
    status: number;
    stderr: string;
    stdout: string;
}

export interface CommandInvocation {
    bin: string;
    prefix: string[];
}

export interface AdvisoryToolSpec {
    tool: string;
    argsFor: (context: RunnerContext) => string[];
    cwdFor: (context: RunnerContext) => string;
    statusOk: (status: number | null) => boolean;
    stream?: "stderr" | "stdout";
    parse: (output: string, ecosystem: string) => Finding[];
}

export interface SelectableToolSpec {
    tool: string;
    configFilename: string;
    loadConfig: (root: string) => Promise<string>;
    argsFor: (configFile: string | null, context: RunnerContext) => string[];
    cwdFor: (context: RunnerContext) => string;
    statusOk: (status: number | null) => boolean;
    parse: (stdout: string, ecosystem: string, advisory: boolean) => Finding[];
}

export interface ToolCall {
    bin: string;
    args: string[];
    cwd: string;
    env?: ProcessEnv | undefined;
}

export interface ScanSpec {
    parse: (result: ToolSpawn) => Finding[];
    failed: (result: ToolSpawn, findings: readonly Finding[]) => boolean;
    failure: (exit: ToolExit) => RunResult;
}

export type ScanOutcome =
    { findings: Finding[]; kind: "findings" } | { kind: "skip" } | { kind: "terminal"; result: RunResult };
```
