Skip to content

v5 A1: action registry - #709

Merged
TheJoeFin merged 11 commits into
devfrom
v5/a1-action-registry
Nov 12, 2026
Merged

TheJoeFin merged 11 commits into
devfrom
v5/a1-action-registry

Conversation

@TheJoeFin

Copy link
Copy Markdown
Owner

Implements v5 phase A1: one registry in Core that describes every action Text Grab can perform on text, as data. It is filled with the pure text transforms and the Windows AI actions, and registered in AppServices. No UI changes. Nothing reads the registry yet; E2 moves the Edit Text Window onto it.

The work plan is docs/v5/A1-Action-Registry.md. Its new appendix inventories every Edit Text Window action, marking which ones A1 registers and which E2 must convert. Each step is its own commit, and each passed the build and test gates.

Registry (Text_Grab.Core.Actions, Core)

  • ActionDescriptor, ActionKind, ActionCategory, ITextTransform and IActionRegistry follow the plan's sketch.
  • ActionRegistry is thread-safe, compares IDs ordinally and lists actions in registration order. It rejects duplicate IDs, blank display names, and IDs that don't follow textgrab.<area>.<verb> (three parts, lower camel case).
  • ITextTransform's doc comments set the contract later phases depend on:
    • Culture: transforms use the current culture.
    • Config: JSON property names match in any case, and enums can be given by name or number.
    • Failure: a transform throws instead of returning error text. Bad config throws ArgumentException. A transform that runs but can't produce a result throws InvalidOperationException with a message fit to show the user. Cancellation throws OperationCanceledException.
  • DelegateTextTransform wraps a plain string-to-string function. DelegateTextTransform<TConfig> adds a config record. One internal reader handles config the same way for every action: unknown properties are ignored, and a missing or null required value, or a wrong JSON type, is an ArgumentException.

Registered actions: 19 IDs, pinned by tests

IDs are stored in users' layouts, workflows and button settings, so they can never be renamed. Tests fail if the list changes.

  • Core (CoreActions.RegisterAll), 13 transforms:
    • No config: trimLines, makeSingleLine, removeDuplicateLines, shuffleLines, tryMakeNumbers, tryMakeLetters, correctGuidErrors, replaceReservedCharacters (keeps the window's Ctrl+R).
    • With config: cleanUp (CorrectToLatin), unstack (Columns), unstackGroups (Rows), applyPattern (regex, mode, separator) and applyRecognizer (built-in recognizer ID, mode, separator, output).
    • All are under textgrab.text.*.
  • Core.Windows (WindowsActions.RegisterAll), 6 actions under textgrab.ai.*, all requiring a Copilot+ PC:
    • Transforms: summarize, meetingNotes, translate (TranslateConfig(TargetLanguage)) and translateToSystemLanguage.
    • Descriptors only: rewrite and convertToTable. Their services report failure by returning "ERROR: …" as the text, which a transform can't tell apart from a real result.
  • Display names are the window's menu text, and icon keys are the SymbolRegular names its bottom-bar buttons use.

Lifted out of the Edit Text Window

Characterization tests were written first, passed against the old code, and still pass unchanged:

  • Toggle Case becomes StringMethods.ToggleCase(text, state, culture), returning the new text and the next state. The window keeps CaseStatusOfToggle and its language. Spreadsheet mode calls the function once per cell, as before. Pinned by EditTextWindowToggleCaseTests (9).
  • Split Lines Before / After Each Selection become StringMethods.SplitOnSelection and SplitAfterSelection. The window keeps its empty-selection message. Pinned by EditTextWindowSplitOnSelectionTests (7).

These are not registered as transforms, because they need window state or a selection. E2 wraps them.

Not done

  • Apply grab template (step 6): ApplyTextOnlyTemplate resolves pattern placeholders through the app's settings service, and templates only load through the app-side GrabTemplateManager, so it couldn't move to Core.
  • Saved patterns by ID: applyPattern takes a regex rather than a saved-pattern ID, for the same reason. A PatternId field can be added later without breaking stored config.
  • Join Lines and Add/Remove/Limit: their functions aren't registered. They're reached only through dialogs, and one menu item covers three operations, so there's no display name to copy.

Found while wrapping, not changed

  • Toggle Case's first press re-applies the case it detects, so all-lower or all-upper text looks unchanged until the second press.
  • Title case leaves an all-capitals word as it is.
  • In Spreadsheet mode, Toggle Case never changes an all-lower or all-upper cell.
  • Rewrite and Convert to Table write "ERROR: …" into the document when Windows AI fails.
  • Apply Pattern with an invalid regex returns empty text, not an error, because that is what PatternExecutor does.
  • SummarizeParagraph takes no cancellation token.

For review

  • The 19 IDs. They are permanent once this ships. The full list, with sources, is in appendix A of the phase file.
  • Two new display names: "Apply Pattern" and "Apply Smart Pattern", because no existing menu text fits. The two unstack transforms keep the menu's "(Select Top Row)" / "(Select First Column)" text, which reads oddly in a workflow. Display names aren't stored in users' files, so these are cheap to change.

Plan corrections

The phase file's "Current state" section now records what changed:

  • E1 moved ToggleCase and the split handlers.
  • ApplyTextOnlyTemplate isn't a pure function of the template and the text: it reads settings.
  • Clean Up Text moved from step 3 to step 7, because it takes config.

Tests

Suite Before (dev @ 7de19ea) After
Tests.Core 1030 passed 1177 passed
Tests.Core.Windows 301 (4 skipped) 322 (4 skipped), 0 failed
Tests 983 (3 skipped) 1001 (3 skipped), 0 failed

The new tests by suite:

  • Tests.Core: ActionRegistryTests, CoreActionsTests (pinned IDs), DelegateTextTransformTests, CoreTextTransformTests and CoreConfigTransformTests (each transform checked against the function it wraps), ToggleCaseTests, SplitOnSelectionTests.
  • Tests.Core.Windows: WindowsActionsTests, covering pinned IDs and how each AI action fails on a device without Windows AI.
  • Tests: the two characterization suites above, a registry case in AppServicesTests, and ActionIconKeyTests, which checks that every icon key is a real SymbolRegular name.

TierBoundaryTests passes, and the build has no new compiler warnings. No NuGet packages were added, so there's nothing to check for MSIX.

One gate run had a single failure: WinRtClipboardServiceTests.RealClipboard_RoundTripsText_WithNoUiThread. It uses the real system clipboard and passed on three immediate reruns with the same binaries.

Needs checking by hand

  • Toggle Case (Shift+F3 and the menu): several presses in Text mode, with a selection, and in Spreadsheet mode. It should behave exactly as before, including the first press appearing to do nothing on all-lower text.
  • Split Lines Before / After Each Selection, from both the Selection menu and the context menu. Each should stay disabled when nothing is selected.

🤖 Generated with Claude Code

TheJoeFin and others added 11 commits November 11, 2026 19:47
Adds the step 1 appendix to the A1 work plan: the transforms A1 registers
with their IDs, display names, categories, config and icons; the functions
A1 lifts for E2 to wrap; everything that needs window state, grouped by E2
cluster; and the pure functions left unregistered, with reasons.

Also corrects the plan's current-state notes for E1's split of the window,
and records that ApplyTextOnlyTemplate reads saved patterns from settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ActionDescriptor, ITextTransform and IActionRegistry in
Text_Grab.Core.Actions, with ActionRegistry as the thread-safe default.
The registry rejects duplicate and malformed IDs (textgrab.<area>.<verb>),
compares IDs ordinally, and lists actions in registration order.

ITextTransform's remarks fix the contract later phases rely on: current
culture, case-insensitive JSON config, and failure by exception rather
than error text. CoreActions.RegisterAll is empty for now; the pinned-ID
test that guards it starts with an empty list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DelegateTextTransform wraps a string-to-string function as an
ITextTransform. CoreActions.RegisterAll now registers eight of them under
pinned IDs, with the Edit Text Window's menu text and bottom-bar icons:
trim lines, single line, remove duplicate lines, shuffle lines, try to
make numbers, try to make letters, correct GUID errors and replace
reserved characters (keeping its Ctrl+R gesture).

Each transform has a test showing it returns what the wrapped function
returns. Shuffle is random, so its test compares the lines kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pins the current behavior before A1 lifts the case logic into Core:
the first press re-applies the detected case, later presses cycle
title, upper, lower; the remembered state carries over to new text; a
selection is detected and changed on its own; the window's culture is
used; and Spreadsheet mode detects per cell and resets the state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The window's case cycle becomes a pure function of the text, the
remembered state and the culture, returning the new text and the next
state. The window keeps CaseStatusOfToggle and its culture and calls the
function; Spreadsheet mode calls it per cell with no remembered state, as
it did before.

The characterization tests from the previous commit pass unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pins Split Lines Before / After Each Selection before A1 lifts them into
Core: every occurrence of the selection is split, matching is
case-sensitive and non-overlapping from the left, and the commands do
nothing without a selection or in Spreadsheet mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SplitOnSelection and SplitAfterSelection are pure functions of the full
text and the selection. The window's two command handlers keep their
empty-selection message and call them. They are not registered as
transforms because they need a selection; E2 wraps them.

The characterization tests from the previous commit pass unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DelegateTextTransform<TConfig> reads an action's JSON config into its
config record. Reading is the same for every action: property names in
any case, enums by name or number, unknown properties ignored; a missing
or null required value, or a wrong JSON type, is an ArgumentException.

Five transforms join the pinned list: clean up text (CorrectToLatin,
default off), unstack (Columns), unstack groups (Rows), apply pattern
(a regex, mode and separator) and apply smart pattern (a built-in
recognizer ID, mode, separator and output). Each matches the function it
wraps; counts below 1, empty patterns and unknown recognizers throw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
WindowsActions.RegisterAll adds six AI actions, all needing a Copilot+
PC: summarize, meeting notes, translate (TranslateConfig carries the
target language) and translate to system language as transforms, and
rewrite and convert to table as descriptors only. Those two services
return failures as "ERROR: ..." text, which a transform cannot tell from
a result.

The transforms throw InvalidOperationException with the service's own
message when Windows AI cannot produce a result, using the window's
fallback wording when there is none. Translation that is not needed
returns the input unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The container builds one IActionRegistry, filled from CoreActions and
WindowsActions on first resolve, so the app and lower tiers (through
ServiceAccess) share it. Nothing in the UI reads it yet.

Tests check it resolves as one instance with every Core and Core.Windows
action, and that every icon key names a Wpf.Ui SymbolRegular member.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The A1 status row is Done. The phase file gets an A1 outcome section:
the types as built and where they differ from the sketch, the step 6
and step 8 outcomes, the two new display names, behavior found while
wrapping and left alone, and the tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@TheJoeFin
TheJoeFin merged commit fdba7ec into dev Nov 12, 2026
1 check passed
@TheJoeFin
TheJoeFin deleted the v5/a1-action-registry branch November 12, 2026 03:49
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.

1 participant