View remote rules and workflows in the editor (#7702)

* allow the user to view remote rules and workflows in the editor by creating a temp file

* add await
This commit is contained in:
celestial-vault authored and GitHub committed 2025-11-27 11:37:47 -06:00
1 parent 06585821d1
commit 2a20523e16
5 files changed
+65 -15

No files matched your search

+50 -2
View File
@@ -1,16 +1,64 @@
import { StateManager } from "@core/storage/StateManager"
import { openFile as openFileIntegration } from "@integrations/misc/open-file"
import { Empty, StringRequest } from "@shared/proto/cline/common"
import { REMOTE_URI_SCHEME } from "@shared/remote-config/constants"
import { writeFile } from "@utils/fs"
import * as os from "os"
import * as path from "path"
import { Controller } from ".."
/**
* Opens a file in the editor
* @param controller The controller instance
* @param request The request message containing the file path in the 'value' field
* @param request The request message containing the file path in the 'value' field.
* Supports special URI format for remote rules/workflows:
* - remote://rule/{ruleName}
* - remote://workflow/{workflowName}
* @returns Empty response
*/
export async function openFile(_controller: Controller, request: StringRequest): Promise<Empty> {
if (request.value) {
openFileIntegration(request.value)
// Check for remote:// prefix for remote rules/workflows
if (request.value.startsWith(REMOTE_URI_SCHEME)) {
await openRemoteFile(request.value)
} else {
await openFileIntegration(request.value)
}
}
return Empty.create()
}
/**
* Opens a remote rule or workflow file by creating a temp file with its contents
* @param uri The remote URI in format: remote://rule/{name} or remote://workflow/{name}
*/
async function openRemoteFile(uri: string): Promise<void> {
// Parse: remote://rule/{name} or remote://workflow/{name}
const match = uri.match(/^remote:\/\/(rule|workflow)\/(.+)$/)
if (!match) {
throw new Error(`Invalid remote file URI: ${uri}`)
}
const [, type, name] = match
const remoteConfig = StateManager.get().getRemoteConfigSettings()
// Look up content based on type
const items = type === "rule" ? remoteConfig.remoteGlobalRules : remoteConfig.remoteGlobalWorkflows
const item = items?.find((r) => r.name === name)
if (!item?.contents) {
throw new Error(`Remote ${type} not found: ${name}`)
}
// Create temp file with read-only header comment
const typeLabel = type === "rule" ? "rule" : "workflow"
const header = `# ⚠️ READ-ONLY: This ${typeLabel} is managed by your organization.\n# Changes made here will not be saved.\n\n`
const content = header + item.contents
// Sanitize the name for use in filename (replace invalid characters)
const sanitizedName = name.replace(/[<>:"/\\|?*]/g, "_")
const tempPath = path.join(os.tmpdir(), `cline-remote-${type}-${sanitizedName}.md`)
await writeFile(tempPath, content)
await openFileIntegration(tempPath)
}
+5
View File
@@ -0,0 +1,5 @@
/**
* URI scheme for opening remote rules/workflows in the editor.
* Used to construct URIs like: remote://rule/{name} or remote://workflow/{name}
*/
export const REMOTE_URI_SCHEME = "remote://"
-1
View File
@@ -1 +0,0 @@
export * from "./schema"
@@ -1,10 +1,10 @@
import { StringRequest } from "@shared/proto/cline/common"
import { RuleFileRequest } from "@shared/proto/index.cline"
import { InfoIcon, PenIcon, Trash2Icon } from "lucide-react"
import { REMOTE_URI_SCHEME } from "@shared/remote-config/constants"
import { EyeIcon, InfoIcon, PenIcon, Trash2Icon } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Switch } from "@/components/ui/switch"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { cn } from "@/lib/utils"
import { FileServiceClient } from "@/services/grpc-client"
const RuleRow: React.FC<{
@@ -81,7 +81,9 @@ const RuleRow: React.FC<{
}
const handleEditClick = () => {
FileServiceClient.openFile(StringRequest.create({ value: rulePath })).catch((err) =>
// For remote rules, use the special remote:// URI format
const filePath = isRemote ? `${REMOTE_URI_SCHEME}${ruleType === "workflow" ? "workflow" : "rule"}/${rulePath}` : rulePath
FileServiceClient.openFile(StringRequest.create({ value: filePath })).catch((err) =>
console.error("Failed to open file:", err),
)
}
@@ -98,10 +100,7 @@ const RuleRow: React.FC<{
return (
<div className="mb-2.5">
<div
className={cn("flex items-center px-2 py-4 rounded bg-text-block-background max-h-4", {
"opacity-60": isDisabled,
})}>
<div className="flex items-center px-2 py-4 rounded bg-text-block-background max-h-4">
<span className="flex-1 overflow-hidden break-all whitespace-normal flex items-center mr-1" title={rulePath}>
{getRuleTypeIcon() && <span className="mr-1.5">{getRuleTypeIcon()}</span>}
<span className="ph-no-capture">{finalDisplayName}</span>
@@ -128,13 +127,12 @@ const RuleRow: React.FC<{
title={isDisabled ? "This rule is required and cannot be disabled" : undefined}
/>
<Button
aria-label="Edit rule file"
disabled={isRemote}
aria-label={isRemote ? "View rule file" : "Edit rule file"}
onClick={handleEditClick}
size="xs"
title="Edit rule file"
title={isRemote ? "View rule file (read-only)" : "Edit rule file"}
variant="icon">
<PenIcon />
{isRemote ? <EyeIcon /> : <PenIcon />}
</Button>
<Button
aria-label="Delete rule file"
+1 -1
View File
@@ -4,7 +4,7 @@ import * as React from "react"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 cursor-pointer [&_svg]:size-2",
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 cursor-pointer [&_svg]:size-2",
{
variants: {
variant: {