style: fix biome formatting
This commit is contained in:
@@ -657,10 +657,16 @@ export async function handleCommands(params: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const snapshot = await readConfigFileSnapshot();
|
const snapshot = await readConfigFileSnapshot();
|
||||||
if (!snapshot.valid || !snapshot.parsed || typeof snapshot.parsed !== "object") {
|
if (
|
||||||
|
!snapshot.valid ||
|
||||||
|
!snapshot.parsed ||
|
||||||
|
typeof snapshot.parsed !== "object"
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
shouldContinue: false,
|
shouldContinue: false,
|
||||||
reply: { text: "⚠️ Config file is invalid; fix it before using /config." },
|
reply: {
|
||||||
|
text: "⚠️ Config file is invalid; fix it before using /config.",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const parsedBase = structuredClone(
|
const parsedBase = structuredClone(
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import { parseConfigCommand } from "./config-commands.js";
|
|||||||
describe("parseConfigCommand", () => {
|
describe("parseConfigCommand", () => {
|
||||||
it("parses show/unset", () => {
|
it("parses show/unset", () => {
|
||||||
expect(parseConfigCommand("/config")).toEqual({ action: "show" });
|
expect(parseConfigCommand("/config")).toEqual({ action: "show" });
|
||||||
expect(parseConfigCommand("/config show")).toEqual({ action: "show", path: undefined });
|
expect(parseConfigCommand("/config show")).toEqual({
|
||||||
|
action: "show",
|
||||||
|
path: undefined,
|
||||||
|
});
|
||||||
expect(parseConfigCommand("/config show foo.bar")).toEqual({
|
expect(parseConfigCommand("/config show foo.bar")).toEqual({
|
||||||
action: "show",
|
action: "show",
|
||||||
path: "foo.bar",
|
path: "foo.bar",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export function parseConfigValue(
|
export function parseConfigValue(raw: string): {
|
||||||
raw: string,
|
value?: unknown;
|
||||||
): { value?: unknown; error?: string } {
|
error?: string;
|
||||||
|
} {
|
||||||
const trimmed = raw.trim();
|
const trimmed = raw.trim();
|
||||||
if (!trimmed) return { error: "Missing value." };
|
if (!trimmed) return { error: "Missing value." };
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ export function parseConfigValue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(trimmed.startsWith("\"") && trimmed.endsWith("\"")) ||
|
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
||||||
(trimmed.startsWith("'") && trimmed.endsWith("'"))
|
(trimmed.startsWith("'") && trimmed.endsWith("'"))
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -9,11 +9,17 @@ export function parseConfigPath(raw: string): {
|
|||||||
} {
|
} {
|
||||||
const trimmed = raw.trim();
|
const trimmed = raw.trim();
|
||||||
if (!trimmed) {
|
if (!trimmed) {
|
||||||
return { ok: false, error: "Invalid path. Use dot notation (e.g. foo.bar)." };
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: "Invalid path. Use dot notation (e.g. foo.bar).",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const parts = trimmed.split(".").map((part) => part.trim());
|
const parts = trimmed.split(".").map((part) => part.trim());
|
||||||
if (parts.some((part) => !part)) {
|
if (parts.some((part) => !part)) {
|
||||||
return { ok: false, error: "Invalid path. Use dot notation (e.g. foo.bar)." };
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: "Invalid path. Use dot notation (e.g. foo.bar).",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (parts.some((part) => BLOCKED_KEYS.has(part))) {
|
if (parts.some((part) => BLOCKED_KEYS.has(part))) {
|
||||||
return { ok: false, error: "Invalid path segment." };
|
return { ok: false, error: "Invalid path segment." };
|
||||||
@@ -66,10 +72,7 @@ export function unsetConfigValueAtPath(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConfigValueAtPath(
|
export function getConfigValueAtPath(root: PathNode, path: string[]): unknown {
|
||||||
root: PathNode,
|
|
||||||
path: string[],
|
|
||||||
): unknown {
|
|
||||||
let cursor: unknown = root;
|
let cursor: unknown = root;
|
||||||
for (const key of path) {
|
for (const key of path) {
|
||||||
if (!isPlainObject(cursor)) return undefined;
|
if (!isPlainObject(cursor)) return undefined;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { ClawdbotConfig } from "./types.js";
|
|
||||||
import {
|
import {
|
||||||
parseConfigPath,
|
parseConfigPath,
|
||||||
setConfigValueAtPath,
|
setConfigValueAtPath,
|
||||||
unsetConfigValueAtPath,
|
unsetConfigValueAtPath,
|
||||||
} from "./config-paths.js";
|
} from "./config-paths.js";
|
||||||
|
import type { ClawdbotConfig } from "./types.js";
|
||||||
|
|
||||||
type OverrideTree = Record<string, unknown>;
|
type OverrideTree = Record<string, unknown>;
|
||||||
|
|
||||||
@@ -58,7 +58,11 @@ export function unsetConfigOverride(pathRaw: string): {
|
|||||||
} {
|
} {
|
||||||
const parsed = parseConfigPath(pathRaw);
|
const parsed = parseConfigPath(pathRaw);
|
||||||
if (!parsed.ok || !parsed.path) {
|
if (!parsed.ok || !parsed.path) {
|
||||||
return { ok: false, removed: false, error: parsed.error ?? "Invalid path." };
|
return {
|
||||||
|
ok: false,
|
||||||
|
removed: false,
|
||||||
|
error: parsed.error ?? "Invalid path.",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const removed = unsetConfigValueAtPath(overrides, parsed.path);
|
const removed = unsetConfigValueAtPath(overrides, parsed.path);
|
||||||
return { ok: true, removed };
|
return { ok: true, removed };
|
||||||
|
|||||||
Reference in New Issue
Block a user