@kienntpixon/dieu-phoi 0.5.0 → 0.5.1

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog — @kienntpixon/dieu-phoi
2
2
 
3
+ ## 0.5.1
4
+
5
+ Nâng ngưỡng watchdog ngữ cảnh subagent 150k/180k -> 200k/230k. Đo thí điểm: sonnet exec với `autoCompactWindow: 200000` tự nén ở 167.370 (~0,837 cửa sổ) — nén TRƯỚC khi lời nhắc 200k kịp tới.
6
+
7
+ - **Ngưỡng cấu hình được, không sửa code:** env `DIEU_PHOI_WATCH_WARN` / `DIEU_PHOI_WATCH_HARD`, hoặc `watch_warn` / `watch_hard` trong `<home>/config.json`; đọc lại mỗi lần hook chạy nên subagent đang chạy cũng nhận (env chỉ đổi được với tiến trình mới; config.json đổi tức thì). Giá trị < 20000 / không phải số bị bỏ qua.
8
+ - **`autoCompactWindow: 300000`** trong cả 4 `agents/dp-*.md` (nén ~251k theo tỉ lệ, ~267k theo độ lệch, đều cao hơn 230k >= 20k). Chạy lại `dieu-phoi setup`. Agent đã chạy giữ cửa sổ cũ tới khi kết thúc.
9
+
3
10
  ## 0.5.0
4
11
 
5
12
  Giới hạn ngữ cảnh subagent (đo trên 429 subagent từ 2026-10-09: p50 đỉnh 144k, p90 373k, max 789k; lượt >128k = 83% chi phí; subagent không bao giờ tự nén vì chạy cửa sổ 1M).
package/README.md CHANGED
@@ -29,7 +29,7 @@ Không cài toàn cục được thì dùng `npx -y @kienntpixon/dieu-phoi <lệ
29
29
  1. chép `hook.cjs` + `pricing.json` vào `~/.claude/dieu-phoi/bin/`;
30
30
  2. sao lưu `~/.claude/settings.json` thành `settings.json.bak-dieu-phoi-<thời gian>` rồi đăng ký `PostToolUse` (matcher `Agent`) và `SubagentStop` chạy `"<đường dẫn node>" "<…>/dieu-phoi/bin/hook.cjs"` (node tuyệt đối, không phụ thuộc PATH). Các hook và khoá khác giữ nguyên, kể cả mảng/đối tượng rỗng. Chạy lại khi hook đã đúng thì không ghi file, không tạo bản sao lưu. Đổi phiên bản node (nvm…) thì chạy lại `setup`;
31
31
  3. ghi `~/.claude/dieu-phoi/config.json` (phòng ban, sink, đường dẫn skill, mã băm người dùng). Thư mục skill tự dò: `<claude>/skills/dieu-phoi`, hoặc thư mục `<claude>/skills/*` có `profile/profile.json` và `SKILL.md` mang `name: dieu-phoi` (fork phòng ban đổi tên thư mục vẫn tìm được).
32
- 4. (0.5.0) ghi `~/.claude/agents/dp-exec.md`, `dp-verify.md`, `dp-scout.md`, `dp-helper.md` (`autoCompactWindow: 200000`, hook watchdog ngữ cảnh + cổng helper gen-2 trong frontmatter — chỉ chạy khi điều phối viên giao bằng các loại agent này). File trùng tên không phải của dieu-phoi được giữ nguyên.
32
+ 4. (0.5.0) ghi `~/.claude/agents/dp-exec.md`, `dp-verify.md`, `dp-scout.md`, `dp-helper.md` (`autoCompactWindow: 300000`, hook watchdog ngữ cảnh + cổng helper gen-2 trong frontmatter — chỉ chạy khi điều phối viên giao bằng các loại agent này). File trùng tên không phải của dieu-phoi được giữ nguyên.
33
33
 
34
34
  Khởi động lại Claude Code sau khi cài. Kiểm tra bằng `dieu-phoi doctor` (chạy thử chính lệnh hook đã đăng ký).
35
35
 
package/agents/dp-exec.md CHANGED
@@ -2,7 +2,8 @@
2
2
  name: dp-exec
3
3
  description: "dieu-phoi only — executor subagent dispatched by the dieu-phoi orchestrator with a [dp:...] brief. Do not pick this agent on your own."
4
4
  # dieu-phoi-managed: do not edit (dieu-phoi setup rewrites this file)
5
- autoCompactWindow: 200000
5
+ # 300000: hook --watch warns at 200k/230k; auto-compact fired at 167,370 of a 200000 window (~0.837, or window-32.6k), so 300000 compacts at ~251k (ratio) / ~267k (offset), >=20k above 230k
6
+ autoCompactWindow: 300000
6
7
  hooks:
7
8
  PostToolUse:
8
9
  - matcher: "*"
@@ -3,7 +3,8 @@ name: dp-helper
3
3
  description: "dieu-phoi only — gen-2 helper spawned by a dp-exec agent (read/scan and summarize, or run tests and summarize logs). Do not pick this agent on your own."
4
4
  # dieu-phoi-managed: do not edit (dieu-phoi setup rewrites this file)
5
5
  disallowedTools: Agent, Task, Edit, Write, NotebookEdit
6
- autoCompactWindow: 200000
6
+ # 300000: hook --watch warns at 200k/230k; auto-compact fired at 167,370 of a 200000 window (~0.837, or window-32.6k), so 300000 compacts at ~251k (ratio) / ~267k (offset), >=20k above 230k
7
+ autoCompactWindow: 300000
7
8
  hooks:
8
9
  PostToolUse:
9
10
  - matcher: "*"
@@ -3,7 +3,8 @@ name: dp-scout
3
3
  description: "dieu-phoi only — read-only scout/planner subagent dispatched by the dieu-phoi orchestrator with a [dp:...|role=plan] brief. Do not pick this agent on your own."
4
4
  # dieu-phoi-managed: do not edit (dieu-phoi setup rewrites this file)
5
5
  disallowedTools: Agent, Task, Edit, NotebookEdit
6
- autoCompactWindow: 200000
6
+ # 300000: hook --watch warns at 200k/230k; auto-compact fired at 167,370 of a 200000 window (~0.837, or window-32.6k), so 300000 compacts at ~251k (ratio) / ~267k (offset), >=20k above 230k
7
+ autoCompactWindow: 300000
7
8
  hooks:
8
9
  PostToolUse:
9
10
  - matcher: "*"
@@ -3,7 +3,8 @@ name: dp-verify
3
3
  description: "dieu-phoi only — independent verifier subagent dispatched by the dieu-phoi orchestrator with a [dp:...|role=verify] brief. Do not pick this agent on your own."
4
4
  # dieu-phoi-managed: do not edit (dieu-phoi setup rewrites this file)
5
5
  disallowedTools: Agent, Task, Edit, NotebookEdit
6
- autoCompactWindow: 200000
6
+ # 300000: hook --watch warns at 200k/230k; auto-compact fired at 167,370 of a 200000 window (~0.837, or window-32.6k), so 300000 compacts at ~251k (ratio) / ~267k (offset), >=20k above 230k
7
+ autoCompactWindow: 300000
7
8
  hooks:
8
9
  PostToolUse:
9
10
  - matcher: "*"
package/hook.cjs CHANGED
@@ -25,7 +25,7 @@ const path = require('path');
25
25
  const os = require('os');
26
26
  const crypto = require('crypto');
27
27
 
28
- const CORE_VERSION = '0.5.0';
28
+ const CORE_VERSION = '0.5.1';
29
29
  const SCHEMA = 1;
30
30
  const TASK_TYPES = [
31
31
  'search', 'extract', 'mechanical-edit', 'feature-impl', 'debug', 'refactor',
@@ -1675,7 +1675,29 @@ function abortReasonOf(lines) {
1675
1675
  // that never uses dieu-phoi never runs them. They still check that the subagent's first prompt carries a `[dp:` tag
1676
1676
  // (state cached per agent in data/watch/<agent_id>.json) and do nothing on the main thread (no agent_id).
1677
1677
 
1678
- const HANDOFF_THRESHOLDS = Object.freeze([150000, 180000]);
1678
+ const HANDOFF_THRESHOLDS = Object.freeze([200000, 230000]);
1679
+ const WATCH_MIN = 20000;
1680
+
1681
+ /**
1682
+ * Warning thresholds [first, second]. Re-read on every hook call so a change reaches running subagents too.
1683
+ * Order: env DIEU_PHOI_WATCH_WARN / DIEU_PHOI_WATCH_HARD, then <home>/config.json watch_warn / watch_hard, then the defaults.
1684
+ * Invalid values (not a number >= 20000) are ignored; second is forced above first.
1685
+ */
1686
+ function watchThresholds(ctx) {
1687
+ let cfg = {};
1688
+ try { cfg = ctx && ctx.paths ? readJsonFile(ctx.paths.config, {}) || {} : {}; } catch (_) { cfg = {}; }
1689
+ const pick = (envName, key, dflt) => {
1690
+ for (const v of [process.env[envName], cfg[key]]) {
1691
+ const n = Number(v);
1692
+ if (v !== undefined && v !== null && v !== '' && Number.isFinite(n) && n >= WATCH_MIN) return Math.round(n);
1693
+ }
1694
+ return dflt;
1695
+ };
1696
+ const warn = pick('DIEU_PHOI_WATCH_WARN', 'watch_warn', HANDOFF_THRESHOLDS[0]);
1697
+ let hard = pick('DIEU_PHOI_WATCH_HARD', 'watch_hard', HANDOFF_THRESHOLDS[1]);
1698
+ if (hard <= warn) hard = warn + (HANDOFF_THRESHOLDS[1] - HANDOFF_THRESHOLDS[0]);
1699
+ return [warn, hard];
1700
+ }
1679
1701
  const WATCH_HEAD_BYTES = 64 * 1024;
1680
1702
  const WATCH_HEAD_MAX = 2 << 20;
1681
1703
  const WATCH_TAIL_BYTES = 256 * 1024;
@@ -1852,7 +1874,7 @@ function handleWatch(p, ctx, o) {
1852
1874
  const ct = parseTag(p.tool_input && p.tool_input.prompt);
1853
1875
  if (ct && ct.task_id) gateConfirm(ctx, st.task_id || agentId, ct.task_id);
1854
1876
  }
1855
- const thresholds = Array.isArray(o && o.thresholds) && o.thresholds.length ? o.thresholds : HANDOFF_THRESHOLDS;
1877
+ const thresholds = Array.isArray(o && o.thresholds) && o.thresholds.length ? o.thresholds : watchThresholds(ctx);
1856
1878
  const tokens = lastContextTokens(tpath);
1857
1879
  if (tokens === null) return null;
1858
1880
  let level = 0;
@@ -2213,7 +2235,7 @@ module.exports = {
2213
2235
  firstPromptText, tagFromTranscript, summarizeTranscript,
2214
2236
  RESULT_ROLES, BLOCKED_RESULT_NAME_RE, resultFileName, findResultFiles, resultRunDir, finalAssistantText, persistInlineResult, orchestratorUsage, orchCacheFile, findSessionTranscript, SESSION_ID_RE, HOOK_COLD_MAX_BYTES, appendEvent, eventLinesFrom, readEventLines, readEvents,
2215
2237
  loadSyncOffset, saveSyncOffset, recordRejected, unsyncedInfo, loadSegments, saveSegments, segmentFile,
2216
- HANDOFF_MARKER, HANDOFF_THRESHOLDS, GATE_MAX_CHILDREN, HELPER_AGENT_TYPE, watchAgentId, subagentTranscriptPath, readHeadTag, lastContextTokens, watchState, handoffMessage, handleWatch, handleGate, handleGateRelease, gateDir, gateSlots, gateReserve, gateConfirm, GATE_PENDING_MS,
2238
+ HANDOFF_MARKER, HANDOFF_THRESHOLDS, watchThresholds, GATE_MAX_CHILDREN, HELPER_AGENT_TYPE, watchAgentId, subagentTranscriptPath, readHeadTag, lastContextTokens, watchState, handoffMessage, handleWatch, handleGate, handleGateRelease, gateDir, gateSlots, gateReserve, gateConfirm, GATE_PENDING_MS,
2217
2239
  extractAgentId, hasAssistantUsage, hasDispatch, buildDispatch, handlePostToolUse, handleSubagentStop, maybeSpawnSync, runHook, runSync,
2218
2240
  };
2219
2241
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kienntpixon/dieu-phoi",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Hook + CLI ghi log subagent của Claude Code và chọn model/effort theo chi phí + thời gian tới lúc nghiệm thu.",
5
5
  "license": "MIT",
6
6
  "author": "kiennt <kiennt@pixon.games>",