@synkro-sh/cli 1.3.50 → 1.3.51

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/dist/bootstrap.js CHANGED
@@ -473,7 +473,7 @@ fi
473
473
  CC_MODEL=""
474
474
  CC_USAGE="{}"
475
475
  if [ -n "$TRANSCRIPT_PATH" ] && [ -f "$TRANSCRIPT_PATH" ]; then
476
- _LAST_ASSISTANT=$(tail -50 "$TRANSCRIPT_PATH" | jq -c 'select(.type == "assistant")' 2>/dev/null | tail -1)
476
+ _LAST_ASSISTANT=$(grep '"type":"assistant"' "$TRANSCRIPT_PATH" 2>/dev/null | tail -1)
477
477
  if [ -n "$_LAST_ASSISTANT" ]; then
478
478
  CC_MODEL=$(echo "$_LAST_ASSISTANT" | jq -r '.message.model // empty' 2>/dev/null)
479
479
  CC_USAGE=$(echo "$_LAST_ASSISTANT" | jq -c '{
@@ -619,7 +619,7 @@ if [ "$USE_LOCAL" = "true" ]; then
619
619
  if [ "$SYNKRO_CAPTURE_DEPTH" = "local_only" ]; then
620
620
  ORG_RULES=$(curl -sS "\${GATEWAY_URL}/api/v1/cli/pr-rules" \\
621
621
  -H "Authorization: Bearer $JWT" --max-time 3 2>/dev/null \\
622
- | jq -c '[.rules[]? | {rule_id, text, severity, category}]' 2>/dev/null || echo "[]")
622
+ | jq -c '[.rules[]? | select(.hook_stage == "pre" or .hook_stage == "both" or .hook_stage == null) | {rule_id, text, severity, category}]' 2>/dev/null || echo "[]")
623
623
  if [ -n "$ORG_RULES" ] && [ "$ORG_RULES" != "null" ] && [ "$ORG_RULES" != "[]" ]; then
624
624
  printf '%s' "$ORG_RULES" > "$RULES_CACHE" 2>/dev/null || true
625
625
  elif [ -f "$RULES_CACHE" ]; then
@@ -632,7 +632,7 @@ if [ "$USE_LOCAL" = "true" ]; then
632
632
  -X POST -H "Content-Type: application/json" \\
633
633
  -H "Authorization: Bearer $JWT" \\
634
634
  -d @- --max-time 2 2>/dev/null \\
635
- | jq -c '[.rules[]? | {rule_id, text, severity, category}]' 2>/dev/null || echo "[]")
635
+ | jq -c '[.rules[]? | select(.hook_stage == "pre" or .hook_stage == "both" or .hook_stage == null) | {rule_id, text, severity, category}]' 2>/dev/null || echo "[]")
636
636
  fi
637
637
  if [ -z "$ORG_RULES" ] || [ "$ORG_RULES" = "null" ]; then ORG_RULES="[]"; fi
638
638
 
@@ -816,7 +816,6 @@ if [ "$USE_LOCAL" = "true" ] && [ -n "$VERDICT_KIND" ]; then
816
816
  --arg severity "$SEVERITY" \\
817
817
  --arg risk_level "\${RISK_LEVEL:-low}" \\
818
818
  --arg category "$CATEGORY" \\
819
- --arg cc_model "\${CC_MODEL:-}" \\
820
819
  --arg model "\${CC_MODEL:-claude-sonnet-4-6}" \\
821
820
  --arg tool_name "$TOOL_NAME" \\
822
821
  --arg repo "\${GIT_REPO:-}" \\
@@ -829,7 +828,6 @@ if [ "$USE_LOCAL" = "true" ] && [ -n "$VERDICT_KIND" ]; then
829
828
  --arg command "$COMMAND" \\
830
829
  --arg reasoning "$REASONING" \\
831
830
  --arg alternative "$ALTERNATIVE" \\
832
- --argjson cc_usage "\${CC_USAGE:-{}}" \\
833
831
  --argjson rules_checked "\${ORG_RULES:-[]}" \\
834
832
  --argjson recent_user_messages "\${RECENT_USER_MESSAGES:-[]}" \\
835
833
  '{
@@ -843,9 +841,7 @@ if [ "$USE_LOCAL" = "true" ] && [ -n "$VERDICT_KIND" ]; then
843
841
  model: $model,
844
842
  tool_name: $tool_name,
845
843
  capture_depth: $capture_depth,
846
- rules_checked: $rules_checked,
847
- cc_model: (if ($cc_model | length) > 0 then $cc_model else null end),
848
- cc_usage: $cc_usage
844
+ rules_checked: $rules_checked
849
845
  } + (if $repo != "" then {repo: $repo} else {} end)
850
846
  + (if $session_id != "" then {session_id: $session_id} else {} end)
851
847
  + (if $tool_use_id != "" then {tool_use_id: $tool_use_id} else {} end)
@@ -906,22 +902,6 @@ TOOL_INPUT=$(echo "$PAYLOAD" | jq -c '.tool_input // {}' 2>/dev/null)
906
902
  SESSION_ID=$(echo "$PAYLOAD" | jq -r '.session_id // empty' 2>/dev/null)
907
903
  TOOL_USE_ID=$(echo "$PAYLOAD" | jq -r '.tool_use_id // empty' 2>/dev/null)
908
904
  CWD=$(echo "$PAYLOAD" | jq -r '.cwd // empty' 2>/dev/null)
909
- TRANSCRIPT_PATH=$(echo "$PAYLOAD" | jq -r '.transcript_path // empty' 2>/dev/null)
910
-
911
- CC_MODEL=""
912
- CC_USAGE="{}"
913
- if [ -n "$TRANSCRIPT_PATH" ] && [ -f "$TRANSCRIPT_PATH" ]; then
914
- _LAST_ASSISTANT=$(tail -50 "$TRANSCRIPT_PATH" | jq -c 'select(.type == "assistant")' 2>/dev/null | tail -1)
915
- if [ -n "$_LAST_ASSISTANT" ]; then
916
- CC_MODEL=$(echo "$_LAST_ASSISTANT" | jq -r '.message.model // empty' 2>/dev/null)
917
- CC_USAGE=$(echo "$_LAST_ASSISTANT" | jq -c '{
918
- input_tokens: .message.usage.input_tokens,
919
- output_tokens: .message.usage.output_tokens,
920
- cache_creation_input_tokens: .message.usage.cache_creation_input_tokens,
921
- cache_read_input_tokens: .message.usage.cache_read_input_tokens
922
- }' 2>/dev/null || echo "{}")
923
- fi
924
- fi
925
905
  # Detect git remote origin \u2192 repo identity (e.g. "owner/repo")
926
906
  GIT_REPO=""
927
907
  if command -v git >/dev/null 2>&1; then
@@ -1144,7 +1124,7 @@ if [ "$USE_LOCAL" = "true" ]; then
1144
1124
  if [ "$SYNKRO_CAPTURE_DEPTH" = "local_only" ]; then
1145
1125
  ORG_RULES=$(curl -sS "\${GATEWAY_URL}/api/v1/cli/pr-rules" \\
1146
1126
  -H "Authorization: Bearer $JWT" --max-time 3 2>/dev/null \\
1147
- | jq -c '[.rules[]? | {rule_id, text, severity, category, mode}]' 2>/dev/null || echo "[]")
1127
+ | jq -c '[.rules[]? | select(.hook_stage == "pre" or .hook_stage == "both" or .hook_stage == null) | {rule_id, text, severity, category, mode}]' 2>/dev/null || echo "[]")
1148
1128
  if [ -n "$ORG_RULES" ] && [ "$ORG_RULES" != "null" ] && [ "$ORG_RULES" != "[]" ]; then
1149
1129
  printf '%s' "$ORG_RULES" > "$RULES_CACHE" 2>/dev/null || true
1150
1130
  elif [ -f "$RULES_CACHE" ]; then
@@ -1157,7 +1137,7 @@ if [ "$USE_LOCAL" = "true" ]; then
1157
1137
  -X POST -H "Content-Type: application/json" \\
1158
1138
  -H "Authorization: Bearer $JWT" \\
1159
1139
  -d @- --max-time 2 2>/dev/null \\
1160
- | jq -c '[.rules[]? | {rule_id, text, severity, category, mode}]' 2>/dev/null || echo "[]")
1140
+ | jq -c '[.rules[]? | select(.hook_stage == "pre" or .hook_stage == "both" or .hook_stage == null) | {rule_id, text, severity, category, mode}]' 2>/dev/null || echo "[]")
1161
1141
  fi
1162
1142
  if [ -z "$ORG_RULES" ] || [ "$ORG_RULES" = "null" ]; then ORG_RULES="[]"; fi
1163
1143
 
@@ -1355,14 +1335,12 @@ if [ "$SYNKRO_CAPTURE_DEPTH" = "local_only" ] && [ -n "$DECISION" ]; then
1355
1335
  --arg verdict "$LOCAL_VERDICT" \\
1356
1336
  --arg severity "$LOCAL_SEVERITY" \\
1357
1337
  --arg category "$LOCAL_CATEGORY" \\
1358
- --arg model "\${CC_MODEL:-claude-sonnet-4-6}" \\
1359
- --arg cc_model "\${CC_MODEL:-}" \\
1338
+ --arg model "claude-sonnet-4-6" \\
1360
1339
  --arg tool_name "$TOOL_NAME" \\
1361
1340
  --arg repo "\${GIT_REPO:-}" \\
1362
1341
  --arg session_id "$SESSION_ID" \\
1363
1342
  --arg mech_cat "$MECH_CAT" \\
1364
1343
  --arg biz_cat "$BIZ_CAT" \\
1365
- --argjson cc_usage "\${CC_USAGE:-{}}" \\
1366
1344
  '{
1367
1345
  event_id: $event_id,
1368
1346
  timestamp: $timestamp,
@@ -1371,11 +1349,9 @@ if [ "$SYNKRO_CAPTURE_DEPTH" = "local_only" ] && [ -n "$DECISION" ]; then
1371
1349
  severity: $severity,
1372
1350
  category: $category,
1373
1351
  model: $model,
1374
- tool_name: $tool_name,
1375
- cc_usage: $cc_usage
1352
+ tool_name: $tool_name
1376
1353
  } + (if $repo != "" then {repo: $repo} else {} end)
1377
1354
  + (if $session_id != "" then {session_id: $session_id} else {} end)
1378
- + (if $cc_model != "" then {cc_model: $cc_model} else {} end)
1379
1355
  + (if $mech_cat != "" then {mechanism_category: $mech_cat} else {} end)
1380
1356
  + (if $biz_cat != "" then {business_category: $biz_cat} else {} end)')
1381
1357
  curl -sS -X POST "\${GATEWAY_URL}/api/v1/events/local-verdict" \\
@@ -1432,22 +1408,6 @@ TOOL_INPUT=$(echo "$PAYLOAD" | jq -c '.tool_input // {}' 2>/dev/null)
1432
1408
  SESSION_ID=$(echo "$PAYLOAD" | jq -r '.session_id // empty' 2>/dev/null)
1433
1409
  TOOL_USE_ID=$(echo "$PAYLOAD" | jq -r '.tool_use_id // empty' 2>/dev/null)
1434
1410
  CWD=$(echo "$PAYLOAD" | jq -r '.cwd // empty' 2>/dev/null)
1435
- TRANSCRIPT_PATH=$(echo "$PAYLOAD" | jq -r '.transcript_path // empty' 2>/dev/null)
1436
-
1437
- CC_MODEL=""
1438
- CC_USAGE="{}"
1439
- if [ -n "$TRANSCRIPT_PATH" ] && [ -f "$TRANSCRIPT_PATH" ]; then
1440
- _LAST_ASSISTANT=$(tail -50 "$TRANSCRIPT_PATH" | jq -c 'select(.type == "assistant")' 2>/dev/null | tail -1)
1441
- if [ -n "$_LAST_ASSISTANT" ]; then
1442
- CC_MODEL=$(echo "$_LAST_ASSISTANT" | jq -r '.message.model // empty' 2>/dev/null)
1443
- CC_USAGE=$(echo "$_LAST_ASSISTANT" | jq -c '{
1444
- input_tokens: .message.usage.input_tokens,
1445
- output_tokens: .message.usage.output_tokens,
1446
- cache_creation_input_tokens: .message.usage.cache_creation_input_tokens,
1447
- cache_read_input_tokens: .message.usage.cache_read_input_tokens
1448
- }' 2>/dev/null || echo "{}")
1449
- fi
1450
- fi
1451
1411
  # Detect git remote origin \u2192 repo identity (e.g. "owner/repo")
1452
1412
  GIT_REPO=""
1453
1413
  if command -v git >/dev/null 2>&1; then
@@ -1627,7 +1587,7 @@ if [ "$USE_LOCAL" = "true" ]; then
1627
1587
  -H "Authorization: Bearer $JWT" \\
1628
1588
  -d @- --max-time 2 2>/dev/null || echo "")
1629
1589
  fi
1630
- ORG_RULES=$(echo "$RULES_RESP" | jq -c '[.rules[]? | {rule_id, text, severity, category}]' 2>/dev/null || echo "[]")
1590
+ ORG_RULES=$(echo "$RULES_RESP" | jq -c '[.rules[]? | select(.hook_stage == "post" or .hook_stage == "both" or .hook_stage == null) | {rule_id, text, severity, category}]' 2>/dev/null || echo "[]")
1631
1591
  if [ -n "$ORG_RULES" ] && [ "$ORG_RULES" != "null" ] && [ "$ORG_RULES" != "[]" ]; then
1632
1592
  printf '%s' "$ORG_RULES" > "$RULES_CACHE" 2>/dev/null || true
1633
1593
  elif [ -f "$RULES_CACHE" ]; then
@@ -1779,22 +1739,18 @@ if [ "$SYNKRO_CAPTURE_DEPTH" = "local_only" ]; then
1779
1739
  --arg severity "$LOCAL_SEVERITY" \\
1780
1740
  --arg risk_level "$LOCAL_RISK" \\
1781
1741
  --arg category "$CATEGORY" \\
1782
- --arg model "\${CC_MODEL:-claude-sonnet-4-6}" \\
1783
- --arg cc_model "\${CC_MODEL:-}" \\
1742
+ --arg model "claude-sonnet-4-6" \\
1784
1743
  --arg tool_name "$TOOL_NAME" \\
1785
1744
  --arg repo "\${GIT_REPO:-}" \\
1786
1745
  --arg session_id "$SESSION_ID" \\
1787
1746
  --arg mech_cat "$MECH_CAT" \\
1788
1747
  --arg biz_cat "$BIZ_CAT" \\
1789
- --argjson cc_usage "\${CC_USAGE:-{}}" \\
1790
1748
  '{
1791
1749
  event_id: $event_id, timestamp: $timestamp, hook_type: $hook_type,
1792
1750
  verdict: $verdict, severity: $severity, risk_level: $risk_level,
1793
- category: $category, model: $model, tool_name: $tool_name,
1794
- cc_usage: $cc_usage
1751
+ category: $category, model: $model, tool_name: $tool_name
1795
1752
  } + (if $repo != "" then {repo: $repo} else {} end)
1796
1753
  + (if $session_id != "" then {session_id: $session_id} else {} end)
1797
- + (if $cc_model != "" then {cc_model: $cc_model} else {} end)
1798
1754
  + (if $mech_cat != "" then {mechanism_category: $mech_cat} else {} end)
1799
1755
  + (if $biz_cat != "" then {business_category: $biz_cat} else {} end)')
1800
1756
  curl -sS -X POST "\${GATEWAY_URL}/api/v1/events/local-verdict" \\
@@ -1864,6 +1820,57 @@ if [ -z "$SESSION_ID" ]; then
1864
1820
  exit 0
1865
1821
  fi
1866
1822
 
1823
+ TRANSCRIPT_PATH=$(echo "$PAYLOAD" | jq -r '.transcript_path // empty' 2>/dev/null)
1824
+ CWD=$(echo "$PAYLOAD" | jq -r '.cwd // empty' 2>/dev/null)
1825
+
1826
+ GIT_REPO=""
1827
+ if command -v git >/dev/null 2>&1; then
1828
+ _REMOTE=$(git -C "\${CWD:-.}" remote get-url origin 2>/dev/null || true)
1829
+ if [ -n "$_REMOTE" ]; then
1830
+ GIT_REPO=$(echo "$_REMOTE" | sed -E 's|^git@[^:]+:||; s|^https?://[^/]+/||; s|\\.git$||')
1831
+ fi
1832
+ fi
1833
+
1834
+ # Fire-and-forget usage telemetry \u2014 runs every turn via Stop hook
1835
+ if [ -n "$TRANSCRIPT_PATH" ] && [ -f "$TRANSCRIPT_PATH" ]; then
1836
+ (
1837
+ _LAST_ASSISTANT=$(grep '"type":"assistant"' "$TRANSCRIPT_PATH" 2>/dev/null | tail -1)
1838
+ if [ -n "$_LAST_ASSISTANT" ]; then
1839
+ CC_MODEL=$(echo "$_LAST_ASSISTANT" | jq -r '.message.model // empty' 2>/dev/null)
1840
+ CC_USAGE=$(echo "$_LAST_ASSISTANT" | jq -c '{
1841
+ input_tokens: .message.usage.input_tokens,
1842
+ output_tokens: .message.usage.output_tokens,
1843
+ cache_creation_input_tokens: .message.usage.cache_creation_input_tokens,
1844
+ cache_read_input_tokens: .message.usage.cache_read_input_tokens
1845
+ }' 2>/dev/null || echo "{}")
1846
+ HAS_TOKENS=$(echo "$CC_USAGE" | jq '(.input_tokens // 0) + (.output_tokens // 0)' 2>/dev/null)
1847
+ if [ -n "$HAS_TOKENS" ] && [ "$HAS_TOKENS" != "0" ]; then
1848
+ USAGE_BODY=$(jq -n \\
1849
+ --arg event_id "usage_$(date +%s)_$$" \\
1850
+ --arg hook_type "stop" \\
1851
+ --arg verdict "allow" \\
1852
+ --arg severity "none" \\
1853
+ --arg model "\${CC_MODEL:-claude-sonnet-4-6}" \\
1854
+ --arg cc_model "\${CC_MODEL:-}" \\
1855
+ --arg repo "\${GIT_REPO:-}" \\
1856
+ --arg session_id "$SESSION_ID" \\
1857
+ --argjson cc_usage "$CC_USAGE" \\
1858
+ '{
1859
+ event_id: $event_id, hook_type: $hook_type,
1860
+ verdict: $verdict, severity: $severity,
1861
+ model: $model, cc_usage: $cc_usage
1862
+ } + (if $repo != "" then {repo: $repo} else {} end)
1863
+ + (if $session_id != "" then {session_id: $session_id} else {} end)
1864
+ + (if $cc_model != "" then {cc_model: $cc_model} else {} end)')
1865
+ curl -sS -X POST "\${GATEWAY_URL}/api/v1/events/local-verdict" \\
1866
+ -H "Content-Type: application/json" \\
1867
+ -H "Authorization: Bearer $JWT" \\
1868
+ -d "$USAGE_BODY" --max-time 2 >/dev/null 2>&1
1869
+ fi
1870
+ fi
1871
+ ) &
1872
+ fi
1873
+
1867
1874
  # Tight timeout \u2014 the user already finished their session, don't make them wait.
1868
1875
  RESP=$(curl -sS -G "\${GATEWAY_URL}/api/v1/cli/session-summary" \\
1869
1876
  --data-urlencode "session_id=$SESSION_ID" \\
@@ -3967,7 +3974,7 @@ function writeConfigEnv(opts) {
3967
3974
  `SYNKRO_CREDENTIALS_PATH=${shellQuoteSingle(credsPath)}`,
3968
3975
  `SYNKRO_TIER=${shellQuoteSingle(safeTier)}`,
3969
3976
  `SYNKRO_INFERENCE=${shellQuoteSingle(safeInference)}`,
3970
- `SYNKRO_VERSION=${shellQuoteSingle("1.3.50")}`
3977
+ `SYNKRO_VERSION=${shellQuoteSingle("1.3.51")}`
3971
3978
  ];
3972
3979
  if (safeUserId) lines.push(`SYNKRO_USER_ID=${shellQuoteSingle(safeUserId)}`);
3973
3980
  if (safeOrgId) lines.push(`SYNKRO_ORG_ID=${shellQuoteSingle(safeOrgId)}`);