lumencode 1.2.0 → 1.3.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/public/app.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { COLORS, SCENARIO_COLORS, TEXT, ID, STORAGE } from './config.js';
2
2
  import { esc, fmt, fmtShort, destroyChart, destroyAllCharts, getChart, setChart, todayISO, fmtDate } from './utils.js';
3
- import { createLatestRequestGuard, fetchTools, fetchReport, fetchConfig, saveConfig, fetchDetails, fetchSessions } from './api.js';
3
+ import { createLatestRequestGuard, fetchTools, fetchReport, fetchConfig, saveConfig, fetchDetails, fetchSessions, fetchStepStats, fetchHooksStatus, updateHooks } from './api.js';
4
4
  import { renderWorkTypePie, renderModelBars, renderProjectBars, renderTimelineArea, renderCacheStack } from './charts.js';
5
- import { renderGitInsights } from './git-insights.js';
5
+ import { renderGitInsights, renderLineBlameEvidence } from './git-insights.js';
6
6
  import { loadWorkReport, copyWorkReport, downloadMarkdown, getWorkReportState, setWorkReportState } from './work-report.js';
7
7
  import { exportCSV, printReport, exportJSON, exportHTML } from './export.js';
8
8
 
@@ -95,6 +95,12 @@ function appState() {
95
95
  sourceOpencodePct: 0,
96
96
  sourceBreakdown: [],
97
97
  aiContributionMeta: '- / - LINES',
98
+ lineBlameEvidence: null,
99
+ lineBlamePrecision: '',
100
+ stepStats: null,
101
+ stepStatusLabel: '',
102
+ hooksStatus: null,
103
+ hooksBusy: false,
98
104
  gitOutputCells: [
99
105
  { l: '提交', en: 'COMMITS', v: '-', c: '' },
100
106
  { l: '变更文件', en: 'FILES', v: '-', c: '' },
@@ -146,6 +152,36 @@ function appState() {
146
152
  reportSummary: '',
147
153
  reportHighlights: [],
148
154
 
155
+ get hooksNeedAction() {
156
+ if (!this.hooksStatus) return false;
157
+ return !this.hooksStatus.stepsInitialized ||
158
+ !this.hooksStatus.claude?.enabled ||
159
+ !this.hooksStatus.codex?.enabled ||
160
+ !this.hooksStatus.opencode?.enabled;
161
+ },
162
+
163
+ get hooksStatusText() {
164
+ if (!this.hooksStatus) return '正在检查 hooks 状态';
165
+ const total = this.hooksStatus.projectCount ?? this.hooksStatus.claude?.total ?? 0;
166
+ if (this.hooksStatus.targetMode === 'configured-projects') {
167
+ if (total === 0) return '未配置项目,请先在设置中添加项目路径';
168
+ const parts = [
169
+ `Claude ${this.hooksStatus.claude?.enabledCount || 0}/${total}`,
170
+ `Codex ${this.hooksStatus.codex?.enabledCount || 0}/${total}`,
171
+ `OpenCode ${this.hooksStatus.opencode?.enabledCount || 0}/${total}`,
172
+ `steps ${this.hooksStatus.stepsReadyCount || 0}/${total}`,
173
+ ];
174
+ return `设置内项目 hooks:${parts.join(' / ')}`;
175
+ }
176
+ const parts = [
177
+ `Claude ${this.hooksStatus.claude?.enabled ? '已开启' : '未开启'}`,
178
+ `Codex ${this.hooksStatus.codex?.enabled ? '已开启' : '未开启'}`,
179
+ `OpenCode ${this.hooksStatus.opencode?.enabled ? '已开启' : '未开启'}`,
180
+ `steps ${this.hooksStatus.stepsInitialized ? '已初始化' : '未初始化'}`,
181
+ ];
182
+ return parts.join(' / ');
183
+ },
184
+
149
185
  /* ── init ── */
150
186
  async init() {
151
187
  this.loadStateFromHash();
@@ -157,6 +193,8 @@ function appState() {
157
193
  }
158
194
  });
159
195
  await this.loadTools();
196
+ await this.loadHooksStatus();
197
+ await this.loadStepStats();
160
198
  // 首次加载时先获取全量数据填充侧边栏,再按当前工具加载
161
199
  if (this.activeTool !== 'all') {
162
200
  try {
@@ -189,6 +227,83 @@ function appState() {
189
227
  } catch (e) { console.warn('loadTools failed:', e); this.availableTools = []; }
190
228
  },
191
229
 
230
+ async loadStepStats() {
231
+ try {
232
+ const data = await fetchStepStats();
233
+ this.stepStats = data;
234
+ this.stepStatusLabel = data?.available
235
+ ? `STEP READY · ${data.stepCount || 0}`
236
+ : 'STEP NOT READY';
237
+ } catch {
238
+ this.stepStats = null;
239
+ this.stepStatusLabel = '';
240
+ }
241
+ },
242
+
243
+ async loadHooksStatus() {
244
+ try {
245
+ this.hooksStatus = await fetchHooksStatus();
246
+ } catch (e) {
247
+ console.warn('loadHooksStatus failed:', e);
248
+ this.hooksStatus = null;
249
+ }
250
+ },
251
+
252
+ showHooksConfirmModal() {
253
+ const count = this.hooksStatus?.projectCount ?? 0;
254
+ const el = document.getElementById('hooksConfirmCount');
255
+ if (el) el.textContent = count;
256
+ const modal = document.getElementById('hooksConfirmModal');
257
+ if (modal) modal.style.display = 'flex';
258
+ },
259
+
260
+ hideHooksConfirmModal() {
261
+ const modal = document.getElementById('hooksConfirmModal');
262
+ if (modal) modal.style.display = 'none';
263
+ },
264
+
265
+ async enableHooksFromUi() {
266
+ this.hideHooksConfirmModal();
267
+ if (this.hooksBusy) return;
268
+ this.hooksBusy = true;
269
+ try {
270
+ await updateHooks('enable');
271
+ await this.loadHooksStatus();
272
+ await this.loadStepStats();
273
+ showToast('hooks 已开启');
274
+ } catch (err) {
275
+ showToast('开启 hooks 失败: ' + err.message);
276
+ } finally {
277
+ this.hooksBusy = false;
278
+ }
279
+ },
280
+
281
+ showHooksDisableConfirmModal() {
282
+ const modal = document.getElementById('hooksDisableConfirmModal');
283
+ if (modal) modal.style.display = 'flex';
284
+ },
285
+
286
+ hideHooksDisableConfirmModal() {
287
+ const modal = document.getElementById('hooksDisableConfirmModal');
288
+ if (modal) modal.style.display = 'none';
289
+ },
290
+
291
+ async disableHooksFromUi() {
292
+ this.hideHooksDisableConfirmModal();
293
+ if (this.hooksBusy) return;
294
+ this.hooksBusy = true;
295
+ try {
296
+ await updateHooks('disable');
297
+ await this.loadHooksStatus();
298
+ await this.loadStepStats();
299
+ showToast('hooks 已关闭');
300
+ } catch (err) {
301
+ showToast('关闭 hooks 失败: ' + err.message);
302
+ } finally {
303
+ this.hooksBusy = false;
304
+ }
305
+ },
306
+
192
307
  setTool(name) {
193
308
  this.activeTool = name;
194
309
  this.loadCurrentView();
@@ -535,6 +650,16 @@ function appState() {
535
650
  pctSum += pct;
536
651
  return { name: toolDisplayNames[name] || name, pct, tokens: fmtShort(tok), color: toolColors[name] || 'var(--foreground)' };
537
652
  });
653
+
654
+ /* Line-level blame evidence */
655
+ const blameEv = renderLineBlameEvidence(gitStats?.commitList);
656
+ if (blameEv) {
657
+ this.lineBlameEvidence = blameEv;
658
+ this.lineBlamePrecision = `行级归因: ${blameEv.aiLines}/${blameEv.totalLines} 行 (${blameEv.precision}%) · ${blameEv.commitCount} 提交`;
659
+ } else {
660
+ this.lineBlameEvidence = null;
661
+ this.lineBlamePrecision = '';
662
+ }
538
663
  },
539
664
 
540
665
  renderTimeline(trendData, usageStats) {
package/public/config.js CHANGED
@@ -5,6 +5,8 @@ export const API = {
5
5
  CONFIG: '/api/config',
6
6
  DETAILS: '/api/details',
7
7
  SESSIONS: '/api/sessions',
8
+ STEP_STATS: '/api/step-stats',
9
+ HOOKS: '/api/hooks',
8
10
  };
9
11
 
10
12
  // 灰阶色板(按视觉权重从重到轻)
@@ -42,6 +42,25 @@ function renderCommitTypeChart(typeEntries) {
42
42
  setChart('commitTypeChart', instance);
43
43
  }
44
44
 
45
+ /**
46
+ * Render line-level attribution evidence summary.
47
+ * Called when gitStats.commitList has commits with lineBlame data.
48
+ */
49
+ export function renderLineBlameEvidence(commitList) {
50
+ const blamed = (commitList || []).filter(c => c.lineBlame && c.lineBlame.source === 'step_blame');
51
+ if (blamed.length === 0) return null;
52
+ const totalAiLines = blamed.reduce((s, c) => s + (c.lineBlame.aiLines || 0), 0);
53
+ const totalLines = blamed.reduce((s, c) => s + (c.lineBlame.totalLines || 0), 0);
54
+ const totalAiDeleted = blamed.reduce((s, c) => s + (c.lineBlame.aiDeletedLines || 0), 0);
55
+ return {
56
+ commitCount: blamed.length,
57
+ aiLines: totalAiLines,
58
+ totalLines,
59
+ aiDeletedLines: totalAiDeleted,
60
+ precision: totalLines > 0 ? Math.round((totalAiLines / totalLines) * 100) : 0,
61
+ };
62
+ }
63
+
45
64
  const COMMIT_TYPE_COLORS = {
46
65
  feat: '#8ab8a0', fix: '#c49090', refactor: '#a090c0', docs: '#90a8c8',
47
66
  test: '#c8b880', chore: '#a8a8a8', perf: '#c890b0', style: '#80b8b8',
package/public/index.html CHANGED
@@ -52,6 +52,22 @@
52
52
  </ul>
53
53
  </nav>
54
54
 
55
+ <div class="rail-hooks" x-show="hooksStatus" x-cloak>
56
+ <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:6px;">
57
+ <span style="font-size:11px;font-weight:500;">行级 AI 归因</span>
58
+ <span class="font-mono" style="font-size:9px;letter-spacing:0.08em;opacity:0.55">HOOKS</span>
59
+ </div>
60
+ <div class="rail-hooks-meta" x-text="hooksStatusText"></div>
61
+ <div style="display:flex;gap:6px;margin-top:8px;">
62
+ <button class="rail-hooks-btn" x-show="hooksNeedAction" @click="showHooksConfirmModal()" :disabled="hooksBusy">
63
+ <span x-text="hooksBusy ? '...' : '开启'"></span>
64
+ </button>
65
+ <button class="rail-hooks-btn rail-hooks-btn--off" x-show="!hooksNeedAction" @click="showHooksDisableConfirmModal()" :disabled="hooksBusy">
66
+ 关闭
67
+ </button>
68
+ </div>
69
+ </div>
70
+
55
71
  <div class="rail-footer">
56
72
  <div style="display:flex;align-items:center;justify-content:space-between;width:100%;">
57
73
  <div style="display:flex;align-items:center;gap:8px;">
@@ -188,6 +204,8 @@
188
204
  <span class="label section-head-en">/ AI CONTRIBUTION</span>
189
205
  <span class="section-head-line"></span>
190
206
  <span class="section-head-meta font-mono" style="font-size:10px;opacity:0.55" x-text="aiContributionMeta"></span>
207
+ <span x-show="stepStatusLabel && !lineBlameEvidence" class="font-mono" style="font-size:9px;padding:2px 8px;border-radius:4px;background:var(--ink-12);color:var(--foreground);letter-spacing:0.08em;opacity:0.7" x-text="stepStatusLabel"></span>
208
+ <span x-show="lineBlameEvidence" class="font-mono" style="font-size:9px;padding:2px 8px;border-radius:4px;background:var(--forest);color:var(--background);letter-spacing:0.08em;opacity:0.85">LINE-BLAME</span>
191
209
  </div>
192
210
 
193
211
  <div class="ai-hero-grid">
@@ -196,6 +214,7 @@
196
214
  <div style="flex-shrink:0;">
197
215
  <div class="ai-hero-pct"><span class="text-aurora-shimmer" x-text="aiLinePctDisplay"></span><span :style="'color:' + colors.rust">%</span></div>
198
216
  <div class="ai-hero-desc" x-html="aiSummaryDesc"></div>
217
+ <div x-show="lineBlamePrecision" class="font-mono" style="font-size:10px;margin-top:6px;opacity:0.55" x-text="lineBlamePrecision"></div>
199
218
  </div>
200
219
  <div style="flex:1;padding-bottom:12px;">
201
220
  <div style="display:flex;justify-content:space-between;margin-bottom:6px;">
@@ -640,6 +659,56 @@
640
659
  </div>
641
660
  </div>
642
661
  </main>
662
+
663
+ <!-- ── Hooks Confirm Modal ── -->
664
+ <div id="hooksConfirmModal" class="modal-overlay" style="display:none;">
665
+ <div class="modal-backdrop" @click="hideHooksConfirmModal()"></div>
666
+ <div class="modal-panel" style="max-width:440px;">
667
+ <div class="modal-header">
668
+ <h3 style="font-size:15px;font-weight:500;">确认开启 hooks</h3>
669
+ <button class="rail-btn-icon" @click="hideHooksConfirmModal()" style="color:var(--foreground);opacity:0.65;">
670
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
671
+ </button>
672
+ </div>
673
+ <div class="modal-body" style="padding:16px 24px;">
674
+ <p style="font-size:13px;line-height:1.7;opacity:0.85;">将为设置中的 <strong id="hooksConfirmCount">0</strong> 个项目开启 hooks,修改各项目下的配置文件并自动备份:</p>
675
+ <div class="hooks-confirm-files">
676
+ <div><span style="color:var(--claude)">Claude</span> .claude/settings.local.json</div>
677
+ <div><span style="color:var(--codex)">Codex</span> .codex/config.toml</div>
678
+ <div><span style="color:var(--opencode)">OpenCode</span> .opencode/plugins/lumencode-step-tracker.js</div>
679
+ </div>
680
+ </div>
681
+ <div class="modal-footer" style="gap:8px;">
682
+ <button class="btn btn-outline" @click="hideHooksConfirmModal()">取消</button>
683
+ <button class="btn btn-primary" @click="enableHooksFromUi()" :disabled="hooksBusy">确认开启</button>
684
+ </div>
685
+ </div>
686
+ </div>
687
+
688
+ <!-- ── Hooks Disable Confirm Modal ── -->
689
+ <div id="hooksDisableConfirmModal" class="modal-overlay" style="display:none;">
690
+ <div class="modal-backdrop" @click="hideHooksDisableConfirmModal()"></div>
691
+ <div class="modal-panel" style="max-width:440px;">
692
+ <div class="modal-header">
693
+ <h3 style="font-size:15px;font-weight:500;">确认关闭 hooks</h3>
694
+ <button class="rail-btn-icon" @click="hideHooksDisableConfirmModal()" style="color:var(--foreground);opacity:0.65;">
695
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
696
+ </button>
697
+ </div>
698
+ <div class="modal-body" style="padding:16px 24px;">
699
+ <p style="font-size:13px;line-height:1.7;opacity:0.85;">关闭后将<strong style="color:var(--warning)">停止记录</strong>行级编辑步骤,影响如下:</p>
700
+ <div class="hooks-confirm-files">
701
+ <div style="color:var(--warning)">新提交的代码将无法进行行级 AI 归因</div>
702
+ <div>已记录的历史数据会保留,不受影响</div>
703
+ <div>恢复记录需重新开启 hooks</div>
704
+ </div>
705
+ </div>
706
+ <div class="modal-footer" style="gap:8px;">
707
+ <button class="btn btn-outline" @click="hideHooksDisableConfirmModal()">取消</button>
708
+ <button class="btn btn-primary" @click="disableHooksFromUi()" :disabled="hooksBusy">确认关闭</button>
709
+ </div>
710
+ </div>
711
+ </div>
643
712
  </div>
644
713
 
645
714
  <!-- ── Settings Modal ── -->
package/public/style.css CHANGED
@@ -378,6 +378,7 @@ input, textarea { font-family: inherit; color: inherit; }
378
378
  color: var(--foreground);
379
379
  }
380
380
  .btn-outline:hover { border-color: var(--foreground); background: var(--ink-8); }
381
+ .btn:disabled { opacity: 0.55; cursor: not-allowed; }
381
382
  .btn-ghost {
382
383
  padding: 6px 10px;
383
384
  color: var(--foreground);
@@ -396,6 +397,88 @@ input, textarea { font-family: inherit; color: inherit; }
396
397
  0 8px 24px -12px var(--card-lift-drop-2);
397
398
  }
398
399
 
400
+ .hooks-notice {
401
+ display: flex;
402
+ align-items: center;
403
+ justify-content: space-between;
404
+ gap: 16px;
405
+ margin: 12px 0 16px;
406
+ padding: 12px 14px;
407
+ border: 1px solid var(--border);
408
+ border-radius: 8px;
409
+ background: var(--ink-4);
410
+ }
411
+
412
+ .hooks-notice-title {
413
+ font-size: 13px;
414
+ font-weight: 500;
415
+ }
416
+
417
+ .hooks-notice-meta {
418
+ margin-top: 4px;
419
+ font-family: var(--font-mono);
420
+ font-size: 10px;
421
+ letter-spacing: 0.04em;
422
+ opacity: 0.62;
423
+ }
424
+
425
+ /* ── Rail Hooks ── */
426
+ .rail-hooks {
427
+ margin: auto 14px 0;
428
+ padding: 12px;
429
+ border: 1px solid var(--border);
430
+ border-radius: 8px;
431
+ background: var(--ink-4);
432
+ }
433
+
434
+ .rail-hooks-meta {
435
+ font-family: var(--font-mono);
436
+ font-size: 9px;
437
+ letter-spacing: 0.04em;
438
+ opacity: 0.62;
439
+ line-height: 1.5;
440
+ word-break: break-all;
441
+ }
442
+
443
+ .hooks-confirm-files {
444
+ margin-top: 12px;
445
+ padding: 12px;
446
+ border: 1px solid var(--border);
447
+ border-radius: 6px;
448
+ background: var(--ink-4);
449
+ display: flex;
450
+ flex-direction: column;
451
+ gap: 6px;
452
+ font-family: var(--font-mono);
453
+ font-size: 11px;
454
+ line-height: 1.5;
455
+ opacity: 0.8;
456
+ }
457
+
458
+ .rail-hooks-btn {
459
+ flex: 1;
460
+ padding: 4px 0;
461
+ font-size: 10px;
462
+ font-weight: 500;
463
+ text-align: center;
464
+ border: none;
465
+ border-radius: 4px;
466
+ cursor: pointer;
467
+ color: var(--background);
468
+ background: var(--foreground);
469
+ }
470
+
471
+ .rail-hooks-btn:disabled {
472
+ opacity: 0.4;
473
+ cursor: not-allowed;
474
+ }
475
+
476
+ .rail-hooks-btn--off {
477
+ background: transparent;
478
+ border: 1px solid var(--border);
479
+ color: var(--foreground);
480
+ }
481
+
399
482
  /* ── KPI Strip ── */
400
483
  .kpi-strip {
401
484
  display: grid;
@@ -855,7 +938,8 @@ input, textarea { font-family: inherit; color: inherit; }
855
938
  .toast {
856
939
  position: fixed;
857
940
  top: 16px;
858
- right: 16px;
941
+ left: 50%;
942
+ transform: translateX(-50%);
859
943
  z-index: 300;
860
944
  background: var(--foreground);
861
945
  color: var(--background);