diff --git a/docs/architecture.md b/docs/architecture.md index 7081f90..7d9e26b 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -116,7 +116,6 @@ packages/ doctor.ts Health checks with lifecycle-based warnings checkpoint.ts Signal host to commit data changes tools/ System primitives backing CapabilityContext - types.ts ProvisionResult interface fs.ts File system helpers (ensureLineInFile, ensureDir) curl.ts Download helpers shell-profile.ts Login profile management diff --git a/docs/vm-cli.md b/docs/vm-cli.md index c7989e8..d00cba7 100644 --- a/docs/vm-cli.md +++ b/docs/vm-cli.md @@ -84,7 +84,6 @@ packages/vm-cli/ doctor.ts Health checks (mounts, env, PATH, services, openclaw) checkpoint.ts Signal host to commit data changes tools/ System primitives backing CapabilityContext - types.ts ProvisionResult interface fs.ts ensureLineInFile, ensureDir curl.ts downloadFile, downloadAndRun shell-profile.ts ensureInBashrc, ensureInProfile, ensurePath @@ -107,7 +106,6 @@ indirectly via the context SDK — not by direct import. | Module | Purpose | | --------------------- | --------------------------------------------------------- | -| `types.ts` | `ProvisionResult` interface | | `fs.ts` | `ensureLineInFile`, `ensureDir` | | `curl.ts` | `downloadFile`, `downloadAndRun` | | `shell-profile.ts` | `ensureInBashrc`, `ensureInProfile`, `ensurePath` | diff --git a/packages/cli/src/app.tsx b/packages/cli/src/app.tsx index 6afb6a1..54f63e1 100644 --- a/packages/cli/src/app.tsx +++ b/packages/cli/src/app.tsx @@ -138,7 +138,6 @@ export function App({ driver, creationTarget }: AppProps) { {step === "finish" && ( { - const { runHeadless } = await import("@clawctl/host-core"); const result = await runHeadless(driver, configPath); const entry: RegistryEntry = { @@ -36,7 +43,6 @@ export async function runCreateWizard(driver: VMDriver): Promise { const React = (await import("react")).default; const { render } = await import("ink"); const { App } = await import("../app.js"); - const { extractGatewayToken } = await import("@clawctl/host-core"); type OnboardResult = { action: "onboard"; @@ -210,7 +216,6 @@ export async function runCreateWizard(driver: VMDriver): Promise { console.log(" First tailnet connection requires device approval:"); console.log(` ${BIN_NAME} oc devices list`); console.log(` ${BIN_NAME} oc devices approve `); - const { loadRegistry, saveRegistry } = await import("@clawctl/host-core"); const registry = await loadRegistry(); if (registry.instances[vmName]) { registry.instances[vmName].tailscaleUrl = tsBaseUrl; diff --git a/packages/cli/src/hooks/use-process-logs.test.ts b/packages/cli/src/hooks/use-process-logs.test.ts index 60ffd35..fc9a800 100644 --- a/packages/cli/src/hooks/use-process-logs.test.ts +++ b/packages/cli/src/hooks/use-process-logs.test.ts @@ -17,23 +17,6 @@ describe("useProcessLogs logic", () => { expect(lines).toEqual(["first", "second", "third"]); }); - test("clear resets the buffer", () => { - let lines: string[] = []; - const addLine = (line: string) => { - lines.push(line); - }; - const clear = () => { - lines = []; - }; - - addLine("a"); - addLine("b"); - expect(lines).toHaveLength(2); - - clear(); - expect(lines).toHaveLength(0); - }); - test("addLine is safe to call rapidly", () => { const lines: string[] = []; const addLine = (line: string) => { diff --git a/packages/cli/src/hooks/use-process-logs.ts b/packages/cli/src/hooks/use-process-logs.ts index bd0ff42..12b8a72 100644 --- a/packages/cli/src/hooks/use-process-logs.ts +++ b/packages/cli/src/hooks/use-process-logs.ts @@ -14,10 +14,5 @@ export function useProcessLogs() { setTick((t) => t + 1); }, []); - const clear = useCallback(() => { - linesRef.current = []; - setTick((t) => t + 1); - }, []); - - return { lines: linesRef.current, addLine, clear }; + return { lines: linesRef.current, addLine }; } diff --git a/packages/cli/src/hooks/use-verbose-mode.ts b/packages/cli/src/hooks/use-verbose-mode.ts index 51b1d02..38dc5ba 100644 --- a/packages/cli/src/hooks/use-verbose-mode.ts +++ b/packages/cli/src/hooks/use-verbose-mode.ts @@ -10,5 +10,5 @@ export function useVerboseMode() { } }); - return { verbose, toggle: () => setVerbose((prev) => !prev) }; + return { verbose }; } diff --git a/packages/cli/src/steps/credential-setup.tsx b/packages/cli/src/steps/credential-setup.tsx index ed74718..f694ef8 100644 --- a/packages/cli/src/steps/credential-setup.tsx +++ b/packages/cli/src/steps/credential-setup.tsx @@ -35,8 +35,6 @@ export function CredentialSetup({ useEffect(() => { async function run() { - const updatedCreds = { ...credentialConfig }; - // Validate 1Password token in VM if (hasOp) { try { @@ -81,7 +79,7 @@ export function CredentialSetup({ } setPhase("done"); - setTimeout(() => onComplete(updatedCreds), 500); + setTimeout(() => onComplete(credentialConfig), 500); } run(); }, []); diff --git a/packages/cli/src/steps/finish.tsx b/packages/cli/src/steps/finish.tsx index ce944b0..a7fe9a4 100644 --- a/packages/cli/src/steps/finish.tsx +++ b/packages/cli/src/steps/finish.tsx @@ -3,7 +3,6 @@ import { Text, Box, useApp } from "ink"; import { StepIndicator } from "../components/step-indicator.js"; import type { VMConfig } from "@clawctl/types"; import { GATEWAY_PORT } from "@clawctl/types"; -import type { VMDriver } from "@clawctl/host-core"; import { BIN_NAME } from "@clawctl/host-core"; export interface FinishResult { @@ -14,7 +13,6 @@ export interface FinishResult { } interface FinishProps { - driver: VMDriver; config: VMConfig; onboardSkipped?: boolean; tailscaleMode?: "off" | "serve" | "funnel"; diff --git a/packages/host-core/src/config.ts b/packages/host-core/src/config.ts index 5aa9a5a..ab514a8 100644 --- a/packages/host-core/src/config.ts +++ b/packages/host-core/src/config.ts @@ -1,6 +1,4 @@ import { readFile } from "fs/promises"; -import { homedir } from "os"; -import { resolve } from "path"; import { resolveEnvRefs, validateConfig } from "@clawctl/types"; import type { InstanceConfig, VMConfig } from "@clawctl/types"; @@ -59,31 +57,6 @@ export function sanitizeConfig(config: InstanceConfig): Record return clone; } -/** Format a zod error into a readable message with field path. */ -export function formatZodError(error: import("zod").ZodError): string { - const issue = error.issues[0]; - const path = issue.path.join("."); - - // Use custom messages (from .min() / .refine()) when they look specific - if (issue.message && !issue.message.startsWith("Invalid input:")) { - return issue.message; - } - - // Build a path-based message for generic zod errors - if (path) { - return `'${path}': ${issue.message}`; - } - return issue.message; -} - -/** Expand leading ~ to the user's home directory. */ -export function expandTilde(path: string): string { - if (path.startsWith("~/") || path === "~") { - return resolve(homedir(), path.slice(2)); - } - return path; -} - /** Read and validate a JSON config file. */ export async function loadConfig(path: string): Promise { let raw: string; diff --git a/packages/host-core/src/index.ts b/packages/host-core/src/index.ts index 00e8123..6a1865c 100644 --- a/packages/host-core/src/index.ts +++ b/packages/host-core/src/index.ts @@ -9,14 +9,7 @@ export type { VMDriver, VMCreateOptions, ExecResult, OnLine } from "./drivers/ty export { exec, execStream, execWithLogs, commandExists } from "./exec.js"; // Config -export { - loadConfig, - validateConfig, - configToVMConfig, - sanitizeConfig, - formatZodError, - expandTilde, -} from "./config.js"; +export { loadConfig, validateConfig, configToVMConfig, sanitizeConfig } from "./config.js"; // Secrets (I/O + re-exports of pure functions from @clawctl/types) export { diff --git a/packages/vm-cli/src/tools/openclaw.ts b/packages/vm-cli/src/tools/openclaw.ts index 7a18749..29deb54 100644 --- a/packages/vm-cli/src/tools/openclaw.ts +++ b/packages/vm-cli/src/tools/openclaw.ts @@ -5,16 +5,6 @@ export async function isInstalled(): Promise { return commandExists("openclaw"); } -/** Get the installed openclaw version string. */ -export async function version(): Promise { - const npmGlobalBin = `${process.env.HOME}/.npm-global/bin`; - const result = await exec("openclaw", ["--version"], { - quiet: true, - env: { ...process.env, PATH: `${npmGlobalBin}:${process.env.PATH}` }, - }); - return result.stdout.trim(); -} - /** Run openclaw doctor. Returns exit code 0 on success. */ export async function doctor(): Promise<{ exitCode: number; stdout: string; stderr: string }> { return exec("openclaw", ["doctor"], { quiet: true }); diff --git a/tasks/2026-03-16_1833_dead-code-cleanup/TASK.md b/tasks/2026-03-16_1833_dead-code-cleanup/TASK.md new file mode 100644 index 0000000..8f2ffc9 --- /dev/null +++ b/tasks/2026-03-16_1833_dead-code-cleanup/TASK.md @@ -0,0 +1,49 @@ +# Dead code & misplaced code cleanup + +## Status: Resolved + +## Scope + +Remove dead exports, unused hook return values, unnecessary dynamic imports, +and stale documentation references found during a codebase audit. All items +are minor hygiene — no behavioral changes. + +Does NOT cover: any functional changes, new features, or refactoring beyond +the identified dead code. + +## Plan + +1. Delete `formatZodError` and `expandTilde` from `host-core/src/config.ts` and barrel +2. Delete `openclaw.version()` from `vm-cli/src/tools/openclaw.ts` +3. Remove `clear` from `useProcessLogs` hook and its test +4. Remove `toggle` from `useVerboseMode` hook +5. Remove `driver` prop from `Finish` component and its usage in `app.tsx` +6. Remove unnecessary `updatedCreds` copy in `CredentialSetup` +7. Convert dynamic imports to static imports in `create.ts` +8. Fix stale `tools/types.ts` references in docs +9. Verify: tests pass, lint clean, format clean + +## Steps + +- [x] Items 1-8 implementation +- [x] `bun test` passes (264 pass, 10 skip, 0 fail) +- [x] `bun run lint` clean +- [x] `bun run format:check` clean +- [x] Grep verification for removed symbols + +## Notes + +## Outcome + +All 8 items delivered as planned: + +1. Deleted `formatZodError` + `expandTilde` from host-core (duplicates of types package) +2. Deleted `openclaw.version()` from vm-cli (unused) +3. Removed `clear` from `useProcessLogs` hook + its test +4. Removed `toggle` from `useVerboseMode` hook +5. Removed `driver` prop from `Finish` component +6. Simplified `CredentialSetup` — removed unnecessary `updatedCreds` copy +7. Converted 3 dynamic imports to static imports in `create.ts` +8. Removed stale `tools/types.ts` references from `vm-cli.md` and `architecture.md` + +No behavioral changes. All tests pass, lint/format clean.