Repository navigation
Conversation
Add analyzeImages: a pure module that analyzes plugin icons/screenshots with the Kimi vision model via the injected env.AI binding and returns validated NormalizedFinding[] (source "image"). Images travel as data-URI content parts on one chat-completions request pinned with satisfies; the system prompt declares text rendered inside images untrusted, and metadata plus the image manifest ride in the same per-request untrusted fences as the code adapter. Bounds: MIME allowlist, per-image and aggregate byte caps, and a count cap, all dropping with honest partial coverage; zero kept images skips the model call entirely (call: null). Both adapters now also fail fast with a non-retryable TypeError on over-long promptVersion/modelId, which validateSourceMetadata would otherwise reject on every call as a misclassified retryable failure.
|
Scope checkThis PR changes 881 lines across 5 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | 203b267 | Jul 13 2026, 06:58 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | 203b267 | Jul 13 2026, 06:57 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 203b267 | Jul 13 2026, 06:57 AM |
There was a problem hiding this comment.
This is the right change at the right time: it adds the W8.3 image AI adapter as a symmetric sibling to the existing code adapter, keeps the same pure-module/injected-binding shape, and deliberately leaves orchestrator wiring to the W7.3 consumer work. The security model—exact-token fences, data-URI image parts, exact MIME allowlist, provenance override, and converting model/validation failures to ModelTransientError—is consistent with the code adapter and the implementation plan.
I read the diff and the full changed files but did not run the test suite, linter, or typechecker. The new tests look comprehensive for the behavior they cover (happy path, source/metadata override, data-URI construction, fence injection resistance, size/count/aggregate bounds, no-call short-circuits, config validation, and prompt-hash stability).
I found one spec gap that should be addressed before this part of W8.3 is considered complete, and one smaller defensive suggestion:
- Missing image hash in the adapter contract — the spec §9.7 and the W8.3 plan require private evidence to retain every image's original
MIME type, hash, dimensions, and source path.ImageAnalysisImagecurrently has nohashfield, so the adapter cannot pass the hash through to the manifest or to any downstream evidence object. This is a broken contract with the spec, not a stylistic nit. - Blank
modelIdslips through fail-fast validation —deps.modelId ?? DEFAULT_MODEL_IDonly falls back onundefined/null; an empty string reaches the binding and becomes a retryableModelTransientError. A blankmodelIdshould be rejected up front like a blankpromptVersion.
Neither issue is a security/data-loss blocker, so I'm leaving this as comment rather than request_changes.
| run(model: string, inputs: ImageAiRunInputs): Promise<unknown>; | ||
| } | ||
|
|
||
| export interface ImageAnalysisImage { |
There was a problem hiding this comment.
[needs fixing] ImageAnalysisImage captures path, mime, dataBase64, width, height, and kind, but it has no content-hash field. The spec §9.7 and the W8.3 plan both require private evidence to retain every image's original MIME type, hash, dimensions, and source path. Without a hash field, the adapter contract is incomplete and the orchestrator/evidence layer must reconstruct the hash out-of-band from the path, which risks losing it at the boundary.
Add readonly hash: string, include it in the image manifest, and update tests to pass and assert it.
| export interface ImageAnalysisImage { | |
| export interface ImageAnalysisImage { | |
| readonly path: string; | |
| readonly mime: string; | |
| readonly dataBase64: string; | |
| + readonly hash: string; | |
| readonly width: number; | |
| readonly height: number; | |
| readonly kind: "icon" | "screenshot"; | |
| } |
Also include the hash in buildManifestFence:
images.map((image) => ({
path: image.path,
+ hash: image.hash,
kind: image.kind,
width: image.width,
height: image.height,
})),| throw new TypeError( | ||
| `analyzeImages: deps.promptVersion must be at most ${MAX_METADATA_FIELD_LENGTH} characters`, | ||
| ); | ||
| if (modelId.length > MAX_METADATA_FIELD_LENGTH) |
There was a problem hiding this comment.
[suggestion] modelId is normalized with deps.modelId ?? DEFAULT_MODEL_ID, which only falls back when the value is null or undefined. An empty string is not nullish, so it slips through and is passed to deps.ai.run, which will fail and be wrapped as a retryable ModelTransientError. A caller/config bug like a blank model ID should fail fast with a non-retryable TypeError, just like the blank promptVersion check above.
| if (modelId.length > MAX_METADATA_FIELD_LENGTH) | |
| const modelId = deps.modelId ?? DEFAULT_MODEL_ID; | |
| + if (modelId.trim().length === 0) | |
| + throw new TypeError("analyzeImages: deps.modelId must be a non-empty string"); | |
| if (modelId.length > MAX_METADATA_FIELD_LENGTH) | |
| throw new TypeError( | |
| `analyzeImages: modelId must be at most ${MAX_METADATA_FIELD_LENGTH} characters`, | |
| ); |
The same gap exists in analyzeCode (apps/labeler/src/code-ai-adapter.ts).
…ront ImageAnalysisImage now carries the original image's sha256, and the model-visible manifest retains mime/sha256/dimensions/path (spec §9.7). A blank modelId slipped past the ?? fallback in both adapters and surfaced as an endlessly-retried ModelTransientError; both now fail fast with a non-retryable TypeError.
|
Both addressed:
259 tests green. Re-triggering. ~ 🤖 Fable |
There was a problem hiding this comment.
Re-review: prior findings are fixed, no new blockers
This is the right change at the right place: it lands the W8.3 image AI adapter as a symmetric sibling to the existing code adapter, preserves the same pure-module/injected-binding shape, and deliberately defers orchestrator wiring to the W7.3 consumer work. The security model (exact-token fences, data-URI image parts, exact MIME allowlist, provenance override, and converting model/validation failures to ModelTransientError) remains consistent with #1994.
I read the updated diff and the full changed files. Both findings from the previous review are addressed:
- Image hash is now in the adapter contract.
ImageAnalysisImagegained a requiredsha256field andbuildManifestFence()now emits the hash, dimensions, MIME type, and source path for every kept image — matching spec §9.7's private-evidence retention requirement. - Blank and over-long
modelId/promptVersionnow fail fast. BothanalyzeCodeandanalyzeImagesreject whitespace-only values and values longer thanMAX_METADATA_FIELD_LENGTHwith a non-retryableTypeError, closing the retry-forever gap described in the PR.
I also re-scanned the new adapter for the cross-cutting concerns in AGENTS.md: no SQL or migrations, no admin UI / i18n surface, no public API breakage, no locale-filtered content queries, ESM imports use .js extensions, type-only imports use import type, and the test-only fake-binding approach is unchanged. The partition/drop logic, aggregate cap, MIME allowlist, data-URI construction, and fence-escaping all behave as described; the coverage / call: null short-circuit for zero kept images is honest and tested.
I found no new blocking issues. Approving.
569832c
into
feat/plugin-registry-labelling-service
What does this PR do?
Adds the labeler's image AI adapter — plan item W8.3, the sibling of #1994's code adapter.
analyzeImages(input, deps)analyzes a plugin's icons/screenshots with the same Kimi model (vision) via the injected Workers AI binding and returns validatedNormalizedFinding[](source"image"), looking for impersonation, phishing UI, misleading content, and policy imagery.satisfies ChatCompletionsInputrequest pin,{ name, schema }structured output constrained to the policy's category/severity enums, unconditional provenance override, model/transport/parse failures and out-of-contract model output → retryableModelTransientError.png/jpeg/webp/gif, exact match) is enforced before URI construction, so a crafted MIME can't reach the URI.coverage: "partial"+ deduplicated, input-ordereddroppedImages). Zero kept images (empty input or all dropped) skips the model call entirely and reportscall: null.promptVersionormodelIdwould failsourceMetadatavalidation on every call and be misclassified as retryable. Both adapters now fail fast with a non-retryableTypeError(bounded byMAX_METADATA_FIELD_LENGTH, now exported fromfindings.ts).Not wired to the orchestrator's
imageAistage — that waits on the W7.3 bundle-input producer, same as the code adapter. No migration, no lexicon change, no public-API change.Reviewed with an opus adversarial pass before opening; it confirmed the MIME/data-URI and manifest-fence surfaces safe and drove the aggregate-payload cap and the shared over-long-config fix.
Targets
feat/plugin-registry-labelling-service. Related to #1909 and RFC #694.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.Admin i18n and changeset are n/a — this touches only
apps/labeler, a private, unpublished Worker app (no admin UI, not on npm).AI-generated code disclosure
Screenshots / test output
pnpm --filter @emdash-cms/labeler test: 256 pass (17 files) — 25 new (happy path; provenance override; data-URI parts; manifest fence injection resistance; in-image-text prompt rule; MIME/size/count/aggregate bounds incl. near-miss MIME variants and duplicate-path dedup; no-call short-circuits; schema enum; transport/parse/out-of-enum →ModelTransientError; blank + over-long config →TypeError; promptHash stability)pnpm lint:jsondiagnostics unchanged at 19 (0 inapps/labeler)Try this PR
Open a fresh playground →
A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.
Tracks
feat/labeler-image-ai-adapter. Updated automatically when the playground redeploys.