@deeeed/metamask-harness 0.2.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 (158) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/README.md +140 -0
  3. package/bin/mm-harness +99 -0
  4. package/docs/CHEATSHEET.md +61 -0
  5. package/docs/CLI-SPEC.md +915 -0
  6. package/docs/MENTAL-MODEL.md +295 -0
  7. package/docs/architecture.md +367 -0
  8. package/docs/extension-runtime-commands.md +60 -0
  9. package/docs/harness-cli.md +43 -0
  10. package/docs/live-adapter-contract.md +188 -0
  11. package/docs/package-boundaries.md +47 -0
  12. package/docs/perps-flow-catalog.md +235 -0
  13. package/docs/recipe-libraries.md +95 -0
  14. package/docs/runtime-file-conventions.md +36 -0
  15. package/library/actions/core/perps/_controller.mjs +727 -0
  16. package/library/actions/core/perps/assert_orders.mjs +53 -0
  17. package/library/actions/core/perps/assert_positions.mjs +52 -0
  18. package/library/actions/core/perps/close_orders.mjs +97 -0
  19. package/library/actions/core/perps/close_positions.mjs +118 -0
  20. package/library/actions/core/perps/ensure_orders.mjs +40 -0
  21. package/library/actions/core/perps/ensure_positions.mjs +37 -0
  22. package/library/actions/core/perps/place_order.mjs +201 -0
  23. package/library/actions/core/perps/read_account.mjs +30 -0
  24. package/library/actions/core/perps/read_orders.mjs +27 -0
  25. package/library/actions/core/perps/read_positions.mjs +27 -0
  26. package/library/actions/core/perps/start_state.mjs +92 -0
  27. package/library/actions/core/perps/teardown_state.mjs +86 -0
  28. package/library/actions/extension/perps/assert_orders.mjs +11 -0
  29. package/library/actions/extension/perps/assert_positions.mjs +11 -0
  30. package/library/actions/extension/perps/close_orders.mjs +8 -0
  31. package/library/actions/extension/perps/close_positions.mjs +8 -0
  32. package/library/actions/extension/perps/ensure_orders.mjs +4 -0
  33. package/library/actions/extension/perps/ensure_positions.mjs +4 -0
  34. package/library/actions/extension/perps/perps.mjs +730 -0
  35. package/library/actions/extension/perps/place_order.mjs +7 -0
  36. package/library/actions/extension/perps/read_orders.mjs +4 -0
  37. package/library/actions/extension/perps/read_positions.mjs +3 -0
  38. package/library/actions/extension/platform/cdp.mjs +541 -0
  39. package/library/actions/extension/ui/navigate.mjs +44 -0
  40. package/library/actions/extension/wallet/ensure_unlocked.mjs +36 -0
  41. package/library/actions/extension/wallet/read_state.mjs +27 -0
  42. package/library/actions/extension/wallet/select_account.mjs +48 -0
  43. package/library/actions/extension/wallet/setup.mjs +35 -0
  44. package/library/actions/mobile/app-overlay/app/dev-tools/AgenticService/AgentStepHud.tsx.patch +185 -0
  45. package/library/actions/mobile/app-overlay/app/dev-tools/AgenticService/AgenticService.ts.patch +1662 -0
  46. package/library/actions/mobile/bridge-runtime/cdp-bridge.cjs +686 -0
  47. package/library/actions/mobile/bridge-runtime/lib/cdp-eval.cjs +110 -0
  48. package/library/actions/mobile/bridge-runtime/lib/config.cjs +39 -0
  49. package/library/actions/mobile/bridge-runtime/lib/issue-capture.cjs +446 -0
  50. package/library/actions/mobile/bridge-runtime/lib/target-discovery.cjs +204 -0
  51. package/library/actions/mobile/bridge-runtime/lib/ws-client.cjs +108 -0
  52. package/library/actions/mobile/bridge-runtime/setup-wallet.sh +442 -0
  53. package/library/actions/mobile/perps/assert_orders.mjs +11 -0
  54. package/library/actions/mobile/perps/assert_positions.mjs +11 -0
  55. package/library/actions/mobile/perps/close_orders.mjs +8 -0
  56. package/library/actions/mobile/perps/close_positions.mjs +8 -0
  57. package/library/actions/mobile/perps/ensure_orders.mjs +4 -0
  58. package/library/actions/mobile/perps/ensure_positions.mjs +4 -0
  59. package/library/actions/mobile/perps/perps.mjs +709 -0
  60. package/library/actions/mobile/perps/place_order.mjs +7 -0
  61. package/library/actions/mobile/perps/read_orders.mjs +4 -0
  62. package/library/actions/mobile/perps/read_positions.mjs +3 -0
  63. package/library/actions/mobile/platform/bridge.mjs +283 -0
  64. package/library/actions/mobile/ui/navigate.mjs +38 -0
  65. package/library/actions/mobile/wallet/ensure_unlocked.mjs +107 -0
  66. package/library/actions/mobile/wallet/home.mjs +35 -0
  67. package/library/actions/mobile/wallet/read_state.mjs +40 -0
  68. package/library/actions/mobile/wallet/select_account.mjs +48 -0
  69. package/library/actions/mobile/wallet/setup.mjs +220 -0
  70. package/library/flows/perps.flows.json +64 -0
  71. package/library/library.json +7 -0
  72. package/library/manifests/core.action-manifest.json +1282 -0
  73. package/library/manifests/extension.action-manifest.json +1749 -0
  74. package/library/manifests/mobile.action-manifest.json +1753 -0
  75. package/library/recipes/action-validation.extension.recipe.json +417 -0
  76. package/library/recipes/action-validation.mobile.recipe.json +422 -0
  77. package/library/recipes/order-lifecycle.core.recipe.json +78 -0
  78. package/library/recipes/perps-lifecycle.recipe.json +194 -0
  79. package/library/recipes/read-markets.core.recipe.json +38 -0
  80. package/library/recipes/smoke.extension.recipe.json +31 -0
  81. package/library/recipes/smoke.mobile.recipe.json +31 -0
  82. package/library/recipes/trading-lifecycle.core.recipe.json +76 -0
  83. package/orchestration/compat-overlays/README.md +19 -0
  84. package/orchestration/compat-overlays/mobile/README.md +13 -0
  85. package/orchestration/compat-overlays/mobile/rn81-message-event-source.patch +42 -0
  86. package/orchestration/core/cleanup.sh +37 -0
  87. package/orchestration/core/inject.sh +154 -0
  88. package/orchestration/doctor.mjs +72 -0
  89. package/orchestration/extension/cleanup.mjs +60 -0
  90. package/orchestration/extension/console-tail.mjs +228 -0
  91. package/orchestration/extension/ensure-browser.sh +416 -0
  92. package/orchestration/extension/ensure-ready.ts +185 -0
  93. package/orchestration/extension/extension-id.ts +107 -0
  94. package/orchestration/extension/inject.mjs +266 -0
  95. package/orchestration/extension/launch-browser.cjs +216 -0
  96. package/orchestration/extension/launch.sh +175 -0
  97. package/orchestration/extension/live.sh +320 -0
  98. package/orchestration/extension/pin-remote-flags.cjs +45 -0
  99. package/orchestration/extension/readiness.mjs +414 -0
  100. package/orchestration/extension/refresh-build.sh +190 -0
  101. package/orchestration/extension/runtime-decision.ts +445 -0
  102. package/orchestration/extension/runtime.ts +407 -0
  103. package/orchestration/extension/seed-fixture.sh +177 -0
  104. package/orchestration/extension/sidepanel-toggle.sh +291 -0
  105. package/orchestration/extension/snapshot-dist.sh +84 -0
  106. package/orchestration/extension/start-watch.sh +339 -0
  107. package/orchestration/extension/wallet-fixture-state.cjs +1086 -0
  108. package/orchestration/lib/activate-repo-node.sh +144 -0
  109. package/orchestration/lib/cli-color.mjs +84 -0
  110. package/orchestration/lib/cli-commands.mjs +243 -0
  111. package/orchestration/lib/cli-home.mjs +354 -0
  112. package/orchestration/lib/cli-ux.sh +252 -0
  113. package/orchestration/lib/cli-version.mjs +123 -0
  114. package/orchestration/lib/ensure-runner-deps.sh +56 -0
  115. package/orchestration/lib/harness-path.sh +55 -0
  116. package/orchestration/lib/hash-helpers.sh +44 -0
  117. package/orchestration/lib/json-field.sh +23 -0
  118. package/orchestration/lib/log-tui.mjs +304 -0
  119. package/orchestration/lib/open-debug.mjs +317 -0
  120. package/orchestration/lib/path-defaults.json +4 -0
  121. package/orchestration/lib/progress.mjs +107 -0
  122. package/orchestration/lib/recipe-paths.mjs +26 -0
  123. package/orchestration/lib/resolve-farmslot-ports.sh +144 -0
  124. package/orchestration/manifest.json +358 -0
  125. package/orchestration/mobile/cleanup.sh +192 -0
  126. package/orchestration/mobile/deps-markers.ts +21 -0
  127. package/orchestration/mobile/inject.sh +681 -0
  128. package/orchestration/mobile/launch.sh +137 -0
  129. package/orchestration/mobile/live.sh +125 -0
  130. package/orchestration/mobile/runtime-decision.ts +292 -0
  131. package/orchestration/porcelain/metamask-recipe +99 -0
  132. package/orchestration/porcelain/mm-recipe +1591 -0
  133. package/orchestration/porcelain/mme-recipe +1181 -0
  134. package/package.json +59 -0
  135. package/runner/extension/verify.sh +511 -0
  136. package/runner/mobile/verify.sh +501 -0
  137. package/runner/src/adapters.ts +601 -0
  138. package/runner/src/cli.ts +1820 -0
  139. package/runner/src/commands/debug.ts +44 -0
  140. package/runner/src/commands/fixtures.ts +99 -0
  141. package/runner/src/commands/launch.ts +397 -0
  142. package/runner/src/commands/logs.ts +60 -0
  143. package/runner/src/commands/shared.ts +138 -0
  144. package/runner/src/completions-cache.ts +86 -0
  145. package/runner/src/doctor.ts +203 -0
  146. package/runner/src/harness.ts +516 -0
  147. package/runner/src/heal-bounds.ts +179 -0
  148. package/runner/src/index.ts +6 -0
  149. package/runner/src/live-adapter-contract.ts +274 -0
  150. package/runner/src/manifest.ts +47 -0
  151. package/runner/src/mm-harness-cli.ts +488 -0
  152. package/runner/src/paths.ts +198 -0
  153. package/runner/src/recording-target.ts +147 -0
  154. package/runner/src/run-recording.ts +329 -0
  155. package/runner/src/runner.ts +108 -0
  156. package/runner/src/types.ts +57 -0
  157. package/scripts/completions.sh +125 -0
  158. package/scripts/install-completions.sh +62 -0
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env bash
2
+ # completions.sh — bundled tab completion for `mm-harness` (bash + zsh).
3
+ #
4
+ # Static parts (commands, positional targets, per-command flags) mirror the
5
+ # mm-harness surface. Dynamic parts are sourced live from the hidden
6
+ # `mm-harness completion-candidates <actions|flows>` command (per-checkout cached):
7
+ # call <TAB> → action names from the adapter manifest
8
+ # run <TAB> → recipe files + flow refs from the recipe library
9
+ # so completion reflects the installed overlay's real vocabulary. A candidate read
10
+ # that fails is silently empty — completion never blocks the shell.
11
+ #
12
+ # Install: source this file from ~/.zshrc / ~/.bashrc
13
+ # (see: mm-harness completions install).
14
+
15
+ # Resolve the mm-harness bin: prefer one on PATH, else this checkout's bin.
16
+ _mmh_bin() {
17
+ if command -v mm-harness >/dev/null 2>&1; then
18
+ command -v mm-harness
19
+ return 0
20
+ fi
21
+ if [ -n "${BASH_SOURCE[0]:-}" ]; then
22
+ local here
23
+ here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." 2>/dev/null && pwd)" || true
24
+ if [ -n "$here" ] && [ -x "$here/bin/mm-harness" ]; then
25
+ printf '%s\n' "$here/bin/mm-harness"
26
+ return 0
27
+ fi
28
+ fi
29
+ return 1
30
+ }
31
+
32
+ _mmh_commands="launch logs debug fixtures actions call flows run doctor install verify cleanup completions"
33
+
34
+ # Per-command flags (static, from the mm-harness surface).
35
+ _mmh_flags_for() {
36
+ case "$1" in
37
+ launch) printf '%s' "--build --watch --verify --sidepanel --fullscreen --runway --device --cdp-port --watcher-port --heal --adapter --target --json" ;;
38
+ logs) printf '%s' "--full --events --source --adapter --target --json" ;;
39
+ debug) printf '%s' "--worker --dev-menu --adapter --target --json" ;;
40
+ fixtures) printf '%s' "--fixture --adapter --target --json" ;;
41
+ actions) printf '%s' "--adapter --action --kind --raw --action-manifest --target --json" ;;
42
+ call) printf '%s' "--arg --adapter --target --artifacts-dir --action-manifest --heal --json" ;;
43
+ flows) printf '%s' "--library --json" ;;
44
+ run) printf '%s' "--plan --adapter --artifacts-dir --target --library --cdp-port --heal --record-video --json" ;;
45
+ doctor) printf '%s' "--adapter --target --fix --json" ;;
46
+ install|verify|cleanup) printf '%s' "--adapter --target --json" ;;
47
+ *) printf '%s' "" ;;
48
+ esac
49
+ }
50
+
51
+ # Dynamic candidates from the DISCOVER layer (silent empty on any failure).
52
+ _mmh_actions() { local b; b="$(_mmh_bin)" || return 0; "$b" completion-candidates actions 2>/dev/null; }
53
+ _mmh_flows() { local b; b="$(_mmh_bin)" || return 0; "$b" completion-candidates flows 2>/dev/null; }
54
+
55
+ # ── Bash ────────────────────────────────────────────────────────────────
56
+ if [ -n "${BASH_VERSION:-}" ]; then
57
+ _mmh_complete_bash() {
58
+ local cur prev words cword
59
+ _get_comp_words_by_ref -n : cur prev words cword 2>/dev/null || {
60
+ cur="${COMP_WORDS[COMP_CWORD]}"
61
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
62
+ words=("${COMP_WORDS[@]}")
63
+ cword=$COMP_CWORD
64
+ }
65
+
66
+ if [ "$cword" -eq 1 ]; then
67
+ COMPREPLY=($(compgen -W "$_mmh_commands" -- "$cur"))
68
+ return
69
+ fi
70
+
71
+ local cmd="${words[1]}"
72
+ case "$cur" in
73
+ -*) COMPREPLY=($(compgen -W "$(_mmh_flags_for "$cmd")" -- "$cur")); return ;;
74
+ esac
75
+
76
+ case "$cmd" in
77
+ launch) [ "$cword" -eq 2 ] && COMPREPLY=($(compgen -W "ios android" -- "$cur")) ;;
78
+ fixtures) [ "$cword" -eq 2 ] && COMPREPLY=($(compgen -W "sync set" -- "$cur")) ;;
79
+ completions) [ "$cword" -eq 2 ] && COMPREPLY=($(compgen -W "install bash zsh status" -- "$cur")) ;;
80
+ flows) [ "$cword" -eq 2 ] && COMPREPLY=($(compgen -W "list promote" -- "$cur")) ;;
81
+ call) [ "$cword" -eq 2 ] && COMPREPLY=($(compgen -W "$(_mmh_actions)" -- "$cur")) ;;
82
+ run) COMPREPLY=($(compgen -f -- "$cur"; compgen -W "$(_mmh_flows)" -- "$cur")) ;;
83
+ *) COMPREPLY=($(compgen -W "$(_mmh_flags_for "$cmd")" -- "$cur")) ;;
84
+ esac
85
+ }
86
+ complete -F _mmh_complete_bash mm-harness 2>/dev/null || true
87
+ fi
88
+
89
+ # ── Zsh ─────────────────────────────────────────────────────────────────
90
+ if [ -n "${ZSH_VERSION:-}" ]; then
91
+ _mmh_complete_zsh() {
92
+ local -a candidates
93
+ local cmd="${words[2]:-}"
94
+
95
+ if (( CURRENT == 2 )); then
96
+ candidates=(${=_mmh_commands})
97
+ compadd -a candidates
98
+ return
99
+ fi
100
+
101
+ local cur="${words[CURRENT]}"
102
+ if [[ "$cur" == -* ]]; then
103
+ candidates=(${=$(_mmh_flags_for "$cmd")})
104
+ compadd -a candidates
105
+ return
106
+ fi
107
+
108
+ case "$cmd" in
109
+ launch) (( CURRENT == 3 )) && { candidates=(ios android); compadd -a candidates; } ;;
110
+ fixtures) (( CURRENT == 3 )) && { candidates=(sync set); compadd -a candidates; } ;;
111
+ completions) (( CURRENT == 3 )) && { candidates=(install bash zsh status); compadd -a candidates; } ;;
112
+ flows) (( CURRENT == 3 )) && { candidates=(list promote); compadd -a candidates; } ;;
113
+ call) (( CURRENT == 3 )) && { candidates=("${(@f)$(_mmh_actions)}"); compadd -a candidates; } ;;
114
+ run) candidates=("${(@f)$(_mmh_flows)}"); compadd -a candidates; _files ;;
115
+ *) candidates=(${=$(_mmh_flags_for "$cmd")}); compadd -a candidates ;;
116
+ esac
117
+ }
118
+
119
+ if (( $+functions[compdef] )); then
120
+ compdef _mmh_complete_zsh mm-harness
121
+ else
122
+ autoload -Uz compinit 2>/dev/null && compinit -u 2>/dev/null
123
+ (( $+functions[compdef] )) && compdef _mmh_complete_zsh mm-harness
124
+ fi
125
+ fi
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env bash
2
+ # install-completions.sh — install mm-harness shell completions (bash + zsh)
3
+ set -euo pipefail
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ RUNNER_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
7
+ BASH_SNIPPET="source \"$RUNNER_ROOT/scripts/completions.sh\""
8
+ ZSH_SNIPPET=$'# mm-harness tab completion\nsource '"\"$RUNNER_ROOT/scripts/completions.sh\""
9
+
10
+ usage() {
11
+ cat <<EOF
12
+ Usage: install-completions.sh [install|bash|zsh|status]
13
+
14
+ install Print setup lines for bash and zsh (default)
15
+ bash Print bash one-liner to add to ~/.bashrc
16
+ zsh Print zsh lines to add to ~/.zshrc
17
+ status Show whether completions appear installed
18
+
19
+ Tab completion: type "mm-harness " (with a trailing space) then press TAB.
20
+
21
+ After install, restart your shell or run:
22
+ source $RUNNER_ROOT/scripts/completions.sh
23
+ EOF
24
+ }
25
+
26
+ cmd="${1:-install}"
27
+ case "$cmd" in
28
+ -h|--help) usage; exit 0 ;;
29
+ bash)
30
+ printf '%s\n' "$BASH_SNIPPET"
31
+ ;;
32
+ zsh)
33
+ printf '%s\n' "$ZSH_SNIPPET"
34
+ ;;
35
+ status)
36
+ if [ -f "$HOME/.bashrc" ] && grep -Fq "$RUNNER_ROOT/scripts/completions.sh" "$HOME/.bashrc" 2>/dev/null; then
37
+ echo "bash: sourced from ~/.bashrc"
38
+ else
39
+ echo "bash: not sourced (run: install-completions.sh bash)"
40
+ fi
41
+ if [ -f "$HOME/.zshrc" ] && grep -Fq "$RUNNER_ROOT/scripts/completions.sh" "$HOME/.zshrc" 2>/dev/null; then
42
+ echo "zsh: sourced from ~/.zshrc"
43
+ else
44
+ echo "zsh: not sourced (run: install-completions.sh zsh)"
45
+ fi
46
+ ;;
47
+ install)
48
+ echo "Add to ~/.bashrc:"
49
+ echo " $BASH_SNIPPET"
50
+ echo ""
51
+ echo "Add to ~/.zshrc:"
52
+ echo " $ZSH_SNIPPET"
53
+ echo ""
54
+ echo "Reload now:"
55
+ echo " source $RUNNER_ROOT/scripts/completions.sh"
56
+ ;;
57
+ *)
58
+ echo "Unknown command: $cmd" >&2
59
+ usage >&2
60
+ exit 2
61
+ ;;
62
+ esac