-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add atomic release operations and trusted PR dev #335
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
42a96cf
feat: add managed release controls
mira-2026 ec15c01
feat: add atomic release operations and trusted PR dev
mira-2026 3b5ac6a
fix: close dev config file race
mira-2026 2f1327d
fix: harden trusted dev boundaries
mira-2026 42bbbed
fix: harden release and PR dev lifecycle
mira-2026 98eec53
fix: address release and PR dev reviews
mira-2026 19a5a9d
fix: close final PR dev review gaps
mira-2026 e713b44
fix: repair managed PR dev runtime regressions
mira-2026 88f539c
fix: close PR dev review findings
mira-2026 af4b8fc
fix: address final PR dev review findings
mira-2026 cb92bc2
fix: address automated review nitpicks
mira-2026 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
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,228 @@ | ||
| import { | ||
| chmodSync, | ||
| cpSync, | ||
| lstatSync, | ||
| mkdirSync, | ||
| readFileSync, | ||
| renameSync, | ||
| rmSync, | ||
| writeFileSync, | ||
| } from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| const MAX_OPENCLAW_CONFIG_BYTES = 2 * 1024 * 1024; | ||
| const OMITTED_WORKSPACE_DIRECTORIES = new Set([ | ||
| ".aws", | ||
| ".azure", | ||
| ".credentials", | ||
| ".git", | ||
| ".gnupg", | ||
| ".secrets", | ||
| ".ssh", | ||
| "credentials", | ||
| "secrets", | ||
| ]); | ||
| const SAFE_ENVIRONMENT_TEMPLATE_SUFFIXES = new Set(["example", "sample", "template"]); | ||
| const SENSITIVE_WORKSPACE_FILE_NAMES = new Set([ | ||
| ".env", | ||
| "credentials.json", | ||
| "id_ed25519", | ||
| "id_rsa", | ||
| "private.key", | ||
| "secrets.json", | ||
| "secrets.yaml", | ||
| "secrets.yml", | ||
| ]); | ||
| const SENSITIVE_AGENT_CONFIG_KEY = | ||
| /(?:^|[._-])(?:api[._-]?key|credential|credentials|password|secret|secrets|token)(?:$|[._-])/iu; | ||
|
|
||
| export type DevelopmentWorkspaceState = "copied" | "empty" | "reused"; | ||
|
|
||
| export interface DevelopmentOpenClawSnapshotConfig { | ||
| configSource?: string; | ||
| openClawHome: string; | ||
| workspaceSource?: string; | ||
| } | ||
|
|
||
| function isRealDirectory(directoryPath: string): boolean { | ||
| try { | ||
| const stat = lstatSync(directoryPath); | ||
| return stat.isDirectory() && !stat.isSymbolicLink(); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function isRealRegularFile(filePath: string): boolean { | ||
| try { | ||
| const stat = lstatSync(filePath); | ||
| return stat.isFile() && !stat.isSymbolicLink(); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function ensurePrivateDirectory(directoryPath: string): void { | ||
| mkdirSync(directoryPath, { mode: 0o700, recursive: true }); | ||
| if (!isRealDirectory(directoryPath)) { | ||
| throw new Error(`Development path must be a real directory: ${directoryPath}`); | ||
| } | ||
| chmodSync(directoryPath, 0o700); | ||
| } | ||
|
|
||
| function writePrivateJson(filePath: string, value: unknown): void { | ||
| const stagingPath = `${filePath}.partial-${Bun.randomUUIDv7()}`; | ||
| try { | ||
| writeFileSync(stagingPath, `${JSON.stringify(value, undefined, 2)}\n`, { | ||
| encoding: "utf8", | ||
| mode: 0o600, | ||
| }); | ||
| renameSync(stagingPath, filePath); | ||
| } catch (error) { | ||
| rmSync(stagingPath, { force: true }); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| function defaultAgentsConfig(openClawHome: string) { | ||
| return { | ||
| defaults: { | ||
| model: { primary: "unknown" }, | ||
| models: {}, | ||
| workspace: path.join(openClawHome, "workspace"), | ||
| }, | ||
| list: [{ default: true, id: "main" }], | ||
| }; | ||
| } | ||
|
|
||
| function sanitizedAgentConfigValue(value: unknown, openClawHome: string): unknown { | ||
| if (Array.isArray(value)) { | ||
| return value.map((item) => sanitizedAgentConfigValue(item, openClawHome)); | ||
| } | ||
| if (!value || typeof value !== "object") { | ||
| return value; | ||
| } | ||
| const sanitized: Record<string, unknown> = {}; | ||
| for (const [key, child] of Object.entries(value)) { | ||
| const normalizedKey = key.replaceAll(/([a-z\d])([A-Z])/gu, "$1_$2"); | ||
| if (SENSITIVE_AGENT_CONFIG_KEY.test(normalizedKey)) { | ||
| continue; | ||
| } | ||
| sanitized[key] = | ||
| key === "workspace" | ||
| ? path.join(openClawHome, "workspace") | ||
| : sanitizedAgentConfigValue(child, openClawHome); | ||
| } | ||
| return sanitized; | ||
| } | ||
|
|
||
| function snapshotAgentsConfig(config: DevelopmentOpenClawSnapshotConfig): unknown { | ||
| if (!config.configSource) { | ||
| return defaultAgentsConfig(config.openClawHome); | ||
| } | ||
| if (!isRealRegularFile(config.configSource)) { | ||
| throw new Error( | ||
| `MIRA_DASHBOARD_DEV_OPENCLAW_CONFIG_SOURCE must be a real regular file: ${config.configSource}` | ||
| ); | ||
| } | ||
| const stat = lstatSync(config.configSource); | ||
| if (stat.size > MAX_OPENCLAW_CONFIG_BYTES) { | ||
| throw new Error("Development OpenClaw config source is too large"); | ||
| } | ||
| const parsed = Bun.JSON5.parse(readFileSync(config.configSource, "utf8")) as { | ||
|
mira-2026 marked this conversation as resolved.
Fixed
|
||
| agents?: unknown; | ||
| }; | ||
| if (!parsed.agents || typeof parsed.agents !== "object") { | ||
| return defaultAgentsConfig(config.openClawHome); | ||
| } | ||
| return sanitizedAgentConfigValue(parsed.agents, config.openClawHome); | ||
| } | ||
|
|
||
| function isEnvironmentTemplate(fileName: string): boolean { | ||
| if (!fileName.startsWith(".env.")) return false; | ||
| const suffix = fileName.slice(".env.".length).toLowerCase(); | ||
| return SAFE_ENVIRONMENT_TEMPLATE_SUFFIXES.has(suffix); | ||
| } | ||
|
|
||
| function shouldCopyWorkspacePath(sourceRoot: string, candidate: string): boolean { | ||
| const relativePath = path.relative(sourceRoot, candidate); | ||
| if (!relativePath) return true; | ||
| const segments = relativePath.split(path.sep); | ||
| if ( | ||
| segments.some((segment) => | ||
| OMITTED_WORKSPACE_DIRECTORIES.has(segment.toLowerCase()) | ||
| ) | ||
| ) { | ||
| return false; | ||
| } | ||
| const fileName = segments.at(-1)?.toLowerCase() || ""; | ||
| return !( | ||
| SENSITIVE_WORKSPACE_FILE_NAMES.has(fileName) || | ||
| (fileName.startsWith(".env.") && !isEnvironmentTemplate(fileName)) || | ||
| fileName.endsWith(".token") || | ||
| fileName.endsWith(".secret") | ||
|
mira-2026 marked this conversation as resolved.
|
||
| ); | ||
| } | ||
|
|
||
| function copyWorkspaceSnapshot(sourcePath: string, targetPath: string): void { | ||
| if (!isRealDirectory(sourcePath)) { | ||
| throw new Error( | ||
| `MIRA_DASHBOARD_DEV_WORKSPACE_SOURCE must be a real directory: ${sourcePath}` | ||
| ); | ||
| } | ||
| if (path.resolve(sourcePath) === path.resolve(targetPath)) { | ||
| throw new Error("Development workspace source and target must be distinct"); | ||
| } | ||
| const stagingPath = `${targetPath}.partial-${Bun.randomUUIDv7()}`; | ||
| try { | ||
| cpSync(sourcePath, stagingPath, { | ||
| errorOnExist: true, | ||
| filter(source) { | ||
| const stat = lstatSync(source); | ||
| if (stat.isSymbolicLink()) { | ||
| throw new Error( | ||
| `Development workspace source contains a symlink: ${source}` | ||
| ); | ||
| } | ||
| return shouldCopyWorkspacePath(sourcePath, source); | ||
| }, | ||
| force: false, | ||
| preserveTimestamps: true, | ||
| recursive: true, | ||
| }); | ||
| renameSync(stagingPath, targetPath); | ||
| } catch (error) { | ||
| rmSync(stagingPath, { force: true, recursive: true }); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| /** Creates a writable workspace snapshot and a secret-free agent config for dev. */ | ||
| export function prepareDevelopmentOpenClawSnapshot( | ||
| config: DevelopmentOpenClawSnapshotConfig | ||
| ): DevelopmentWorkspaceState { | ||
| ensurePrivateDirectory(config.openClawHome); | ||
| ensurePrivateDirectory(path.join(config.openClawHome, "agents")); | ||
| const targetWorkspace = path.join(config.openClawHome, "workspace"); | ||
| let workspaceState: DevelopmentWorkspaceState; | ||
| if (isRealDirectory(targetWorkspace)) { | ||
| workspaceState = "reused"; | ||
| } else if (config.workspaceSource) { | ||
| copyWorkspaceSnapshot(config.workspaceSource, targetWorkspace); | ||
| workspaceState = "copied"; | ||
| } else { | ||
| ensurePrivateDirectory(targetWorkspace); | ||
| workspaceState = "empty"; | ||
| } | ||
| chmodSync(targetWorkspace, 0o700); | ||
|
|
||
| const visibleConfigPath = path.join(config.openClawHome, "openclaw.json"); | ||
| if (isRealRegularFile(visibleConfigPath)) { | ||
| chmodSync(visibleConfigPath, 0o600); | ||
| } else { | ||
| writePrivateJson(visibleConfigPath, { | ||
| agents: snapshotAgentsConfig(config), | ||
| }); | ||
| } | ||
| return workspaceState; | ||
| } | ||
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.