diff --git a/cmd/collect/main.go b/cmd/collect/main.go index 8eba780..d2d2815 100644 --- a/cmd/collect/main.go +++ b/cmd/collect/main.go @@ -53,6 +53,7 @@ func main() { shell := flag.String("shell", "", "actual shell") uname := flag.String("uname", "", "uname") sessionID := flag.String("sessionId", "", "resh generated session id") + recordID := flag.String("recordId", "", "resh generated record id") // recall metadata recallActions := flag.String("recall-actions", "", "recall actions that took place before executing the command") @@ -195,6 +196,7 @@ func main() { Shell: *shell, Uname: *uname, SessionID: *sessionID, + RecordID: *recordID, // posix Home: *home, diff --git a/cmd/postcollect/main.go b/cmd/postcollect/main.go index d987bc5..b5cb6b0 100644 --- a/cmd/postcollect/main.go +++ b/cmd/postcollect/main.go @@ -44,6 +44,8 @@ func main() { cmdLine := flag.String("cmdLine", "", "command line") exitCode := flag.Int("exitCode", -1, "exit code") sessionID := flag.String("sessionId", "", "resh generated session id") + recordID := flag.String("recordId", "", "resh generated record id") + shlvl := flag.Int("shlvl", -1, "$SHLVL") shell := flag.String("shell", "", "actual shell") @@ -118,6 +120,7 @@ func main() { CmdLine: *cmdLine, ExitCode: *exitCode, SessionID: *sessionID, + RecordID: *recordID, Shlvl: *shlvl, Shell: *shell, diff --git a/pkg/records/records.go b/pkg/records/records.go index 9283429..8696ef3 100644 --- a/pkg/records/records.go +++ b/pkg/records/records.go @@ -23,6 +23,7 @@ type BaseRecord struct { Shell string `json:"shell"` Uname string `json:"uname"` SessionID string `json:"sessionId"` + RecordID string `json:"recordId"` // posix Home string `json:"home"` @@ -232,6 +233,9 @@ func (r *Record) Merge(r2 Record) error { if r.CmdLine != r2.CmdLine { return errors.New("Records to merge are not parts of the same records - r1:" + r.CmdLine + " r2:" + r2.CmdLine) } + if r.RecordID != r2.RecordID { + return errors.New("Records to merge do not have the same ID - r1:" + r.RecordID + " r2:" + r2.RecordID) + } // r.RealtimeBefore != r2.RealtimeBefore - can't be used because of bash-preexec runs when it's not supposed to r.ExitCode = r2.ExitCode r.PwdAfter = r2.PwdAfter diff --git a/scripts/hooks.sh b/scripts/hooks.sh index b0fd1ce..6a1d6bf 100644 --- a/scripts/hooks.sh +++ b/scripts/hooks.sh @@ -9,6 +9,7 @@ __resh_reset_variables() { __RESH_HIST_RECALL_ACTIONS="" __RESH_HIST_NO_PREFIX_MODE=0 __RESH_HIST_RECALL_STRATEGY="" + __RESH_RECORD_ID=$(__resh_get_uuid) } __resh_preexec() { @@ -81,6 +82,7 @@ __resh_collect() { -shell "$__RESH_SHELL" \ -uname "$__RESH_UNAME" \ -sessionId "$__RESH_SESSION_ID" \ + -recordId "$__RESH_RECORD_ID" \ -cols "$__RESH_COLS" \ -home "$__RESH_HOME" \ -lang "$__RESH_LANG" \ @@ -157,6 +159,7 @@ __resh_precmd() { -realtimeBefore "$__RESH_RT_BEFORE" \ -exitCode "$__RESH_EXIT_CODE" \ -sessionId "$__RESH_SESSION_ID" \ + -recordId "$__RESH_RECORD_ID" \ -shell "$__RESH_SHELL" \ -shlvl "$__RESH_SHLVL" \ -pwdAfter "$__RESH_PWD_AFTER" \