claude-pangu 2.1.14 → 2.1.15

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://code.claude.com/plugin-schema.json",
3
3
  "name": "oh-my-claude",
4
- "version": "2.1.14",
4
+ "version": "2.1.15",
5
5
  "hooks": "./hooks/hooks.json",
6
6
  "description": "基于中国传统文化的 Claude Code 智能编排插件 - A Claude Code plugin inspired by Chinese traditional culture",
7
7
  "author": "ZDragon17",
@@ -520,11 +520,105 @@ detect_update_commands() {
520
520
  return 1
521
521
  }
522
522
 
523
+ # ==================== SessionStart 专用函数 ====================
524
+
525
+ # SessionStart 时的快速检查和自动更新
526
+ # 特点:
527
+ # 1. 非阻塞 - 不影响启动速度
528
+ # 2. 静默 - 只在有更新时才显示消息
529
+ # 3. 自动更新 - 后台执行更新
530
+ session_start_check() {
531
+ log "SessionStart 触发自动更新检查"
532
+
533
+ # 首先检查之前的后台更新是否完成
534
+ check_background_update_result
535
+
536
+ # 检查插件是否安装
537
+ if ! is_plugin_installed; then
538
+ log "插件未安装,跳过更新检查"
539
+ return 0
540
+ fi
541
+
542
+ # 检查是否有正在进行的后台更新
543
+ local pid_file="$UPDATE_CACHE/update-pid.txt"
544
+ if [ -f "$pid_file" ]; then
545
+ local pid=$(cat "$pid_file" 2>/dev/null)
546
+ if kill -0 "$pid" 2>/dev/null; then
547
+ log "后台更新正在进行中 (PID: $pid),跳过本次检查"
548
+ return 0
549
+ fi
550
+ fi
551
+
552
+ # 检查是否需要检查(时间间隔)- SessionStart 时使用较短的间隔检查
553
+ # 但如果距离上次检查不足 1 小时,则跳过
554
+ local last_check=$(get_last_check_time)
555
+ if [ -n "$last_check" ]; then
556
+ local last_ts=$(date -d "$last_check" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%S" "$last_check" +%s 2>/dev/null || echo 0)
557
+ local now_ts=$(date +%s)
558
+ local hours_diff=$(( (now_ts - last_ts) / 3600 ))
559
+
560
+ if [ "$hours_diff" -lt 1 ]; then
561
+ log "距离上次检查不足 1 小时,跳过"
562
+ return 0
563
+ fi
564
+ fi
565
+
566
+ log "开始 SessionStart 更新检查"
567
+
568
+ local current=$(get_current_version)
569
+ local latest=$(get_latest_npm_version)
570
+
571
+ if [ -z "$latest" ]; then
572
+ latest=$(get_latest_github_version)
573
+ fi
574
+
575
+ local status=$(compare_versions "$current" "$latest")
576
+
577
+ save_update_state "$current" "$latest" "$status"
578
+
579
+ # 如果有更新且启用了自动更新
580
+ if [ "$status" = "outdated" ]; then
581
+ if [ "$AUTO_UPDATE" = "true" ]; then
582
+ # 输出 JSON 格式的 systemMessage,在启动时显示更新提示
583
+ cat << EOF
584
+ {
585
+ "hookSpecificOutput": {
586
+ "hookEventName": "SessionStart",
587
+ "additionalContext": "🔄 oh-my-claude 发现新版本: $current → $latest,正在后台自动更新..."
588
+ }
589
+ }
590
+ EOF
591
+ # 启动后台更新
592
+ background_update "$current" "$latest"
593
+ else
594
+ # 非自动更新模式:只显示提示
595
+ cat << EOF
596
+ {
597
+ "hookSpecificOutput": {
598
+ "hookEventName": "SessionStart",
599
+ "additionalContext": "🔔 oh-my-claude 有新版本可用! 当前: $current → 最新: $latest。更新命令: npm update -g $PACKAGE_NAME"
600
+ }
601
+ }
602
+ EOF
603
+ fi
604
+ else
605
+ log "当前已是最新版本或无法确定版本状态: $status"
606
+ fi
607
+
608
+ return 0
609
+ }
610
+
523
611
  # ==================== 主函数 ====================
524
612
 
525
613
  main() {
526
614
  local input="$1"
527
615
 
616
+ # 检查是否是 SessionStart 模式
617
+ if [ "$input" = "--session-start" ]; then
618
+ session_start_check
619
+ exit 0
620
+ fi
621
+
528
622
  if [ -z "$input" ]; then
529
623
  # 无输入时,执行自动检查
530
624
  auto_check_update
package/hooks/hooks.json CHANGED
@@ -1,5 +1,16 @@
1
1
  {
2
2
  "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "type": "command",
6
+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/auto-update-checker.sh --session-start",
7
+ "timeout": 10000,
8
+ "continueOnError": true,
9
+ "priority": "low",
10
+ "windows_compatible": true,
11
+ "description": "启动时自动检查更新 - 后台静默检查和更新"
12
+ }
13
+ ],
3
14
  "Stop": [
4
15
  {
5
16
  "type": "command",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-pangu",
3
- "version": "2.1.14",
3
+ "version": "2.1.15",
4
4
  "description": "基于中国传统文化的 Claude Code 智能编排插件 - A Claude Code plugin inspired by Chinese traditional culture (原名 oh-my-claude)",
5
5
  "keywords": [
6
6
  "claude-code",