mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-12 17:36:03 +00:00
Centralized managed worktrees under <state-dir>/worktrees/<repo-fingerprint>/<name> with branch-per-task (openclaw/<name>), .worktreeinclude provisioning, an optional .openclaw/worktree-setup.sh repo hook, and a SQLite registry in the shared state DB. Removal always snapshots the tree (untracked included, gitignored excluded) to refs/openclaw/snapshots/<id>; restore rebuilds the branch at the original commit with the snapshot content as uncommitted state. Lossless run-end cleanup, 7-day idle GC for run-owned worktrees (manual exempt), orphan reconciliation, 30-day snapshot retention. Surfaces: worktrees.* gateway RPC (operator.admin mutations), openclaw worktrees CLI, Control UI page, plugin-SDK facade + Workboard kind:"worktree" materialization. E2E-verified on Testbox: full create->work->remove->restore->gc lifecycle.
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { Type } from "typebox";
|
|
import { NonEmptyString } from "./primitives.js";
|
|
|
|
const WorktreeNameSchema = Type.String({ pattern: "^[a-z0-9][a-z0-9-]{0,63}$" });
|
|
|
|
export const WorktreeRecordSchema = Type.Object(
|
|
{
|
|
id: NonEmptyString,
|
|
name: WorktreeNameSchema,
|
|
repoFingerprint: Type.String({ pattern: "^[a-f0-9]{16}$" }),
|
|
repoRoot: NonEmptyString,
|
|
path: NonEmptyString,
|
|
branch: NonEmptyString,
|
|
baseRef: NonEmptyString,
|
|
ownerKind: Type.String({ enum: ["manual", "workboard", "session"] }),
|
|
ownerId: Type.Optional(NonEmptyString),
|
|
snapshotRef: Type.Optional(NonEmptyString),
|
|
createdAt: Type.Integer({ minimum: 0 }),
|
|
lastActiveAt: Type.Integer({ minimum: 0 }),
|
|
removedAt: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
},
|
|
{ additionalProperties: false },
|
|
);
|
|
|
|
export const WorktreesListParamsSchema = Type.Object({}, { additionalProperties: false });
|
|
export const WorktreesListResultSchema = Type.Object(
|
|
{ worktrees: Type.Array(WorktreeRecordSchema) },
|
|
{ additionalProperties: false },
|
|
);
|
|
|
|
export const WorktreesCreateParamsSchema = Type.Object(
|
|
{
|
|
repoRoot: NonEmptyString,
|
|
name: Type.Optional(WorktreeNameSchema),
|
|
baseRef: Type.Optional(NonEmptyString),
|
|
},
|
|
{ additionalProperties: false },
|
|
);
|
|
|
|
export const WorktreesRemoveParamsSchema = Type.Object(
|
|
{ id: NonEmptyString, force: Type.Optional(Type.Boolean()) },
|
|
{ additionalProperties: false },
|
|
);
|
|
export const WorktreesRemoveResultSchema = Type.Object(
|
|
{ removed: Type.Boolean(), snapshotRef: Type.Optional(NonEmptyString) },
|
|
{ additionalProperties: false },
|
|
);
|
|
|
|
export const WorktreesRestoreParamsSchema = Type.Object(
|
|
{ id: NonEmptyString },
|
|
{ additionalProperties: false },
|
|
);
|
|
export const WorktreesGcParamsSchema = Type.Object({}, { additionalProperties: false });
|
|
export const WorktreesGcResultSchema = Type.Object(
|
|
{
|
|
removed: Type.Array(NonEmptyString),
|
|
orphansDeleted: Type.Integer({ minimum: 0 }),
|
|
snapshotsPruned: Type.Integer({ minimum: 0 }),
|
|
},
|
|
{ additionalProperties: false },
|
|
);
|