@mayurdluffy/ccwf 0.5.0 → 0.6.0

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.
Files changed (38) hide show
  1. package/README.md +19 -13
  2. package/lib/chrome-mcp.js +63 -13
  3. package/lib/index.js +171 -64
  4. package/lib/installer.js +115 -30
  5. package/lib/machine.js +63 -18
  6. package/lib/merge.js +56 -12
  7. package/lib/modules.js +38 -6
  8. package/lib/published.js +51 -0
  9. package/lib/stats.js +110 -0
  10. package/package.json +2 -2
  11. package/templates/blocks/browser.md +2 -2
  12. package/templates/blocks/guardrails.md +7 -0
  13. package/templates/docs/ROADMAP.md +1 -1
  14. package/templates/docs/agents/issue-tracker.md +5 -5
  15. package/templates/docs/agents/setup.md +5 -5
  16. package/templates/docs/agents/workflow.md +3 -3
  17. package/templates/guardrails/check.sh +100 -0
  18. package/templates/machine.json +53 -43
  19. package/templates/skills/commit/SKILL.md +1 -1
  20. package/templates/skills/orchestrate-workers/SKILL.md +46 -16
  21. package/templates/skills/orchestrate-workers/approve.sh +5 -1
  22. package/templates/skills/orchestrate-workers/assign.sh +2 -0
  23. package/templates/skills/orchestrate-workers/checks.sh +17 -0
  24. package/templates/skills/orchestrate-workers/claude-worker-settings.json +6 -2
  25. package/templates/skills/orchestrate-workers/end.sh +5 -2
  26. package/templates/skills/orchestrate-workers/grid.sh +2 -0
  27. package/templates/skills/orchestrate-workers/pane.sh +19 -4
  28. package/templates/skills/orchestrate-workers/review.sh +68 -0
  29. package/templates/skills/orchestrate-workers/runlog.sh +23 -0
  30. package/templates/skills/orchestrate-workers/tickets.sh +94 -0
  31. package/templates/skills/orchestrate-workers/watch.sh +64 -13
  32. package/templates/skills/orchestrate-workers/workers.conf +4 -0
  33. package/templates/skills/orchestrate-workers/worktree.sh +160 -0
  34. package/templates/skills/verify-ui/SKILL.md +5 -4
  35. package/templates/skills/verify-ui/ab.sh +9 -0
  36. package/templates/skills/verify-ui/lib.sh +59 -0
  37. package/templates/skills/verify-ui/probe.sh +6 -3
  38. package/templates/skills/verify-ui/run.sh +21 -7
@@ -32,6 +32,8 @@ base=${BASE_URL:-$conf_base}
32
32
  host=${${base#*://}%%[:/]*}
33
33
  # Evidence lives inside the repo so every agent may read it; the folder ignores itself in git.
34
34
  outroot=${VERIFY_OUT:-$(git -C "$lib" rev-parse --show-toplevel)/.scratch/.verify-out}
35
+ # Folders in here are deleted and rewritten, so a link in its place must not lead that elsewhere.
36
+ [[ -n $VERIFY_OUT || ${outroot:A} == $outroot ]] || { echo "SETUP: $outroot is or is inside a link to ${outroot:A}; remove the link, or set VERIFY_OUT to the folder to use"; exit 2; }
35
37
  mkdir -p "$outroot" && [[ -e $outroot/.gitignore ]] || print '*' > "$outroot/.gitignore"
36
38
  # Cursor and plain shells do not get this from agent settings; without it agent-browser asks or roams.
37
39
  export AGENT_BROWSER_ALLOWED_DOMAINS=${AGENT_BROWSER_ALLOWED_DOMAINS:-${conf_domains:-localhost}}
@@ -42,6 +44,63 @@ need_server() {
42
44
  }
43
45
  ab() { agent-browser --session "$S" "$@" 2>&1; }
44
46
  ab_open() { local u=$1; shift; [[ $u == http* ]] || u="$base$u"; ab "$@" open "$u"; } # a path is joined to BASE_URL
47
+
48
+ # Workers write the scenarios, and these scripts are approved to run outside a worker's sandbox. So a
49
+ # line may only act on the page: it never reaches the shell, and commands or flags of agent-browser that
50
+ # start programs, read its config or write files are refused. VERIFY_TRUST=1 (the user) lifts this.
51
+ page_cmds=(a11y back check click close console cookies dblclick dialog drag errors eval fill find focus forward
52
+ frame get highlight hover is keyboard keydown keyup mouse network open press pushstate react reload scroll
53
+ scrollintoview select set snapshot storage tab type uncheck upload vitals wait)
54
+ page_flags=(-i -c -d -s -u -b --delta --json --selector --tags --name --exact --text --url --load --fn --timeout --state
55
+ --abort --body --allow-origin --resource-type --clear --filter --type --method --status
56
+ --domain --path --http-only --httpOnly --secure --same-site --sameSite --expires --new-tab --human)
57
+
58
+ # Split a line into $reply the way a person reads it: spaces separate, quotes group, and $ ; & * mean nothing.
59
+ words() {
60
+ emulate -L zsh
61
+ local s=$1 c q= cur=; local -i i has=0
62
+ reply=()
63
+ for (( i = 1; i <= ${#s}; i++ )); do
64
+ c=$s[i]
65
+ if [[ -n $q ]]; then
66
+ if [[ $c == "$q" ]]; then q=
67
+ elif [[ $c == \\ && $q == \" && ( $s[i+1] == \" || $s[i+1] == \\ ) ]]; then (( i += 1 )); cur+=$s[i]
68
+ else cur+=$c; fi
69
+ elif [[ $c == \" || $c == \' ]]; then q=$c; has=1
70
+ elif [[ $c == \\ && $i -lt ${#s} ]]; then (( i += 1 )); cur+=$s[i]; has=1
71
+ elif [[ $c == [[:space:]] ]]; then (( has )) && reply+=("$cur"); cur=; has=0
72
+ else cur+=$c; has=1; fi
73
+ done
74
+ (( has )) && reply+=("$cur")
75
+ [[ -z $q ]] || reply=(${=s}) # an apostrophe, not a quote: take the words as they are
76
+ }
77
+
78
+ # Prints why these words are refused and returns 1, or returns 0.
79
+ action_ok() {
80
+ [[ -n $VERIFY_TRUST ]] && return 0
81
+ local a f; local -i i
82
+ (( ${page_cmds[(Ie)$1]} )) || { echo "'$1' is not allowed here (page commands only)"; return 1; }
83
+ [[ $1 != network || $2 == (route|unroute|requests|request) ]] || { echo "'network $2' is not allowed here"; return 1; }
84
+ for (( i = 2; i <= $#; i++ )); do
85
+ a=${@[i]}; f=${a%%=*}
86
+ [[ $a == -[^0-9.]* ]] || continue
87
+ (( ${page_flags[(Ie)$f]} )) || { echo "'$f' is not allowed here"; return 1; }
88
+ if [[ $f == --state ]]; then # also a global flag that loads a saved login
89
+ [[ $a == *=* ]] && a=${a#*=} || a=${@[i+1]}
90
+ [[ $a == (visible|hidden|attached|detached) ]] || { echo "'--state $a' is not allowed here"; return 1; }
91
+ fi
92
+ done
93
+ }
94
+ act() { if [[ $1 == open ]]; then ab_open "$2"; else ab "$@"; fi; } # words already checked by action_ok
95
+
96
+ # guard.sh is code that sits among files workers write: run it only as it was last committed.
97
+ guard_ok() {
98
+ [[ -n $VERIFY_TRUST ]] && return 0
99
+ local top rel; top=$(git -C "$lib" rev-parse --show-toplevel 2>/dev/null) && rel=${1#$top/} || return 1
100
+ if [[ -f $1 ]]; then git -C "$top" cat-file blob "HEAD:$rel" 2>/dev/null | cmp -s - "$1"
101
+ else ! git -C "$top" cat-file -e "HEAD:$rel" 2>/dev/null; fi
102
+ }
103
+
45
104
  tree() { ab snapshot -c; } # all text a person can see, as the accessibility tree
46
105
  itree() { ab snapshot -i -c; } # interactive elements only, with @eN refs
47
106
  short() { cut -c1-220; }
@@ -2,7 +2,7 @@
2
2
  # One-shot health report of a page: what a person, the console and the network panel would show,
3
3
  # in about 30 lines. The first command to run when debugging or reviewing anything in the browser.
4
4
  # Usage: probe.sh [options] <path-or-url> BASE_URL comes from verify-ui.conf
5
- # --do '<agent-browser command>' run before reporting (repeatable, in order), e.g.
5
+ # --do '<page command>' run before reporting (repeatable, in order), e.g.
6
6
  # --do 'find role button click --name "Create an item"'
7
7
  # --a11y add the axe accessibility audit (violations by impact)
8
8
  # --react launch with React DevTools; saves the component tree; implies --keep
@@ -26,6 +26,7 @@ while (( $# )); do
26
26
  esac
27
27
  shift
28
28
  done
29
+ [[ $lines =~ '^[0-9]+$' ]] || { echo "SETUP: --tree takes a number"; exit 2; }
29
30
  [[ -n $target ]] || { echo "SETUP: no page given (probe.sh --help)"; exit 2; }
30
31
  need_server
31
32
 
@@ -35,7 +36,8 @@ rm -rf "$out"; mkdir -p "$out"
35
36
  flags=(); (( react )) && flags=(--enable react-devtools)
36
37
  o=$(ab_open "$target" $flags) || { echo "SETUP: cannot open $target: $(print -r -- "$o" | tail -1)"; ab close >/dev/null; exit 2; }
37
38
  for d in $dos; do
38
- o=$(eval "ab $d") || echo "do failed: $d: $(print -r -- "$o" | tail -1 | short)"
39
+ words "$d"
40
+ o=$(action_ok "${(@)reply}" && act "${(@)reply}") || echo "do failed: $d: $(print -r -- "$o" | tail -1 | short)"
39
41
  done
40
42
  ab wait 400 >/dev/null # let the last action's requests and renders land
41
43
 
@@ -48,7 +50,8 @@ n() { [[ -z $1 ]] && echo 0 || print -r -- "$1" | wc -l | tr -d ' '; }
48
50
  {
49
51
  echo "PROBE $(ab get url) \"$(ab get title)\""
50
52
  echo "page errors: $(print -r -- "$errs" | grep -c '^✗') console: $(n "$cerr") error, $(n "$cwarn") warning requests: $(requests | wc -l | tr -d ' ') ($(n "$bad") failed, $(n "$dead") no response, $(n "$api") api)"
51
- echo "vitals: $(ab vitals | sed -n '2p')"
53
+ # vitals reloads the page, which would undo what --do set up before the tree and evidence are taken.
54
+ (( ${#dos} )) && echo "vitals: not measured with --do" || echo "vitals: $(ab vitals | sed -n '2p')"
52
55
  [[ -n $errs ]] && { echo "-- page errors"; print -r -- "$errs" | head -8 | short; }
53
56
  [[ -n $cerr ]] && { echo "-- console errors (count, message)"; print -r -- "$cerr" | head -5 | short; }
54
57
  [[ -n $cwarn ]] && { echo "-- console warnings"; print -r -- "$cwarn" | head -3 | short; }
@@ -24,10 +24,12 @@
24
24
  # shot <name> save a screenshot as evidence (a drawing, layout); path is printed
25
25
  # use <name> [args] run the lines of steps/<name>.txt beside the scenario file here;
26
26
  # {1}, {2}, ... in that file are replaced by the args (shared sign-in, seeding)
27
- # <anything else> an agent-browser command, must succeed (a missing element is retried for 5s):
27
+ # <anything else> an agent-browser command that acts on the page, must succeed (a missing element is retried for 5s):
28
28
  # find role button click --name "Save", fill, press, wait --text,
29
29
  # set viewport 390 844, set offline on, network route <url> --abort
30
30
  # Arguments with spaces: quote them where a command takes more than one (expect-value "#name" "Sam").
31
+ # Lines never go through the shell: $, ;, & and * are plain text. Commands and flags that start programs,
32
+ # load agent-browser settings or write files are refused (VERIFY_TRUST=1 lifts that).
31
33
  #
32
34
  # After every scenario, automatically: no uncaught page errors, no console errors, no 4xx/5xx
33
35
  # request to the app (unhandled promise rejections count as page errors). On FAIL the full tree, console,
@@ -38,6 +40,7 @@
38
40
  #
39
41
  # A guard.sh beside the scenario files runs once before them (BASE_URL is exported to it). A non-zero
40
42
  # exit refuses the run: use it to make sure scenarios that create data only run against a throwaway app.
43
+ # It runs only when it is unchanged since the last commit: read it, then commit it or set VERIFY_TRUST=1.
41
44
  . ${0:A:h}/lib.sh
42
45
  need_server
43
46
 
@@ -48,6 +51,7 @@ done
48
51
  (( ${#files} )) || { echo "SETUP: no scenario files"; exit 2; }
49
52
 
50
53
  for d in ${(u)files:A:h}; do
54
+ guard_ok "$d/guard.sh" || { echo "SETUP: $d/guard.sh is new, changed or missing since the last commit. Someone other than its author reads it, then commits it or runs this with VERIFY_TRUST=1"; exit 2; }
51
55
  [[ -f $d/guard.sh ]] || continue
52
56
  BASE_URL=$base sh "$d/guard.sh" || { echo "SETUP: $d/guard.sh refused this run"; exit 2; }
53
57
  done
@@ -71,7 +75,7 @@ load() {
71
75
  for (( i = 1; i <= ${#params}; i++ )); do line=${line//\{$i\}/$params[i]}; done
72
76
  cmd=${line%% *}; arg=${line#* }
73
77
  if [[ $cmd == use ]]; then
74
- local -a u; u=("${(@Q)${(z)arg}}")
78
+ local -a u; words "$arg"; u=("${(@)reply}")
75
79
  inc=${file:A:h}/steps/$u[1].txt
76
80
  [[ -f $inc ]] || inc=$sdir/steps/$u[1].txt
77
81
  [[ -f $inc ]] || { loaderr="use $u[1]: no steps/$u[1].txt beside $file"; return 1; }
@@ -85,7 +89,7 @@ load() {
85
89
  # Run one scenario file. Sets $fail (empty on success), $rep (the lines to print) and $step.
86
90
  run_one() {
87
91
  local f=$1 line cmd arg o e v i bl max pct warn
88
- local -a w
92
+ local -a w a
89
93
  S=verify-$name-$$; out=$outroot/$name
90
94
  step=0; fail=""; okcon=""; okreq=""; shots=(); lines=(); loaderr=""; sdir=${f:A:h}
91
95
  rm -rf "$out"
@@ -93,7 +97,15 @@ run_one() {
93
97
  for line in $lines; do
94
98
  [[ -n $fail ]] && break
95
99
  (( step++ ))
96
- cmd=${line%% *}; arg=${line#* }; w=("${(@Q)${(z)arg}}")
100
+ cmd=${line%% *}; arg=${line#* }; words "$arg"; w=("${(@)reply}")
101
+ case $cmd in # arguments that would be read as an agent-browser flag, a path or a formula
102
+ expect-visible|expect-count|expect-value|expect-storage)
103
+ [[ $arg == -* || $w[1] == -* ]] && { fail="step $step: $cmd $w[1]: not allowed, a selector or key cannot start with -"; break; } ;;
104
+ shot|expect-shot)
105
+ [[ $w[1] =~ '^[A-Za-z0-9_][A-Za-z0-9._-]*$' && ${w[2]:-0} =~ '^[0-9]+([.][0-9]+)?$' ]] || { fail="step $step: $line: not allowed, use a plain name (letters, digits, . _ -) and a number"; break; } ;;
106
+ expect-status)
107
+ [[ $w[1] == /* ]] || { fail="step $step: $line: not allowed, the path must start with /"; break; } ;;
108
+ esac
97
109
  case $cmd in
98
110
  open) o=$(ab_open "$arg") || fail="open $arg: $(print -r -- "$o" | tail -1)" ;;
99
111
  expect-text) poll has_text "$arg" || fail="text not found: $arg" ;;
@@ -129,10 +141,12 @@ run_one() {
129
141
  fi ;;
130
142
  allow-console) okcon=${okcon:+$okcon|}$arg ;;
131
143
  allow-request) okreq=${okreq:+$okreq|}$arg ;;
132
- shot) mkdir -p "$out"; o=$(ab screenshot "$out/$arg.png") && shots+=("$out/$arg.png") || fail="screenshot: $o" ;;
133
- *) # An element that is not there yet (page still loading) is retried like an expect; any other error fails at once.
144
+ shot) mkdir -p "$out"; o=$(ab screenshot "$out/$w[1].png") && shots+=("$out/$w[1].png") || fail="screenshot: $o" ;;
145
+ *) words "$line"; a=("${(@)reply}")
146
+ o=$(action_ok "${(@)a}") || { fail="step $step: $o"; break; }
147
+ # An element that is not there yet (page still loading) is retried like an expect; any other error fails at once.
134
148
  for i in 1 2 3 4 5 6 7 8 9 10; do
135
- o=$(eval "ab $line") && break
149
+ o=$(act "${(@)a}") && break
136
150
  [[ ( $o == *"No element found"* || $o == *"but none match"* ) && $i != 10 ]] || { fail="'$line' failed: $(print -r -- "$o" | tail -2 | tr '\n' ' ')"; break; }
137
151
  sleep 0.5
138
152
  done ;;