dsh-hashline-edit 0.4.3 → 0.5.1
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/CHANGELOG.md +345 -0
- package/README.md +58 -5
- package/cordis.patch.yml +11 -1
- package/grammars/go-0.25.0-9504573f352b20be.wasm +0 -0
- package/grammars/java-0.23.5-4fdeac4ca6ca089f.wasm +0 -0
- package/grammars/python-0.25.0-16108b50df4ee9a3.wasm +0 -0
- package/grammars/rust-0.24.2-24c89bd9252255e4.wasm +0 -0
- package/grammars/tsx-0.23.2-79e5da75ea62855a.wasm +0 -0
- package/grammars/typescript-0.23.2-778025db5a8be0e7.wasm +0 -0
- package/grammars/vue-0.1.0-193c01119229352f.wasm +0 -0
- package/lib/client.js +13 -3
- package/lib/index.js +2345 -75
- 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 +7 -3
- package/lib/types/dsh/index.d.ts +32 -3
- package/lib/types/dsh/syntax-health.d.ts +60 -0
- package/lib/types/dsh/tools/edit.d.ts +15 -1
- package/lib/types/dsh/tools/output.d.ts +10 -0
- package/lib/types/dsh/tools/read-folded.d.ts +85 -0
- package/lib/types/src/bundled-assets.d.ts +13 -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 +8 -0
- package/lib/types/src/mutation-engine/types.d.ts +57 -0
- package/lib/types/src/payload-contract.d.ts +8 -0
- package/lib/types/src/read-expansion/fold-skeleton.d.ts +32 -0
- package/lib/types/src/read-expansion/grammar-manifest.d.ts +3 -1
- package/lib/types/src/read-expansion/grammar-runtime.d.ts +1 -1
- package/lib/types/src/read-expansion/span-expansion.d.ts +26 -0
- package/package.json +21 -23
- package/prompts/codegraph-guidelines.md +8 -0
- package/prompts/diagnostics-guidelines.md +8 -0
- package/prompts/edit-guidelines.md +6 -2
- package/prompts/edit.md +3 -1
- package/prompts/read-description.md +1 -1
- package/prompts/read-guidelines.md +3 -1
- package/src/bundled-assets.ts +23 -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 +8 -1
- package/src/mutation-engine/pipeline.ts +150 -48
- package/src/mutation-engine/types.ts +54 -0
- package/src/payload-contract.ts +165 -19
- package/src/read-expansion/ast-provider.ts +32 -0
- package/src/read-expansion/fold-skeleton.ts +56 -0
- package/src/read-expansion/grammar-cache.ts +33 -1
- package/src/read-expansion/grammar-manifest.ts +3 -1
- package/src/read-expansion/grammar-runtime.ts +1 -1
- 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: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.
|
|
@@ -27,7 +27,7 @@ export interface GuidanceSection {
|
|
|
27
27
|
/** The compiled default text. */
|
|
28
28
|
renderDefault(): string;
|
|
29
29
|
}
|
|
30
|
-
/** The
|
|
30
|
+
/** The six 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,10 @@ export interface GuidanceToggles {
|
|
|
36
36
|
readonly read: boolean;
|
|
37
37
|
readonly applyPatch: boolean;
|
|
38
38
|
readonly edit: boolean;
|
|
39
|
+
/** Whether the codegraph tool set registered; absent keeps its section dark. */
|
|
40
|
+
readonly codegraph?: boolean;
|
|
41
|
+
/** Whether the diagnostics tool registered; absent keeps its section dark. */
|
|
42
|
+
readonly diagnostics?: boolean;
|
|
39
43
|
}
|
|
40
44
|
/**
|
|
41
45
|
* Register the enabled guidance sections with STATIC bundled text.
|
package/lib/types/dsh/index.d.ts
CHANGED
|
@@ -31,16 +31,22 @@ 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">;
|
|
40
43
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
41
44
|
read: Schema<boolean, boolean, "volatile-defined">;
|
|
42
45
|
applyPatch: Schema<boolean, boolean, "volatile-defined">;
|
|
43
46
|
edit: Schema<boolean, boolean, "volatile-defined">;
|
|
47
|
+
codegraph: Schema<boolean, boolean, "volatile-defined">;
|
|
48
|
+
codegraphPath: Schema<string, string, "volatile-defined">;
|
|
49
|
+
diagnostics: Schema<boolean, boolean, "volatile-defined">;
|
|
44
50
|
}>>, "plain">;
|
|
45
51
|
/** The plugin configuration the loader passes as the second `apply` argument. */
|
|
46
52
|
export interface PluginConfig {
|
|
@@ -64,14 +70,37 @@ export interface PluginConfig {
|
|
|
64
70
|
* mutation queue with `apply_patch`; both may be on at once.
|
|
65
71
|
*/
|
|
66
72
|
edit?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Expose the codegraph graph tools (`codegraph_explore`, `codegraph_node`,
|
|
75
|
+
* `codegraph_context`, `codegraph_search`, `codegraph_callers`, `codegraph_callees`,
|
|
76
|
+
* `codegraph_impact`, `codegraph_implementations`). Defaults to false; they need the
|
|
77
|
+
* external `codegraph` CLI (1.6.4+) and a repository indexed by it. The three source
|
|
78
|
+
* tools serve their blocks as `HASH│content` rows, so their files are editable by anchor.
|
|
79
|
+
*/
|
|
80
|
+
codegraph?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Executable used for codegraph calls. Empty uses the first `codegraph` on `PATH`;
|
|
83
|
+
* set it when the CLI lives outside `PATH` or a specific install must be pinned.
|
|
84
|
+
*/
|
|
85
|
+
codegraphPath?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Expose the `diagnostics` tool: run `cargo check`, `cargo clippy` or `tsc` over a project
|
|
88
|
+
* and return its errors and warnings as `HASH│content` rows served around each reported
|
|
89
|
+
* line, so the following `edit`/`apply_patch` needs no separate `read`. Defaults to false;
|
|
90
|
+
* it needs that toolchain on the machine, and a missing one is reported as call text.
|
|
91
|
+
*/
|
|
92
|
+
diagnostics?: boolean;
|
|
67
93
|
}
|
|
68
|
-
/** The
|
|
94
|
+
/** The feature switches after the shipped defaults are applied. */
|
|
69
95
|
export interface ResolvedSwitches {
|
|
70
96
|
readonly read: boolean;
|
|
71
97
|
readonly applyPatch: boolean;
|
|
72
98
|
readonly edit: boolean;
|
|
99
|
+
readonly codegraph: boolean;
|
|
100
|
+
readonly codegraphPath: string;
|
|
101
|
+
readonly diagnostics: boolean;
|
|
73
102
|
}
|
|
74
|
-
/** Resolve the plugin's
|
|
103
|
+
/** Resolve the plugin's switches with the shipped defaults: read and apply_patch on, edit, codegraph and diagnostics off. */
|
|
75
104
|
export declare function resolveSwitches(config?: PluginConfig): ResolvedSwitches;
|
|
76
105
|
/**
|
|
77
106
|
* Install the hashline toolset for one agent inside its own effect, so the
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-edit syntax health: parse the committed text and report only NEWLY introduced errors.
|
|
3
|
+
*
|
|
4
|
+
* WHY this exists: a hash-anchored range edit can match both anchors, commit, and still swallow
|
|
5
|
+
* or leave one extra brace — an off-by-one at a boundary. Nothing in the anchor machinery can see
|
|
6
|
+
* that, and waiting for a compiler wastes a whole tool round. A tree parse is 1-3 ms and turns that
|
|
7
|
+
* silently-wrong case into a same-call warning the model can self-heal from.
|
|
8
|
+
*
|
|
9
|
+
* The signal is deliberately narrow. It compares the error-node count of the file BEFORE the edit
|
|
10
|
+
* with the count AFTER it and speaks only when the edit ADDED errors to a previously clean file.
|
|
11
|
+
* A file that arrives broken stays silent (no baseline to attribute a new error to) and a clean
|
|
12
|
+
* file stays clean. No grammar, no wasm host, or an abort all mean say nothing — this seam never
|
|
13
|
+
* blocks, never fails a call, and never invents a diagnosis.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-hashline-edit/syntax-health
|
|
16
|
+
*/
|
|
17
|
+
import type { FileIO } from "./contracts.js";
|
|
18
|
+
import type { GrammarHandle } from "../src/read-expansion/ast-span.js";
|
|
19
|
+
/** The grammar key for one path, or undefined when no grammar covers its extension. */
|
|
20
|
+
export declare function grammarForPath(path: string): string | undefined;
|
|
21
|
+
export interface SyntaxHealthOptions {
|
|
22
|
+
/** Override the grammar lookup (tests). */
|
|
23
|
+
readonly grammarFor?: (path: string) => Promise<GrammarHandle | undefined>;
|
|
24
|
+
/** Abort signal from the hosting tool call. */
|
|
25
|
+
readonly signal?: AbortSignal | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Diagnose one committed edit.
|
|
29
|
+
*
|
|
30
|
+
* @returns a one-line model-facing warning when this edit INTRODUCED parse errors, else undefined.
|
|
31
|
+
* Never throws: every internal failure is no signal.
|
|
32
|
+
*/
|
|
33
|
+
export declare function syntaxWarningForEdit(path: string, before: string, after: string, options?: SyntaxHealthOptions): Promise<string | undefined>;
|
|
34
|
+
/** A pre-edit snapshot: the absolute path and the text the file held before the write. */
|
|
35
|
+
export interface SyntaxBaseline {
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly text: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Snapshot one file's text BEFORE its edit commits, when a grammar covers its extension.
|
|
41
|
+
*
|
|
42
|
+
* WHY the extension gate comes first: a path no grammar parses never needs a read, so an edit to a
|
|
43
|
+
* lockfile or a config pays nothing for this seam.
|
|
44
|
+
* @param io - the call's filesystem seam.
|
|
45
|
+
* @param path - the absolute path the edit will write.
|
|
46
|
+
* @param signal - caller cancellation.
|
|
47
|
+
* @returns the baseline, or undefined when the path is unsupported, unreadable or already aborted.
|
|
48
|
+
*/
|
|
49
|
+
export declare function readSyntaxBaseline(io: Pick<FileIO, "read">, path: string, signal?: AbortSignal): Promise<SyntaxBaseline | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Re-read the committed file and diagnose the edit against its baseline.
|
|
52
|
+
*
|
|
53
|
+
* Split from {@link syntaxWarningForEdit} so the pre-edit read happens before the write and the
|
|
54
|
+
* post-edit read happens after it: one function cannot straddle the mutation it measures.
|
|
55
|
+
* @param io - the call's filesystem seam.
|
|
56
|
+
* @param baseline - the snapshot {@link readSyntaxBaseline} took before the write.
|
|
57
|
+
* @param options - grammar override (tests) and caller cancellation.
|
|
58
|
+
* @returns the model-facing warning, or undefined when the edit introduced no parse error.
|
|
59
|
+
*/
|
|
60
|
+
export declare function syntaxWarningAfterEdit(io: Pick<FileIO, "read">, baseline: SyntaxBaseline, options?: SyntaxHealthOptions): Promise<string | undefined>;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import type { ToolDefinition } from "@deepseek-ai/dsh-tools";
|
|
2
2
|
import type { ToolDependencies } from "../contracts.js";
|
|
3
|
-
|
|
3
|
+
import type { SpanProvider } from "../../src/read-expansion/span-expansion.js";
|
|
4
|
+
/**
|
|
5
|
+
* Optional seams of the dsh edit adapter; `spanProvider` overrides the AST span provider an
|
|
6
|
+
* `expand: "item"` payload reads (ADR-0031).
|
|
7
|
+
*/
|
|
8
|
+
export interface EditToolOptions {
|
|
9
|
+
spanProvider?: SpanProvider;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Build the dsh `edit` tool for one agent install.
|
|
13
|
+
* @param deps - the host seams this tool may touch; `sandbox` advertises and resolves escalation.
|
|
14
|
+
* @param options - optional span provider override for `expand: "item"`.
|
|
15
|
+
* @returns a registry-ready dsh tool definition named `edit`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildEditTool(deps: ToolDependencies, options?: EditToolOptions): ToolDefinition;
|
|
@@ -106,4 +106,14 @@ export declare function diffResultView(title: string, result: {
|
|
|
106
106
|
* @returns the same object, typed as the declared output.
|
|
107
107
|
*/
|
|
108
108
|
export declare function toCanonicalValue(result: ToolResultValue): ToolResultOutput;
|
|
109
|
+
/**
|
|
110
|
+
* Append one model-facing warning to a settled result.
|
|
111
|
+
*
|
|
112
|
+
* The warning reaches both channels the envelope already exposes: the text the model reads and the
|
|
113
|
+
* `warnings` array a presenter and the metrics recorder inspect. Every other byte is preserved.
|
|
114
|
+
* @param result - the canonical value a tool is about to return.
|
|
115
|
+
* @param warning - the line to append, or undefined to return the result untouched.
|
|
116
|
+
* @returns the same result when no warning applies; a copy carrying the warning otherwise.
|
|
117
|
+
*/
|
|
118
|
+
export declare function withWarning(result: ToolResultOutput, warning: string | undefined): ToolResultOutput;
|
|
109
119
|
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The folded read mode: a large file's structural skeleton instead of every line.
|
|
3
|
+
*
|
|
4
|
+
* One output row per retained syntax item, in file order, showing the item's own verbatim opening
|
|
5
|
+
* line and the item's range anchors — `HASH│line` for a single-line item, `HASH1..HASH2│line` for a
|
|
6
|
+
* multi-line one — so a whole item is one anchored range a following edit can replace or delete
|
|
7
|
+
* without ever finding its closing brace. A run of lines that belongs to no retained item becomes
|
|
8
|
+
* ONE elided-gap row carrying the run's own first..last anchors and its exact line count, so the
|
|
9
|
+
* model can see what it did not see.
|
|
10
|
+
*
|
|
11
|
+
* WHY the rows reuse the served seam: both anchors of a range row must be the real served anchors of
|
|
12
|
+
* the item's first and last line, leased to this session, or the range edit this mode exists for
|
|
13
|
+
* fails with `E_UNKNOWN_ANCHOR`. This module owns the layout; the caller serves the lines through
|
|
14
|
+
* the read tool's own serve path and hands back each line's anchor and text.
|
|
15
|
+
*
|
|
16
|
+
* Fail open: a file with no grammar, an unparsable tree or an unanchorable skeleton is not an error.
|
|
17
|
+
* The caller renders the exact served page with one note row instead — never a guessed row.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-hashline-edit/tools/read-folded
|
|
20
|
+
*/
|
|
21
|
+
import { type AdmittedRequest, type RawReadParams } from "../../src/file-content/admission.js";
|
|
22
|
+
import type { SkeletonItem, SpanDecline } from "../../src/read-expansion/span-expansion.js";
|
|
23
|
+
/** One anchored line the caller served for this page. */
|
|
24
|
+
interface FoldedLine {
|
|
25
|
+
/** 1-based line number the anchor addresses. */
|
|
26
|
+
readonly line: number;
|
|
27
|
+
/** The line's served anchor. */
|
|
28
|
+
readonly hash: string;
|
|
29
|
+
/** The line's decoded text, without the anchor prefix. */
|
|
30
|
+
readonly text: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Serves exactly these 1-based lines and returns each one's anchor and text. Structurally the read
|
|
34
|
+
* tool's own served-row shape, redeclared here so the layout module does not import the tool that
|
|
35
|
+
* imports it.
|
|
36
|
+
*/
|
|
37
|
+
type FoldedServe = (lineNumbers: readonly number[]) => Promise<readonly FoldedLine[]>;
|
|
38
|
+
/** A folded read's admitted payload: the plain request under it, and the depth it reveals. */
|
|
39
|
+
export interface FoldedRead {
|
|
40
|
+
readonly request: AdmittedRequest;
|
|
41
|
+
readonly foldDepth: number;
|
|
42
|
+
}
|
|
43
|
+
/** Everything one folded page needs from the read it belongs to. */
|
|
44
|
+
export interface FoldedPageInput {
|
|
45
|
+
/** The file as the caller named it; the page header labels it with this spelling. */
|
|
46
|
+
readonly file: string;
|
|
47
|
+
/** The file's total visible lines — never the retained count. */
|
|
48
|
+
readonly totalLines: number;
|
|
49
|
+
readonly foldDepth: number;
|
|
50
|
+
readonly items: readonly SkeletonItem[];
|
|
51
|
+
readonly serve: FoldedServe;
|
|
52
|
+
}
|
|
53
|
+
/** The rendered skeleton text: the page header followed by one row per region. */
|
|
54
|
+
export interface FoldedPage {
|
|
55
|
+
readonly text: string;
|
|
56
|
+
}
|
|
57
|
+
/** Why a folded read fell open to the served page. */
|
|
58
|
+
export type FoldedUnavailable = SpanDecline["refusal"] | "provider_error" | "unanchored" | "empty_file";
|
|
59
|
+
/**
|
|
60
|
+
* Admits `mode: "folded"`: the depth it reveals, plus the plain request underneath it.
|
|
61
|
+
*
|
|
62
|
+
* WHY it strips the folded fields before handing the rest to the shared admission: the folded page
|
|
63
|
+
* never reaches `prepareFile` (whose render mode is `served`/`verbatim`), so the fields that shape
|
|
64
|
+
* a window page are refused here rather than silently ignored — a folded read always covers the
|
|
65
|
+
* whole file. An out-of-range depth and a depth without the mode both fail closed.
|
|
66
|
+
*
|
|
67
|
+
* @param params - the raw tool payload.
|
|
68
|
+
* @returns the folded admission, or `undefined` when the payload is not a folded read.
|
|
69
|
+
*/
|
|
70
|
+
export declare function admitFoldedRequest(params: RawReadParams): FoldedRead | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Render the skeleton page: one row per region, in file order, each carrying its anchors.
|
|
73
|
+
*
|
|
74
|
+
* @param input - the file, its total, the depth and the served lines' anchors.
|
|
75
|
+
* @returns the page, or `undefined` when a region's first or last line has no served anchor (the
|
|
76
|
+
* caller then falls open to the served page — a row with a guessed anchor is never emitted).
|
|
77
|
+
*/
|
|
78
|
+
export declare function renderFoldedPage(input: FoldedPageInput): Promise<FoldedPage | undefined>;
|
|
79
|
+
/**
|
|
80
|
+
* The one note row a folded read that fell open states first, so the model never mistakes the served
|
|
81
|
+
* page that follows for a skeleton.
|
|
82
|
+
* @param reason - why folding was unavailable.
|
|
83
|
+
*/
|
|
84
|
+
export declare function foldedUnavailableNote(reason: FoldedUnavailable): string;
|
|
85
|
+
export {};
|