feat(#11): CLI/MCP 薄殼對齊 — P0 run 死端點修 + P1 list 同源 + R4 防複發機制

P0 CLI run 改打 /webhooks/named/:name/trigger 真端點(原打 /webhooks/<name> 死端點 404)。
P1 CLI/MCP list 收斂到 GET /webhooks/named(KV 同源):
   - CLI list 停 CfKvClient 直連 KV,順手修 key 前綴 bug(原讀 workflow: 對不上部署的 {apiKey}:wf:)
     + self-hosted 不再需 CF API token。
   - MCP u6u_list_workflows 從讀 KBDB record 改讀 GET /webhooks/named(registry 簽名加 partnerToken)。
R4 防複發機制:
   - cli-mcp-capability-matrix.md(13 能力對照,docs/ gitignored 不進此 commit,僅本機)
   - thin-shell-smoke.sh(對真端點斷言非 404,本機手動跑非 CI/cron)
   - 機制自驗:注入故意死端點當場攔下、exit 1。

依賴關係:本批依賴 #8(webhooks-named GET 補 description/created_at 欄位、search/backfill 端點),
故疊在 feat/issue-8 branch 上、作獨立 commit。

⚠️ tsc 綠 = code done 非完成。端到端待 leo21c(CLI/MCP 真打通 200 非 404、smoke 對已部署 prod
全綠——目前 smoke 揭 #8 search/backfill 在 prod 仍 404=未部署)。P2 validate 收斂待 #10、
tag resource_id 語意債待方向①。#11 留 open。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
uncle6me-web
2026-06-27 19:36:58 +08:00
parent 558e80b4da
commit 5d38b599fd
5 changed files with 161 additions and 55 deletions
+26 -42
View File
@@ -1,68 +1,52 @@
/**
* acr list — 列出 USER_KV 中所有已上傳的 workflow
* acr list — 列出已部署的 workflow
*
* thin-shell-alignment P1issue #11):原本直連 CF KV 讀 `workflow:` 前綴(CfKvClient),
* 有兩個漂移:① 前綴對不上(部署寫 `{apiKey}:wf:` → 永遠列不到新部署)② 薄殼直碰底層儲存
* self-hosted 用戶需 CF API token 才能 list)。改走 cypher `GET /webhooks/named`KV 源,與
* MCP u6u_list_workflows 同源),薄殼不再直連 KV、key 前綴 bug 自然消失。
*/
import chalk from 'chalk';
import ora from 'ora';
import { loadConfig } from '../lib/config.js';
import { CfKvClient } from '../lib/cf-api.js';
import { loadConfig, getCypherExecutorUrl } from '../lib/config.js';
export async function cmdList(): Promise<void> {
const config = loadConfig();
const executorUrl = getCypherExecutorUrl(config);
if (!config.cloudflare_account_id || !config.cf_api_token) {
console.error(chalk.red('缺少 Cloudflare 設定,請執行 acr init'));
process.exit(1);
}
const namespaceId = config.mode === 'standard'
? config.user_kv_namespace_id!
: config.webhooks_kv_namespace_id!;
if (!namespaceId) {
console.error(chalk.red('缺少 KV Namespace ID,請執行 acr init'));
process.exit(1);
}
const kv = new CfKvClient({
accountId: config.cloudflare_account_id,
namespaceId,
apiToken: config.cf_api_token,
});
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
if (config.api_key) headers['X-Arcrun-API-Key'] = config.api_key;
const spinner = ora('讀取 workflow 清單').start();
try {
const keys = await kv.list('workflow:');
const res = await fetch(`${executorUrl}/webhooks/named`, { method: 'GET', headers });
if (!res.ok) {
spinner.fail(chalk.red(`讀取失敗(HTTP ${res.status}):${(await res.text()).slice(0, 200)}`));
process.exit(1);
}
const data = await res.json() as {
workflows: Array<{ name: string; description?: string; created_at?: string }>;
};
spinner.stop();
if (keys.length === 0) {
const workflows = data.workflows ?? [];
if (workflows.length === 0) {
console.log(chalk.yellow('\n 沒有已部署的 workflow。執行 acr push <workflow.yaml> 部署第一個。\n'));
return;
}
console.log(chalk.bold(`\n 已部署 ${keys.length} 個 workflow\n`));
console.log(chalk.bold(`\n 已部署 ${workflows.length} 個 workflow\n`));
for (const key of keys) {
const name = key.name.replace('workflow:', '');
// 嘗試讀取 workflow 定義取得 created_at
try {
const raw = await kv.get(key.name);
if (raw) {
const def = JSON.parse(raw) as { name: string; description?: string; created_at?: string };
const date = def.created_at ? new Date(def.created_at).toLocaleString('zh-TW') : '未知';
const desc = def.description ? chalk.gray(`${def.description}`) : '';
console.log(`${chalk.cyan(name.padEnd(25))} ${date}${desc}`);
} else {
console.log(`${chalk.cyan(name)}`);
}
} catch {
console.log(`${chalk.cyan(name)}`);
}
for (const wf of workflows) {
const date = wf.created_at ? new Date(wf.created_at).toLocaleString('zh-TW') : '未知';
const desc = wf.description ? chalk.gray(`${wf.description}`) : '';
console.log(`${chalk.cyan(wf.name.padEnd(25))} ${date}${desc}`);
}
console.log('');
} catch (e) {
spinner.fail(chalk.red(`KV 讀取失敗:${e instanceof Error ? e.message : e}`));
spinner.fail(chalk.red(`讀取失敗:${e instanceof Error ? e.message : e}`));
process.exit(1);
}
}
+3 -1
View File
@@ -97,9 +97,11 @@ export async function cmdRun(workflowName: string, options: RunOptions): Promise
}
// ── 玩法二:本機沒這個 YAML → 按名字打已 push 到 KV 的 workflow ───────────────
// thin-shell-alignment P0issue #11):原打 /webhooks/${name} 是死端點(404)。
// 真端點是 /webhooks/named/:name/triggerwebhooks-named.ts:279X-Arcrun-API-Key header)。
const spinner = ora(`執行 workflow "${workflowName}"`).start();
try {
const res = await fetch(`${executorUrl}/webhooks/${workflowName}`, {
const res = await fetch(`${executorUrl}/webhooks/named/${workflowName}/trigger`, {
method: 'POST',
headers,
body: JSON.stringify(inputContext),