@ngockhoale/ukit 2.3.7 → 2.3.8

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.
@@ -43,6 +43,30 @@ async function main() {
43
43
  ? process.env.CLAUDE_PROJECT_DIR
44
44
  : process.cwd();
45
45
  const config = await loadRuntimeConfig(projectRoot);
46
+ // Session-scoped pressure bookkeeping: this PreCompact run must zero ONLY the calling
47
+ // session's record. Reading stdin here is safe — the harness payload is modest and this
48
+ // process owns it exclusively.
49
+ const rawHookInput = await (async () => {
50
+ if (process.stdin.isTTY) return '';
51
+ const chunks = [];
52
+ for await (const chunk of process.stdin) {
53
+ chunks.push(typeof chunk === 'string' ? chunk : chunk.toString('utf8'));
54
+ }
55
+ return chunks.join('');
56
+ })();
57
+ const hookPayload = (() => {
58
+ try {
59
+ return JSON.parse(rawHookInput || '{}');
60
+ } catch {
61
+ return {};
62
+ }
63
+ })();
64
+ const sessionConfig = {
65
+ ...config,
66
+ sessionId: typeof hookPayload.session_id === 'string' && hookPayload.session_id.trim()
67
+ ? hookPayload.session_id.trim()
68
+ : undefined,
69
+ };
46
70
  const state = await loadFreshRouteState(projectRoot);
47
71
  const compressEnabled = shouldCompress(config);
48
72
  const header = '=== PROJECT CONTEXT (post-compaction) ===';
@@ -67,15 +91,16 @@ async function main() {
67
91
 
68
92
  const rawBodyLines = [...rawStaticLines, ...dynamicLines];
69
93
  const bodyLines = [...staticLines, ...dynamicLines];
70
- const pressureState = await readCompactPressureState(projectRoot, config);
94
+ const pressureState = await readCompactPressureState(projectRoot, sessionConfig);
71
95
 
72
96
  // Reset the hard-cap tracker as early as possible: this hook fires on every real
73
97
  // compaction, and it is the only signal that context actually shrank. It must happen
74
98
  // before the promptCache early-return below, otherwise a cache hit would skip it and
75
99
  // leave context-hardcap-gate.sh permanently tripped. Downstream writes
76
100
  // (writeThresholdCompactPlan) re-read from disk, so they build on the zeroed state and
77
- // keep their own stats increments intact.
78
- await writeCompactPressureState(projectRoot, resetCompactPressureState(pressureState, config), config);
101
+ // keep their own stats increments intact. Session-scoped: sibling sessions keep their
102
+ // own records.
103
+ await writeCompactPressureState(projectRoot, resetCompactPressureState(pressureState, sessionConfig), sessionConfig);
79
104
  const anchorLines = dynamicLines.filter((line) => (
80
105
  line.startsWith('- Recent routed lane:')
81
106
  || line.startsWith('- Current approach:')
@@ -153,7 +178,8 @@ async function main() {
153
178
  tokensBefore: compactedBody.tokensBefore,
154
179
  tokensAfter: compactedBody.tokensAfter,
155
180
  savedTokens: compactedBody.savedTokens,
156
- }, config);
181
+ sessionId: sessionConfig.sessionId,
182
+ }, sessionConfig);
157
183
  }
158
184
 
159
185
  const compactSource = thresholdPlan.active