@ngockhoale/ukit 3.5.13 → 3.5.15

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.
@@ -497,28 +497,265 @@ async function evaluate({ rawInput, projectRoot, env }) {
497
497
  return bodies;
498
498
  };
499
499
 
500
+ // Field-telemetry #4 (2026-11-20): quote/substitution/heredoc-aware split of
501
+ // a command into its top-level list segments. The old
502
+ // `command.split(/\|\||&&|;|\||\n/)` cut INSIDE quotes, so `grep -E
503
+ // "release|history"` produced a bare `history` segment, and heredoc body
504
+ // lines were parsed as commands. Returns the segments, the command text with
505
+ // heredoc bodies removed, and the bodies of UNQUOTED heredocs (where `$(…)`
506
+ // still expands); quoted-delimiter heredoc bodies (`<<'EOF'`) are literal
507
+ // data and dropped. Unbalanced input consumes the rest of the text (bash
508
+ // would reject it; the scan stays pessimistic, never skips content).
509
+ const skipBalancedSubst = (src, i) => {
510
+ // src[i] === '$' && src[i+1] === '(' -> index after the matching ')'.
511
+ let d = 1;
512
+ let j = i + 2;
513
+ while (j < src.length && d > 0) {
514
+ const b = src[j];
515
+ if (b === '\\') { j += 2; continue; }
516
+ if (b === "'") { const e = src.indexOf("'", j + 1); j = e === -1 ? src.length : e + 1; continue; }
517
+ if (b === '"') {
518
+ j += 1;
519
+ while (j < src.length && src[j] !== '"') {
520
+ if (src[j] === '\\') { j += 2; continue; }
521
+ if (src[j] === '$' && src[j + 1] === '(') { j = skipBalancedSubst(src, j); continue; }
522
+ j += 1;
523
+ }
524
+ j += 1;
525
+ continue;
526
+ }
527
+ if (b === '`') { const e = src.indexOf('`', j + 1); j = e === -1 ? src.length : e + 1; continue; }
528
+ if (b === '(') d += 1;
529
+ else if (b === ')') d -= 1;
530
+ j += 1;
531
+ }
532
+ return Math.min(j, src.length);
533
+ };
534
+ const splitTopLevel = (command) => {
535
+ const src = String(command ?? '');
536
+ const segments = [];
537
+ const heredocBodies = [];
538
+ let stripped = '';
539
+ let cur = '';
540
+ const seps = []; // separator FOLLOWING each segment ('|', '||', ';', '&&', '&', '\n', '')
541
+ const pending = []; // { delim, quoted, stripTabs }
542
+ const push = (sep = '') => { segments.push(cur); seps.push(sep); cur = ''; };
543
+ let i = 0;
544
+ while (i < src.length) {
545
+ const ch = src[i];
546
+ if (ch === '\\') { const s = src.slice(i, i + 2); cur += s; stripped += s; i += 2; continue; }
547
+ if (ch === "'") {
548
+ const e = src.indexOf("'", i + 1);
549
+ const end = e === -1 ? src.length : e + 1;
550
+ cur += src.slice(i, end); stripped += src.slice(i, end); i = end; continue;
551
+ }
552
+ if (ch === '"') {
553
+ let j = i + 1;
554
+ while (j < src.length && src[j] !== '"') {
555
+ if (src[j] === '\\') { j += 2; continue; }
556
+ if (src[j] === '$' && src[j + 1] === '(') { j = skipBalancedSubst(src, j); continue; }
557
+ if (src[j] === '`') { const e = src.indexOf('`', j + 1); j = e === -1 ? src.length : e + 1; continue; }
558
+ j += 1;
559
+ }
560
+ const end = Math.min(j + 1, src.length);
561
+ cur += src.slice(i, end); stripped += src.slice(i, end); i = end; continue;
562
+ }
563
+ if (ch === '`') {
564
+ const e = src.indexOf('`', i + 1);
565
+ const end = e === -1 ? src.length : e + 1;
566
+ cur += src.slice(i, end); stripped += src.slice(i, end); i = end; continue;
567
+ }
568
+ if (ch === '$' && src[i + 1] === '(') {
569
+ const end = skipBalancedSubst(src, i);
570
+ cur += src.slice(i, end); stripped += src.slice(i, end); i = end; continue;
571
+ }
572
+ if (ch === '<' && src[i + 1] === '<' && src[i + 2] !== '<') {
573
+ // Heredoc operator: record the delimiter; the body starts after the
574
+ // next unquoted newline.
575
+ let j = i + 2;
576
+ const stripTabs = src[j] === '-';
577
+ if (stripTabs) j += 1;
578
+ while (src[j] === ' ' || src[j] === '\t') j += 1;
579
+ const wordStart = j;
580
+ while (j < src.length && !/[\s;&|<>()]/.test(src[j])) {
581
+ if (src[j] === "'") { const e = src.indexOf("'", j + 1); j = e === -1 ? src.length : e + 1; continue; }
582
+ if (src[j] === '"') { const e = src.indexOf('"', j + 1); j = e === -1 ? src.length : e + 1; continue; }
583
+ if (src[j] === '\\') { j += 2; continue; }
584
+ j += 1;
585
+ }
586
+ const word = src.slice(wordStart, j);
587
+ if (word) {
588
+ pending.push({ delim: stripQuotes(word), quoted: /["'\\]/.test(word), stripTabs });
589
+ }
590
+ cur += src.slice(i, j); stripped += src.slice(i, j); i = j; continue;
591
+ }
592
+ if (ch === '\n') {
593
+ push('\n');
594
+ stripped += '\n';
595
+ i += 1;
596
+ // Consume heredoc bodies, in operator order, line by line.
597
+ while (pending.length) {
598
+ const doc = pending.shift();
599
+ const bodyLines = [];
600
+ let closed = false;
601
+ while (i < src.length) {
602
+ const nl = src.indexOf('\n', i);
603
+ const lineEnd = nl === -1 ? src.length : nl;
604
+ const line = src.slice(i, lineEnd);
605
+ i = nl === -1 ? src.length : nl + 1;
606
+ const cmp = doc.stripTabs ? line.replace(/^\t+/, '') : line;
607
+ if (cmp === doc.delim) { closed = true; break; }
608
+ bodyLines.push(line);
609
+ }
610
+ if (!doc.quoted) heredocBodies.push(bodyLines.join('\n'));
611
+ if (!closed) break;
612
+ }
613
+ continue;
614
+ }
615
+ if (ch === ';' || ch === '|') {
616
+ const two = src[i + 1] === ch || (ch === '|' && src[i + 1] === '&');
617
+ push(two ? ch + src[i + 1] : ch);
618
+ stripped += ch;
619
+ i += two ? 2 : 1;
620
+ continue;
621
+ }
622
+ if (ch === '&') {
623
+ const prev = src[i - 1];
624
+ if (src[i + 1] === '&') { push('&&'); stripped += '&&'; i += 2; continue; }
625
+ // `2>&1`, `&>file`, `>&2` are redirects, not list separators.
626
+ if (prev !== '>' && prev !== '<' && src[i + 1] !== '>') { push('&'); stripped += '&'; i += 1; continue; }
627
+ }
628
+ cur += ch; stripped += ch; i += 1;
629
+ }
630
+ push();
631
+ return { segments, seps, stripped, heredocBodies };
632
+ };
633
+
634
+ // grep-family verbs: the first positional operand is the PATTERN (unless
635
+ // -e/-f/--regexp/--file supplied it), never a file. `grep -v "^./\.env"`
636
+ // reads stdin. `-f FILE` / `--file=FILE` does read FILE, so it stays
637
+ // classified like any file operand.
638
+ const PATTERN_VERBS = new Set(['grep', 'egrep', 'fgrep', 'rg', 'zgrep']);
639
+ const PATTERN_FLAG_OPERANDS = new Set([
640
+ '-A', '-B', '-C', '-m', '-d', '-D', '-g', '-t', '-T', '-M', '-j',
641
+ '--include', '--exclude', '--exclude-dir', '--glob', '--type', '--type-not',
642
+ '--max-count', '--context', '--after-context', '--before-context',
643
+ ]);
644
+ const patternOperandIndex = (tokens, verbIdx) => {
645
+ let explicit = false;
646
+ let firstPositional = -1;
647
+ let endOfFlags = false;
648
+ for (let k = verbIdx + 1; k < tokens.length; k += 1) {
649
+ const t = stripQuotes(tokens[k]);
650
+ if (!endOfFlags && t === '--') { endOfFlags = true; continue; }
651
+ if (!endOfFlags && t.startsWith('-') && t.length > 1) {
652
+ if (/^--(regexp|file)(=|$)/.test(t) || /^-[^-]*[ef]/.test(t)) explicit = true;
653
+ // -e PATTERN as a separate word: that word is a pattern, skip it.
654
+ // Flags whose operand is a separate word (`-A 3`, `rg -g '*.ts'`)
655
+ // also consume it, so the operand is never mistaken for the pattern.
656
+ if (/^(-[^-]*e|--regexp)$/.test(t) || PATTERN_FLAG_OPERANDS.has(t)) k += 1;
657
+ continue;
658
+ }
659
+ if (firstPositional === -1) firstPositional = k;
660
+ }
661
+ return explicit ? -1 : firstPositional;
662
+ };
663
+ const regexpOperandIndexes = (tokens, verbIdx) => {
664
+ const idx = new Set();
665
+ for (let k = verbIdx + 1; k < tokens.length; k += 1) {
666
+ const t = stripQuotes(tokens[k]);
667
+ if (t === '--') break;
668
+ if (/^(-[^-]*e|--regexp)$/.test(t)) { idx.add(k + 1); k += 1; }
669
+ }
670
+ return idx;
671
+ };
672
+
673
+ const JQ_SECRET_FIELD_RE = /(token|secret|password|passwd|api[_-]?key|auth|credential|private)/i;
674
+ // Count-only / list-only grep flags (-c, -q, -l, -L, --count, --quiet,
675
+ // --files-with-matches) print a number or file names, never matched text.
676
+ // `-o`/`-n`/`-h` and friends are NOT in this set, so `grep -oE '^KEY_' .env`
677
+ // stays blocked (it prints key names/values).
678
+ // Only REAL flag words count: the operand of -e/--regexp and of operand-taking
679
+ // flags (-A/-m/...) is skipped, so `grep -e -c -e . .env` is not count-only.
680
+ // Any value-printing flag (-o/-n/-b/-A/-B/-C/-f, --only-matching, ...) next to
681
+ // -c/-l/-q disqualifies the call: the guard stays conservative.
682
+ const VALUE_PRINT_LONG_RE = /^--(only-matching|line-number|byte-offset|context|after-context|before-context|file|replace|passthru|json|vimgrep)(=|$)/;
683
+ const isCountOnlyGrep = (tokens, verbIdx) => {
684
+ let countOnly = false;
685
+ for (let k = verbIdx + 1; k < tokens.length; k += 1) {
686
+ const t = stripQuotes(tokens[k]);
687
+ if (t === '--') break;
688
+ if (!t.startsWith('-') || t.length < 2) continue;
689
+ if (/^(-[^-]*e|--regexp)$/.test(t) || PATTERN_FLAG_OPERANDS.has(t)) { k += 1; }
690
+ if (t.startsWith('--')) {
691
+ if (VALUE_PRINT_LONG_RE.test(t)) return false;
692
+ if (/^--(count|quiet|silent|files-with-matches|files-without-match)$/.test(t)) countOnly = true;
693
+ continue;
694
+ }
695
+ // Short cluster: letters up to the first operand-taking letter are flags;
696
+ // the rest of the word is that flag's attached operand.
697
+ const flags = t.slice(1).replace(/([efmABCdDgtTMj]).*$/, '$1');
698
+ if (/[onbABCf]/.test(flags)) return false;
699
+ if (/[cqlL]/.test(flags)) countOnly = true;
700
+ }
701
+ return countOnly;
702
+ };
703
+ // `env | grep -c X` / `printenv | grep -q X`: decided per segment — only an
704
+ // env/printenv segment whose OWN pipe feeds a count-only grep is exempt.
705
+ const envPipedToCountGrep = (segments, seps, si) => {
706
+ if (seps[si] !== '|' || si + 1 >= segments.length) return false;
707
+ const next = splitShellWords(String(segments[si + 1]).trim()).filter((t) => stripQuotes(t) !== '');
708
+ if (!next.length) return false;
709
+ const nextHead = cleanPathToken(next[0]).replace(/^.*\//, '');
710
+ return PATTERN_VERBS.has(nextHead) && isCountOnlyGrep(next, 0);
711
+ };
712
+
500
713
  const scanBashShapes = (command, depth = 0) => {
501
714
  const found = [];
715
+ const { segments, seps, stripped, heredocBodies } = splitTopLevel(command);
502
716
  // Substitution bodies are extracted BEFORE segment splitting — a `;`
503
717
  // inside `$(…)` belongs to the substitution, not the top level. Each body
504
718
  // is scanned recursively AND its words are classified directly: `cat
505
719
  // $(echo .env)` produces the file via substitution, a route no segment
506
- // split can see.
720
+ // split can see. Quoted heredoc bodies are literal (already dropped);
721
+ // unquoted heredoc bodies still expand `$(…)`/backticks, and quotes there
722
+ // are literal characters, so they are neutralised before extraction.
723
+ const substSources = [stripped, ...heredocBodies.map((b) => b.replace(/["']/g, ' '))];
507
724
  if (depth < MAX_SUBST_DEPTH) {
508
- for (const body of extractSubstBodies(command)) {
725
+ for (const body of substSources.flatMap((s) => extractSubstBodies(s))) {
509
726
  for (const inner of scanBashShapes(body, depth + 1)) found.push(inner);
510
- for (const rawTok of splitShellWords(body)) {
511
- const cleaned = cleanPathToken(rawTok);
512
- const kind = classifySecretFile(cleaned);
513
- if (kind && !pathAllowed(cleaned)) {
514
- found.push({ label: `${kind} referenced in command substitution`, value: cleaned, isPath: true });
727
+ // Per segment: a grep-family PATTERN operand (`grep -x id_rsa`,
728
+ // `grep -E "^\.env"`) is a regexp, not a file; a `jq` path
729
+ // (`.env.FOO`) is a JSON path, not a dotenv file.
730
+ for (const bodySeg of splitTopLevel(body).segments) {
731
+ const segTokens = splitShellWords(bodySeg.trim()).filter((t) => stripQuotes(t) !== '');
732
+ if (!segTokens.length) continue;
733
+ const segHead = cleanPathToken(segTokens[0]).replace(/^.*\//, '');
734
+ const skip = new Set();
735
+ if (PATTERN_VERBS.has(segHead)) {
736
+ const pi = patternOperandIndex(segTokens, 0);
737
+ if (pi !== -1) skip.add(pi);
738
+ for (const ri of regexpOperandIndexes(segTokens, 0)) skip.add(ri);
515
739
  }
740
+ segTokens.forEach((rawTok, ti) => {
741
+ if (skip.has(ti)) return;
742
+ const cleaned = cleanPathToken(rawTok);
743
+ const kind = classifySecretFile(cleaned);
744
+ if (!kind || pathAllowed(cleaned)) return;
745
+ if (segHead === 'jq' && /^\.env\./.test(cleaned)) {
746
+ // jq path into a JSON document: only credential-named fields matter.
747
+ if (JQ_SECRET_FIELD_RE.test(cleaned)) {
748
+ found.push({ label: 'jq path reads a credential field of a JSON document referenced in command substitution', value: cleaned, isPath: true });
749
+ }
750
+ return;
751
+ }
752
+ found.push({ label: `${kind} referenced in command substitution`, value: cleaned, isPath: true });
753
+ });
516
754
  }
517
755
  }
518
756
  }
519
- const segments = command.split(/\|\||&&|;|\||\n/);
520
- for (const rawSegment of segments) {
521
- const segment = rawSegment.trim();
757
+ for (let si = 0; si < segments.length; si += 1) {
758
+ const segment = segments[si].trim();
522
759
  if (!segment) continue;
523
760
  // Shell word semantics: whitespace AND `<`/`>` split words, quoted runs
524
761
  // (`"a b"`), escapes and `${IFS}` separators behave like the shell —
@@ -536,6 +773,7 @@ async function evaluate({ rawInput, projectRoot, env }) {
536
773
  const unquote = stripQuotes;
537
774
 
538
775
  if ((head === 'env' || head === 'printenv' || head === 'history') && tokens.length === 1) {
776
+ if (head !== 'history' && envPipedToCountGrep(segments, seps, si)) continue;
539
777
  found.push({ label: `bare \`${head}\` dumps environment/history (may contain tokens)`, value: segment });
540
778
  continue;
541
779
  }
@@ -674,8 +912,19 @@ async function evaluate({ rawInput, projectRoot, env }) {
674
912
  const headBase = effectiveHead.replace(/^.*\//, '');
675
913
 
676
914
  if (DUMP_VERBS.has(headBase)) {
677
- for (const token of tokens.slice(headIdx + 1)) {
678
- const cleaned = cleanPathToken(token);
915
+ const isPatternVerb = PATTERN_VERBS.has(headBase);
916
+ const patternIdx = isPatternVerb ? patternOperandIndex(tokens, headIdx) : -1;
917
+ const regexpIdx = isPatternVerb ? regexpOperandIndexes(tokens, headIdx) : new Set();
918
+ const countOnly = isPatternVerb && isCountOnlyGrep(tokens, headIdx);
919
+ for (let k = headIdx + 1; k < tokens.length; k += 1) {
920
+ if (k === patternIdx || regexpIdx.has(k) || countOnly) continue;
921
+ const token = tokens[k];
922
+ // Attached pattern-file operand (`--file=.env`, `-f.env`) reads that
923
+ // file: classify the value, not the whole flag word.
924
+ const attachedFile = isPatternVerb
925
+ ? /^(?:--file=|-[^-]*f)(.+)$/.exec(stripQuotes(token))
926
+ : null;
927
+ const cleaned = cleanPathToken(attachedFile ? attachedFile[1] : token);
679
928
  const kind = classifySecretFile(cleaned);
680
929
  if (kind && !pathAllowed(cleaned)) {
681
930
  found.push({ label: `${effectiveHead} reads ${kind}`, value: cleaned, isPath: true });
@@ -789,6 +1038,41 @@ async function evaluate({ rawInput, projectRoot, env }) {
789
1038
  return verdict && Array.isArray(verdict.labels) ? verdict.labels : [];
790
1039
  };
791
1040
 
1041
+ // Fixture/doc keys in a Bash command (heredoc test files, `memory propose`
1042
+ // examples) are not secrets: gitleaks/trufflehog ship the same kind of
1043
+ // stopword/placeholder allowlist. A vendor-shaped match whose body holds an
1044
+ // alphabet/digit run or an obvious placeholder word is neutralised before the
1045
+ // scan; random-looking keys are untouched. Bash channel only.
1046
+ const PLACEHOLDER_KEY_RE = /\b(?:sk-|gh[pousr]_)[A-Za-z0-9_-]{20,}/g;
1047
+ const PLACEHOLDER_WORD_RE = /(claude|secret|canary|example|sample|fake|dummy|placeholder|redacted|changeme|your[_-]?key|x{6,})/gi;
1048
+ // A placeholder word must be a real share of the body (>= 1/4), so a random
1049
+ // key that merely contains "secret" somewhere is not exempted.
1050
+ const placeholderShare = (body) => (body.match(PLACEHOLDER_WORD_RE) || []).join('').length / Math.max(1, body.length);
1051
+ // Longest ascending alphabet/digit run (a-b-c-d..., 1-2-3-4...) in a key body.
1052
+ const longestSequentialRun = (body) => {
1053
+ const lower = body.toLowerCase();
1054
+ let run = 1;
1055
+ let best = 1;
1056
+ for (let i = 1; i < lower.length; i += 1) {
1057
+ const sameClass = /[a-z]/.test(lower[i]) === /[a-z]/.test(lower[i - 1]);
1058
+ run = lower.charCodeAt(i) - lower.charCodeAt(i - 1) === 1 && sameClass && /[a-z0-9]/.test(lower[i]) ? run + 1 : 1;
1059
+ if (run > best) best = run;
1060
+ }
1061
+ return best;
1062
+ };
1063
+ const stripPlaceholderKeys = (text) => {
1064
+ const inHeredoc = text.includes('<<');
1065
+ return text.replace(PLACEHOLDER_KEY_RE, (m) => {
1066
+ // Anthropic-shaped keys are never treated as fixtures.
1067
+ if (/^sk-ant-/i.test(m)) return m;
1068
+ const body = m.replace(/^(?:sk-|gh[pousr]_)/, '');
1069
+ const run = longestSequentialRun(body);
1070
+ // Full-alphabet run (26) is never random; a shorter ascending run only
1071
+ // counts as a fixture inside a heredoc body (test file being written).
1072
+ return placeholderShare(body) >= 0.25 || run >= 26 || (inHeredoc && run >= 8) ? '<placeholder-key>' : m;
1073
+ });
1074
+ };
1075
+
792
1076
  const seenLabels = new Set();
793
1077
  for (const { channel, text } of textChannels) {
794
1078
  for (const label of scanTextLabels(text)) {
@@ -808,7 +1092,7 @@ async function evaluate({ rawInput, projectRoot, env }) {
808
1092
  if (allowedValueHashes.has(sha256(finding.value))) continue;
809
1093
  findings.push({ label: `${finding.label} in bash command`, value: finding.value });
810
1094
  }
811
- for (const label of scanTextLabels(bashCommand)) {
1095
+ for (const label of scanTextLabels(stripPlaceholderKeys(bashCommand))) {
812
1096
  const key = `bash:${label}`;
813
1097
  if (seenLabels.has(key)) continue;
814
1098
  seenLabels.add(key);
@@ -35,12 +35,12 @@ if source "$SCRIPT_DIR/../ukit/runtime/hook-input.sh" 2>/dev/null; then
35
35
  # runtime (pre-install tree) simply leaves telemetry off.
36
36
  source "$SCRIPT_DIR/../ukit/runtime/hook-telemetry.sh" 2>/dev/null || true
37
37
  trap ukit_cleanup_hook_input EXIT
38
- # Bounded stdin (H01): the 64 KiB cap is preserved, but the payload now travels
38
+ # Bounded stdin (H01): the cap is 2 MiB like the other Stop hooks, but the payload now travels
39
39
  # as a staged file path — never through the exec environment, so an oversized
40
40
  # input can no longer stop node from starting (E2BIG) or stall the wrapper in
41
41
  # `cat`. A truncated payload simply fails JSON.parse inside node → {} → silent
42
42
  # degrade exit 0 (documented posture).
43
- ukit_stage_hook_input 65536 truncate
43
+ ukit_stage_hook_input 2097152 truncate
44
44
  __ukit_main_stage_rc=$?
45
45
  if [ "$__ukit_main_stage_rc" -ne 0 ]; then
46
46
  # Infra failure during staging (mktemp/truncate): payload was never
@@ -48,7 +48,7 @@ source "$SCRIPT_DIR/../ukit/runtime/hook-telemetry.sh" 2>/dev/null || true
48
48
  ukit_emit_input_degraded advisory "task-watchdog"
49
49
  fi
50
50
  # BUG-C21-01: a truncated/stalled staged payload must be announced (SPEC §8), never silently passed.
51
- # Exception: a payload cut ONLY by the 64 KiB size cap (not a stall) for PostToolUse. That path reads
51
+ # Exception: a payload cut ONLY by the 2 MiB size cap (not a stall) for PostToolUse. That path reads
52
52
  # nothing but hook_event_name from the payload (tasks/state/config all come from disk), so a size-truncated
53
53
  # payload is not incomplete for this hook. The event name is recovered only when provably complete
54
54
  # (ukit_salvage_tool_field); anything else - stall, unrecoverable name, non-PostToolUse (Stop forwards the
@@ -62,16 +62,16 @@ if ukit_input_degraded; then
62
62
  [ -n "$UKIT_WD_SALVAGED_EVENT" ] || ukit_emit_input_degraded advisory "task-watchdog"
63
63
  fi
64
64
  else
65
- # 64 KiB cap and the advisory degrade path alive.
65
+ # 2 MiB cap and the advisory degrade path alive.
66
66
  # Runtime helper missing (pre-install tree): the SAME bounded staging,
67
67
  # inline - `cat >/dev/null` used to block forever on a producer that never
68
68
  # closes the pipe (R4.5). Read cap+1 in the background, bound the wait.
69
69
  UKIT_INPUT_FILE="$(mktemp "${TMPDIR:-/tmp}/ukit-hook-in.XXXXXX")"
70
70
  if [ -e /dev/fd/0 ]; then
71
71
  exec 8<&0
72
- head -c 65537 <&8 > "$UKIT_INPUT_FILE" 2>/dev/null &
72
+ head -c 2097153 <&8 > "$UKIT_INPUT_FILE" 2>/dev/null &
73
73
  else
74
- head -c 65537 > "$UKIT_INPUT_FILE" 2>/dev/null &
74
+ head -c 2097153 > "$UKIT_INPUT_FILE" 2>/dev/null &
75
75
  fi
76
76
  __ukit_reader=$!
77
77
  __ukit_stage_ms="${UKIT_HOOK_STAGE_MS:-2000}"
@@ -88,7 +88,7 @@ else
88
88
  wait "$__ukit_waiter" 2>/dev/null
89
89
  exec 8<&-
90
90
  __ukit_size="$(wc -c < "$UKIT_INPUT_FILE" 2>/dev/null | tr -d '[:space:]')"
91
- if [ "$__ukit_stage_rc" -ne 0 ] || [ "$__ukit_size" -gt 65536 ]; then
91
+ if [ "$__ukit_stage_rc" -ne 0 ] || [ "$__ukit_size" -gt 2097152 ]; then
92
92
  # BUG-C21-01 fallback parity (SPEC §8): a truncated/stalled staged payload
93
93
  # must be announced, never silently acted on — same shape as the helper
94
94
  # path's ukit_emit_input_degraded.
@@ -243,13 +243,7 @@ async function main() {
243
243
  const result = await verifyPostEdit({ projectRoot, payload });
244
244
  if (json) {
245
245
  process.stdout.write(`${JSON.stringify(result)}\n`);
246
- } else if (result.status === 'ok') {
247
- // A plain-text line would make the chain's merged stdout invalid JSON and Claude Code
248
- // would drop a later step's additionalContext (edit-hint). omp's bridge appends step
249
- // stdout verbatim to the tool result, so omp keeps the plain line.
250
- const line = `[ukit-safe-patch] ${result.message}`;
251
- if (payload?.ukit_harness === 'omp' || process.env.UKIT_HARNESS === 'omp') process.stdout.write(`${line}\n`);
252
- else emitSystemMessage(line);
246
+ // status 'ok' is silent: exit 0 with no output (Claude Code hook convention; 798x field noise).
253
247
  } else if (result.status === 'advisory') {
254
248
  process.stderr.write(`[ukit-safe-patch] ${result.message}\n`);
255
249
  process.stderr.write('[ukit-safe-patch] handoff authoring advisory — change is already written; continue updating docs/AI_HANDOFF/.\n');
@@ -276,6 +270,8 @@ async function main() {
276
270
 
277
271
  if (process.argv[1] && path.basename(fileURLToPath(import.meta.url)) === path.basename(process.argv[1])) {
278
272
  main().catch((error) => {
273
+ // OS temp scratch targets are never project scope: skip silently.
274
+ if (error?.osTemp) process.exit(0);
279
275
  process.stderr.write(`[ukit-safe-patch] post-edit ERROR: ${error?.message || error}\n`);
280
276
  // BUG-C23-01: stderr-only crash announces nothing to the user — §8 requires
281
277
  // the paired stdout systemMessage before the non-zero exit.
@@ -90,6 +90,7 @@ async function main() {
90
90
 
91
91
  if (process.argv[1] && path.basename(fileURLToPath(import.meta.url)) === path.basename(process.argv[1])) {
92
92
  main().catch((error) => {
93
+ if (error?.osTemp) process.exit(0); // OS temp scratch target: silent skip
93
94
  process.stderr.write(`[ukit-safe-patch] backup ERROR: ${error?.message || error}\n`);
94
95
  process.exit(1);
95
96
  });
@@ -1551,13 +1551,13 @@ async function runCli() {
1551
1551
  if (nextState?.phase === 'hard') {
1552
1552
  process.stdout.write(
1553
1553
  `[ukit-skill-router] Context pressure: hard (est ${nextState.estimatedTotalTokens} / soft ${nextState.softThreshold} / hard ${nextState.hardThreshold}). `
1554
- + 'FIRST THING IN YOUR REPLY, tell the user plainly — do not stay silent: "Context sắp đầy — hãy gõ /compact ngay bây giờ (run /compact now)". '
1555
- + 'Then hold heavy work: no new investigations, subagents, or large edits until the user has compacted.\n',
1554
+ + 'Do NOT end the turn to ask the user for /compact — keep working: land the step in flight, persist remaining steps to docs/STATUS.md, '
1555
+ + 'delegate broad reads/searches to subagents, and continue the task. The host auto-compacts and UKit resumes from disk.\n',
1556
1556
  );
1557
1557
  } else if (nextState?.phase === 'soft') {
1558
1558
  process.stdout.write(
1559
1559
  `[ukit-skill-router] Context pressure: soft (est ${nextState.estimatedTotalTokens} / soft ${nextState.softThreshold} / hard ${nextState.hardThreshold}). `
1560
- + 'Finish the current step, then tell the user to run /compact at the next natural pause instead of continuing indefinitely.\n',
1560
+ + 'Keep working; keep replies and reads lean and persist progress to docs/STATUS.md so a host auto-compact resumes cleanly.\n',
1561
1561
  );
1562
1562
  }
1563
1563
  }