Skip to content

Add order to SMARTBLOCK#131

Merged
mdroidian merged 4 commits into
mainfrom
codex/add-order-as-sbbomb-param-for-%smartblock%-command
Jul 21, 2025
Merged

Add order to SMARTBLOCK#131
mdroidian merged 4 commits into
mainfrom
codex/add-order-as-sbbomb-param-for-%smartblock%-command

Conversation

@mdroidian

@mdroidian mdroidian commented Jul 6, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • allow passing an order to sbBomb when running SMARTBLOCKs
  • update SMARTBLOCK command docs with optional order parameter
  • update SMARTBLOCK handler to accept order as third parameter

Testing

  • npm test (fails: samepage not found)

https://chatgpt.com/codex/tasks/task_e_6869c48c140c8326a8f5dd83cc22ccb3

Summary by CodeRabbit

  • New Features

    • Added support for specifying the insertion order of new blocks when using the SMARTBLOCK command remotely.
  • Documentation

    • Updated documentation for the SMARTBLOCK command to describe the new optional order parameter and provided multiple usage examples.

@coderabbitai

coderabbitai Bot commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

The SMARTBLOCK command was updated to support an optional third parameter for specifying the insertion order of new blocks when executed remotely. Documentation was revised to describe this new parameter and provide usage examples. The command handler and related logic were updated to parse and apply the order argument, and type definitions were extended accordingly.

Changes

File(s) Change Summary
docs/050-command-reference.md Extended SMARTBLOCK command documentation with a new optional order parameter and multiple usage examples.
src/utils/core.ts Enhanced SMARTBLOCK handler to parse optional order argument; expanded sbBomb target type with order; adjusted block insertion logic to respect the order value.
package.json Bumped version from 1.9.1 to 1.10.0 without other changes.

Possibly related PRs

  • Add order to SMARTBLOCK #131: Also modifies the SMARTBLOCK command handler and sbBomb function to support an optional order parameter for block insertion, making it directly related.

Estimated code review effort

2 (45 minutes)

Poem

A rabbit hops with code so bright,
SMARTBLOCKS now can set their height!
With order placed, blocks find their way,
In docs and code, it's clear as day.
🐇✨
New features bloom, as changes flow—
The garden of logic continues to grow!


📜 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 028b492 and b63058a.

⛔ 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/utils/core.ts (5 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
docs/050-command-reference.md (1)

1101-1108: Clarify index semantics & default behavior of the new “order” parameter

The docs introduce the order argument but omit two critical details:

  1. Whether the index is 0-based (0 = top) or 1-based (1 = top).
  2. What happens when the value is greater than the current block count or omitted entirely (fallback to append?).

Ambiguity here will lead to off-by-one errors and inconsistent usage across workflows. Please tighten the wording, e.g.:

-3. When the second parameter is set, you may optionally pass a number to specify the order of the new block on that page.
+3. (Optional) **Order** – zero-based index of the position to insert the new block on the target page.  
+   • `0` inserts at the top, `1` after the first block, etc.  
+   • If the index ≥ current block count, the block is appended at the bottom.  
+   • If omitted, the block is appended by default.

And mirror this clarification in the example:

-<%SMARTBLOCK:Daily,Some Page,2%>
+<%SMARTBLOCK:Daily,Some Page,2%>   <!-- inserts as the third block -->

This keeps the reference unambiguous and aligned with the implementation in sbBomb.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7119529 and 994ee82.

📒 Files selected for processing (2)
  • docs/050-command-reference.md (1 hunks)
  • src/utils/core.ts (4 hunks)
🔇 Additional comments (3)
src/utils/core.ts (3)

1769-1769: Documentation update looks good.

The help text clearly describes the new optional order parameter and follows the established documentation pattern.


1794-1798: Target parameter construction looks correct.

The conditional inclusion of the order property using the spread operator is well-implemented and maintains clean object structure.


2658-2658: Order implementation in sbBomb is well-structured.

The optional order parameter is properly handled with appropriate fallbacks and type checking. The logic correctly uses the provided order when available while maintaining existing behavior as the default.

Also applies to: 2670-2670, 2706-2708

Comment thread src/utils/core.ts Outdated
… parameter in the format `order=value`. Update examples to reflect new usage and improve argument parsing for page names and order specification.
@mdroidian

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit full review

@coderabbitai

coderabbitai Bot commented Jul 21, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
src/utils/core.ts (1)

1770-1851: Improve parameter parsing robustness and add validation.

While the variadic arguments approach maintains backward compatibility, the parameter parsing logic has several areas for improvement:

  1. Fragile order detection: Line 1787 uses lastArg.includes("=") which could incorrectly match page names containing "="
  2. Missing order validation: No validation that the order value is a valid number or "last"
  3. Assumption about space separation: Line 1790 joins with spaces, which may not be the original format

Consider this more robust approach:

-          // Multiple arguments - last one might be order=value
-          const lastArg = pageNameOrUid[pageNameOrUid.length - 1];
-          if (lastArg.includes("=")) {
-            // Last argument is order=value, rest is page name
-            const orderValue = lastArg.split("=")[1];
-            title = extractTag(pageNameOrUid.slice(0, -1).join(" "));
-            order =
-              orderValue.toLowerCase() === "last"
-                ? "last"
-                : Number(orderValue);
-          } else {
-            // All arguments are page name
-            title = extractTag(pageNameOrUid.join(" "));
-          }
+          // More robust order parsing
+          const lastArg = pageNameOrUid[pageNameOrUid.length - 1];
+          const orderMatch = /^order=(.+)$/i.exec(lastArg);
+          
+          if (orderMatch) {
+            const orderValue = orderMatch[1];
+            title = extractTag(pageNameOrUid.slice(0, -1).join(","));
+            
+            if (orderValue.toLowerCase() === "last") {
+              order = "last";
+            } else {
+              const numOrder = Number(orderValue);
+              if (!isNaN(numOrder) && Number.isInteger(numOrder) && numOrder >= 0) {
+                order = numOrder;
+              } else {
+                // Invalid order value, treat as part of page name
+                title = extractTag(pageNameOrUid.join(","));
+              }
+            }
+          } else {
+            title = extractTag(pageNameOrUid.join(","));
+          }
🧹 Nitpick comments (2)
docs/050-command-reference.md (2)

1101-1102: Clarify when order= is valid
The sentence implies the order= parameter is only permitted when a page name (second parameter) is present.
However, one of the examples below shows order= being used while the page parameter is intentionally left blank (line 1109 – <%SMARTBLOCK:MyWorkflow,,order=3%>). Please tighten the wording or update the example so that the documented rule and examples do not contradict each other.


1105-1110: Example set has internal inconsistencies

  1. Line 1109 demonstrates an empty page parameter followed by order=3, which conflicts with the rule above.
  2. Line 1108 uses a raw UID V_MTxadSW while line 1107 encloses the same UID in double-parens. Calling out the semantic difference (page UID vs block UID) in a short comment would prevent reader confusion.
  3. Consider adding an explicit numeric order example other than 0 (e.g. order=2) and making it clear that indices are zero-based.

A concise, self-contained example list might look like:

- `<%SMARTBLOCK:MyWorkflow%>`                           <!-- run in-place -->
- `<%SMARTBLOCK:MyWorkflow,Some Page%>`                 <!-- run on page -->
- `<%SMARTBLOCK:MyWorkflow,Some Page,order=last%>`      <!-- append -->
- `<%SMARTBLOCK:MyWorkflow,Some Page,order=2%>`         <!-- 3rd position -->

This both removes the contradictory empty parameter case and highlights practical usages.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7119529 and 028b492.

📒 Files selected for processing (2)
  • docs/050-command-reference.md (1 hunks)
  • src/utils/core.ts (5 hunks)
🔇 Additional comments (4)
src/utils/core.ts (4)

1769-1769: LGTM! Clear documentation for the new order parameter.

The help text effectively documents the new optional order parameter with clear usage instructions and format specification.


2675-2675: LGTM! Well-defined type for the order parameter.

The optional order?: number | "last" property correctly represents the new functionality while maintaining backward compatibility.

Also applies to: 2687-2687


2722-2725: LGTM! Correct logic for determining starting order.

The conditional logic properly handles explicit order values while maintaining backward compatibility with the default behavior.


2767-2770: LGTM! Proper handling of subsequent block ordering.

The logic correctly handles both "last" and numeric order values for creating multiple blocks in the proper sequence.

…gument parsing. Use regex for order extraction and validate numeric values, ensuring robust title extraction from page names.
@mdroidian
mdroidian merged commit 4983f74 into main Jul 21, 2025
1 of 2 checks passed
@mdroidian
mdroidian deleted the codex/add-order-as-sbbomb-param-for-%smartblock%-command branch July 21, 2025 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant