opencode-block 1.3.0 → 1.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-block",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "File and directory protection for OpenCode using .block marker files with pattern matching",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -743,6 +743,138 @@ def get_bash_target_paths(command: str) -> list:
743
743
  i += 1
744
744
  continue
745
745
 
746
+ # In-place file modification commands
747
+ if token == "sed":
748
+ # sed -i / --in-place modifies files; without -i it's read-only
749
+ has_inplace = False
750
+ has_explicit_script = False
751
+ scan = i + 1
752
+ while scan < len(tokens) and tokens[scan] not in ("|", ";", "&", "&&", "||"):
753
+ arg = tokens[scan]
754
+ if arg.startswith("--in-place") or (
755
+ arg.startswith("-") and not arg.startswith("--") and "i" in arg[1:]
756
+ ):
757
+ has_inplace = True
758
+ if arg in ("-e", "-f"):
759
+ has_explicit_script = True
760
+ scan += 1 # skip the argument to -e/-f
761
+ scan += 1
762
+
763
+ if has_inplace:
764
+ first_nonoption_seen = False
765
+ i += 1
766
+ while i < len(tokens):
767
+ arg = tokens[i]
768
+ if arg in ("|", ";", "&", "&&", "||", ">", ">>"):
769
+ break
770
+ if arg.startswith("--in-place"):
771
+ i += 1
772
+ continue
773
+ if arg.startswith("-") and not arg.startswith("--") and "i" in arg[1:]:
774
+ i += 1
775
+ continue
776
+ if arg in ("-e", "-f"):
777
+ i += 2
778
+ continue
779
+ if arg.startswith("-"):
780
+ i += 1
781
+ continue
782
+ if not has_explicit_script and not first_nonoption_seen:
783
+ # Without -e/-f, first non-option is the sed script
784
+ first_nonoption_seen = True
785
+ i += 1
786
+ continue
787
+ paths.append(arg)
788
+ i += 1
789
+ continue
790
+ i += 1
791
+ continue
792
+
793
+ if token in ("awk", "gawk"):
794
+ # awk -i inplace modifies files (GNU awk extension)
795
+ has_inplace = False
796
+ scan = i + 1
797
+ while scan < len(tokens) and tokens[scan] not in ("|", ";", "&", "&&", "||"):
798
+ if tokens[scan] == "-i" and scan + 1 < len(tokens) and tokens[scan + 1] == "inplace":
799
+ has_inplace = True
800
+ break
801
+ scan += 1
802
+
803
+ if has_inplace:
804
+ program_seen = False
805
+ i += 1
806
+ while i < len(tokens):
807
+ arg = tokens[i]
808
+ if arg in ("|", ";", "&", "&&", "||", ">", ">>"):
809
+ break
810
+ if arg == "-i":
811
+ i += 2 # skip -i and its argument (e.g., inplace)
812
+ continue
813
+ if arg in ("-v", "-f"):
814
+ i += 2
815
+ continue
816
+ if arg.startswith("-"):
817
+ i += 1
818
+ continue
819
+ if not program_seen:
820
+ program_seen = True
821
+ i += 1
822
+ continue
823
+ paths.append(arg)
824
+ i += 1
825
+ continue
826
+ i += 1
827
+ continue
828
+
829
+ if token == "perl":
830
+ # perl -i modifies files in-place
831
+ has_inplace = False
832
+ scan = i + 1
833
+ while scan < len(tokens) and tokens[scan] not in ("|", ";", "&", "&&", "||"):
834
+ arg = tokens[scan]
835
+ if arg.startswith("-") and not arg.startswith("--") and "i" in arg[1:]:
836
+ has_inplace = True
837
+ break
838
+ scan += 1
839
+
840
+ if has_inplace:
841
+ i += 1
842
+ while i < len(tokens):
843
+ arg = tokens[i]
844
+ if arg in ("|", ";", "&", "&&", "||", ">", ">>"):
845
+ break
846
+ if arg == "-e":
847
+ i += 2 # skip -e and code argument
848
+ continue
849
+ if arg.startswith("-"):
850
+ i += 1
851
+ continue
852
+ paths.append(arg)
853
+ i += 1
854
+ continue
855
+ i += 1
856
+ continue
857
+
858
+ if token == "patch":
859
+ i += 1
860
+ while i < len(tokens):
861
+ arg = tokens[i]
862
+ if arg in ("|", ";", "&", "&&", "||", ">", ">>", "<"):
863
+ break
864
+ if arg == "-o" and i + 1 < len(tokens):
865
+ paths.append(tokens[i + 1])
866
+ i += 2
867
+ continue
868
+ if arg in ("-i", "-d"):
869
+ i += 2 # skip flag and its argument
870
+ continue
871
+ if arg.startswith("-"):
872
+ i += 1
873
+ continue
874
+ paths.append(arg)
875
+ i += 1
876
+ continue
877
+
746
878
  i += 1
747
879
 
748
880
  except ValueError:
@@ -809,6 +941,36 @@ def get_bash_target_paths(command: str) -> list:
809
941
  paths.append(path)
810
942
  break
811
943
 
944
+ # In-place editor regex patterns (fallback for when shlex fails)
945
+ inplace_patterns = [
946
+ # sed -i: file path after sed script (single-quoted script)
947
+ (r"\bsed\s+(?:-\S+\s+)*-i\S*\s+(?:-\S+\s+)*'[^']*'\s+\"([^\"]+)\"", 1),
948
+ (r"\bsed\s+(?:-\S+\s+)*-i\S*\s+(?:-\S+\s+)*'[^']*'\s+'([^']+)'", 1),
949
+ (r"\bsed\s+(?:-\S+\s+)*-i\S*\s+(?:-\S+\s+)*'[^']*'\s+([^\s|;&>]+)", 1),
950
+ # sed --in-place: file path after sed script
951
+ (r"\bsed\s+(?:-\S+\s+)*--in-place\S*\s+(?:-\S+\s+)*'[^']*'\s+\"([^\"]+)\"", 1),
952
+ (r"\bsed\s+(?:-\S+\s+)*--in-place\S*\s+(?:-\S+\s+)*'[^']*'\s+'([^']+)'", 1),
953
+ (r"\bsed\s+(?:-\S+\s+)*--in-place\S*\s+(?:-\S+\s+)*'[^']*'\s+([^\s|;&>]+)", 1),
954
+ # perl -i: file path after code
955
+ (r"\bperl\s+(?:-\S+\s+)*-\S*i\S*\s+(?:-\S+\s+)*'[^']*'\s+\"([^\"]+)\"", 1),
956
+ (r"\bperl\s+(?:-\S+\s+)*-\S*i\S*\s+(?:-\S+\s+)*'[^']*'\s+'([^']+)'", 1),
957
+ (r"\bperl\s+(?:-\S+\s+)*-\S*i\S*\s+(?:-\S+\s+)*'[^']*'\s+([^\s|;&>]+)", 1),
958
+ # awk -i inplace: file path after awk program
959
+ (r"\bawk\s+[^|;&]*-i\s+inplace\s+(?:-\S+\s+)*'[^']*'\s+\"([^\"]+)\"", 1),
960
+ (r"\bawk\s+[^|;&]*-i\s+inplace\s+(?:-\S+\s+)*'[^']*'\s+'([^']+)'", 1),
961
+ (r"\bawk\s+[^|;&]*-i\s+inplace\s+(?:-\S+\s+)*'[^']*'\s+([^\s|;&>]+)", 1),
962
+ # patch: file path
963
+ (r"\bpatch\s+(?:-\S+\s+)*\"([^\"]+)\"", 1),
964
+ (r"\bpatch\s+(?:-\S+\s+)*'([^']+)'", 1),
965
+ (r"\bpatch\s+(?:-\S+\s+)*([^\s|;&<>]+)", 1),
966
+ ]
967
+
968
+ for pattern, group in inplace_patterns:
969
+ for match in re.finditer(pattern, command):
970
+ path = match.group(group)
971
+ if path and not path.startswith("-"):
972
+ paths.append(path)
973
+
812
974
  return list(set(paths))
813
975
 
814
976