-
Notifications
You must be signed in to change notification settings - Fork 1
feat(mail): fail-closed Inkspan edit handoff for recognized HWPX #1407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
6
commits into
cursor/mail-hwpx-attachment-preview-7b5e
Choose a base branch
from
cursor/mail-hwpx-inkspan-edit-handoff-ef6f
base: cursor/mail-hwpx-attachment-preview-7b5e
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b37929
feat(mail): fail-closed Inkspan edit handoff for HWPX
cursoragent 73208a9
merge: retarget #1407 onto live #1406 head
cursoragent b5115d4
fix(mail): fail closed on malformed Inkspan handoff metadata
cursoragent 22e4909
fix(hwpx): reject mismatched edit handoff metadata
seonghobae 730ac37
merge(stack): inherit repaired mail HWPX preview
seonghobae 4f41ef1
fix(docs): restore canonical AGENTS ownership
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| """Probe a read-only Inkspan edit handoff for recognized HWPX attachments. | ||
|
|
||
| Naruon already exposes ordered HWPX paragraphs through the repository-asset | ||
| preview. This module does not convert those paragraphs into an editable | ||
| document, does not overwrite the original attachment, and does not invent a | ||
| write API. It only records whether a released, installed Inkspan Hangul | ||
| document engine is present and whether an authorized editor contract exists. | ||
|
|
||
| Released Inkspan remains a Markdown/HTML editor. Hangul import/edit/export is | ||
| owned by unreleased inkspan Draft #320 and is not installed here, so the host | ||
| adapter hook stays empty and the buyer-visible handoff fails closed. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Literal | ||
|
|
||
| HANDOFF_STATE_UNAVAILABLE = "unavailable" | ||
| EDITOR_CAPABILITY_HANGUL_DOCUMENT_ENGINE = "inkspan_hangul_document_engine" | ||
| ERROR_INKSPAN_HANGUL_CAPABILITY_UNAVAILABLE = "inkspan_hangul_capability_unavailable" | ||
| ERROR_INKSPAN_EDIT_CONTRACT_UNAVAILABLE = "inkspan_edit_contract_unavailable" | ||
| NEXT_ACTION_KEEP_READING_RECOGNIZED_TEXT = "keep_reading_recognized_text" | ||
| HWPX_PARSER_FAMILY = "hwpx" | ||
| AUTHORIZED_EDIT_CONTRACTS: frozenset[str] = frozenset() | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class InkspanEditHandoff: | ||
| """Carry one scoped, non-mutating Inkspan handoff for a recognized HWPX file.""" | ||
|
|
||
| source_asset_key: str | ||
| source_asset_type: str | ||
| parser_family: str | None | ||
| handoff_state: Literal["unavailable"] | ||
| editor_capability_name: str | ||
| mutation_allowed: bool | ||
| converts_source_to_plain_text: bool | ||
| overwrites_original: bool | ||
| provider_write_executed: bool | ||
| next_action: str | ||
| error_code: str | ||
| editable_document_payload: None = None | ||
|
|
||
|
|
||
| def registered_inkspan_editor_capability() -> object | None: | ||
| """Return the host-owned Inkspan editor adapter when one is installed. | ||
|
|
||
| Naruon does not vendor Inkspan. A future host adapter may register here | ||
| after a released Hangul document engine exists. The default workspace has | ||
| no such adapter. | ||
| """ | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def installed_inkspan_editor_capability() -> object | None: | ||
| """Return a Hangul engine adapter only when it accepts HWPX without conversion.""" | ||
|
|
||
| adapter = registered_inkspan_editor_capability() | ||
| if _is_hangul_hwpx_capability(adapter): | ||
| return adapter | ||
| return None | ||
|
|
||
|
|
||
| def _adapter_field(adapter: object | None, field_name: str) -> object | None: | ||
| """Read one adapter attribute without treating missing hosts as installed.""" | ||
|
|
||
| if adapter is None: | ||
| return None | ||
| return getattr(adapter, field_name, None) | ||
|
|
||
|
|
||
| def _accepted_source_families(adapter: object | None) -> tuple[str, ...]: | ||
| """Return the source families an adapter can open without conversion. | ||
|
|
||
| Malformed non-collection metadata is treated as absent so a recognized | ||
| preview can fail closed instead of raising. | ||
| """ | ||
|
|
||
| families = _adapter_field(adapter, "accepted_source_families") | ||
| if not isinstance(families, (list, tuple, set, frozenset)): | ||
| return () | ||
| return tuple(str(family) for family in families) | ||
|
|
||
|
|
||
| def _is_hangul_hwpx_capability(adapter: object | None) -> bool: | ||
| """True only for a Hangul engine that accepts HWPX as HWPX.""" | ||
|
|
||
| capability_name = _adapter_field(adapter, "capability_name") | ||
| return ( | ||
| capability_name == EDITOR_CAPABILITY_HANGUL_DOCUMENT_ENGINE | ||
| and HWPX_PARSER_FAMILY in _accepted_source_families(adapter) | ||
| ) | ||
|
|
||
|
|
||
| def _unavailable_handoff( | ||
| preview: object, | ||
| error_code: str, | ||
| ) -> InkspanEditHandoff: | ||
| """Build a fail-closed handoff that keeps the exact source identity.""" | ||
|
|
||
| return InkspanEditHandoff( | ||
| source_asset_key=str(getattr(preview, "asset_key")), | ||
| source_asset_type=str(getattr(preview, "asset_type")), | ||
| parser_family=str(getattr(preview, "parser_family") or "") or None, | ||
| handoff_state=HANDOFF_STATE_UNAVAILABLE, | ||
| editor_capability_name=EDITOR_CAPABILITY_HANGUL_DOCUMENT_ENGINE, | ||
| mutation_allowed=False, | ||
| converts_source_to_plain_text=False, | ||
| overwrites_original=False, | ||
| provider_write_executed=False, | ||
| next_action=NEXT_ACTION_KEEP_READING_RECOGNIZED_TEXT, | ||
| error_code=error_code, | ||
| editable_document_payload=None, | ||
| ) | ||
|
|
||
|
|
||
| def build_inkspan_edit_handoff(preview: object) -> InkspanEditHandoff | None: | ||
| """Return a read-only Inkspan handoff for recognized HWPX, or None. | ||
|
|
||
| Pending, failed, unavailable, and non-HWPX previews do not offer an edit | ||
| control. Recognized HWPX always preserves the preview asset key and fails | ||
| closed unless a released Hangul capability and an authorized editor | ||
| contract are both present. No authorized contract exists in this slice. | ||
| """ | ||
|
|
||
| preview_state = str(getattr(preview, "preview_state", "") or "") | ||
| parser_family = str(getattr(preview, "parser_family", "") or "") | ||
| if preview_state != "recognized" or parser_family != HWPX_PARSER_FAMILY: | ||
| return None | ||
|
|
||
| adapter = registered_inkspan_editor_capability() | ||
| if not _is_hangul_hwpx_capability(adapter): | ||
| return _unavailable_handoff( | ||
| preview, | ||
| ERROR_INKSPAN_HANGUL_CAPABILITY_UNAVAILABLE, | ||
| ) | ||
|
|
||
| contract_name = _adapter_field(adapter, "mutation_contract_name") | ||
| if ( | ||
| not isinstance(contract_name, str) | ||
| or contract_name not in AUTHORIZED_EDIT_CONTRACTS | ||
| ): | ||
| return _unavailable_handoff( | ||
| preview, | ||
| ERROR_INKSPAN_EDIT_CONTRACT_UNAVAILABLE, | ||
| ) | ||
|
|
||
| return _unavailable_handoff( | ||
| preview, | ||
| ERROR_INKSPAN_EDIT_CONTRACT_UNAVAILABLE, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.