项目文件夹

文件
heranran 71c7672545 feat: Skill Hub hardening with session usage tracking and egress governance (#163)
* feat(skill-hub): add Skill Hub catalog, publish flow, and lite materialize pipeline

Introduce Skill Hub for browsing, importing, publishing, and installing skills, with lite instance package materialization and runtime sync support.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): remove token-governance hooks from Skill Hub PR

Strip validateManagedRuntimeEnvironmentOverrides, network lock policy sync,
and egress proxy audit wiring that belong to the upcoming token-usage work,
so the Skill Hub branch compiles independently.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): update migration number in materialize docs

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): make RuntimeAgentClient test stub and hub tests compile-safe

Add ResyncInstanceSkills to the runtime pool handler fake client, and harden
skill hub payload helpers/tests against nil storage/instance repos so go test passes.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat: add Skill Hub hardening with session usage tracking and egress governance

Unify Skill Hub runtime sync improvements with session-token observability,
egress network policy, and admin/instance usage reporting for reopenable PR.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): repair CI tests and nested skill install

* fix(ci): restore release deployment configuration

---------

Co-authored-by: heshengran <heshengran@ieisystem.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 12:37:01 +08:00

64 行
1.8 KiB
Go

package services
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"clawreef/internal/models"
"clawreef/internal/repository"
"clawreef/internal/services/k8s"
)
func hostPathWorkspaceScanEnabled() bool {
client := k8s.GetClient()
return client != nil && client.HostPathFallbackEnabled
}
func instancePersistentHostPath(userID, instanceID int) (string, bool) {
if !hostPathWorkspaceScanEnabled() || userID <= 0 || instanceID <= 0 {
return "", false
}
hostPathPrefix := "/data/clawreef"
if client := k8s.GetClient(); client != nil && strings.TrimSpace(client.HostPathPrefix) != "" {
hostPathPrefix = strings.TrimSpace(client.HostPathPrefix)
}
return filepath.Join(hostPathPrefix, fmt.Sprintf("user-%d", userID), fmt.Sprintf("instance-%d", instanceID)), true
}
func proDesktopWorkspaceScanEligible(instance *models.Instance) bool {
if instance == nil || isLiteRuntimeInstance(instance) {
return false
}
if v2Type, ok := v2RuntimeTypeForInstance(instance); ok && strings.TrimSpace(v2Type) != "" {
return false
}
return supportsManagedRuntimeIntegration(instance.Type)
}
func EnsureInstanceWorkspacePathForServerScan(ctx context.Context, repo repository.InstanceRepository, instance *models.Instance) error {
if repo == nil || instance == nil {
return nil
}
if instance.WorkspacePath != nil && strings.TrimSpace(*instance.WorkspacePath) != "" {
return nil
}
if !proDesktopWorkspaceScanEligible(instance) {
return nil
}
hostPath, ok := instancePersistentHostPath(instance.UserID, instance.ID)
if !ok {
return nil
}
if _, err := os.Stat(hostPath); err != nil {
return nil
}
if err := repo.SetWorkspacePath(ctx, instance.ID, hostPath); err != nil {
return fmt.Errorf("failed to persist pro desktop workspace path: %w", err)
}
instance.WorkspacePath = &hostPath
return nil
}