@taptap/cli 2026.11.11 → 2026.11.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +19 -0
  3. package/bin/taptap-cli-darwin-amd64 +0 -0
  4. package/bin/taptap-cli-darwin-arm64 +0 -0
  5. package/bin/taptap-cli-linux-amd64 +0 -0
  6. package/bin/taptap-cli-linux-arm64 +0 -0
  7. package/bin/taptap-cli-linux-riscv64 +0 -0
  8. package/bin/taptap-cli-windows-amd64.exe +0 -0
  9. package/bin/taptap-cli-windows-arm64.exe +0 -0
  10. package/checksums.txt +7 -7
  11. package/package.json +2 -2
  12. package/scripts/bot/agent-turn.mjs +35 -10
  13. package/scripts/bot/agents/cindy-permissions.mjs +32 -0
  14. package/scripts/bot/agents/cindy-plugin.mjs +148 -0
  15. package/scripts/bot/agents/cindy.mjs +37 -11
  16. package/scripts/bot/agents/codex-permissions.mjs +75 -0
  17. package/scripts/bot/agents/codex-server.mjs +2 -2
  18. package/scripts/bot/agents/codex.mjs +30 -15
  19. package/scripts/bot/agents/index.mjs +2 -0
  20. package/scripts/bot/cindy-plugin/README.md +73 -0
  21. package/scripts/bot/cindy-plugin/ghost.json +41 -0
  22. package/scripts/bot/cindy-plugin/main.js +55 -0
  23. package/scripts/bot/cindy-plugin/node/bridge.cjs +100 -0
  24. package/scripts/bot/cli.mjs +71 -13
  25. package/scripts/bot/entry.cjs +7 -1
  26. package/scripts/bot/listener.mjs +1 -1
  27. package/scripts/bot/permissions.mjs +97 -0
  28. package/scripts/bot/store.mjs +4 -0
  29. package/scripts/bot/turn-policy.mjs +23 -0
  30. package/scripts/bot/workspace-tools.mjs +120 -0
  31. package/skills/taptap-app-edit/references/app-edit-field-map.md +2 -0
  32. package/skills/taptap-app-edit/references/app-edit-fields-and-packages.md +8 -4
  33. package/skills/taptap-asset-library/references/asset-library-ingest.md +2 -2
  34. package/skills/taptap-asset-library/references/asset-library-search.md +1 -1
  35. package/skills/taptap-materials/SKILL.md +2 -2
  36. package/skills/taptap-official-message-push/SKILL.md +1 -1
  37. package/skills/taptap-official-message-push/references/push-runbook.md +11 -8
  38. package/skills/taptap-package-management/references/package-management-diagnostics.md +6 -1
  39. package/taptap-suite/references/taptap-app-edit/references/app-edit-field-map.md +2 -0
  40. package/taptap-suite/references/taptap-app-edit/references/app-edit-fields-and-packages.md +8 -4
  41. package/taptap-suite/references/taptap-asset-library/references/asset-library-ingest.md +2 -2
  42. package/taptap-suite/references/taptap-asset-library/references/asset-library-search.md +1 -1
  43. package/taptap-suite/references/taptap-materials/SKILL.md +2 -2
  44. package/taptap-suite/references/taptap-official-message-push/SKILL.md +1 -1
  45. package/taptap-suite/references/taptap-official-message-push/references/push-runbook.md +11 -8
  46. package/taptap-suite/references/taptap-package-management/references/package-management-diagnostics.md +6 -1
@@ -10,6 +10,7 @@ export { codexCommand, codexOverrides } from "./codex-server.mjs";
10
10
  import path from "node:path";
11
11
  import { spawn } from "node:child_process";
12
12
  import { run } from "../process.mjs";
13
+ import { codexPermissionConfiguration, verifyMcpConfiguration } from "./codex-permissions.mjs";
13
14
 
14
15
  const tools = [
15
16
  contextTool,
@@ -28,7 +29,7 @@ const instructions =
28
29
  "You are the local TapTap bot. Use the provided trigger. Call taptap_cli_get_content only if you need forum context. Reply in its language with taptap_cli_reply. The ancestor texts are context only. Never expose credentials, call the TapTap CLI through the shell, or choose another destination. If an operation has an uncertain outcome, do not repeat it.";
29
30
  async function runTurn({
30
31
  workspace,
31
- write: allowWrite,
32
+ permissions,
32
33
  model,
33
34
  options,
34
35
  signal,
@@ -101,15 +102,19 @@ async function runTurn({
101
102
  }
102
103
  const timer = setTimeout(() => fail(Error("Codex 轮次超时")), 15 * 60 * 1000);
103
104
  try {
104
- await withCodexServer({ workspace, options, allowWrite, signal, onMessage, onStop: fail }, async (rpc) => {
105
- const { config } = await rpc("config/read", { cwd: workspace });
105
+ const source = await withCodexServer({ workspace, options, signal }, rpc =>
106
+ rpc("config/read", { cwd: workspace, includeLayers: true }));
107
+ const policy = codexPermissionConfiguration(source, workspace, permissions);
108
+ await withCodexServer({ workspace, options, allowWrite: true, configOverrides: policy.overrides,
109
+ signal, onMessage, onStop: fail }, async (rpc) => {
110
+ await verifyMcpConfiguration(rpc, workspace, policy);
106
111
  const params = {
107
112
  cwd: workspace,
108
113
  approvalPolicy: "never",
109
- sandbox: allowWrite ? "workspace-write" : "read-only",
110
- developerInstructions: instructions,
111
- // Overriding a missing MCP entry would create an invalid transport.
112
- ...(config.mcp_servers?.node_repl && { config: { "mcp_servers.node_repl.enabled": false } }),
114
+ permissions: policy.profile,
115
+ developerInstructions: instructions + (permissions.mode === "read"
116
+ ? " Search and read knowledge in the current workspace using native tools. Do not modify files or request elevated permissions."
117
+ : " You may use native tools within the workspace and the owner's configured MCP permissions. Do not request elevated permissions."),
113
118
  ...(model ? { model: model } : {}),
114
119
  };
115
120
  const projectId = options?.projectId;
@@ -125,13 +130,10 @@ async function runTurn({
125
130
  if (
126
131
  t.approvalPolicy !== "never" ||
127
132
  path.resolve(t.cwd ?? t.thread.cwd ?? workspace) !== workspace ||
128
- (t.sandbox?.writableRoots || []).some(
129
- (root) => path.resolve(root) !== workspace,
130
- ) ||
131
- t.sandbox?.type !== (allowWrite ? "workspaceWrite" : "readOnly") ||
133
+ t.activePermissionProfile?.id !== policy.profile ||
132
134
  (previousThread && threadId !== previousThread)
133
135
  )
134
- throw Error("Codex 工作区权限未确认");
136
+ throw Error("Codex 未应用机器人目录权限,请升级 Codex 后重新连接");
135
137
  const inventory = await rpc("mcpServerStatus/list", {
136
138
  threadId,
137
139
  limit: 100,
@@ -141,10 +143,10 @@ async function runTurn({
141
143
  inventory.data?.some(
142
144
  (s) =>
143
145
  s.runtimeStatus !== "disabled" &&
144
- (s.tools?.length || Object.keys(s.tools || {}).length),
146
+ !Object.hasOwn(policy.mcp, s.name),
145
147
  )
146
148
  )
147
- throw Error("请禁用此 Codex 配置的外部 MCP 工具");
149
+ throw Error("Codex 加载了本次连接未配置的 MCP,已停止执行");
148
150
  saveThread(threadId);
149
151
  if (t.thread.projectId !== projectId) {
150
152
  const updated = await rpc("thread/metadata/update", { threadId, projectId });
@@ -193,6 +195,19 @@ async function checkReady(options) {
193
195
  if (result.code !== 0) throw Error("请先运行 taptap-cli bot codex-login");
194
196
  }
195
197
 
198
+ async function checkPermissions(workspace, options, permissions, model) {
199
+ const source = await withCodexServer({ workspace, options }, rpc =>
200
+ rpc("config/read", { cwd: workspace, includeLayers: true }));
201
+ const policy = codexPermissionConfiguration(source, workspace, permissions);
202
+ await withCodexServer({ workspace, options, allowWrite: true, configOverrides: policy.overrides }, async rpc => {
203
+ await verifyMcpConfiguration(rpc, workspace, policy);
204
+ const current = await rpc("thread/start", { cwd: workspace, ephemeral: true,
205
+ permissions: policy.profile, approvalPolicy: "never", model });
206
+ if (current.activePermissionProfile?.id !== policy.profile || current.approvalPolicy !== "never")
207
+ throw Error("Codex 不支持机器人目录权限,请升级 Codex 后重新连接");
208
+ });
209
+ }
210
+
196
211
  async function listModels(options, workspace) {
197
212
  await checkReady(options);
198
213
  return withCodexServer({ options, workspace }, async (rpc) => {
@@ -237,4 +252,4 @@ async function prepareProject(workspace, options) {
237
252
  return ensureProject(root, work => withCodexServer(server, work));
238
253
  }
239
254
 
240
- export const codex = { name: "codex", runTurn, checkReady, listModels, login, prepareProject };
255
+ export const codex = { name: "codex", runTurn, checkReady, checkPermissions, listModels, login, prepareProject };
@@ -4,10 +4,12 @@
4
4
  import { codex } from "./codex.mjs";
5
5
 
6
6
  import { cindy } from "./cindy.mjs";
7
+ import { cindyPlugin } from "./cindy-plugin.mjs";
7
8
 
8
9
  const agents = new Map([
9
10
  [codex.name, codex],
10
11
  [cindy.name, cindy],
12
+ [cindyPlugin.name, cindyPlugin],
11
13
  ]);
12
14
 
13
15
  export function getAgent(name = codex.name) {
@@ -0,0 +1,73 @@
1
+ # TapTap Bot — Cindy plugin integration
2
+
3
+ An additive `.cindy` plugin source package shipped with the CLI npm package.
4
+ The existing `--agent cindy` Local Agent connection remains available. This plugin
5
+ uses the public `cindy.tasks` SDK, never private Electron IPC or the Local Agent API.
6
+
7
+ ## Connect
8
+
9
+ 1. `taptap-cli bot cindy-plugin-source` locates the author source directory.
10
+ 2. Use Cindy's official `ghost_forge_pack` / `ghost_forge_install` workflow on this
11
+ directory. Review the own-task and resident Node permissions. No marketplace
12
+ publication is needed. Source inclusion in npm does not mean installation.
13
+ 3. In the plugin detail's task settings, choose the working directory and permission
14
+ ceiling. These remain Cindy-owned settings; the CLI cannot overwrite them.
15
+ 4. Run `taptap-cli bot models --agent cindy-plugin` and choose an actual model ID.
16
+ 5. Select native permissions explicitly. PUBLIC bots allow only `ask` (read-only prompt plus Host approval, not a filesystem sandbox). MEMBERS/PERSONAL allow `ask`, `auto`, or `bypassPermissions`. For example:
17
+ `taptap-cli bot connect --bot <ID> --reply --agent cindy-plugin --model <ID> --cindy-permission ask`.
18
+ Optionally add `--workspace <directory>` to verify that Cindy created the task
19
+ in that exact directory. A mismatch prevents sending; it does not change Cindy.
20
+ 6. Forum events become visible tasks titled from the current question; each reply
21
+ chain reuses its task. The CLI provides the authorized original post/parent chain,
22
+ waits for the exact run's completed output and submits through the ordinary
23
+ forum reply API. Forum moderation status still comes from that API.
24
+
25
+ ## Permissions and unsupported capabilities
26
+
27
+ `ask`, `auto`, `bypassPermissions` mean Cindy's default approval, automatic review
28
+ and full access. They are not aliases for Codex's workspace-only read/work. Ask/auto
29
+ may wait for approval in Cindy. The plugin never approves on the user's behalf.
30
+ The Host enforces its configured task permission ceiling. Existing task policy,
31
+ model/Harness and working directory are checked before each send; changed tasks
32
+ are not silently reconfigured or replaced.
33
+
34
+ Native tools and MCP use Cindy's own settings and authorization. The public API
35
+ does not guarantee workspace-only access, never-escalate execution or directory-only
36
+ MCP. PUBLIC bots require an explicit ask selection and a read-only workspace policy in every turn. This is a behavioral fallback plus Host approval, not a hard read-only boundary. For enforced file-tool boundaries use Codex read or the client-only link adapter. MEMBERS/PERSONAL require explicit initial
37
+ selection. The CLI checks authoritative scope every turn and during execution;
38
+ changes invalidate the grant and cancel only the current accepted run.
39
+
40
+ The original link mode supports `client-only` and `native` through its public
41
+ toolPolicy API. Native is full access without interactive approval. It does not
42
+ expose a custom task-title API. Neither mode invents unsupported Host parameters.
43
+
44
+ ## Verify and transport
45
+
46
+ Use the same onboarding flow as Codex and the Cindy link adapter: choose the
47
+ working directory, model and permissions once, then connect. Existing settings
48
+ are reused. The assistant handles commands and only asks for missing choices or
49
+ Host-required confirmation. Installation is needed only when the plugin is absent.
50
+ After connecting, send a message in the configuration page's **04 测试消息收发**
51
+ and verify the received event and actual reply in that thread. There is no separate
52
+ plugin self-test command or synthetic conversation in the product flow.
53
+
54
+ The Node bridge binds only 127.0.0.1, rejects browser origins and uses an owner-only
55
+ discovery file with a fresh bearer. It forwards only model/capability queries,
56
+ the documented own-task create/get/send/getRun/readMessages/cancel
57
+ operations. TapTap credentials and reply grants never enter Cindy. Only authorized
58
+ forum content enters the task. Stop uses the exact accepted run ID; uncertain sends
59
+ are not automatically repeated. After an abnormal worker crash, verify the old
60
+ process has exited before removing the stale discovery file and restarting.
61
+
62
+ ## Host evidence and verification limits
63
+
64
+ Installed Cindy 0.1.133 reports build source
65
+ `95e70d24407638cac83220f46f0751c42017fe1e`, unavailable in the public repository.
66
+ Its shipped manuals and public tag v0.1.133
67
+ (`4a068d08cf9ea6633f6ee48cea800944bf70f746`) agree on the APIs used. The live Local
68
+ Agent capabilities explicitly report nativeReadOnly:false and no task-title method.
69
+ The public tag is not claimed to be the exact installed build. Plugin operations
70
+ are checked at runtime. Local contract/transport tests do not prove installation,
71
+ actual Host model execution or RND forum delivery; report those separately.
72
+
73
+ Every new or continued turn includes its actual working directory, granted mode and MCP restrictions. `bot events` exposes the question title, visible task ID and observed run status. Queued/running does not prove an approval is pending; the hint asks the owner to inspect Cindy without automatically approving. Timeouts cancel only the accepted run and never automatically resend.
@@ -0,0 +1,41 @@
1
+ {
2
+ "schemaVersion": 3,
3
+ "id": "taptap-bot-preview",
4
+ "name": "TapTap Bot 插件接入",
5
+ "description": "通过 CLI 接收机器人的论坛事件,在 Cindy 可见任务中处理并回传回复。使用 Cindy 原生审批、工作目录和 MCP,不保证目录隔离;全论坛仅允许接入者明确选择默认审批,配合每轮只读提示词。接入后在配置页的 04「测试消息收发」中验证。",
6
+ "whenToUse": "接入 TapTap Bot 到 Cindy 插件任务,查询模型或检查连接能力。",
7
+ "version": "0.2.0",
8
+ "minCindyVersion": "0.1.133",
9
+ "entry": "main.js",
10
+ "launch": "resident",
11
+ "command": "taptap-bot-preview",
12
+ "showTaskPreferences": true,
13
+ "agent": {
14
+ "tasks": true
15
+ },
16
+ "node": {
17
+ "entry": "node/bridge.cjs",
18
+ "protocol": "json-rpc-stdio",
19
+ "lifecycle": "resident"
20
+ },
21
+ "tools": [
22
+ {
23
+ "name": "diagnose",
24
+ "description": "检查 Cindy 插件接口和 TapTap 权限兼容性。只读,不连接论坛。",
25
+ "parameters": {
26
+ "type": "object",
27
+ "properties": {},
28
+ "additionalProperties": false
29
+ }
30
+ },
31
+ {
32
+ "name": "models",
33
+ "description": "列出 Cindy 插件任务真实可用的模型与 Harness,不能根据模型名称猜 Harness。",
34
+ "parameters": {
35
+ "type": "object",
36
+ "properties": {},
37
+ "additionalProperties": false
38
+ }
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,55 @@
1
+ // Copyright (c) 2026 TapTap
2
+ // SPDX-License-Identifier: MIT
3
+ // Public Cindy plugin SDK only. No private Electron IPC or Local Agent API.
4
+ (() => {
5
+ let bridgeError;
6
+ const gap = "Cindy 使用原生任务审批和 MCP,不保证目录隔离,ask/auto/完全访问不等于 Codex read/work。全论坛仅允许明确选择 ask,使用每轮只读提示词+宿主审批;不是强制只读沙箱。";
7
+ async function node(method, params = {}) {
8
+ const result = await cindy.node.request({ method, params, timeoutMs: 30000 });
9
+ if (!result.ok) throw Error(result.message || "插件 Node 进程不可用");
10
+ return result.result;
11
+ }
12
+ async function capabilities() {
13
+ if (typeof cindy.tasks?.capabilities !== "function") throw Error("请升级到支持插件任务接口的 Cindy");
14
+ const caps = await cindy.tasks.capabilities();
15
+ return { protocol: 1, mode: "cindy-plugin", host: caps, executionPolicySupported: false,
16
+ supportedScopes: ["PUBLIC", "MEMBERS", "PERSONAL"], message: gap, ...(bridgeError ? { bridgeError } : {}) };
17
+ }
18
+ async function models() {
19
+ const caps = await capabilities();
20
+ if (!caps.host.operations?.includes("models")) throw Error("当前 Cindy 不支持插件模型查询");
21
+ return cindy.tasks.models();
22
+ }
23
+ async function dispatch(method, params, bridge = false) {
24
+ if (method === "capabilities" || method === "diagnose") return capabilities();
25
+ if (method === "models") return models();
26
+ // The authenticated local bridge exposes only the documented own-task API.
27
+ // No private IPC, generic Host calls, directory overrides or silent fallback.
28
+ const operations = { task_create: "create", task_get: "get", task_send: "send",
29
+ task_run: "getRun", task_messages: "readMessages", task_cancel: "cancel" };
30
+ if (bridge && Object.hasOwn(operations, method)) {
31
+ const { host } = await capabilities();
32
+ const operation = operations[method];
33
+ if (!host.operations?.includes(operation)) throw Error("Cindy 不支持插件任务操作:" + operation);
34
+ if (operation === "create" && (!host.createPermissionMode || !["ask", "auto", "bypassPermissions"].includes(params?.permissionMode)))
35
+ throw Error("创建任务需要宿主支持的明确权限档位");
36
+ return cindy.tasks[operation](params);
37
+ }
38
+ throw Error("不支持的插件方法");
39
+ }
40
+ cindy.onHostMessage(async msg => {
41
+ if (msg.type === "event" && msg.name === "node-notification" && msg.method === "bridge/request") {
42
+ const { id, method, params } = msg.params;
43
+ try { await node("bridge/result", { id, result: await dispatch(method, params, true) }); }
44
+ catch (error) { await node("bridge/result", { id, error: { message: error.message, code: error.code || "CINDY_PLUGIN_FAILED" } }); }
45
+ } else if (msg.type === "tool-call") {
46
+ try {
47
+ const result = await dispatch(msg.tool, msg.args ?? {});
48
+ cindy.send({ type: "tool-result", callId: msg.callId, ok: true, result });
49
+ } catch (error) {
50
+ cindy.send({ type: "tool-result", callId: msg.callId, ok: false, errorCode: "TAPTAP_PLUGIN_FAILED", message: error.message });
51
+ }
52
+ }
53
+ });
54
+ node("bridge/start").catch(error => { bridgeError = error.message; });
55
+ })();
@@ -0,0 +1,100 @@
1
+ // Copyright (c) 2026 TapTap
2
+ // SPDX-License-Identifier: MIT
3
+ const http = require("node:http");
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
6
+ const os = require("node:os");
7
+ const crypto = require("node:crypto");
8
+ const readline = require("node:readline");
9
+
10
+ const root = path.join(process.env.TAPTAP_CLI_CONFIG_DIR || path.join(os.homedir(), ".taptap-cli"), "bot", "cindy-plugin");
11
+ const discovery = path.join(root, "discovery.json");
12
+ const token = crypto.randomBytes(32).toString("hex");
13
+ const instance = crypto.randomUUID();
14
+ const pending = new Map();
15
+ let server, starting, discoveryFd;
16
+ const emit = value => process.stdout.write(JSON.stringify(value) + "\n");
17
+ const json = (response, status, value) => {
18
+ response.writeHead(status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
19
+ response.end(JSON.stringify(value));
20
+ };
21
+ async function start() {
22
+ if (starting) return starting;
23
+ starting = (async () => {
24
+ fs.mkdirSync(root, { recursive: true, mode: 0o700 });
25
+ if (fs.lstatSync(root).isSymbolicLink()) throw Error("插件发现目录不能是软链接");
26
+ // Never replace a running bridge or race another simultaneous startup.
27
+ try { discoveryFd = fs.openSync(discovery, "wx", 0o600); }
28
+ catch (error) {
29
+ if (error.code === "EEXIST") throw Error("插件发现文件已存在,请先停用旧插件;若曾异常退出,确认旧进程退出后移除 discovery.json 再重试");
30
+ throw error;
31
+ }
32
+ server = http.createServer(async (request, response) => {
33
+ if (request.method !== "POST" || request.url !== "/rpc" || request.headers.origin ||
34
+ request.headers.host !== "127.0.0.1:" + server.address().port || request.headers.authorization !== "Bearer " + token)
35
+ return json(response, 403, { error: { code: "FORBIDDEN", message: "拒绝未授权的插件接入" } });
36
+ if (pending.size >= 8) return json(response, 429, { error: { code: "BUSY", message: "插件请求过多,请稍后重试" } });
37
+ try {
38
+ const chunks = [];
39
+ let bytes = 0;
40
+ for await (const chunk of request) {
41
+ bytes += chunk.length;
42
+ if (bytes > 262144) return json(response, 413, { error: { code: "TOO_LARGE", message: "请求过大" } });
43
+ chunks.push(chunk);
44
+ }
45
+ const message = JSON.parse(Buffer.concat(chunks).toString("utf8"));
46
+ if (pending.size >= 8) return json(response, 429, { error: { code: "BUSY", message: "插件请求过多,请稍后重试" } });
47
+ if (message.instance !== instance || !["capabilities", "models", "task_create", "task_get", "task_send", "task_run", "task_messages", "task_cancel"].includes(message.method))
48
+ return json(response, 400, { error: { code: "INVALID_REQUEST", message: "不支持的插件请求" } });
49
+ const id = crypto.randomUUID();
50
+ const timeout = setTimeout(() => {
51
+ pending.delete(id);
52
+ if (!response.destroyed) json(response, 504, { error: { code: "OUTCOME_UNKNOWN", message: "插件处理结果不明,请保留原请求键核对" } });
53
+ }, 25000);
54
+ pending.set(id, { response, timeout });
55
+ response.on("close", () => { clearTimeout(timeout); pending.delete(id); });
56
+ emit({ jsonrpc: "2.0", method: "bridge/request", params: { id, method: message.method, params: message.params ?? {} } });
57
+ } catch { if (!response.headersSent) json(response, 400, { error: { code: "INVALID_REQUEST", message: "插件请求格式无效" } }); }
58
+ });
59
+ await new Promise((resolve, reject) => { server.once("error", reject); server.listen(0, "127.0.0.1", resolve); });
60
+ fs.writeFileSync(discoveryFd, JSON.stringify({ protocol: 1, instance, token, pid: process.pid, port: server.address().port }));
61
+ return { protocol: 1, discovery, instance };
62
+ })().catch(error => { stop(); throw error; });
63
+ return starting;
64
+ }
65
+ const lines = readline.createInterface({ input: process.stdin });
66
+ lines.on("line", async line => {
67
+ let request;
68
+ try {
69
+ request = JSON.parse(line);
70
+ if (request.id == null) return;
71
+ let result;
72
+ if (request.method === "bridge/start") result = await start();
73
+ else if (request.method === "bridge/result") {
74
+ const item = pending.get(request.params?.id);
75
+ if (item) {
76
+ clearTimeout(item.timeout);
77
+ pending.delete(request.params.id);
78
+ json(item.response, request.params.error ? 422 : 200,
79
+ request.params.error ? { error: request.params.error } : { result: request.params.result });
80
+ }
81
+ result = { accepted: Boolean(item) };
82
+ } else throw Error("不支持的 Node 方法");
83
+ emit({ jsonrpc: "2.0", id: request.id, result });
84
+ } catch (error) { if (request?.id != null) emit({ jsonrpc: "2.0", id: request.id, error: { code: -32000, message: error.message } }); }
85
+ });
86
+ function stop() {
87
+ for (const { response, timeout } of pending.values()) { clearTimeout(timeout); response.destroy(); }
88
+ pending.clear();
89
+ server?.close();
90
+ if (discoveryFd !== undefined) {
91
+ try {
92
+ if (fs.lstatSync(discovery).ino === fs.fstatSync(discoveryFd).ino) fs.unlinkSync(discovery);
93
+ } catch {}
94
+ fs.closeSync(discoveryFd);
95
+ discoveryFd = undefined;
96
+ }
97
+ }
98
+ lines.once("close", stop);
99
+ process.once("exit", stop);
100
+ process.once("SIGTERM", () => { stop(); process.exit(0); });
@@ -12,22 +12,34 @@ import { login, loginBinding, assertLoginBinding, tap, nativeCli, servers } from
12
12
  import { run } from "./process.mjs";
13
13
  import { getAgent } from "./agents/index.mjs";
14
14
  import { selectModel, saveModel } from "./models.mjs";
15
+ import { connectionScope, selectPermissions, permissionNotice } from "./permissions.mjs";
16
+ import { cindyModes } from "./agents/cindy-permissions.mjs";
15
17
 
16
18
  const help = `taptap-cli bot — TapTap 机器人长连接
17
19
  taptap-cli bot connect --bot 2 选择机器人并登录
18
20
  taptap-cli bot connect --bot 2 --reply --agent codex --model 模型ID --workspace . 接收事件并用 Codex 回复
19
21
  taptap-cli bot connect --bot 2 --reply --agent cindy --model 模型ID 在 Cindy 可见会话里处理论坛 @
20
- taptap-cli bot models --agent codex 列出模型,先让用户确认模型 ID
22
+ taptap-cli bot connect --bot 2 --reply --agent cindy-plugin --model 模型ID --cindy-permission ask 使用插件任务回复
23
+ taptap-cli bot models --agent codex 列出模型,向用户展示名称供选择
21
24
  taptap-cli bot models --agent cindy 列出 Cindy 可用模型
25
+ taptap-cli bot models --agent cindy-plugin 列出独立插件模式的模型与 Harness
26
+ taptap-cli bot cindy-plugin-source 查看随 npm 分发的插件源码位置
22
27
  taptap-cli bot cindy-login 允许 TapTap Bot 连接本机 Cindy
23
28
  taptap-cli bot codex-login 授权本机 Codex
24
- taptap-cli bot list [--profile NAME] 查看当前账号的机器人
29
+ taptap-cli bot permissions --bot 2 查询服务端确认的使用范围与可选权限
25
30
  taptap-cli bot status 所有本地实例
26
31
  taptap-cli bot events --bot 2 [--limit 10] 最近事件及回复回执
27
32
  taptap-cli bot stop --bot 2 停止指定实例
28
33
  --bot-name 昵称:为未返回昵称的机器人指定 Codex 项目名称中的昵称。
29
34
  选项:--profile NAME、--env production|rnd、--cli 绝对路径、--personal、
30
- --cindy-keepalive-minutes 分钟(默认 30)、--replace-epoch N、--foreground、--codex 可执行文件、--model 模型ID、--allow-workspace-write
35
+ --cindy-keepalive-minutes 分钟(默认 30)、--replace-epoch N、--foreground、--codex 可执行文件、--model 模型ID、--permissions read|work
36
+ Codex 首次连接:选定会话目录后确认 --permissions read(只读)或 work(修改目录文件、执行命令及联网)。
37
+ 全论坛社区机器人固定只读。指定成员共用接入者电脑;个人机器人仅本人 @ 进入自己的连接。
38
+ 社区机器人仅加载当前会话目录 .codex/config.toml 中的 MCP,不继承全局 MCP;需要时请在当前目录配置。
39
+ 运行中不弹审批,范围外操作拒绝。--allow-workspace-write 是 --permissions work 的兼容别名。
40
+ Cindy 链接版:--cindy-permission client-only(默认,可搜索和读取会话目录)或 native(原生工具与 MCP,完全访问且不弹审批)。
41
+ Cindy 插件版:--cindy-permission ask、auto 或 bypassPermissions,按 Cindy 原生审批执行;工作目录在插件详情配置。
42
+ Cindy 原生工具和 MCP 不保证目录隔离,不能用 --permissions read/work 冒充。全论坛可用链接版 client-only,或明确选择插件版 ask(只读提示词+宿主审批,不是目录沙箱)。
31
43
  首次 connect --reply 请加 --model 用户确认的模型ID。后续沿用已保存模型。
32
44
  换模型:先 stop --bot ID,再 connect --bot ID --reply --agent 名称 --model 新模型ID。
33
45
  共享机器人签发结果不明时,请先核对绑定,再用 connect --retry-issue 确认重新签发。
@@ -56,8 +68,8 @@ function config(v, requireBot = true) {
56
68
  throw Error("环境或 profile 无效");
57
69
  if (env === "rnd" && !v.cli && requireBot === false)
58
70
  throw Error("RND 登录需要 --cli 对应构建");
59
- if (v.agent === "cindy" && (v["allow-workspace-write"] || v.codex))
60
- throw Error("Cindy 论坛会话只开放文字回复");
71
+ if (cindyModes(v.agent).length && (v.permissions || v["allow-workspace-write"] || v.codex))
72
+ throw Error("Cindy 不支持 Codex read/work 配置,请使用 --cindy-permission 并核对宿主能力");
61
73
  const minutes = v["cindy-keepalive-minutes"];
62
74
  if (
63
75
  minutes !== undefined &&
@@ -82,18 +94,21 @@ function config(v, requireBot = true) {
82
94
  workspace,
83
95
  reply: !!v.reply,
84
96
  write: !!v["allow-workspace-write"],
97
+ permissionMode: v.permissions,
98
+ cindyPermission: v["cindy-permission"],
85
99
  model: v.model,
86
100
  replace: v["replace-epoch"],
87
101
  personal: !!v.personal,
88
102
  cli: v.cli && realpathSync(v.cli),
89
103
  agent: v.reply ? getAgent(v.agent).name : undefined,
90
104
  agentOptions:
91
- v.agent === "cindy"
105
+ cindyModes(v.agent).length
92
106
  ? {
93
107
  keepAliveMinutes:
94
108
  minutes === undefined ? undefined : Number(minutes),
95
109
  discovery:
96
110
  v["cindy-discovery"] && realpathSync(v["cindy-discovery"]),
111
+ ...(v.agent === "cindy-plugin" && workspace ? { expectedWorkspace: workspace } : {}),
97
112
  }
98
113
  : v.codex
99
114
  ? { executable: realpathSync(v.codex) }
@@ -137,7 +152,7 @@ function activeAgent(row) {
137
152
  const config = JSON.parse(row.config);
138
153
  return config.reply ? getAgent(config.agent).name : null;
139
154
  }
140
- function runningSummary(row, requestedAgent, requestedModel) {
155
+ function runningSummary(row, requestedAgent, requestedModel, requestedPermissions, workspace) {
141
156
  if (activeAgent(row) && !JSON.parse(row.config).model)
142
157
  throw Error("当前监听尚未确认模型,请先 stop,再让用户确认模型后带 --model 重新 connect");
143
158
  if (requestedAgent && activeAgent(row) !== requestedAgent)
@@ -146,6 +161,10 @@ function runningSummary(row, requestedAgent, requestedModel) {
146
161
  );
147
162
  if (requestedModel !== undefined && JSON.parse(row.config).model !== requestedModel)
148
163
  throw Error("监听器正在使用其他模型,请先 stop 当前实例,再带 --model 重新 connect");
164
+ const current = JSON.parse(row.config);
165
+ if ((requestedPermissions && current.permissions?.mode !== requestedPermissions) ||
166
+ (workspace && current.workspace !== workspace))
167
+ throw Error("监听器正在使用其他目录或权限,请先 stop 再重新 connect");
149
168
  return summary(row);
150
169
  }
151
170
  function summary(row) {
@@ -153,6 +172,7 @@ function summary(row) {
153
172
  instance: row.id,
154
173
  agent: activeAgent(row),
155
174
  model: JSON.parse(row.config).model ?? null,
175
+ permissions: JSON.parse(row.config).permissions ?? null,
156
176
  status: alive(row.pid)
157
177
  ? row.status
158
178
  : row.status === "failed"
@@ -192,7 +212,9 @@ export async function main(argv) {
192
212
  "agent",
193
213
  "cindy-discovery",
194
214
  "cindy-keepalive-minutes",
215
+ "cindy-permission",
195
216
  "model",
217
+ "permissions",
196
218
  "limit",
197
219
  "replace-epoch",
198
220
  ];
@@ -211,14 +233,19 @@ export async function main(argv) {
211
233
  ]),
212
234
  });
213
235
  if (v["bot-name"] !== undefined &&
214
- (cmd !== "connect" || !v.reply || v.agent === "cindy" || v.workspace || !v["bot-name"].trim()))
236
+ (cmd !== "connect" || !v.reply || cindyModes(v.agent).length || v.workspace || !v["bot-name"].trim()))
215
237
  throw Error("--bot-name 仅用于 Codex 的默认项目,请提供机器人昵称");
216
238
  if (v["retry-issue"] && (cmd !== "connect" || v.personal || v["replace-epoch"]))
217
239
  throw Error("--retry-issue 仅适用于共享机器人的 connect");
218
240
  if (v.model !== undefined && (cmd !== "connect" || !v.reply || !v.model.trim()))
219
241
  throw Error("--model 需要与 connect --reply 一起使用,请提供用户确认的模型 ID");
242
+ if (v.permissions !== undefined && (cmd !== "connect" || !v.reply ||
243
+ !["read", "work"].includes(v.permissions) || (v["allow-workspace-write"] && v.permissions !== "work")))
244
+ throw Error("--permissions 需要 connect --reply,值为 read 或 work,且不能与写入选项冲突");
245
+ if (v["cindy-permission"] !== undefined && (cmd !== "connect" || !v.reply || !cindyModes(v.agent).includes(v["cindy-permission"])))
246
+ throw Error("--cindy-permission 需要 connect --reply;cindy 使用 client-only/native,cindy-plugin 使用 ask/auto/bypassPermissions");
220
247
  if (cmd === "models") {
221
- if (!v.agent) throw Error("请使用 models --agent codex 或 models --agent cindy");
248
+ if (!v.agent) throw Error("请使用 models --agent codex、cindy 或 cindy-plugin");
222
249
  const agent = getAgent(v.agent);
223
250
  const options = {
224
251
  executable: v.codex && realpathSync(v.codex),
@@ -227,8 +254,10 @@ export async function main(argv) {
227
254
  const workspace = v.workspace ? realpathSync(v.workspace) : process.cwd();
228
255
  return output({ agent: agent.name, models: await agent.listModels(options, workspace) });
229
256
  }
230
- if (v.agent !== undefined && (cmd !== "connect" || !v.reply))
257
+ if (v.agent !== undefined && (cmd !== "permissions" && (cmd !== "connect" || !v.reply)))
231
258
  throw Error("--agent 需要与 connect --reply 一起使用");
259
+ if (cmd === "cindy-plugin-source") return output({ source: fileURLToPath(new URL("./cindy-plugin/", import.meta.url)),
260
+ status: "local-development", supportedScopes: ["PUBLIC", "MEMBERS", "PERSONAL"], runtimeVerified: false });
232
261
  if (cmd === "cindy-login")
233
262
  return getAgent("cindy").login({ discovery: v["cindy-discovery"] });
234
263
  if (cmd === "codex-login") {
@@ -244,6 +273,23 @@ export async function main(argv) {
244
273
  }
245
274
  return;
246
275
  }
276
+ if (cmd === "permissions") {
277
+ const c = config(v);
278
+ await login(c);
279
+ c.loginBinding = await loginBinding(c);
280
+ const scope = await connectionScope(c);
281
+ if (v.agent && v.agent !== "codex") {
282
+ const agent = getAgent(v.agent);
283
+ const modes = scope === "PUBLIC" ? (v.agent === "cindy" ? ["client-only"] : ["ask"]) : cindyModes(v.agent);
284
+ return output({ agent: v.agent, connection_scope: scope,
285
+ modes,
286
+ notice: "Cindy 原生权限不等于 Codex read/work;原生工具与 MCP 不保证仅访问会话目录。",
287
+ choices: modes.map(mode => ({ mode, notice: agent.permissionNotice({ scope, mode }) })) });
288
+ }
289
+ return output({ connection_scope: scope, modes: scope === "PUBLIC" ? ["read"] : ["read", "work"],
290
+ default: "read", notice: permissionNotice({ scope, mode: "read" }),
291
+ work_notice: scope === "PUBLIC" ? null : permissionNotice({ scope, mode: "work" }) });
292
+ }
247
293
  const db = store();
248
294
  try {
249
295
  if (cmd === "status")
@@ -263,7 +309,7 @@ export async function main(argv) {
263
309
  return output(
264
310
  db
265
311
  .prepare(
266
- "SELECT frame,at,ack,phase,reply,visibleSession FROM events WHERE id=? ORDER BY rowid DESC LIMIT ?",
312
+ "SELECT frame,at,ack,phase,reply,visibleSession,title,progress FROM events WHERE id=? ORDER BY rowid DESC LIMIT ?",
267
313
  )
268
314
  .all(inboxId(id, saved), limit)
269
315
  .map((r) => {
@@ -273,6 +319,8 @@ export async function main(argv) {
273
319
  event: data.event.eventId,
274
320
  source: data.event.sourceId,
275
321
  body: data.content?.current?.body,
322
+ ...(r.title ? { title: r.title } : {}),
323
+ ...(r.progress ? { progress: JSON.parse(r.progress) } : {}),
276
324
  ...(r.visibleSession ? { cindySessionId: r.visibleSession } : {}),
277
325
  ack: !!r.ack,
278
326
  phase: r.phase,
@@ -303,7 +351,7 @@ export async function main(argv) {
303
351
  if (cmd !== "connect") throw Error("未知命令,请运行 taptap-cli bot --help");
304
352
  if (alive(row?.pid)) {
305
353
  await assertLoginBinding(JSON.parse(row.config));
306
- return output(runningSummary(row, c.agent, c.model));
354
+ return output(runningSummary(row, c.agent, c.model, c.cindyPermission ?? c.permissionMode ?? (c.write ? "work" : undefined), c.workspace));
307
355
  }
308
356
  if (c.env === "rnd" && !c.cli) throw Error("RND 需要 --cli 指定 RND 构建");
309
357
  const listen = await loadListener();
@@ -315,10 +363,20 @@ export async function main(argv) {
315
363
  }
316
364
  if (c.reply) {
317
365
  const agent = getAgent(c.agent);
366
+ if (agent.name === "codex" || agent.selectPermissions) {
367
+ const scope = await connectionScope(c);
368
+ c.permissions = (agent.selectPermissions ?? selectPermissions)(c, scope, row && JSON.parse(row.config));
369
+ c.personal = scope === "PERSONAL";
370
+ delete c.permissionMode;
371
+ delete c.cindyPermission;
372
+ c.write = false;
373
+ console.error((agent.permissionNotice ?? permissionNotice)(c.permissions));
374
+ }
318
375
  c.model = selectModel(db, id, c, row && JSON.parse(row.config));
319
376
  const models = await agent.listModels(c.agentOptions, c.workspace);
320
377
  if (!models.some(model => model.id === c.model))
321
378
  throw Error("所选模型不可用:" + c.model + "。请运行 bot models --agent " + agent.name + ",让用户重新确认后使用 --model");
379
+ if (agent.checkPermissions) await agent.checkPermissions(c.workspace, c.agentOptions, c.permissions, c.model);
322
380
 
323
381
  if (agent.prepareProject) {
324
382
  const projectId = await agent.prepareProject(c.workspace, c.agentOptions);
@@ -341,7 +399,7 @@ export async function main(argv) {
341
399
  if (alive(row?.pid)) {
342
400
  if (JSON.parse(row.config).loginBinding !== c.loginBinding)
343
401
  throw Error("已有不同账号的实例,请先 stop");
344
- const result = runningSummary(row, c.agent, c.model);
402
+ const result = runningSummary(row, c.agent, c.model, c.permissions?.mode, c.workspace);
345
403
  db.exec("COMMIT");
346
404
  return output(result);
347
405
  }
@@ -6,5 +6,11 @@ module.exports = async function runBot(args) {
6
6
  throw new Error("taptap-cli bot requires built-in SQLite. Use Node.js 22.13+ LTS or a newer LTS.");
7
7
  }
8
8
  const bot = await import("./cli.mjs");
9
- return bot.main(args);
9
+ try {
10
+ return await bot.main(args);
11
+ } catch (error) {
12
+ if (error.code !== "BOT_PERMISSION_REQUIRED") throw error;
13
+ console.error("权限配置:" + error.message);
14
+ process.exitCode = 1;
15
+ }
10
16
  };
@@ -234,7 +234,7 @@ export async function listen(db, id, ticket) {
234
234
  if (!event || ctrl.signal.aborted) break;
235
235
  const phase = (value, reply = null) =>
236
236
  db
237
- .prepare("UPDATE events SET phase=?,reply=? WHERE id=? AND key=?")
237
+ .prepare("UPDATE events SET phase=?,reply=?,progress=NULL WHERE id=? AND key=?")
238
238
  .run(value, reply, inbox, event.key);
239
239
  const e = JSON.parse(event.frame).data.event;
240
240
  if (