@peakinfer/cli 1.0.133
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/settings.local.json +8 -0
- package/.env.example +6 -0
- package/.github/workflows/peakinfer.yml +64 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +190 -0
- package/README.md +335 -0
- package/data/inferencemax.json +274 -0
- package/dist/agent-analyzer.d.ts +45 -0
- package/dist/agent-analyzer.d.ts.map +1 -0
- package/dist/agent-analyzer.js +374 -0
- package/dist/agent-analyzer.js.map +1 -0
- package/dist/agent.d.ts +76 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +965 -0
- package/dist/agent.js.map +1 -0
- package/dist/agents/correlation-analyzer.d.ts +34 -0
- package/dist/agents/correlation-analyzer.d.ts.map +1 -0
- package/dist/agents/correlation-analyzer.js +261 -0
- package/dist/agents/correlation-analyzer.js.map +1 -0
- package/dist/agents/index.d.ts +91 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +111 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/runtime-analyzer.d.ts +38 -0
- package/dist/agents/runtime-analyzer.d.ts.map +1 -0
- package/dist/agents/runtime-analyzer.js +244 -0
- package/dist/agents/runtime-analyzer.js.map +1 -0
- package/dist/analysis-types.d.ts +500 -0
- package/dist/analysis-types.d.ts.map +1 -0
- package/dist/analysis-types.js +11 -0
- package/dist/analysis-types.js.map +1 -0
- package/dist/analytics.d.ts +25 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +94 -0
- package/dist/analytics.js.map +1 -0
- package/dist/analyzer.d.ts +48 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/analyzer.js +547 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/artifacts.d.ts +44 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +165 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/benchmarks/index.d.ts +88 -0
- package/dist/benchmarks/index.d.ts.map +1 -0
- package/dist/benchmarks/index.js +205 -0
- package/dist/benchmarks/index.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +427 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/ci.d.ts +19 -0
- package/dist/commands/ci.d.ts.map +1 -0
- package/dist/commands/ci.js +253 -0
- package/dist/commands/ci.js.map +1 -0
- package/dist/commands/config.d.ts +16 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +249 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/demo.d.ts +15 -0
- package/dist/commands/demo.d.ts.map +1 -0
- package/dist/commands/demo.js +106 -0
- package/dist/commands/demo.js.map +1 -0
- package/dist/commands/export.d.ts +14 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +209 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/history.d.ts +15 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +389 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/template.d.ts +14 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/template.js +341 -0
- package/dist/commands/template.js.map +1 -0
- package/dist/commands/validate-map.d.ts +12 -0
- package/dist/commands/validate-map.d.ts.map +1 -0
- package/dist/commands/validate-map.js +274 -0
- package/dist/commands/validate-map.js.map +1 -0
- package/dist/commands/whatif.d.ts +17 -0
- package/dist/commands/whatif.d.ts.map +1 -0
- package/dist/commands/whatif.js +206 -0
- package/dist/commands/whatif.js.map +1 -0
- package/dist/comparison.d.ts +38 -0
- package/dist/comparison.d.ts.map +1 -0
- package/dist/comparison.js +223 -0
- package/dist/comparison.js.map +1 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +158 -0
- package/dist/config.js.map +1 -0
- package/dist/connectors/helicone.d.ts +9 -0
- package/dist/connectors/helicone.d.ts.map +1 -0
- package/dist/connectors/helicone.js +106 -0
- package/dist/connectors/helicone.js.map +1 -0
- package/dist/connectors/index.d.ts +37 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +65 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors/langsmith.d.ts +9 -0
- package/dist/connectors/langsmith.d.ts.map +1 -0
- package/dist/connectors/langsmith.js +122 -0
- package/dist/connectors/langsmith.js.map +1 -0
- package/dist/connectors/types.d.ts +83 -0
- package/dist/connectors/types.d.ts.map +1 -0
- package/dist/connectors/types.js +98 -0
- package/dist/connectors/types.js.map +1 -0
- package/dist/cost-estimator.d.ts +46 -0
- package/dist/cost-estimator.d.ts.map +1 -0
- package/dist/cost-estimator.js +104 -0
- package/dist/cost-estimator.js.map +1 -0
- package/dist/costs.d.ts +57 -0
- package/dist/costs.d.ts.map +1 -0
- package/dist/costs.js +251 -0
- package/dist/costs.js.map +1 -0
- package/dist/counterfactuals.d.ts +29 -0
- package/dist/counterfactuals.d.ts.map +1 -0
- package/dist/counterfactuals.js +448 -0
- package/dist/counterfactuals.js.map +1 -0
- package/dist/enhancement-prompts.d.ts +41 -0
- package/dist/enhancement-prompts.d.ts.map +1 -0
- package/dist/enhancement-prompts.js +88 -0
- package/dist/enhancement-prompts.js.map +1 -0
- package/dist/envelopes.d.ts +20 -0
- package/dist/envelopes.d.ts.map +1 -0
- package/dist/envelopes.js +790 -0
- package/dist/envelopes.js.map +1 -0
- package/dist/format-normalizer.d.ts +71 -0
- package/dist/format-normalizer.d.ts.map +1 -0
- package/dist/format-normalizer.js +1331 -0
- package/dist/format-normalizer.js.map +1 -0
- package/dist/history.d.ts +79 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +313 -0
- package/dist/history.js.map +1 -0
- package/dist/html.d.ts +11 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +463 -0
- package/dist/html.js.map +1 -0
- package/dist/impact.d.ts +42 -0
- package/dist/impact.d.ts.map +1 -0
- package/dist/impact.js +443 -0
- package/dist/impact.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/insights.d.ts +5 -0
- package/dist/insights.d.ts.map +1 -0
- package/dist/insights.js +271 -0
- package/dist/insights.js.map +1 -0
- package/dist/joiner.d.ts +9 -0
- package/dist/joiner.d.ts.map +1 -0
- package/dist/joiner.js +247 -0
- package/dist/joiner.js.map +1 -0
- package/dist/orchestrator.d.ts +34 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +827 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/pdf.d.ts +26 -0
- package/dist/pdf.d.ts.map +1 -0
- package/dist/pdf.js +84 -0
- package/dist/pdf.js.map +1 -0
- package/dist/prediction.d.ts +33 -0
- package/dist/prediction.d.ts.map +1 -0
- package/dist/prediction.js +316 -0
- package/dist/prediction.js.map +1 -0
- package/dist/prompts/loader.d.ts +38 -0
- package/dist/prompts/loader.d.ts.map +1 -0
- package/dist/prompts/loader.js +60 -0
- package/dist/prompts/loader.js.map +1 -0
- package/dist/renderer.d.ts +64 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +923 -0
- package/dist/renderer.js.map +1 -0
- package/dist/runid.d.ts +57 -0
- package/dist/runid.d.ts.map +1 -0
- package/dist/runid.js +199 -0
- package/dist/runid.js.map +1 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +366 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scanner.d.ts +11 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +426 -0
- package/dist/scanner.js.map +1 -0
- package/dist/templates.d.ts +120 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +429 -0
- package/dist/templates.js.map +1 -0
- package/dist/tools/index.d.ts +153 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +177 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types.d.ts +3647 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +703 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +23 -0
- package/dist/version.js.map +1 -0
- package/docs/demo-guide.md +423 -0
- package/docs/events-format.md +295 -0
- package/docs/inferencemap-spec.md +344 -0
- package/docs/migration-v2.md +293 -0
- package/fixtures/demo/precomputed.json +142 -0
- package/fixtures/demo-project/README.md +52 -0
- package/fixtures/demo-project/ai-service.ts +65 -0
- package/fixtures/demo-project/sample-events.jsonl +15 -0
- package/fixtures/demo-project/src/ai-service.ts +128 -0
- package/fixtures/demo-project/src/llm-client.ts +155 -0
- package/package.json +65 -0
- package/prompts/agent-analyzer.yaml +47 -0
- package/prompts/ci-gate.yaml +98 -0
- package/prompts/correlation-analyzer.yaml +178 -0
- package/prompts/format-normalizer.yaml +46 -0
- package/prompts/peak-performance.yaml +180 -0
- package/prompts/pr-comment.yaml +111 -0
- package/prompts/runtime-analyzer.yaml +189 -0
- package/prompts/unified-analyzer.yaml +241 -0
- package/schemas/inference-map.v0.1.json +215 -0
- package/scripts/benchmark.ts +394 -0
- package/scripts/demo-v1.5.sh +158 -0
- package/scripts/sync-from-site.sh +197 -0
- package/scripts/validate-sync.sh +178 -0
- package/src/agent-analyzer.ts +481 -0
- package/src/agent.ts +1232 -0
- package/src/agents/correlation-analyzer.ts +353 -0
- package/src/agents/index.ts +235 -0
- package/src/agents/runtime-analyzer.ts +343 -0
- package/src/analysis-types.ts +558 -0
- package/src/analytics.ts +100 -0
- package/src/analyzer.ts +692 -0
- package/src/artifacts.ts +218 -0
- package/src/benchmarks/index.ts +309 -0
- package/src/cli.ts +503 -0
- package/src/commands/ci.ts +336 -0
- package/src/commands/config.ts +288 -0
- package/src/commands/demo.ts +175 -0
- package/src/commands/export.ts +297 -0
- package/src/commands/history.ts +425 -0
- package/src/commands/template.ts +385 -0
- package/src/commands/validate-map.ts +324 -0
- package/src/commands/whatif.ts +272 -0
- package/src/comparison.ts +283 -0
- package/src/config.ts +188 -0
- package/src/connectors/helicone.ts +164 -0
- package/src/connectors/index.ts +93 -0
- package/src/connectors/langsmith.ts +179 -0
- package/src/connectors/types.ts +180 -0
- package/src/cost-estimator.ts +146 -0
- package/src/costs.ts +347 -0
- package/src/counterfactuals.ts +516 -0
- package/src/enhancement-prompts.ts +118 -0
- package/src/envelopes.ts +814 -0
- package/src/format-normalizer.ts +1486 -0
- package/src/history.ts +400 -0
- package/src/html.ts +512 -0
- package/src/impact.ts +522 -0
- package/src/index.ts +83 -0
- package/src/insights.ts +341 -0
- package/src/joiner.ts +289 -0
- package/src/orchestrator.ts +1015 -0
- package/src/pdf.ts +110 -0
- package/src/prediction.ts +392 -0
- package/src/prompts/loader.ts +88 -0
- package/src/renderer.ts +1045 -0
- package/src/runid.ts +261 -0
- package/src/runtime.ts +450 -0
- package/src/scanner.ts +508 -0
- package/src/templates.ts +561 -0
- package/src/tools/index.ts +214 -0
- package/src/types.ts +873 -0
- package/src/version.ts +24 -0
- package/templates/context-accumulation.yaml +23 -0
- package/templates/cost-concentration.yaml +20 -0
- package/templates/dead-code.yaml +20 -0
- package/templates/latency-explainer.yaml +23 -0
- package/templates/optimizations/ab-testing-framework.yaml +74 -0
- package/templates/optimizations/api-gateway-optimization.yaml +81 -0
- package/templates/optimizations/api-model-routing-strategy.yaml +126 -0
- package/templates/optimizations/auto-scaling-optimization.yaml +85 -0
- package/templates/optimizations/batch-utilization-diagnostic.yaml +142 -0
- package/templates/optimizations/comprehensive-apm.yaml +76 -0
- package/templates/optimizations/context-window-optimization.yaml +91 -0
- package/templates/optimizations/cost-sensitive-batch-processing.yaml +77 -0
- package/templates/optimizations/distributed-training-optimization.yaml +77 -0
- package/templates/optimizations/document-analysis-edge.yaml +77 -0
- package/templates/optimizations/document-pipeline-optimization.yaml +78 -0
- package/templates/optimizations/domain-specific-distillation.yaml +78 -0
- package/templates/optimizations/error-handling-optimization.yaml +76 -0
- package/templates/optimizations/gptq-4bit-quantization.yaml +96 -0
- package/templates/optimizations/long-context-memory-management.yaml +78 -0
- package/templates/optimizations/max-tokens-optimization.yaml +76 -0
- package/templates/optimizations/memory-bandwidth-optimization.yaml +73 -0
- package/templates/optimizations/multi-framework-resilience.yaml +75 -0
- package/templates/optimizations/multi-tenant-optimization.yaml +75 -0
- package/templates/optimizations/prompt-caching-optimization.yaml +143 -0
- package/templates/optimizations/pytorch-to-onnx-migration.yaml +109 -0
- package/templates/optimizations/quality-monitoring.yaml +74 -0
- package/templates/optimizations/realtime-budget-controls.yaml +74 -0
- package/templates/optimizations/realtime-latency-optimization.yaml +74 -0
- package/templates/optimizations/sglang-concurrency-optimization.yaml +78 -0
- package/templates/optimizations/smart-model-routing.yaml +96 -0
- package/templates/optimizations/streaming-batch-selection.yaml +167 -0
- package/templates/optimizations/system-prompt-optimization.yaml +75 -0
- package/templates/optimizations/tensorrt-llm-performance.yaml +77 -0
- package/templates/optimizations/vllm-high-throughput-optimization.yaml +93 -0
- package/templates/optimizations/vllm-migration-memory-bound.yaml +78 -0
- package/templates/overpowered-extraction.yaml +32 -0
- package/templates/overpowered-model.yaml +31 -0
- package/templates/prompt-bloat.yaml +24 -0
- package/templates/retry-explosion.yaml +28 -0
- package/templates/schema/insight.schema.json +113 -0
- package/templates/schema/optimization.schema.json +180 -0
- package/templates/streaming-drift.yaml +30 -0
- package/templates/throughput-gap.yaml +21 -0
- package/templates/token-underutilization.yaml +28 -0
- package/templates/untested-fallback.yaml +21 -0
- package/tests/accuracy/drift-detection.test.ts +184 -0
- package/tests/accuracy/false-positives.test.ts +166 -0
- package/tests/accuracy/templates.test.ts +205 -0
- package/tests/action/commands.test.ts +125 -0
- package/tests/action/comments.test.ts +347 -0
- package/tests/cli.test.ts +203 -0
- package/tests/comparison.test.ts +309 -0
- package/tests/correlation-analyzer.test.ts +534 -0
- package/tests/counterfactuals.test.ts +347 -0
- package/tests/fixtures/events/missing-id.jsonl +1 -0
- package/tests/fixtures/events/missing-input.jsonl +1 -0
- package/tests/fixtures/events/missing-latency.jsonl +1 -0
- package/tests/fixtures/events/missing-model.jsonl +1 -0
- package/tests/fixtures/events/missing-output.jsonl +1 -0
- package/tests/fixtures/events/missing-provider.jsonl +1 -0
- package/tests/fixtures/events/missing-ts.jsonl +1 -0
- package/tests/fixtures/events/valid.csv +3 -0
- package/tests/fixtures/events/valid.json +1 -0
- package/tests/fixtures/events/valid.jsonl +2 -0
- package/tests/fixtures/events/with-callsite.jsonl +1 -0
- package/tests/fixtures/events/with-intent.jsonl +1 -0
- package/tests/fixtures/events/wrong-type.jsonl +1 -0
- package/tests/fixtures/repos/empty/.gitkeep +0 -0
- package/tests/fixtures/repos/hybrid-router/router.py +35 -0
- package/tests/fixtures/repos/saas-anthropic/agent.ts +27 -0
- package/tests/fixtures/repos/saas-openai/assistant.js +33 -0
- package/tests/fixtures/repos/saas-openai/client.py +26 -0
- package/tests/fixtures/repos/self-hosted-vllm/inference.py +22 -0
- package/tests/github-action.test.ts +292 -0
- package/tests/insights.test.ts +878 -0
- package/tests/joiner.test.ts +168 -0
- package/tests/performance/action-latency.test.ts +132 -0
- package/tests/performance/benchmark.test.ts +189 -0
- package/tests/performance/cli-latency.test.ts +102 -0
- package/tests/pr-comment.test.ts +313 -0
- package/tests/prediction.test.ts +296 -0
- package/tests/runtime-analyzer.test.ts +375 -0
- package/tests/runtime.test.ts +205 -0
- package/tests/scanner.test.ts +122 -0
- package/tests/template-conformance.test.ts +526 -0
- package/tests/unit/cost-calculator.test.ts +303 -0
- package/tests/unit/credits.test.ts +180 -0
- package/tests/unit/inference-map.test.ts +276 -0
- package/tests/unit/schema.test.ts +300 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# PeakInfer Sync Script
|
|
4
|
+
# =============================================================================
|
|
5
|
+
# Development convenience script to sync source-of-truth files from peakinfer-site.
|
|
6
|
+
#
|
|
7
|
+
# IMPORTANT: This script is for DEVELOPMENT ONLY.
|
|
8
|
+
# The peakinfer CLI is fully self-contained and does NOT depend on peakinfer-site
|
|
9
|
+
# at runtime. All synced files are committed to this repo for enterprise auditability.
|
|
10
|
+
#
|
|
11
|
+
# Usage:
|
|
12
|
+
# ./scripts/sync-from-site.sh [--dry-run] [--check]
|
|
13
|
+
#
|
|
14
|
+
# Options:
|
|
15
|
+
# --dry-run Show what would be synced without making changes
|
|
16
|
+
# --check Exit with error if files are out of sync (for CI)
|
|
17
|
+
# =============================================================================
|
|
18
|
+
|
|
19
|
+
set -e
|
|
20
|
+
|
|
21
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
22
|
+
CLI_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
23
|
+
SITE_ROOT="$(dirname "$CLI_ROOT")/peakinfer-site"
|
|
24
|
+
|
|
25
|
+
# Colors for output
|
|
26
|
+
RED='\033[0;31m'
|
|
27
|
+
GREEN='\033[0;32m'
|
|
28
|
+
YELLOW='\033[1;33m'
|
|
29
|
+
NC='\033[0m' # No Color
|
|
30
|
+
|
|
31
|
+
# Sync mappings: CLI_PATH <- SITE_PATH
|
|
32
|
+
declare -A SYNC_FILES=(
|
|
33
|
+
["src/orchestrator.ts"]="lib/agents/static-orchestrator.ts"
|
|
34
|
+
["src/analysis-types.ts"]="lib/agents/types.ts"
|
|
35
|
+
["src/prompts/loader.ts"]="lib/prompts/loader.ts"
|
|
36
|
+
["prompts/unified-analyzer.yaml"]="prompts/unified-analyzer.yaml"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Parse arguments
|
|
40
|
+
DRY_RUN=false
|
|
41
|
+
CHECK_MODE=false
|
|
42
|
+
|
|
43
|
+
while [[ $# -gt 0 ]]; do
|
|
44
|
+
case $1 in
|
|
45
|
+
--dry-run)
|
|
46
|
+
DRY_RUN=true
|
|
47
|
+
shift
|
|
48
|
+
;;
|
|
49
|
+
--check)
|
|
50
|
+
CHECK_MODE=true
|
|
51
|
+
shift
|
|
52
|
+
;;
|
|
53
|
+
*)
|
|
54
|
+
echo -e "${RED}Unknown option: $1${NC}"
|
|
55
|
+
exit 1
|
|
56
|
+
;;
|
|
57
|
+
esac
|
|
58
|
+
done
|
|
59
|
+
|
|
60
|
+
# Check if peakinfer-site exists
|
|
61
|
+
if [ ! -d "$SITE_ROOT" ]; then
|
|
62
|
+
echo -e "${YELLOW}Warning: peakinfer-site not found at $SITE_ROOT${NC}"
|
|
63
|
+
echo "This is expected in production/CI environments."
|
|
64
|
+
echo "The CLI is fully self-contained and doesn't require peakinfer-site."
|
|
65
|
+
exit 0
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
echo "=== PeakInfer Sync ==="
|
|
69
|
+
echo "Source: $SITE_ROOT"
|
|
70
|
+
echo "Target: $CLI_ROOT"
|
|
71
|
+
echo ""
|
|
72
|
+
|
|
73
|
+
SYNC_HEADER="/**
|
|
74
|
+
* SYNC NOTE: This file is synced from peakinfer-site (source of truth).
|
|
75
|
+
* DO NOT modify directly in the CLI repo.
|
|
76
|
+
*
|
|
77
|
+
* Source: peakinfer-site/%SOURCE_PATH%
|
|
78
|
+
* Last synced: %DATE%
|
|
79
|
+
*
|
|
80
|
+
* To modify: Edit in peakinfer-site, then run: ./scripts/sync-from-site.sh
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
"
|
|
84
|
+
|
|
85
|
+
YAML_SYNC_HEADER="# =============================================================================
|
|
86
|
+
# SYNC NOTE: This file is synced from peakinfer-site (source of truth).
|
|
87
|
+
# DO NOT modify directly in the CLI repo.
|
|
88
|
+
#
|
|
89
|
+
# Source: peakinfer-site/%SOURCE_PATH%
|
|
90
|
+
# Last synced: %DATE%
|
|
91
|
+
#
|
|
92
|
+
# To modify: Edit in peakinfer-site, then run: ./scripts/sync-from-site.sh
|
|
93
|
+
# =============================================================================
|
|
94
|
+
|
|
95
|
+
"
|
|
96
|
+
|
|
97
|
+
OUT_OF_SYNC=0
|
|
98
|
+
SYNCED=0
|
|
99
|
+
|
|
100
|
+
for CLI_PATH in "${!SYNC_FILES[@]}"; do
|
|
101
|
+
SITE_PATH="${SYNC_FILES[$CLI_PATH]}"
|
|
102
|
+
CLI_FILE="$CLI_ROOT/$CLI_PATH"
|
|
103
|
+
SITE_FILE="$SITE_ROOT/$SITE_PATH"
|
|
104
|
+
|
|
105
|
+
if [ ! -f "$SITE_FILE" ]; then
|
|
106
|
+
echo -e "${YELLOW}[SKIP] $SITE_PATH not found in peakinfer-site${NC}"
|
|
107
|
+
continue
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
# Read source file
|
|
111
|
+
SOURCE_CONTENT=$(cat "$SITE_FILE")
|
|
112
|
+
|
|
113
|
+
# Prepare sync header
|
|
114
|
+
DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
115
|
+
|
|
116
|
+
if [[ "$CLI_PATH" == *.yaml ]]; then
|
|
117
|
+
HEADER="${YAML_SYNC_HEADER//%SOURCE_PATH%/$SITE_PATH}"
|
|
118
|
+
HEADER="${HEADER//%DATE%/$DATE}"
|
|
119
|
+
else
|
|
120
|
+
HEADER="${SYNC_HEADER//%SOURCE_PATH%/$SITE_PATH}"
|
|
121
|
+
HEADER="${HEADER//%DATE%/$DATE}"
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
# Transform imports for CLI context
|
|
125
|
+
if [[ "$CLI_PATH" == *.ts ]]; then
|
|
126
|
+
# Replace @/lib/ imports with relative imports
|
|
127
|
+
SOURCE_CONTENT=$(echo "$SOURCE_CONTENT" | sed "s|from '@/lib/|from './|g")
|
|
128
|
+
SOURCE_CONTENT=$(echo "$SOURCE_CONTENT" | sed "s|import '@/lib/|import './|g")
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
NEW_CONTENT="${HEADER}${SOURCE_CONTENT}"
|
|
132
|
+
|
|
133
|
+
# Check if file exists and compare
|
|
134
|
+
if [ -f "$CLI_FILE" ]; then
|
|
135
|
+
# Strip sync header from existing file for comparison (compare actual content)
|
|
136
|
+
EXISTING_CONTENT=$(cat "$CLI_FILE")
|
|
137
|
+
|
|
138
|
+
# Simple content comparison (ignoring header)
|
|
139
|
+
# Extract content after sync header
|
|
140
|
+
if [[ "$CLI_PATH" == *.yaml ]]; then
|
|
141
|
+
EXISTING_BODY=$(echo "$EXISTING_CONTENT" | sed -n '/^# ====/,/^# ====/!p' | tail -n +2)
|
|
142
|
+
NEW_BODY=$(echo "$SOURCE_CONTENT")
|
|
143
|
+
else
|
|
144
|
+
EXISTING_BODY=$(echo "$EXISTING_CONTENT" | sed -n '/^\*\//,$p' | tail -n +2)
|
|
145
|
+
NEW_BODY=$(echo "$SOURCE_CONTENT")
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
if [ "$EXISTING_BODY" = "$NEW_BODY" ]; then
|
|
149
|
+
echo -e "${GREEN}[OK] $CLI_PATH is in sync${NC}"
|
|
150
|
+
continue
|
|
151
|
+
fi
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
# Files differ
|
|
155
|
+
OUT_OF_SYNC=$((OUT_OF_SYNC + 1))
|
|
156
|
+
|
|
157
|
+
if [ "$CHECK_MODE" = true ]; then
|
|
158
|
+
echo -e "${RED}[OUT OF SYNC] $CLI_PATH <- $SITE_PATH${NC}"
|
|
159
|
+
continue
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
if [ "$DRY_RUN" = true ]; then
|
|
163
|
+
echo -e "${YELLOW}[DRY RUN] Would sync: $CLI_PATH <- $SITE_PATH${NC}"
|
|
164
|
+
else
|
|
165
|
+
# Create directory if needed
|
|
166
|
+
mkdir -p "$(dirname "$CLI_FILE")"
|
|
167
|
+
|
|
168
|
+
# Write synced file
|
|
169
|
+
echo "$NEW_CONTENT" > "$CLI_FILE"
|
|
170
|
+
echo -e "${GREEN}[SYNCED] $CLI_PATH <- $SITE_PATH${NC}"
|
|
171
|
+
SYNCED=$((SYNCED + 1))
|
|
172
|
+
fi
|
|
173
|
+
done
|
|
174
|
+
|
|
175
|
+
echo ""
|
|
176
|
+
echo "=== Summary ==="
|
|
177
|
+
|
|
178
|
+
if [ "$CHECK_MODE" = true ]; then
|
|
179
|
+
if [ $OUT_OF_SYNC -gt 0 ]; then
|
|
180
|
+
echo -e "${RED}$OUT_OF_SYNC file(s) out of sync${NC}"
|
|
181
|
+
echo "Run './scripts/sync-from-site.sh' to sync"
|
|
182
|
+
exit 1
|
|
183
|
+
else
|
|
184
|
+
echo -e "${GREEN}All files in sync${NC}"
|
|
185
|
+
exit 0
|
|
186
|
+
fi
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
if [ "$DRY_RUN" = true ]; then
|
|
190
|
+
echo "$OUT_OF_SYNC file(s) would be synced"
|
|
191
|
+
else
|
|
192
|
+
echo "$SYNCED file(s) synced"
|
|
193
|
+
fi
|
|
194
|
+
|
|
195
|
+
echo ""
|
|
196
|
+
echo "Remember: peakinfer CLI is fully self-contained."
|
|
197
|
+
echo "Synced files are committed to git for enterprise auditability."
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# SYNC VALIDATION SCRIPT
|
|
4
|
+
# Validates that synced files between peakinfer-site and peakinfer CLI are identical
|
|
5
|
+
# (modulo expected differences like import paths)
|
|
6
|
+
#
|
|
7
|
+
# Usage: ./scripts/validate-sync.sh [--strict]
|
|
8
|
+
# --strict: Fail on ANY difference (no import path tolerance)
|
|
9
|
+
#
|
|
10
|
+
# Exit codes:
|
|
11
|
+
# 0: All files in sync (or only expected differences)
|
|
12
|
+
# 1: Files out of sync (unexpected differences)
|
|
13
|
+
# 2: Missing files or configuration error
|
|
14
|
+
# =============================================================================
|
|
15
|
+
|
|
16
|
+
set -e
|
|
17
|
+
|
|
18
|
+
# Colors for output
|
|
19
|
+
RED='\033[0;31m'
|
|
20
|
+
GREEN='\033[0;32m'
|
|
21
|
+
YELLOW='\033[1;33m'
|
|
22
|
+
NC='\033[0m' # No Color
|
|
23
|
+
|
|
24
|
+
# Configuration
|
|
25
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
26
|
+
CLI_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
27
|
+
SITE_ROOT="$(cd "$CLI_ROOT/../peakinfer-site" 2>/dev/null && pwd)" || SITE_ROOT=""
|
|
28
|
+
|
|
29
|
+
# Synced file pairs: CLI path -> Site path
|
|
30
|
+
declare -A SYNC_PAIRS=(
|
|
31
|
+
["src/orchestrator.ts"]="lib/agents/static-orchestrator.ts"
|
|
32
|
+
["src/analysis-types.ts"]="lib/agents/types.ts"
|
|
33
|
+
["src/prompts/loader.ts"]="lib/prompts/loader.ts"
|
|
34
|
+
["prompts/unified-analyzer.yaml"]="prompts/unified-analyzer.yaml"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Known import path differences to ignore (regex patterns)
|
|
38
|
+
IMPORT_DIFFS=(
|
|
39
|
+
"import.*from '@/lib/" # Site uses @/lib/, CLI uses ./
|
|
40
|
+
"from '\.\./" # Relative path differences
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Parse arguments
|
|
44
|
+
STRICT_MODE=false
|
|
45
|
+
if [[ "$1" == "--strict" ]]; then
|
|
46
|
+
STRICT_MODE=true
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# Functions
|
|
50
|
+
print_header() {
|
|
51
|
+
echo ""
|
|
52
|
+
echo "======================================================================"
|
|
53
|
+
echo " PeakInfer Sync Validation"
|
|
54
|
+
echo "======================================================================"
|
|
55
|
+
echo ""
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
print_status() {
|
|
59
|
+
local status=$1
|
|
60
|
+
local message=$2
|
|
61
|
+
|
|
62
|
+
if [[ "$status" == "OK" ]]; then
|
|
63
|
+
echo -e "${GREEN}[OK]${NC} $message"
|
|
64
|
+
elif [[ "$status" == "WARN" ]]; then
|
|
65
|
+
echo -e "${YELLOW}[WARN]${NC} $message"
|
|
66
|
+
elif [[ "$status" == "FAIL" ]]; then
|
|
67
|
+
echo -e "${RED}[FAIL]${NC} $message"
|
|
68
|
+
else
|
|
69
|
+
echo "[$status] $message"
|
|
70
|
+
fi
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
check_site_exists() {
|
|
74
|
+
if [[ -z "$SITE_ROOT" || ! -d "$SITE_ROOT" ]]; then
|
|
75
|
+
print_status "WARN" "peakinfer-site not found at ../peakinfer-site"
|
|
76
|
+
echo " This is expected in CI or when only CLI repo is cloned."
|
|
77
|
+
echo " Skipping sync validation."
|
|
78
|
+
exit 0
|
|
79
|
+
fi
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
normalize_file() {
|
|
83
|
+
local file=$1
|
|
84
|
+
|
|
85
|
+
# Read file, normalize line endings, and remove SYNC NOTE headers
|
|
86
|
+
cat "$file" 2>/dev/null | \
|
|
87
|
+
tr -d '\r' | \
|
|
88
|
+
sed '/^\/\*\*/,/^\*\//d' | \
|
|
89
|
+
sed '/SYNC NOTE/d'
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
compare_files() {
|
|
93
|
+
local cli_file=$1
|
|
94
|
+
local site_file=$2
|
|
95
|
+
local cli_path="$CLI_ROOT/$cli_file"
|
|
96
|
+
local site_path="$SITE_ROOT/$site_file"
|
|
97
|
+
|
|
98
|
+
# Check files exist
|
|
99
|
+
if [[ ! -f "$cli_path" ]]; then
|
|
100
|
+
print_status "FAIL" "$cli_file: CLI file missing"
|
|
101
|
+
return 1
|
|
102
|
+
fi
|
|
103
|
+
|
|
104
|
+
if [[ ! -f "$site_path" ]]; then
|
|
105
|
+
print_status "FAIL" "$site_file: Site file missing"
|
|
106
|
+
return 1
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# Create temp files for comparison
|
|
110
|
+
local tmp_cli=$(mktemp)
|
|
111
|
+
local tmp_site=$(mktemp)
|
|
112
|
+
|
|
113
|
+
normalize_file "$cli_path" > "$tmp_cli"
|
|
114
|
+
normalize_file "$site_path" > "$tmp_site"
|
|
115
|
+
|
|
116
|
+
# In non-strict mode, also normalize import paths
|
|
117
|
+
if [[ "$STRICT_MODE" == "false" ]]; then
|
|
118
|
+
# Normalize @/lib/ imports to relative
|
|
119
|
+
sed -i.bak "s|from '@/lib/|from './|g" "$tmp_site" 2>/dev/null || \
|
|
120
|
+
sed "s|from '@/lib/|from './|g" "$tmp_site" > "$tmp_site.new" && mv "$tmp_site.new" "$tmp_site"
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
# Compare
|
|
124
|
+
if diff -q "$tmp_cli" "$tmp_site" > /dev/null 2>&1; then
|
|
125
|
+
print_status "OK" "$cli_file <-> $site_file"
|
|
126
|
+
rm -f "$tmp_cli" "$tmp_site" "$tmp_cli.bak" "$tmp_site.bak"
|
|
127
|
+
return 0
|
|
128
|
+
else
|
|
129
|
+
print_status "FAIL" "$cli_file <-> $site_file (DIFFERS)"
|
|
130
|
+
|
|
131
|
+
# Show diff preview (first 10 lines)
|
|
132
|
+
echo " Diff preview:"
|
|
133
|
+
diff "$tmp_cli" "$tmp_site" | head -20 | sed 's/^/ /'
|
|
134
|
+
echo " ..."
|
|
135
|
+
|
|
136
|
+
rm -f "$tmp_cli" "$tmp_site" "$tmp_cli.bak" "$tmp_site.bak"
|
|
137
|
+
return 1
|
|
138
|
+
fi
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
# Main
|
|
142
|
+
print_header
|
|
143
|
+
|
|
144
|
+
echo "CLI Root: $CLI_ROOT"
|
|
145
|
+
echo "Site Root: ${SITE_ROOT:-'(not found)'}"
|
|
146
|
+
echo ""
|
|
147
|
+
|
|
148
|
+
# Check if site exists
|
|
149
|
+
check_site_exists
|
|
150
|
+
|
|
151
|
+
echo "Mode: ${STRICT_MODE:+STRICT}${STRICT_MODE:-TOLERANT} (import path differences ${STRICT_MODE:+NOT }ignored)"
|
|
152
|
+
echo ""
|
|
153
|
+
|
|
154
|
+
# Run comparisons
|
|
155
|
+
failures=0
|
|
156
|
+
for cli_file in "${!SYNC_PAIRS[@]}"; do
|
|
157
|
+
site_file="${SYNC_PAIRS[$cli_file]}"
|
|
158
|
+
if ! compare_files "$cli_file" "$site_file"; then
|
|
159
|
+
((failures++))
|
|
160
|
+
fi
|
|
161
|
+
done
|
|
162
|
+
|
|
163
|
+
echo ""
|
|
164
|
+
echo "======================================================================"
|
|
165
|
+
|
|
166
|
+
if [[ $failures -eq 0 ]]; then
|
|
167
|
+
print_status "OK" "All ${#SYNC_PAIRS[@]} synced files are in sync"
|
|
168
|
+
exit 0
|
|
169
|
+
else
|
|
170
|
+
print_status "FAIL" "$failures of ${#SYNC_PAIRS[@]} files are OUT OF SYNC"
|
|
171
|
+
echo ""
|
|
172
|
+
echo "To fix:"
|
|
173
|
+
echo " 1. Make changes in peakinfer-site first (source of truth)"
|
|
174
|
+
echo " 2. Copy updated files to peakinfer CLI"
|
|
175
|
+
echo " 3. Adapt imports (@/lib/ -> ./)"
|
|
176
|
+
echo " 4. Run this script again to verify"
|
|
177
|
+
exit 1
|
|
178
|
+
fi
|