@ngockhoale/ukit 2.2.8 → 2.2.9
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 +34 -0
- package/README.md +30 -0
- package/package.json +1 -1
- package/src/core/compact/contextBudget.js +57 -0
- package/src/core/compact/threshold.js +5 -1
- package/src/core/runtimeConfig.js +2 -1
- package/src/render/buildVariables.js +10 -0
- package/templates/.claude/settings.json +1 -1
- package/templates/.claude/ukit/runtime/compact-threshold.mjs +10 -8
- package/templates/.omp/config.yml +6 -3
- package/templates/docs/AI_HANDOFF/RULES.md +2 -2
- package/templates/ukit/storage/config.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to UKit are documented here.
|
|
4
4
|
|
|
5
|
+
## 2.2.9 - 2026-08-28
|
|
6
|
+
|
|
7
|
+
Retuning UKit's context budget used to mean editing five scattered places and hand-syncing two
|
|
8
|
+
of them. It is now **three numbers in one file**, and everything else is derived at install time.
|
|
9
|
+
|
|
10
|
+
The shipped defaults also move up for a 1M context window: compaction is recommended at 150,000
|
|
11
|
+
estimated tokens (was 50,000) and the hard cap sits at 500,000 — half the window (was 220,000).
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- **`compact.tokenThreshold` / `compact.hardCapTokens` / `compact.autoCompactWindowRatio` in
|
|
16
|
+
`.ukit/storage/config.json` are now the only knobs.** New `src/core/compact/contextBudget.js`
|
|
17
|
+
reads them and derives the rest, so the defaults in `runtimeConfig.js` and
|
|
18
|
+
`compact/threshold.js` no longer carry their own copies of the number. Edit the three values,
|
|
19
|
+
rerun `ukit install`, and the whole budget follows. Documented in README →
|
|
20
|
+
*Retuning The Context Budget (maintainers)*, including a window→cap sizing table, because the
|
|
21
|
+
new 500,000 default sits **above** a 200k or 256k model's window, where the gate could never fire.
|
|
22
|
+
- **New defaults:** `tokenThreshold` 50,000 → **150,000**; `hardCapTokens` 220,000 → **500,000**;
|
|
23
|
+
auto-compact fires at **70%** of the cap → 350,000.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **omp auto-compact had silently drifted out of sync.** `.omp/config.yml`'s
|
|
28
|
+
`compaction.thresholdTokens` was still 180,000 while Claude Code's
|
|
29
|
+
`CLAUDE_CODE_AUTO_COMPACT_WINDOW` had moved on — the two were separate hand-maintained numbers
|
|
30
|
+
with nothing pinning them together. Both are now rendered from the same derived value at
|
|
31
|
+
install time, so **omp and Claude Code auto-compact at the same point** and cannot drift apart
|
|
32
|
+
again.
|
|
33
|
+
- **`ompDocsSync > historical records are untouched by this cycle` failed on every new plan doc.**
|
|
34
|
+
The guard compared *all* changes under `docs/plans/` and friends against an old cycle's base
|
|
35
|
+
commit, so the first plan added afterwards (2.2.8's) tripped it permanently. Narrowed to
|
|
36
|
+
`--diff-filter=MDR`: rewriting, deleting or renaming a historical record still fails; adding a
|
|
37
|
+
new plan does not.
|
|
38
|
+
|
|
5
39
|
## 2.2.8 - 2026-08-28
|
|
6
40
|
|
|
7
41
|
UKit already picked the right files to open, but the step *after* that — actually entering the
|
package/README.md
CHANGED
|
@@ -114,6 +114,36 @@ For maintainers, the runtime is inspectable with:
|
|
|
114
114
|
|
|
115
115
|
Normal teammates should still only need **`ukit install`**.
|
|
116
116
|
|
|
117
|
+
## Retuning The Context Budget (maintainers)
|
|
118
|
+
|
|
119
|
+
Switching to a model with a different context window is a **three-number edit in one file**:
|
|
120
|
+
`templates/ukit/storage/config.json` → `compact`.
|
|
121
|
+
|
|
122
|
+
| Key | Default | What it means |
|
|
123
|
+
| --- | --- | --- |
|
|
124
|
+
| `tokenThreshold` | `150000` | Soft advisory. Past this UKit starts recommending compaction. |
|
|
125
|
+
| `hardCapTokens` | `500000` | Absolute ceiling — 50% of a 1M window. `context-hardcap-gate` blocks Edit/Write/Bash here. |
|
|
126
|
+
| `autoCompactWindowRatio` | `0.7` | Auto-compact fires at this fraction of the cap (→ `350000`). Must be `< 1`. |
|
|
127
|
+
|
|
128
|
+
Everything else is derived — do **not** hand-edit these:
|
|
129
|
+
|
|
130
|
+
- `.claude/settings.json` → `env.CLAUDE_CODE_AUTO_COMPACT_WINDOW`
|
|
131
|
+
- `.omp/config.yml` → `compaction.thresholdTokens`
|
|
132
|
+
- the code-side defaults in `src/core/runtimeConfig.js` and `src/core/compact/threshold.js`
|
|
133
|
+
|
|
134
|
+
They are all rendered/read from the three keys above via `src/core/compact/contextBudget.js`.
|
|
135
|
+
Edit the three numbers, rerun **`ukit install`**, and Claude Code and omp both follow.
|
|
136
|
+
|
|
137
|
+
`hardCapTokens` must stay **below the model's real context window**, otherwise the API rejects
|
|
138
|
+
the request before the gate can ever fire. Sizing at 50% of the window keeps room for the
|
|
139
|
+
response plus the estimator's own undercount:
|
|
140
|
+
|
|
141
|
+
| Model window | `hardCapTokens` | derived auto-compact |
|
|
142
|
+
| --- | --- | --- |
|
|
143
|
+
| 1M | `500000` | `350000` |
|
|
144
|
+
| 256k | `128000` | `89600` |
|
|
145
|
+
| 200k | `100000` | `70000` |
|
|
146
|
+
|
|
117
147
|
## Installer Behavior
|
|
118
148
|
|
|
119
149
|
- idempotent install (safe to rerun)
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
// The shipped compact.tokenThreshold / compact.hardCapTokens / compact.autoCompactWindowRatio
|
|
5
|
+
// trio is the ONLY place the context budget is written down. Every other number — the
|
|
6
|
+
// code-side defaults, CLAUDE_CODE_AUTO_COMPACT_WINDOW in .claude/settings.json, and
|
|
7
|
+
// compaction.thresholdTokens in .omp/config.yml — is read or derived from here, so retuning
|
|
8
|
+
// UKit for a different model context window is a three-number edit in
|
|
9
|
+
// templates/ukit/storage/config.json and nothing else.
|
|
10
|
+
const SHIPPED_CONFIG_URL = new URL('../../../templates/ukit/storage/config.json', import.meta.url);
|
|
11
|
+
|
|
12
|
+
// Only reachable if the package ships without its own templates. Deliberately conservative:
|
|
13
|
+
// a 200k model survives these, a 1M model merely compacts earlier than it had to.
|
|
14
|
+
const EMERGENCY_BUDGET = {
|
|
15
|
+
tokenThreshold: 50_000,
|
|
16
|
+
hardCapTokens: 160_000,
|
|
17
|
+
autoCompactWindowRatio: 0.7,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Auto-compact must land strictly below hardCapTokens so the client heals itself before
|
|
21
|
+
// context-hardcap-gate starts refusing Edit/Write/Bash; a ratio >= 1 would invert that and is
|
|
22
|
+
// treated as a typo rather than honoured.
|
|
23
|
+
export function deriveAutoCompactWindow(hardCapTokens, ratio) {
|
|
24
|
+
const safeRatio = Number.isFinite(ratio) && ratio > 0 && ratio < 1
|
|
25
|
+
? ratio
|
|
26
|
+
: EMERGENCY_BUDGET.autoCompactWindowRatio;
|
|
27
|
+
return Math.round(hardCapTokens * safeRatio);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let cachedBudget = null;
|
|
31
|
+
|
|
32
|
+
export function loadShippedCompactBudget() {
|
|
33
|
+
if (cachedBudget) {
|
|
34
|
+
return cachedBudget;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let compact = EMERGENCY_BUDGET;
|
|
38
|
+
try {
|
|
39
|
+
compact = JSON.parse(readFileSync(fileURLToPath(SHIPPED_CONFIG_URL), 'utf8')).compact ?? {};
|
|
40
|
+
} catch {
|
|
41
|
+
compact = EMERGENCY_BUDGET;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const tokenThreshold = Number.isFinite(compact.tokenThreshold)
|
|
45
|
+
? compact.tokenThreshold
|
|
46
|
+
: EMERGENCY_BUDGET.tokenThreshold;
|
|
47
|
+
const hardCapTokens = Number.isFinite(compact.hardCapTokens)
|
|
48
|
+
? compact.hardCapTokens
|
|
49
|
+
: EMERGENCY_BUDGET.hardCapTokens;
|
|
50
|
+
|
|
51
|
+
cachedBudget = {
|
|
52
|
+
tokenThreshold,
|
|
53
|
+
hardCapTokens,
|
|
54
|
+
autoCompactWindow: deriveAutoCompactWindow(hardCapTokens, compact.autoCompactWindowRatio),
|
|
55
|
+
};
|
|
56
|
+
return cachedBudget;
|
|
57
|
+
}
|
|
@@ -2,6 +2,7 @@ import { readJsonIfExists, writeJson } from '../fileOps.js';
|
|
|
2
2
|
import { buildRuntimePaths } from '../runtimePaths.js';
|
|
3
3
|
import { buildCompactMachineKey, compressLine, estimateTokenCount } from '../token/index.js';
|
|
4
4
|
import { compactContextBlock } from './index.js';
|
|
5
|
+
import { loadShippedCompactBudget } from './contextBudget.js';
|
|
5
6
|
|
|
6
7
|
const DEFAULT_MAX_PROMPT_ENTRIES = 12;
|
|
7
8
|
const DEFAULT_MAX_OUTPUT_ENTRIES = 12;
|
|
@@ -427,7 +428,10 @@ function computeEstimatedTotalTokens({
|
|
|
427
428
|
}
|
|
428
429
|
|
|
429
430
|
export function buildCompactThresholds(config = {}) {
|
|
430
|
-
const softThreshold = Math.max(
|
|
431
|
+
const softThreshold = Math.max(
|
|
432
|
+
1,
|
|
433
|
+
finiteNumber(config?.compact?.tokenThreshold, loadShippedCompactBudget().tokenThreshold),
|
|
434
|
+
);
|
|
431
435
|
const hardThreshold = Math.max(softThreshold + 1, Math.round(softThreshold * 1.6));
|
|
432
436
|
const baselineTokens = Math.max(120, Math.min(18_000, Math.round(softThreshold * 0.18)));
|
|
433
437
|
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { buildRuntimePaths } from './runtimePaths.js';
|
|
5
|
+
import { loadShippedCompactBudget } from './compact/contextBudget.js';
|
|
5
6
|
|
|
6
7
|
const require = createRequire(import.meta.url);
|
|
7
8
|
const { version: PACKAGE_VERSION } = require('../../package.json');
|
|
@@ -70,7 +71,7 @@ export function buildDefaultRuntimeConfig(overrides = {}) {
|
|
|
70
71
|
},
|
|
71
72
|
compact: {
|
|
72
73
|
enabled: true,
|
|
73
|
-
tokenThreshold:
|
|
74
|
+
tokenThreshold: loadShippedCompactBudget().tokenThreshold,
|
|
74
75
|
contextRotDetection: true,
|
|
75
76
|
askBeforeDrop: true,
|
|
76
77
|
agentContext: {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { loadShippedCompactBudget } from '../core/compact/contextBudget.js';
|
|
2
|
+
|
|
1
3
|
const CODEGRAPH_SECTION = `
|
|
2
4
|
## CodeGraph Integration (active)
|
|
3
5
|
|
|
@@ -12,7 +14,15 @@ To disable: rerun \`ukit install\` without \`--with-codegraph\`.
|
|
|
12
14
|
`;
|
|
13
15
|
|
|
14
16
|
export function buildTemplateVariables({ projectContext, stackContext, packageVersion, providerContext, withCodegraph = false }) {
|
|
17
|
+
// Derived, never hand-written: .claude/settings.json is read by Claude Code itself and so
|
|
18
|
+
// cannot consult .ukit/storage/config.json at runtime. Baking the window in here keeps
|
|
19
|
+
// compact.hardCapTokens the single number that retunes both.
|
|
20
|
+
const { autoCompactWindow } = loadShippedCompactBudget();
|
|
21
|
+
|
|
15
22
|
return {
|
|
23
|
+
compact: {
|
|
24
|
+
autoCompactWindow: String(autoCompactWindow),
|
|
25
|
+
},
|
|
16
26
|
project: {
|
|
17
27
|
name: projectContext.project.name,
|
|
18
28
|
root: projectContext.project.root,
|
|
@@ -434,7 +434,7 @@ function computeEstimatedTotalTokens({
|
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
export function buildCompactThresholds(config = {}) {
|
|
437
|
-
const softThreshold = Math.max(1, finiteNumber(config?.compact?.tokenThreshold,
|
|
437
|
+
const softThreshold = Math.max(1, finiteNumber(config?.compact?.tokenThreshold, 150_000));
|
|
438
438
|
const hardThreshold = Math.max(softThreshold + 1, Math.round(softThreshold * 1.6));
|
|
439
439
|
const baselineTokens = Math.max(120, Math.min(18_000, Math.round(softThreshold * 0.18)));
|
|
440
440
|
// Deliberately NOT coupled to hardThreshold: this is an absolute ceiling, so raising
|
|
@@ -442,13 +442,15 @@ export function buildCompactThresholds(config = {}) {
|
|
|
442
442
|
//
|
|
443
443
|
// Must stay BELOW the model's real context window or the cap is unreachable: the API
|
|
444
444
|
// rejects the request with "input exceeds the context window" long before an estimate
|
|
445
|
-
// climbing toward a higher number ever trips this.
|
|
446
|
-
//
|
|
447
|
-
// model this default sits ABOVE the window, so the gate can never fire and is
|
|
448
|
-
// in exactly the situation it exists to prevent — set compact.hardCapTokens to
|
|
449
|
-
//
|
|
450
|
-
//
|
|
451
|
-
|
|
445
|
+
// climbing toward a higher number ever trips this. 500_000 is half of a 1M window, which
|
|
446
|
+
// leaves ample headroom for the response plus the estimator's own undercount. On any
|
|
447
|
+
// smaller model this default sits ABOVE the window, so the gate can never fire and is
|
|
448
|
+
// dead code in exactly the situation it exists to prevent — set compact.hardCapTokens to
|
|
449
|
+
// 100_000 (200k model) or 128_000 (256k model) for those. Both
|
|
450
|
+
// env.CLAUDE_CODE_AUTO_COMPACT_WINDOW and omp's compaction.thresholdTokens are rendered
|
|
451
|
+
// from this number at install time (70% of it), so the client auto-compacts before the
|
|
452
|
+
// gate blocks tools without anyone hand-syncing a second value.
|
|
453
|
+
const hardCapTokens = Math.max(1, finiteNumber(config?.compact?.hardCapTokens, 500_000));
|
|
452
454
|
|
|
453
455
|
return {
|
|
454
456
|
softThreshold,
|
|
@@ -78,8 +78,11 @@ memory:
|
|
|
78
78
|
backend: off
|
|
79
79
|
|
|
80
80
|
# Auto-compact must trigger BEFORE context-hardcap-gate.sh starts blocking tool
|
|
81
|
-
# calls (compact.hardCapTokens, default
|
|
82
|
-
# env.CLAUDE_CODE_AUTO_COMPACT_WINDOW
|
|
81
|
+
# calls (compact.hardCapTokens, default 500000). Rendered at install time from the
|
|
82
|
+
# same derived number as env.CLAUDE_CODE_AUTO_COMPACT_WINDOW in
|
|
83
|
+
# templates/.claude/settings.json (70% of hardCapTokens), so omp and Claude Code
|
|
84
|
+
# cannot drift apart and retuning both is a single edit to
|
|
85
|
+
# templates/ukit/storage/config.json.
|
|
83
86
|
#
|
|
84
87
|
# Key VERIFIED against omp v17.4.2 (2026-08-22): `compaction.thresholdTokens` is a
|
|
85
88
|
# fixed token limit for context maintenance and overrides the percentage threshold
|
|
@@ -88,4 +91,4 @@ memory:
|
|
|
88
91
|
# omp rejects it outright (`omp config get compact.autoCompactWindow` → "Unknown
|
|
89
92
|
# setting"), so auto-compact never moved off omp's default. See PLAN.md §3 D13.
|
|
90
93
|
compaction:
|
|
91
|
-
thresholdTokens:
|
|
94
|
+
thresholdTokens: {{compact.autoCompactWindow}}
|
|
@@ -79,8 +79,8 @@ Next: <bước kế tiếp chính xác>
|
|
|
79
79
|
- Subagent ghi **full log vào task file trên đĩa**, chỉ trả về orchestrator ≤10 dòng (executor) / ≤6 dòng (reviewer). Paste log ngược lại orchestrator là nguyên nhân số 1 làm run chết vì hết context.
|
|
80
80
|
- Hết mỗi wave: commit, ghi cursor, **collapse** wave đó còn 1 dòng/task trong bộ nhớ làm việc, rồi chạy tiếp.
|
|
81
81
|
- Yêu cầu `/compact` **chỉ** được đặt ở cuối command, giữa 2 cycle. Giữa cycle thì tuyệt đối không — state đã nằm hết ở git + `INDEX.md` + `RUN.md` nên compact ở ranh giới cycle không mất gì.
|
|
82
|
-
- Vượt `compact.hardCapTokens` (mặc định
|
|
83
|
-
- Không hook nào gọi được `/compact` — đó là lệnh client-only. Nhưng từ 2.1.3, settings mặc định đặt `env.CLAUDE_CODE_AUTO_COMPACT_WINDOW =
|
|
82
|
+
- Vượt `compact.hardCapTokens` (mặc định 500k = 50% của context window 1M) mà `RUN.md` còn run dở: `context-hardcap-gate` cho thêm `compact.hardCapGraceCalls` (mặc định 10) tool call rồi mới chặn cứng. **Grace đó chỉ để hạ cánh** — hoàn tất edit đang dở, commit, ghi cursor, push. Không mở task mới, không đọc thêm file, không spawn agent. Hết grace là chặn thật; budget chỉ reset khi ước lượng token thực sự giảm (có compact thật), không reset theo wave.
|
|
83
|
+
- Không hook nào gọi được `/compact` — đó là lệnh client-only. Nhưng từ 2.1.3, settings mặc định đặt `env.CLAUDE_CODE_AUTO_COMPACT_WINDOW` = 70% của `hardCapTokens` (mặc định 350000 < 500k), render lúc install, nên **client tự auto-compact trước khi gate chặn**. Đường thường: auto-compact chạy → `handoff-resume.sh` replay cursor → chạy tiếp, không cần người gõ gì. Grace window ở trên chỉ còn là lưới an toàn.
|
|
84
84
|
- Sửa một trong hai số đó thì phải giữ `autoCompactWindow < hardCapTokens`. Đảo thứ tự là deadlock: gate chặn tool trước → transcript ngừng lớn → ngưỡng auto-compact không bao giờ tới. `tests/core/autoCompactWindow.test.js` khóa bất biến này.
|
|
85
85
|
|
|
86
86
|
### Git
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
},
|
|
9
9
|
"compact": {
|
|
10
10
|
"enabled": true,
|
|
11
|
-
"tokenThreshold":
|
|
12
|
-
"hardCapTokens":
|
|
11
|
+
"tokenThreshold": 150000,
|
|
12
|
+
"hardCapTokens": 500000,
|
|
13
|
+
"autoCompactWindowRatio": 0.7,
|
|
13
14
|
"hardCapBlock": true,
|
|
14
15
|
"hardCapGraceCalls": 10,
|
|
15
16
|
"contextRotDetection": true,
|
|
@@ -394,7 +395,8 @@
|
|
|
394
395
|
"compact": {
|
|
395
396
|
"enabled": "Bật/tắt toàn bộ helper compact của UKit.",
|
|
396
397
|
"tokenThreshold": "Ngưỡng token chung cho runtime compact dùng chung.",
|
|
397
|
-
"hardCapTokens": "Ngưỡng cứng tuyệt đối (mặc định
|
|
398
|
+
"hardCapTokens": "Ngưỡng cứng tuyệt đối (mặc định 500000 token ước lượng = 50% của context window 1M). Chạm/vượt ngưỡng này thì context coi như quá dài — không phải gợi ý nữa, là bắt buộc. PHẢI thấp hơn context window thật của model, nếu không API sẽ báo lỗi vượt context trước khi gate kịp chặn — model 200k thì hạ xuống 100000, model 256k thì 128000. Cả env.CLAUDE_CODE_AUTO_COMPACT_WINDOW (.claude/settings.json) lẫn compaction.thresholdTokens (.omp/config.yml) đều được SUY RA từ số này khi chạy ukit install, nên chỉ cần sửa ở đây rồi cài lại là auto-compact của cả Claude Code và omp đổi theo.",
|
|
399
|
+
"autoCompactWindowRatio": "Auto-compact chạy ở bao nhiêu phần của hardCapTokens (mặc định 0.7 → 350000). Phải < 1 để client tự compact TRƯỚC khi context-hardcap-gate chặn tool; số càng nhỏ thì compact càng sớm và càng nhiều đệm an toàn.",
|
|
398
400
|
"hardCapBlock": "Nếu true, hook context-hardcap-gate chặn cứng Edit/Write/Bash (exit 2) khi vượt hardCapTokens, cho tới khi có compact thật (PreCompact) reset lại bộ đếm.",
|
|
399
401
|
"hardCapGraceCalls": "Số tool call được phép chạy tiếp sau khi vượt hardCapTokens KHI docs/AI_HANDOFF/RUN.md còn run dở (mặc định 10). Dùng để run kịp commit + ghi cursor + push rồi mới bị chặn, thay vì chết giữa lúc đang Edit. Hết grace là chặn cứng như cũ. Budget tính theo mỗi đợt vượt cap, chỉ reset khi ước lượng token thật sự giảm (có compact thật) — không reset theo wave.",
|
|
400
402
|
"contextRotDetection": "Phát hiện context quá dài/dễ mục để giữ lại state quan trọng trước khi AI nhớ sai.",
|