@ngockhoale/ukit 3.5.10 → 3.5.13

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.
@@ -1388,6 +1388,81 @@ function shouldCompress(config) {
1388
1388
  return Boolean(config?.tokenPipeline?.outputCompression);
1389
1389
  }
1390
1390
 
1391
+ // 3.5.11 quality fix: since 3.5.10 a summary REPLACES the Bash output on Claude Code.
1392
+ // For commands whose output is the content the model asked to read (cat/sed -n/head/
1393
+ // git diff …), for output already bounded by a trailing head/tail/sed stage, and for
1394
+ // chained commands (`a; b && c`) whose sections the line picker cannot keep apart, a
1395
+ // lossy summary drops source text or misfiles sections — quality > token savings, so
1396
+ // these pass through untouched.
1397
+ const VERBATIM_READ_HEADS = new Set([
1398
+ 'cat', 'sed', 'head', 'tail', 'nl', 'bat', 'less', 'more', 'jq', 'diff', 'awk', 'cut',
1399
+ ]);
1400
+ const VERBATIM_GIT_SUBCOMMANDS = new Set(['show', 'diff', 'blame', 'cat-file']);
1401
+ const BOUNDING_TAIL_STAGES = new Set(['head', 'tail', 'sed']);
1402
+
1403
+ function splitShellCommand(command) {
1404
+ const segments = [];
1405
+ let current = '';
1406
+ let ops = [];
1407
+ let quote = '';
1408
+ const text = String(command ?? '');
1409
+ for (let i = 0; i < text.length; i += 1) {
1410
+ const ch = text[i];
1411
+ if (quote) {
1412
+ if (ch === '\\' && quote === '"' && i + 1 < text.length) { current += ch + text[i + 1]; i += 1; continue; }
1413
+ if (ch === quote) quote = '';
1414
+ current += ch;
1415
+ continue;
1416
+ }
1417
+ if (ch === '\\' && i + 1 < text.length) { current += ch + text[i + 1]; i += 1; continue; }
1418
+ if (ch === '"' || ch === "'") { quote = ch; current += ch; continue; }
1419
+ const two = text.slice(i, i + 2);
1420
+ if (two === '&&' || two === '||') { segments.push(current); ops.push(two); current = ''; i += 1; continue; }
1421
+ if (ch === ';' || ch === '\n' || ch === '|') { segments.push(current); ops.push(ch === '|' ? '|' : ';'); current = ''; continue; }
1422
+ current += ch;
1423
+ }
1424
+ segments.push(current);
1425
+ return { segments: segments.map((s) => s.trim()), ops };
1426
+ }
1427
+
1428
+ function segmentWords(segment) {
1429
+ const words = segment.split(/\s+/).filter(Boolean);
1430
+ while (words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[0])) words.shift();
1431
+ return words;
1432
+ }
1433
+
1434
+ export function isVerbatimOutputCommand(command) {
1435
+ const { segments, ops } = splitShellCommand(command);
1436
+ // Group pipe stages into pipelines; drop `cd …` navigation pipelines.
1437
+ const pipelines = [];
1438
+ let stages = [segments[0]];
1439
+ for (let i = 0; i < ops.length; i += 1) {
1440
+ if (ops[i] === '|') stages.push(segments[i + 1]);
1441
+ else { pipelines.push(stages); stages = [segments[i + 1]]; }
1442
+ }
1443
+ pipelines.push(stages);
1444
+ const meaningful = pipelines
1445
+ .map((p) => p.filter(Boolean))
1446
+ .filter((p) => p.length > 0 && !(p.length === 1 && segmentWords(p[0])[0] === 'cd'));
1447
+ if (meaningful.length > 1) return true;
1448
+ if (meaningful.length === 0) return false;
1449
+ const pipeline = meaningful[0];
1450
+ const first = segmentWords(pipeline[0]);
1451
+ const head = (first[0] || '').replace(/^.*\//, '');
1452
+ if (VERBATIM_READ_HEADS.has(head)) return true;
1453
+ if (head === 'git') {
1454
+ const sub = first.slice(1).find((w) => !w.startsWith('-'));
1455
+ const listingOnly = first.some((w) => /^--(stat|numstat|shortstat|name-only|name-status)\b/.test(w));
1456
+ if (VERBATIM_GIT_SUBCOMMANDS.has(sub) && !listingOnly) return true;
1457
+ if (sub === 'log' && first.some((w) => w === '-p' || w === '--patch')) return true;
1458
+ }
1459
+ if (pipeline.length > 1) {
1460
+ const last = segmentWords(pipeline[pipeline.length - 1]);
1461
+ if (BOUNDING_TAIL_STAGES.has((last[0] || '').replace(/^.*\//, ''))) return true;
1462
+ }
1463
+ return false;
1464
+ }
1465
+
1391
1466
  function mergeDeep(base, override) {
1392
1467
  if (!override || typeof override !== 'object' || Array.isArray(override)) {
1393
1468
  return override === undefined ? base : override;
@@ -1482,6 +1557,12 @@ async function main() {
1482
1557
  return;
1483
1558
  }
1484
1559
 
1560
+ // 3.5.11: content reads, bounded pipelines and chained commands pass through raw.
1561
+ if (isVerbatimOutputCommand(command)) {
1562
+ process.exit(0);
1563
+ return;
1564
+ }
1565
+
1485
1566
  const requestKey = buildCompactMachineKey('tool-output-v1', {
1486
1567
  command,
1487
1568
  stdoutHash: buildCompactMachineKey('stdout', stripAnsi(stdout)),
@@ -9,7 +9,7 @@
9
9
  * Stalled-cursor releases are advisory, never completion evidence.
10
10
  * Completion infrastructure failures block with redacted reasons (details only
11
11
  * on stderr); watchdog failures are advisory and reported verbatim.
12
- * UKIT_HOOK_DEADLINE_MS bounds execution (wrapper default 5000ms), including the ledger
12
+ * UKIT_HOOK_DEADLINE_MS bounds execution (wrapper default 10000ms), including the ledger
13
13
  * child. Deadline expiry synchronously emits a fail-closed block and reaps the
14
14
  * child before exit0: empty stdout would incorrectly release the wrapper.
15
15
  * Exported evaluators, merge, normalization and redaction seams are tested directly.
@@ -143,14 +143,14 @@ export const DEDUPE_WINDOW_MS = 2000;
143
143
 
144
144
  // Budget slices inside the hook deadline: the ledger child gets the larger slice, each
145
145
  // watchdog lock acquisition gets a short one. The ledger slice is 1500ms under a short
146
- // deadline and grows with a longer one (the shipped wrapper arms 5000ms) up to 3000ms,
147
- // always leaving 1500ms for the advisory lanes and the decision write. Field telemetry:
146
+ // deadline and grows with a longer one (the shipped wrapper arms 10000ms → 7000ms) capped at 8000ms:
147
+ // min(8000, max(min(3000, d-1500), d-3000)), leaving 1500-3000ms for the advisory lanes and the decision write. Field telemetry:
148
148
  // on a loaded machine / external volume a healthy evaluation overran 1500ms and the
149
149
  // stop was blocked as an "infrastructure failure".
150
150
  export function resolveLedgerBudgetMs(deadlineMs) {
151
151
  const deadline = Number(deadlineMs);
152
152
  if (!Number.isFinite(deadline) || deadline <= 3000) return 1500;
153
- return Math.min(3000, deadline - 1500);
153
+ return Math.min(8000, Math.max(Math.min(3000, deadline - 1500), deadline - 3000));
154
154
  }
155
155
  const LEDGER_BUDGET_MS = resolveLedgerBudgetMs(HOOK_DEADLINE_MS);
156
156
  export const LOCK_BUDGET_MS = 600;
@@ -66,6 +66,7 @@ If any input is missing, return `CHANGES-REQUESTED` with reason "incomplete hand
66
66
  4. **Safety / security / data loss** — Destructive actions, auth/permission, path handling, unsafe shell/DB/file ops.
67
67
  5. **Performance / scale** — Accidental N+1, repeated I/O, large scans inside hot paths.
68
68
  6. **Maintainability** — Duplicated logic, dead branches, misleading naming, drift between docs/tests/source.
69
+ 6a. **Test hygiene (test diffs)** — Follow `.claude/skills/code-review/SKILL.md` § Test Diffs: app/server/client/DB fixtures without teardown, real-data reachability, per-test app registries, oversized new test files (count parametrize expansion), and tests skipped to save time/RAM. Run `node .claude/ukit/index/test-batches.mjs audit --changed`; an enforced ERROR on a new test file is `CHANGES-REQUESTED` unless the project records an exception.
69
70
  7. **Solution fit** — For each added block, ask with evidence and cite the construct + why (never the prose length):
70
71
  - Does new code duplicate an existing helper with the same semantics? A same-semantics duplicate is `CHANGES-REQUESTED` — reuse the existing helper.
71
72
  - Would the standard library or a native platform API satisfy every stated requirement? If yes, the custom implementation is avoidable.
@@ -42,6 +42,7 @@ and even then, report it, don't ask about it.
42
42
  ### 2. Plan Approach (< 1 minute)
43
43
 
44
44
  - List files to create/modify (max diff).
45
+ - **Tests you add:** plan the layout first (feature, category, expected case count incl. parametrize, target files, fixture teardown) and follow `.claude/skills/testing-quality/SKILL.md` § Writing Memory-Safe Tests — small focused files, every app/client/DB fixture torn down, test paths isolated before app import. Full-suite verification uses `node .claude/ukit/index/test-batches.mjs run`.
45
46
  - **Handoff mode only:** if no Test Plan exists in the task file and task is not `trivial`, write one inline before implementing (happy + ≥2 edge cases of different kinds; regression test if fixing a bug). In daily mode, skip this step.
46
47
  - **Choose the smallest solution that fully meets the stated requirements and project conventions.** When more than one option qualifies, prefer, in order: (1) reuse an existing codebase helper with the same semantics; (2) standard library, native platform API, or an already-installed dependency; (3) custom code or a new dependency (last resort). Never drop validation, security, accessibility, error handling, compatibility, or required tests to reduce code. A bugfix fixes the root cause and the affected callers. If the small option is insufficient, build the full option — never ship a weaker version and ask. No speculative abstraction for imagined needs.
47
48
 
@@ -0,0 +1,10 @@
1
+ # Testing patterns (UKit default)
2
+
3
+ Seeded once by UKit; this file is yours — edit, extend or delete entries. Full rules: `.claude/skills/testing-quality/memory-safe-tests.md`.
4
+
5
+ - Pattern: run the full test suite with `node .claude/ukit/index/test-batches.mjs run` — sequential small batches, one fresh process per batch, every test file runs; only verdict PASS satisfies a release gate (FAIL/INCOMPLETE/UNSAFE do not). Do not add parallel workers (pytest-xdist -n, maxWorkers) to fix test memory: workers multiply RAM.
6
+ - Pattern: test suite memory blow-up / swap is usually a per-test leak, not runner speed — a fixture builds a fresh app per test that is never freed (global app registry, OpenAPI/docs singleton, module-level routers holding app refs, background tasks never cancelled). Fix fixture teardown; smaller batches or files alone do not fix it.
7
+ - Pattern: every test fixture that builds an app, server, client, DB connection, browser, thread or async task tears it down (yield + finally / afterAll): cancel tasks, close connections, unregister from registries, clear singletons. Prefer one app per module (scope=module) when tests do not mutate app state.
8
+ - Pattern: plan test files before writing them — count cases including parametrize expansion; budgets per file: unit 40, integration 20, app-heavy 10, e2e 10; split by behaviour, never into one 200-case test file. Check with `test-batches.mjs audit --changed`.
9
+ - Pattern: test isolation — set data, DB, log and telemetry paths to a temp dir before the app module is imported; app code reads paths from config at call time, not at import; disable schedulers, sweeps and auto-fetch in tests. Tests must never touch real project data, auth/system DBs or shared logs; prove it with `test-batches.mjs run --guard <data dir>`.
10
+ - Pattern: never skip, deselect or xfail tests to save RAM or time; RAM thresholds only flag heavy test files. Suspected test memory leak → `test-batches.mjs detect-leaks --file <file>` and `--resource-warnings` for unclosed DB connections.