flyspace-cli 0.1.65 → 0.1.67

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.
@@ -3,12 +3,18 @@ import { createRequire as __flyspaceCreateRequire } from 'node:module';
3
3
  const require = __flyspaceCreateRequire(import.meta.url);
4
4
  import {
5
5
  LOCAL_ACTION_PATH,
6
+ SessionStore,
6
7
  __export,
8
+ getProfile,
7
9
  getSupabaseClient,
8
10
  loadEnvFiles,
11
+ paths,
12
+ postToDashboardChannel,
9
13
  readHostEndpoint,
14
+ refreshChannelRegistry,
15
+ resolveLogicalCwd,
10
16
  useHostDbWithoutCredentials
11
- } from "./chunk-O7OYNQND.js";
17
+ } from "./chunk-JH66T2SW.js";
12
18
 
13
19
  // ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
14
20
  var external_exports = {};
@@ -14614,6 +14620,38 @@ var moveThreadAction = defineContract({
14614
14620
  })
14615
14621
  ])
14616
14622
  });
14623
+ var renameChannelAction = defineContract({
14624
+ name: "rename_channel",
14625
+ description: "Rename a dashboard channel. The channel id, folder and threads are unchanged.",
14626
+ effect: "write",
14627
+ input: external_exports.object({
14628
+ channel_id: id.describe("The channel to rename (see list_channels)."),
14629
+ name: external_exports.string().trim().min(1).max(80).describe("The new channel name.")
14630
+ }),
14631
+ output: external_exports.object({ id: external_exports.string(), from: external_exports.string(), to: external_exports.string() })
14632
+ });
14633
+ var slackChannelId = external_exports.string().trim().regex(/^[CG][A-Z0-9]{6,}$/, "expected a Slack channel id such as C0123ABCD");
14634
+ var createChannelAction = defineContract({
14635
+ name: "create_channel",
14636
+ description: "Create a dashboard channel, optionally bound to a Slack channel. Its folder is <workspace>/<name> under the Host root, created on this Host. Returns the new channel id.",
14637
+ effect: "write",
14638
+ input: external_exports.object({
14639
+ name: external_exports.string().trim().regex(/^[a-z0-9][a-z0-9-]{0,79}$/, "lowercase letters, digits and dashes only").describe("Channel name, e.g. client-acme."),
14640
+ workspace: external_exports.string().optional().describe("Workspace slug. Defaults to the requester's workspace."),
14641
+ slack_channel_id: slackChannelId.optional().describe("Optional Slack channel id to sync with.")
14642
+ }),
14643
+ output: external_exports.object({ id: external_exports.string(), name: external_exports.string(), profile: external_exports.string(), cwd: external_exports.string() })
14644
+ });
14645
+ var setChannelSlackAction = defineContract({
14646
+ name: "set_channel_slack",
14647
+ description: "Bind a dashboard channel to a Slack channel, or unbind it (omit slack_channel_id). A Slack channel can be bound to only one dashboard channel.",
14648
+ effect: "write",
14649
+ input: external_exports.object({
14650
+ channel_id: id.describe("The dashboard channel (see list_channels)."),
14651
+ slack_channel_id: slackChannelId.optional().describe("Slack channel id; omit to unbind.")
14652
+ }),
14653
+ output: external_exports.object({ id: external_exports.string(), from: external_exports.string().nullable(), to: external_exports.string().nullable() })
14654
+ });
14617
14655
  var shareDocAction = defineContract({
14618
14656
  name: "share_doc",
14619
14657
  description: 'Publish a channel doc (Markdown or HTML) as a public link and return its URL, the same as "Copy public link" in the Docs pane. Re-sharing the same doc keeps the URL and updates the content.',
@@ -14684,6 +14722,9 @@ var ACTIONS = [
14684
14722
  createThreadAction,
14685
14723
  postReplyAction,
14686
14724
  moveThreadAction,
14725
+ renameChannelAction,
14726
+ createChannelAction,
14727
+ setChannelSlackAction,
14687
14728
  shareDocAction,
14688
14729
  openDocAction,
14689
14730
  setUiZoomAction,
@@ -14712,9 +14753,6 @@ async function callAction(action, input, requester) {
14712
14753
  return action.output.parse(body.value);
14713
14754
  }
14714
14755
 
14715
- // src/commands/docs.ts
14716
- import { isAbsolute, normalize, relative } from "path";
14717
-
14718
14756
  // src/store/chat-admin-store.ts
14719
14757
  async function listChannels(profile) {
14720
14758
  let query = getSupabaseClient().from("channels").select("id, name, profile, cwd");
@@ -14776,8 +14814,278 @@ function rowToThread(row) {
14776
14814
  };
14777
14815
  }
14778
14816
 
14779
- // src/commands/docs.ts
14817
+ // src/store/thread-move.ts
14818
+ async function moveThreadFully(threadId, toChannelId) {
14819
+ const thread = await getThread(threadId);
14820
+ if (!thread) throw new Error(`No thread with id ${threadId}.`);
14821
+ if (thread.channelId === toChannelId) return "unchanged";
14822
+ const channels = await listChannels();
14823
+ const to = channels.find((c) => c.id === toChannelId);
14824
+ if (!to) throw new Error(`No channel with id ${toChannelId}.`);
14825
+ const from = channels.find((c) => c.id === thread.channelId);
14826
+ const store = new SessionStore(paths.DB_FILE);
14827
+ try {
14828
+ await moveThread(thread.id, to.id);
14829
+ const counts = store.moveThread(`chat:${thread.channelId}`, `chat:${to.id}`, thread.id);
14830
+ return { from, to, ...counts, cwdChanged: !!from && from.cwd !== to.cwd };
14831
+ } finally {
14832
+ store.close();
14833
+ }
14834
+ }
14835
+
14836
+ // ../core/src/bridge-protocol.ts
14837
+ var HOST_SOCKET_PATH = "/internal/host-socket";
14838
+ var DEFAULT_DATA_API_PORT = 4757;
14839
+ var CALL_TIMEOUT_MS = 15e3;
14840
+ var DOCS_CALL_TIMEOUT_MS = 12e4;
14841
+ var MEMORY_EXTRACTION_TIMEOUT_MS = 165e3;
14842
+ var HEARTBEAT_INTERVAL_MS = 15e3;
14843
+ var HEARTBEAT_TIMEOUT_MS = HEARTBEAT_INTERVAL_MS * 2.5;
14844
+ var LOCAL_RELAY_PATH = "/internal/agent-call";
14845
+ var RELAYED_METHODS = [
14846
+ "onChatMessage",
14847
+ "isAgentThinking",
14848
+ "getAgentActivities",
14849
+ "getBackgroundTasks",
14850
+ "cancelAgentRun",
14851
+ "regenerateAgentRun",
14852
+ "listAgentRuns",
14853
+ "listBackgroundThreads",
14854
+ "wakeAgentRun"
14855
+ ];
14856
+ function encodeWireMessage(msg) {
14857
+ return JSON.stringify(msg);
14858
+ }
14859
+ function parseWireMessage(raw) {
14860
+ try {
14861
+ return JSON.parse(String(raw));
14862
+ } catch {
14863
+ return null;
14864
+ }
14865
+ }
14866
+
14867
+ // src/commands/chat.ts
14868
+ import { mkdirSync } from "fs";
14780
14869
  var USAGE = `
14870
+ Usage: flyspace chat <subcommand> [options]
14871
+
14872
+ Subcommands:
14873
+ channels [--profile-name <p>] List dashboard chat channels (id, name, cwd)
14874
+ threads <channel> [--limit <n>] List recent threads in a channel (default: 20)
14875
+ move <thread-id> --to <channel> Move a thread to another channel
14876
+ post --channel <c> --text <t> Start a new thread, or reply with --thread
14877
+ [--thread <id>] [--title <t>]
14878
+ create-channel <name> Create a dashboard channel (folder <workspace>/<name>)
14879
+ [--workspace <slug>] [--slack <slack-channel-id>]
14880
+ bind-slack <channel-id> <slack-id> Bind a channel to a Slack channel
14881
+ unbind-slack <channel-id> Remove a channel's Slack binding
14882
+ wake --thread <id> --text <t> Post a background task's result AND start a
14883
+ new agent turn on the thread to act on it
14884
+ [--about <t>] What the job waits for (shown in the thread)
14885
+
14886
+ Options:
14887
+ --to <name-or-id> Destination channel for "move"
14888
+ --limit <n> Max threads to list (default: 20)
14889
+ --profile-name <p> Only channels belonging to this profile
14890
+ --dry-run Show what "move" would do, change nothing
14891
+ --channel <name-or-id> Target channel for "post"
14892
+ --thread <id> Reply to this thread instead of starting one
14893
+ --text <t> Message body for "post"
14894
+ --title <t> Thread title for "post" (new threads only)
14895
+ `;
14896
+ function getArg(args, flag) {
14897
+ const idx = args.indexOf(flag);
14898
+ return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : void 0;
14899
+ }
14900
+ function label(thread, opener) {
14901
+ const text = thread.title ?? opener ?? "(empty)";
14902
+ const oneLine = text.replace(/\s+/g, " ").trim();
14903
+ return oneLine.length > 60 ? `${oneLine.slice(0, 59)}\u2026` : oneLine;
14904
+ }
14905
+ async function runChannels(args) {
14906
+ const channels = await listChannels(getArg(args, "--profile-name"));
14907
+ if (channels.length === 0) {
14908
+ console.log("No chat channels found.");
14909
+ return;
14910
+ }
14911
+ const width = Math.max(...channels.map((c) => c.name.length));
14912
+ for (const channel of channels) {
14913
+ console.log(`${channel.id} ${channel.name.padEnd(width)} ${channel.profile} ${channel.cwd}`);
14914
+ }
14915
+ }
14916
+ async function runThreads(args) {
14917
+ const nameOrId = args[0];
14918
+ if (!nameOrId) throw new Error("Usage: flyspace chat threads <channel> [--limit <n>]");
14919
+ const channel = await resolveChannel(nameOrId, getArg(args, "--profile-name"));
14920
+ const limit = Number(getArg(args, "--limit") ?? 20);
14921
+ const threads = await listThreads(channel.id, limit);
14922
+ if (threads.length === 0) {
14923
+ console.log(`No threads in ${channel.name}.`);
14924
+ return;
14925
+ }
14926
+ console.log(`${channel.name} (${channel.id}):`);
14927
+ for (const thread of threads) {
14928
+ const opener = thread.title ? void 0 : await firstReplyBody(thread.id);
14929
+ const when = thread.updatedAt.slice(0, 16).replace("T", " ");
14930
+ const replies = String(thread.replies).padStart(3);
14931
+ console.log(` ${thread.id} ${when} ${replies} replies ${label(thread, opener)}`);
14932
+ }
14933
+ }
14934
+ async function runMove(args) {
14935
+ const threadId = args[0];
14936
+ const to = getArg(args, "--to");
14937
+ if (!threadId || !to) {
14938
+ throw new Error("Usage: flyspace chat move <thread-id> --to <channel> [--dry-run]");
14939
+ }
14940
+ const thread = await getThread(threadId);
14941
+ if (!thread) throw new Error(`No thread with id ${threadId}.`);
14942
+ const destination = await resolveChannel(to, getArg(args, "--profile-name"));
14943
+ if (thread.channelId === destination.id) {
14944
+ console.log(`Thread is already in ${destination.name} \u2014 nothing to do.`);
14945
+ return;
14946
+ }
14947
+ const channels = await listChannels();
14948
+ const source = channels.find((c) => c.id === thread.channelId);
14949
+ const opener = thread.title ? void 0 : await firstReplyBody(thread.id);
14950
+ const from = source ? `${source.name} (${source.id})` : thread.channelId;
14951
+ console.log(`Thread: ${label(thread, opener)}`);
14952
+ console.log(` ${thread.replies} replies, last active ${thread.updatedAt.slice(0, 16)}`);
14953
+ console.log(`From: ${from}`);
14954
+ console.log(`To: ${destination.name} (${destination.id})`);
14955
+ if (args.includes("--dry-run")) {
14956
+ console.log("\n--dry-run: nothing changed.");
14957
+ return;
14958
+ }
14959
+ const moved = await moveThreadFully(thread.id, destination.id);
14960
+ if (moved === "unchanged") return;
14961
+ console.log(
14962
+ `
14963
+ Moved. Re-keyed ${moved.sessions} session(s), ${moved.modelOverrides} model override(s), ${moved.effortOverrides} effort override(s).`
14964
+ );
14965
+ if (moved.cwdChanged && source) {
14966
+ console.log(
14967
+ `
14968
+ Note: the channels have different working directories.
14969
+ ${source.cwd}
14970
+ ${destination.cwd}
14971
+ Files this thread created live in the old one, move them yourself if the
14972
+ thread still refers to them.`
14973
+ );
14974
+ }
14975
+ console.log("Reload the dashboard to see it in its new home.");
14976
+ }
14977
+ async function runPost(args) {
14978
+ const channelArg = getArg(args, "--channel");
14979
+ const threadArg = getArg(args, "--thread");
14980
+ const text = getArg(args, "--text");
14981
+ const title = getArg(args, "--title");
14982
+ if (!text || !channelArg && !threadArg) {
14983
+ throw new Error(
14984
+ "Usage: flyspace chat post --channel <c> --text <t> [--thread <id>] [--title <t>]"
14985
+ );
14986
+ }
14987
+ const channelId = threadArg ? void 0 : (await resolveChannel(channelArg, getArg(args, "--profile-name"))).id;
14988
+ const { threadId } = await postToDashboardChannel({
14989
+ channelId,
14990
+ threadId: threadArg,
14991
+ text,
14992
+ title
14993
+ });
14994
+ console.log(threadArg ? `Replied in thread ${threadId}.` : `Posted new thread ${threadId}.`);
14995
+ }
14996
+ async function runWake(args) {
14997
+ const threadId = getArg(args, "--thread");
14998
+ const text = getArg(args, "--text");
14999
+ if (!threadId || !text) throw new Error("Usage: flyspace chat wake --thread <id> --text <t>");
15000
+ const { replyId } = await postToDashboardChannel({ threadId, text });
15001
+ const endpoint = readHostEndpoint();
15002
+ if (!endpoint) {
15003
+ console.log(`Replied in thread ${threadId}, but no Host is running to wake the agent.`);
15004
+ return;
15005
+ }
15006
+ const res = await fetch(`http://127.0.0.1:${endpoint.port}${LOCAL_RELAY_PATH}`, {
15007
+ method: "POST",
15008
+ headers: { authorization: `Bearer ${endpoint.token}`, "content-type": "application/json" },
15009
+ body: JSON.stringify({ method: "wakeAgentRun", profile: getProfile(), args: [threadId, replyId, text] }),
15010
+ signal: AbortSignal.timeout(3e4)
15011
+ });
15012
+ if (!res.ok) throw new Error(`Replied in thread ${threadId}, but the Host answered ${res.status}`);
15013
+ const { value } = await res.json();
15014
+ console.log(
15015
+ value ? `Replied in thread ${threadId} and woke the agent.` : `Replied in thread ${threadId}; wake refused (too many wakes in a row without a human message).`
15016
+ );
15017
+ }
15018
+ async function createChannelOnHost(input, requester) {
15019
+ const ch = await callAction(createChannelAction, input, requester);
15020
+ await refreshChannelRegistry();
15021
+ mkdirSync(resolveLogicalCwd(ch.cwd), { recursive: true });
15022
+ return `Created #${ch.name} (${ch.id}) in ${ch.profile}, folder ${ch.cwd}${input.slack_channel_id ? `, synced with Slack ${input.slack_channel_id}` : ""}.`;
15023
+ }
15024
+ async function setChannelSlack(channelId, slackId) {
15025
+ const r = await callAction(setChannelSlackAction, {
15026
+ channel_id: channelId,
15027
+ ...slackId ? { slack_channel_id: slackId } : {}
15028
+ });
15029
+ return r.to ? `Bound channel ${r.id} to Slack ${r.to}${r.from && r.from !== r.to ? ` (was ${r.from})` : ""}.` : `Removed the Slack binding from channel ${r.id}${r.from ? ` (was ${r.from})` : ""}.`;
15030
+ }
15031
+ async function runChatCmd(args) {
15032
+ loadEnvFiles();
15033
+ useHostDbWithoutCredentials();
15034
+ const subcommand = args[0];
15035
+ const rest = args.slice(1);
15036
+ switch (subcommand) {
15037
+ case "channels":
15038
+ await runChannels(rest);
15039
+ break;
15040
+ case "threads":
15041
+ await runThreads(rest);
15042
+ break;
15043
+ case "move":
15044
+ await runMove(rest);
15045
+ break;
15046
+ case "post":
15047
+ await runPost(rest);
15048
+ break;
15049
+ case "wake":
15050
+ await runWake(rest);
15051
+ break;
15052
+ case "create-channel": {
15053
+ const name = rest[0];
15054
+ if (!name || name.startsWith("--")) throw new Error("Usage: flyspace chat create-channel <name>");
15055
+ const workspace = getArg(rest, "--workspace");
15056
+ const slack = getArg(rest, "--slack");
15057
+ console.log(
15058
+ await createChannelOnHost({
15059
+ name,
15060
+ ...workspace ? { workspace } : {},
15061
+ ...slack ? { slack_channel_id: slack } : {}
15062
+ })
15063
+ );
15064
+ break;
15065
+ }
15066
+ case "bind-slack":
15067
+ if (!rest[0] || !rest[1]) throw new Error("Usage: flyspace chat bind-slack <channel-id> <slack-id>");
15068
+ console.log(await setChannelSlack(rest[0], rest[1]));
15069
+ break;
15070
+ case "unbind-slack":
15071
+ if (!rest[0]) throw new Error("Usage: flyspace chat unbind-slack <channel-id>");
15072
+ console.log(await setChannelSlack(rest[0]));
15073
+ break;
15074
+ case "-h":
15075
+ case "--help":
15076
+ case void 0:
15077
+ console.log(USAGE);
15078
+ break;
15079
+ default:
15080
+ console.error(`Unknown subcommand: ${subcommand}`);
15081
+ console.log(USAGE);
15082
+ process.exit(1);
15083
+ }
15084
+ }
15085
+
15086
+ // src/commands/docs.ts
15087
+ import { isAbsolute, normalize, relative } from "path";
15088
+ var USAGE2 = `
14781
15089
  Usage: flyspace docs share <path> --channel <name-or-id> [--slug <name>]
14782
15090
 
14783
15091
  Publish a channel doc (Markdown or HTML) as a public link and print its URL,
@@ -14787,23 +15095,23 @@ var USAGE = `
14787
15095
  relative to the current directory, which the agent runs in)
14788
15096
  --slug <name> Custom URL: /share/<name>
14789
15097
  `;
14790
- function getArg(args, flag) {
15098
+ function getArg2(args, flag) {
14791
15099
  const idx = args.indexOf(flag);
14792
15100
  return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : void 0;
14793
15101
  }
14794
15102
  async function runDocsCmd(args) {
14795
15103
  const [sub, rawPath] = args;
14796
15104
  if (sub !== "share" || !rawPath || rawPath.startsWith("--")) {
14797
- console.log(USAGE);
15105
+ console.log(USAGE2);
14798
15106
  if (sub && sub !== "-h" && sub !== "--help") process.exitCode = 1;
14799
15107
  return;
14800
15108
  }
14801
- const channelRef = getArg(args, "--channel");
15109
+ const channelRef = getArg2(args, "--channel");
14802
15110
  if (!channelRef) throw new Error("--channel is required");
14803
15111
  loadEnvFiles();
14804
15112
  useHostDbWithoutCredentials();
14805
15113
  const channel = await resolveChannel(channelRef);
14806
- console.log(await shareDoc(channel.id, rawPath, getArg(args, "--slug")));
15114
+ console.log(await shareDoc(channel.id, rawPath, getArg2(args, "--slug")));
14807
15115
  }
14808
15116
  async function shareDoc(channelId, rawPath, slug) {
14809
15117
  const path = normalize(isAbsolute(rawPath) ? relative(process.cwd(), rawPath) : rawPath);
@@ -14812,18 +15120,26 @@ async function shareDoc(channelId, rawPath, slug) {
14812
15120
  }
14813
15121
 
14814
15122
  export {
14815
- listChannels,
14816
15123
  resolveChannel,
14817
- listThreads,
14818
- getThread,
14819
- firstReplyBody,
14820
- moveThread,
15124
+ HOST_SOCKET_PATH,
15125
+ DEFAULT_DATA_API_PORT,
15126
+ CALL_TIMEOUT_MS,
15127
+ DOCS_CALL_TIMEOUT_MS,
15128
+ MEMORY_EXTRACTION_TIMEOUT_MS,
15129
+ HEARTBEAT_TIMEOUT_MS,
15130
+ LOCAL_RELAY_PATH,
15131
+ RELAYED_METHODS,
15132
+ encodeWireMessage,
15133
+ parseWireMessage,
14821
15134
  searchThreadsAction,
14822
15135
  readThreadAction,
14823
15136
  listChannelsAction,
14824
15137
  createThreadAction,
14825
15138
  postReplyAction,
14826
15139
  moveThreadAction,
15140
+ renameChannelAction,
15141
+ createChannelAction,
15142
+ setChannelSlackAction,
14827
15143
  shareDocAction,
14828
15144
  openDocAction,
14829
15145
  setUiZoomAction,
@@ -14833,6 +15149,9 @@ export {
14833
15149
  ACTIONS,
14834
15150
  actionInputJsonSchema,
14835
15151
  callAction,
15152
+ createChannelOnHost,
15153
+ setChannelSlack,
15154
+ runChatCmd,
14836
15155
  runDocsCmd,
14837
15156
  shareDoc
14838
15157
  };