@wingsbutterfly/dsh-rtk 0.1.0
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 +52 -0
- package/LICENSE +21 -0
- package/README.md +214 -0
- package/README.zh.md +211 -0
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/docs/assets/how-it-works.svg +47 -0
- package/docs/verification.md +279 -0
- package/lib/command.d.ts +41 -0
- package/lib/command.d.ts.map +1 -0
- package/lib/command.js +137 -0
- package/lib/command.js.map +1 -0
- package/lib/compact/build.d.ts +15 -0
- package/lib/compact/build.d.ts.map +1 -0
- package/lib/compact/build.js +140 -0
- package/lib/compact/build.js.map +1 -0
- package/lib/compact/detect.d.ts +22 -0
- package/lib/compact/detect.d.ts.map +1 -0
- package/lib/compact/detect.js +54 -0
- package/lib/compact/detect.js.map +1 -0
- package/lib/compact/dsh-result.d.ts +49 -0
- package/lib/compact/dsh-result.d.ts.map +1 -0
- package/lib/compact/dsh-result.js +84 -0
- package/lib/compact/dsh-result.js.map +1 -0
- package/lib/compact/git.d.ts +21 -0
- package/lib/compact/git.d.ts.map +1 -0
- package/lib/compact/git.js +197 -0
- package/lib/compact/git.js.map +1 -0
- package/lib/compact/index.d.ts +39 -0
- package/lib/compact/index.d.ts.map +1 -0
- package/lib/compact/index.js +236 -0
- package/lib/compact/index.js.map +1 -0
- package/lib/compact/linter.d.ts +12 -0
- package/lib/compact/linter.d.ts.map +1 -0
- package/lib/compact/linter.js +118 -0
- package/lib/compact/linter.js.map +1 -0
- package/lib/compact/search.d.ts +16 -0
- package/lib/compact/search.d.ts.map +1 -0
- package/lib/compact/search.js +67 -0
- package/lib/compact/search.js.map +1 -0
- package/lib/compact/source.d.ts +22 -0
- package/lib/compact/source.d.ts.map +1 -0
- package/lib/compact/source.js +224 -0
- package/lib/compact/source.js.map +1 -0
- package/lib/compact/test-output.d.ts +12 -0
- package/lib/compact/test-output.d.ts.map +1 -0
- package/lib/compact/test-output.js +168 -0
- package/lib/compact/test-output.js.map +1 -0
- package/lib/compact/text.d.ts +22 -0
- package/lib/compact/text.d.ts.map +1 -0
- package/lib/compact/text.js +87 -0
- package/lib/compact/text.js.map +1 -0
- package/lib/config.d.ts +243 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +183 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +46 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +405 -0
- package/lib/index.js.map +1 -0
- package/lib/metrics.d.ts +35 -0
- package/lib/metrics.d.ts.map +1 -0
- package/lib/metrics.js +51 -0
- package/lib/metrics.js.map +1 -0
- package/lib/rtk-executable.d.ts +51 -0
- package/lib/rtk-executable.d.ts.map +1 -0
- package/lib/rtk-executable.js +75 -0
- package/lib/rtk-executable.js.map +1 -0
- package/lib/rtk-rewrite.d.ts +88 -0
- package/lib/rtk-rewrite.d.ts.map +1 -0
- package/lib/rtk-rewrite.js +150 -0
- package/lib/rtk-rewrite.js.map +1 -0
- package/lib/runtime-guard.d.ts +31 -0
- package/lib/runtime-guard.d.ts.map +1 -0
- package/lib/runtime-guard.js +32 -0
- package/lib/runtime-guard.js.map +1 -0
- package/package.json +82 -0
- package/scripts/link-dsh.mjs +135 -0
- package/src/command.ts +174 -0
- package/src/compact/build.ts +154 -0
- package/src/compact/detect.ts +54 -0
- package/src/compact/dsh-result.ts +99 -0
- package/src/compact/git.ts +209 -0
- package/src/compact/index.ts +284 -0
- package/src/compact/linter.ts +126 -0
- package/src/compact/search.ts +73 -0
- package/src/compact/source.ts +244 -0
- package/src/compact/test-output.ts +184 -0
- package/src/compact/text.ts +86 -0
- package/src/config.ts +263 -0
- package/src/index.ts +431 -0
- package/src/metrics.ts +84 -0
- package/src/rtk-executable.ts +117 -0
- package/src/rtk-rewrite.ts +179 -0
- package/src/runtime-guard.ts +44 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command classification helpers.
|
|
3
|
+
*
|
|
4
|
+
* Every technique asks the same question first — "is this the kind of command
|
|
5
|
+
* whose output I know how to summarize?" — so the normalization lives here
|
|
6
|
+
* rather than being repeated (and drifting) per technique.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Reduce a command line to its first simple command, lower-cased.
|
|
10
|
+
*
|
|
11
|
+
* `FOO=1 git status | head` normalizes to `git status`: the assignment run is
|
|
12
|
+
* not the command, and the pipeline is not part of what the first command is.
|
|
13
|
+
* A pattern that matches the whole line would classify every prefixed or
|
|
14
|
+
* piped invocation as unknown and skip compaction entirely.
|
|
15
|
+
*
|
|
16
|
+
* @param command - raw command line, possibly multi-line.
|
|
17
|
+
* @returns the normalized first command, or `null` when there is none.
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeCommandForDetection(command: string | undefined | null): string | null;
|
|
20
|
+
/** Whether the command's first simple command matches any pattern. */
|
|
21
|
+
export declare function matchesCommandPatterns(command: string | undefined | null, patterns: readonly RegExp[]): boolean;
|
|
22
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/compact/detect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAc9F;AAED,sEAAsE;AACtE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAI/G"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command classification helpers.
|
|
3
|
+
*
|
|
4
|
+
* Every technique asks the same question first — "is this the kind of command
|
|
5
|
+
* whose output I know how to summarize?" — so the normalization lives here
|
|
6
|
+
* rather than being repeated (and drifting) per technique.
|
|
7
|
+
*/
|
|
8
|
+
const ENV_PREFIX_PATTERN = /^(?:[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|[^\s]+)\s+)*/;
|
|
9
|
+
const CHAIN_OPERATORS = ['&&', '||', ';', '|'];
|
|
10
|
+
function sliceFirstSegment(command) {
|
|
11
|
+
let cutIndex = -1;
|
|
12
|
+
for (const operator of CHAIN_OPERATORS) {
|
|
13
|
+
const index = command.indexOf(operator);
|
|
14
|
+
if (index === -1)
|
|
15
|
+
continue;
|
|
16
|
+
if (cutIndex === -1 || index < cutIndex)
|
|
17
|
+
cutIndex = index;
|
|
18
|
+
}
|
|
19
|
+
return cutIndex === -1 ? command : command.slice(0, cutIndex);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reduce a command line to its first simple command, lower-cased.
|
|
23
|
+
*
|
|
24
|
+
* `FOO=1 git status | head` normalizes to `git status`: the assignment run is
|
|
25
|
+
* not the command, and the pipeline is not part of what the first command is.
|
|
26
|
+
* A pattern that matches the whole line would classify every prefixed or
|
|
27
|
+
* piped invocation as unknown and skip compaction entirely.
|
|
28
|
+
*
|
|
29
|
+
* @param command - raw command line, possibly multi-line.
|
|
30
|
+
* @returns the normalized first command, or `null` when there is none.
|
|
31
|
+
*/
|
|
32
|
+
export function normalizeCommandForDetection(command) {
|
|
33
|
+
if (typeof command !== 'string')
|
|
34
|
+
return null;
|
|
35
|
+
const firstNonEmptyLine = command
|
|
36
|
+
.split(/\r?\n/)
|
|
37
|
+
.map((line) => line.trim())
|
|
38
|
+
.find((line) => line.length > 0);
|
|
39
|
+
if (!firstNonEmptyLine)
|
|
40
|
+
return null;
|
|
41
|
+
const withoutEnvPrefix = firstNonEmptyLine.replace(ENV_PREFIX_PATTERN, '').trim();
|
|
42
|
+
if (!withoutEnvPrefix)
|
|
43
|
+
return null;
|
|
44
|
+
const firstSegment = sliceFirstSegment(withoutEnvPrefix).trim().toLowerCase();
|
|
45
|
+
return firstSegment || null;
|
|
46
|
+
}
|
|
47
|
+
/** Whether the command's first simple command matches any pattern. */
|
|
48
|
+
export function matchesCommandPatterns(command, patterns) {
|
|
49
|
+
const normalized = normalizeCommandForDetection(command);
|
|
50
|
+
if (!normalized)
|
|
51
|
+
return false;
|
|
52
|
+
return patterns.some((pattern) => pattern.test(normalized));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/compact/detect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,kBAAkB,GAAG,4DAA4D,CAAA;AACvF,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAU,CAAA;AAEvD,SAAS,iBAAiB,CAAC,OAAe;IACxC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAA;IACjB,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACvC,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,SAAQ;QAC1B,IAAI,QAAQ,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG,QAAQ;YAAE,QAAQ,GAAG,KAAK,CAAA;IAC3D,CAAC;IACD,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AAC/D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,4BAA4B,CAAC,OAAkC;IAC7E,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAE5C,MAAM,iBAAiB,GAAG,OAAO;SAC9B,KAAK,CAAC,OAAO,CAAC;SACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAClC,IAAI,CAAC,iBAAiB;QAAE,OAAO,IAAI,CAAA;IAEnC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IACjF,IAAI,CAAC,gBAAgB;QAAE,OAAO,IAAI,CAAA;IAElC,MAAM,YAAY,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC7E,OAAO,YAAY,IAAI,IAAI,CAAA;AAC7B,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,sBAAsB,CAAC,OAAkC,EAAE,QAA2B;IACpG,MAAM,UAAU,GAAG,4BAA4B,CAAC,OAAO,CAAC,CAAA;IACxD,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAA;IAC7B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAA;AAC7D,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split and reassemble the harness `bash` result envelope.
|
|
3
|
+
*
|
|
4
|
+
* The bash tool renders a result as the stdout tail, an optional `[stderr]`
|
|
5
|
+
* section, and a run of trailing status markers (`[exit code: N]`,
|
|
6
|
+
* `[timed out after …]`, `[sandbox: …]`, …). Those markers are load-bearing:
|
|
7
|
+
* the model is told to check `[exit code: N]` on every call, and the Web UI
|
|
8
|
+
* parses that same line to draw its exit-status pill.
|
|
9
|
+
*
|
|
10
|
+
* Compaction rewrites the output body, so anything that rebuilds the text
|
|
11
|
+
* wholesale — the git, build, and test summarizers all do — would drop the
|
|
12
|
+
* markers with it. This module is the boundary that keeps that from happening:
|
|
13
|
+
* markers are lifted out before compaction and put back after, in their
|
|
14
|
+
* original order.
|
|
15
|
+
*/
|
|
16
|
+
/** The bash tool's placeholder for a command that printed nothing at all. */
|
|
17
|
+
export declare const NO_OUTPUT_PLACEHOLDER = "(no output)";
|
|
18
|
+
/** A bash result decomposed into the parts compaction must treat differently. */
|
|
19
|
+
export interface BashResultParts {
|
|
20
|
+
/** True when the tool rendered its "printed nothing" placeholder. */
|
|
21
|
+
empty: boolean;
|
|
22
|
+
/** stdout body, without the `[stderr]` section or trailing markers. */
|
|
23
|
+
stdout: string;
|
|
24
|
+
/** stderr body when the result carried a `[stderr]` section. */
|
|
25
|
+
stderr?: string;
|
|
26
|
+
/** Trailing status markers, in their original order. */
|
|
27
|
+
markers: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decompose a rendered bash result.
|
|
31
|
+
*
|
|
32
|
+
* Trailing markers are peeled from the end first, then the `[stderr]` section
|
|
33
|
+
* is split off. Only the first `[stderr]` header counts: if the command's own
|
|
34
|
+
* output contains that literal line, everything after it belongs to stderr,
|
|
35
|
+
* which is what the renderer produced.
|
|
36
|
+
*
|
|
37
|
+
* @param text - the rendered bash result.
|
|
38
|
+
* @returns the decomposed parts.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseBashResult(text: string): BashResultParts;
|
|
41
|
+
/**
|
|
42
|
+
* Reassemble a bash result from its parts.
|
|
43
|
+
*
|
|
44
|
+
* The inverse of {@link parseBashResult}, so the model-visible contract — the
|
|
45
|
+
* marker lines the agent loop and the UI both depend on — survives a
|
|
46
|
+
* compaction pass untouched.
|
|
47
|
+
*/
|
|
48
|
+
export declare function renderBashResult(parts: BashResultParts): string;
|
|
49
|
+
//# sourceMappingURL=dsh-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsh-result.d.ts","sourceRoot":"","sources":["../../src/compact/dsh-result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAaH,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,gBAAgB,CAAA;AAMlD,iFAAiF;AACjF,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,KAAK,EAAE,OAAO,CAAA;IACd,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAA;IACd,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,wDAAwD;IACxD,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAsB7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAU/D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split and reassemble the harness `bash` result envelope.
|
|
3
|
+
*
|
|
4
|
+
* The bash tool renders a result as the stdout tail, an optional `[stderr]`
|
|
5
|
+
* section, and a run of trailing status markers (`[exit code: N]`,
|
|
6
|
+
* `[timed out after …]`, `[sandbox: …]`, …). Those markers are load-bearing:
|
|
7
|
+
* the model is told to check `[exit code: N]` on every call, and the Web UI
|
|
8
|
+
* parses that same line to draw its exit-status pill.
|
|
9
|
+
*
|
|
10
|
+
* Compaction rewrites the output body, so anything that rebuilds the text
|
|
11
|
+
* wholesale — the git, build, and test summarizers all do — would drop the
|
|
12
|
+
* markers with it. This module is the boundary that keeps that from happening:
|
|
13
|
+
* markers are lifted out before compaction and put back after, in their
|
|
14
|
+
* original order.
|
|
15
|
+
*/
|
|
16
|
+
/** Markers the bash tool appends after the output body. */
|
|
17
|
+
const TRAILING_MARKER_PATTERNS = [
|
|
18
|
+
/^\[exit code: -?\d+\]$/,
|
|
19
|
+
/^\[killed by signal: .+\]$/,
|
|
20
|
+
/^\[timed out after \d+ms\]$/,
|
|
21
|
+
/^\[output truncated; full output: .+\]$/,
|
|
22
|
+
/^\[some output was dropped from memory; full output: .+\]$/,
|
|
23
|
+
/^\[sandbox: .+\]$/,
|
|
24
|
+
];
|
|
25
|
+
const STDERR_HEADER = '[stderr]';
|
|
26
|
+
/** The bash tool's placeholder for a command that printed nothing at all. */
|
|
27
|
+
export const NO_OUTPUT_PLACEHOLDER = '(no output)';
|
|
28
|
+
function isTrailingMarker(line) {
|
|
29
|
+
return TRAILING_MARKER_PATTERNS.some((pattern) => pattern.test(line));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decompose a rendered bash result.
|
|
33
|
+
*
|
|
34
|
+
* Trailing markers are peeled from the end first, then the `[stderr]` section
|
|
35
|
+
* is split off. Only the first `[stderr]` header counts: if the command's own
|
|
36
|
+
* output contains that literal line, everything after it belongs to stderr,
|
|
37
|
+
* which is what the renderer produced.
|
|
38
|
+
*
|
|
39
|
+
* @param text - the rendered bash result.
|
|
40
|
+
* @returns the decomposed parts.
|
|
41
|
+
*/
|
|
42
|
+
export function parseBashResult(text) {
|
|
43
|
+
if (text === NO_OUTPUT_PLACEHOLDER) {
|
|
44
|
+
return { empty: true, stdout: '', markers: [] };
|
|
45
|
+
}
|
|
46
|
+
const lines = text.split('\n');
|
|
47
|
+
const markers = [];
|
|
48
|
+
while (lines.length > 0) {
|
|
49
|
+
const last = lines[lines.length - 1];
|
|
50
|
+
if (last === undefined || !isTrailingMarker(last))
|
|
51
|
+
break;
|
|
52
|
+
markers.unshift(last);
|
|
53
|
+
lines.pop();
|
|
54
|
+
}
|
|
55
|
+
const headerIndex = lines.indexOf(STDERR_HEADER);
|
|
56
|
+
if (headerIndex === -1) {
|
|
57
|
+
return { empty: false, stdout: lines.join('\n'), markers };
|
|
58
|
+
}
|
|
59
|
+
const stdout = lines.slice(0, headerIndex).join('\n');
|
|
60
|
+
const stderr = lines.slice(headerIndex + 1).join('\n');
|
|
61
|
+
return { empty: false, stdout, stderr, markers };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Reassemble a bash result from its parts.
|
|
65
|
+
*
|
|
66
|
+
* The inverse of {@link parseBashResult}, so the model-visible contract — the
|
|
67
|
+
* marker lines the agent loop and the UI both depend on — survives a
|
|
68
|
+
* compaction pass untouched.
|
|
69
|
+
*/
|
|
70
|
+
export function renderBashResult(parts) {
|
|
71
|
+
const sections = [];
|
|
72
|
+
if (parts.empty) {
|
|
73
|
+
sections.push(NO_OUTPUT_PLACEHOLDER);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
if (parts.stdout.length > 0)
|
|
77
|
+
sections.push(parts.stdout);
|
|
78
|
+
if (parts.stderr !== undefined)
|
|
79
|
+
sections.push(STDERR_HEADER, parts.stderr);
|
|
80
|
+
}
|
|
81
|
+
sections.push(...parts.markers);
|
|
82
|
+
return sections.join('\n');
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=dsh-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsh-result.js","sourceRoot":"","sources":["../../src/compact/dsh-result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2DAA2D;AAC3D,MAAM,wBAAwB,GAAG;IAC/B,wBAAwB;IACxB,4BAA4B;IAC5B,6BAA6B;IAC7B,yCAAyC;IACzC,4DAA4D;IAC5D,mBAAmB;CACX,CAAA;AAEV,MAAM,aAAa,GAAG,UAAU,CAAA;AAChC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAA;AAElD,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,wBAAwB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AACvE,CAAC;AAcD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,IAAI,KAAK,qBAAqB,EAAE,CAAC;QACnC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAA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AAM,CAAC,MAAM,GAAG,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACxD,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;YAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC5E,CAAC;IACD,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA;IAC/B,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Whether the command is one of the git commands this module understands. */
|
|
2
|
+
export declare function isGitCommand(command: string | undefined | null): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Condense a unified diff to file headers, hunk headers, and a bounded sample
|
|
5
|
+
* of changed lines, with an added/removed count per file.
|
|
6
|
+
*/
|
|
7
|
+
export declare function compactDiff(output: string, maxLines?: number): string;
|
|
8
|
+
/** Condense `git status` porcelain output into per-bucket counts and samples. */
|
|
9
|
+
export declare function compactStatus(output: string): string;
|
|
10
|
+
/** Keep the first `limit` log lines, capping each line's width. */
|
|
11
|
+
export declare function compactLog(output: string, limit?: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Compact a git command's output, or `null` when nothing applies.
|
|
14
|
+
*
|
|
15
|
+
* Each branch first checks that the output actually looks like raw git output.
|
|
16
|
+
* A command like `git diff --stat` inside a wrapper, or a script whose name
|
|
17
|
+
* merely starts with `git`, would otherwise be rewritten into a summary of
|
|
18
|
+
* text this module never parsed correctly.
|
|
19
|
+
*/
|
|
20
|
+
export declare function compactGitOutput(output: string, command: string | undefined | null): string | null;
|
|
21
|
+
//# sourceMappingURL=git.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/compact/git.ts"],"names":[],"mappings":"AAkCA,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAExE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAK,GAAG,MAAM,CA+DjE;AAYD,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAwDpD;AAED,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAQ7D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAYlG"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { matchesCommandPatterns, normalizeCommandForDetection } from './detect.js';
|
|
2
|
+
const GIT_COMMAND_PATTERNS = [/^git\s+(diff|status|log|show|stash)\b/];
|
|
3
|
+
const RAW_GIT_DIFF_PATTERN = /^diff --git /m;
|
|
4
|
+
const RAW_GIT_STATUS_PATTERN = /^(?:## |(?:M|A|D|R|C|U|\?| )\S)/m;
|
|
5
|
+
/**
|
|
6
|
+
* One line of `git status --porcelain` output.
|
|
7
|
+
*
|
|
8
|
+
* Covers the v1 branch header (`## main...origin/main`), the v2 headers
|
|
9
|
+
* (`# branch.head main`), the `??` untracked form, and the two-column status
|
|
10
|
+
* form. The human report contains none of these shapes.
|
|
11
|
+
*/
|
|
12
|
+
const PORCELAIN_STATUS_LINE = /^(?:##?\s|\?\? .+|[ MADRCU?!]{2} .+)/;
|
|
13
|
+
/** Share of non-blank lines that must parse as porcelain before summarizing. */
|
|
14
|
+
const PORCELAIN_LINE_MIN_RATIO = 0.8;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a body is `git status --porcelain` rather than the human report.
|
|
17
|
+
*
|
|
18
|
+
* The two are indistinguishable line by line — ` M path` is valid porcelain
|
|
19
|
+
* and also occurs inside the human report — but only porcelain may be sliced
|
|
20
|
+
* with fixed column offsets. Running the summarizer over the human text
|
|
21
|
+
* silently invents and drops entries, so the body must be *consistently*
|
|
22
|
+
* porcelain before any of it is interpreted.
|
|
23
|
+
*/
|
|
24
|
+
function isPorcelainStatus(output) {
|
|
25
|
+
const lines = output.split('\n').filter((line) => line.trim().length > 0);
|
|
26
|
+
if (lines.length === 0)
|
|
27
|
+
return false;
|
|
28
|
+
const matches = lines.filter((line) => PORCELAIN_STATUS_LINE.test(line)).length;
|
|
29
|
+
return matches / lines.length >= PORCELAIN_LINE_MIN_RATIO;
|
|
30
|
+
}
|
|
31
|
+
/** Whether the command is one of the git commands this module understands. */
|
|
32
|
+
export function isGitCommand(command) {
|
|
33
|
+
return matchesCommandPatterns(command, GIT_COMMAND_PATTERNS);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Condense a unified diff to file headers, hunk headers, and a bounded sample
|
|
37
|
+
* of changed lines, with an added/removed count per file.
|
|
38
|
+
*/
|
|
39
|
+
export function compactDiff(output, maxLines = 50) {
|
|
40
|
+
const lines = output.split('\n');
|
|
41
|
+
const result = [];
|
|
42
|
+
let currentFile = '';
|
|
43
|
+
let added = 0;
|
|
44
|
+
let removed = 0;
|
|
45
|
+
let inHunk = false;
|
|
46
|
+
let hunkLines = 0;
|
|
47
|
+
const maxHunkLines = 10;
|
|
48
|
+
for (const line of lines) {
|
|
49
|
+
if (result.length >= maxLines) {
|
|
50
|
+
result.push('\n... (more changes truncated)');
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
if (line.startsWith('diff --git')) {
|
|
54
|
+
if (currentFile && (added > 0 || removed > 0))
|
|
55
|
+
result.push(` +${added} -${removed}`);
|
|
56
|
+
const match = line.match(/diff --git a\/(.+) b\/(.+)/);
|
|
57
|
+
currentFile = match?.[2] ?? 'unknown';
|
|
58
|
+
result.push(`\n> ${currentFile}`);
|
|
59
|
+
added = 0;
|
|
60
|
+
removed = 0;
|
|
61
|
+
inHunk = false;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (line.startsWith('@@')) {
|
|
65
|
+
inHunk = true;
|
|
66
|
+
hunkLines = 0;
|
|
67
|
+
result.push(` ${line.match(/@@ .+ @@/)?.[0] ?? '@@'}`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (!inHunk)
|
|
71
|
+
continue;
|
|
72
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
73
|
+
added++;
|
|
74
|
+
if (hunkLines < maxHunkLines) {
|
|
75
|
+
result.push(` ${line}`);
|
|
76
|
+
hunkLines++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
80
|
+
removed++;
|
|
81
|
+
if (hunkLines < maxHunkLines) {
|
|
82
|
+
result.push(` ${line}`);
|
|
83
|
+
hunkLines++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (hunkLines < maxHunkLines && !line.startsWith('\\')) {
|
|
87
|
+
if (hunkLines > 0) {
|
|
88
|
+
result.push(` ${line}`);
|
|
89
|
+
hunkLines++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (hunkLines === maxHunkLines) {
|
|
93
|
+
result.push(' ... (truncated)');
|
|
94
|
+
hunkLines++;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (currentFile && (added > 0 || removed > 0))
|
|
98
|
+
result.push(` +${added} -${removed}`);
|
|
99
|
+
return result.join('\n');
|
|
100
|
+
}
|
|
101
|
+
/** Condense `git status` porcelain output into per-bucket counts and samples. */
|
|
102
|
+
export function compactStatus(output) {
|
|
103
|
+
const lines = output.split('\n');
|
|
104
|
+
if (lines.length === 0 || (lines.length === 1 && lines[0]?.trim() === ''))
|
|
105
|
+
return 'Clean working tree';
|
|
106
|
+
const stats = {
|
|
107
|
+
staged: 0,
|
|
108
|
+
modified: 0,
|
|
109
|
+
untracked: 0,
|
|
110
|
+
conflicts: 0,
|
|
111
|
+
stagedFiles: [],
|
|
112
|
+
modifiedFiles: [],
|
|
113
|
+
untrackedFiles: [],
|
|
114
|
+
};
|
|
115
|
+
let branchName = '';
|
|
116
|
+
for (const line of lines) {
|
|
117
|
+
if (line.startsWith('##')) {
|
|
118
|
+
const match = line.match(/## (.+)/);
|
|
119
|
+
if (match?.[1])
|
|
120
|
+
branchName = match[1].split('...')[0] ?? match[1];
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (line.length < 3)
|
|
124
|
+
continue;
|
|
125
|
+
const status = line.slice(0, 2);
|
|
126
|
+
const filename = line.slice(3);
|
|
127
|
+
const indexStatus = status[0];
|
|
128
|
+
const worktreeStatus = status[1];
|
|
129
|
+
if (indexStatus !== undefined && ['M', 'A', 'D', 'R', 'C'].includes(indexStatus)) {
|
|
130
|
+
stats.staged++;
|
|
131
|
+
stats.stagedFiles.push(filename);
|
|
132
|
+
}
|
|
133
|
+
if (indexStatus === 'U')
|
|
134
|
+
stats.conflicts++;
|
|
135
|
+
if (worktreeStatus !== undefined && ['M', 'D'].includes(worktreeStatus)) {
|
|
136
|
+
stats.modified++;
|
|
137
|
+
stats.modifiedFiles.push(filename);
|
|
138
|
+
}
|
|
139
|
+
if (status === '??') {
|
|
140
|
+
stats.untracked++;
|
|
141
|
+
stats.untrackedFiles.push(filename);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
let result = `Branch: ${branchName}\n`;
|
|
145
|
+
const append = (label, count, files, shown) => {
|
|
146
|
+
if (count === 0)
|
|
147
|
+
return;
|
|
148
|
+
result += `${label}: ${count} files\n`;
|
|
149
|
+
for (const file of files.slice(0, shown))
|
|
150
|
+
result += ` ${file}\n`;
|
|
151
|
+
if (count > shown)
|
|
152
|
+
result += ` ... +${count - shown} more\n`;
|
|
153
|
+
};
|
|
154
|
+
append('Staged', stats.staged, stats.stagedFiles, 5);
|
|
155
|
+
append('Modified', stats.modified, stats.modifiedFiles, 5);
|
|
156
|
+
append('Untracked', stats.untracked, stats.untrackedFiles, 3);
|
|
157
|
+
if (stats.conflicts > 0)
|
|
158
|
+
result += `Conflicts: ${stats.conflicts} files\n`;
|
|
159
|
+
return result.trim();
|
|
160
|
+
}
|
|
161
|
+
/** Keep the first `limit` log lines, capping each line's width. */
|
|
162
|
+
export function compactLog(output, limit = 20) {
|
|
163
|
+
const lines = output.split('\n');
|
|
164
|
+
const result = [];
|
|
165
|
+
for (const line of lines.slice(0, limit)) {
|
|
166
|
+
result.push(line.length > 80 ? `${line.slice(0, 77)}...` : line);
|
|
167
|
+
}
|
|
168
|
+
if (lines.length > limit)
|
|
169
|
+
result.push(`... and ${lines.length - limit} more commits`);
|
|
170
|
+
return result.join('\n');
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Compact a git command's output, or `null` when nothing applies.
|
|
174
|
+
*
|
|
175
|
+
* Each branch first checks that the output actually looks like raw git output.
|
|
176
|
+
* A command like `git diff --stat` inside a wrapper, or a script whose name
|
|
177
|
+
* merely starts with `git`, would otherwise be rewritten into a summary of
|
|
178
|
+
* text this module never parsed correctly.
|
|
179
|
+
*/
|
|
180
|
+
export function compactGitOutput(output, command) {
|
|
181
|
+
if (!isGitCommand(command))
|
|
182
|
+
return null;
|
|
183
|
+
const normalized = normalizeCommandForDetection(command);
|
|
184
|
+
if (!normalized)
|
|
185
|
+
return null;
|
|
186
|
+
if (normalized.startsWith('git diff'))
|
|
187
|
+
return RAW_GIT_DIFF_PATTERN.test(output) ? compactDiff(output) : null;
|
|
188
|
+
if (normalized.startsWith('git status')) {
|
|
189
|
+
if (!isPorcelainStatus(output))
|
|
190
|
+
return null;
|
|
191
|
+
return RAW_GIT_STATUS_PATTERN.test(output) ? compactStatus(output) : null;
|
|
192
|
+
}
|
|
193
|
+
if (normalized.startsWith('git log'))
|
|
194
|
+
return compactLog(output);
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
//#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IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC5G,IAAI,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAA;QAC3C,OAAO,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC3E,CAAC;IACD,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/D,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RtkConfig } from '../config.js';
|
|
2
|
+
/** Banner prefixed to a `read` result that lost information. */
|
|
3
|
+
export declare const READ_COMPACTION_BANNER_PREFIX = "[rtk compacted output:";
|
|
4
|
+
/** The tool-result projection compaction reads and writes. */
|
|
5
|
+
export interface CompactionInput {
|
|
6
|
+
toolName: string;
|
|
7
|
+
args: unknown;
|
|
8
|
+
content: unknown;
|
|
9
|
+
}
|
|
10
|
+
/** What one compaction pass did, for the session metrics. */
|
|
11
|
+
export interface CompactionMetadata {
|
|
12
|
+
applied: boolean;
|
|
13
|
+
techniques: string[];
|
|
14
|
+
truncated: boolean;
|
|
15
|
+
originalCharCount: number;
|
|
16
|
+
compactedCharCount: number;
|
|
17
|
+
originalLineCount: number;
|
|
18
|
+
compactedLineCount: number;
|
|
19
|
+
}
|
|
20
|
+
/** The pipeline's verdict for one tool result. */
|
|
21
|
+
export interface CompactionOutcome {
|
|
22
|
+
changed: boolean;
|
|
23
|
+
content?: unknown[];
|
|
24
|
+
techniques: string[];
|
|
25
|
+
metadata?: CompactionMetadata;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run every enabled technique over one tool result.
|
|
29
|
+
*
|
|
30
|
+
* Returns `changed: false` whenever the result would not actually shrink, so a
|
|
31
|
+
* caller can treat "no outcome" and "no improvement" identically and the model
|
|
32
|
+
* never pays for a rewrite that saved nothing.
|
|
33
|
+
*
|
|
34
|
+
* @param input - the tool name, its parsed arguments, and the content blocks.
|
|
35
|
+
* @param config - the resolved plugin configuration.
|
|
36
|
+
* @returns the replacement content and the techniques that fired.
|
|
37
|
+
*/
|
|
38
|
+
export declare function compactToolResult(input: CompactionInput, config: RtkConfig): CompactionOutcome;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compact/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA0B,SAAS,EAAE,MAAM,cAAc,CAAA;AAgBrE,gEAAgE;AAChE,eAAO,MAAM,6BAA6B,2BAA2B,CAAA;AAErE,8DAA8D;AAC9D,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,6DAA6D;AAC7D,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,EAAE,MAAM,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAED,kDAAkD;AAClD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAA;IACnB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,QAAQ,CAAC,EAAE,kBAAkB,CAAA;CAC9B;AA6KD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,GAAG,iBAAiB,CAqD9F"}
|