dsh-hashline-edit 0.5.0 → 0.5.2
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 +84 -7
- package/cordis.patch.yml +20 -2
- package/lib/client.js +13 -3
- package/lib/index.js +2643 -78
- package/lib/types/dsh/codegraph/cli.d.ts +61 -0
- package/lib/types/dsh/codegraph/project.d.ts +27 -0
- package/lib/types/dsh/codegraph/tools.d.ts +36 -0
- package/lib/types/dsh/codegraph/view.d.ts +25 -0
- package/lib/types/dsh/diagnostics/cli.d.ts +76 -0
- package/lib/types/dsh/diagnostics/messages.d.ts +37 -0
- package/lib/types/dsh/diagnostics/parse.d.ts +39 -0
- package/lib/types/dsh/diagnostics/tools.d.ts +20 -0
- package/lib/types/dsh/diagnostics/view.d.ts +31 -0
- package/lib/types/dsh/guidance.d.ts +10 -4
- package/lib/types/dsh/hide.d.ts +6 -0
- package/lib/types/dsh/index.d.ts +51 -3
- package/lib/types/dsh/rg/cli.d.ts +67 -0
- package/lib/types/dsh/rg/command.d.ts +70 -0
- package/lib/types/dsh/rg/tools.d.ts +47 -0
- package/lib/types/dsh/rg/view.d.ts +81 -0
- package/lib/types/dsh/shell-view.d.ts +2 -2
- package/lib/types/dsh/tools/edit.d.ts +15 -1
- package/lib/types/dsh/tools/read-folded.d.ts +85 -0
- package/lib/types/src/domain-errors.d.ts +12 -1
- package/lib/types/src/edit-tool.d.ts +9 -1
- package/lib/types/src/mutation-engine/edit-expand.d.ts +36 -0
- package/lib/types/src/mutation-engine/edit-indent.d.ts +49 -0
- package/lib/types/src/mutation-engine/edit-request.d.ts +4 -0
- package/lib/types/src/mutation-engine/types.d.ts +57 -0
- package/lib/types/src/payload-contract.d.ts +4 -0
- package/lib/types/src/read-expansion/fold-skeleton.d.ts +32 -0
- package/lib/types/src/read-expansion/span-expansion.d.ts +26 -0
- package/package.json +1 -1
- package/prompts/codegraph-guidelines.md +8 -0
- package/prompts/diagnostics-guidelines.md +8 -0
- package/prompts/edit-guidelines.md +3 -1
- package/prompts/edit.md +3 -1
- package/prompts/read-description.md +1 -1
- package/prompts/read-guidelines.md +3 -1
- package/prompts/rg-guidelines.md +8 -0
- package/src/domain-errors.ts +52 -1
- package/src/edit-tool.ts +12 -1
- package/src/mutation-engine/edit-expand.ts +328 -0
- package/src/mutation-engine/edit-indent.ts +121 -0
- package/src/mutation-engine/edit-request.ts +4 -0
- package/src/mutation-engine/pipeline.ts +134 -48
- package/src/mutation-engine/types.ts +54 -0
- package/src/payload-contract.ts +74 -4
- package/src/read-expansion/ast-provider.ts +32 -0
- package/src/read-expansion/fold-skeleton.ts +56 -0
- package/src/read-expansion/qualified-names.ts +7 -0
- package/src/read-expansion/read-provider.ts +9 -0
- package/src/read-expansion/span-expansion.ts +26 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** The command prefix one codegraph call starts with. */
|
|
2
|
+
export interface CodegraphInvocation {
|
|
3
|
+
/** Executable to spawn. */
|
|
4
|
+
readonly command: string;
|
|
5
|
+
/** Arguments that always precede the subcommand: a bundled node runtime and its script. */
|
|
6
|
+
readonly prefixArgs: readonly string[];
|
|
7
|
+
/** The entry point that was found, for refusal text and diagnostics. */
|
|
8
|
+
readonly source: string;
|
|
9
|
+
}
|
|
10
|
+
/** A located CLI, or the reason none could be located. */
|
|
11
|
+
export type CodegraphResolution = {
|
|
12
|
+
readonly ok: true;
|
|
13
|
+
readonly invocation: CodegraphInvocation;
|
|
14
|
+
} | {
|
|
15
|
+
readonly ok: false;
|
|
16
|
+
readonly problem: string;
|
|
17
|
+
};
|
|
18
|
+
/** Inputs of {@link resolveCodegraphInvocation}; every ambient fact is injectable for tests. */
|
|
19
|
+
export interface ResolveCodegraphOptions {
|
|
20
|
+
/** The plugin's `codegraphPath` config; an empty or absent value falls back to `PATH`. */
|
|
21
|
+
readonly explicitPath?: string | undefined;
|
|
22
|
+
/** The `PATH` value to scan; defaults to `process.env.PATH`. */
|
|
23
|
+
readonly pathValue?: string | undefined;
|
|
24
|
+
/** Target platform; defaults to `process.platform`. */
|
|
25
|
+
readonly platform?: NodeJS.Platform | undefined;
|
|
26
|
+
/** Existence oracle; defaults to `existsSync`. */
|
|
27
|
+
readonly exists?: ((candidate: string) => boolean) | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Locate the codegraph CLI: an explicit `codegraphPath` wins, then the first runnable
|
|
31
|
+
* `codegraph` entry on `PATH`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveCodegraphInvocation(options?: ResolveCodegraphOptions): CodegraphResolution;
|
|
34
|
+
/** Default wall clock one codegraph query may take before it is killed. */
|
|
35
|
+
export declare const CODEGRAPH_TIMEOUT_MS = 120000;
|
|
36
|
+
/** One query's process facts. */
|
|
37
|
+
export interface CodegraphRunOptions {
|
|
38
|
+
/** Working directory the CLI runs in (the session's live directory). */
|
|
39
|
+
readonly cwd: string;
|
|
40
|
+
/** Caller cancellation; aborts the child and rejects with the abort reason. */
|
|
41
|
+
readonly signal: AbortSignal | undefined;
|
|
42
|
+
/** Wall clock budget; defaults to {@link CODEGRAPH_TIMEOUT_MS}. */
|
|
43
|
+
readonly timeoutMs?: number | undefined;
|
|
44
|
+
/** Extra environment entries layered over the host environment. */
|
|
45
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
46
|
+
}
|
|
47
|
+
/** A finished query: both streams, the exit code and whether the deadline killed it. */
|
|
48
|
+
export interface CodegraphRunResult {
|
|
49
|
+
readonly stdout: string;
|
|
50
|
+
readonly stderr: string;
|
|
51
|
+
readonly code: number | null;
|
|
52
|
+
readonly timedOut: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Run one codegraph subcommand and capture its output.
|
|
56
|
+
*
|
|
57
|
+
* The promise resolves for every outcome the caller can report — a non-zero exit,
|
|
58
|
+
* a timeout, a missing executable — and rejects only for cancellation, so a query
|
|
59
|
+
* failure never becomes an opaque tool error.
|
|
60
|
+
*/
|
|
61
|
+
export declare function runCodegraph(invocation: CodegraphInvocation, args: readonly string[], options: CodegraphRunOptions): Promise<CodegraphRunResult>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FileIO } from "../contracts.js";
|
|
2
|
+
/** The index directory codegraph creates in a project root. */
|
|
3
|
+
export declare const CODEGRAPH_DIR = ".codegraph";
|
|
4
|
+
/** One project lookup: where to start, or the session directory when absent. */
|
|
5
|
+
export interface ProjectLookupRequest {
|
|
6
|
+
/** An explicit project path from the tool call; resolved against `cwd` when relative. */
|
|
7
|
+
readonly requested?: string | undefined;
|
|
8
|
+
/** The session's live working directory. */
|
|
9
|
+
readonly cwd: string;
|
|
10
|
+
/** Caller cancellation. */
|
|
11
|
+
readonly signal?: AbortSignal | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** The located index root, or the directory the walk started from when none was found. */
|
|
14
|
+
export type ProjectLookup = {
|
|
15
|
+
readonly ok: true;
|
|
16
|
+
/** Absolute directory holding the `.codegraph` index. */
|
|
17
|
+
readonly projectPath: string;
|
|
18
|
+
/** Directory levels walked up from the start; 0 means the start itself is the root. */
|
|
19
|
+
readonly distance: number;
|
|
20
|
+
} | {
|
|
21
|
+
readonly ok: false;
|
|
22
|
+
/** The absolute directory the walk started from. */ readonly searchedFrom: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Find the nearest directory this session may treat as its indexed project.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveProjectPath(io: FileIO, request: ProjectLookupRequest): Promise<ProjectLookup>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The codegraph tool surface: read-only graph queries with anchored source.
|
|
3
|
+
*
|
|
4
|
+
* Each tool maps one codegraph CLI subcommand onto the model surface. The three that
|
|
5
|
+
* print source (`explore`, `node`, `context`) route their output through
|
|
6
|
+
* {@link anchorCodegraphView}, so every returned file is served — and therefore
|
|
7
|
+
* editable — exactly like a `read` page. The rest answer a structural question with
|
|
8
|
+
* locations only, at a fraction of a source dump.
|
|
9
|
+
*
|
|
10
|
+
* WHY every expected failure is a successful text result: a missing CLI, an
|
|
11
|
+
* unindexed workspace or a stale index is something the agent can work around, and an
|
|
12
|
+
* `isError` result teaches it the toolset is broken instead (codegraph's own MCP
|
|
13
|
+
* server makes the same trade).
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-hashline-edit/codegraph/tools
|
|
16
|
+
*/
|
|
17
|
+
import { type ToolDefinition } from "@deepseek-ai/dsh-tools";
|
|
18
|
+
import type { ToolDependencies } from "../contracts.js";
|
|
19
|
+
import { type CodegraphResolution } from "./cli.js";
|
|
20
|
+
/** The tool names this module registers, in registration order. */
|
|
21
|
+
export declare const CODEGRAPH_TOOL_NAMES: readonly ["codegraph_explore", "codegraph_node", "codegraph_context", "codegraph_search", "codegraph_callers", "codegraph_callees", "codegraph_impact", "codegraph_implementations"];
|
|
22
|
+
/** What one agent install hands the tool set. */
|
|
23
|
+
export interface CodegraphToolOptions {
|
|
24
|
+
/** The located CLI, or why none was found; tools still register either way. */
|
|
25
|
+
readonly resolution: CodegraphResolution;
|
|
26
|
+
/** Per-call wall clock budget; defaults to {@link CODEGRAPH_TIMEOUT_MS}. */
|
|
27
|
+
readonly timeoutMs?: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build the whole codegraph tool set for one agent install.
|
|
31
|
+
*
|
|
32
|
+
* Registration is unconditional: a missing CLI or an unindexed workspace is reported
|
|
33
|
+
* by the tool call, not by an absent schema, so the model can ask for one `init`
|
|
34
|
+
* rather than silently falling back to grep.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildCodegraphTools(deps: ToolDependencies, options: CodegraphToolOptions): readonly ToolDefinition[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ToolDependencies } from "../contracts.js";
|
|
2
|
+
/** One view request: codegraph's text plus where its relative paths resolve. */
|
|
3
|
+
export interface CodegraphViewRequest {
|
|
4
|
+
/** The codegraph stdout to rewrite. */
|
|
5
|
+
readonly text: string;
|
|
6
|
+
/** Absolute project root the printed paths are relative to. */
|
|
7
|
+
readonly projectPath: string;
|
|
8
|
+
/** Session identity that keys the served anchors. */
|
|
9
|
+
readonly sessionKey: string;
|
|
10
|
+
/** Caller cancellation. */
|
|
11
|
+
readonly signal: AbortSignal | undefined;
|
|
12
|
+
/** Execution passed through to the host observation channel. */
|
|
13
|
+
readonly exec: object;
|
|
14
|
+
}
|
|
15
|
+
/** The rewritten text plus the files whose lines were served. */
|
|
16
|
+
export interface CodegraphViewResult {
|
|
17
|
+
readonly text: string;
|
|
18
|
+
/** Absolute paths whose rows were served, ascending. */
|
|
19
|
+
readonly servedFiles: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Serve every source region a codegraph query printed and rewrite it into anchored
|
|
23
|
+
* rows. Regions that do not verify are copied through byte for byte.
|
|
24
|
+
*/
|
|
25
|
+
export declare function anchorCodegraphView(deps: ToolDependencies, request: CodegraphViewRequest): Promise<CodegraphViewResult>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Every toolchain this surface can run, in enum order. */
|
|
2
|
+
export declare const DIAGNOSTICS_TOOL_NAMES: readonly ["cargo-check", "cargo-clippy", "tsc"];
|
|
3
|
+
/** One supported toolchain identifier. */
|
|
4
|
+
export type DiagnosticsTool = (typeof DIAGNOSTICS_TOOL_NAMES)[number];
|
|
5
|
+
/** One located executable plus the arguments that always precede the toolchain arguments. */
|
|
6
|
+
export interface DiagnosticsInvocation {
|
|
7
|
+
/** Executable to spawn. */
|
|
8
|
+
readonly command: string;
|
|
9
|
+
/** Arguments that always precede the toolchain arguments: a node runtime and its script. */
|
|
10
|
+
readonly prefixArgs: readonly string[];
|
|
11
|
+
/** The entry point that was found, for refusal text and diagnostics. */
|
|
12
|
+
readonly source: string;
|
|
13
|
+
}
|
|
14
|
+
/** A located toolchain, or the reason none could be located. */
|
|
15
|
+
export type DiagnosticsResolution = {
|
|
16
|
+
readonly ok: true;
|
|
17
|
+
readonly invocation: DiagnosticsInvocation;
|
|
18
|
+
} | {
|
|
19
|
+
readonly ok: false;
|
|
20
|
+
readonly problem: string;
|
|
21
|
+
};
|
|
22
|
+
/** Inputs of the resolvers; every ambient fact is injectable for tests. */
|
|
23
|
+
export interface ResolveToolchainOptions {
|
|
24
|
+
/** The `PATH` value to scan; defaults to `process.env.PATH`. */
|
|
25
|
+
readonly pathValue?: string | undefined;
|
|
26
|
+
/** Target platform; defaults to `process.platform`. */
|
|
27
|
+
readonly platform?: NodeJS.Platform | undefined;
|
|
28
|
+
/** Existence oracle; defaults to `existsSync`. */
|
|
29
|
+
readonly exists?: ((candidate: string) => boolean) | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** True for this surface's toolchain identifiers. */
|
|
32
|
+
export declare function isDiagnosticsTool(value: unknown): value is DiagnosticsTool;
|
|
33
|
+
/** The toolchain arguments one call adds to its located executable. */
|
|
34
|
+
export declare function planDiagnosticsArgs(tool: DiagnosticsTool): readonly string[];
|
|
35
|
+
/**
|
|
36
|
+
* Locate the Rust `cargo` executable on `PATH`.
|
|
37
|
+
*
|
|
38
|
+
* A `.cmd`/`.bat` shim is refused rather than run through a shell (a shell would re-quote
|
|
39
|
+
* the arguments this plugin passes), unless a real `cargo.exe` sits in the same directory —
|
|
40
|
+
* the layout a rustup install has.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveCargoInvocation(options?: ResolveToolchainOptions): DiagnosticsResolution;
|
|
43
|
+
/**
|
|
44
|
+
* Locate the TypeScript compiler: the project's own `node_modules/typescript/bin/tsc`
|
|
45
|
+
* first (it is the version the project compiles with), then a `tsc` on `PATH`, whose
|
|
46
|
+
* npm shim resolves to the same script so no shell is involved.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveTscInvocation(cwd: string, options?: ResolveToolchainOptions): DiagnosticsResolution;
|
|
49
|
+
/** Default wall clock one toolchain run may take before it is killed. */
|
|
50
|
+
export declare const DIAGNOSTICS_TIMEOUT_MS = 120000;
|
|
51
|
+
/** One toolchain run's process facts. */
|
|
52
|
+
export interface DiagnosticsRunOptions {
|
|
53
|
+
/** Working directory the toolchain runs in (the project directory). */
|
|
54
|
+
readonly cwd: string;
|
|
55
|
+
/** Caller cancellation; aborts the child and rejects with the abort reason. */
|
|
56
|
+
readonly signal: AbortSignal | undefined;
|
|
57
|
+
/** Wall clock budget; defaults to {@link DIAGNOSTICS_TIMEOUT_MS}. */
|
|
58
|
+
readonly timeoutMs?: number | undefined;
|
|
59
|
+
/** Extra environment entries layered over the host environment. */
|
|
60
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
61
|
+
}
|
|
62
|
+
/** A finished run: both streams, the exit code and whether the deadline killed it. */
|
|
63
|
+
export interface DiagnosticsRunResult {
|
|
64
|
+
readonly stdout: string;
|
|
65
|
+
readonly stderr: string;
|
|
66
|
+
readonly code: number | null;
|
|
67
|
+
readonly timedOut: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Run one toolchain command and capture its output.
|
|
71
|
+
*
|
|
72
|
+
* The promise resolves for every outcome the caller can report — a non-zero exit, a
|
|
73
|
+
* timeout, a missing executable — and rejects only for cancellation, so a build failure
|
|
74
|
+
* never becomes an opaque tool error.
|
|
75
|
+
*/
|
|
76
|
+
export declare function runDiagnosticsCommand(invocation: DiagnosticsInvocation, args: readonly string[], options: DiagnosticsRunOptions): Promise<DiagnosticsRunResult>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The diagnostics surface's model-facing text: summary, notes and the guidance every
|
|
3
|
+
* expected failure returns.
|
|
4
|
+
*
|
|
5
|
+
* WHY every expected failure is text rather than an error: a missing toolchain, a missing
|
|
6
|
+
* tsconfig, a timeout or unparseable output is a normal state of an optional surface, and
|
|
7
|
+
* an `isError` result would teach a model the toolset is broken instead of what to change.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-hashline-edit/diagnostics/messages
|
|
10
|
+
*/
|
|
11
|
+
import type { DiagnosticsRunResult, DiagnosticsTool } from "./cli.js";
|
|
12
|
+
/** The diagnostic counts one summary line reports. */
|
|
13
|
+
export interface DiagnosticsCounts {
|
|
14
|
+
readonly total: number;
|
|
15
|
+
readonly errors: number;
|
|
16
|
+
readonly warnings: number;
|
|
17
|
+
}
|
|
18
|
+
/** The call's summary header: how much the toolchain reported, where, and from which one. */
|
|
19
|
+
export declare function summaryLine(tool: DiagnosticsTool, cwd: string, counts: DiagnosticsCounts): string;
|
|
20
|
+
/** A note saying the call reported only part of what the toolchain found. */
|
|
21
|
+
export declare function showingNote(total: number, shown: number): string;
|
|
22
|
+
/** A note naming how many diagnostics could not be served as rows. */
|
|
23
|
+
export declare function skippedNote(skipped: number): string;
|
|
24
|
+
/** The clean result: the toolchain ran and reported nothing. */
|
|
25
|
+
export declare function cleanText(tool: DiagnosticsTool, cwd: string): string;
|
|
26
|
+
/** The toolchain is not installed or not locatable. */
|
|
27
|
+
export declare function missingToolchainText(tool: DiagnosticsTool, problem: string): string;
|
|
28
|
+
/** `tsc` has no project to check: no tsconfig.json/jsconfig.json at or above the directory. */
|
|
29
|
+
export declare function missingTsconfigText(cwd: string): string;
|
|
30
|
+
/** The requested project directory is not a readable directory. */
|
|
31
|
+
export declare function unusableCwdText(cwd: string): string;
|
|
32
|
+
/** The toolchain ran past its deadline and was killed. */
|
|
33
|
+
export declare function timeoutText(tool: DiagnosticsTool, timeoutMs: number): string;
|
|
34
|
+
/** The toolchain exited, but nothing in its output parsed into a diagnostic. */
|
|
35
|
+
export declare function rawOutputText(tool: DiagnosticsTool, result: DiagnosticsRunResult): string;
|
|
36
|
+
/** The toolchain process could not be launched at all. */
|
|
37
|
+
export declare function launchFailureText(tool: DiagnosticsTool, error: unknown): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compiler-output parsers: one structured diagnostic per reported error or warning.
|
|
3
|
+
*
|
|
4
|
+
* Cargo and clippy print one JSON object per line (`reason: "compiler-message"`), so a
|
|
5
|
+
* diagnostic's level, code and primary span are read structurally. `tsc --pretty false`
|
|
6
|
+
* prints `file(line,col): error TSxxxx: message` plus indented continuation lines, so its
|
|
7
|
+
* parser consumes a matched line together with the lines indented under it.
|
|
8
|
+
*
|
|
9
|
+
* Anything that does not parse is skipped rather than guessed over, and a run whose whole
|
|
10
|
+
* output is unparsed is reported by the caller as raw guidance text.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-hashline-edit/diagnostics/parse
|
|
13
|
+
*/
|
|
14
|
+
import type { DiagnosticsTool } from "./cli.js";
|
|
15
|
+
/** One parsed compiler diagnostic, already resolved to an editable location. */
|
|
16
|
+
export interface ParsedDiagnostic {
|
|
17
|
+
/** Severity as the toolchain printed it (`error`, `warning`, `note`, …). */
|
|
18
|
+
readonly level: string;
|
|
19
|
+
/** The toolchain's own code, e.g. `E0308` (cargo) or `TS2322` (tsc), when it printed one. */
|
|
20
|
+
readonly code?: string | undefined;
|
|
21
|
+
/** The diagnostic's headline message. */
|
|
22
|
+
readonly message: string;
|
|
23
|
+
/** The file as the toolchain printed it: relative to its own root, or absolute. */
|
|
24
|
+
readonly file: string;
|
|
25
|
+
/** 1-based line the primary span starts at. */
|
|
26
|
+
readonly line: number;
|
|
27
|
+
/** 1-based column the primary span starts at. */
|
|
28
|
+
readonly column: number;
|
|
29
|
+
/** The primary span's own label, which names what is wrong at that line. */
|
|
30
|
+
readonly label?: string | undefined;
|
|
31
|
+
/** Indented continuation lines the toolchain printed under the diagnostic (tsc's detail). */
|
|
32
|
+
readonly detail?: readonly string[] | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Parse cargo/clippy's JSON-lines output. */
|
|
35
|
+
export declare function parseCargoOutput(stdout: string): readonly ParsedDiagnostic[];
|
|
36
|
+
/** Parse `tsc --pretty false` output, folding each diagnostic's indented detail into it. */
|
|
37
|
+
export declare function parseTscOutput(stdout: string): readonly ParsedDiagnostic[];
|
|
38
|
+
/** Parse one toolchain's captured stdout into structured diagnostics. */
|
|
39
|
+
export declare function parseDiagnostics(tool: DiagnosticsTool, stdout: string): readonly ParsedDiagnostic[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ToolDefinition } from "@deepseek-ai/dsh-tools";
|
|
2
|
+
import type { ToolDependencies } from "../contracts.js";
|
|
3
|
+
import { type DiagnosticsResolution, type DiagnosticsTool } from "./cli.js";
|
|
4
|
+
/** The tool name this module registers. */
|
|
5
|
+
export declare const DIAGNOSTICS_TOOL_NAME = "diagnostics";
|
|
6
|
+
/** What one agent install hands the tool. */
|
|
7
|
+
export interface DiagnosticsToolOptions {
|
|
8
|
+
/** Per-call wall clock budget; defaults to {@link DIAGNOSTICS_TIMEOUT_MS}. */
|
|
9
|
+
readonly timeoutMs?: number | undefined;
|
|
10
|
+
/** Toolchain locator; defaults to the real `PATH`/node_modules resolution. */
|
|
11
|
+
readonly resolve?: ((tool: DiagnosticsTool, cwd: string) => DiagnosticsResolution) | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build the diagnostics tool set for one agent install.
|
|
15
|
+
*
|
|
16
|
+
* Registration is unconditional once the switch is on: a missing toolchain or a project
|
|
17
|
+
* without a tsconfig is reported by the call, not by an absent schema, so the model gets
|
|
18
|
+
* guidance instead of silently falling back to re-reading build logs.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildDiagnosticsTools(deps: ToolDependencies, options?: DiagnosticsToolOptions): readonly ToolDefinition[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ToolDependencies } from "../contracts.js";
|
|
2
|
+
import type { ParsedDiagnostic } from "./parse.js";
|
|
3
|
+
/** One view request: the selected diagnostics plus where their paths resolve. */
|
|
4
|
+
export interface DiagnosticsViewRequest {
|
|
5
|
+
/** The selected diagnostics, in the order the toolchain printed them. */
|
|
6
|
+
readonly diagnostics: readonly ParsedDiagnostic[];
|
|
7
|
+
/** Absolute directory the toolchain ran in; relative printed paths resolve from it. */
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
/** Served lines above and below each diagnostic's own line. */
|
|
10
|
+
readonly contextLines: number;
|
|
11
|
+
/** Session identity that keys the served anchors. */
|
|
12
|
+
readonly sessionKey: string;
|
|
13
|
+
/** Caller cancellation. */
|
|
14
|
+
readonly signal: AbortSignal | undefined;
|
|
15
|
+
/** Execution passed through to the host observation channel. */
|
|
16
|
+
readonly exec: object;
|
|
17
|
+
}
|
|
18
|
+
/** The served blocks plus what could not be served. */
|
|
19
|
+
export interface DiagnosticsViewResult {
|
|
20
|
+
/** One block per served diagnostic: marker header, detail lines, anchored rows. */
|
|
21
|
+
readonly blocks: readonly string[];
|
|
22
|
+
/** How many diagnostics could not be served as rows. */
|
|
23
|
+
readonly skipped: number;
|
|
24
|
+
/** Absolute paths whose rows were served, ascending. */
|
|
25
|
+
readonly servedFiles: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Serve every selected diagnostic's window and render one block per served diagnostic.
|
|
29
|
+
* Diagnostics whose file cannot be served are counted, never guessed over.
|
|
30
|
+
*/
|
|
31
|
+
export declare function anchorDiagnosticsView(deps: ToolDependencies, request: DiagnosticsViewRequest): Promise<DiagnosticsViewResult>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hashline guidance sections for the dsh host layer.
|
|
3
3
|
*
|
|
4
|
-
* Prompt sections are owned here — `tool:read`, `tool:
|
|
5
|
-
* and `tool:edit` — because the hashline tools
|
|
4
|
+
* Prompt sections are owned here — `tool:read`, `tool:rg`, `tool:codegraph`, `tool:diagnostics`,
|
|
5
|
+
* `tool:write`, `tool:apply_patch` and `tool:edit` — because the hashline tools
|
|
6
6
|
* must bring their own brief. The compiled default text IS the
|
|
7
7
|
* pi-side guidance (`prompts/*.md`) loaded through `src/prompts.ts`, so the dsh
|
|
8
8
|
* and pi hosts cannot drift about the tool contract.
|
|
@@ -23,11 +23,11 @@ export interface GuidanceSection {
|
|
|
23
23
|
/** Order used when the harness registry names no slot for this section. */
|
|
24
24
|
readonly defaultOrder: number;
|
|
25
25
|
/** The `systemPrompt.getSectionOrder` slot this section shadows, when one exists. */
|
|
26
|
-
readonly orderName?: "TOOL_READ" | "TOOL_WRITE" | "TOOL_EDIT" | "TOOL_APPLY_PATCH";
|
|
26
|
+
readonly orderName?: "TOOL_READ" | "TOOL_WRITE" | "TOOL_EDIT" | "TOOL_APPLY_PATCH" | "TOOL_GREP";
|
|
27
27
|
/** The compiled default text. */
|
|
28
28
|
renderDefault(): string;
|
|
29
29
|
}
|
|
30
|
-
/** The
|
|
30
|
+
/** The seven sections, in default-order sequence. */
|
|
31
31
|
export declare const GUIDANCE_SECTIONS: readonly GuidanceSection[];
|
|
32
32
|
/** Render the compiled default text for one section. */
|
|
33
33
|
export declare function renderSectionDefault(name: string): string;
|
|
@@ -36,6 +36,12 @@ export interface GuidanceToggles {
|
|
|
36
36
|
readonly read: boolean;
|
|
37
37
|
readonly applyPatch: boolean;
|
|
38
38
|
readonly edit: boolean;
|
|
39
|
+
/** Whether the system-`rg` search tool registered; absent keeps its section dark. */
|
|
40
|
+
readonly rg?: boolean;
|
|
41
|
+
/** Whether the codegraph tool set registered; absent keeps its section dark. */
|
|
42
|
+
readonly codegraph?: boolean;
|
|
43
|
+
/** Whether the diagnostics tool registered; absent keeps its section dark. */
|
|
44
|
+
readonly diagnostics?: boolean;
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
47
|
* Register the enabled guidance sections with STATIC bundled text.
|
package/lib/types/dsh/hide.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ export interface NativeHideConfig {
|
|
|
8
8
|
readonly hideNativeWriteTools?: BooleanSource;
|
|
9
9
|
/** Extra global tool names to hide alongside the native set. */
|
|
10
10
|
readonly hiddenToolNames?: readonly string[];
|
|
11
|
+
/**
|
|
12
|
+
* The denial text for one hidden name when the default editor wording would be wrong.
|
|
13
|
+
* The caller that configured the name is the only party that knows what replaces it;
|
|
14
|
+
* this layer only knows the names. Returning `undefined` keeps the editor wording.
|
|
15
|
+
*/
|
|
16
|
+
readonly denialText?: ((name: string) => string | undefined) | undefined;
|
|
11
17
|
/** Guidance sections to empty because this plugin provides no such tool. */
|
|
12
18
|
readonly guidanceToClear?: readonly string[];
|
|
13
19
|
/** The Agent scope key used for the agent-view probe; absent keeps the global probe. */
|
package/lib/types/dsh/index.d.ts
CHANGED
|
@@ -31,16 +31,26 @@ export declare const inject: string[];
|
|
|
31
31
|
/**
|
|
32
32
|
* The row's editable config schema. Exporting `Config` is what makes the host
|
|
33
33
|
* expose `dsh-hashline-edit#dsh-hashline-edit` as a writable settings namespace,
|
|
34
|
-
* so the Plugins-page card can render its
|
|
34
|
+
* so the Plugins-page card can render its live switches and write them back.
|
|
35
35
|
*/
|
|
36
36
|
export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
|
|
37
37
|
read: Schema<boolean, boolean, "volatile-defined">;
|
|
38
38
|
applyPatch: Schema<boolean, boolean, "volatile-defined">;
|
|
39
39
|
edit: Schema<boolean, boolean, "volatile-defined">;
|
|
40
|
+
codegraph: Schema<boolean, boolean, "volatile-defined">;
|
|
41
|
+
codegraphPath: Schema<string, string, "volatile-defined">;
|
|
42
|
+
diagnostics: Schema<boolean, boolean, "volatile-defined">;
|
|
43
|
+
rg: Schema<boolean, boolean, "volatile-defined">;
|
|
44
|
+
rgPath: Schema<string, string, "volatile-defined">;
|
|
40
45
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
41
46
|
read: Schema<boolean, boolean, "volatile-defined">;
|
|
42
47
|
applyPatch: Schema<boolean, boolean, "volatile-defined">;
|
|
43
48
|
edit: Schema<boolean, boolean, "volatile-defined">;
|
|
49
|
+
codegraph: Schema<boolean, boolean, "volatile-defined">;
|
|
50
|
+
codegraphPath: Schema<string, string, "volatile-defined">;
|
|
51
|
+
diagnostics: Schema<boolean, boolean, "volatile-defined">;
|
|
52
|
+
rg: Schema<boolean, boolean, "volatile-defined">;
|
|
53
|
+
rgPath: Schema<string, string, "volatile-defined">;
|
|
44
54
|
}>>, "plain">;
|
|
45
55
|
/** The plugin configuration the loader passes as the second `apply` argument. */
|
|
46
56
|
export interface PluginConfig {
|
|
@@ -64,14 +74,52 @@ export interface PluginConfig {
|
|
|
64
74
|
* mutation queue with `apply_patch`; both may be on at once.
|
|
65
75
|
*/
|
|
66
76
|
edit?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Expose the codegraph graph tools (`codegraph_explore`, `codegraph_node`,
|
|
79
|
+
* `codegraph_context`, `codegraph_search`, `codegraph_callers`, `codegraph_callees`,
|
|
80
|
+
* `codegraph_impact`, `codegraph_implementations`). Defaults to false; they need the
|
|
81
|
+
* external `codegraph` CLI (1.6.4+) and a repository indexed by it. The three source
|
|
82
|
+
* tools serve their blocks as `HASH│content` rows, so their files are editable by anchor.
|
|
83
|
+
*/
|
|
84
|
+
codegraph?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Executable used for codegraph calls. Empty uses the first `codegraph` on `PATH`;
|
|
87
|
+
* set it when the CLI lives outside `PATH` or a specific install must be pinned.
|
|
88
|
+
*/
|
|
89
|
+
codegraphPath?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Expose the `diagnostics` tool: run `cargo check`, `cargo clippy` or `tsc` over a project
|
|
92
|
+
* and return its errors and warnings as `HASH│content` rows served around each reported
|
|
93
|
+
* line, so the following `edit`/`apply_patch` needs no separate `read`. Defaults to false;
|
|
94
|
+
* it needs that toolchain on the machine, and a missing one is reported as call text.
|
|
95
|
+
*/
|
|
96
|
+
diagnostics?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Expose the `rg` tool: file-content search executed by the system `rg`, so the user's own
|
|
99
|
+
* ripgrep, its version and its config are what runs. Defaults to true; while it is on the
|
|
100
|
+
* native `grep` tool and its `tool:grep` brief are hidden in favour of this surface, and
|
|
101
|
+
* its matches come back in the native grep's value shape so the read switch's grep view
|
|
102
|
+
* still serves them as `HASH│content` rows.
|
|
103
|
+
*/
|
|
104
|
+
rg?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Executable used for `rg` calls. Empty uses the first `rg` on `PATH`; set it when
|
|
107
|
+
* ripgrep lives outside `PATH` or a specific install must be pinned.
|
|
108
|
+
*/
|
|
109
|
+
rgPath?: string;
|
|
67
110
|
}
|
|
68
|
-
/** The
|
|
111
|
+
/** The feature switches after the shipped defaults are applied. */
|
|
69
112
|
export interface ResolvedSwitches {
|
|
70
113
|
readonly read: boolean;
|
|
71
114
|
readonly applyPatch: boolean;
|
|
72
115
|
readonly edit: boolean;
|
|
116
|
+
readonly codegraph: boolean;
|
|
117
|
+
readonly codegraphPath: string;
|
|
118
|
+
readonly diagnostics: boolean;
|
|
119
|
+
readonly rg: boolean;
|
|
120
|
+
readonly rgPath: string;
|
|
73
121
|
}
|
|
74
|
-
/** Resolve the plugin's
|
|
122
|
+
/** Resolve the plugin's switches with the shipped defaults: read, apply_patch and rg on; edit, codegraph and diagnostics off. */
|
|
75
123
|
export declare function resolveSwitches(config?: PluginConfig): ResolvedSwitches;
|
|
76
124
|
/**
|
|
77
125
|
* Install the hashline toolset for one agent inside its own effect, so the
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** One located executable plus the arguments that always precede the call's own arguments. */
|
|
2
|
+
export interface RgInvocation {
|
|
3
|
+
/** Executable to spawn. */
|
|
4
|
+
readonly command: string;
|
|
5
|
+
/** Arguments that always precede the call arguments (unused today; a script layout would fill it). */
|
|
6
|
+
readonly prefixArgs: readonly string[];
|
|
7
|
+
/** The entry point that was found, for refusal text and diagnostics. */
|
|
8
|
+
readonly source: string;
|
|
9
|
+
}
|
|
10
|
+
/** A located ripgrep, or the reason none could be located. */
|
|
11
|
+
export type RgResolution = {
|
|
12
|
+
readonly ok: true;
|
|
13
|
+
readonly invocation: RgInvocation;
|
|
14
|
+
} | {
|
|
15
|
+
readonly ok: false;
|
|
16
|
+
readonly problem: string;
|
|
17
|
+
};
|
|
18
|
+
/** Inputs of {@link resolveRgInvocation}; every ambient fact is injectable for tests. */
|
|
19
|
+
export interface ResolveRgOptions {
|
|
20
|
+
/** The plugin's `rgPath` config; an empty or absent value falls back to `PATH`. */
|
|
21
|
+
readonly explicitPath?: string | undefined;
|
|
22
|
+
/** The `PATH` value to scan; defaults to `process.env.PATH`. */
|
|
23
|
+
readonly pathValue?: string | undefined;
|
|
24
|
+
/** Target platform; defaults to `process.platform`. */
|
|
25
|
+
readonly platform?: NodeJS.Platform | undefined;
|
|
26
|
+
/** Existence oracle; defaults to `existsSync`. */
|
|
27
|
+
readonly exists?: ((candidate: string) => boolean) | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Locate the ripgrep executable: an explicit `rgPath` wins, then the first `rg` entry on `PATH`.
|
|
31
|
+
*
|
|
32
|
+
* A `.cmd`/`.bat` shim is refused rather than run through a shell — a shell would re-quote the
|
|
33
|
+
* pattern and target this plugin passes as plain argv.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveRgInvocation(options?: ResolveRgOptions): RgResolution;
|
|
36
|
+
/** Default wall clock one search may take before it is killed. */
|
|
37
|
+
export declare const RG_TIMEOUT_MS = 30000;
|
|
38
|
+
/** One search's process facts. */
|
|
39
|
+
export interface RgRunOptions {
|
|
40
|
+
/** Working directory the search runs in (the live session directory). */
|
|
41
|
+
readonly cwd: string;
|
|
42
|
+
/** Caller cancellation; aborts the child and rejects with the abort reason. */
|
|
43
|
+
readonly signal: AbortSignal | undefined;
|
|
44
|
+
/** Wall clock budget; defaults to {@link RG_TIMEOUT_MS}. */
|
|
45
|
+
readonly timeoutMs?: number | undefined;
|
|
46
|
+
/** Extra environment entries layered over the host environment. */
|
|
47
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
48
|
+
}
|
|
49
|
+
/** A finished search: both streams, the exit code, and how it ended. */
|
|
50
|
+
export interface RgRunResult {
|
|
51
|
+
readonly stdout: string;
|
|
52
|
+
readonly stderr: string;
|
|
53
|
+
/** Ripgrep's exit code: `0` matches found, `1` none, `2` an error (bad pattern, unreadable target). */
|
|
54
|
+
readonly code: number | null;
|
|
55
|
+
/** Whether the deadline killed it. */
|
|
56
|
+
readonly timedOut: boolean;
|
|
57
|
+
/** Whether the capture ceiling was reached (the stdout is then incomplete). */
|
|
58
|
+
readonly overflow: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Run one ripgrep command and capture its output.
|
|
62
|
+
*
|
|
63
|
+
* The promise resolves for every outcome the caller can report — a non-zero exit, a timeout, a
|
|
64
|
+
* capture overflow — and rejects only for cancellation, so a failed search never becomes an
|
|
65
|
+
* opaque tool error.
|
|
66
|
+
*/
|
|
67
|
+
export declare function runRg(invocation: RgInvocation, args: readonly string[], options: RgRunOptions): Promise<RgRunResult>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** One matched line as ripgrep reported it, before display-path normalization. */
|
|
2
|
+
export interface RgMatch {
|
|
3
|
+
/** The path ripgrep printed for the match (relative to its working directory, or as given). */
|
|
4
|
+
readonly path: string;
|
|
5
|
+
/** 1-based line number of the match inside that file. */
|
|
6
|
+
readonly lineNumber: number;
|
|
7
|
+
/** The matched line's text, without its line terminator. */
|
|
8
|
+
readonly line: string;
|
|
9
|
+
}
|
|
10
|
+
/** Validated `grep` arguments. */
|
|
11
|
+
export interface RgInput {
|
|
12
|
+
/** The ripgrep regular expression (or literal text when {@link RgInput.fixedStrings}). */
|
|
13
|
+
readonly pattern: string;
|
|
14
|
+
/** File or directory to search; absent searches the working directory. */
|
|
15
|
+
readonly path?: string;
|
|
16
|
+
/** One positive glob filter for which files to search. */
|
|
17
|
+
readonly include?: string;
|
|
18
|
+
/** Force a case-insensitive search (`-i`); absent keeps ripgrep's smart case. */
|
|
19
|
+
readonly ignoreCase?: boolean;
|
|
20
|
+
/** Treat the pattern as literal text (`-F`) instead of a regular expression. */
|
|
21
|
+
readonly fixedStrings?: boolean;
|
|
22
|
+
/** Only match whole words (`-w`). */
|
|
23
|
+
readonly wordMatch?: boolean;
|
|
24
|
+
/** Also search hidden files and directories (`--hidden`). */
|
|
25
|
+
readonly hidden?: boolean;
|
|
26
|
+
/** Ignore `.gitignore`/`.ignore` rules and search every file (`--no-ignore`). */
|
|
27
|
+
readonly noIgnore?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate the raw tool arguments into {@link RgInput}.
|
|
31
|
+
*
|
|
32
|
+
* The parameter schema already refuses a wrong type; this admission keeps the contract explicit for
|
|
33
|
+
* a direct (nested `run_code`) call and for the value constraints the schema cannot express: a
|
|
34
|
+
* non-EMPTY `pattern` (whitespace is a legitimate regex), a non-blank `path` when given, and a
|
|
35
|
+
* single positive `include` glob. An exact empty `include` is treated as omitted.
|
|
36
|
+
*
|
|
37
|
+
* @param raw - the tool call's raw arguments.
|
|
38
|
+
* @returns the accepted input.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseRgArgs(raw: unknown): RgInput;
|
|
41
|
+
/**
|
|
42
|
+
* Build the fixed `rg --json` argv for one `grep` call.
|
|
43
|
+
*
|
|
44
|
+
* Every model-controlled value is a plain argv element — no shell layer exists, so no quoting
|
|
45
|
+
* applies. The pattern rides in `--regexp=` form and the target behind `--`, so a leading-dash
|
|
46
|
+
* value can never be parsed as a flag.
|
|
47
|
+
*
|
|
48
|
+
* @param input - the validated arguments.
|
|
49
|
+
* @returns the complete ripgrep argument vector (excluding the binary itself).
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildRgCommand(input: RgInput): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Parse complete `rg --json` stdout into flat matches, in output order (ripgrep emits one file's
|
|
54
|
+
* matches contiguously and in ascending line order, which the grep view relies on).
|
|
55
|
+
*
|
|
56
|
+
* @param stdout - the complete raw `rg --json` stdout.
|
|
57
|
+
* @returns the flat matches; empty for output with no match records.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseRgOutput(stdout: string): RgMatch[];
|
|
60
|
+
/**
|
|
61
|
+
* The model-facing path of one match: `./` stripped, and an absolute path inside the working
|
|
62
|
+
* directory shown relative to it.
|
|
63
|
+
*
|
|
64
|
+
* WHY: ripgrep echoes the operand it was given, so `grep path: "."` would otherwise print
|
|
65
|
+
* `./src/a.ts` and an absolute target would print the whole drive path. Neither is wrong, but the
|
|
66
|
+
* grep view resolves matches back against the working directory and the model reads the shorter
|
|
67
|
+
* form; a path outside the directory is kept absolute because relativizing it would invent `..`
|
|
68
|
+
* segments the search never named.
|
|
69
|
+
*/
|
|
70
|
+
export declare function displayPath(rawPath: string, cwd: string): string;
|