Skip to content

feat(shared): support reference images in the act CLI tool - #2871

Merged
codeestX merged 5 commits into
mainfrom
feat/cli-act-image-prompt
Jul 28, 2026
Merged

feat(shared): support reference images in the act CLI tool#2871
codeestX merged 5 commits into
mainfrom
feat/cli-act-image-prompt

Conversation

@codeestX

Copy link
Copy Markdown
Collaborator

What

Adds reference-image input to the act common tool, so platform CLIs
(@midscene/web, @midscene/android, @midscene/ios, …) can pass images to
act the same way they already can to assert:

npx @midscene/web act \
  --url https://example.com \
  --prompt "tap the icon that matches the reference image" \
  --image ./target.png \
  --image-name target

--image / --image-name may be repeated (counts must match) and remote URLs
can be inlined via --convert-http-image2-base64 true.

Why

act was the odd one out: only assert exposed the image flags at the CLI
surface, even though core already supports multimodal prompts everywhere.
aiAct / aiAction accept a TUserPrompt and forward reference images to the
planner (TaskExecutor.actionplanImpl({ referenceImageMessages }),
packages/core/src/agent/tasks.ts). So this is purely CLI wiring — no core
change was needed.

How

  • add promptInputExtraSchema (image / imageName / convertHttpImage2Base64)
    to the act tool schema
  • compose a UserPromptLike via composeUserPrompt(...) before calling
    aiAction, mirroring assert
  • widen BaseAgent.aiAction to accept UserPromptLike

Plan-cache correctness is preserved: the plan cache key is
JSON.stringify(prompt), which already incorporates each image name/url, so
"same text, different image" does not hit a stale cached plan.

aiWaitFor intentionally stays string-only (no multimodal entry point yet); the
stale comment in types.ts is updated accordingly.

Validation

  • npx nx test @midscene/shared -- tests/unit-test/tool-generator.test.ts — 45 passed
    (new generateCommonTools — act image prompts cases: forwards images as a
    TUserPrompt object, forwards a local-path url verbatim, no-image prompt stays a
    bare string; updated schema assertions)
  • npx nx build @midscene/shared — passed with the type checker enabled
  • npx nx build @midscene/android — passed (downstream consumer of the widened
    BaseAgent.aiAction type)
  • pre-commit lint-staged (biome) — passed on the changed files

🤖 Generated with Claude Code

codeestX and others added 2 commits July 24, 2026 17:55
The `act` common tool accepted only a text prompt, while `assert` already
exposed `--image` / `--image-name` / `--convert-http-image2-base64`. Core
`aiAct`/`aiAction` already forwards reference images to the planner
(TaskExecutor.action -> planImpl(referenceImageMessages)), so this only wires
the same multimodal entry point into the act tool:

- add `promptInputExtraSchema` to the act tool schema
- compose a `UserPromptLike` via `composeUserPrompt` before calling `aiAction`
- widen `BaseAgent.aiAction` to accept `UserPromptLike` to match

Image references support local paths, base64 and remote URLs, mirroring the
existing `assert` behavior. Plan-cache correctness is preserved because the
cache key is `JSON.stringify(prompt)`, which already includes image name/url.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`aiAct` already forwards reference images to the planner, and the CLI `act`
tool now exposes the same image flags, but the docs only listed image
prompting for the locate / insight / assert methods. Add aiAct to the
image-prompting docs so site readers can discover it:

- api.mdx: widen the aiAct signature to `string | Object`, link its `prompt`
  param to "Prompting with images", and add an aiAct example.
- automate-with-scripts-in-yaml.mdx: document the `aiAct` object form with
  `images` / `convertHttpImage2Base64`, already covered by
  yaml-doc-usage.test.ts.

Bilingual (en + zh).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deploying midscene with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8ec1cbb
Status: ✅  Deploy successful!
Preview URL: https://5ed3c54c.midscene.pages.dev
Branch Preview URL: https://feat-cli-act-image-prompt.midscene.pages.dev

View logs

codeestX and others added 3 commits July 27, 2026 19:43
…ompt

# Conflicts:
#	apps/site/docs/en/api.mdx
#	apps/site/docs/zh/api.mdx
The main branch consolidated the API docs from api.mdx into
reference/index.mdx after this branch first documented aiAct image
prompting. Re-apply the same change on the new file: widen the aiAct
signature to `string | object`, link its `prompt` param to
"Prompting with images", and add an aiAct image example.

Bilingual (en + zh).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
aiAct attaches images with the same object form as the insight steps
(`prompt` + `images` under the action key), so a separate example was
redundant. List aiAct (and its `ai` shorthand) in the existing sentence —
kept distinct from the "insight steps" wording since aiAct is an action,
not a Q&A step — and drop the duplicate example.

Bilingual (en + zh).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codeestX
codeestX merged commit 56e1d85 into main Jul 28, 2026
15 of 17 checks passed
@codeestX
codeestX deleted the feat/cli-act-image-prompt branch July 28, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants