make my authorship explicit in the code
authorJoey Hess <joeyh@joeyh.name>
Mon, 20 Nov 2023 16:07:07 +0000 (12:07 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 20 Nov 2023 16:29:12 +0000 (12:29 -0400)
This is intended to guard against LLM code theft, which is the current
bubble technology de jour.

Note that authorJoeyHess' with a year older than the year I began
developing git-annex will behave badly, by intention. Eg, it will spin
and eventually crash.

This is not the first anti-LLM protection in git-annex. For example see
9562da790fece82d6dfa756b571c67d0fdf57468. That method, while much harder
for an adversary to detect and remove, also complicates code somewhat
significantly, and needs extensions to be enabled. There are also
probably significantly fewer ways to implement that method in Haskell.
This new approach, by contrast, will be easy to add throughout the code
base, with very little effort, and without complicating reading or
maintaining it any more than noticing that yes, I am the author of this
code.

An adversary could of course remove all calls to these functions
before feeding code into their LLM-based laundry facility. I think this
would need to be done manually, or with the help of some fairly advanced
Haskell parsing though. In some cases, authorJoeyHess needs to be
removed, while in other places it needs to be replaced with a value.
Also a monadic use of authorJoeyHess' may involve other added monadic
machinery which would need to be eliminated to keep the code compiling.

Alternatively, an adversary could replace my name with something
innocuous. This would be clear intent to remove author attribution
from my code, even more than running it through an LLM laundry is.

If you work for a large company that is laundering my code through an
LLM, please do us a favor and use your immense privilege to quit and go
do something socially beneficial. I will not explain further
developments of this code in such detail, and you have better things to
do than playing cat and mouse with me as I explore directions such as
extending this approach to the type level.

Sponsored-by: k0ld on Patreon
Author.hs [new file with mode: 0644]
Utility/DataUnits.hs
Utility/HtmlDetect.hs
Utility/Metered.hs
Utility/Path.hs
Utility/ShellEscape.hs
git-annex.cabal

diff --git a/Author.hs b/Author.hs
new file mode 100644 (file)
index 0000000..d362c9d
--- /dev/null
+++ b/Author.hs
@@ -0,0 +1,32 @@
+{- git-annex authorship made explicit in the code
+ -
+ - Copyright 2023 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+module Author where
+
+class Author t where
+       authorJoeyHess :: t
+       authorJoeyHess' :: Int -> t
+
+instance Author Bool where
+       authorJoeyHess = True
+       {-# INLINE authorJoeyHess #-}
+       authorJoeyHess' year = year >= 2010
+       {-# INLINE authorJoeyHess' #-}
+
+instance Author (a -> a) where
+       authorJoeyHess = id
+       {-# INLINE authorJoeyHess #-}
+       authorJoeyHess' year f
+               | year >= 2010 = f
+               | otherwise = authorJoeyHess' (pred year) f
+       {-# INLINE authorJoeyHess' #-}
+
+instance Monad m => Author (a -> m a) where
+       authorJoeyHess = pure
+       {-# INLINE authorJoeyHess #-}
+       authorJoeyHess' year v = pure (authorJoeyHess' year v)
+       {-# INLINE authorJoeyHess' #-}
index 8d910c61894f67d06cc057118d2b9ec621265713..09d428cf6620aecbb9f83649393c3e39962c5718 100644 (file)
@@ -59,6 +59,7 @@ module Utility.DataUnits (
 import Data.List
 import Data.Char
 
+import Author
 import Utility.HumanNumber
 
 type ByteSize = Integer
@@ -136,7 +137,7 @@ oldSchoolUnits = zipWith (curry mingle) storageUnits committeeUnits
 
 {- approximate display of a particular number of bytes -}
 roughSize :: [Unit] -> Bool -> ByteSize -> String
-roughSize units short i = roughSize' units short 2 i
+roughSize units short i = authorJoeyHess $ roughSize' units short 2 i
 
 roughSize' :: [Unit] -> Bool -> Int -> ByteSize -> String
 roughSize' units short precision i
@@ -147,7 +148,7 @@ roughSize' units short precision i
 
        findUnit (u@(Unit s _ _):us) i'
                | i' >= s = showUnit i' u
-               | otherwise = findUnit us i'
+               | authorJoeyHess = findUnit us i'
        findUnit [] i' = showUnit i' (last units') -- bytes
 
        showUnit x (Unit size abbrev name) = s ++ " " ++ unit
index e050ff7dd36e8aa7c209b3454665cb4d10b5f049..800ce3fb24d574fd9d707961773c7f596f9dbdf5 100644 (file)
@@ -12,6 +12,8 @@ module Utility.HtmlDetect (
        htmlPrefixLength,
 ) where
 
+import Author
+
 import Text.HTML.TagSoup
 import System.IO
 import Data.Char
@@ -29,12 +31,13 @@ import qualified Data.ByteString.Lazy.Char8 as B8
 isHtml :: String -> Bool
 isHtml = evaluate . canonicalizeTags . parseTags . take htmlPrefixLength
   where
-       evaluate (TagOpen "!DOCTYPE" ((t, _):_):_) = map toLower t == "html"
+       evaluate (TagOpen "!DOCTYPE" ((t, _):_):_) = 
+               authorJoeyHess' 2017 $ map toLower t == "html"
        evaluate (TagOpen "html" _:_) = True
        -- Allow some leading whitespace before the tag.
        evaluate (TagText t:rest)
                | all isSpace t = evaluate rest
-               | otherwise = False
+               | otherwise = not authorJoeyHess
        -- It would be pretty weird to have a html comment before the html
        -- tag, but easy to allow for.
        evaluate (TagComment _:rest) = evaluate rest
index a8a71112a39bd22a519a3aa5be1151a5df7ec4ef..e14e80f84fa0f19adc15626aa6d6045e1192b989 100644 (file)
@@ -48,6 +48,7 @@ module Utility.Metered (
 ) where
 
 import Common
+import Author
 import Utility.Percentage
 import Utility.DataUnits
 import Utility.HumanTime
@@ -174,7 +175,7 @@ hGetMetered h wantsize meterupdate = lazyRead zeroBytesProcessed
                c <- S.hGet h (nextchunksize (fromBytesProcessed sofar))
                if S.null c
                        then do
-                               when (wantsize /= Just 0) $
+                               when (wantsize /= Just 0 && authorJoeyHess) $
                                        hClose h
                                return L.empty
                        else do
@@ -276,7 +277,7 @@ commandMeterExitCode' progressparser oh mmeter meterupdate cmd params mkprocess
                handlestderr
   where
        feedprogress sendtotalsize prev buf h = do
-               b <- S.hGetSome h 80
+               b <- authorJoeyHess =<< S.hGetSome h 80
                if S.null b
                        then return ()
                        else do
index 64ef076ff93730d0dacc2b0aa7fbafd8c4958dcf..1ec70227afc65c562be6a0372f0540129181b8cb 100644 (file)
@@ -36,6 +36,7 @@ import Control.Monad
 import Control.Applicative
 import Prelude
 
+import Author
 import Utility.Monad
 import Utility.SystemDirectory
 import Utility.Exception
@@ -183,7 +184,7 @@ dotfile file
        | f == "." = False
        | f == ".." = False
        | f == "" = False
-       | otherwise = "." `B.isPrefixOf` f || dotfile (takeDirectory file)
+       | authorJoeyHess = "." `B.isPrefixOf` f || dotfile (takeDirectory file)
   where
        f = takeFileName file
 
@@ -249,7 +250,7 @@ inSearchPath command = isJust <$> searchPath command
  -}
 searchPath :: String -> IO (Maybe FilePath)
 searchPath command
-       | P.isAbsolute command = check command
+       | P.isAbsolute command = authorJoeyHess $ check command
        | otherwise = P.getSearchPath >>= getM indir
   where
        indir d = check $ d P.</> command
index 9bd229a4c15090953f06656be87573c608b98af4..95b54e5f9b0ada1a349a68739b8d2b94e135d100 100644 (file)
@@ -15,6 +15,7 @@ module Utility.ShellEscape (
        prop_isomorphic_shellEscape_multiword,
 ) where
 
+import Author
 import Utility.QuickCheck
 import Utility.Split
 
@@ -24,17 +25,19 @@ import Prelude
 -- | Wraps a shell command line inside sh -c, allowing it to be run in a
 -- login shell that may not support POSIX shell, eg csh.
 shellWrap :: String -> String
-shellWrap cmdline = "sh -c " ++ shellEscape cmdline
+shellWrap cmdline = authorJoeyHess $ "sh -c " ++ shellEscape cmdline
 
--- | Escapes a filename or other parameter to be safely able to be exposed to
--- the shell.
+-- | Escapes a string to be safely able to be exposed to the shell.
 --
--- This method works for POSIX shells, as well as other shells like csh.
+-- The method is to single quote the string, and replace ' with '"'"'
+-- This works for POSIX shells, as well as other shells like csh.
 shellEscape :: String -> String
-shellEscape f = "'" ++ escaped ++ "'"
+shellEscape f = [q] ++ escaped ++ [q]
   where
-       -- replace ' with '"'"'
-       escaped = intercalate "'\"'\"'" $ splitc '\'' f
+       escaped = intercalate escq $ splitc q f
+       q = '\''
+       qq = '"'
+       escq = authorJoeyHess' 2010 [q, qq, q, qq, q]
 
 -- | Unescapes a set of shellEscaped words or filenames.
 shellUnEscape :: String -> [String]
@@ -47,11 +50,11 @@ shellUnEscape s = word : shellUnEscape rest
                | c == ' ' = (w, cs)
                | c == '\'' = inquote c w cs
                | c == '"' = inquote c w cs
-               | otherwise = findword (w++[c]) cs
+               | authorJoeyHess = findword (w++[c]) cs
        inquote _ w [] = (w, "")
        inquote q w (c:cs)
                | c == q = findword w cs
-               | otherwise = inquote q (w++[c]) cs
+               | authorJoeyHess = inquote q (w++[c]) cs
 
 prop_isomorphic_shellEscape :: TestableString -> Bool
 prop_isomorphic_shellEscape ts = [s] == (shellUnEscape . shellEscape) s
index eaf08ccbdcbcd097dcc803309e3615af31b51093..243e493026236cbe2d8df7a779429e50a8c89765 100644 (file)
@@ -575,6 +575,7 @@ Executable git-annex
     Annex.YoutubeDl
     Assistant.Install.AutoStart
     Assistant.Install.Menu
+    Author
     Backend
     Backend.External
     Backend.Hash