flyspace-cli 0.1.47 → 0.1.49
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.
- package/dist/{chunk-F5CXKDZV.js → chunk-HTFQL66T.js} +5 -7
- package/dist/{chunk-ETFEQSMF.js → chunk-PIAF4FJX.js} +1 -1
- package/dist/{chunk-AMA7LCCE.js → chunk-YPKJR5LT.js} +176 -95
- package/dist/cli.js +760 -242
- package/dist/index.js +2 -2
- package/dist/{threads-S4L5QX7T.js → threads-QAVO2Z4L.js} +89 -4
- package/package.json +1 -1
- package/system.capabilities.md +5 -4
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { createRequire as __flyspaceCreateRequire } from 'node:module';
|
|
|
3
3
|
const require = __flyspaceCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
startServer
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-YPKJR5LT.js";
|
|
7
|
+
import "./chunk-HTFQL66T.js";
|
|
8
8
|
export {
|
|
9
9
|
startServer
|
|
10
10
|
};
|
|
@@ -4,11 +4,12 @@ const require = __flyspaceCreateRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
listChannels,
|
|
6
6
|
moveThread
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PIAF4FJX.js";
|
|
8
8
|
import {
|
|
9
|
+
AGENT_AUTHOR,
|
|
9
10
|
getSupabaseClient,
|
|
10
11
|
postToDashboardChannel
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-HTFQL66T.js";
|
|
12
13
|
|
|
13
14
|
// src/mcp/servers/threads.ts
|
|
14
15
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -177,12 +178,89 @@ var TOOLS = [
|
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
];
|
|
181
|
+
var PERMISSION_TOOL = {
|
|
182
|
+
name: "request_permission",
|
|
183
|
+
description: "Internal: asks an admin in the thread to allow or deny a blocked tool call. Called by Claude Code itself as the permission prompt tool; never call it directly.",
|
|
184
|
+
inputSchema: {
|
|
185
|
+
type: "object",
|
|
186
|
+
properties: {
|
|
187
|
+
tool_name: { type: "string" },
|
|
188
|
+
input: { type: "object" },
|
|
189
|
+
tool_use_id: { type: "string" }
|
|
190
|
+
},
|
|
191
|
+
required: ["tool_name", "input"]
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var PERMISSION_POLL_MS = 2e3;
|
|
195
|
+
var DEFAULT_PERMISSION_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
196
|
+
function permissionTarget() {
|
|
197
|
+
const threadId = process.env["FLYSPACE_PERMISSION_THREAD_ID"];
|
|
198
|
+
const channelId = process.env["FLYSPACE_PERMISSION_CHANNEL_ID"];
|
|
199
|
+
return threadId && channelId ? { threadId, channelId } : null;
|
|
200
|
+
}
|
|
201
|
+
function describeToolInput(input) {
|
|
202
|
+
const pick = input["command"] ?? input["file_path"] ?? input["path"] ?? input["url"];
|
|
203
|
+
const text = typeof pick === "string" ? pick : JSON.stringify(input, null, 2);
|
|
204
|
+
return text.length > 1500 ? `${text.slice(0, 1500)}\u2026` : text;
|
|
205
|
+
}
|
|
206
|
+
async function requestPermission(target, toolName, input, timeoutMs = Number(process.env["FLYSPACE_PERMISSION_TIMEOUT_MS"]) || DEFAULT_PERMISSION_TIMEOUT_MS) {
|
|
207
|
+
const supabase = getSupabaseClient();
|
|
208
|
+
const expiresAt = new Date(Date.now() + timeoutMs);
|
|
209
|
+
const { data: request, error } = await supabase.from("permission_requests").insert({
|
|
210
|
+
channel_id: target.channelId,
|
|
211
|
+
thread_id: target.threadId,
|
|
212
|
+
tool_name: toolName,
|
|
213
|
+
input,
|
|
214
|
+
expires_at: expiresAt.toISOString()
|
|
215
|
+
}).select("id").single();
|
|
216
|
+
if (error || !request) throw new Error(`failed to create permission request: ${error?.message}`);
|
|
217
|
+
const requestId = request["id"];
|
|
218
|
+
const prompt = `The agent wants to use **${toolName}**:
|
|
219
|
+
|
|
220
|
+
\`\`\`
|
|
221
|
+
${describeToolInput(input)}
|
|
222
|
+
\`\`\`
|
|
223
|
+
|
|
224
|
+
[PERMISSION: ${requestId}]`;
|
|
225
|
+
const { data: reply } = await supabase.from("thread_replies").insert({ thread_id: target.threadId, author: AGENT_AUTHOR, body: prompt }).select("id").single();
|
|
226
|
+
const replyId = reply?.["id"] ?? null;
|
|
227
|
+
if (replyId) await supabase.from("permission_requests").update({ reply_id: replyId }).eq("id", requestId);
|
|
228
|
+
let status = "pending";
|
|
229
|
+
let decidedBy = null;
|
|
230
|
+
while (status === "pending" && Date.now() < expiresAt.getTime()) {
|
|
231
|
+
await new Promise((r) => setTimeout(r, PERMISSION_POLL_MS));
|
|
232
|
+
const { data } = await supabase.from("permission_requests").select("status, decided_by").eq("id", requestId).maybeSingle();
|
|
233
|
+
status = data?.["status"] ?? "pending";
|
|
234
|
+
decidedBy = data?.["decided_by"] ?? null;
|
|
235
|
+
}
|
|
236
|
+
if (status === "pending") {
|
|
237
|
+
const { data } = await supabase.from("permission_requests").update({ status: "expired" }).eq("id", requestId).eq("status", "pending").select("status");
|
|
238
|
+
if (data?.length) status = "expired";
|
|
239
|
+
else {
|
|
240
|
+
const { data: latest } = await supabase.from("permission_requests").select("status, decided_by").eq("id", requestId).maybeSingle();
|
|
241
|
+
status = latest?.["status"] ?? "expired";
|
|
242
|
+
decidedBy = latest?.["decided_by"] ?? null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const outcome = status === "allow" ? `\u2705 Allowed by @${decidedBy}` : status === "deny" ? `\u{1F6AB} Denied by @${decidedBy}` : "\u23F0 No answer in time, denied automatically";
|
|
246
|
+
if (replyId) {
|
|
247
|
+
await supabase.from("thread_replies").update({ body: prompt.replace(`[PERMISSION: ${requestId}]`, outcome) }).eq("id", replyId).eq("thread_id", target.threadId);
|
|
248
|
+
}
|
|
249
|
+
if (status === "allow") return { behavior: "allow", updatedInput: input };
|
|
250
|
+
return {
|
|
251
|
+
behavior: "deny",
|
|
252
|
+
message: status === "deny" ? `An admin denied ${toolName}. Do not retry it; find another way or explain what you needed.` : `Nobody answered the permission prompt for ${toolName} in time, so it was denied.`
|
|
253
|
+
};
|
|
254
|
+
}
|
|
180
255
|
async function startThreadsServer() {
|
|
181
256
|
const server = new Server(
|
|
182
257
|
{ name: "flyspace-threads", version: "1.0.0" },
|
|
183
258
|
{ capabilities: { tools: {} } }
|
|
184
259
|
);
|
|
185
|
-
|
|
260
|
+
const permission = permissionTarget();
|
|
261
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
262
|
+
tools: permission ? [...TOOLS, PERMISSION_TOOL] : TOOLS
|
|
263
|
+
}));
|
|
186
264
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
187
265
|
const args = request.params.arguments ?? {};
|
|
188
266
|
try {
|
|
@@ -208,7 +286,7 @@ async function startThreadsServer() {
|
|
|
208
286
|
const text = typeof args["text"] === "string" ? args["text"] : "";
|
|
209
287
|
if (!channelId || !text) throw new Error("channel_id and text are required");
|
|
210
288
|
const title = typeof args["title"] === "string" ? args["title"] : void 0;
|
|
211
|
-
const threadId = await postToDashboardChannel({ channelId, text, title });
|
|
289
|
+
const { threadId } = await postToDashboardChannel({ channelId, text, title });
|
|
212
290
|
return { content: [{ type: "text", text: `Created thread ${threadId}.` }] };
|
|
213
291
|
}
|
|
214
292
|
if (request.params.name === "post_reply") {
|
|
@@ -225,6 +303,12 @@ async function startThreadsServer() {
|
|
|
225
303
|
await moveThread(threadId, toChannelId);
|
|
226
304
|
return { content: [{ type: "text", text: `Moved thread ${threadId} to ${toChannelId}.` }] };
|
|
227
305
|
}
|
|
306
|
+
if (request.params.name === PERMISSION_TOOL.name && permission) {
|
|
307
|
+
const toolName = typeof args["tool_name"] === "string" ? args["tool_name"] : "a tool";
|
|
308
|
+
const input = args["input"] && typeof args["input"] === "object" ? args["input"] : {};
|
|
309
|
+
const result = await requestPermission(permission, toolName, input);
|
|
310
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
311
|
+
}
|
|
228
312
|
throw new Error(`unknown tool: ${request.params.name}`);
|
|
229
313
|
} catch (err) {
|
|
230
314
|
return {
|
|
@@ -240,6 +324,7 @@ export {
|
|
|
240
324
|
clampLimit,
|
|
241
325
|
formatHits,
|
|
242
326
|
formatThread,
|
|
327
|
+
requestPermission,
|
|
243
328
|
rowsToHits,
|
|
244
329
|
startThreadsServer
|
|
245
330
|
};
|
package/package.json
CHANGED
package/system.capabilities.md
CHANGED
|
@@ -55,14 +55,15 @@ Never run a foreground watcher / dev server / `tail -f` directly — even if the
|
|
|
55
55
|
|
|
56
56
|
Some background tasks DO finish on their own: a build, a deploy, a test suite, a long script, waiting on a file to appear. For these, NEVER say "I'll let you know when it's done" and then end your turn — you run headless, so once your turn ends there is no future "you" to follow up. That promise is a lie.
|
|
57
57
|
|
|
58
|
-
Instead, bake the notification into the command itself so the task pushes the result back when it finishes. You already know the current channel ID and thread id from the `[context: ...]` header at the top of the message — use those literal values, and pick the right command for where you are: `flyspace chat
|
|
58
|
+
Instead, bake the notification into the command itself so the task pushes the result back when it finishes. You already know the current channel ID and thread id from the `[context: ...]` header at the top of the message — use those literal values, and pick the right command for where you are: `flyspace chat wake --thread <THREAD_ID>` when the context says `chat channel=...` (a Workspace/dashboard thread — see Flyspace Workspace Tools below), or `flyspace slack post --channel <CHANNEL_ID> --thread <THREAD_TS>` when it's a Slack thread:
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
nohup bash -c 'if pnpm build; then S="✅ build 好了"; else S="❌ build 失敗,看 /tmp/build.log"; fi; flyspace chat
|
|
61
|
+
nohup bash -c 'if pnpm build; then S="✅ build 好了"; else S="❌ build 失敗,看 /tmp/build.log"; fi; flyspace chat wake --thread <THREAD_ID> --text "$S"' > /tmp/build.log 2>&1 & disown
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
- The task does not need to know Flyspace exists. YOU append the callback to the command you launch. The `--thread` value routes it back to this exact thread; multiple concurrent tasks each carry their own destination, so they never collide.
|
|
65
65
|
- Report both success and failure — capture the exit status and post a different message for each. Include the log path on failure.
|
|
66
|
+
- `chat wake` (Workspace threads only) posts the result AND starts a new turn for you in this thread with the result as its prompt, resuming this session, so you can carry on with the next step (fix the failure, continue the plan) without the user coming back. Write the `--text` so your future self can act on it: what finished, pass or fail, and where the log is. Slack threads have no wake: `flyspace slack post` only posts. Wakes are capped at 5 in a row without a human message.
|
|
66
67
|
- Then finish your turn immediately. Tell the user it's running in the background and will report back here when done. Do NOT block waiting for it.
|
|
67
68
|
- This detached pattern survives your turn ending (verified: `nohup … & disown` with redirected IO outlives the `claude` subprocess).
|
|
68
69
|
- This only works for tasks YOU launch. For external systems you don't control (someone else's CI, a third-party deploy, waiting on a human), you cannot push — say so, and use the polling pattern below instead.
|
|
@@ -77,12 +78,12 @@ Prefer the SAME detached shell pattern as push. It costs zero tokens per check (
|
|
|
77
78
|
nohup bash -c '
|
|
78
79
|
for i in $(seq 1 120); do # ALWAYS cap attempts — here 120 × 30s = 1h max
|
|
79
80
|
if curl -sfo /dev/null https://review-app.example.com; then
|
|
80
|
-
flyspace chat
|
|
81
|
+
flyspace chat wake --thread <THREAD_ID> --text "✅ review app 起來了 (等了 $((i*30))s)"
|
|
81
82
|
exit 0
|
|
82
83
|
fi
|
|
83
84
|
sleep 30
|
|
84
85
|
done
|
|
85
|
-
flyspace chat
|
|
86
|
+
flyspace chat wake --thread <THREAD_ID> --text "⏰ 等了 1 小時還沒好,停止監看 (/tmp/watch.log)。"
|
|
86
87
|
' > /tmp/watch.log 2>&1 & disown
|
|
87
88
|
```
|
|
88
89
|
|