flyspace-cli 0.1.49 → 0.1.50

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.
@@ -5764,7 +5764,16 @@ function richTextToMrkdwn(blocks) {
5764
5764
  return lines.length ? lines.join("\n") : null;
5765
5765
  }
5766
5766
  function bodyTextFor(msg) {
5767
- return richTextToMrkdwn(msg.blocks) ?? msg.text ?? "";
5767
+ return (richTextToMrkdwn(msg.blocks) ?? msg.text ?? "").replace(
5768
+ /<@([A-Z0-9]+)>/g,
5769
+ (m, id) => {
5770
+ const name = displayNameFor(id);
5771
+ return name === id ? m : `<@${id}|${name}>`;
5772
+ }
5773
+ );
5774
+ }
5775
+ function mentionedUserIds(msg) {
5776
+ return [...(richTextToMrkdwn(msg.blocks) ?? msg.text ?? "").matchAll(/<@([A-Z0-9]+)>/g)].map((m) => m[1]);
5768
5777
  }
5769
5778
  var SKIP_SUBTYPES = /* @__PURE__ */ new Set([
5770
5779
  "channel_join",
@@ -5813,6 +5822,7 @@ async function mirrorIncomingMessage(client, msg) {
5813
5822
  if (msg.subtype && SKIP_SUBTYPES.has(msg.subtype)) return;
5814
5823
  if (msg.subtype === "message_changed" || msg.subtype === "message_deleted") return;
5815
5824
  try {
5825
+ await ensureUsersCached(client, mentionedUserIds(msg));
5816
5826
  const body = bodyTextFor(msg);
5817
5827
  if (!body) return;
5818
5828
  const supabase = getSupabaseClient();
@@ -9394,6 +9404,7 @@ export {
9394
9404
  buildFilesPromptSection,
9395
9405
  syncSlackAvatars,
9396
9406
  bodyTextFor,
9407
+ mentionedUserIds,
9397
9408
  SKIP_SUBTYPES,
9398
9409
  tsToIso,
9399
9410
  authorFor,
package/dist/cli.js CHANGED
@@ -133,6 +133,7 @@ import {
133
133
  markWorkspaceProjectsSetup,
134
134
  markdownToBlocks,
135
135
  mcpStrictConfigEnabled,
136
+ mentionedUserIds,
136
137
  mimetypeSizeLimit,
137
138
  modelLabel,
138
139
  pinnedClaudeConfigDir,
@@ -196,7 +197,7 @@ import {
196
197
  warnOnBrokenChannelCwds,
197
198
  workspaceSkillsDir,
198
199
  writeSkillFile
199
- } from "./chunk-YPKJR5LT.js";
200
+ } from "./chunk-NR5FHLR2.js";
200
201
  import {
201
202
  firstReplyBody,
202
203
  getThread,
@@ -19497,7 +19498,7 @@ async function runAuthCmd(args) {
19497
19498
 
19498
19499
  // ../api/src/version.ts
19499
19500
  import { readFileSync as readFileSync8 } from "fs";
19500
- var CLI_VERSION = true ? "0.1.49" : devVersion();
19501
+ var CLI_VERSION = true ? "0.1.50" : devVersion();
19501
19502
  function isOlderVersion(a, b) {
19502
19503
  const parse = (v) => v.replace(/^v/, "").split("-")[0].split(".").map(Number);
19503
19504
  const [pa, pb] = [parse(a), parse(b)];
@@ -20125,7 +20126,7 @@ function npmEnv(target) {
20125
20126
  return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
20126
20127
  }
20127
20128
  async function runUpgrade() {
20128
- const current = "0.1.49";
20129
+ const current = "0.1.50";
20129
20130
  console.log(`Current version: ${current}`);
20130
20131
  console.log("Checking for updates...\n");
20131
20132
  try {
@@ -22642,7 +22643,7 @@ async function syncChannel(client2, channelId, channelName, own, oldest) {
22642
22643
  (m) => m.ts && m.text !== void 0 && !(m.subtype && SKIP_SUBTYPES.has(m.subtype))
22643
22644
  );
22644
22645
  const userIds = [...new Set(parents.map((m) => m.user).filter((v) => Boolean(v)))];
22645
- await ensureUsersCached(client2, userIds);
22646
+ await ensureUsersCached(client2, [...userIds, ...parents.flatMap(mentionedUserIds)]);
22646
22647
  await syncSlackAvatars(userIds);
22647
22648
  let threadCount = 0;
22648
22649
  let replyCount = 0;
@@ -23732,6 +23733,7 @@ var RELAYED_METHODS = [
23732
23733
  "onChatMessage",
23733
23734
  "isAgentThinking",
23734
23735
  "getAgentActivities",
23736
+ "getBackgroundTasks",
23735
23737
  "cancelAgentRun",
23736
23738
  "regenerateAgentRun",
23737
23739
  "listAgentRuns",
@@ -27012,7 +27014,10 @@ function emojifyShortcode(code) {
27012
27014
  return nameToEmoji[name] ?? SLACK_EMOJI_ALIASES[name] ?? code;
27013
27015
  }
27014
27016
  function resolveSlackTokens(text) {
27015
- return text.replace(/<@([A-Z0-9]+)(?:\|[^>]*)?>/g, (_m, id) => `@${getLocalCache().displayNameFor(id)}`).replace(/<#([A-Z0-9]+)\|([^>]+)>/g, (_m, _id, name) => `#${name}`).replace(/<#([A-Z0-9]+)>/g, (_m, id) => `#${getLocalCache().lookupChannelById(id)?.name ?? id}`).replace(/<!channel>/g, "@channel").replace(/<!here>/g, "@here").replace(/<!everyone>/g, "@everyone").replace(/<!subteam\^[A-Z0-9]+\|@?([^>]+)>/g, "@$1").replace(/<mailto:([^|>]+)\|([^>]+)>/g, (_m, addr, label2) => `[${label2}](mailto:${addr})`).replace(/<(https?:\/\/[^|>]+)\|([^>]+)>/g, (_m, url, label2) => `[${label2}](${url})`).replace(/:[a-z0-9_+-]+:/gi, emojifyShortcode);
27017
+ return text.replace(/<@([A-Z0-9]+)(?:\|([^>]*))?>/g, (_m, id, label2) => {
27018
+ const name = getLocalCache().displayNameFor(id);
27019
+ return `@${name === id && label2 ? label2 : name}`;
27020
+ }).replace(/<#([A-Z0-9]+)\|([^>]+)>/g, (_m, _id, name) => `#${name}`).replace(/<#([A-Z0-9]+)>/g, (_m, id) => `#${getLocalCache().lookupChannelById(id)?.name ?? id}`).replace(/<!channel>/g, "@channel").replace(/<!here>/g, "@here").replace(/<!everyone>/g, "@everyone").replace(/<!subteam\^[A-Z0-9]+\|@?([^>]+)>/g, "@$1").replace(/<mailto:([^|>]+)\|([^>]+)>/g, (_m, addr, label2) => `[${label2}](mailto:${addr})`).replace(/<(https?:\/\/[^|>]+)\|([^>]+)>/g, (_m, url, label2) => `[${label2}](${url})`).replace(/:[a-z0-9_+-]+:/gi, emojifyShortcode);
27016
27021
  }
27017
27022
  function slackMrkdwnToMarkdown(text) {
27018
27023
  return resolveSlackTokens(text).replace(/(?<![\w*])\*(?!\*)(\S(?:[^*\n]*?\S)?)\*(?!\*)(?![\w*])/g, "**$1**").replace(/(?<![\w~])~(?!~)(\S(?:[^~\n]*?\S)?)~(?!~)(?![\w~])/g, "~~$1~~").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
@@ -28834,6 +28839,7 @@ function createChatRouter(agent = {}) {
28834
28839
  onChatMessage: onMessage,
28835
28840
  isAgentThinking,
28836
28841
  getAgentActivities,
28842
+ getBackgroundTasks,
28837
28843
  cancelAgentRun,
28838
28844
  regenerateAgentRun,
28839
28845
  listAgentRuns
@@ -28857,7 +28863,8 @@ function createChatRouter(agent = {}) {
28857
28863
  "/threads/:id/agent-status",
28858
28864
  async (c) => c.json({
28859
28865
  thinking: await isAgentThinking?.(c.req.param("id")) ?? false,
28860
- activities: await getAgentActivities?.(c.req.param("id")) ?? []
28866
+ activities: await getAgentActivities?.(c.req.param("id")) ?? [],
28867
+ background: await getBackgroundTasks?.(c.req.param("id")) ?? []
28861
28868
  })
28862
28869
  );
28863
28870
  app.get("/agent-runs", async (c) => c.json({ threadIds: await listAgentRuns?.() ?? [] }));
@@ -35102,6 +35109,44 @@ ${recent.map((m) => `${m.author}: ${m.body}`).join("\n")}`;
35102
35109
  }
35103
35110
  }
35104
35111
 
35112
+ // src/dashboard/background-tasks.ts
35113
+ import { execFile as execFile2 } from "child_process";
35114
+ import { promisify as promisify2 } from "util";
35115
+ var execFileAsync = promisify2(execFile2);
35116
+ var WAKE_THREAD_RE = /chat wake\b.*?--thread[ =]['"]?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/;
35117
+ function parseEtime(etime) {
35118
+ const [days, rest] = etime.includes("-") ? etime.split("-") : ["0", etime];
35119
+ const parts = rest.split(":").map(Number);
35120
+ while (parts.length < 3) parts.unshift(0);
35121
+ const [h, m, s] = parts;
35122
+ return Number(days) * 86400 + h * 3600 + m * 60 + s;
35123
+ }
35124
+ function parseBackgroundTasks(psOutput, now = Date.now()) {
35125
+ const byThread = /* @__PURE__ */ new Map();
35126
+ for (const line of psOutput.split("\n")) {
35127
+ const m = /^\s*(\d+)\s+(\S+)\s+(.*)$/.exec(line);
35128
+ if (!m) continue;
35129
+ const [, pid, etime, command] = m;
35130
+ if (/^\S*node\b/.test(command)) continue;
35131
+ const threadId = WAKE_THREAD_RE.exec(command)?.[1];
35132
+ if (!threadId) continue;
35133
+ const list = byThread.get(threadId) ?? [];
35134
+ list.push({ pid: Number(pid), startedAt: now - parseEtime(etime) * 1e3 });
35135
+ byThread.set(threadId, list);
35136
+ }
35137
+ return byThread;
35138
+ }
35139
+ async function scanBackgroundTasks() {
35140
+ try {
35141
+ const { stdout } = await execFileAsync("ps", ["-axo", "pid=,etime=,command="], {
35142
+ maxBuffer: 16 * 1024 * 1024
35143
+ });
35144
+ return parseBackgroundTasks(stdout);
35145
+ } catch {
35146
+ return /* @__PURE__ */ new Map();
35147
+ }
35148
+ }
35149
+
35105
35150
  // src/dashboard/attachment-downloader.ts
35106
35151
  import { writeFile } from "fs/promises";
35107
35152
  import { join as join22 } from "path";
@@ -35263,6 +35308,7 @@ function loadChatAgentConfig() {
35263
35308
  }
35264
35309
  var RETRY_DELAY_MS = 3e3;
35265
35310
  var MAX_CONSECUTIVE_WAKES = 5;
35311
+ var BACKGROUND_SWEEP_MS = 6e4;
35266
35312
  var MISSED_MESSAGE_WINDOW_MS = 24 * 60 * 60 * 1e3;
35267
35313
  var MISSED_MESSAGE_THREAD_LIMIT = 100;
35268
35314
  var delay = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -35329,6 +35375,13 @@ var ChatAgent = class {
35329
35375
  * `MAX_CONSECUTIVE_WAKES` so a woken turn that launches another background
35330
35376
  * job (which wakes it again, and so on) can't loop forever unattended. */
35331
35377
  consecutiveWakes = /* @__PURE__ */ new Map();
35378
+ /** threadId → when its last wake arrived, so the sweep can tell a job that
35379
+ * reported back from one that died silently. */
35380
+ lastWakeAt = /* @__PURE__ */ new Map();
35381
+ /** threadId → background jobs seen waiting on it, and the profile that owns
35382
+ * the thread (the sweep runs outside any request's profile binding). */
35383
+ watchedTasks = /* @__PURE__ */ new Map();
35384
+ backgroundSweep;
35332
35385
  /** Workspace roots (workspaces.root_path) for path-prefix stripping in
35333
35386
  * activity labels. Fetched once per process — roots change ~never, and a
35334
35387
  * restart picks up edits. */
@@ -35421,10 +35474,48 @@ var ChatAgent = class {
35421
35474
  const asker = (data ?? []).find((r) => isHumanAuthor(r.author));
35422
35475
  if (!asker) return false;
35423
35476
  this.consecutiveWakes.set(threadId, wakes + 1);
35477
+ this.lastWakeAt.set(threadId, Date.now());
35424
35478
  console.log(`[chat-agent] woken by background task. thread=${threadId}`);
35425
35479
  this.handleMessage({ threadId, replyId, author: asker.author, body: text, woken: true });
35426
35480
  return true;
35427
35481
  }
35482
+ /** Background jobs still waiting to wake this thread (the "waiting on a
35483
+ * background task" status). */
35484
+ async backgroundTasks(threadId) {
35485
+ return (await scanBackgroundTasks()).get(threadId) ?? [];
35486
+ }
35487
+ /** After a run, start watching any job it left behind, so one that dies
35488
+ * without calling `chat wake` (killed, machine rebooted) still brings the
35489
+ * agent back instead of leaving the thread waiting forever. */
35490
+ async watchBackgroundTasks(threadId, profile) {
35491
+ const tasks = await this.backgroundTasks(threadId);
35492
+ if (tasks.length === 0) return;
35493
+ this.watchedTasks.set(threadId, { profile, firstSeen: Date.now(), tasks });
35494
+ this.backgroundSweep ??= setInterval(() => void this.sweepBackgroundTasks(), BACKGROUND_SWEEP_MS);
35495
+ this.backgroundSweep.unref?.();
35496
+ }
35497
+ async sweepBackgroundTasks() {
35498
+ const live = await scanBackgroundTasks();
35499
+ for (const [threadId, watched] of this.watchedTasks) {
35500
+ const tasks = live.get(threadId);
35501
+ if (tasks?.length) {
35502
+ watched.tasks = tasks;
35503
+ continue;
35504
+ }
35505
+ this.watchedTasks.delete(threadId);
35506
+ if ((this.lastWakeAt.get(threadId) ?? 0) >= watched.firstSeen) continue;
35507
+ console.log(`[chat-agent] background task ended without waking. thread=${threadId}`);
35508
+ const text = "Background task ended without reporting a result (it may have been killed or the machine restarted).";
35509
+ await runWithProfile(watched.profile, async () => {
35510
+ const { replyId } = await postToDashboardChannel({ threadId, text });
35511
+ await this.wake(threadId, replyId, text);
35512
+ }).catch((err) => console.error("[chat-agent] background wake failed:", err.message));
35513
+ }
35514
+ if (this.watchedTasks.size === 0 && this.backgroundSweep) {
35515
+ clearInterval(this.backgroundSweep);
35516
+ this.backgroundSweep = void 0;
35517
+ }
35518
+ }
35428
35519
  /**
35429
35520
  * Picks up messages nobody answered. `handleMessage` is fire-and-forget and
35430
35521
  * every bit of run state lives in this process, so a message is silently
@@ -36064,6 +36155,7 @@ ${msg.body}` : msg.body;
36064
36155
  store.close();
36065
36156
  this.activeRuns.delete(msg.threadId);
36066
36157
  notifyThinking(false);
36158
+ void this.watchBackgroundTasks(msg.threadId, owningProfile);
36067
36159
  }
36068
36160
  }
36069
36161
  /**
@@ -38575,9 +38667,9 @@ function startHostUpgrade() {
38575
38667
  }
38576
38668
 
38577
38669
  // src/dashboard/mcp-servers-host.ts
38578
- import { execFile as execFile2 } from "child_process";
38670
+ import { execFile as execFile3 } from "child_process";
38579
38671
  import { homedir as homedir11 } from "os";
38580
- import { promisify as promisify2 } from "util";
38672
+ import { promisify as promisify3 } from "util";
38581
38673
 
38582
38674
  // ../api/src/dashboard/mcp-servers.ts
38583
38675
  var LINE = /^(.+?): (.+) - [✔✘!✓✗] ?(.*)$/u;
@@ -38624,7 +38716,7 @@ function parseMcpList(output) {
38624
38716
  }
38625
38717
 
38626
38718
  // src/dashboard/mcp-servers-host.ts
38627
- var run4 = promisify2(execFile2);
38719
+ var run4 = promisify3(execFile3);
38628
38720
  async function listMcpServers() {
38629
38721
  const env = { ...process.env };
38630
38722
  const pinned = pinnedClaudeConfigDir(profileClaudeConfigDir());
@@ -38668,6 +38760,7 @@ function localAgentCallbacks(chatAgent) {
38668
38760
  onChatMessage: (msg) => chatAgent.handleMessage(msg),
38669
38761
  isAgentThinking: (threadId) => chatAgent.isThinking(threadId),
38670
38762
  getAgentActivities: (threadId) => chatAgent.getActivities(threadId),
38763
+ getBackgroundTasks: (threadId) => chatAgent.backgroundTasks(threadId),
38671
38764
  cancelAgentRun: (threadId) => chatAgent.cancel(threadId),
38672
38765
  regenerateAgentRun: (threadId, stoppedReplyId) => chatAgent.regenerate(threadId, stoppedReplyId),
38673
38766
  listAgentRuns: () => chatAgent.runningThreadIds(),
@@ -39596,7 +39689,7 @@ async function main() {
39596
39689
  break;
39597
39690
  case "-v":
39598
39691
  case "--version":
39599
- printRaw("0.1.49");
39692
+ printRaw("0.1.50");
39600
39693
  break;
39601
39694
  case "-h":
39602
39695
  case "--help":
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { createRequire as __flyspaceCreateRequire } from 'node:module';
3
3
  const require = __flyspaceCreateRequire(import.meta.url);
4
4
  import {
5
5
  startServer
6
- } from "./chunk-YPKJR5LT.js";
6
+ } from "./chunk-NR5FHLR2.js";
7
7
  import "./chunk-HTFQL66T.js";
8
8
  export {
9
9
  startServer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flyspace-cli",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "description": "AI-native headless community OS",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "private": false,