harnesstrim 0.0.6 → 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.
|
@@ -225,14 +225,20 @@ def _write_metric(tool: str, reducer: str | None, before: int, after: int) -> No
|
|
|
225
225
|
directory lazily and swallows any error — telemetry must never crash the plugin.
|
|
226
226
|
"""
|
|
227
227
|
import datetime as _dt
|
|
228
|
+
import uuid as _uuid
|
|
228
229
|
|
|
229
230
|
event = {
|
|
231
|
+
"schemaVersion": 1,
|
|
232
|
+
"eventId": str(_uuid.uuid4()),
|
|
230
233
|
"ts": _dt.datetime.now(_dt.timezone.utc).isoformat(),
|
|
231
234
|
"harness": "hermes",
|
|
232
235
|
"tool": tool,
|
|
233
236
|
"reducer": reducer,
|
|
234
237
|
"beforeChars": before,
|
|
235
238
|
"afterChars": after,
|
|
239
|
+
"changed": True,
|
|
240
|
+
"beforeTokens": None,
|
|
241
|
+
"afterTokens": None,
|
|
236
242
|
}
|
|
237
243
|
try:
|
|
238
244
|
METRICS_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -29,6 +29,11 @@ const MODE = env.HARNESSTRIM_MODE ?? "dryrun";
|
|
|
29
29
|
const MIN_LENGTH = Number(env.HARNESSTRIM_MINLENGTH ?? "400") || 400;
|
|
30
30
|
const MARKER = "[harnesstrim";
|
|
31
31
|
|
|
32
|
+
/** True when a text chunk should not be reduced: too short, or already reduced. */
|
|
33
|
+
export function shouldSkip(text: string, minLength: number): boolean {
|
|
34
|
+
return text.length < minLength || text.includes(MARKER);
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
function reduceViaCli(text: string): string | null {
|
|
33
38
|
try {
|
|
34
39
|
const r = spawnSync("harnesstrim", ["reduce", "--min-length", String(MIN_LENGTH)], {
|
|
@@ -54,7 +59,7 @@ export default function harnesstrim(pi: ExtensionAPI): void {
|
|
|
54
59
|
const content = event.content.map((chunk) => {
|
|
55
60
|
if (chunk.type !== "text" || typeof chunk.text !== "string") return chunk;
|
|
56
61
|
const text = chunk.text;
|
|
57
|
-
if (text
|
|
62
|
+
if (shouldSkip(text, MIN_LENGTH)) return chunk;
|
|
58
63
|
|
|
59
64
|
const reduced = reduceViaCli(text);
|
|
60
65
|
if (!reduced || reduced.length >= text.length) return chunk;
|