Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions .github/workflows/platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
run: bash scripts/build-chatbot.sh
- name: Let Chromium use its sandbox as an unprivileged user
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
# Engine and API tests run SOP nodes in the shared test-native sandbox,
# which is bwrap on Linux.
- name: Install bubblewrap for the native sandbox
run: sudo apt-get update && sudo apt-get install -y bubblewrap
- name: Warm up Chromium so the first real-browser test does not pay the cold start
run: |
for name in chromium chromium-browser google-chrome-stable google-chrome; do
Expand Down Expand Up @@ -87,6 +91,19 @@ jobs:
working-directory: e2e
- run: bash ../scripts/install-playwright-deps.sh npx playwright
working-directory: e2e
# The e2e SOPs and the runner the suite starts use the native e2e sandbox,
# which is bwrap on Linux.
- name: Let bubblewrap create user namespaces
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
- name: Install bubblewrap for the native sandbox
run: sudo apt-get update && sudo apt-get install -y bubblewrap
# The welcome SOP runs in generic-docker. As in a Compose installation, it
# uses the pinned platform image instead of building one during the tests.
- name: Pull the pinned platform image for the generic-docker sandbox
run: |
pinned=$(sed -n 's/^ *image: \${LOOPFORGE_IMAGE:-\(.*\)}$/\1/p' compose.yaml)
docker pull --quiet "$pinned"
echo "AGENTFLOW_ISOLATED_IMAGE=$pinned" >> "$GITHUB_ENV"
- name: Start clean local installation
run: |
bash scripts/dev.sh > /tmp/loopforge.log 2>&1 &
Expand Down Expand Up @@ -172,6 +189,8 @@ jobs:
# The path a new user takes: one-command install, then accounts created in the browser.
# Pulls the GHCR release pinned in compose.yaml; release.yml smoke-tests each newly published image.
# A pin bumped ahead of its tag has no image yet, so that commit is checked from source.
# So is a commit whose schema scripts differ from the pinned tag: the installer applies
# this checkout's scripts, which the released image may not be able to read.
runs-on: ubuntu-latest
timeout-minutes: 30
env:
Expand All @@ -187,14 +206,22 @@ jobs:
working-directory: e2e
- run: bash ../scripts/install-playwright-deps.sh npx playwright
working-directory: e2e
- name: Install the pinned release, or build it while that release is not published yet
- name: Install the pinned release, or build this checkout when the release cannot run it
run: |
pinned=$(sed -n 's/^ *image: \${LOOPFORGE_IMAGE:-\(.*\)}$/\1/p' compose.yaml)
if docker manifest inspect "$pinned" > /dev/null 2>&1; then
./start.sh -d
else
tag="v${pinned##*:}"
schema=(migrations scripts/install-schema-extensions.sh scripts/install-observability-schema.sh)
if ! docker manifest inspect "$pinned" > /dev/null 2>&1; then
echo "::notice::$pinned is not published yet; building this checkout"
./start.sh dev
elif ! git fetch --quiet --depth=1 origin "refs/tags/$tag:refs/tags/$tag"; then
echo "::warning::could not fetch $tag to compare schema scripts; installing $pinned"
./start.sh -d
elif ! git diff --quiet "$tag" -- "${schema[@]}"; then
echo "::notice::schema scripts changed since $tag; building this checkout"
./start.sh dev
else
./start.sh -d
fi
- name: Generate test passwords
run: |
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Preserve the platform architecture; keep deployment-specific adapters isolated.

| 领域 Repo | 拥有 |
|---|---|
| `CatalogRepo` | agents/rules/skills/MCP servers/executors/dockerfiles/environments/sandboxes/workflows/repositories/sync config/schedule jobs/definition revisions/generic templates |
| `CatalogRepo` | agents/rules/skills/MCP servers/executors/sandboxes(内嵌 Dockerfile 与安装脚本)/workflows/repositories/sync config/schedule jobs/definition revisions/generic templates |
| `ProjectsRepo` | projects、project members |
| `IssuesRepo` | issues、issue comments |
| `TasksRepo` | tasks(跨实例幂等记录) |
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Platform releases use `vX.Y.Z` tags and publish `ghcr.io/tencent/loopforge`. Loo

- On macOS `/bin/bash` 3.2, a missing local image or a failed automatic mirror pull no longer aborts `./start.sh` before the official image pull.
- `./start.sh` and `./start.sh pull` time `ghcr.io` and `ghcr.nju.edu.cn`. Nanjing is used only when the ghcr.io manifest digest was verified and the mirror returned the same digest; the pull is that digest, then tagged back to the name pinned in `compose.yaml`. A missing official digest, a digest mismatch, or a failed mirror pull stays on `ghcr.io`. `MIRROR=ghcr.io` forces the upstream registry; `MIRROR=<host>` still forces that host and does not fall back. Accepting Nanjing, or setting `MIRROR`, trusts that host. The choice is not saved in `.env`. `registry-mirrors` such as `https://docker.nju.edu.cn` only accelerates Docker Hub.
- **Breaking:** `local` sandboxes are now bound to one execution machine and its owner, and are for conversation workspaces only. A local workspace starts empty like any other conversation workspace; the repository list sent to the agent names each repository's checkout on the machine (its configured path, or a clone under `~/.loopforge/local`), and the agent adds git worktrees of it when a task needs the repository instead of cloning into the workspace. The workspace keeps its files and worktrees until it is deleted, and follows Claude Code's default permission rules for every CLI: reads, searches and built-in read-only commands inside the workspace run directly, while other commands, edits and reads outside the workspace follow the chosen approval mode. SOPs can no longer use `local`; the default sandbox is `generic-docker`, and `AGENTFLOW_LOCAL_SANDBOX` is removed. Unbound local profiles must be re-saved by the machine owner; run `migrations/040_local_sandbox_runner_only.sql` to move built-in SOPs to `generic-docker`. Local workspaces need Runner 0.12.0.
- 设置 → AI 助手 gains 「对话工作区」: users choose the sandbox kind (Docker, native or local) the assistant prefers when it opens a conversation workspace itself. The preference (`workspaceDriver` in `/api/assistant/preferences`) puts that kind first in the assistant's choices and is used when it names no environment; the assistant still switches when only another environment has the toolchain a task needs, and a conversation's fixed environment still wins. The workbench environment picker now also lists native sandboxes, and local sandboxes bound to the conversation's machine for their owner, grouped by kind. `migrations/042_assistant_workspace_driver.sql` adds the column for deployments that apply DDL by hand; startup AutoMigrate also adds it.
- **Breaking:** a sandbox now carries its own Dockerfile (docker) or environment install script (native), and the 环境资产 page becomes 「沙箱管理」 without type tabs: the sandbox editor holds the Dockerfile and its build-context files, or the install script, PATH entries and install variables. Dockerfiles and install scripts are no longer separate assets that sandboxes reference and share on their own. `/api/dockerfiles`, `/api/environments`, the `dockerfiles_*` / `environments_*` assistant and MCP tools and the `dockerfiles` / `environments` bootstrap fields are removed; `PUT /api/sandboxes` takes `dockerfile {content, files}` and `install {script, pathEntries, variables}` in place of `dockerfileId` and `environmentId`. Run `migrations/041_sandbox_inline_assets.sql` after upgrading (the installer and `./start.sh pull` run it): it copies each referenced Dockerfile and install script into its sandbox, turns one that no sandbox used into a sandbox of its own, and drops the `dockerfiles` and `environments` tables. Docker images are reused; a native sandbox reinstalls its toolchain once. The runner protocol is unchanged.

## 0.4.0 — scheduled task history, an MR node in delivery SOPs and agent CLIs in conversation workspaces

Expand Down
10 changes: 5 additions & 5 deletions chatbot/src/NativeApprovalPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { api, write, sessionPath } from "./api";
import HarnessIcon from "./HarnessIcon";
import "./native-approval.css";

// External commands and external MCP writes can wait here for the speaker
// in "请求批准" mode.
// External commands and external MCP writes, and every non-read action of a
// local workspace, can wait here for the speaker in "请求批准" mode.
function commandText(input) {
const command = input?.command ?? input?.cmd ?? input?.commands;
if (typeof command === "string") return command;
Expand Down Expand Up @@ -56,15 +56,15 @@ export default function NativeApprovalPanel({ chat, onChange }) {
}, [pendingIds]);
if (!mine.length) return null;
return (
<section className="native-approvals" aria-label="待批准的外部写入" aria-live="polite">
<section className="native-approvals" aria-label="待批准的操作" aria-live="polite">
{mine.map((item) => (
<div className="native-approval" key={item.id}>
<div className="native-approval-title">
<HarnessIcon name="warning" size={15} aria-hidden="true" />
<strong>批准外部写入{item.summary ? `:${item.summary}` : ""}</strong>
<strong>{item.local ? "批准本机操作" : "批准外部写入"}{item.summary ? `:${item.summary}` : ""}</strong>
</div>
<pre>{commandText(item.input)}</pre>
<p>这项操作会写入外部系统。仅批准这一次。停止回复、调用取消或等待超时后,审批会失效。</p>
<p>{item.local ? "这项操作直接在你的执行机器上执行,没有沙箱隔离。" : "这项操作会写入外部系统。"}仅批准这一次。停止回复、调用取消或等待超时后,审批会失效。</p>
<div className="native-approval-actions">
<button type="button" disabled={!!saving} onClick={() => decide(item, "deny")}>
拒绝
Expand Down
4 changes: 2 additions & 2 deletions chatbot/src/PermissionPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { usePanelPresence } from "./usePanelPresence";
import "./permission-picker.css";

const modes = [
{ id: "confirm", icon: "gate", label: "请求批准", detail: "工作区文件和命令自动执行;平台写入由你确认,外部工具写入需要授权。" },
{ id: "assisted", icon: "confirmation-check", label: "帮我批准", detail: "工作区文件和命令自动执行;git push 等外部写入命令由 AI 审查直接批准或拒绝;平台写入未通过审查时交给你确认。" },
{ id: "confirm", icon: "gate", label: "请求批准", detail: "沙箱工作区里的文件和命令自动执行,local 工作区的每次操作都由你批准;平台写入由你确认,外部工具写入需要授权。" },
{ id: "assisted", icon: "confirmation-check", label: "帮我批准", detail: "沙箱工作区里的文件和命令自动执行;local 工作区的每次操作和 git push 等外部写入命令由 AI 审查直接批准或拒绝;平台写入未通过审查时交给你确认。" },
{ id: "auto", icon: "priority-bolt", label: "完全权限", tone: "danger", detail: "工作区文件和命令自动执行;平台及外部操作使用当前账号权限直接执行。" },
];

Expand Down
33 changes: 27 additions & 6 deletions chatbot/src/SandboxPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,33 @@ import { SelectMenu } from "./ui";
import HarnessIcon from "./HarnessIcon";
import "./sandbox-picker.css";

export function conversationSandboxOptions(sandboxes, project, selected = "") {
const available = (sandboxes || []).filter(
(s) => s.driver === "docker" && (s.projectId === project?.id || s.shared),
);
const SANDBOX_KINDS = ["docker", "native", "local"];
const SANDBOX_KIND_LABELS = {
docker: "Docker 容器",
native: "native 轻量隔离",
local: "local · 本机,无隔离",
};

function sandboxKind(sandbox) {
if (!sandbox.driver || sandbox.driver === "docker") return "docker";
return sandbox.driver === "local" ? "local" : "native";
}

// A local sandbox opens only on the machine it is bound to, for that
// machine's owner.
function localSandboxUsable(sandbox, access) {
const machine = (access.machines || []).find((m) => m.id === sandbox.runnerId);
return !!access.userId && !!sandbox.runnerId && sandbox.runnerId === access.runnerId && machine?.ownerUserId === access.userId;
}

export function conversationSandboxOptions(sandboxes, project, selected = "", access = {}) {
const available = (sandboxes || [])
.filter((s) => (s.projectId === project?.id || s.shared) &&
(sandboxKind(s) !== "local" || localSandboxUsable(s, access)))
.sort((a, b) => SANDBOX_KINDS.indexOf(sandboxKind(a)) - SANDBOX_KINDS.indexOf(sandboxKind(b)));
const options = [
{ value: "", label: "由 Agent 选择" },
...available.map((s) => ({ value: s.id, label: s.name || s.id })),
...available.map((s) => ({ value: s.id, label: s.name || s.id, kind: sandboxKind(s) })),
];
if (selected && !available.some((s) => s.id === selected)) {
options.push({
Expand Down Expand Up @@ -49,6 +69,7 @@ export default function SandboxPicker({ chat, onCreate }) {
chat.sandboxes,
project,
chat.sandboxProfileId,
{ userId: chat.user?.id, runnerId: chat.conversationRunnerId, machines: chat.machines },
);
const label =
options.find((o) => o.value === chat.sandboxProfileId)?.label ||
Expand All @@ -58,7 +79,7 @@ export default function SandboxPicker({ chat, onCreate }) {
.map((o) => ({
id: o.value,
label: o.label,
description: o.value ? "" : "按要改的代码自动选择,拿不准时用平台通用 Docker",
description: o.value ? SANDBOX_KIND_LABELS[o.kind] : "按 AI 助手设置里倾向的沙箱和任务需要自动选择",
icon: o.value ? "terminal" : "folder",
}));
return (
Expand Down
2 changes: 0 additions & 2 deletions chatbot/src/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const entities = {
assistant_tasks: "助手定时任务",
runs: "运行",
issues: "需求",
environments: "环境",
sandboxes: "沙箱",
dockerfiles: "Dockerfile",
executors: "执行器",
};
const verbs = {
Expand Down
1 change: 1 addition & 0 deletions chatbot/src/useChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ export function useChat() {
workspaceExecution,
workspaceExecutionError,
...executionMachines,
conversationRunnerId: runnerId,
selectSandbox,
models: executorModels,
executor,
Expand Down
8 changes: 8 additions & 0 deletions chatbot/tests/native-approval.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ test("shows an external MCP tool and the arguments being approved", async () =>
fireEvent.click(screen.getByRole("button", { name: "拒绝" }));
await waitFor(() => expect(writeMock).toHaveBeenCalledWith("/api/assistant/sessions/chat1/native-approvals/mcp1", { decision: "deny" }));
});

test("labels a local workspace action as an unisolated action on the owner's machine", async () => {
apiMock.mockResolvedValue([{ id: "l1", actorId: 1, tool: "Bash", summary: "执行命令", local: true, input: { command: "npm test" } }]);
render(<NativeApprovalPanel chat={chat} />);
expect(await screen.findByText("批准本机操作:执行命令")).toBeInTheDocument();
expect(screen.getByText(/直接在你的执行机器上执行,没有沙箱隔离/)).toBeInTheDocument();
expect(screen.queryByText(/会写入外部系统/)).not.toBeInTheDocument();
});
16 changes: 15 additions & 1 deletion chatbot/tests/sandbox-picker.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ describe("conversation environment selection", () => {
expect(missing).toMatchObject({ value: "deleted", disabled: true });
});

test("lists native sandboxes and the user's local sandbox on its own machine", () => {
const rows = [
{ id: "mine", name: "我的 Mac", projectId: "p", driver: "local", runnerId: "mac" },
{ id: "peer", name: "同事的机器", projectId: "p", driver: "local", runnerId: "peer-mac" },
{ id: "light", name: "轻量沙箱", projectId: "p", driver: "native" },
...sandboxes,
];
const machines = [{ id: "mac", ownerUserId: 7 }, { id: "peer-mac", ownerUserId: 8 }];
const values = (access) => conversationSandboxOptions(rows, project, "", access).map((o) => o.value);
expect(values({ userId: 7, runnerId: "mac", machines })).toEqual(["", "business", "shared", "light", "mine"]);
expect(values({ userId: 7, runnerId: "", machines })).toEqual(["", "business", "shared", "light"]);
expect(values({ userId: 8, runnerId: "mac", machines })).toEqual(["", "business", "shared", "light"]);
});

test("a task conversation shows the task environment", () => {
render(<SandboxPicker chat={{
projectId: "p", projects: [project],
Expand All @@ -62,7 +76,7 @@ describe("conversation environment selection", () => {
trigger.getBoundingClientRect = () => ({top:500,bottom:528,left:200,right:450,width:250,height:28});
const user = userEvent.setup();
await user.click(trigger);
await user.click(screen.getByRole("option", { name: "PHP 业务环境" }));
await user.click(screen.getByRole("option", { name: /^PHP 业务环境/ }));
expect(select).toHaveBeenCalledWith("business");
});
});
1 change: 0 additions & 1 deletion cmd/agentflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func main() {
}
log.Printf("storage driver=%v database=%v role=%s", s.StorageInfo()["driver"], s.StorageInfo()["database"], role)
e := engine.New(s, runtime.NewManagerWithLimit(root, *workerConcurrency))
runtime.PrebuildIsolatedImage()
host, _ := os.Hostname()
instanceID := strings.TrimSpace(os.Getenv("AGENTFLOW_INSTANCE_ID"))
if instanceID == "" {
Expand Down
1 change: 0 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ services:
AGENTFLOW_PREVIEW_PUBLIC_URL: ${AGENTFLOW_PREVIEW_PUBLIC_URL:-}
AGENTFLOW_PLATFORM_MCP_URL: ${AGENTFLOW_PLATFORM_MCP_URL:-http://platform:8080}
AGENTFLOW_DOCKER_NETWORK: ${COMPOSE_PROJECT_NAME:-loopforge}_default
AGENTFLOW_LOCAL_SANDBOX: docker
AGENTFLOW_ISOLATED_IMAGE: ${LOOPFORGE_IMAGE:-ghcr.io/tencent/loopforge:0.4.0}
HOME: ${LOOPFORGE_DATA_DIR:?Run scripts/configure.sh first}/home
AGENTFLOW_RUNNER_BINARY: /app/bin/agentflow-runner-{os}-{arch}
Expand Down
Loading
Loading