开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

长路/openclaw

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (939)
标签 (94)
main
codex/matrix-approval-reactions
codex/plan-plugin-boundaries
codex/approval-error-dedupe
fix/android-talk-speak
feat/whatsapp-reply-quoting
vk/allow-private-network-migration
vk/allow-private-network-audit
workspace/taskflow-webhooks
fix/minimax-pricing
fix/minimax-coding-plan-remaining-count
refactor/provider-request-cleanup-2
pr-60556
codex/prompt-cache-ci-lane
steipete/telegram-model-list-regression
cache/image-prune-lazy
cache/context-guard-reverse
dependabot/swift/apps/macos/swift-deps-81e14130ac
codex/pr-template-root-cause-trim
fix/matrix-semantic-loop-judge
v2026.4.2
v2026.4.1
v2026.4.1-beta.1
v2026.3.31
v2026.3.31-beta.1
v2026.3.28
v2026.3.28-beta.1
v2026.3.24
v2026.3.24-beta.2
v2026.3.24-beta.1
v2026.3.23-2
v2026.3.23
v2026.3.23-beta.1
v2026.3.22
v2026.3.22-beta.1
v2026.3.13-1
v2026.3.13-beta.1
v2026.3.12
v2026.3.11
v2026.3.11-beta.1
main
分支 (939)
标签 (94)
main
codex/matrix-approval-reactions
codex/plan-plugin-boundaries
codex/approval-error-dedupe
fix/android-talk-speak
feat/whatsapp-reply-quoting
vk/allow-private-network-migration
vk/allow-private-network-audit
workspace/taskflow-webhooks
fix/minimax-pricing
fix/minimax-coding-plan-remaining-count
refactor/provider-request-cleanup-2
pr-60556
codex/prompt-cache-ci-lane
steipete/telegram-model-list-regression
cache/image-prune-lazy
cache/context-guard-reverse
dependabot/swift/apps/macos/swift-deps-81e14130ac
codex/pr-template-root-cause-trim
fix/matrix-semantic-loop-judge
v2026.4.2
v2026.4.1
v2026.4.1-beta.1
v2026.3.31
v2026.3.31-beta.1
v2026.3.28
v2026.3.28-beta.1
v2026.3.24
v2026.3.24-beta.2
v2026.3.24-beta.1
v2026.3.23-2
v2026.3.23
v2026.3.23-beta.1
v2026.3.22
v2026.3.22-beta.1
v2026.3.13-1
v2026.3.13-beta.1
v2026.3.12
v2026.3.11
v2026.3.11-beta.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (939)
标签 (94)
main
codex/matrix-approval-reactions
codex/plan-plugin-boundaries
codex/approval-error-dedupe
fix/android-talk-speak
feat/whatsapp-reply-quoting
vk/allow-private-network-migration
vk/allow-private-network-audit
workspace/taskflow-webhooks
fix/minimax-pricing
fix/minimax-coding-plan-remaining-count
refactor/provider-request-cleanup-2
pr-60556
codex/prompt-cache-ci-lane
steipete/telegram-model-list-regression
cache/image-prune-lazy
cache/context-guard-reverse
dependabot/swift/apps/macos/swift-deps-81e14130ac
codex/pr-template-root-cause-trim
fix/matrix-semantic-loop-judge
v2026.4.2
v2026.4.1
v2026.4.1-beta.1
v2026.3.31
v2026.3.31-beta.1
v2026.3.28
v2026.3.28-beta.1
v2026.3.24
v2026.3.24-beta.2
v2026.3.24-beta.1
v2026.3.23-2
v2026.3.23
v2026.3.23-beta.1
v2026.3.22
v2026.3.22-beta.1
v2026.3.13-1
v2026.3.13-beta.1
v2026.3.12
v2026.3.11
v2026.3.11-beta.1
openclaw
/
src
/
utils.ts
openclaw
/
src
/
utils.ts
utils.ts 5.33 KB
一键复制 编辑 原始数据 按行查看 历史
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import {
resolveEffectiveHomeDir,
resolveHomeRelativePath,
resolveRequiredHomeDir,
} from "./infra/home-dir.js";
import { isPlainObject } from "./infra/plain-object.js";
import { formatTerminalLink } from "./terminal/terminal-link.js";
export async function ensureDir(dir: string) {
await fs.promises.mkdir(dir, { recursive: true });
}
/**
* Check if a file or directory exists at the given path.
*/
export async function pathExists(targetPath: string): Promise<boolean> {
try {
await fs.promises.access(targetPath);
return true;
} catch {
return false;
}
}
export function clampNumber(value: number, min: number, max: number): number {
return Math.max(min, Math.min(max, value));
}
export function clampInt(value: number, min: number, max: number): number {
return clampNumber(Math.floor(value), min, max);
}
/** Alias for clampNumber (shorter, more common name) */
export const clamp = clampNumber;
/**
* Escapes special regex characters in a string so it can be used in a RegExp constructor.
*/
export function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
/**
* Safely parse JSON, returning null on error instead of throwing.
*/
export function safeParseJson<T>(raw: string): T | null {
try {
return JSON.parse(raw) as T;
} catch {
return null;
}
}
export { formatTerminalLink, isPlainObject };
/**
* Type guard for Record<string, unknown> (less strict than isPlainObject).
* Accepts any non-null object that isn't an array.
*/
export function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
export function normalizeE164(number: string): string {
const withoutPrefix = number.replace(/^[a-z][a-z0-9-]*:/i, "").trim();
const digits = withoutPrefix.replace(/[^\d+]/g, "");
if (digits.startsWith("+")) {
return `+${digits.slice(1)}`;
}
return `+${digits}`;
}
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function isHighSurrogate(codeUnit: number): boolean {
return codeUnit >= 0xd800 && codeUnit <= 0xdbff;
}
function isLowSurrogate(codeUnit: number): boolean {
return codeUnit >= 0xdc00 && codeUnit <= 0xdfff;
}
export function sliceUtf16Safe(input: string, start: number, end?: number): string {
const len = input.length;
let from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
let to = end === undefined ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
if (to < from) {
const tmp = from;
from = to;
to = tmp;
}
if (from > 0 && from < len) {
const codeUnit = input.charCodeAt(from);
if (isLowSurrogate(codeUnit) && isHighSurrogate(input.charCodeAt(from - 1))) {
from += 1;
}
}
if (to > 0 && to < len) {
const codeUnit = input.charCodeAt(to - 1);
if (isHighSurrogate(codeUnit) && isLowSurrogate(input.charCodeAt(to))) {
to -= 1;
}
}
return input.slice(from, to);
}
export function truncateUtf16Safe(input: string, maxLen: number): string {
const limit = Math.max(0, Math.floor(maxLen));
if (input.length <= limit) {
return input;
}
return sliceUtf16Safe(input, 0, limit);
}
export function resolveUserPath(
input: string,
env: NodeJS.ProcessEnv = process.env,
homedir: () => string = os.homedir,
): string {
if (!input) {
return "";
}
return resolveHomeRelativePath(input, { env, homedir });
}
export function resolveConfigDir(
env: NodeJS.ProcessEnv = process.env,
homedir: () => string = os.homedir,
): string {
const override = env.OPENCLAW_STATE_DIR?.trim();
if (override) {
return resolveUserPath(override, env, homedir);
}
const newDir = path.join(resolveRequiredHomeDir(env, homedir), ".openclaw");
try {
const hasNew = fs.existsSync(newDir);
if (hasNew) {
return newDir;
}
} catch {
// best-effort
}
return newDir;
}
export function resolveHomeDir(): string | undefined {
return resolveEffectiveHomeDir(process.env, os.homedir);
}
function resolveHomeDisplayPrefix(): { home: string; prefix: string } | undefined {
const home = resolveHomeDir();
if (!home) {
return undefined;
}
const explicitHome = process.env.OPENCLAW_HOME?.trim();
if (explicitHome) {
return { home, prefix: "$OPENCLAW_HOME" };
}
return { home, prefix: "~" };
}
export function shortenHomePath(input: string): string {
if (!input) {
return input;
}
const display = resolveHomeDisplayPrefix();
if (!display) {
return input;
}
const { home, prefix } = display;
if (input === home) {
return prefix;
}
if (input.startsWith(`${home}/`) || input.startsWith(`${home}\\`)) {
return `${prefix}${input.slice(home.length)}`;
}
return input;
}
export function shortenHomeInString(input: string): string {
if (!input) {
return input;
}
const display = resolveHomeDisplayPrefix();
if (!display) {
return input;
}
return input.split(display.home).join(display.prefix);
}
export function displayPath(input: string): string {
return shortenHomePath(input);
}
export function displayString(input: string): string {
return shortenHomeInString(input);
}
// Configuration root; can be overridden via OPENCLAW_STATE_DIR.
export const CONFIG_DIR = resolveConfigDir();
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

11萨顶顶的 sddd
暂无标签
MIT
使用 MIT 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/changluJava/openclaw.git
git@gitee.com:changluJava/openclaw.git
changluJava
openclaw
openclaw
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /