@synkro-sh/cli 1.4.38 → 1.4.39

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
@@ -654,6 +654,8 @@ synkro_rule_mode() {
654
654
 
655
655
  SYNKRO_CONSENT_FILE="$HOME/.synkro/.local-consent"
656
656
 
657
+ _TAB=$(printf '\\t')
658
+
657
659
  synkro_consent_grant() {
658
660
  local sid="$1" hash="$2"
659
661
  printf '%s\\t%s\\tactive\\n' "$sid" "$hash" >> "$SYNKRO_CONSENT_FILE" 2>/dev/null || true
@@ -661,26 +663,28 @@ synkro_consent_grant() {
661
663
 
662
664
  synkro_consent_has_active() {
663
665
  local sid="$1" hash="$2"
664
- grep -q "^$sid\\\\t$hash\\\\tactive$" "$SYNKRO_CONSENT_FILE" 2>/dev/null
666
+ grep -q "^\${sid}\${_TAB}\${hash}\${_TAB}active$" "$SYNKRO_CONSENT_FILE" 2>/dev/null
665
667
  }
666
668
 
667
669
  synkro_consent_consume() {
668
670
  local sid="$1" hash="$2"
669
671
  [ ! -f "$SYNKRO_CONSENT_FILE" ] && return
670
672
  local tmp="\${SYNKRO_CONSENT_FILE}.tmp"
671
- sed "s/^$sid\\\\t$hash\\\\tactive$/$sid\\t$hash\\tconsumed/" "$SYNKRO_CONSENT_FILE" > "$tmp" 2>/dev/null && mv "$tmp" "$SYNKRO_CONSENT_FILE" 2>/dev/null || true
673
+ local pat="\${sid}\${_TAB}\${hash}\${_TAB}active"
674
+ local rep="\${sid}\${_TAB}\${hash}\${_TAB}consumed"
675
+ awk -v p="$pat" -v r="$rep" '{if($0==p)print r;else print}' "$SYNKRO_CONSENT_FILE" > "$tmp" 2>/dev/null && mv "$tmp" "$SYNKRO_CONSENT_FILE" 2>/dev/null || true
672
676
  }
673
677
 
674
678
  synkro_consent_has_consumed() {
675
679
  local sid="$1" hash="$2"
676
- grep -q "^$sid\\\\t$hash\\\\tconsumed$" "$SYNKRO_CONSENT_FILE" 2>/dev/null
680
+ grep -q "^\${sid}\${_TAB}\${hash}\${_TAB}consumed$" "$SYNKRO_CONSENT_FILE" 2>/dev/null
677
681
  }
678
682
 
679
683
  synkro_consent_clear_consumed() {
680
684
  local sid="$1" hash="$2"
681
685
  [ ! -f "$SYNKRO_CONSENT_FILE" ] && return
682
686
  local tmp="\${SYNKRO_CONSENT_FILE}.tmp"
683
- grep -v "^$sid\\\\t$hash\\\\tconsumed$" "$SYNKRO_CONSENT_FILE" > "$tmp" 2>/dev/null && mv "$tmp" "$SYNKRO_CONSENT_FILE" 2>/dev/null || true
687
+ grep -v "^\${sid}\${_TAB}\${hash}\${_TAB}consumed$" "$SYNKRO_CONSENT_FILE" > "$tmp" 2>/dev/null && mv "$tmp" "$SYNKRO_CONSENT_FILE" 2>/dev/null || true
684
688
  }
685
689
 
686
690
  synkro_post_with_retry() {
@@ -753,20 +757,13 @@ if [ "$SYNKRO_SILENT" = "true" ]; then
753
757
  exit 0
754
758
  fi
755
759
 
756
- # Pre-grade consent check: skip grading if user already approved this command in this session
757
- CMD_HASH=$(printf '%s' "$COMMAND" | shasum -a 256 | cut -c1-16)
758
- if [ -n "$SESSION_ID" ] && [ -n "$CMD_HASH" ] && synkro_consent_has_active "$SESSION_ID" "$CMD_HASH"; then
759
- jq -n --arg m "$TAG bashGuard \u2192 pass (previously approved)" '{systemMessage: $m}'
760
- exit 0
761
- fi
762
-
763
760
  ROUTE=$(synkro_route)
764
761
 
765
762
  if [ "$ROUTE" = "local" ]; then
766
763
  # \u2500\u2500\u2500 Local grading (local_only privacy or local-cc channel) \u2500\u2500\u2500
767
764
  GRADER_FILE=$(mktemp -t synkro-bash.XXXXXX)
768
765
  trap "rm -f \\"$GRADER_FILE\\"" EXIT
769
- printf 'Command: %s\\nUser intent: %s\\nOrg rules: %s\\n' "$COMMAND" "\${USER_INTENT:-none stated}" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
766
+ printf 'Working directory: %s\\nRepo: %s\\nCommand: %s\\nUser intent: %s\\nOrg rules: %s\\n' "\${CWD:-.}" "\${GIT_REPO:-unknown}" "$COMMAND" "\${USER_INTENT:-none stated}" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
770
767
 
771
768
  CC_RESP=$(synkro_local_grade bash < "$GRADER_FILE" 2>&1)
772
769
  if [ $? -ne 0 ]; then
@@ -963,7 +960,7 @@ if [ "$ROUTE" = "local" ]; then
963
960
  # \u2500\u2500\u2500 Local grading (local_only privacy or local-cc channel) \u2500\u2500\u2500
964
961
  GRADER_FILE=$(mktemp -t synkro-edit.XXXXXX)
965
962
  trap "rm -f \\"$GRADER_FILE\\"" EXIT
966
- printf 'File: %s\\nProposed content (first 4000 chars):\\n%s\\nUser intent: %s\\nOrg rules: %s\\n' "$FILE_PATH" "$(printf '%s' "$PROPOSED" | head -c 4000)" "\${USER_INTENT:-none stated}" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
963
+ printf 'Working directory: %s\\nRepo: %s\\nFile: %s\\nProposed content (first 4000 chars):\\n%s\\nUser intent: %s\\nOrg rules: %s\\n' "\${CWD:-.}" "\${GIT_REPO:-unknown}" "$FILE_PATH" "$(printf '%s' "$PROPOSED" | head -c 4000)" "\${USER_INTENT:-none stated}" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
967
964
 
968
965
  CC_RESP=$(synkro_local_grade edit < "$GRADER_FILE" 2>&1)
969
966
  if [ $? -ne 0 ]; then
@@ -1130,7 +1127,7 @@ if [ "$ROUTE" = "local" ]; then
1130
1127
  # \u2500\u2500\u2500 Local edit scan (local_only privacy or local-cc channel) \u2500\u2500\u2500
1131
1128
  GRADER_FILE=$(mktemp -t synkro-escan.XXXXXX)
1132
1129
  trap "rm -f \\"$GRADER_FILE\\"" EXIT
1133
- printf 'File: %s\\nContent (first 4000 chars):\\n%s\\nOrg rules: %s\\n' "$FILE_PATH" "$(printf '%s' "$FILE_CONTENT" | head -c 4000)" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
1130
+ printf 'Working directory: %s\\nRepo: %s\\nFile: %s\\nContent (first 4000 chars):\\n%s\\nOrg rules: %s\\n' "\${CWD:-.}" "\${GIT_REPO:-unknown}" "$FILE_PATH" "$(printf '%s' "$FILE_CONTENT" | head -c 4000)" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
1134
1131
 
1135
1132
  CC_RESP=$(synkro_local_grade edit < "$GRADER_FILE" 2>&1)
1136
1133
  if [ $? -ne 0 ]; then
@@ -1242,7 +1239,7 @@ ROUTE=$(synkro_route)
1242
1239
  if [ "$ROUTE" = "local" ]; then
1243
1240
  GRADER_FILE=$(mktemp -t synkro-plan.XXXXXX)
1244
1241
  trap "rm -f \\"$GRADER_FILE\\"" EXIT
1245
- printf 'Plan:\\n%s\\nOrg rules: %s\\n' "$(printf '%s' "$PLAN" | head -c 8000)" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
1242
+ printf 'Working directory: %s\\nRepo: %s\\nPlan:\\n%s\\nOrg rules: %s\\n' "\${CWD:-.}" "\${GIT_REPO:-unknown}" "$(printf '%s' "$PLAN" | head -c 8000)" "\${SYNKRO_RULES:-[]}" > "$GRADER_FILE"
1246
1243
 
1247
1244
  CC_RESP=$(synkro_local_grade plan < "$GRADER_FILE" 2>&1)
1248
1245
  if [ $? -ne 0 ]; then
@@ -1468,10 +1465,14 @@ BODY=$(jq -n --arg sid "$SESSION_ID" --arg tid "$TOOL_USE_ID" \\
1468
1465
  # Local consent tracking: command ran = user consented
1469
1466
  # On success \u2192 consume (next attempt blocks fresh)
1470
1467
  # On failure \u2192 grant active (retry allowed)
1471
- # Command ran (user approved it) \u2014 grant persistent consent for this session
1468
+ # Consent tracking: on success \u2192 consume (next run blocks fresh), on error \u2192 grant (retry allowed)
1472
1469
  if [ -n "$CMD_HASH" ] && [ -n "$SESSION_ID" ]; then
1473
- if ! synkro_consent_has_active "$SESSION_ID" "$CMD_HASH"; then
1474
- synkro_consent_grant "$SESSION_ID" "$CMD_HASH"
1470
+ if [ "$IS_ERROR" = "false" ]; then
1471
+ synkro_consent_consume "$SESSION_ID" "$CMD_HASH"
1472
+ else
1473
+ if ! synkro_consent_has_active "$SESSION_ID" "$CMD_HASH"; then
1474
+ synkro_consent_grant "$SESSION_ID" "$CMD_HASH"
1475
+ fi
1475
1476
  fi
1476
1477
  fi
1477
1478
 
@@ -1768,8 +1769,12 @@ if [ -n "$CMD" ]; then
1768
1769
  fi
1769
1770
 
1770
1771
  if [ -n "$CMD_HASH" ] && [ -n "$SESSION_ID" ]; then
1771
- if ! synkro_consent_has_active "$SESSION_ID" "$CMD_HASH"; then
1772
- synkro_consent_grant "$SESSION_ID" "$CMD_HASH"
1772
+ if [ "$IS_ERROR" = "false" ]; then
1773
+ synkro_consent_consume "$SESSION_ID" "$CMD_HASH"
1774
+ else
1775
+ if ! synkro_consent_has_active "$SESSION_ID" "$CMD_HASH"; then
1776
+ synkro_consent_grant "$SESSION_ID" "$CMD_HASH"
1777
+ fi
1773
1778
  fi
1774
1779
  fi
1775
1780
 
@@ -3982,7 +3987,7 @@ function writeConfigEnv(opts) {
3982
3987
  `SYNKRO_CREDENTIALS_PATH=${shellQuoteSingle(credsPath)}`,
3983
3988
  `SYNKRO_TIER=${shellQuoteSingle(safeTier)}`,
3984
3989
  `SYNKRO_INFERENCE=${shellQuoteSingle(safeInference)}`,
3985
- `SYNKRO_VERSION=${shellQuoteSingle("1.4.38")}`
3990
+ `SYNKRO_VERSION=${shellQuoteSingle("1.4.39")}`
3986
3991
  ];
3987
3992
  if (safeSynkroBin) lines.push(`SYNKRO_CLI_BIN=${shellQuoteSingle(safeSynkroBin)}`);
3988
3993
  if (safeUserId) lines.push(`SYNKRO_USER_ID=${shellQuoteSingle(safeUserId)}`);