@workscribe/cli 3.0.0 → 3.0.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": "@workscribe/cli",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Passive developer work journal — automatic terminal activity summaries",
5
5
  "homepage": "https://workscribe.co",
6
6
  "repository": {
package/shell/hook.bash CHANGED
@@ -1,9 +1,26 @@
1
1
  # Workscribe — developer work journal
2
2
  # Do not edit this block manually. Managed by `workscribe init`.
3
3
  # workscribe:hook:start
4
+ # workscribe:hook-version 2
5
+ # Now in milliseconds, or nothing: bash 5's $EPOCHREALTIME, else `date +%s` (macOS's bash 3.2 has no $EPOCHREALTIME,
6
+ # and its BSD date has no %N)
7
+ _workscribe_now_ms() {
8
+ if [[ -n "${EPOCHREALTIME:-}" ]]; then
9
+ local micros=${EPOCHREALTIME//[.,]/}
10
+ [[ $micros =~ ^[0-9]+$ ]] && echo $(( 10#$micros / 1000 ))
11
+ return 0
12
+ fi
13
+ local seconds
14
+ seconds=$(date +%s 2>/dev/null)
15
+ [[ $seconds =~ ^[0-9]+$ ]] && echo $(( seconds * 1000 ))
16
+ return 0
17
+ }
18
+
4
19
  _workscribe_preexec() {
20
+ # The DEBUG trap also fires for the rest of the rc file — nothing before the first prompt is the user's command
21
+ [[ -n "${_workscribe_primed:-}" ]] || return 0
5
22
  if [ "$BASH_COMMAND" != "_workscribe_precmd" ]; then
6
- _workscribe_cmd_start=$(date +%s%3N 2>/dev/null || echo 0)
23
+ _workscribe_cmd_start=$(_workscribe_now_ms)
7
24
  _workscribe_last_cmd="$BASH_COMMAND"
8
25
  _workscribe_git_before=$(git rev-parse HEAD 2>/dev/null || echo "")
9
26
  fi
@@ -13,17 +30,21 @@ _workscribe_precmd() {
13
30
  local exit_code=$?
14
31
  command -v workscribe &>/dev/null || return 0
15
32
  if [[ -n "$_workscribe_last_cmd" ]]; then
16
- local now
17
- now=$(date +%s%3N 2>/dev/null || echo 0)
18
- local duration=$(( now - _workscribe_cmd_start ))
33
+ # The command is captured even when it can't be timed: no duration rather than no event
34
+ local now duration=""
35
+ now=$(_workscribe_now_ms)
36
+ if [[ $now =~ ^[0-9]+$ && $_workscribe_cmd_start =~ ^[0-9]+$ ]]; then
37
+ duration=$(( now - _workscribe_cmd_start ))
38
+ fi
19
39
  command workscribe _capture \
20
40
  --cmd "$_workscribe_last_cmd" \
21
41
  --cwd "$PWD" \
22
42
  --exit "$exit_code" \
23
- --duration "$duration" \
43
+ ${duration:+--duration "$duration"} \
24
44
  ${_workscribe_git_before:+--git-before "$_workscribe_git_before"} \
25
45
  > /dev/null 2>&1 &
26
46
  _workscribe_last_cmd=""
47
+ _workscribe_cmd_start=""
27
48
  _workscribe_git_before=""
28
49
  fi
29
50
  # Skip the alert check on the first precmd: it fires before the shell has
package/shell/hook.zsh CHANGED
@@ -1,6 +1,10 @@
1
1
  # Workscribe — developer work journal
2
2
  # Do not edit this block manually. Managed by `workscribe init`.
3
3
  # workscribe:hook:start
4
+ # workscribe:hook-version 2
5
+ # $EPOCHREALTIME exists only once zsh/datetime is loaded — plain zsh doesn't load it
6
+ zmodload zsh/datetime 2>/dev/null
7
+
4
8
  _workscribe_preexec() {
5
9
  _workscribe_cmd_start=$EPOCHREALTIME
6
10
  _workscribe_cmd="$1"
@@ -11,16 +15,22 @@ _workscribe_precmd() {
11
15
  local exit_code=$?
12
16
  command -v workscribe > /dev/null 2>&1 || return 0
13
17
  if [[ -n "$_workscribe_cmd" ]]; then
14
- local _raw_ms=$(( ($EPOCHREALTIME - $_workscribe_cmd_start) * 1000 ))
15
- local duration_ms=${_raw_ms%%.*}
18
+ # Optional flags as an array: zsh doesn't word-split ${x:+--flag "$x"}, which would pass "--flag value" as one
19
+ # argument. And the command is captured even when it can't be timed.
20
+ local -a _workscribe_args
21
+ if [[ -n "$_workscribe_cmd_start" && -n "$EPOCHREALTIME" ]]; then
22
+ local _raw_ms=$(( (EPOCHREALTIME - _workscribe_cmd_start) * 1000 ))
23
+ _workscribe_args+=(--duration "${_raw_ms%%.*}")
24
+ fi
25
+ [[ -n "$_workscribe_git_before" ]] && _workscribe_args+=(--git-before "$_workscribe_git_before")
16
26
  command workscribe _capture \
17
27
  --cmd "$_workscribe_cmd" \
18
28
  --cwd "$PWD" \
19
29
  --exit "$exit_code" \
20
- --duration "$duration_ms" \
21
- ${_workscribe_git_before:+--git-before "$_workscribe_git_before"} \
30
+ "${_workscribe_args[@]}" \
22
31
  > /dev/null 2>&1 &!
23
32
  _workscribe_cmd=""
33
+ _workscribe_cmd_start=""
24
34
  _workscribe_git_before=""
25
35
  fi
26
36
  # Skip the alert check on the first precmd: it fires before the shell has