@deeeed/metamask-harness 0.20.0 → 0.22.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.
package/dist/manifest.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { OFFICIAL_RECIPE_ACTIONS } from "@farmslot/protocol";
3
4
  import { manifestPath, readJson, importRecipeProtocol } from "./paths.js";
4
- import {
5
- actionSourceIntegrity,
6
- metaMaskActionExecutionCapabilities
7
- } from "./recipe-security.js";
5
+ import { actionSourceIntegrity } from "./recipe-security.js";
8
6
  function loadMetaMaskMobileActionManifest() {
9
7
  return asActionManifest(readJson(manifestPath("mobile")));
10
8
  }
@@ -26,12 +24,12 @@ async function resolveActionManifest(adapter, overridePath, librarySources, task
26
24
  const implementationRoot = path.resolve(
27
25
  taskActionRoot ?? defaultImplementationRoot(manifestPath2)
28
26
  );
29
- const manifest = withMetaMaskExecutionCapabilities(loadActionManifest(adapter, manifestPath2));
27
+ const manifest = loadActionManifest(adapter, manifestPath2);
30
28
  await validateManifest(manifest);
31
29
  const integrity = await actionSourceIntegrity(manifestPath2, "task", implementationRoot);
32
30
  return {
33
31
  manifest,
34
- actionSources: describeManifestSources(manifest, {
32
+ actionSources: await describeManifestSources(manifest, {
35
33
  name: "task",
36
34
  tier: "task",
37
35
  manifestPath: manifestPath2,
@@ -41,109 +39,125 @@ async function resolveActionManifest(adapter, overridePath, librarySources, task
41
39
  })
42
40
  };
43
41
  }
44
- const canonicalPath = manifestPath(adapter);
45
- const sources = librarySources?.length ? librarySources : [{ name: "metamask", root: path.dirname(path.dirname(canonicalPath)) }];
42
+ const canonicalPath = path.resolve(manifestPath(adapter));
43
+ const canonicalRoot = path.dirname(path.dirname(canonicalPath));
44
+ const sources = librarySources?.length ? librarySources : [{ name: "metamask", root: canonicalRoot }];
46
45
  const manifests = [];
47
46
  for (const source of sources) {
48
- const file = path.join(source.root, "manifests", `${adapter}.action-manifest.json`);
47
+ const file = path.resolve(source.root, "manifests", `${adapter}.action-manifest.json`);
49
48
  if (!fs.existsSync(file)) continue;
50
49
  const manifest = asActionManifest(readJson(file));
51
50
  await validateManifest(manifest);
52
51
  manifests.push({ source, file, manifest });
53
52
  }
54
- if (!manifests.some((entry) => path.resolve(entry.file) === path.resolve(canonicalPath))) {
53
+ if (!manifests.some((entry) => entry.file === canonicalPath)) {
55
54
  const manifest = loadActionManifest(adapter);
56
55
  await validateManifest(manifest);
57
- manifests.push({ source: { name: "metamask", root: path.dirname(path.dirname(canonicalPath)) }, file: canonicalPath, manifest });
56
+ manifests.push({
57
+ source: { name: "metamask", root: canonicalRoot },
58
+ file: canonicalPath,
59
+ manifest
60
+ });
58
61
  }
59
- const canonical = manifests.find((entry) => entry.source.name === "metamask") ?? manifests.at(-1);
62
+ const canonical = manifests.find((entry) => entry.file === canonicalPath);
60
63
  if (!canonical) throw new Error(`No ${adapter} action manifest could be resolved.`);
61
- const base = cloneManifest(canonical.manifest);
62
- const official = new Set(stringArray(recordOf(base).supported_official_actions));
63
- const custom = /* @__PURE__ */ new Map();
64
- const customMetadata = /* @__PURE__ */ new Map();
65
- const bindings = /* @__PURE__ */ new Map();
64
+ const official = new Set(OFFICIAL_RECIPE_ACTIONS);
65
+ const canonicalActions = actionsOf(canonical.manifest);
66
+ const mergedActions = {};
67
+ for (const [name, entry] of Object.entries(canonicalActions)) {
68
+ if (official.has(name)) mergedActions[name] = entry;
69
+ }
66
70
  const canonicalImplementationRoot = path.join(canonical.source.root, "actions");
67
71
  const canonicalIntegrity = await actionSourceIntegrity(
68
72
  canonical.file,
69
73
  "canonical",
70
74
  canonicalImplementationRoot
71
75
  );
72
- const actionSources = describeManifestSources(base, {
73
- name: "metamask",
74
- tier: "canonical",
75
- manifestPath: canonical.file,
76
- implementationRoot: canonicalImplementationRoot,
77
- trust: "trusted",
78
- ...canonicalIntegrity
79
- });
80
- for (const entry of manifests) {
81
- const sourceName = entry.source.name ?? path.basename(entry.source.root);
82
- const tier = sourceName === "metamask" ? "canonical" : sourceName === "personal" ? "personal" : "team";
76
+ const actionSources = /* @__PURE__ */ new Map();
77
+ for (const name of Object.keys(mergedActions)) {
78
+ actionSources.set(name, {
79
+ name: "official",
80
+ tier: "official",
81
+ manifestPath: canonical.file
82
+ });
83
+ }
84
+ const custom = /* @__PURE__ */ new Set();
85
+ const ordered = [
86
+ ...manifests.filter((entry) => entry.file !== canonicalPath),
87
+ canonical
88
+ ];
89
+ for (const entry of ordered) {
90
+ const isCanonical = entry.file === canonicalPath;
91
+ if (!isCanonical && entry.manifest.observers?.length) {
92
+ throw new Error(
93
+ `Library manifest ${entry.file} declares observers, but external library observers are not executable; remove observers or use an explicit task action manifest.`
94
+ );
95
+ }
96
+ const sourceName = isCanonical ? "metamask" : entry.source.name ?? path.basename(entry.source.root);
97
+ const tier = isCanonical ? "canonical" : sourceName === "personal" ? "personal" : "team";
83
98
  const implementationRoot = path.join(entry.source.root, "actions");
84
- const integrity = await actionSourceIntegrity(entry.file, tier, implementationRoot);
99
+ const integrity = isCanonical ? canonicalIntegrity : await actionSourceIntegrity(entry.file, tier, implementationRoot);
85
100
  const sourceInfo = {
86
101
  name: sourceName,
87
102
  tier,
88
103
  manifestPath: entry.file,
89
104
  implementationRoot,
90
- trust: entry.source.provenance?.trust ?? (tier === "canonical" ? "trusted" : "unknown"),
105
+ trust: entry.source.provenance?.trust ?? (isCanonical ? "trusted" : "unknown"),
91
106
  ...integrity
92
107
  };
93
- const manifestRecord = recordOf(entry.manifest);
94
- const metadata = recordOf(manifestRecord.action_metadata);
95
- for (const action of customActions(manifestRecord.custom_actions)) {
96
- if (official.has(action.name)) {
97
- throw new Error(`Library action ${action.name} from ${entry.file} conflicts with an official action.`);
108
+ for (const [name, action] of Object.entries(actionsOf(entry.manifest))) {
109
+ if (official.has(name)) {
110
+ if (!isCanonical) {
111
+ throw new Error(
112
+ `Library action ${name} from ${entry.file} conflicts with an official action; team libraries may declare namespaced custom actions only.`
113
+ );
114
+ }
115
+ continue;
98
116
  }
99
- if (custom.has(action.name)) {
100
- const existing = actionSources.get(action.name);
117
+ if (custom.has(name)) {
118
+ const existing = actionSources.get(name);
101
119
  if (existing && existing.name !== sourceName) {
102
120
  existing.shadows = [...existing.shadows ?? [], sourceName];
103
121
  }
104
122
  continue;
105
123
  }
106
- custom.set(action.name, action.value);
107
- customMetadata.set(action.name, metadata[action.name]);
108
- actionSources.set(action.name, { ...sourceInfo });
109
- }
110
- for (const binding of objectArray(manifestRecord.native_bindings)) {
111
- const action = typeof binding.action === "string" ? binding.action : void 0;
112
- if (action && !bindings.has(action)) bindings.set(action, binding);
124
+ custom.add(name);
125
+ mergedActions[name] = action;
126
+ actionSources.set(name, { ...sourceInfo });
113
127
  }
114
128
  }
115
- const baseRecord = recordOf(base);
116
- baseRecord.custom_actions = [...custom.values()];
117
- const baseMetadata = recordOf(baseRecord.action_metadata);
118
- for (const [name, metadata] of customMetadata) {
119
- if (metadata !== void 0) baseMetadata[name] = metadata;
129
+ return {
130
+ manifest: {
131
+ $schema: canonical.manifest.$schema,
132
+ actions: mergedActions,
133
+ ...canonical.manifest.observers ? { observers: canonical.manifest.observers } : {}
134
+ },
135
+ actionSources
136
+ };
137
+ }
138
+ function actionsOf(manifest) {
139
+ return manifest.actions;
140
+ }
141
+ async function describeManifestSources(manifest, customSource) {
142
+ const official = new Set(OFFICIAL_RECIPE_ACTIONS);
143
+ const sources = /* @__PURE__ */ new Map();
144
+ for (const name of Object.keys(actionsOf(manifest))) {
145
+ if (official.has(name)) {
146
+ sources.set(name, {
147
+ name: "official",
148
+ tier: "official",
149
+ manifestPath: customSource.manifestPath
150
+ });
151
+ continue;
152
+ }
153
+ sources.set(name, { ...customSource });
120
154
  }
121
- baseRecord.action_metadata = baseMetadata;
122
- baseRecord.native_bindings = [...bindings.values()];
123
- return { manifest: withMetaMaskExecutionCapabilities(base), actionSources };
155
+ return sources;
124
156
  }
125
157
  function defaultImplementationRoot(selectedManifestPath) {
126
158
  const manifestDirectory = path.dirname(selectedManifestPath);
127
159
  return path.basename(manifestDirectory) === "manifests" ? path.join(path.dirname(manifestDirectory), "actions") : path.join(manifestDirectory, "actions");
128
160
  }
129
- function withMetaMaskExecutionCapabilities(manifest) {
130
- const result = cloneManifest(manifest);
131
- const record = recordOf(result);
132
- if (!Array.isArray(record.custom_actions)) return result;
133
- record.custom_actions = record.custom_actions.map((entry) => {
134
- const name = typeof entry === "string" ? entry : recordOf(entry).name;
135
- if (typeof name !== "string") return entry;
136
- const capabilities = metaMaskActionExecutionCapabilities(name);
137
- if (capabilities.length === 0) return entry;
138
- const declaredValue = typeof entry === "string" ? void 0 : recordOf(entry).execution_capabilities;
139
- const declared = Array.isArray(declaredValue) ? declaredValue.filter(
140
- (capability) => typeof capability === "string"
141
- ) : [];
142
- const executionCapabilities = [.../* @__PURE__ */ new Set([...declared, ...capabilities])];
143
- return typeof entry === "string" ? { name, execution_capabilities: executionCapabilities } : { ...recordOf(entry), execution_capabilities: executionCapabilities };
144
- });
145
- return result;
146
- }
147
161
  async function validateManifest(manifest) {
148
162
  const { validateRecipeActionManifestDocument } = await importRecipeProtocol();
149
163
  const result = validateRecipeActionManifestDocument(manifest);
@@ -157,41 +171,11 @@ async function validateManifest(manifest) {
157
171
  function asActionManifest(value) {
158
172
  return value;
159
173
  }
160
- function cloneManifest(value) {
161
- return JSON.parse(JSON.stringify(value));
162
- }
163
- function recordOf(value) {
164
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
165
- }
166
- function stringArray(value) {
167
- return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
168
- }
169
- function objectArray(value) {
170
- return Array.isArray(value) ? value.filter((entry) => Boolean(entry) && typeof entry === "object" && !Array.isArray(entry)) : [];
171
- }
172
- function customActions(value) {
173
- if (!Array.isArray(value)) return [];
174
- return value.flatMap((entry) => {
175
- if (typeof entry === "string") return [{ name: entry, value: entry }];
176
- const record = recordOf(entry);
177
- return typeof record.name === "string" ? [{ name: record.name, value: entry }] : [];
178
- });
179
- }
180
- function describeManifestSources(manifest, customSource) {
181
- const record = recordOf(manifest);
182
- const sources = /* @__PURE__ */ new Map();
183
- for (const name of stringArray(record.supported_official_actions)) {
184
- sources.set(name, { name: "official", tier: "official", manifestPath: customSource.manifestPath });
185
- }
186
- for (const action of customActions(record.custom_actions)) sources.set(action.name, { ...customSource });
187
- return sources;
188
- }
189
174
  export {
190
175
  loadActionManifest,
191
176
  loadMetaMaskCoreActionManifest,
192
177
  loadMetaMaskExtensionActionManifest,
193
178
  loadMetaMaskMobileActionManifest,
194
179
  resolveActionManifest,
195
- validateManifest,
196
- withMetaMaskExecutionCapabilities
180
+ validateManifest
197
181
  };
@@ -77,6 +77,40 @@ Example:
77
77
  mm-harness checklist mark temp/tasks/recipe-cook/<task> complete --mark-last
78
78
  mm-harness checklist closeout temp/tasks/recipe-cook/<task> --share`
79
79
  },
80
+ {
81
+ name: "execution-template",
82
+ summary: "Discover, validate, and materialize shared agent checklists.",
83
+ example: "mm-harness execution-template list --package-templates <path> --json",
84
+ helpText: `mm-harness execution-template <list|materialize|lint|new> [options]
85
+
86
+ Shared Markdown checklist catalog used by direct and orchestrated workflows.
87
+ Sources use the flow-tree shape <root>/<flow>/<variant>.md.
88
+
89
+ list List compatible templates and portable source provenance.
90
+ materialize Select one template, copy its immutable snapshot, and optionally
91
+ write a provenance record.
92
+ lint Validate one template file or flow-tree directory.
93
+ new Create a minimal starter template.
94
+
95
+ Common source/filter options:
96
+ --dir <path> Custom flow-tree source (repeatable)
97
+ --domain-dir <domain=path> Domain-scoped team source (repeatable)
98
+ --package-templates <path> Canonical package flow-tree root
99
+ --package-id <id> Source label for the package root
100
+ --project-worker <path> Project template directory
101
+ --project-name <name> Source label for project templates
102
+ --flow <flow> Exact flow
103
+ --platform <platform> Exact platform
104
+ --run-mode <mode> autonomous|interactive|validation
105
+ --domain <domain> Exact domain
106
+ --id <id> Exact template id
107
+ --json Machine-readable output
108
+
109
+ Materialize:
110
+ mm-harness execution-template materialize <output> --flow fix-bug \\
111
+ --platform mobile --run-mode autonomous --id fix-bug/autonomous.mobile \\
112
+ --package-templates <path> --provenance <path> --json`
113
+ },
80
114
  {
81
115
  name: "actions",
82
116
  summary: "Discover typed single operations and their fields.",
@@ -552,7 +586,7 @@ const HELP_GROUPS = [
552
586
  {
553
587
  title: "DISCOVER",
554
588
  blurb: "discover atomic actions and reusable recipes (--json is the agent-primary form)",
555
- commands: ["actions", "call"]
589
+ commands: ["actions", "call", "execution-template"]
556
590
  },
557
591
  {
558
592
  title: "PROVE",
package/dist/runner.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { execSync } from "node:child_process";
2
+ import { OFFICIAL_RECIPE_ACTIONS } from "@farmslot/protocol";
2
3
  import { createMetaMaskAdapters, createMetaMaskUiTransport } from "./adapters.js";
3
4
  import {
4
5
  mobileSourceFingerprint,
@@ -6,11 +7,13 @@ import {
6
7
  } from "./adapters/mobile/source-freshness.js";
7
8
  import { resolveMetaMaskMobileLifecycleTarget } from "./app-lifecycle.js";
8
9
  import { loadMetaMaskExtensionActionManifest, loadMetaMaskMobileActionManifest } from "./manifest.js";
10
+ import { metaMaskActionExecutionCapabilities } from "./recipe-security.js";
9
11
  import {
10
12
  prepareLiveAdapterScript
11
13
  } from "./live-adapter-contract.js";
12
14
  import { createMetaMaskRecordingTargetProvider } from "./recording-target.js";
13
15
  import { importRecipeHarness, importRecipeHarnessAppLifecycle, importRecipeHarnessRuntimeCdp, importRecipeHarnessRuntimeReactNativeBridge, runnerDir } from "./paths.js";
16
+ const OFFICIAL_ACTIONS = new Set(OFFICIAL_RECIPE_ACTIONS);
14
17
  async function createMetaMaskMobileRunner(options = {}) {
15
18
  return createMetaMaskRunner(
16
19
  "mobile",
@@ -32,9 +35,8 @@ async function createMetaMaskRunner(adapter, actionManifest, options = {}) {
32
35
  const { createCdpWebUiTransport } = await importRecipeHarnessRuntimeCdp();
33
36
  const { createReactNativeBridgeUiTransport } = await importRecipeHarnessRuntimeReactNativeBridge();
34
37
  const { createAppLifecycleAdapters } = await importRecipeHarnessAppLifecycle();
35
- const customActions = (actionManifest.custom_actions ?? []).map(
36
- (entry) => typeof entry === "string" ? entry : entry.name
37
- );
38
+ const actions = Object.keys(actionManifest.actions);
39
+ const customActions = actions.filter((action) => !OFFICIAL_ACTIONS.has(action));
38
40
  const actionSources = options.actionSources ? new Map([...options.actionSources].map(([action, source]) => [action, { ...source }])) : void 0;
39
41
  const preparedLiveAdapters = await prepareLiveAdapterImplementations(
40
42
  adapter,
@@ -42,7 +44,6 @@ async function createMetaMaskRunner(adapter, actionManifest, options = {}) {
42
44
  actionSources,
43
45
  options.trustTaskActions
44
46
  );
45
- const actions = [...actionManifest.supported_official_actions, ...customActions];
46
47
  const declaredActions = new Set(actions);
47
48
  const core = createStandardCoreAdapters({ actions });
48
49
  const projectOwnedOfficialActions = /* @__PURE__ */ new Set(["app.status", "app.lifecycle"]);
@@ -144,8 +145,10 @@ async function prepareLiveAdapterImplementations(platform, actions, sources, tru
144
145
  }
145
146
  function adapterSecurity(action, sources, trustTaskActions = false) {
146
147
  const source = sources?.get(action);
148
+ const capabilities = !OFFICIAL_ACTIONS.has(action) ? { capabilities: metaMaskActionExecutionCapabilities(action) } : {};
147
149
  if (source?.tier === "task") {
148
150
  return {
151
+ ...capabilities,
149
152
  source: {
150
153
  kind: "custom-adapter",
151
154
  trust: trustTaskActions ? "trusted" : "untrusted",
@@ -158,6 +161,7 @@ function adapterSecurity(action, sources, trustTaskActions = false) {
158
161
  }
159
162
  if (source && source.tier !== "official") {
160
163
  return {
164
+ ...capabilities,
161
165
  source: {
162
166
  kind: source.tier === "canonical" ? "bundled" : "custom-adapter",
163
167
  trust: source.trust ?? (source.tier === "canonical" ? "trusted" : "unknown"),
@@ -169,6 +173,7 @@ function adapterSecurity(action, sources, trustTaskActions = false) {
169
173
  };
170
174
  }
171
175
  return {
176
+ ...capabilities,
172
177
  source: {
173
178
  kind: "bundled",
174
179
  trust: "trusted",
package/docs/RECIPES.md CHANGED
@@ -89,21 +89,11 @@ The protocol is authoritative:
89
89
 
90
90
  ```text
91
91
  team-recipes/
92
- library.json
93
92
  manifests/extension.action-manifest.json
94
93
  actions/extension/wallet/ensure_ready.mjs
95
94
  recipes/onboarding/smoke.extension.recipe.json
96
95
  ```
97
96
 
98
- ```json
99
- {
100
- "kind": "recipe-library",
101
- "schema_version": 1,
102
- "name": "wallet-team",
103
- "owner": "wallet-team"
104
- }
105
- ```
106
-
107
97
  ```bash
108
98
  export RECIPE_LIBRARY_PATH="wallet=$HOME/shared-library/wallet-team"
109
99
  mm-harness run --list
@@ -111,7 +101,8 @@ mm-harness run onboarding.smoke --describe
111
101
  mm-harness run onboarding.smoke --plan
112
102
  ```
113
103
 
114
- Use `--library wallet=/path/to/library` for one command. Resolution follows the
104
+ Use `--library wallet=/path/to/library` for one command. The alias is the
105
+ source name; without one, the directory name is used. Resolution follows the
115
106
  explicit library order, then bundled MetaMask. Adapter-specific variants are
116
107
  selected deterministically. Every run records the root recipe, exact resolved
117
108
  dependency documents, their digests, call edges, selected sources, and shadows.
@@ -69,12 +69,17 @@ async function activateSemanticControl(page, selector) {
69
69
  export async function openHome(page, timeoutMs) {
70
70
  const home = dataTestId('bottom-nav-home');
71
71
  const selectedHome = `${home}[aria-current="page"]`;
72
+ const legacyHome = dataTestId('account-overview__asset-tab');
73
+ const selectedLegacyHome = `${legacyHome}[aria-selected="true"]`;
72
74
  const deadline = Date.now() + timeoutMs;
73
75
  const steps = [];
74
76
  let pendingActivation;
75
77
 
76
78
  while (Date.now() < deadline) {
77
- if (await hasVisibleSelector(page, selectedHome)) {
79
+ if (
80
+ (await hasVisibleSelector(page, selectedHome)) ||
81
+ (await hasVisibleSelector(page, selectedLegacyHome))
82
+ ) {
78
83
  return { method: 'visible-ui', href: await currentHref(page), steps };
79
84
  }
80
85
  const href = await currentHref(page);
@@ -83,12 +88,17 @@ export async function openHome(page, timeoutMs) {
83
88
  await pauseForUi(page);
84
89
  continue;
85
90
  }
86
- if (await hasVisibleSelector(page, home)) {
87
- if (pendingActivation?.selector !== home) pendingActivation = undefined;
91
+ const homeControl = (await hasVisibleSelector(page, home))
92
+ ? home
93
+ : (await hasVisibleSelector(page, legacyHome))
94
+ ? legacyHome
95
+ : undefined;
96
+ if (homeControl) {
97
+ if (pendingActivation?.selector !== homeControl) pendingActivation = undefined;
88
98
  if (!pendingActivation) {
89
- await activateSemanticControl(page, home);
90
- steps.push(home);
91
- pendingActivation = { selector: home, href };
99
+ await activateSemanticControl(page, homeControl);
100
+ steps.push(homeControl);
101
+ pendingActivation = { selector: homeControl, href };
92
102
  }
93
103
  await pauseForUi(page);
94
104
  continue;