Skip to content

Conversation

@mdroidian
Copy link
Collaborator

@mdroidian mdroidian commented Oct 19, 2025

Summary by CodeRabbit

  • New Features

    • Tag workflows with <%CMD%> to expose them in the Command Palette.
    • Added a Command Palette opt-in setting to control which workflows appear.
    • New "Refresh SmartBlocks Command Palette" command to update the list after tagging workflows.
  • Documentation

    • Added CMD modifier docs and usage guidance.
    • Expanded Command Palette setup with refresh steps.
  • Chore

    • Package version bumped to 1.12.0.

- Added support for a new <%CMD%> tag to opt specific workflows into the Roam command palette.
- Updated documentation to reflect the new command palette opt-in feature and usage instructions.
- Implemented functionality to refresh command palette workflows after changes to the <%CMD%> tag.
- Refactored command palette command management in the code for better clarity and performance.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 19, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Workflows can opt into Roam's Command Palette by tagging titles with <%CMD%> and enabling a new Command Palette Opt‑In setting. Implementation adds command lifecycle helpers, a refresh command, regex-based detection/cleaning, docs updates, and a package version bump.

Changes

Cohort / File(s) Summary
Documentation
docs/050-command-reference.md, docs/060-alternative-methods.md
Added CMD workflow modifier docs, instructions to tag workflows with <%CMD%>, guidance for enabling the Command Palette Opt‑In, and a "Refreshing Command Palette Workflows" subsection describing refresh steps.
Command Palette Core
src/index.ts
Added command palette state and opt‑in UI setting; introduced removeCommandPaletteCommands, addCommandPaletteCommands, syncCommandPaletteCommands, and toggleCommandPalette; initialized state from settings; added a "Refresh SmartBlocks Command Palette" command and integrated CMD modifier handling into command help/trigger flow.
Workflow Utilities
src/utils/core.ts
Exported COMMAND_PALETTE_REGEX and global regex variants; updated getVisibleCustomWorkflows to include commandPaletteEligible and strip HIDE/CMD tags globally; updated getCleanCustomWorkflows to use a global tag‑removal regex.
Metadata
package.json
Bumped package version from 1.11.0 to 1.12.0.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant SettingsUI as Settings UI
    participant Sync as syncCommandPaletteCommands()
    participant RoamCP as Roam Command Palette

    User->>SettingsUI: Toggle "Command Palette Opt‑In"
    SettingsUI->>Sync: Trigger syncCommandPaletteCommands()
    Sync->>Sync: removeCommandPaletteCommands()
    Sync->>RoamCP: Clear existing commands
    alt commandPaletteEnabled
        Sync->>Sync: addCommandPaletteCommands() (filter by opt‑in & eligibility)
        Sync->>RoamCP: Register tagged workflows
    end
    RoamCP->>User: Updated command palette
Loading
sequenceDiagram
    actor User
    participant Palette as Command Palette
    participant RefreshCmd as "Refresh SmartBlocks" Command
    participant Sync as syncCommandPaletteCommands()
    participant Toast as Toast

    User->>Palette: Invoke "Refresh SmartBlocks Command Palette"
    Palette->>RefreshCmd: Execute
    RefreshCmd->>Sync: Call syncCommandPaletteCommands()
    Sync->>Palette: Re-synchronize commands
    RefreshCmd->>Toast: Show confirmation
    Toast->>User: Display success
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

codex

Poem

🐇 I tagged my flow with <%CMD%> bright,
A tiny hop, a palette light.
I press refresh and watch them show,
Opt‑in blooms — my workflows glow. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat: enhance command palette integration for SmartBlocks" accurately reflects the main objective of this changeset. The modifications across all files—documentation updates introducing CMD modifier guidance, core implementation of a modular command palette management system with opt-in capability, utility functions updated to detect and handle CMD tags, and a version bump—collectively work toward enhancing how SmartBlocks workflows integrate with Roam's command palette. The title is concise, clear, and specific enough that a developer scanning the repository history would immediately understand the primary purpose of these changes without confusion.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0831732 and 3e674ef.

📒 Files selected for processing (1)
  • src/index.ts (6 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mdroidian mdroidian merged commit a9579bb into main Oct 19, 2025
1 of 2 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/index.ts (3)

131-174: De‑duplicate labels and record them for reliable removal.

Multiple workflows with the same cleaned name will collide on a single label. Also, add each label to the tracking set you introduced so removeCommandPaletteCommands can clean them up.

Apply:

   const addCommandPaletteCommands = () => {
     const eligibleWorkflows = getVisibleCustomWorkflows().filter((wf) =>
       commandPaletteOptIn ? wf.commandPaletteEligible : true
     );
-    getCleanCustomWorkflows(eligibleWorkflows).forEach((wf) => {
-      window.roamAlphaAPI.ui.commandPalette.addCommand({
-        label: `Trigger SmartBlock: ${wf.name}`,
+    const labelsThisSync = new Set<string>();
+    getCleanCustomWorkflows(eligibleWorkflows).forEach((wf) => {
+      const base = `Trigger SmartBlock: ${wf.name}`;
+      let label = base;
+      let i = 2;
+      while (labelsThisSync.has(label)) label = `${base} (${i++})`;
+      window.roamAlphaAPI.ui.commandPalette.addCommand({
+        label,
         callback: () => {
           const targetUid =
             window.roamAlphaAPI.ui.getFocusedBlock()?.["block-uid"];
           // Because the command palette does a blur event on close,
           // we want a slight delay so that we could keep focus
           window.setTimeout(() => {
             if (targetUid) {
               sbBomb({
                 srcUid: wf.uid,
                 target: {
                   uid: targetUid,
                   isParent: false,
                   start: getTextByBlockUid(targetUid).length,
                 },
                 mutableCursor: true,
               });
             } else {
               window.roamAlphaAPI.ui.mainWindow
                 .getOpenPageOrBlockUid()
                 .then((uid) =>
                   sbBomb({
                     srcUid: wf.uid,
                     target: {
                       uid:
                         uid ||
                         window.roamAlphaAPI.util.dateToPageUid(new Date()),
                       isParent: true,
                     },
                     mutableCursor: true,
                   })
                 );
             }
           }, 500);
         },
       });
+      labelsThisSync.add(label);
+      registeredCommandLabels.add(label);
     });
   };

Optional: consider extracting the 500 ms delay into a named constant for readability.


555-569: Refresh command is useful; suggest guarding for API availability.

Minor: add a defensive check so older Roam builds or test environments without ui.commandPalette don’t throw.

Example:

-  window.roamAlphaAPI.ui.commandPalette.addCommand({
+  if (window.roamAlphaAPI.ui?.commandPalette) {
+    window.roamAlphaAPI.ui.commandPalette.addCommand({
       label: REFRESH_SMARTBLOCKS_COMMAND_LABEL,
       callback: () => {
         syncCommandPaletteCommands();
         renderToast({
           id: "smartblocks-command-palette-refresh",
           intent: Intent.SUCCESS,
           content: "Command palette workflows refreshed",
           timeout: 2000,
         });
       },
-  });
+    });
+  }

947-950: Also remove dynamic palette commands on unload.

Static commands are removed via the commands array, but dynamic ones won’t be unless you call your remover in unload.

Apply:

   unload: () => {
+      removeCommandPaletteCommands();
       unloads.forEach((u) => u());
       window.clearTimeout(getDailyConfig()["next-run-timeout"]);
       saveDailyConfig({ "next-run-timeout": 0 });
     },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f63c52 and 0831732.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/index.ts (6 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.ts (1)
src/utils/core.ts (3)
  • getCleanCustomWorkflows (356-360)
  • getVisibleCustomWorkflows (341-354)
  • sbBomb (2694-2867)
🔇 Additional comments (5)
src/index.ts (5)

176-181: Sync helper reads clearly and is side‑effect free. LGTM.


183-187: Toggle wiring looks good.


217-229: Opt‑in setting UI/handler looks correct.

Switch updates state and triggers a sync as expected.

Please confirm the settings panel persists the “command-palette-opt-in” value automatically (consistent with other switches in this file).


293-295: Good: initialize from saved setting and immediately sync.


433-437: Nice addition: CMD workflow modifier surfaced in cursor menu help.

Consistent with the opt‑in behavior.

@mdroidian mdroidian deleted the add-opt-in-flag-for-cmd-palette-workflows branch October 28, 2025 07:28
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