Add worktree-aware workspace runtime support
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
help,
|
||||
} from "../../components/agent-config-primitives";
|
||||
import { ChoosePathButton } from "../../components/PathInstructionsModal";
|
||||
import { LocalWorkspaceRuntimeFields } from "../local-workspace-runtime-fields";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";
|
||||
@@ -15,38 +16,54 @@ const instructionsFileHint =
|
||||
"Absolute path to a markdown file (e.g. AGENTS.md) that defines this agent's behavior. Injected into the system prompt at runtime.";
|
||||
|
||||
export function ClaudeLocalConfigFields({
|
||||
mode,
|
||||
isCreate,
|
||||
adapterType,
|
||||
values,
|
||||
set,
|
||||
config,
|
||||
eff,
|
||||
mark,
|
||||
models,
|
||||
}: AdapterConfigFieldsProps) {
|
||||
return (
|
||||
<Field label="Agent instructions file" hint={instructionsFileHint}>
|
||||
<div className="flex items-center gap-2">
|
||||
<DraftInput
|
||||
value={
|
||||
isCreate
|
||||
? values!.instructionsFilePath ?? ""
|
||||
: eff(
|
||||
"adapterConfig",
|
||||
"instructionsFilePath",
|
||||
String(config.instructionsFilePath ?? ""),
|
||||
)
|
||||
}
|
||||
onCommit={(v) =>
|
||||
isCreate
|
||||
? set!({ instructionsFilePath: v })
|
||||
: mark("adapterConfig", "instructionsFilePath", v || undefined)
|
||||
}
|
||||
immediate
|
||||
className={inputClass}
|
||||
placeholder="/absolute/path/to/AGENTS.md"
|
||||
/>
|
||||
<ChoosePathButton />
|
||||
</div>
|
||||
</Field>
|
||||
<>
|
||||
<Field label="Agent instructions file" hint={instructionsFileHint}>
|
||||
<div className="flex items-center gap-2">
|
||||
<DraftInput
|
||||
value={
|
||||
isCreate
|
||||
? values!.instructionsFilePath ?? ""
|
||||
: eff(
|
||||
"adapterConfig",
|
||||
"instructionsFilePath",
|
||||
String(config.instructionsFilePath ?? ""),
|
||||
)
|
||||
}
|
||||
onCommit={(v) =>
|
||||
isCreate
|
||||
? set!({ instructionsFilePath: v })
|
||||
: mark("adapterConfig", "instructionsFilePath", v || undefined)
|
||||
}
|
||||
immediate
|
||||
className={inputClass}
|
||||
placeholder="/absolute/path/to/AGENTS.md"
|
||||
/>
|
||||
<ChoosePathButton />
|
||||
</div>
|
||||
</Field>
|
||||
<LocalWorkspaceRuntimeFields
|
||||
isCreate={isCreate}
|
||||
values={values}
|
||||
set={set}
|
||||
config={config}
|
||||
mark={mark}
|
||||
eff={eff}
|
||||
mode={mode}
|
||||
adapterType={adapterType}
|
||||
models={models}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
help,
|
||||
} from "../../components/agent-config-primitives";
|
||||
import { ChoosePathButton } from "../../components/PathInstructionsModal";
|
||||
import { LocalWorkspaceRuntimeFields } from "../local-workspace-runtime-fields";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";
|
||||
@@ -13,12 +14,15 @@ const instructionsFileHint =
|
||||
"Absolute path to a markdown file (e.g. AGENTS.md) that defines this agent's behavior. Injected into the system prompt at runtime.";
|
||||
|
||||
export function CodexLocalConfigFields({
|
||||
mode,
|
||||
isCreate,
|
||||
adapterType,
|
||||
values,
|
||||
set,
|
||||
config,
|
||||
eff,
|
||||
mark,
|
||||
models,
|
||||
}: AdapterConfigFieldsProps) {
|
||||
const bypassEnabled =
|
||||
config.dangerouslyBypassApprovalsAndSandbox === true || config.dangerouslyBypassSandbox === true;
|
||||
@@ -81,6 +85,17 @@ export function CodexLocalConfigFields({
|
||||
: mark("adapterConfig", "search", v)
|
||||
}
|
||||
/>
|
||||
<LocalWorkspaceRuntimeFields
|
||||
isCreate={isCreate}
|
||||
values={values}
|
||||
set={set}
|
||||
config={config}
|
||||
mark={mark}
|
||||
eff={eff}
|
||||
mode={mode}
|
||||
adapterType={adapterType}
|
||||
models={models}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
136
ui/src/adapters/local-workspace-runtime-fields.tsx
Normal file
136
ui/src/adapters/local-workspace-runtime-fields.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
import type { AdapterConfigFieldsProps } from "./types";
|
||||
import { DraftInput, Field, help } from "../components/agent-config-primitives";
|
||||
import { RuntimeServicesJsonField } from "./runtime-json-fields";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
: {};
|
||||
}
|
||||
|
||||
function asString(value: unknown): string {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function readWorkspaceStrategy(config: Record<string, unknown>) {
|
||||
const strategy = asRecord(config.workspaceStrategy);
|
||||
const type = asString(strategy.type) || "project_primary";
|
||||
return {
|
||||
type,
|
||||
baseRef: asString(strategy.baseRef),
|
||||
branchTemplate: asString(strategy.branchTemplate),
|
||||
worktreeParentDir: asString(strategy.worktreeParentDir),
|
||||
};
|
||||
}
|
||||
|
||||
function buildWorkspaceStrategyPatch(input: {
|
||||
type: string;
|
||||
baseRef?: string;
|
||||
branchTemplate?: string;
|
||||
worktreeParentDir?: string;
|
||||
}) {
|
||||
if (input.type !== "git_worktree") return undefined;
|
||||
return {
|
||||
type: "git_worktree",
|
||||
...(input.baseRef ? { baseRef: input.baseRef } : {}),
|
||||
...(input.branchTemplate ? { branchTemplate: input.branchTemplate } : {}),
|
||||
...(input.worktreeParentDir ? { worktreeParentDir: input.worktreeParentDir } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function LocalWorkspaceRuntimeFields({
|
||||
isCreate,
|
||||
values,
|
||||
set,
|
||||
config,
|
||||
mark,
|
||||
}: AdapterConfigFieldsProps) {
|
||||
const existing = readWorkspaceStrategy(config);
|
||||
const strategyType = isCreate ? values!.workspaceStrategyType ?? "project_primary" : existing.type;
|
||||
const updateEditWorkspaceStrategy = (patch: Partial<typeof existing>) => {
|
||||
const next = {
|
||||
...existing,
|
||||
...patch,
|
||||
};
|
||||
mark(
|
||||
"adapterConfig",
|
||||
"workspaceStrategy",
|
||||
buildWorkspaceStrategyPatch(next),
|
||||
);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Field label="Workspace strategy" hint={help.workspaceStrategy}>
|
||||
<select
|
||||
className={inputClass}
|
||||
value={strategyType}
|
||||
onChange={(e) => {
|
||||
const nextType = e.target.value;
|
||||
if (isCreate) {
|
||||
set!({ workspaceStrategyType: nextType });
|
||||
} else {
|
||||
updateEditWorkspaceStrategy({ type: nextType });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<option value="project_primary">Project primary workspace</option>
|
||||
<option value="git_worktree">Git worktree</option>
|
||||
</select>
|
||||
</Field>
|
||||
|
||||
{strategyType === "git_worktree" && (
|
||||
<>
|
||||
<Field label="Base ref" hint={help.workspaceBaseRef}>
|
||||
<DraftInput
|
||||
value={isCreate ? values!.workspaceBaseRef ?? "" : existing.baseRef}
|
||||
onCommit={(v) =>
|
||||
isCreate
|
||||
? set!({ workspaceBaseRef: v })
|
||||
: updateEditWorkspaceStrategy({ baseRef: v || "" })
|
||||
}
|
||||
immediate
|
||||
className={inputClass}
|
||||
placeholder="origin/main"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Branch template" hint={help.workspaceBranchTemplate}>
|
||||
<DraftInput
|
||||
value={isCreate ? values!.workspaceBranchTemplate ?? "" : existing.branchTemplate}
|
||||
onCommit={(v) =>
|
||||
isCreate
|
||||
? set!({ workspaceBranchTemplate: v })
|
||||
: updateEditWorkspaceStrategy({ branchTemplate: v || "" })
|
||||
}
|
||||
immediate
|
||||
className={inputClass}
|
||||
placeholder="{{issue.identifier}}-{{slug}}"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Worktree parent dir" hint={help.worktreeParentDir}>
|
||||
<DraftInput
|
||||
value={isCreate ? values!.worktreeParentDir ?? "" : existing.worktreeParentDir}
|
||||
onCommit={(v) =>
|
||||
isCreate
|
||||
? set!({ worktreeParentDir: v })
|
||||
: updateEditWorkspaceStrategy({ worktreeParentDir: v || "" })
|
||||
}
|
||||
immediate
|
||||
className={inputClass}
|
||||
placeholder=".paperclip/worktrees"
|
||||
/>
|
||||
</Field>
|
||||
</>
|
||||
)}
|
||||
<RuntimeServicesJsonField
|
||||
isCreate={isCreate}
|
||||
values={values}
|
||||
set={set}
|
||||
config={config}
|
||||
mark={mark}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,10 @@ import {
|
||||
DraftInput,
|
||||
help,
|
||||
} from "../../components/agent-config-primitives";
|
||||
import {
|
||||
PayloadTemplateJsonField,
|
||||
RuntimeServicesJsonField,
|
||||
} from "../runtime-json-fields";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";
|
||||
@@ -112,6 +116,22 @@ export function OpenClawGatewayConfigFields({
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<PayloadTemplateJsonField
|
||||
isCreate={isCreate}
|
||||
values={values}
|
||||
set={set}
|
||||
config={config}
|
||||
mark={mark}
|
||||
/>
|
||||
|
||||
<RuntimeServicesJsonField
|
||||
isCreate={isCreate}
|
||||
values={values}
|
||||
set={set}
|
||||
config={config}
|
||||
mark={mark}
|
||||
/>
|
||||
|
||||
{!isCreate && (
|
||||
<>
|
||||
<Field label="Paperclip API URL override">
|
||||
|
||||
115
ui/src/adapters/runtime-json-fields.tsx
Normal file
115
ui/src/adapters/runtime-json-fields.tsx
Normal file
@@ -0,0 +1,115 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import type { AdapterConfigFieldsProps } from "./types";
|
||||
import { Field, help } from "../components/agent-config-primitives";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
: {};
|
||||
}
|
||||
|
||||
function formatJsonObject(value: unknown): string {
|
||||
const record = asRecord(value);
|
||||
return Object.keys(record).length > 0 ? JSON.stringify(record, null, 2) : "";
|
||||
}
|
||||
|
||||
function updateJsonConfig(
|
||||
isCreate: boolean,
|
||||
key: "runtimeServicesJson" | "payloadTemplateJson",
|
||||
next: string,
|
||||
set: AdapterConfigFieldsProps["set"],
|
||||
mark: AdapterConfigFieldsProps["mark"],
|
||||
configKey: string,
|
||||
) {
|
||||
if (isCreate) {
|
||||
set?.({ [key]: next });
|
||||
return;
|
||||
}
|
||||
|
||||
const trimmed = next.trim();
|
||||
if (!trimmed) {
|
||||
mark("adapterConfig", configKey, undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed);
|
||||
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
||||
mark("adapterConfig", configKey, parsed);
|
||||
}
|
||||
} catch {
|
||||
// Keep local draft until JSON is valid.
|
||||
}
|
||||
}
|
||||
|
||||
type JsonFieldProps = Pick<
|
||||
AdapterConfigFieldsProps,
|
||||
"isCreate" | "values" | "set" | "config" | "mark"
|
||||
>;
|
||||
|
||||
export function RuntimeServicesJsonField({
|
||||
isCreate,
|
||||
values,
|
||||
set,
|
||||
config,
|
||||
mark,
|
||||
}: JsonFieldProps) {
|
||||
const existing = formatJsonObject(config.workspaceRuntime);
|
||||
const [draft, setDraft] = useState(existing);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isCreate) setDraft(existing);
|
||||
}, [existing, isCreate]);
|
||||
|
||||
const value = isCreate ? values?.runtimeServicesJson ?? "" : draft;
|
||||
|
||||
return (
|
||||
<Field label="Runtime services JSON" hint={help.runtimeServicesJson}>
|
||||
<textarea
|
||||
className={`${inputClass} min-h-[148px]`}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
const next = e.target.value;
|
||||
if (!isCreate) setDraft(next);
|
||||
updateJsonConfig(isCreate, "runtimeServicesJson", next, set, mark, "workspaceRuntime");
|
||||
}}
|
||||
placeholder={`{\n "services": [\n {\n "name": "preview",\n "lifecycle": "ephemeral",\n "metadata": {\n "purpose": "remote preview"\n }\n }\n ]\n}`}
|
||||
/>
|
||||
</Field>
|
||||
);
|
||||
}
|
||||
|
||||
export function PayloadTemplateJsonField({
|
||||
isCreate,
|
||||
values,
|
||||
set,
|
||||
config,
|
||||
mark,
|
||||
}: JsonFieldProps) {
|
||||
const existing = formatJsonObject(config.payloadTemplate);
|
||||
const [draft, setDraft] = useState(existing);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isCreate) setDraft(existing);
|
||||
}, [existing, isCreate]);
|
||||
|
||||
const value = isCreate ? values?.payloadTemplateJson ?? "" : draft;
|
||||
|
||||
return (
|
||||
<Field label="Payload template JSON" hint={help.payloadTemplateJson}>
|
||||
<textarea
|
||||
className={`${inputClass} min-h-[132px]`}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
const next = e.target.value;
|
||||
if (!isCreate) setDraft(next);
|
||||
updateJsonConfig(isCreate, "payloadTemplateJson", next, set, mark, "payloadTemplate");
|
||||
}}
|
||||
placeholder={`{\n "agentId": "remote-agent-123",\n "metadata": {\n "team": "platform"\n }\n}`}
|
||||
/>
|
||||
</Field>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user