feat: 薄殼原則落地 + seed 下沉 API + MCP 進主庫 + 部署一致性

壓測四橫向問題修正(docs 壓測報告):

① 薄殼原則成鐵律:能力長在 API,CLI/MCP/lib 只暴露
   - seed 下沉成 API 行為:cypher-executor POST /init/seed(一次灌 API+auth recipe),
     種子資料移到 server src/lib/api-recipe-seeds.ts,CLI 改薄殼一次呼叫
   - 解除 deployFullyOk 連坐 + init 補 seed auth recipe + update 補 seed/全 KV
   - registry SUBMISSIONS_KV 補進 REQUIRED_KV_NAMESPACES(修 20/21)

② MCP 統一帳號來源(單一 remote MCP + .env 切 MCP URL)
   - MCP 從 sibling repo 搬進 arcrun/mcp/(remote Worker,route 改 mcp.arcrun.dev)
   - config 加 mcp_url 三層解析 + getMcpUrl + DEFAULT_MCP_URL
   - 新增 acr mcp-setup:依 config 寫專案 .mcp.json(接案切資料夾自動切 MCP)
   - acr --version 改動態讀 package.json(根治漂移)

③ Deploy 一致性
   - tests/release.feature + scripts/check-release.sh
   - local-deploy.sh:CLI npm publish + auto patch bump + CHANGELOG
   - local-deploy.sh bash 3.2 相容修正(mapfile / 空陣列 set -u)
   - builtins/pnpm-lock.yaml

④ README self-hosted 同步現況(移除 R2 殘留、加 flag/env、多帳號)

CLI bump → 1.3.0

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
uncle6me-web
2026-06-06 15:45:35 +08:00
parent 5f381a44a6
commit 3e65e22775
58 changed files with 8608 additions and 74 deletions
+84
View File
@@ -0,0 +1,84 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { Env } from "../types.js";
import { kbdbFetch } from "../lib/kbdb-client.js";
interface ActionLogSlots {
org_namespace?: string;
action_type?: string;
payload?: string;
occurred_at?: string;
}
interface ActionLogRecord {
id: string;
slots?: ActionLogSlots;
}
export function registerGetGuiContext(server: McpServer, env: Env, orgNamespace: string) {
server.tool(
"u6u_get_gui_context",
"查詢用戶在 GUI 上的最近操作記錄,了解用戶的當前意圖與操作上下文。" +
"回傳最近 N 條操作記錄(從新到舊),以及用戶當前所在頁面和正在編輯的 Workflow ID。",
{
limit: z.number().int().min(1).max(100).default(20)
.describe("要取回的最近操作數量(預設 20,最大 100)"),
},
async ({ limit }) => {
try {
if (!env.KBDB) {
return {
content: [{ type: "text", text: "Error: KBDB service binding unavailable" }],
isError: true,
};
}
const resp = await kbdbFetch(
env,
`/records/search?template_id=tpl-action-log&user_id=${encodeURIComponent(orgNamespace)}&limit=${limit ?? 20}`
);
if (!resp.ok) {
return {
content: [{ type: "text", text: `Error querying action log: ${await resp.text()}` }],
isError: true,
};
}
const data = await resp.json<{ records: ActionLogRecord[] }>();
const records = data.records ?? [];
// 按 occurred_at 降序排列(最新在前)
const sorted = records
.map(r => ({
action_type: r.slots?.action_type ?? '',
payload: (() => {
try { return JSON.parse(r.slots?.payload ?? '{}'); } catch { return {}; }
})(),
occurred_at: r.slots?.occurred_at ?? '',
}))
.sort((a, b) => b.occurred_at.localeCompare(a.occurred_at))
.slice(0, limit ?? 20);
// 提取當前頁面和正在操作的 Workflow
const lastNavigate = sorted.find(a => a.action_type === 'NAVIGATE');
const lastOpenWorkflow = sorted.find(a => a.action_type === 'OPEN_WORKFLOW');
const context = {
recent_actions: sorted,
current_page: (lastNavigate?.payload as { page?: string })?.page ?? null,
open_workflow_id: (lastOpenWorkflow?.payload as { workflow_id?: string })?.workflow_id ?? null,
};
return {
content: [{ type: "text", text: JSON.stringify(context, null, 2) }],
};
} catch (error) {
return {
content: [{ type: "text", text: `Internal Error: ${error instanceof Error ? error.message : String(error)}` }],
isError: true,
};
}
}
);
}