@alexgreensh/token-optimizer 5.13.68 → 5.13.69
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/hooks/module_runner.py +1 -1
- package/package.json +1 -1
- package/skills/fleet-auditor/references/fleet-systems.md +38 -0
- package/skills/fleet-auditor/scripts/fleet.py +63 -92
- package/skills/fleet-auditor/scripts/fleet_base.py +106 -0
- package/skills/fleet-auditor/scripts/fleet_cursor_adapter.py +376 -0
- package/skills/token-coach/SKILL.md +21 -23
- package/skills/token-dashboard/SKILL.md +5 -4
- package/skills/token-optimizer/SKILL.md +1 -1
- package/skills/token-optimizer/assets/dashboard.html +101 -50
- package/skills/token-optimizer/references/cli-reference.md +1 -1
- package/skills/token-optimizer/references/cursor-workflow.md +1 -1
- package/skills/token-optimizer/references/phase0-setup.md +1 -1
- package/skills/token-optimizer/references/presentation-workflow.md +1 -1
- package/skills/token-optimizer/scripts/_measure/__init__.py +1 -1
- package/skills/token-optimizer/scripts/_measure/cli.py +86 -0
- package/skills/token-optimizer/scripts/_measure/daemon.py +13 -25
- package/skills/token-optimizer/scripts/_measure/dashboard.py +63 -37
- package/skills/token-optimizer/scripts/_measure/dashboard_history.py +79 -0
- package/skills/token-optimizer/scripts/_measure/lifecycle.py +6 -7
- package/skills/token-optimizer/scripts/_measure/savings.py +20 -70
- package/skills/token-optimizer/scripts/_measure/sessions.py +58 -20
- package/skills/token-optimizer/scripts/_measure/weekly_activity.py +69 -0
- package/skills/token-optimizer/scripts/antigravity_install.py +4 -0
- package/skills/token-optimizer/scripts/bash_compress.py +8 -40
- package/skills/token-optimizer/scripts/bash_compress_hook.py +6 -0
- package/skills/token-optimizer/scripts/bash_search_results.py +43 -0
- package/skills/token-optimizer/scripts/cloud_kit.py +1 -1
- package/skills/token-optimizer/scripts/codex_doctor.py +1 -1
- package/skills/token-optimizer/scripts/copilot_install.py +4 -0
- package/skills/token-optimizer/scripts/credential_patterns.py +4 -19
- package/skills/token-optimizer/scripts/credential_url_patterns.py +42 -0
- package/skills/token-optimizer/scripts/cursor_audit.py +723 -0
- package/skills/token-optimizer/scripts/cursor_bridge_checkpoint.py +213 -0
- package/skills/token-optimizer/scripts/cursor_bridge_payload.py +170 -0
- package/skills/token-optimizer/scripts/cursor_bridge_rewrite.py +106 -0
- package/skills/token-optimizer/scripts/cursor_bridge_rollup.py +115 -0
- package/skills/token-optimizer/scripts/cursor_coach.py +485 -0
- package/skills/token-optimizer/scripts/cursor_doctor.py +89 -9
- package/skills/token-optimizer/scripts/cursor_hook_bridge.py +393 -276
- package/skills/token-optimizer/scripts/cursor_install.py +106 -19
- package/skills/token-optimizer/scripts/cursor_quality.py +505 -0
- package/skills/token-optimizer/scripts/cursor_read_cache.py +597 -0
- package/skills/token-optimizer/scripts/cursor_session.py +26 -5
- package/skills/token-optimizer/scripts/cursor_state.py +8 -0
- package/skills/token-optimizer/scripts/cursor_statusline.py +372 -0
- package/skills/token-optimizer/scripts/cursor_thrash.py +78 -0
- package/skills/token-optimizer/scripts/cursor_transcript.py +223 -0
- package/skills/token-optimizer/scripts/devin_source.py +12 -2
- package/skills/token-optimizer/scripts/devin_verify.py +7 -6
- package/skills/token-optimizer/scripts/grok_install.py +4 -0
- package/skills/token-optimizer/scripts/hermes_doctor.py +4 -1
- package/skills/token-optimizer/scripts/hermes_install.py +4 -1
- package/skills/token-optimizer/scripts/measure.py +2 -2
- package/skills/token-optimizer/scripts/thrash_guard.py +10 -5
|
@@ -2406,7 +2406,7 @@ function isNoInstructionHost(data) {
|
|
|
2406
2406
|
return !!data && (data.runtime === 'cursor' || data.runtime === 'antigravity');
|
|
2407
2407
|
}
|
|
2408
2408
|
function hostRefreshHtml(data) {
|
|
2409
|
-
return tcliHtml('<span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=' + esc(data.runtime) + ' python3 measure.py dashboard</span>');
|
|
2409
|
+
return tcliHtml('<span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=' + esc(data.runtime) + ' python3 measure.py dashboard --user</span>');
|
|
2410
2410
|
}
|
|
2411
2411
|
function hermesComponentDetails(c) {
|
|
2412
2412
|
function fileSub(x, missing) {
|
|
@@ -3653,7 +3653,9 @@ var DB = (function() {
|
|
|
3653
3653
|
var collectNote = isCodex
|
|
3654
3654
|
? tcliHtml('Codex sessions can be collected manually for now: <span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py collect</span>')
|
|
3655
3655
|
: tcliHtml('Sessions are collected automatically via the SessionEnd hook. Run a few sessions first, or manually: <span class="update-cmd">python3 measure.py collect</span>');
|
|
3656
|
-
html += '<div class="empty-state">No trends data yet. ' + collectNote +
|
|
3656
|
+
html += '<div class="empty-state">No trends data yet. ' + collectNote +
|
|
3657
|
+
' <button class="date-nav-btn" onclick="window.__TOKEN_LOAD_HISTORY(\'all\', document.getElementById(\'history-load-message\'))">Load full history</button>' +
|
|
3658
|
+
'<span id="history-load-message" role="status"></span></div>';
|
|
3657
3659
|
el.innerHTML = html;
|
|
3658
3660
|
return;
|
|
3659
3661
|
}
|
|
@@ -3757,21 +3759,32 @@ var DB = (function() {
|
|
|
3757
3759
|
// Daily breakdown with date navigation
|
|
3758
3760
|
var daily = t.daily || [];
|
|
3759
3761
|
if (daily.length > 0) {
|
|
3760
|
-
|
|
3762
|
+
var selectedRange = '7';
|
|
3763
|
+
try { selectedRange = localStorage.getItem('to-daily-range') || '7'; } catch (e) {}
|
|
3764
|
+
if (['7', '14', '30', '90', '180', 'all'].indexOf(selectedRange) < 0) selectedRange = '7';
|
|
3761
3765
|
html += '<div class="card wide" id="daily-breakdown-card">' +
|
|
3762
3766
|
'<div class="card-header"><span>Daily Breakdown</span></div>' +
|
|
3763
3767
|
'<div style="font-size:12px;color:var(--c-text-dim);padding:0 0 var(--s-2) 0;">Click any row to expand per-session details with cost, quality scores, and cache data. ' + (isCodex ? 'Codex cache write TTL is not exposed, so those fields are hidden.' : 'Claude cache TTL mix is shown when available.') + ' Click a session for per-turn token breakdown.</div>' +
|
|
3764
3768
|
'<div class="date-nav">' +
|
|
3765
|
-
'<button class="date-nav-btn
|
|
3769
|
+
'<button class="date-nav-btn" data-range="7">7 days</button>' +
|
|
3766
3770
|
'<button class="date-nav-btn" data-range="14">14 days</button>' +
|
|
3767
3771
|
'<button class="date-nav-btn" data-range="30">30 days</button>' +
|
|
3772
|
+
'<button class="date-nav-btn" data-range="90">90 days</button>' +
|
|
3773
|
+
'<button class="date-nav-btn" data-range="180">180 days</button>' +
|
|
3774
|
+
'<button class="date-nav-btn" data-range="all">All</button>' +
|
|
3775
|
+
'<button class="date-nav-btn" id="load-full-history">Load full history</button>' +
|
|
3776
|
+
'<span id="history-load-message" role="status"></span>' +
|
|
3768
3777
|
'<span style="color:var(--c-text-dim);font-size:12px;margin:0 4px;">|</span>' +
|
|
3769
3778
|
'<label style="font-size:12px;color:var(--c-text-dim);font-family:var(--font-mono);">Jump to:</label>' +
|
|
3770
3779
|
'<input type="date" class="date-picker-input" id="daily-date-picker" value="' + esc(daily[0].date) + '">' +
|
|
3771
3780
|
'</div>';
|
|
3772
3781
|
html += '<div id="daily-table-container">';
|
|
3773
|
-
html += buildDailyTable(daily,
|
|
3782
|
+
html += buildDailyTable(daily, selectedRange, null);
|
|
3774
3783
|
html += '</div></div>';
|
|
3784
|
+
} else {
|
|
3785
|
+
html += '<div class="empty-state">No daily sessions in this window. ' +
|
|
3786
|
+
'<button class="date-nav-btn" onclick="window.__TOKEN_LOAD_HISTORY(\'all\', document.getElementById(\'history-load-message\'))">Load full history</button>' +
|
|
3787
|
+
'<span id="history-load-message" role="status"></span></div>';
|
|
3775
3788
|
}
|
|
3776
3789
|
|
|
3777
3790
|
// Skills usage bar chart with clickable skill details
|
|
@@ -3858,27 +3871,34 @@ var DB = (function() {
|
|
|
3858
3871
|
|
|
3859
3872
|
el.innerHTML = html;
|
|
3860
3873
|
|
|
3861
|
-
//
|
|
3874
|
+
// The table range is local to the browser; the embedded window is saved
|
|
3875
|
+
// by the generator and can be expanded explicitly through the local server.
|
|
3862
3876
|
if (daily.length > 0) {
|
|
3863
3877
|
var container = document.getElementById('daily-table-container');
|
|
3864
3878
|
var rangeBtns = document.querySelectorAll('.date-nav-btn[data-range]');
|
|
3879
|
+
var historyMessage = document.getElementById('history-load-message');
|
|
3880
|
+
function setRange(range) {
|
|
3881
|
+
selectedRange = range;
|
|
3882
|
+
try { localStorage.setItem('to-daily-range', range); } catch (e) {}
|
|
3883
|
+
rangeBtns.forEach(function(b) { b.classList.toggle('active', b.getAttribute('data-range') === range); });
|
|
3884
|
+
container.innerHTML = buildDailyTable(daily, range, null);
|
|
3885
|
+
}
|
|
3886
|
+
setRange(selectedRange);
|
|
3865
3887
|
rangeBtns.forEach(function(btn) {
|
|
3866
3888
|
btn.addEventListener('click', function() {
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
container.innerHTML = buildDailyTable(daily, range, null);
|
|
3889
|
+
var range = this.getAttribute('data-range');
|
|
3890
|
+
setRange(range);
|
|
3891
|
+
if (range !== 'all' && Number(range) > Number(t.period_days || 0)) window.__TOKEN_LOAD_HISTORY(Number(range), historyMessage);
|
|
3871
3892
|
});
|
|
3872
3893
|
});
|
|
3894
|
+
document.getElementById('load-full-history').addEventListener('click', function() {
|
|
3895
|
+
setRange('all');
|
|
3896
|
+
window.__TOKEN_LOAD_HISTORY('all', historyMessage);
|
|
3897
|
+
});
|
|
3873
3898
|
var picker = document.getElementById('daily-date-picker');
|
|
3874
|
-
if (picker) {
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
var range = activeBtn ? parseInt(activeBtn.getAttribute('data-range'), 10) || 7 : 7;
|
|
3878
|
-
rangeBtns.forEach(function(b) { b.classList.remove('active'); });
|
|
3879
|
-
container.innerHTML = buildDailyTable(daily, range, this.value);
|
|
3880
|
-
});
|
|
3881
|
-
}
|
|
3899
|
+
if (picker) picker.addEventListener('change', function() {
|
|
3900
|
+
container.innerHTML = buildDailyTable(daily, selectedRange, this.value);
|
|
3901
|
+
});
|
|
3882
3902
|
}
|
|
3883
3903
|
|
|
3884
3904
|
// Bind skill detail expand
|
|
@@ -3971,7 +3991,7 @@ var DB = (function() {
|
|
|
3971
3991
|
names.forEach(function(name) {
|
|
3972
3992
|
cmd += ' && mv "$HOME/.claude/skills/"' + shellQuote(name) + ' "$ARCHIVE_DIR/"';
|
|
3973
3993
|
});
|
|
3974
|
-
cmd += ' && echo "Archived ' + names.length + tcli(' skill(s). Regenerate dashboard: python3 measure.py dashboard"');
|
|
3994
|
+
cmd += ' && echo "Archived ' + names.length + tcli(' skill(s). Regenerate dashboard: python3 measure.py dashboard --user"');
|
|
3975
3995
|
|
|
3976
3996
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
3977
3997
|
navigator.clipboard.writeText(cmd).then(function() {
|
|
@@ -4001,20 +4021,18 @@ var DB = (function() {
|
|
|
4001
4021
|
return 'avg ' + fmtGap(avgGap) + ' | max ' + fmtGap(maxGap);
|
|
4002
4022
|
}
|
|
4003
4023
|
|
|
4004
|
-
function
|
|
4024
|
+
function selectDailyRange(daily, range, jumpToDate) {
|
|
4025
|
+
if (!daily.length) return [];
|
|
4026
|
+
var start = jumpToDate || daily[0].date;
|
|
4027
|
+
if (range === 'all') return daily.filter(function(d) { return d.date <= start; });
|
|
4028
|
+
var end = new Date(start + 'T00:00:00Z');
|
|
4029
|
+
end.setUTCDate(end.getUTCDate() - Number(range) + 1);
|
|
4030
|
+
var cutoff = end.toISOString().slice(0, 10);
|
|
4031
|
+
return daily.filter(function(d) { return d.date <= start && d.date >= cutoff; });
|
|
4032
|
+
}
|
|
4005
4033
|
|
|
4006
|
-
|
|
4007
|
-
var filtered;
|
|
4008
|
-
if (jumpToDate) {
|
|
4009
|
-
// Show 7 days starting from the selected date
|
|
4010
|
-
var startDate = jumpToDate;
|
|
4011
|
-
var endDate = new Date(jumpToDate);
|
|
4012
|
-
endDate.setDate(endDate.getDate() - range + 1);
|
|
4013
|
-
var endStr = endDate.toISOString().slice(0, 10);
|
|
4014
|
-
filtered = daily.filter(function(d) { return d.date <= startDate && d.date >= endStr; });
|
|
4015
|
-
} else {
|
|
4016
|
-
filtered = daily.slice(0, range);
|
|
4017
|
-
}
|
|
4034
|
+
function buildDailyTable(daily, range, jumpToDate) {
|
|
4035
|
+
var filtered = selectDailyRange(daily, range, jumpToDate);
|
|
4018
4036
|
|
|
4019
4037
|
if (filtered.length === 0) {
|
|
4020
4038
|
return '<div class="empty-state">No sessions found for this period.</div>';
|
|
@@ -4216,11 +4234,14 @@ var DB = (function() {
|
|
|
4216
4234
|
var savedUsd = Number(w.saved_usd);
|
|
4217
4235
|
var spanWord = w.key === 'five_hour' ? '5h' : 'week';
|
|
4218
4236
|
var hasUsd = isFinite(savedUsd) && (w.key === 'five_hour' ? savedUsd > 0 : savedUsd >= 15);
|
|
4219
|
-
|
|
4220
|
-
|
|
4237
|
+
// Without a whole-week estimate the figure is only the event-by-event count, so say so.
|
|
4238
|
+
var usdCaption = w.full_value
|
|
4239
|
+
? (w.key === 'seven_day' ? 'in API-equivalent savings this week' : 'in API-equivalent savings this 5h')
|
|
4240
|
+
: (w.key === 'seven_day' ? 'in counted savings this week (partial)' : 'in counted savings this 5h (partial)');
|
|
4221
4241
|
var usdExplainer = w.full_value
|
|
4222
4242
|
? 'Estimated additional cost at API prices for the same work without Token Optimizer. Includes lighter context, fewer repeat reads and working habits, counted once. Your plan may cover some or all of that usage.'
|
|
4223
|
-
: 'API
|
|
4243
|
+
: 'Only the savings counted one event at a time, at API prices. This is a floor, not the whole saving. A whole-week estimate appears when your work measures consistently against your baseline; this window it did not.';
|
|
4244
|
+
if (w.full_value && w.full_value.coverage && w.full_value.coverage.priced_sessions < w.full_value.coverage.total_sessions && Number(w.full_value.saved_usd) >= savedUsd) usdExplainer += ' Based on ' + Number(w.full_value.coverage.priced_sessions) + ' of ' + Number(w.full_value.coverage.total_sessions) + ' sessions; missing sessions are not estimated.';
|
|
4224
4245
|
if (w.full_value && w.full_value.start) {
|
|
4225
4246
|
usdExplainer += ' Since ' + esc(new Date(w.full_value.start).toLocaleString([], {month:'short', day:'numeric', hour:'numeric', minute:'2-digit'})) + '.';
|
|
4226
4247
|
}
|
|
@@ -4260,7 +4281,7 @@ var DB = (function() {
|
|
|
4260
4281
|
rwCards += '<div style="padding:var(--s-3);border:1px solid var(--c-border);border-radius:8px;">' +
|
|
4261
4282
|
'<div class="label">Weekly savings</div><div style="font-size:22px;color:var(--c-savings-alt,#10b981);">≈' +
|
|
4262
4283
|
rwMoney(standaloneWeek.saved_usd) + ' in API-equivalent savings this week</div>' +
|
|
4263
|
-
'<p>Full workload estimate since ' + esc(new Date(standaloneWeek.start).toLocaleString()) +
|
|
4284
|
+
'<p>Full workload estimate' + (standaloneWeek.coverage && standaloneWeek.coverage.priced_sessions < standaloneWeek.coverage.total_sessions ? ' based on ' + Number(standaloneWeek.coverage.priced_sessions) + ' of ' + Number(standaloneWeek.coverage.total_sessions) + ' sessions, missing sessions are not estimated,' : '') + ' since ' + esc(new Date(standaloneWeek.start).toLocaleString()) +
|
|
4264
4285
|
'. Your weekly limit reading is unavailable.</p></div>';
|
|
4265
4286
|
}
|
|
4266
4287
|
// USD-per-window headline: the dollar figure reuses the metered
|
|
@@ -4271,10 +4292,7 @@ var DB = (function() {
|
|
|
4271
4292
|
(rw.windows || []).forEach(function (w) {
|
|
4272
4293
|
var v = Number(w.saved_usd);
|
|
4273
4294
|
if (!isFinite(v) || v <= 0) return;
|
|
4274
|
-
//
|
|
4275
|
-
// a slice of a longer ledger. The weekly dollar is aligned to the
|
|
4276
|
-
// subscription limit reset boundary (not a rolling 7-day lookback), so
|
|
4277
|
-
// it does not drift down as heavy days age out.
|
|
4295
|
+
// The weekly figure follows the subscription reset boundary.
|
|
4278
4296
|
var span = w.key === 'five_hour' ? 'past 5h' : 'since your limit reset';
|
|
4279
4297
|
usdParts.push('<em style="font-style:normal;color:var(--c-accent-cyan);">' + rwMoney(v) + '</em> ' + span);
|
|
4280
4298
|
});
|
|
@@ -4725,14 +4743,14 @@ var DB = (function() {
|
|
|
4725
4743
|
// is the net<=0 branch — parity with OpenClaw/OpenCode.
|
|
4726
4744
|
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4727
4745
|
'<div class="label" style="margin-bottom:var(--s-2);">At or above your baseline this period</div>' +
|
|
4728
|
-
'<div class="lede">Your recent sessions cost about what your frozen baseline would have — est. <strong>' + money(ba.actual_monthly_usd) + '
|
|
4746
|
+
'<div class="lede">Your recent sessions cost about what your frozen baseline would have — est. <strong>' + money(ba.actual_monthly_usd) + '</strong> now vs <strong>' + money(ba.counterfactual_monthly_usd) + '</strong> the old way in the last ' + days + ' days. There is no net saving to headline this period, so we are not showing one. The figure below is what Token Optimizer counted directly, action by action.</div>' +
|
|
4729
4747
|
'</div>';
|
|
4730
4748
|
} else if (ba.reason === 'flat') {
|
|
4731
4749
|
// Both work-unit methods sit within a few percent of spend: no
|
|
4732
4750
|
// measurable whole-workload change, so no headline and no scary number.
|
|
4733
4751
|
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4734
4752
|
'<div class="label" style="margin-bottom:var(--s-2);">No measurable change in cost per unit of work</div>' +
|
|
4735
|
-
'<div class="plain-line">Your recent work costs about the same per request as before install (' + money(ba.actual_monthly_usd) + '
|
|
4753
|
+
'<div class="plain-line">Your recent work costs about the same per request as before install (' + money(ba.actual_monthly_usd) + ' now vs ' + money(ba.counterfactual_monthly_usd) + ' the old way over ' + days + ' days). The savings below are counted action by action.</div>' +
|
|
4736
4754
|
'</div>';
|
|
4737
4755
|
} else if (ba.reason === 'methods_disagree') {
|
|
4738
4756
|
// The two independent work-unit methods (per-API-call and per-message)
|
|
@@ -4752,8 +4770,8 @@ var DB = (function() {
|
|
|
4752
4770
|
};
|
|
4753
4771
|
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4754
4772
|
'<div class="label" style="margin-bottom:var(--s-2);">Two estimates disagree this period</div>' +
|
|
4755
|
-
'<div class="lede">The ' + mainUnit + ' estimate is <strong>' + signedMoney(mainUsd) + '
|
|
4756
|
-
' estimate is <strong>' + signedMoney(crossUsd) + '
|
|
4773
|
+
'<div class="lede">The ' + mainUnit + ' estimate is <strong>' + signedMoney(mainUsd) + '</strong> and the ' + crossUnit +
|
|
4774
|
+
' estimate is <strong>' + signedMoney(crossUsd) + '</strong> over ' + days + ' days. They are too far apart to headline either one. The figure below is what Token Optimizer counted directly, action by action.</div>' +
|
|
4757
4775
|
'</div>';
|
|
4758
4776
|
}
|
|
4759
4777
|
|
|
@@ -5801,8 +5819,8 @@ var DB = (function() {
|
|
|
5801
5819
|
var isCodex = data.runtime === 'codex';
|
|
5802
5820
|
var codexSetup = (data.manage && data.manage.codex) || {};
|
|
5803
5821
|
var refreshCmd = isCodex
|
|
5804
|
-
? tcli('TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py dashboard')
|
|
5805
|
-
: tcli('python3 measure.py dashboard');
|
|
5822
|
+
? tcli('TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py dashboard --user')
|
|
5823
|
+
: tcli('python3 measure.py dashboard --user');
|
|
5806
5824
|
|
|
5807
5825
|
var html = '<div class="section-header">' +
|
|
5808
5826
|
'<div class="label">Configuration</div>' +
|
|
@@ -6064,7 +6082,7 @@ var DB = (function() {
|
|
|
6064
6082
|
? 'Your ' + esc(data.runtime_label || 'runtime') + ' skills and MCP servers, read from its own files. Token Optimizer feature toggles are below.'
|
|
6065
6083
|
: window.__TOKEN_API_LIVE
|
|
6066
6084
|
? '<span style="color:var(--c-accent-cyan);font-weight:600;">Live mode</span> — toggles apply instantly to settings. <strong>Restart ' + (isCodex ? 'Codex' : isNoInstructionHost(data) ? esc(data.runtime_label || 'the runtime') : 'Claude') + '</strong> to activate changes.'
|
|
6067
|
-
: tcliHtml('Open in serve mode for live toggles: <code style="background:var(--c-bg);padding:2px 5px;border-radius:4px;">python3 measure.py dashboard --serve</code>')) +
|
|
6085
|
+
: tcliHtml('Open in serve mode for live toggles: <code style="background:var(--c-bg);padding:2px 5px;border-radius:4px;">python3 measure.py dashboard --user --serve</code>')) +
|
|
6068
6086
|
'</p>' +
|
|
6069
6087
|
'</div>';
|
|
6070
6088
|
|
|
@@ -6442,7 +6460,7 @@ var DB = (function() {
|
|
|
6442
6460
|
title: 'Toggling v5 features needs a terminal',
|
|
6443
6461
|
body: 'The read-only dashboard server can\u2019t write config. Run this in a terminal:',
|
|
6444
6462
|
cmd: cliCmd,
|
|
6445
|
-
hint: tcli('Or re-open the dashboard with full API: python3 measure.py dashboard --serve')
|
|
6463
|
+
hint: tcli('Or re-open the dashboard with full API: python3 measure.py dashboard --user --serve')
|
|
6446
6464
|
});
|
|
6447
6465
|
return;
|
|
6448
6466
|
}
|
|
@@ -7480,7 +7498,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7480
7498
|
|
|
7481
7499
|
var data = window.__TOKEN_DATA__;
|
|
7482
7500
|
if (!data) {
|
|
7483
|
-
document.body.innerHTML = '<div style="max-width:820px;margin:80px auto;padding:32px;border:1px solid var(--c-border);border-radius:14px;background:var(--c-surface);color:var(--c-text-main);font-family:system-ui,sans-serif;line-height:1.6;"><h1 style="margin-top:0;">Token Optimizer</h1><p><strong>You opened the dashboard template.</strong> This file intentionally contains no local metrics. Generate the runtime dashboard first, then open the generated file.</p><p style="margin-bottom:8px;color:var(--c-text-dim);">From the Token Optimizer checkout:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">TOKEN_OPTIMIZER_RUNTIME=codex python3 skills/token-optimizer/scripts/measure.py dashboard</code><p style="margin:18px 0 8px;color:var(--c-text-dim);">Generated Codex dashboard path:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">~/.codex/_backups/token-optimizer/dashboard.html</code></div>';
|
|
7501
|
+
document.body.innerHTML = '<div style="max-width:820px;margin:80px auto;padding:32px;border:1px solid var(--c-border);border-radius:14px;background:var(--c-surface);color:var(--c-text-main);font-family:system-ui,sans-serif;line-height:1.6;"><h1 style="margin-top:0;">Token Optimizer</h1><p><strong>You opened the dashboard template.</strong> This file intentionally contains no local metrics. Generate the runtime dashboard first, then open the generated file.</p><p style="margin-bottom:8px;color:var(--c-text-dim);">From the Token Optimizer checkout:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">TOKEN_OPTIMIZER_RUNTIME=codex python3 skills/token-optimizer/scripts/measure.py dashboard --user</code><p style="margin:18px 0 8px;color:var(--c-text-dim);">Generated Codex dashboard path:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">~/.codex/_backups/token-optimizer/dashboard.html</code></div>';
|
|
7484
7502
|
return;
|
|
7485
7503
|
}
|
|
7486
7504
|
var runtimeLabel = data.runtime_label || (data.runtime === 'codex' ? 'Codex' : 'Claude Code');
|
|
@@ -7498,7 +7516,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7498
7516
|
brandMeta.textContent = brandParts.join(' \u00b7 ');
|
|
7499
7517
|
}
|
|
7500
7518
|
|
|
7501
|
-
function startApp() {
|
|
7519
|
+
function startApp() {
|
|
7520
|
+
DB.init(data); refreshSavingsLive();
|
|
7521
|
+
try {
|
|
7522
|
+
if (sessionStorage.getItem('to-history-return')) {
|
|
7523
|
+
sessionStorage.removeItem('to-history-return');
|
|
7524
|
+
document.querySelector('.nav-item[data-view="trends"]').click();
|
|
7525
|
+
}
|
|
7526
|
+
} catch (e) {}
|
|
7527
|
+
}
|
|
7502
7528
|
|
|
7503
7529
|
// Pull fresh savings from the daemon and live-patch the Savings/Overview tiles.
|
|
7504
7530
|
// No-op unless the custom API is live (served over http, health probe passed) —
|
|
@@ -7575,6 +7601,31 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7575
7601
|
});
|
|
7576
7602
|
};
|
|
7577
7603
|
|
|
7604
|
+
window.__TOKEN_LOAD_HISTORY = function(choice, message) {
|
|
7605
|
+
if (choice === 'all') { try { localStorage.setItem('to-daily-range', 'all'); } catch (e) {} }
|
|
7606
|
+
if (!window.__TOKEN_API_LIVE) {
|
|
7607
|
+
message.textContent = 'Open the dashboard through the local server to load more history.';
|
|
7608
|
+
return;
|
|
7609
|
+
}
|
|
7610
|
+
message.textContent = 'Loading history…';
|
|
7611
|
+
function attempt(retried) {
|
|
7612
|
+
window.__TOKEN_API_POST('/api/regenerate', {days: choice}).then(function(r) { return r.json(); })
|
|
7613
|
+
.then(function(result) {
|
|
7614
|
+
if (!result.ok) throw new Error(result.msg || 'Regeneration failed');
|
|
7615
|
+
try { sessionStorage.setItem('to-history-return', '1'); } catch (e) {}
|
|
7616
|
+
location.reload();
|
|
7617
|
+
}).catch(function(err) {
|
|
7618
|
+
if (err.authError && !retried) {
|
|
7619
|
+
_fetchToken(window.__TOKEN_API_BASE || '').then(function() { attempt(true); })
|
|
7620
|
+
.catch(function(e) { message.textContent = 'Could not load history: ' + e.message; });
|
|
7621
|
+
} else message.textContent = 'Could not load history: ' + err.message;
|
|
7622
|
+
});
|
|
7623
|
+
}
|
|
7624
|
+
if (window.__TOKEN_API_TOKEN) attempt(false);
|
|
7625
|
+
else _fetchToken(window.__TOKEN_API_BASE || '').then(function() { attempt(false); })
|
|
7626
|
+
.catch(function(e) { message.textContent = 'Could not load history: ' + e.message; });
|
|
7627
|
+
};
|
|
7628
|
+
|
|
7578
7629
|
// Manual regeneration. The background freshness regen is stale-while-revalidate:
|
|
7579
7630
|
// it serves the current file and refreshes for NEXT time, so a reader who wants
|
|
7580
7631
|
// current numbers now would have to reload twice and never knows that. This is
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- `measure.py report` -- Token overhead report with per-component breakdown
|
|
6
6
|
- `measure.py snapshot [label]` -- Save a measurement snapshot
|
|
7
7
|
- `measure.py compare` -- Compare before/after snapshots
|
|
8
|
-
- `measure.py dashboard [--coord-path PATH]` -- Generate interactive HTML dashboard
|
|
8
|
+
- `measure.py dashboard [--user] [--coord-path PATH]` -- Generate interactive HTML dashboard (`--user` marks a person-initiated run so the 20s hook budget does not apply on piped stdin)
|
|
9
9
|
- `measure.py setup-daemon [--uninstall]` -- Bookmarkable dashboard URL (macOS/Windows)
|
|
10
10
|
- `measure.py trends [--days N] [--json]` -- Skill adoption, model mix, overhead over time
|
|
11
11
|
- `measure.py health` -- Session hygiene: stale/zombie sessions, version checks
|
|
@@ -42,7 +42,7 @@ Resolve `$MEASURE_PY` and `$PY` first with the SKILL.md Step 0b snippet (this fi
|
|
|
42
42
|
"$PY" "$MEASURE_PY" cursor-doctor --probe # replay each wired event through the installed command
|
|
43
43
|
TOKEN_OPTIMIZER_RUNTIME=cursor "$PY" "$MEASURE_PY" cursor-summary
|
|
44
44
|
TOKEN_OPTIMIZER_RUNTIME=cursor "$PY" "$MEASURE_PY" cursor-rollup
|
|
45
|
-
"$PY" "$MEASURE_PY" cursor-uninstall # remove
|
|
45
|
+
"$PY" "$MEASURE_PY" cursor-uninstall # remove hooks, payload and derived caches; keep session history
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
Install from a checkout with `bash install.sh --cursor` (merges into Cursor's
|
|
@@ -109,7 +109,7 @@ First-time install prompt:
|
|
|
109
109
|
|
|
110
110
|
After you run `setup-daemon`, the dashboard is served at:
|
|
111
111
|
URL: http://localhost:24842/token-optimizer
|
|
112
|
-
Until then, open the file path `measure.py dashboard` prints on its ` Dashboard: ` line. The location is install-dependent, so read it from the output rather than assuming a literal path.
|
|
112
|
+
Until then, open the file path `measure.py dashboard --user` prints on its ` Dashboard: ` line. The location is install-dependent, so read it from the output rather than assuming a literal path.
|
|
113
113
|
|
|
114
114
|
What installing the URL does:
|
|
115
115
|
- Runs a tiny web server on your machine (~2MB memory)
|
|
@@ -39,7 +39,7 @@ What should we tackle first?
|
|
|
39
39
|
## Dashboard Generation
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
"$PY" "$MEASURE_PY" dashboard --coord-path "$COORD_PATH"
|
|
42
|
+
"$PY" "$MEASURE_PY" dashboard --user --coord-path "$COORD_PATH"
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
Tell the user: "Dashboard opened in your browser. Browse findings by category, check the optimizations you want, click Copy Prompt and paste back here. Or just tell me directly what to tackle."
|
|
@@ -10,7 +10,7 @@ DOMAIN_MODULES = (
|
|
|
10
10
|
# HOOK_IMPORT. No module-level facade code and no UserPromptSubmit handler
|
|
11
11
|
# uses them (perf attribution, 2026-11-06).
|
|
12
12
|
DEFERRED_MODULES = ('audit', 'dashboard', 'sessions', 'savings', 'cli')
|
|
13
|
-
RUNTIME_SOURCES = ('__init__.py', '_compat.py') + tuple(name + '.py' for name in DOMAIN_MODULES)
|
|
13
|
+
RUNTIME_SOURCES = ('__init__.py', '_compat.py') + tuple(name + '.py' for name in DOMAIN_MODULES) + ('dashboard_history.py', 'weekly_activity.py')
|
|
14
14
|
# Set True by hooks/userpromptsubmit_runner.py right before `import measure`,
|
|
15
15
|
# which consumes it. That process never patches or enumerates the facade.
|
|
16
16
|
HOOK_IMPORT = False
|
|
@@ -262,6 +262,17 @@ def main():
|
|
|
262
262
|
elif _measure_facade.args[0] == "cursor-uninstall":
|
|
263
263
|
import cursor_install as _measure_import_24; _measure_facade.cursor_install = _measure_import_24; del _measure_import_24
|
|
264
264
|
_measure_facade.sys.exit(_measure_facade.cursor_install.main(["uninstall"] + _measure_facade.args[1:]))
|
|
265
|
+
elif _measure_facade.args[0] == "cursor-home":
|
|
266
|
+
# Print the resolved Cursor home directory (honors
|
|
267
|
+
# TOKEN_OPTIMIZER_CURSOR_HOME via runtime_env.cursor_home() → the
|
|
268
|
+
# safe-home guard plus the WSL-root /mnt opt-in). Used by install.sh
|
|
269
|
+
# to show the TRUE hook destination in its banner instead of a
|
|
270
|
+
# hardcoded ~/.cursor path (WSL-root installs wrote to /root/.cursor
|
|
271
|
+
# which the Windows Cursor never reads).
|
|
272
|
+
from runtime_env import cursor_home as _measure_import_ch; _measure_facade._clh = _measure_import_ch; del _measure_import_ch # noqa: PLC0415
|
|
273
|
+
|
|
274
|
+
print(str(_measure_facade._clh()))
|
|
275
|
+
_measure_facade.sys.exit(0)
|
|
265
276
|
elif _measure_facade.args[0] == "cursor-rollup":
|
|
266
277
|
# The bridge always pins TOKEN_OPTIMIZER_RUNTIME=cursor. A bare manual
|
|
267
278
|
# run must refuse (not silently collect under the default runtime).
|
|
@@ -325,6 +336,62 @@ def main():
|
|
|
325
336
|
_measure_facade.sys.exit(0)
|
|
326
337
|
_measure_facade._cursor_summary()
|
|
327
338
|
_measure_facade.sys.exit(0)
|
|
339
|
+
elif _measure_facade.args[0] == "cursor-coach":
|
|
340
|
+
# Native coach data for the Cursor runtime (Slice D): tallies,
|
|
341
|
+
# per-signal quality, and rollup trends - never a ~/.claude scan.
|
|
342
|
+
if _measure_facade.detect_runtime() != "cursor":
|
|
343
|
+
print(
|
|
344
|
+
"[Token Optimizer] cursor-coach reads only the Cursor runtime; "
|
|
345
|
+
"set TOKEN_OPTIMIZER_RUNTIME=cursor.",
|
|
346
|
+
file=_measure_facade.sys.stderr,
|
|
347
|
+
)
|
|
348
|
+
_measure_facade.sys.exit(0)
|
|
349
|
+
import cursor_coach as _measure_import_cc
|
|
350
|
+
_measure_facade.cursor_coach = _measure_import_cc
|
|
351
|
+
del _measure_import_cc
|
|
352
|
+
# Forward --days/--focus like `coach` does; the generator accepts both
|
|
353
|
+
# (window_days / focus_area in the snapshot).
|
|
354
|
+
_measure_facade._cc_days = 30
|
|
355
|
+
_measure_facade._cc_focus = None
|
|
356
|
+
_measure_facade._i = 1
|
|
357
|
+
while _measure_facade._i < len(_measure_facade.args):
|
|
358
|
+
_measure_facade._a = _measure_facade.args[_measure_facade._i]
|
|
359
|
+
if _measure_facade._a == "--days" and _measure_facade._i + 1 < len(_measure_facade.args):
|
|
360
|
+
try:
|
|
361
|
+
_measure_facade._cc_days = int(_measure_facade.args[_measure_facade._i + 1])
|
|
362
|
+
except ValueError:
|
|
363
|
+
pass
|
|
364
|
+
_measure_facade._i += 2
|
|
365
|
+
elif _measure_facade._a == "--focus" and _measure_facade._i + 1 < len(_measure_facade.args):
|
|
366
|
+
_measure_facade._cc_focus = _measure_facade.args[_measure_facade._i + 1]
|
|
367
|
+
_measure_facade._i += 2
|
|
368
|
+
else:
|
|
369
|
+
_measure_facade._i += 1
|
|
370
|
+
_measure_facade._cc_data = _measure_facade.cursor_coach.generate_cursor_coach_data(
|
|
371
|
+
days=_measure_facade._cc_days, focus=_measure_facade._cc_focus
|
|
372
|
+
)
|
|
373
|
+
if "--json" in _measure_facade.args:
|
|
374
|
+
print(_measure_facade.json.dumps(_measure_facade._cc_data, indent=2))
|
|
375
|
+
else:
|
|
376
|
+
_measure_facade._csnap = _measure_facade._cc_data["snapshot"]
|
|
377
|
+
print("Token Optimizer - Cursor coach data")
|
|
378
|
+
_measure_facade._chs = _measure_facade._cc_data["health_score"]
|
|
379
|
+
print(f" Health score: {_measure_facade._chs if _measure_facade._chs is not None else 'no scored sessions'}")
|
|
380
|
+
print(f" Sessions analyzed: {_measure_facade._csnap['sessions_analyzed']} "
|
|
381
|
+
f"({_measure_facade._csnap['total_turns']} turns, "
|
|
382
|
+
f"{_measure_facade._csnap['total_tool_calls']} tool calls, "
|
|
383
|
+
f"{_measure_facade._csnap['total_compactions']} compactions)")
|
|
384
|
+
print(f" Cost: {_measure_facade._csnap['cost']['detail']}")
|
|
385
|
+
if _measure_facade._cc_data["patterns_bad"]:
|
|
386
|
+
print(" Issues detected:")
|
|
387
|
+
for _measure_facade._p in _measure_facade._cc_data["patterns_bad"]:
|
|
388
|
+
_measure_facade._sev = {"high": "!!!", "medium": "!!", "low": "!"}.get(_measure_facade._p["severity"], "!")
|
|
389
|
+
print(f" [{_measure_facade._sev}] {_measure_facade._p['name']}: {_measure_facade._p['detail']}")
|
|
390
|
+
if _measure_facade._cc_data["patterns_good"]:
|
|
391
|
+
print(" Good practices:")
|
|
392
|
+
for _measure_facade._p in _measure_facade._cc_data["patterns_good"]:
|
|
393
|
+
print(f" [OK] {_measure_facade._p['name']}: {_measure_facade._p['detail']}")
|
|
394
|
+
_measure_facade.sys.exit(0)
|
|
328
395
|
elif _measure_facade.args[0] == "grok-summary":
|
|
329
396
|
_measure_facade._grok_summary()
|
|
330
397
|
_measure_facade.sys.exit(0)
|
|
@@ -2483,6 +2550,23 @@ def main():
|
|
|
2483
2550
|
stale_days=_measure_facade.stale_d, project_dir=_measure_facade.proj_dir)
|
|
2484
2551
|
if _measure_facade.output_json and _measure_facade.result:
|
|
2485
2552
|
print(_measure_facade.json.dumps(_measure_facade.result, indent=2, default=str))
|
|
2553
|
+
elif _measure_facade.args[0] == "cursor-audit":
|
|
2554
|
+
# Read-only audit of Cursor rules + hooks; deliberately NOT gated on
|
|
2555
|
+
# detect_runtime() == "cursor": beyond the Cursor runtime itself it
|
|
2556
|
+
# reads only 4 Claude settings files for hook-import coexistence
|
|
2557
|
+
# detection (never other ~/.claude state), so a Claude-runtime user
|
|
2558
|
+
# auditing their Cursor setup is legitimate.
|
|
2559
|
+
_measure_facade.output_json = "--json" in _measure_facade.args
|
|
2560
|
+
_measure_facade.proj_dir = None
|
|
2561
|
+
for _measure_facade.i, _measure_facade.a in enumerate(_measure_facade.args):
|
|
2562
|
+
if _measure_facade.a == "--project-dir" and _measure_facade.i + 1 < len(_measure_facade.args):
|
|
2563
|
+
_measure_facade.proj_dir = _measure_facade.args[_measure_facade.i + 1]
|
|
2564
|
+
import cursor_audit as _measure_import_ca
|
|
2565
|
+
_measure_facade.cursor_audit_mod = _measure_import_ca
|
|
2566
|
+
del _measure_import_ca
|
|
2567
|
+
_measure_facade.result = _measure_facade.cursor_audit_mod.cursor_audit(project_dir=_measure_facade.proj_dir, as_json=_measure_facade.output_json)
|
|
2568
|
+
if _measure_facade.output_json and _measure_facade.result:
|
|
2569
|
+
print(_measure_facade.json.dumps(_measure_facade.result, indent=2, default=str))
|
|
2486
2570
|
elif _measure_facade.args[0] == "archive-result":
|
|
2487
2571
|
# PostToolUse hook handler: archive large tool results
|
|
2488
2572
|
_measure_facade.quiet = "--quiet" in _measure_facade.args or "-q" in _measure_facade.args
|
|
@@ -2600,7 +2684,9 @@ def main():
|
|
|
2600
2684
|
print(" python3 measure.py cursor-doctor # Cursor adapter readiness check")
|
|
2601
2685
|
print(" python3 measure.py cursor-install # Install Cursor hooks (merged into ~/.cursor/hooks.json)")
|
|
2602
2686
|
print(" python3 measure.py cursor-summary # Token/quality Cursor session summary")
|
|
2687
|
+
print(" python3 measure.py cursor-coach # Cursor coach data (sessions, quality, patterns; --json --days N --focus X)")
|
|
2603
2688
|
print(" python3 measure.py cursor-rollup # Ingest Cursor sessions into trends DB")
|
|
2689
|
+
print(" python3 measure.py cursor-audit # Audit Cursor rules (.cursor/rules, AGENTS.md) + hooks.json health")
|
|
2604
2690
|
print(" python3 measure.py antigravity-doctor # Google Antigravity adapter readiness check")
|
|
2605
2691
|
print(" python3 measure.py antigravity-install # Install Antigravity hooks (consent-gated)")
|
|
2606
2692
|
print(" python3 measure.py antigravity-uninstall # Remove Antigravity hooks + trend rows")
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
from . import _compat
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
def _parse_elapsed_time(elapsed_str):
|
|
7
6
|
"""Parse ps elapsed time format (dd-HH:MM:SS or HH:MM:SS or MM:SS) to seconds."""
|
|
8
7
|
_measure_facade = _compat.facade()
|
|
@@ -24,7 +23,6 @@ def _parse_elapsed_time(elapsed_str):
|
|
|
24
23
|
|
|
25
24
|
return days * 86400 + hours * 3600 + minutes * 60 + seconds
|
|
26
25
|
|
|
27
|
-
|
|
28
26
|
def _format_elapsed(seconds):
|
|
29
27
|
"""Format seconds into a human-readable elapsed string."""
|
|
30
28
|
_measure_facade = _compat.facade()
|
|
@@ -38,7 +36,6 @@ def _format_elapsed(seconds):
|
|
|
38
36
|
h = hours % 24
|
|
39
37
|
return f"{d}d {h}h"
|
|
40
38
|
|
|
41
|
-
|
|
42
39
|
def _scan_project_jsonl_stats():
|
|
43
40
|
"""Return [(path, birth_time, mtime), ...] for every project JSONL, cached.
|
|
44
41
|
|
|
@@ -77,7 +74,6 @@ def _scan_project_jsonl_stats():
|
|
|
77
74
|
_measure_facade._PROJECT_JSONL_STAT_CACHE_TS = _measure_facade.time.monotonic()
|
|
78
75
|
return out
|
|
79
76
|
|
|
80
|
-
|
|
81
77
|
def _find_session_version_for_pid(pid):
|
|
82
78
|
"""Try to find the Claude Code version for a running process by matching its session JSONL.
|
|
83
79
|
|
|
@@ -154,7 +150,6 @@ def _find_session_version_for_pid(pid):
|
|
|
154
150
|
return best_match
|
|
155
151
|
return None # No confident match; don't guess (causes false OUTDATED flags)
|
|
156
152
|
|
|
157
|
-
|
|
158
153
|
def _command_matches_process(command, process_name):
|
|
159
154
|
"""True if a `ps` COMMAND field denotes a `process_name` CLI session.
|
|
160
155
|
|
|
@@ -198,7 +193,6 @@ def _command_matches_process(command, process_name):
|
|
|
198
193
|
exe_base = exe_base[:-4]
|
|
199
194
|
return exe_base == process_name
|
|
200
195
|
|
|
201
|
-
|
|
202
196
|
def _posix_comm_name(comm):
|
|
203
197
|
"""Lower-case executable name from a ps COMM field ("-zsh" -> "zsh",
|
|
204
198
|
"tmux: server" -> "tmux", "/bin/bash" -> "bash"). Never raises."""
|
|
@@ -209,7 +203,6 @@ def _posix_comm_name(comm):
|
|
|
209
203
|
text = text.split(": ", 1)[0].rsplit("/", 1)[-1]
|
|
210
204
|
return text.lstrip("-").strip().lower()
|
|
211
205
|
|
|
212
|
-
|
|
213
206
|
def _posix_comm_is_claude(comm):
|
|
214
207
|
"""True when a COMM field names a claude CLI executable (basename `claude`,
|
|
215
208
|
`.exe` stripped, or the versioned ccd-cli launcher). Matches desktop-hosted
|
|
@@ -224,7 +217,6 @@ def _posix_comm_is_claude(comm):
|
|
|
224
217
|
base = base[:-4]
|
|
225
218
|
return base == "claude" or bool(_measure_facade._CCD_CLI_LAUNCHER_RE.search(text))
|
|
226
219
|
|
|
227
|
-
|
|
228
220
|
def _posix_is_claude_host(comm, args):
|
|
229
221
|
"""True when a process is the Claude desktop app (main, helper, disclaimer
|
|
230
222
|
wrapper, Electron build) or another claude process: a claude below it is hosted."""
|
|
@@ -238,14 +230,12 @@ def _posix_is_claude_host(comm, args):
|
|
|
238
230
|
return True
|
|
239
231
|
return _measure_facade._command_matches_process(args or "", "claude")
|
|
240
232
|
|
|
241
|
-
|
|
242
233
|
def _posix_option_args(argv):
|
|
243
234
|
"""Arguments that can be options: everything after argv[0] up to a bare --."""
|
|
244
235
|
_measure_facade = _compat.facade()
|
|
245
236
|
args = list(argv[1:])
|
|
246
237
|
return args[:args.index("--")] if "--" in args else args
|
|
247
238
|
|
|
248
|
-
|
|
249
239
|
def _posix_is_headless(options):
|
|
250
240
|
"""True for SDK/headless/IDE switches and for subcommand processes."""
|
|
251
241
|
_measure_facade = _compat.facade()
|
|
@@ -259,7 +249,6 @@ def _posix_is_headless(options):
|
|
|
259
249
|
return True
|
|
260
250
|
return False
|
|
261
251
|
|
|
262
|
-
|
|
263
252
|
def _posix_read_argv(pid):
|
|
264
253
|
"""Exact argv of a process, or None when the OS will not say.
|
|
265
254
|
|
|
@@ -2569,7 +2558,7 @@ REGEN_STEP_TIMEOUT = 45
|
|
|
2569
2558
|
# thread waits for the child and clears _regen_inflight when it exits, bounded by
|
|
2570
2559
|
# this timeout so a hung child can never wedge the guard True forever (the manual
|
|
2571
2560
|
# regen path already caps each step at REGEN_STEP_TIMEOUT; this is one step + headroom).
|
|
2572
|
-
REGEN_BG_TIMEOUT =
|
|
2561
|
+
REGEN_BG_TIMEOUT = 300
|
|
2573
2562
|
MEASURE_PY_RESOLVE_TTL = 300
|
|
2574
2563
|
REGEN_LOG = os.path.join(os.path.dirname(DASHBOARD), "daemon-regen.log")
|
|
2575
2564
|
|
|
@@ -3134,6 +3123,15 @@ class Handler(http.server.SimpleHTTPRequestHandler):
|
|
|
3134
3123
|
self._json_response(200 if payload.get("ok") else 500, payload)
|
|
3135
3124
|
return
|
|
3136
3125
|
if clean == "api/regenerate":
|
|
3126
|
+
try:
|
|
3127
|
+
length = int(self.headers.get("Content-Length", 0))
|
|
3128
|
+
if length < 0 or length > 4096: raise ValueError()
|
|
3129
|
+
body = json.loads(self.rfile.read(length).decode("utf-8")) if length else {{}}
|
|
3130
|
+
days = body.get("days")
|
|
3131
|
+
if days is not None and not (days == "all" or type(days) is int and 1 <= days <= 365000): raise ValueError()
|
|
3132
|
+
except (ValueError, TypeError, AttributeError, UnicodeDecodeError):
|
|
3133
|
+
self._json_response(400, {{"ok": False, "msg": "invalid history window"}})
|
|
3134
|
+
return
|
|
3137
3135
|
# Synchronous, unlike the background freshness regen: the caller is a
|
|
3138
3136
|
# human who pressed a button and needs a real success/failure answer,
|
|
3139
3137
|
# not a fire-and-forget that looks identical whether it worked or not.
|
|
@@ -3167,23 +3165,13 @@ class Handler(http.server.SimpleHTTPRequestHandler):
|
|
|
3167
3165
|
argv = [sys.executable, target, step, "--quiet"]
|
|
3168
3166
|
if step == "dashboard":
|
|
3169
3167
|
argv.append("--force")
|
|
3170
|
-
|
|
3171
|
-
#
|
|
3172
|
-
# makes the normally-~9s build blow past a single
|
|
3173
|
-
# REGEN_STEP_TIMEOUT shot) -- and do NOT double the cap on the
|
|
3174
|
-
# retry. The earlier "2 attempts per step, doubled cap" put the
|
|
3175
|
-
# worst case at REGEN_STEP_TIMEOUT*(1+2)*2 = 6x = 270s, WORSE
|
|
3176
|
-
# than the ~240s wedge the original per-step cap fixed. Capping
|
|
3177
|
-
# every attempt at a flat REGEN_STEP_TIMEOUT and retrying only
|
|
3178
|
-
# the flaky step bounds the worst case at
|
|
3179
|
-
# REGEN_STEP_TIMEOUT*(1 + 2) = 3x = 135s, well under 240s, while
|
|
3180
|
-
# still surviving one transient dashboard hang. `collect` has no
|
|
3181
|
-
# observed hang, so it stays single-shot.
|
|
3168
|
+
if days is not None: argv.extend(["--days", str(days)])
|
|
3169
|
+
# Full-history dashboards can exceed the normal collect timeout.
|
|
3182
3170
|
_max_attempts = 2 if step == "dashboard" else 1
|
|
3183
3171
|
r = None
|
|
3184
3172
|
_timeout_exc = None
|
|
3185
3173
|
for _attempt in range(_max_attempts):
|
|
3186
|
-
_to = REGEN_STEP_TIMEOUT
|
|
3174
|
+
_to = 180 if step == "dashboard" else REGEN_STEP_TIMEOUT
|
|
3187
3175
|
try:
|
|
3188
3176
|
r = subprocess.run(
|
|
3189
3177
|
argv,
|