principles-disciple 1.11.0 → 1.13.0
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 +26 -0
- package/README.md +66 -0
- package/esbuild.config.js +1 -1
- package/openclaw.plugin.json +4 -4
- package/package.json +2 -3
- package/run-nocturnal.mjs +30 -0
- package/scripts/db-migrate.mjs +170 -0
- package/scripts/sync-plugin.mjs +250 -6
- package/src/commands/archive-impl.ts +136 -0
- package/src/commands/capabilities.ts +4 -2
- package/src/commands/context.ts +5 -1
- package/src/commands/disable-impl.ts +151 -0
- package/src/commands/evolution-status.ts +64 -19
- package/src/commands/export.ts +8 -6
- package/src/commands/focus.ts +8 -20
- package/src/commands/nocturnal-review.ts +5 -7
- package/src/commands/nocturnal-rollout.ts +1 -12
- package/src/commands/nocturnal-train.ts +21 -47
- package/src/commands/pain.ts +10 -5
- package/src/commands/principle-rollback.ts +4 -2
- package/src/commands/promote-impl.ts +274 -0
- package/src/commands/rollback-impl.ts +234 -0
- package/src/commands/rollback.ts +6 -3
- package/src/commands/samples.ts +2 -0
- package/src/commands/thinking-os.ts +3 -4
- package/src/commands/workflow-debug.ts +2 -1
- package/src/config/errors.ts +1 -0
- package/src/core/AGENTS.md +34 -0
- package/src/core/adaptive-thresholds.ts +4 -3
- package/src/core/code-implementation-storage.ts +241 -0
- package/src/core/config.ts +5 -2
- package/src/core/control-ui-db.ts +29 -10
- package/src/core/detection-funnel.ts +12 -7
- package/src/core/diagnostician-task-store.ts +156 -0
- package/src/core/dictionary.ts +4 -4
- package/src/core/empathy-keyword-matcher.ts +7 -3
- package/src/core/empathy-types.ts +13 -2
- package/src/core/event-log.ts +14 -6
- package/src/core/evolution-engine.ts +27 -31
- package/src/core/evolution-logger.ts +3 -2
- package/src/core/evolution-reducer.ts +110 -31
- package/src/core/evolution-types.ts +10 -0
- package/src/core/external-training-contract.ts +1 -0
- package/src/core/focus-history.ts +38 -24
- package/src/core/hygiene/tracker.ts +10 -6
- package/src/core/init.ts +5 -2
- package/src/core/migration.ts +3 -3
- package/src/core/model-deployment-registry.ts +6 -4
- package/src/core/model-training-registry.ts +5 -3
- package/src/core/nocturnal-arbiter.ts +13 -14
- package/src/core/nocturnal-artifact-lineage.ts +117 -0
- package/src/core/nocturnal-artificer.ts +257 -0
- package/src/core/nocturnal-candidate-scoring.ts +4 -2
- package/src/core/nocturnal-compliance.ts +67 -19
- package/src/core/nocturnal-dataset.ts +95 -2
- package/src/core/nocturnal-executability.ts +2 -3
- package/src/core/nocturnal-export.ts +6 -3
- package/src/core/nocturnal-rule-implementation-validator.ts +245 -0
- package/src/core/nocturnal-trajectory-extractor.ts +10 -3
- package/src/core/nocturnal-trinity.ts +319 -61
- package/src/core/pain-context-extractor.ts +29 -15
- package/src/core/pain.ts +7 -5
- package/src/core/path-resolver.ts +16 -15
- package/src/core/paths.ts +2 -1
- package/src/core/pd-task-reconciler.ts +463 -0
- package/src/core/pd-task-service.ts +42 -0
- package/src/core/pd-task-store.ts +77 -0
- package/src/core/pd-task-types.ts +128 -0
- package/src/core/principle-internalization/deprecated-readiness.ts +91 -0
- package/src/core/principle-internalization/internalization-routing-policy.ts +208 -0
- package/src/core/principle-internalization/lifecycle-metrics.ts +149 -0
- package/src/core/principle-internalization/lifecycle-read-model.ts +243 -0
- package/src/core/principle-internalization/lifecycle-refresh.ts +11 -0
- package/src/core/principle-internalization/principle-lifecycle-service.ts +167 -0
- package/src/core/principle-training-state.ts +95 -370
- package/src/core/principle-tree-ledger.ts +733 -0
- package/src/core/principle-tree-migration.ts +195 -0
- package/src/core/profile.ts +3 -1
- package/src/core/promotion-gate.ts +14 -18
- package/src/core/replay-engine.ts +562 -0
- package/src/core/risk-calculator.ts +6 -4
- package/src/core/rule-host-helpers.ts +39 -0
- package/src/core/rule-host-types.ts +82 -0
- package/src/core/rule-host.ts +245 -0
- package/src/core/rule-implementation-runtime.ts +38 -0
- package/src/core/schema/db-types.ts +16 -0
- package/src/core/schema/index.ts +26 -0
- package/src/core/schema/migration-runner.ts +207 -0
- package/src/core/schema/migrations/001-init-trajectory.ts +211 -0
- package/src/core/schema/migrations/002-init-central.ts +122 -0
- package/src/core/schema/migrations/003-init-workflow.ts +55 -0
- package/src/core/schema/migrations/004-add-thinking-and-gfi.ts +74 -0
- package/src/core/schema/migrations/index.ts +31 -0
- package/src/core/schema/schema-definitions.ts +650 -0
- package/src/core/session-tracker.ts +6 -4
- package/src/core/shadow-observation-registry.ts +6 -3
- package/src/core/system-logger.ts +2 -2
- package/src/core/thinking-models.ts +182 -46
- package/src/core/thinking-os-parser.ts +156 -0
- package/src/core/training-program.ts +7 -7
- package/src/core/trajectory.ts +42 -36
- package/src/core/workspace-context.ts +77 -11
- package/src/core/workspace-dir-validation.ts +152 -0
- package/src/hooks/AGENTS.md +31 -0
- package/src/hooks/bash-risk.ts +3 -1
- package/src/hooks/edit-verification.ts +9 -5
- package/src/hooks/gate-block-helper.ts +5 -1
- package/src/hooks/gate.ts +152 -5
- package/src/hooks/gfi-gate.ts +9 -2
- package/src/hooks/lifecycle-routing.ts +124 -0
- package/src/hooks/lifecycle.ts +12 -12
- package/src/hooks/llm.ts +17 -109
- package/src/hooks/message-sanitize.ts +5 -3
- package/src/hooks/pain.ts +19 -15
- package/src/hooks/progressive-trust-gate.ts +7 -1
- package/src/hooks/prompt.ts +169 -60
- package/src/hooks/subagent.ts +5 -4
- package/src/hooks/thinking-checkpoint.ts +2 -0
- package/src/hooks/trajectory-collector.ts +15 -12
- package/src/http/principles-console-route.ts +31 -68
- package/src/i18n/commands.ts +2 -2
- package/src/index.ts +130 -40
- package/src/service/central-database.ts +131 -43
- package/src/service/central-health-service.ts +47 -0
- package/src/service/central-overview-service.ts +135 -0
- package/src/service/central-sync-service.ts +87 -0
- package/src/service/control-ui-query-service.ts +46 -36
- package/src/service/event-log-auditor.ts +261 -0
- package/src/service/evolution-query-service.ts +23 -22
- package/src/service/evolution-worker.ts +565 -261
- package/src/service/health-query-service.ts +213 -36
- package/src/service/nocturnal-runtime.ts +8 -4
- package/src/service/nocturnal-service.ts +503 -59
- package/src/service/nocturnal-target-selector.ts +5 -7
- package/src/service/runtime-summary-service.ts +2 -1
- package/src/service/subagent-workflow/deep-reflect-workflow-manager.ts +25 -336
- package/src/service/subagent-workflow/dynamic-timeout.ts +30 -0
- package/src/service/subagent-workflow/empathy-observer-workflow-manager.ts +48 -386
- package/src/service/subagent-workflow/index.ts +2 -0
- package/src/service/subagent-workflow/nocturnal-workflow-manager.ts +169 -284
- package/src/service/subagent-workflow/runtime-direct-driver.ts +114 -16
- package/src/service/subagent-workflow/subagent-error-utils.ts +25 -0
- package/src/service/subagent-workflow/types.ts +9 -4
- package/src/service/subagent-workflow/workflow-manager-base.ts +573 -0
- package/src/service/subagent-workflow/workflow-store.ts +71 -11
- package/src/service/trajectory-service.ts +2 -1
- package/src/tools/critique-prompt.ts +1 -1
- package/src/tools/deep-reflect.ts +175 -209
- package/src/tools/model-index.ts +2 -1
- package/src/types/event-types.ts +2 -2
- package/src/types/principle-tree-schema.ts +29 -23
- package/src/utils/file-lock.ts +5 -3
- package/src/utils/io.ts +5 -2
- package/src/utils/nlp.ts +5 -46
- package/src/utils/node-vm-polyfill.ts +11 -0
- package/src/utils/plugin-logger.ts +2 -0
- package/src/utils/retry.ts +572 -0
- package/src/utils/subagent-probe.ts +1 -1
- package/templates/langs/en/core/AGENTS.md +0 -13
- package/templates/langs/en/core/SOUL.md +1 -31
- package/templates/langs/en/core/TOOLS.md +0 -4
- package/templates/langs/en/principles/THINKING_OS.md +77 -0
- package/templates/langs/en/skills/admin/SKILL.md +0 -1
- package/templates/langs/en/skills/evolution-framework-update/SKILL.md +1 -1
- package/templates/langs/en/skills/pd-diagnostician/SKILL.md +18 -5
- package/templates/langs/zh/core/AGENTS.md +0 -22
- package/templates/langs/zh/core/SOUL.md +1 -31
- package/templates/langs/zh/core/TOOLS.md +0 -4
- package/templates/langs/zh/principles/THINKING_OS.md +77 -0
- package/templates/langs/zh/skills/admin/SKILL.md +0 -1
- package/templates/langs/zh/skills/evolution-framework-update/SKILL.md +1 -1
- package/templates/langs/zh/skills/pd-diagnostician/SKILL.md +25 -4
- package/tests/commands/evolution-status.test.ts +119 -0
- package/tests/commands/implementation-lifecycle.test.ts +362 -0
- package/tests/core/code-implementation-storage.test.ts +398 -0
- package/tests/core/evolution-reducer.detector-metadata.test.ts +28 -28
- package/tests/core/nocturnal-artifact-lineage.test.ts +53 -0
- package/tests/core/nocturnal-artificer.test.ts +241 -0
- package/tests/core/nocturnal-compliance-p-principles.test.ts +133 -0
- package/tests/core/nocturnal-rule-implementation-validator.test.ts +127 -0
- package/tests/core/pd-task-store.test.ts +126 -0
- package/tests/core/principle-internalization/deprecated-readiness.test.ts +193 -0
- package/tests/core/principle-internalization/internalization-routing-policy.test.ts +212 -0
- package/tests/core/principle-internalization/lifecycle-metrics.test.ts +350 -0
- package/tests/core/principle-internalization/principle-lifecycle-service.test.ts +211 -0
- package/tests/core/principle-training-state.test.ts +228 -1
- package/tests/core/principle-tree-ledger.test.ts +423 -0
- package/tests/core/regression-v1-9-1.test.ts +265 -0
- package/tests/core/replay-engine.test.ts +234 -0
- package/tests/core/rule-host-helpers.test.ts +120 -0
- package/tests/core/rule-host.test.ts +389 -0
- package/tests/core/rule-implementation-runtime.test.ts +64 -0
- package/tests/core/workspace-context.test.ts +53 -0
- package/tests/core/workspace-dir-validation.test.ts +272 -0
- package/tests/hooks/gate-rule-host-pipeline.test.ts +385 -0
- package/tests/hooks/pain.test.ts +74 -10
- package/tests/hooks/prompt.test.ts +63 -1
- package/tests/integration/principle-lifecycle.e2e.test.ts +197 -0
- package/tests/integration/tool-hooks-workspace-dir.e2e.test.ts +211 -0
- package/tests/service/data-endpoints-regression.test.ts +834 -0
- package/tests/service/evolution-worker.test.ts +0 -123
- package/tests/service/nocturnal-service-code-candidate.test.ts +330 -0
- package/tests/utils/nlp.test.ts +1 -19
- package/tests/utils/retry.test.ts +327 -0
- package/ui/src/App.tsx +1 -1
- package/ui/src/api.ts +4 -0
- package/ui/src/charts.tsx +366 -0
- package/ui/src/components/WorkspaceConfig.tsx +107 -75
- package/ui/src/i18n/ui.ts +89 -31
- package/ui/src/pages/EvolutionPage.tsx +1 -1
- package/ui/src/pages/OverviewPage.tsx +441 -81
- package/ui/src/pages/ThinkingModelsPage.tsx +287 -69
- package/ui/src/styles.css +43 -0
- package/ui/src/types.ts +17 -1
- package/src/agents/nocturnal-dreamer.md +0 -152
- package/src/agents/nocturnal-philosopher.md +0 -138
- package/src/agents/nocturnal-reflector.md +0 -126
- package/src/agents/nocturnal-scribe.md +0 -164
- package/templates/workspace/.principles/00-kernel.md +0 -51
- package/templates/workspace/.principles/DECISION_POLICY.json +0 -44
- package/templates/workspace/.principles/PRINCIPLES.md +0 -20
- package/templates/workspace/.principles/PROFILE.json +0 -54
- package/templates/workspace/.principles/PROFILE.schema.json +0 -56
- package/templates/workspace/.principles/THINKING_OS.md +0 -64
- package/templates/workspace/.principles/THINKING_OS_ARCHIVE.md +0 -7
- package/templates/workspace/.principles/THINKING_OS_CANDIDATES.md +0 -9
- package/templates/workspace/.principles/models/_INDEX.md +0 -27
- package/templates/workspace/.principles/models/first_principles.md +0 -62
- package/templates/workspace/.principles/models/marketing_4p.md +0 -52
- package/templates/workspace/.principles/models/porter_five.md +0 -63
- package/templates/workspace/.principles/models/swot.md +0 -60
- package/templates/workspace/.principles/models/user_story_map.md +0 -63
- package/templates/workspace/.state/WORKBOARD.json +0 -4
package/ui/src/charts.tsx
CHANGED
|
@@ -584,3 +584,369 @@ export function CollapsiblePanel({
|
|
|
584
584
|
</section>
|
|
585
585
|
);
|
|
586
586
|
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* BulletChart - 子弹图(Performance vs Target)
|
|
590
|
+
* 用于展示 GFI vs 阈值,带安全/警告/危险分区
|
|
591
|
+
*/
|
|
592
|
+
|
|
593
|
+
interface BulletChartProps {
|
|
594
|
+
value: number;
|
|
595
|
+
target: number;
|
|
596
|
+
peak?: number;
|
|
597
|
+
max?: number;
|
|
598
|
+
width?: number;
|
|
599
|
+
height?: number;
|
|
600
|
+
unit?: string;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function BulletChart({
|
|
604
|
+
value,
|
|
605
|
+
target,
|
|
606
|
+
peak,
|
|
607
|
+
max = 150,
|
|
608
|
+
width = 200,
|
|
609
|
+
height = 28,
|
|
610
|
+
unit = '',
|
|
611
|
+
}: BulletChartProps) {
|
|
612
|
+
const pct = Math.min(value / max, 1);
|
|
613
|
+
const targetPct = Math.min(target / max, 1);
|
|
614
|
+
const peakPct = peak ? Math.min(peak / max, 1) : 0;
|
|
615
|
+
|
|
616
|
+
// Zones
|
|
617
|
+
const safeEnd = 0.47; // 70/150
|
|
618
|
+
const warnEnd = 0.73; // 110/150
|
|
619
|
+
|
|
620
|
+
const barH = height * 0.5;
|
|
621
|
+
const barY = (height - barH) / 2;
|
|
622
|
+
|
|
623
|
+
return (
|
|
624
|
+
<div className="bullet-chart">
|
|
625
|
+
<svg width={width} height={height} viewBox={`0 0 ${width} ${height}`}>
|
|
626
|
+
{/* Background zones */}
|
|
627
|
+
<rect x={0} y={barY} width={width * safeEnd} height={barH} fill="var(--success)" opacity={0.15} rx={3} />
|
|
628
|
+
<rect x={width * safeEnd} y={barY} width={width * (warnEnd - safeEnd)} height={barH} fill="var(--warning)" opacity={0.15} />
|
|
629
|
+
<rect x={width * warnEnd} y={barY} width={width * (1 - warnEnd)} height={barH} fill="var(--error)" opacity={0.15} rx={3} />
|
|
630
|
+
|
|
631
|
+
{/* Value bar */}
|
|
632
|
+
<rect
|
|
633
|
+
x={0} y={barY}
|
|
634
|
+
width={Math.max(width * pct, 2)}
|
|
635
|
+
height={barH}
|
|
636
|
+
fill={value >= target ? 'var(--error)' : value >= target * 0.7 ? 'var(--warning)' : 'var(--success)'}
|
|
637
|
+
rx={3}
|
|
638
|
+
>
|
|
639
|
+
<title>{`GFI: ${value}${unit} | 阈值: ${target}${unit}`}{peak ? ` | 今日峰值: ${peak}${unit}` : ''}</title>
|
|
640
|
+
</rect>
|
|
641
|
+
|
|
642
|
+
{/* Target marker */}
|
|
643
|
+
<line
|
|
644
|
+
x1={width * targetPct} y1={barY - 2}
|
|
645
|
+
x2={width * targetPct} y2={barY + barH + 2}
|
|
646
|
+
stroke="var(--text-primary)" strokeWidth={2} opacity={0.7}
|
|
647
|
+
/>
|
|
648
|
+
|
|
649
|
+
{/* Peak marker */}
|
|
650
|
+
{peakPct > pct && (
|
|
651
|
+
<circle cx={width * peakPct} cy={height / 2} r={3} fill="var(--warning)" opacity={0.8} />
|
|
652
|
+
)}
|
|
653
|
+
</svg>
|
|
654
|
+
<div className="bullet-labels" style={{ display: 'flex', justifyContent: 'space-between', marginTop: 2, fontSize: '0.7rem', color: 'var(--text-secondary)' }}>
|
|
655
|
+
<span>0</span>
|
|
656
|
+
<span style={{ position: 'relative', left: `-${width * targetPct * 0.3}px` }}>阈值 {target}</span>
|
|
657
|
+
<span>{max}</span>
|
|
658
|
+
</div>
|
|
659
|
+
</div>
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* GaugeChart - 半圆仪表盘
|
|
665
|
+
* 用于展示 Trust Score (0-100)
|
|
666
|
+
*/
|
|
667
|
+
|
|
668
|
+
interface GaugeChartProps {
|
|
669
|
+
value: number;
|
|
670
|
+
max?: number;
|
|
671
|
+
label: string;
|
|
672
|
+
sublabel?: string;
|
|
673
|
+
size?: number;
|
|
674
|
+
segments?: Array<{ label: string; color: string; max: number }>;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
export function GaugeChart({
|
|
678
|
+
value,
|
|
679
|
+
max = 100,
|
|
680
|
+
label,
|
|
681
|
+
sublabel,
|
|
682
|
+
size = 100,
|
|
683
|
+
segments = [
|
|
684
|
+
{ label: 'Observer', color: 'var(--text-secondary)', max: 30 },
|
|
685
|
+
{ label: 'Editor', color: 'var(--info)', max: 60 },
|
|
686
|
+
{ label: 'Developer', color: 'var(--accent)', max: 80 },
|
|
687
|
+
{ label: 'Architect', color: 'var(--success)', max: 100 },
|
|
688
|
+
],
|
|
689
|
+
}: GaugeChartProps) {
|
|
690
|
+
const pct = Math.min(value / max, 1);
|
|
691
|
+
const radius = (size - 16) / 2;
|
|
692
|
+
const center = size / 2;
|
|
693
|
+
const circumference = Math.PI * radius;
|
|
694
|
+
const arcLength = circumference * pct;
|
|
695
|
+
|
|
696
|
+
// Find current segment
|
|
697
|
+
const currentSeg = segments.find(s => value <= s.max) ?? segments[segments.length - 1];
|
|
698
|
+
|
|
699
|
+
return (
|
|
700
|
+
<div className="gauge-chart" style={{ textAlign: 'center' }}>
|
|
701
|
+
<svg width={size} height={size / 2 + 20} viewBox={`0 0 ${size} ${size / 2 + 20}`}>
|
|
702
|
+
{/* Background arc */}
|
|
703
|
+
<path
|
|
704
|
+
d={`M ${center - radius} ${center} A ${radius} ${radius} 0 0 1 ${center + radius} ${center}`}
|
|
705
|
+
fill="none"
|
|
706
|
+
stroke="var(--bg-sunken)"
|
|
707
|
+
strokeWidth={8}
|
|
708
|
+
strokeLinecap="round"
|
|
709
|
+
/>
|
|
710
|
+
{/* Value arc */}
|
|
711
|
+
<path
|
|
712
|
+
d={`M ${center - radius} ${center} A ${radius} ${radius} 0 0 1 ${center + radius} ${center}`}
|
|
713
|
+
fill="none"
|
|
714
|
+
stroke={currentSeg.color}
|
|
715
|
+
strokeWidth={8}
|
|
716
|
+
strokeLinecap="round"
|
|
717
|
+
strokeDasharray={`${arcLength} ${circumference}`}
|
|
718
|
+
style={{ transition: 'stroke-dasharray 0.5s ease' }}
|
|
719
|
+
/>
|
|
720
|
+
{/* Value text */}
|
|
721
|
+
<text
|
|
722
|
+
x={center} y={center - 4}
|
|
723
|
+
textAnchor="middle"
|
|
724
|
+
fontSize="18"
|
|
725
|
+
fontWeight="600"
|
|
726
|
+
fill="var(--text-primary)"
|
|
727
|
+
>
|
|
728
|
+
{value}
|
|
729
|
+
</text>
|
|
730
|
+
</svg>
|
|
731
|
+
<div style={{ fontSize: '0.75rem', color: currentSeg.color, fontWeight: 500 }}>{label}</div>
|
|
732
|
+
{sublabel && <div style={{ fontSize: '0.65rem', color: 'var(--text-secondary)' }}>{sublabel}</div>}
|
|
733
|
+
</div>
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* PrincipleStack - 原则状态堆叠
|
|
739
|
+
* 展示原则分布
|
|
740
|
+
*/
|
|
741
|
+
|
|
742
|
+
interface PrincipleStackProps {
|
|
743
|
+
candidate: number;
|
|
744
|
+
probation: number;
|
|
745
|
+
active: number;
|
|
746
|
+
deprecated: number;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
export function PrincipleStack({ candidate, probation, active, deprecated }: PrincipleStackProps) {
|
|
750
|
+
const total = candidate + probation + active + deprecated;
|
|
751
|
+
const segs = [
|
|
752
|
+
{ label: 'Active', value: active, color: 'var(--success)' },
|
|
753
|
+
{ label: 'Probation', value: probation, color: 'var(--warning)' },
|
|
754
|
+
{ label: 'Candidate', value: candidate, color: 'var(--info)' },
|
|
755
|
+
{ label: 'Deprecated', value: deprecated, color: 'var(--text-secondary)' },
|
|
756
|
+
].filter(s => s.value > 0);
|
|
757
|
+
|
|
758
|
+
if (total === 0) {
|
|
759
|
+
return (
|
|
760
|
+
<div className="principle-stack" style={{ textAlign: 'center', padding: 'var(--space-3)', color: 'var(--text-secondary)', fontSize: '0.85rem' }}>
|
|
761
|
+
No principles yet
|
|
762
|
+
</div>
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
return (
|
|
767
|
+
<div className="principle-stack">
|
|
768
|
+
{/* Stacked bar */}
|
|
769
|
+
<div style={{ display: 'flex', height: 8, borderRadius: 4, overflow: 'hidden', marginBottom: 8 }}>
|
|
770
|
+
{segs.map(seg => (
|
|
771
|
+
<div
|
|
772
|
+
key={seg.label}
|
|
773
|
+
style={{
|
|
774
|
+
width: `${(seg.value / total) * 100}%`,
|
|
775
|
+
backgroundColor: seg.color,
|
|
776
|
+
transition: 'width 0.3s ease',
|
|
777
|
+
}}
|
|
778
|
+
title={`${seg.label}: ${seg.value}`}
|
|
779
|
+
/>
|
|
780
|
+
))}
|
|
781
|
+
</div>
|
|
782
|
+
{/* Legend */}
|
|
783
|
+
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, fontSize: '0.7rem' }}>
|
|
784
|
+
{segs.map(seg => (
|
|
785
|
+
<span key={seg.label} style={{ display: 'flex', alignItems: 'center', gap: 3 }}>
|
|
786
|
+
<span style={{ width: 6, height: 6, borderRadius: '50%', backgroundColor: seg.color, display: 'inline-block' }} />
|
|
787
|
+
<span style={{ color: 'var(--text-secondary)' }}>{seg.label}</span>
|
|
788
|
+
<span style={{ fontWeight: 600, color: 'var(--text-primary)' }}>{seg.value}</span>
|
|
789
|
+
</span>
|
|
790
|
+
))}
|
|
791
|
+
</div>
|
|
792
|
+
</div>
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* QueueBar - 队列状态条
|
|
798
|
+
* 展示 pending/in-progress/completed
|
|
799
|
+
*/
|
|
800
|
+
|
|
801
|
+
interface QueueBarProps {
|
|
802
|
+
pending: number;
|
|
803
|
+
inProgress: number;
|
|
804
|
+
completed: number;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export function QueueBar({ pending, inProgress, completed }: QueueBarProps) {
|
|
808
|
+
const total = pending + inProgress + completed;
|
|
809
|
+
const items = [
|
|
810
|
+
{ label: 'Pending', value: pending, color: 'var(--warning)' },
|
|
811
|
+
{ label: 'In Progress', value: inProgress, color: 'var(--info)' },
|
|
812
|
+
{ label: 'Completed', value: completed, color: 'var(--success)' },
|
|
813
|
+
];
|
|
814
|
+
|
|
815
|
+
if (total === 0) {
|
|
816
|
+
return (
|
|
817
|
+
<div className="queue-bar" style={{ textAlign: 'center', padding: 'var(--space-3)', color: 'var(--text-secondary)', fontSize: '0.85rem' }}>
|
|
818
|
+
Queue empty
|
|
819
|
+
</div>
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
return (
|
|
824
|
+
<div className="queue-bar">
|
|
825
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
826
|
+
{items.map(item => (
|
|
827
|
+
<div key={item.label} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
828
|
+
<div style={{ width: 6, height: 6, borderRadius: '50%', backgroundColor: item.color, flexShrink: 0 }} />
|
|
829
|
+
<span style={{ fontSize: '0.7rem', color: 'var(--text-secondary)', minWidth: 55 }}>{item.label}</span>
|
|
830
|
+
<div style={{ flex: 1, height: 6, backgroundColor: 'var(--bg-sunken)', borderRadius: 3, overflow: 'hidden' }}>
|
|
831
|
+
<div
|
|
832
|
+
style={{
|
|
833
|
+
width: `${(item.value / total) * 100}%`,
|
|
834
|
+
height: '100%',
|
|
835
|
+
backgroundColor: item.color,
|
|
836
|
+
borderRadius: 3,
|
|
837
|
+
minWidth: item.value > 0 ? 4 : 0,
|
|
838
|
+
transition: 'width 0.3s ease',
|
|
839
|
+
}}
|
|
840
|
+
/>
|
|
841
|
+
</div>
|
|
842
|
+
<span style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-primary)', minWidth: 20, textAlign: 'right' }}>{item.value}</span>
|
|
843
|
+
</div>
|
|
844
|
+
))}
|
|
845
|
+
</div>
|
|
846
|
+
</div>
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* LineChart - 全尺寸折线图
|
|
852
|
+
* 用于展示 GFI 等时间序列数据的完整趋势
|
|
853
|
+
*/
|
|
854
|
+
|
|
855
|
+
interface LineChartProps {
|
|
856
|
+
data: Array<{ label: string; value: number }>;
|
|
857
|
+
width?: number;
|
|
858
|
+
height?: number;
|
|
859
|
+
color?: string;
|
|
860
|
+
showGrid?: boolean;
|
|
861
|
+
showDots?: boolean;
|
|
862
|
+
showArea?: boolean;
|
|
863
|
+
unit?: string;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
export function LineChart({
|
|
867
|
+
data,
|
|
868
|
+
width = 560,
|
|
869
|
+
height = 180,
|
|
870
|
+
color = 'var(--accent)',
|
|
871
|
+
showGrid = true,
|
|
872
|
+
showDots = true,
|
|
873
|
+
showArea = true,
|
|
874
|
+
unit = '',
|
|
875
|
+
}: LineChartProps) {
|
|
876
|
+
if (!data || data.length === 0) {
|
|
877
|
+
return (
|
|
878
|
+
<div style={{ height, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text-secondary)', fontSize: '0.85rem' }}>
|
|
879
|
+
暂无数据
|
|
880
|
+
</div>
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
const padding = { top: 16, right: 16, bottom: 28, left: 44 };
|
|
885
|
+
const chartW = width - padding.left - padding.right;
|
|
886
|
+
const chartH = height - padding.top - padding.bottom;
|
|
887
|
+
|
|
888
|
+
const values = data.map(d => d.value);
|
|
889
|
+
const maxVal = Math.max(...values, 1);
|
|
890
|
+
const minVal = Math.min(...values, 0);
|
|
891
|
+
const range = maxVal - minVal || 1;
|
|
892
|
+
|
|
893
|
+
// Y-axis ticks (5 ticks)
|
|
894
|
+
const yTicks = Array.from({ length: 5 }, (_, i) => minVal + (range * i) / 4);
|
|
895
|
+
|
|
896
|
+
const xStep = data.length > 1 ? chartW / (data.length - 1) : 0;
|
|
897
|
+
|
|
898
|
+
const points = data.map((d, i) => ({
|
|
899
|
+
x: padding.left + (data.length > 1 ? i * xStep : chartW / 2),
|
|
900
|
+
y: padding.top + chartH - ((d.value - minVal) / range) * chartH,
|
|
901
|
+
label: d.label,
|
|
902
|
+
value: d.value,
|
|
903
|
+
}));
|
|
904
|
+
|
|
905
|
+
const linePath = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ');
|
|
906
|
+
const areaPath = linePath + ` L ${points[points.length - 1].x} ${padding.top + chartH} L ${points[0].x} ${padding.top + chartH} Z`;
|
|
907
|
+
|
|
908
|
+
return (
|
|
909
|
+
<svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} style={{ display: 'block' }}>
|
|
910
|
+
{/* Grid lines */}
|
|
911
|
+
{showGrid && yTicks.map((tick, i) => {
|
|
912
|
+
const y = padding.top + chartH - ((tick - minVal) / range) * chartH;
|
|
913
|
+
return (
|
|
914
|
+
<g key={i}>
|
|
915
|
+
<line x1={padding.left} y1={y} x2={padding.left + chartW} y2={y} stroke="var(--border)" strokeWidth={0.5} strokeDasharray="3 3" />
|
|
916
|
+
<text x={padding.left - 6} y={y + 4} textAnchor="end" fontSize="10" fill="var(--text-secondary)">
|
|
917
|
+
{Math.round(tick)}
|
|
918
|
+
</text>
|
|
919
|
+
</g>
|
|
920
|
+
);
|
|
921
|
+
})}
|
|
922
|
+
|
|
923
|
+
{/* Area fill */}
|
|
924
|
+
{showArea && points.length > 1 && (
|
|
925
|
+
<path d={areaPath} fill={color} fillOpacity={0.08} />
|
|
926
|
+
)}
|
|
927
|
+
|
|
928
|
+
{/* Line */}
|
|
929
|
+
<path d={linePath} fill="none" stroke={color} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" />
|
|
930
|
+
|
|
931
|
+
{/* Dots */}
|
|
932
|
+
{showDots && points.map((p, i) => (
|
|
933
|
+
<g key={i}>
|
|
934
|
+
<circle cx={p.x} cy={p.y} r={3} fill={color} stroke="var(--bg-raised)" strokeWidth={1.5} />
|
|
935
|
+
<title>{p.label}: {p.value}{unit}</title>
|
|
936
|
+
</g>
|
|
937
|
+
))}
|
|
938
|
+
|
|
939
|
+
{/* X-axis labels */}
|
|
940
|
+
{points.map((p, i) => {
|
|
941
|
+
// Skip some labels if too many
|
|
942
|
+
const skipCount = data.length > 12 ? 2 : data.length > 8 ? 1 : 0;
|
|
943
|
+
if (i % (skipCount + 1) !== 0 && i !== points.length - 1) return null;
|
|
944
|
+
return (
|
|
945
|
+
<text key={i} x={p.x} y={height - 4} textAnchor="middle" fontSize="9" fill="var(--text-secondary)">
|
|
946
|
+
{p.label}
|
|
947
|
+
</text>
|
|
948
|
+
);
|
|
949
|
+
})}
|
|
950
|
+
</svg>
|
|
951
|
+
);
|
|
952
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { api } from '../api';
|
|
3
3
|
import { useI18n } from '../i18n/ui';
|
|
4
|
-
import {
|
|
5
|
-
import { Loading } from './Loading';
|
|
4
|
+
import { Settings, ChevronDown, ChevronUp } from 'lucide-react';
|
|
6
5
|
|
|
7
6
|
export function WorkspaceConfig() {
|
|
8
7
|
const { t } = useI18n();
|
|
8
|
+
const [visible, setVisible] = useState(false);
|
|
9
9
|
const [wsData, setWsData] = useState<{
|
|
10
10
|
configs: Array<{ workspaceName: string; enabled: boolean; displayName: string | null; syncEnabled: boolean }>;
|
|
11
11
|
workspaces: Array<{ name: string; path: string; lastSync: string | null; config: null | { workspaceName: string; enabled: boolean; displayName: string | null; syncEnabled: boolean } }>;
|
|
@@ -28,8 +28,8 @@ export function WorkspaceConfig() {
|
|
|
28
28
|
}, []);
|
|
29
29
|
|
|
30
30
|
useEffect(() => {
|
|
31
|
-
loadConfigs();
|
|
32
|
-
}, [loadConfigs]);
|
|
31
|
+
if (visible) loadConfigs();
|
|
32
|
+
}, [loadConfigs, visible]);
|
|
33
33
|
|
|
34
34
|
const handleToggle = async (workspaceName: string, field: 'enabled' | 'syncEnabled', currentValue: boolean) => {
|
|
35
35
|
setSaving(workspaceName);
|
|
@@ -61,86 +61,118 @@ export function WorkspaceConfig() {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const enabledCount = (wsData?.configs ?? []).filter(c => c.enabled && c.syncEnabled).length;
|
|
65
|
+
const totalCount = wsData?.workspaces?.length ?? 0;
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
// Toggle bar (always visible)
|
|
68
|
+
if (!visible) {
|
|
69
|
+
return (
|
|
70
|
+
<div style={{ marginBottom: 'var(--space-4)' }}>
|
|
71
|
+
<button
|
|
72
|
+
className="button-secondary"
|
|
73
|
+
onClick={() => setVisible(true)}
|
|
74
|
+
style={{ display: 'flex', alignItems: 'center', gap: 'var(--space-2)', fontSize: '0.8rem' }}
|
|
75
|
+
>
|
|
76
|
+
<Settings size={14} />
|
|
77
|
+
<span>{t('workspace.title')}</span>
|
|
78
|
+
{wsData && (
|
|
79
|
+
<span className="badge" style={{ fontSize: '0.7rem' }}>{enabledCount} / {totalCount}</span>
|
|
80
|
+
)}
|
|
76
81
|
</button>
|
|
77
82
|
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<div style={{ display: 'flex', gap: 'var(--space-3)', alignItems: 'flex-end' }}>
|
|
82
|
-
<div style={{ flex: 1 }}>
|
|
83
|
-
<label style={{ display: 'block', fontSize: '12px', marginBottom: '4px', color: 'var(--text-secondary)' }}>{t('workspace.workspaceName')}</label>
|
|
84
|
-
<input
|
|
85
|
-
type="text"
|
|
86
|
-
value={newWsName}
|
|
87
|
-
onChange={(e) => setNewWsName(e.target.value)}
|
|
88
|
-
placeholder={t('workspace.placeholder.name')}
|
|
89
|
-
style={{ width: '100%', padding: 'var(--space-2)', fontSize: '13px', border: '1px solid var(--border)', borderRadius: 'var(--radius-sm)' }}
|
|
90
|
-
/>
|
|
91
|
-
</div>
|
|
92
|
-
<div style={{ flex: 2 }}>
|
|
93
|
-
<label style={{ display: 'block', fontSize: '12px', marginBottom: '4px', color: 'var(--text-secondary)' }}>{t('workspace.path')}</label>
|
|
94
|
-
<input
|
|
95
|
-
type="text"
|
|
96
|
-
value={newWsPath}
|
|
97
|
-
onChange={(e) => setNewWsPath(e.target.value)}
|
|
98
|
-
placeholder={t('workspace.placeholder.path')}
|
|
99
|
-
style={{ width: '100%', padding: 'var(--space-2)', fontSize: '13px', border: '1px solid var(--border)', borderRadius: 'var(--radius-sm)' }}
|
|
100
|
-
/>
|
|
101
|
-
</div>
|
|
102
|
-
<button type="submit" className="button-primary" disabled={adding || !newWsName.trim() || !newWsPath.trim()}>
|
|
103
|
-
{adding ? t('workspace.adding') : t('workspace.addWorkspace')}
|
|
104
|
-
</button>
|
|
105
|
-
</div>
|
|
106
|
-
</form>
|
|
107
|
-
)}
|
|
86
|
+
if (error) return <div className="panel error">{error}</div>;
|
|
87
|
+
if (!wsData) return <div className="panel" style={{ padding: 'var(--space-3)' }}>Loading...</div>;
|
|
108
88
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
89
|
+
return (
|
|
90
|
+
<section className="panel" style={{ marginBottom: 'var(--space-4)' }}>
|
|
91
|
+
<div
|
|
92
|
+
className="panel-header"
|
|
93
|
+
style={{ cursor: 'pointer', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}
|
|
94
|
+
onClick={() => setVisible(false)}
|
|
95
|
+
>
|
|
96
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 'var(--space-2)' }}>
|
|
97
|
+
<Settings size={16} />
|
|
98
|
+
<h3 style={{ fontSize: '0.9rem', margin: 0 }}>{t('workspace.title')}</h3>
|
|
99
|
+
<span className="badge" style={{ fontSize: '0.7rem' }}>{enabledCount} / {totalCount} enabled</span>
|
|
100
|
+
</div>
|
|
101
|
+
<ChevronUp size={18} style={{ color: 'var(--text-secondary)' }} />
|
|
102
|
+
</div>
|
|
103
|
+
<div className="panel-content">
|
|
104
|
+
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: 'var(--space-4)' }}>
|
|
105
|
+
<button className="button-secondary" onClick={() => setShowAddForm(!showAddForm)}>
|
|
106
|
+
{showAddForm ? t('workspace.cancel') : '+ ' + t('workspace.addWorkspace')}
|
|
107
|
+
</button>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
{showAddForm && (
|
|
111
|
+
<form className="add-workspace-form" onSubmit={handleAddWorkspace} style={{ marginBottom: 'var(--space-4)', padding: 'var(--space-3)', background: 'var(--bg-sunken)', borderRadius: 'var(--radius-md)', border: '1px solid var(--border)' }}>
|
|
112
|
+
<div style={{ display: 'flex', gap: 'var(--space-3)', alignItems: 'flex-end' }}>
|
|
113
|
+
<div style={{ flex: 1 }}>
|
|
114
|
+
<label style={{ display: 'block', fontSize: '12px', marginBottom: '4px', color: 'var(--text-secondary)' }}>{t('workspace.workspaceName')}</label>
|
|
115
|
+
<input
|
|
116
|
+
type="text"
|
|
117
|
+
value={newWsName}
|
|
118
|
+
onChange={(e) => setNewWsName(e.target.value)}
|
|
119
|
+
placeholder={t('workspace.placeholder.name')}
|
|
120
|
+
style={{ width: '100%', padding: 'var(--space-2)', fontSize: '13px', border: '1px solid var(--border)', borderRadius: 'var(--radius-sm)' }}
|
|
121
|
+
/>
|
|
118
122
|
</div>
|
|
119
|
-
<div style={{
|
|
120
|
-
<label style={{ display: '
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
</label>
|
|
129
|
-
<label style={{ display: 'flex', alignItems: 'center', gap: 'var(--space-2)', cursor: 'pointer' }}>
|
|
130
|
-
<input
|
|
131
|
-
type="checkbox"
|
|
132
|
-
checked={config.syncEnabled}
|
|
133
|
-
onChange={() => handleToggle(ws.name, 'syncEnabled', config.syncEnabled)}
|
|
134
|
-
disabled={isSaving || !config.enabled}
|
|
135
|
-
/>
|
|
136
|
-
<span style={{ fontSize: '13px' }}>{t('workspace.sync')}</span>
|
|
137
|
-
</label>
|
|
123
|
+
<div style={{ flex: 2 }}>
|
|
124
|
+
<label style={{ display: 'block', fontSize: '12px', marginBottom: '4px', color: 'var(--text-secondary)' }}>{t('workspace.path')}</label>
|
|
125
|
+
<input
|
|
126
|
+
type="text"
|
|
127
|
+
value={newWsPath}
|
|
128
|
+
onChange={(e) => setNewWsPath(e.target.value)}
|
|
129
|
+
placeholder={t('workspace.placeholder.path')}
|
|
130
|
+
style={{ width: '100%', padding: 'var(--space-2)', fontSize: '13px', border: '1px solid var(--border)', borderRadius: 'var(--radius-sm)' }}
|
|
131
|
+
/>
|
|
138
132
|
</div>
|
|
133
|
+
<button type="submit" className="button-primary" disabled={adding || !newWsName.trim() || !newWsPath.trim()}>
|
|
134
|
+
{adding ? t('workspace.adding') : t('workspace.addWorkspace')}
|
|
135
|
+
</button>
|
|
139
136
|
</div>
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
</form>
|
|
138
|
+
)}
|
|
139
|
+
|
|
140
|
+
<div className="stack">
|
|
141
|
+
{(wsData.workspaces ?? []).map((ws) => {
|
|
142
|
+
const config = ws.config ?? { workspaceName: ws.name, enabled: true, displayName: ws.name, syncEnabled: true };
|
|
143
|
+
const isSaving = saving === ws.name;
|
|
144
|
+
return (
|
|
145
|
+
<div className="row-card" key={ws.name}>
|
|
146
|
+
<div>
|
|
147
|
+
<strong>{ws.name}</strong>
|
|
148
|
+
<span>{ws.path}</span>
|
|
149
|
+
</div>
|
|
150
|
+
<div style={{ display: 'flex', gap: 'var(--space-3)', alignItems: 'center' }}>
|
|
151
|
+
<label style={{ display: 'flex', alignItems: 'center', gap: 'var(--space-2)', cursor: 'pointer' }}>
|
|
152
|
+
<input
|
|
153
|
+
type="checkbox"
|
|
154
|
+
checked={config.enabled}
|
|
155
|
+
onChange={() => handleToggle(ws.name, 'enabled', config.enabled)}
|
|
156
|
+
disabled={isSaving}
|
|
157
|
+
/>
|
|
158
|
+
<span style={{ fontSize: '13px' }}>{t('workspace.include')}</span>
|
|
159
|
+
</label>
|
|
160
|
+
<label style={{ display: 'flex', alignItems: 'center', gap: 'var(--space-2)', cursor: 'pointer' }}>
|
|
161
|
+
<input
|
|
162
|
+
type="checkbox"
|
|
163
|
+
checked={config.syncEnabled}
|
|
164
|
+
onChange={() => handleToggle(ws.name, 'syncEnabled', config.syncEnabled)}
|
|
165
|
+
disabled={isSaving || !config.enabled}
|
|
166
|
+
/>
|
|
167
|
+
<span style={{ fontSize: '13px' }}>{t('workspace.sync')}</span>
|
|
168
|
+
</label>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
})}
|
|
173
|
+
</div>
|
|
142
174
|
</div>
|
|
143
|
-
</
|
|
175
|
+
</section>
|
|
144
176
|
);
|
|
145
177
|
}
|
|
146
178
|
|