@pmate/cli 0.21.0 → 0.21.1

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/index.js CHANGED
@@ -12659,16 +12659,23 @@ function readSessionToken() {
12659
12659
  preferredApp: DEFAULT_APP_ID
12660
12660
  }).token;
12661
12661
  }
12662
- function unwrapAgentResult(value) {
12662
+ function unwrapAgentResult(agentId, value) {
12663
12663
  if (!value || typeof value !== "object") {
12664
+ if (value == null) {
12665
+ throw new Error(`Agent ${agentId} returned no result`);
12666
+ }
12664
12667
  return value;
12665
12668
  }
12666
12669
  if ("content" in value && "type" in value) {
12667
- return value.content ?? null;
12670
+ const content = value.content;
12671
+ if (content == null) {
12672
+ throw new Error(`Agent ${agentId} returned empty envelope content`);
12673
+ }
12674
+ return content;
12668
12675
  }
12669
12676
  return value;
12670
12677
  }
12671
- var import_agent_sdk, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_HUB_BASE_URL, DEFAULT_NAMESPACE, DEFAULT_FROM, AgentLlmClient;
12678
+ var import_agent_sdk, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_HUB_BASE_URL, DEFAULT_NAMESPACE, DEFAULT_FROM, DEFAULT_AGENT_PROMPT_TIMEOUT_MS, AgentLlmClient;
12672
12679
  var init_AgentLlmClient = __esm({
12673
12680
  "src/llm/AgentLlmClient.ts"() {
12674
12681
  "use strict";
@@ -12678,6 +12685,7 @@ var init_AgentLlmClient = __esm({
12678
12685
  DEFAULT_AGENT_HUB_BASE_URL = "https://hub.pmate.chat";
12679
12686
  DEFAULT_NAMESPACE = "pmate-cli";
12680
12687
  DEFAULT_FROM = "pmate-cli";
12688
+ DEFAULT_AGENT_PROMPT_TIMEOUT_MS = 12e4;
12681
12689
  AgentLlmClient = class {
12682
12690
  constructor(options) {
12683
12691
  this.token = options?.token ?? readSessionToken();
@@ -12696,7 +12704,8 @@ var init_AgentLlmClient = __esm({
12696
12704
  async call(agentId, payload, options) {
12697
12705
  const client = new import_agent_sdk.AgentClient({
12698
12706
  baseUrl: options?.hubBaseUrl ?? this.hubBaseUrl,
12699
- agentService: this.agentService
12707
+ agentService: this.agentService,
12708
+ timeoutMs: DEFAULT_AGENT_PROMPT_TIMEOUT_MS
12700
12709
  });
12701
12710
  try {
12702
12711
  await client.login(options?.from ?? this.from, {
@@ -12706,7 +12715,7 @@ var init_AgentLlmClient = __esm({
12706
12715
  agentId,
12707
12716
  payload
12708
12717
  });
12709
- return unwrapAgentResult(result);
12718
+ return unwrapAgentResult(agentId, result);
12710
12719
  } finally {
12711
12720
  client.close();
12712
12721
  }
@@ -12721,8 +12730,8 @@ __export(index_exports, {
12721
12730
  parseCommandArgs: () => parseCommandArgs
12722
12731
  });
12723
12732
  module.exports = __toCommonJS(index_exports);
12724
- var import_node_fs16 = require("fs");
12725
- var import_node_path21 = __toESM(require("path"));
12733
+ var import_node_fs17 = require("fs");
12734
+ var import_node_path22 = __toESM(require("path"));
12726
12735
  var import_chalk4 = __toESM(require("chalk"));
12727
12736
 
12728
12737
  // src/cli.ts
@@ -17621,9 +17630,9 @@ ${indent}\`\`\``;
17621
17630
  static richTextToPlain(richText) {
17622
17631
  return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
17623
17632
  }
17624
- static async requestJson(path22, init) {
17633
+ static async requestJson(path23, init) {
17625
17634
  const token = this.getToken();
17626
- const response = await fetch(`${this.baseUrl}${path22}`, {
17635
+ const response = await fetch(`${this.baseUrl}${path23}`, {
17627
17636
  method: init.method,
17628
17637
  headers: {
17629
17638
  Authorization: `Bearer ${token}`,
@@ -18660,15 +18669,72 @@ var QuizCommandHandler = class {
18660
18669
 
18661
18670
  // src/commands/CollectCommandHandler.ts
18662
18671
  var import_playwright = require("playwright");
18672
+ var import_node_crypto4 = require("crypto");
18673
+ var import_node_fs11 = require("fs");
18674
+ var import_node_os6 = __toESM(require("os"));
18675
+ var import_node_path16 = __toESM(require("path"));
18676
+
18677
+ // src/collectStore.ts
18663
18678
  var import_node_crypto3 = require("crypto");
18664
18679
  var import_node_fs10 = require("fs");
18665
18680
  var import_node_os5 = __toESM(require("os"));
18666
18681
  var import_node_path15 = __toESM(require("path"));
18682
+ function resolveCollectTarget(input) {
18683
+ const endpoint = input.endpoint ?? (input.source === "cc" ? "http://localhost:9223" : "http://localhost:9222");
18684
+ const sourceKey = input.source ?? `endpoint-${(0, import_node_crypto3.createHash)("sha1").update(endpoint).digest("hex").slice(0, 8)}`;
18685
+ const rootDir = import_node_path15.default.join(import_node_os5.default.homedir(), ".pmate", "collect", sourceKey);
18686
+ return { sourceKey, endpoint, rootDir };
18687
+ }
18688
+ function toThreadKey(name) {
18689
+ const normalized = name.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g, "-").replace(/^-+|-+$/g, "");
18690
+ const base = normalized || "thread";
18691
+ const suffix = (0, import_node_crypto3.createHash)("sha1").update(name).digest("hex").slice(0, 8);
18692
+ return `${base}-${suffix}`;
18693
+ }
18694
+ async function readStoredThread(rootDir, threadKey) {
18695
+ const filePath = getThreadFilePath(rootDir, threadKey);
18696
+ try {
18697
+ const raw = await import_node_fs10.promises.readFile(filePath, "utf8");
18698
+ return JSON.parse(raw);
18699
+ } catch {
18700
+ return null;
18701
+ }
18702
+ }
18703
+ async function writeStoredThread(rootDir, thread) {
18704
+ const filePath = getThreadFilePath(rootDir, thread.threadKey);
18705
+ await import_node_fs10.promises.mkdir(import_node_path15.default.dirname(filePath), { recursive: true });
18706
+ await import_node_fs10.promises.writeFile(filePath, JSON.stringify(thread, null, 2) + "\n", "utf8");
18707
+ }
18708
+ async function writeStoredIndex(rootDir, index) {
18709
+ await import_node_fs10.promises.mkdir(rootDir, { recursive: true });
18710
+ const filePath = import_node_path15.default.join(rootDir, "index.json");
18711
+ await import_node_fs10.promises.writeFile(filePath, JSON.stringify(index, null, 2) + "\n", "utf8");
18712
+ }
18713
+ function mergeMessages(existing, incoming) {
18714
+ const seen = new Set(existing.map((message) => message.hash));
18715
+ const merged = [...existing];
18716
+ let added = 0;
18717
+ for (const message of incoming) {
18718
+ if (seen.has(message.hash)) {
18719
+ continue;
18720
+ }
18721
+ seen.add(message.hash);
18722
+ merged.push(message);
18723
+ added += 1;
18724
+ }
18725
+ return { messages: merged, added };
18726
+ }
18727
+ function getThreadFilePath(rootDir, threadKey) {
18728
+ return import_node_path15.default.join(rootDir, "threads", `${threadKey}.json`);
18729
+ }
18730
+
18731
+ // src/commands/CollectCommandHandler.ts
18667
18732
  var CollectCommandHandler = class {
18668
18733
  async handle(args) {
18669
18734
  let browser = null;
18670
18735
  try {
18671
- browser = await import_playwright.chromium.connectOverCDP(args.endpoint);
18736
+ const target = resolveCollectTarget(args);
18737
+ browser = await import_playwright.chromium.connectOverCDP(target.endpoint);
18672
18738
  const targetPage = await this.pickTargetPage(
18673
18739
  browser.contexts().flatMap((context) => context.pages())
18674
18740
  );
@@ -18677,36 +18743,20 @@ var CollectCommandHandler = class {
18677
18743
  }
18678
18744
  const { rows } = await this.locateThreadRows(targetPage);
18679
18745
  const threads = await this.extractThreads(rows);
18680
- if (args.mode === "list") {
18681
- if (args.json) {
18682
- ui.plain(JSON.stringify({ total: threads.length, threads }, null, 2));
18683
- return;
18684
- }
18685
- this.printThreadList(threads);
18686
- return;
18687
- }
18688
- const matched = this.findThread(threads, args.threadName || "");
18689
- if (!matched) {
18690
- throw new Error(`Thread not found: ${args.threadName}`);
18691
- }
18692
- await this.clickThreadRow(rows, matched);
18693
- await targetPage.waitForTimeout(1200);
18694
- const messages = await this.extractMessages(targetPage, matched.name);
18695
- if (args.json) {
18696
- ui.plain(
18697
- JSON.stringify(
18698
- {
18699
- thread: matched,
18700
- totalMessages: messages.length,
18701
- messages
18702
- },
18703
- null,
18704
- 2
18705
- )
18706
- );
18707
- return;
18708
- }
18709
- this.printThreadMessages(matched, messages);
18746
+ if (threads.length === 0) {
18747
+ throw new Error("No threads found in target page.");
18748
+ }
18749
+ const syncedAt = (/* @__PURE__ */ new Date()).toISOString();
18750
+ const results = [];
18751
+ for (const thread of threads) {
18752
+ await this.clickThreadRow(rows, thread);
18753
+ await targetPage.waitForTimeout(1200);
18754
+ const messages = await this.extractMessages(targetPage, thread.name);
18755
+ const result = await this.persistThread(target.rootDir, target, thread, messages, syncedAt);
18756
+ results.push(result);
18757
+ }
18758
+ await this.writeIndex(target.rootDir, target, results, syncedAt);
18759
+ this.printSyncSummary(target.sourceKey, target.rootDir, threads.length, results);
18710
18760
  } catch (error) {
18711
18761
  const message = error instanceof Error ? error.message : String(error);
18712
18762
  throw new Error(`collect failed: ${message}`);
@@ -18714,6 +18764,67 @@ var CollectCommandHandler = class {
18714
18764
  await browser?.close().catch(() => void 0);
18715
18765
  }
18716
18766
  }
18767
+ async persistThread(rootDir, target, thread, messages, syncedAt) {
18768
+ const threadKey = toThreadKey(thread.name);
18769
+ const existing = await readStoredThread(rootDir, threadKey);
18770
+ const incoming = messages.map((message) => ({
18771
+ hash: message.hash,
18772
+ time: message.time,
18773
+ sender: message.sender,
18774
+ content: message.content,
18775
+ links: [...message.links],
18776
+ images: [...message.images],
18777
+ collectedAt: syncedAt
18778
+ }));
18779
+ const merged = mergeMessages(existing?.messages ?? [], incoming);
18780
+ const stored = {
18781
+ source: target.sourceKey,
18782
+ endpoint: target.endpoint,
18783
+ threadKey,
18784
+ threadName: thread.name,
18785
+ preview: thread.preview,
18786
+ unread: thread.unread,
18787
+ lastMessageAt: thread.time,
18788
+ lastSyncedAt: syncedAt,
18789
+ messageCount: merged.messages.length,
18790
+ messages: merged.messages
18791
+ };
18792
+ await writeStoredThread(rootDir, stored);
18793
+ return {
18794
+ thread: stored,
18795
+ addedMessages: merged.added,
18796
+ updated: merged.added > 0 || !existing || existing.preview !== stored.preview || existing.unread !== stored.unread || existing.lastMessageAt !== stored.lastMessageAt
18797
+ };
18798
+ }
18799
+ async writeIndex(rootDir, target, results, syncedAt) {
18800
+ const threads = results.map(({ thread }) => ({
18801
+ threadKey: thread.threadKey,
18802
+ name: thread.threadName,
18803
+ unread: thread.unread,
18804
+ preview: thread.preview,
18805
+ lastMessageAt: thread.lastMessageAt,
18806
+ messageCount: thread.messageCount,
18807
+ lastSyncedAt: thread.lastSyncedAt
18808
+ })).sort((left, right) => left.name.localeCompare(right.name));
18809
+ const messageCount = threads.reduce((sum, thread) => sum + thread.messageCount, 0);
18810
+ await writeStoredIndex(rootDir, {
18811
+ source: target.sourceKey,
18812
+ endpoint: target.endpoint,
18813
+ lastSyncedAt: syncedAt,
18814
+ threadCount: threads.length,
18815
+ messageCount,
18816
+ threads
18817
+ });
18818
+ }
18819
+ printSyncSummary(sourceKey, rootDir, scannedThreads, results) {
18820
+ const updatedThreads = results.filter((result) => result.updated).length;
18821
+ const newMessages = results.reduce((sum, result) => sum + result.addedMessages, 0);
18822
+ ui.plain(`Synced source: ${sourceKey}`);
18823
+ ui.plain(`Threads scanned: ${scannedThreads}`);
18824
+ ui.plain(`Threads updated: ${updatedThreads}`);
18825
+ ui.plain(`New messages: ${newMessages}`);
18826
+ ui.plain(`Saved under: ${rootDir}`);
18827
+ }
18717
18828
  async pickTargetPage(pages) {
18718
18829
  let best = null;
18719
18830
  for (const page of pages) {
@@ -18730,7 +18841,7 @@ var CollectCommandHandler = class {
18730
18841
  async locateThreadRows(page) {
18731
18842
  const preferred = page.locator(".ReactVirtualized__Grid__innerScrollContainer").first();
18732
18843
  const preferredCount = await preferred.locator(":scope > *").count().catch(() => 0);
18733
- if (preferredCount >= 5) {
18844
+ if (preferredCount >= 1) {
18734
18845
  return { rows: preferred.locator(":scope > *") };
18735
18846
  }
18736
18847
  const seeds = [
@@ -18750,7 +18861,7 @@ var CollectCommandHandler = class {
18750
18861
  for (let i = 0; i < max; i += 1) {
18751
18862
  const rows = containers.nth(i).locator(":scope > *");
18752
18863
  const rowCount = await rows.count().catch(() => 0);
18753
- if (rowCount < 5 || rowCount > 500) {
18864
+ if (rowCount < 1 || rowCount > 500) {
18754
18865
  continue;
18755
18866
  }
18756
18867
  const textCount = await containers.nth(i).locator("text=/./").count().catch(() => 0);
@@ -18784,21 +18895,7 @@ var CollectCommandHandler = class {
18784
18895
  ) ?? "";
18785
18896
  result.push({ index: i, name, unread, preview, time });
18786
18897
  }
18787
- return result;
18788
- }
18789
- findThread(threads, name) {
18790
- const target = normalizeText(name).toLowerCase();
18791
- if (!target) {
18792
- return null;
18793
- }
18794
- const exact = threads.find((thread) => thread.name.toLowerCase() === target);
18795
- if (exact) {
18796
- return exact;
18797
- }
18798
- const contains = threads.find(
18799
- (thread) => thread.name.toLowerCase().includes(target) || target.includes(thread.name.toLowerCase())
18800
- );
18801
- return contains ?? null;
18898
+ return dedupeThreads(result);
18802
18899
  }
18803
18900
  async extractMessages(page, threadName) {
18804
18901
  const container = await this.locateMessageContainer(page);
@@ -18841,17 +18938,14 @@ var CollectCommandHandler = class {
18841
18938
  return messages;
18842
18939
  }
18843
18940
  async clickThreadRow(rows, matched) {
18844
- const exactInRows = rows.filter({ hasText: matched.name }).first();
18845
- const exactCount = await exactInRows.count().catch(() => 0);
18846
- if (exactCount > 0) {
18847
- const clicked2 = await this.tryClick(exactInRows);
18848
- if (clicked2) {
18941
+ const row = rows.nth(matched.index);
18942
+ const clicked = await this.tryClick(row);
18943
+ if (!clicked) {
18944
+ const exactInRows = rows.filter({ hasText: matched.name }).first();
18945
+ const exactCount = await exactInRows.count().catch(() => 0);
18946
+ if (exactCount > 0 && await this.tryClick(exactInRows)) {
18849
18947
  return;
18850
18948
  }
18851
- }
18852
- const fallback = rows.nth(matched.index);
18853
- const clicked = await this.tryClick(fallback);
18854
- if (!clicked) {
18855
18949
  throw new Error(`Failed to select thread row: ${matched.name}`);
18856
18950
  }
18857
18951
  }
@@ -18990,31 +19084,20 @@ var CollectCommandHandler = class {
18990
19084
  }
18991
19085
  return candidates[0] ?? "";
18992
19086
  }
18993
- printThreadList(threads) {
18994
- for (const thread of threads) {
18995
- const unread = thread.unread > 0 ? ` (${thread.unread})` : "";
18996
- const preview = thread.preview ? ` - ${thread.preview}` : "";
18997
- ui.plain(`- ${thread.name}${unread}${preview}`);
18998
- }
18999
- }
19000
- printThreadMessages(thread, messages) {
19001
- const unread = thread.unread > 0 ? thread.unread : messages.length;
19002
- ui.plain(`## ${thread.name} (${unread})`);
19003
- for (const message of messages) {
19004
- ui.plain("-");
19005
- ui.plain(` time: ${message.time ?? ""}`);
19006
- ui.plain(` sender: ${message.sender ?? ""}`);
19007
- ui.plain(` content: ${message.content}`);
19008
- ui.plain(` hash: ${message.hash}`);
19009
- ui.plain(
19010
- ` links: ${message.links.length > 0 ? message.links.join(", ") : ""}`
19011
- );
19012
- ui.plain(
19013
- ` images: ${message.images.length > 0 ? message.images.join(", ") : ""}`
19014
- );
19087
+ };
19088
+ function dedupeThreads(threads) {
19089
+ const seen = /* @__PURE__ */ new Set();
19090
+ const result = [];
19091
+ for (const thread of threads) {
19092
+ const key = `${thread.name}::${thread.preview}::${thread.time ?? ""}`;
19093
+ if (seen.has(key)) {
19094
+ continue;
19015
19095
  }
19096
+ seen.add(key);
19097
+ result.push(thread);
19016
19098
  }
19017
- };
19099
+ return result;
19100
+ }
19018
19101
  function normalizeText(value) {
19019
19102
  return value.replace(/\s+/g, " ").replace(/\u200B/g, "").trim();
19020
19103
  }
@@ -19027,22 +19110,46 @@ function computeMessageHash(threadName, message) {
19027
19110
  message.links.map(normalizeText).join("|"),
19028
19111
  message.images.map(normalizeText).join("|")
19029
19112
  ].join("||");
19030
- return (0, import_node_crypto3.createHash)("sha1").update(base).digest("hex").slice(0, 16);
19113
+ return (0, import_node_crypto4.createHash)("sha1").update(base).digest("hex").slice(0, 16);
19114
+ }
19115
+ function parseMessageText(rawText) {
19116
+ const text = normalizeText(rawText);
19117
+ if (!text) {
19118
+ return { time: null, sender: null, content: "" };
19119
+ }
19120
+ const timeMatch = text.match(/^(\d{1,2}:\d{2}\s?(?:AM|PM)?)\s+(.*)$/i) ?? text.match(/^(\d{1,2}\/\d{1,2}|\d{4}\/\d{1,2}\/\d{1,2})\s+(.*)$/);
19121
+ if (!timeMatch) {
19122
+ return { time: null, sender: null, content: text };
19123
+ }
19124
+ const time = timeMatch[1];
19125
+ const rest = normalizeText(timeMatch[2] ?? "");
19126
+ if (!rest) {
19127
+ return { time, sender: null, content: "" };
19128
+ }
19129
+ const senderMatch = rest.match(/^([^:]{1,80}):\s*(.*)$/);
19130
+ if (!senderMatch) {
19131
+ return { time, sender: null, content: rest };
19132
+ }
19133
+ return {
19134
+ time,
19135
+ sender: normalizeText(senderMatch[1] ?? "") || null,
19136
+ content: normalizeText(senderMatch[2] ?? "")
19137
+ };
19031
19138
  }
19032
19139
  async function toDisplayableImagePath(src) {
19033
- if (!import_node_path15.default.isAbsolute(src)) {
19140
+ if (!import_node_path16.default.isAbsolute(src)) {
19034
19141
  return src;
19035
19142
  }
19036
- const ext = import_node_path15.default.extname(src);
19143
+ const ext = import_node_path16.default.extname(src);
19037
19144
  if (ext) {
19038
19145
  return src;
19039
19146
  }
19040
19147
  try {
19041
- const stat = await import_node_fs10.promises.stat(src);
19148
+ const stat = await import_node_fs11.promises.stat(src);
19042
19149
  if (!stat.isFile()) {
19043
19150
  return src;
19044
19151
  }
19045
- const fh = await import_node_fs10.promises.open(src, "r");
19152
+ const fh = await import_node_fs11.promises.open(src, "r");
19046
19153
  try {
19047
19154
  const buf = Buffer.alloc(32);
19048
19155
  const { bytesRead } = await fh.read(buf, 0, 32, 0);
@@ -19051,17 +19158,17 @@ async function toDisplayableImagePath(src) {
19051
19158
  if (!guessedExt) {
19052
19159
  return src;
19053
19160
  }
19054
- const cacheDir = import_node_path15.default.join(
19055
- import_node_os5.default.homedir(),
19161
+ const cacheDir = import_node_path16.default.join(
19162
+ import_node_os6.default.homedir(),
19056
19163
  ".pmate",
19057
19164
  "messages",
19058
19165
  "images"
19059
19166
  );
19060
- await import_node_fs10.promises.mkdir(cacheDir, { recursive: true });
19061
- const base = (0, import_node_crypto3.createHash)("sha1").update(src).digest("hex");
19062
- const displayPath = import_node_path15.default.join(cacheDir, `${base}.${guessedExt}`);
19063
- await import_node_fs10.promises.rm(displayPath, { force: true }).catch(() => void 0);
19064
- await import_node_fs10.promises.copyFile(src, displayPath);
19167
+ await import_node_fs11.promises.mkdir(cacheDir, { recursive: true });
19168
+ const base = (0, import_node_crypto4.createHash)("sha1").update(src).digest("hex");
19169
+ const displayPath = import_node_path16.default.join(cacheDir, `${base}.${guessedExt}`);
19170
+ await import_node_fs11.promises.rm(displayPath, { force: true }).catch(() => void 0);
19171
+ await import_node_fs11.promises.copyFile(src, displayPath);
19065
19172
  return displayPath;
19066
19173
  } finally {
19067
19174
  await fh.close();
@@ -19085,40 +19192,10 @@ function guessImageExtension(header) {
19085
19192
  }
19086
19193
  return null;
19087
19194
  }
19088
- function parseMessageText(raw) {
19089
- if (!raw) {
19090
- return { time: null, sender: null, content: "" };
19091
- }
19092
- const timeMatches = raw.match(/\b\d{1,2}:\d{2}\s?(?:AM|PM)\b/gi) || [];
19093
- const time = timeMatches.length > 0 ? timeMatches[timeMatches.length - 1] : null;
19094
- let sender = null;
19095
- const chefSender = raw.match(/^(Chef\s+[A-Za-z0-9_-]+)/);
19096
- if (chefSender) {
19097
- sender = chefSender[1];
19098
- } else {
19099
- const simpleSender = raw.match(/^([A-Za-z][A-Za-z0-9._-]{1,30})/);
19100
- sender = simpleSender ? simpleSender[1] : null;
19101
- }
19102
- let content = raw;
19103
- if (sender && content.startsWith(sender)) {
19104
- content = content.slice(sender.length).trim();
19105
- }
19106
- if (time) {
19107
- const timeIdx = content.lastIndexOf(time);
19108
- if (timeIdx >= 0) {
19109
- content = content.slice(0, timeIdx).trim();
19110
- }
19111
- }
19112
- content = content.replace(
19113
- /QuoteReply|Forward|Save to Note|Select|Pin|Add To-Do|Info|Translate>English中文/g,
19114
- " "
19115
- ).replace(/Group Chat History|Chat History/g, " ").replace(/\s+/g, " ").trim();
19116
- return { time, sender, content };
19117
- }
19118
19195
 
19119
19196
  // src/commands/AgentCommandHandler.ts
19120
- var import_node_fs11 = require("fs");
19121
- var import_node_path16 = __toESM(require("path"));
19197
+ var import_node_fs12 = require("fs");
19198
+ var import_node_path17 = __toESM(require("path"));
19122
19199
  init_AgentLlmClient();
19123
19200
  init_sessionStore();
19124
19201
 
@@ -19126,7 +19203,7 @@ init_sessionStore();
19126
19203
  var STORE_LOG_VERSION = 1;
19127
19204
  var LOG_KIND_TABLE = 1e4;
19128
19205
  var LOG_KIND_MAPPING = 6003;
19129
- function createHash3() {
19206
+ function createHash4() {
19130
19207
  return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
19131
19208
  }
19132
19209
  function createDescriptor(input) {
@@ -19151,8 +19228,8 @@ function descriptorPathSegments(descriptor) {
19151
19228
  return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
19152
19229
  }
19153
19230
  function buildPathUrl(baseUrl, pathSegments, query) {
19154
- const path22 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
19155
- const url = new URL(path22, baseUrl);
19231
+ const path23 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
19232
+ const url = new URL(path23, baseUrl);
19156
19233
  if (query) {
19157
19234
  for (const [key, value] of Object.entries(query)) {
19158
19235
  url.searchParams.set(key, String(value));
@@ -19265,7 +19342,7 @@ var Namespace = class {
19265
19342
  },
19266
19343
  appendRow: async (data) => {
19267
19344
  const log = {
19268
- hash: createHash3(),
19345
+ hash: createHash4(),
19269
19346
  t: Date.now(),
19270
19347
  kind: LOG_KIND_TABLE,
19271
19348
  topic: descriptorToTopic(descriptor),
@@ -19277,7 +19354,7 @@ var Namespace = class {
19277
19354
  updateRow: async (data) => {
19278
19355
  const { id, ...value } = data;
19279
19356
  const log = {
19280
- hash: createHash3(),
19357
+ hash: createHash4(),
19281
19358
  t: Date.now(),
19282
19359
  kind: LOG_KIND_TABLE,
19283
19360
  topic: descriptorToTopic(descriptor),
@@ -19288,7 +19365,7 @@ var Namespace = class {
19288
19365
  },
19289
19366
  deleteRow: async (id) => {
19290
19367
  const log = {
19291
- hash: createHash3(),
19368
+ hash: createHash4(),
19292
19369
  t: Date.now(),
19293
19370
  kind: LOG_KIND_TABLE,
19294
19371
  topic: descriptorToTopic(descriptor),
@@ -19331,7 +19408,7 @@ var Namespace = class {
19331
19408
  },
19332
19409
  set: async (key, value) => {
19333
19410
  const log = {
19334
- hash: createHash3(),
19411
+ hash: createHash4(),
19335
19412
  t: Date.now(),
19336
19413
  kind: LOG_KIND_MAPPING,
19337
19414
  topic: descriptorToTopic(descriptor),
@@ -19342,7 +19419,7 @@ var Namespace = class {
19342
19419
  },
19343
19420
  delete: async (key) => {
19344
19421
  const log = {
19345
- hash: createHash3(),
19422
+ hash: createHash4(),
19346
19423
  t: Date.now(),
19347
19424
  kind: LOG_KIND_MAPPING,
19348
19425
  topic: descriptorToTopic(descriptor),
@@ -19535,6 +19612,24 @@ var AgentCommandHandler = class {
19535
19612
  this.renderJson(record, args.json);
19536
19613
  return;
19537
19614
  }
19615
+ case "move": {
19616
+ const record = await this.request(
19617
+ baseUrl,
19618
+ token,
19619
+ "POST",
19620
+ `/agents/${encodeURIComponent(args.namespace)}/move`,
19621
+ {
19622
+ from: args.fromName,
19623
+ toNamespace: args.targetNamespace,
19624
+ ...args.toName ? { to: args.toName } : {}
19625
+ }
19626
+ );
19627
+ ui.success(
19628
+ `Moved agent ${formatNamespacedDisplayId(args.namespace, args.fromName)} -> ${record.id}`
19629
+ );
19630
+ this.renderJson(record, args.json);
19631
+ return;
19632
+ }
19538
19633
  }
19539
19634
  }
19540
19635
  resolveBaseUrl(baseUrl) {
@@ -19566,11 +19661,11 @@ var AgentCommandHandler = class {
19566
19661
  }).token;
19567
19662
  }
19568
19663
  readJsonFile(filePath) {
19569
- const absolutePath = import_node_path16.default.resolve(process.cwd(), filePath);
19570
- if (!(0, import_node_fs11.existsSync)(absolutePath)) {
19664
+ const absolutePath = import_node_path17.default.resolve(process.cwd(), filePath);
19665
+ if (!(0, import_node_fs12.existsSync)(absolutePath)) {
19571
19666
  throw new Error(`JSON file not found: ${absolutePath}`);
19572
19667
  }
19573
- const raw = (0, import_node_fs11.readFileSync)(absolutePath, "utf8");
19668
+ const raw = (0, import_node_fs12.readFileSync)(absolutePath, "utf8");
19574
19669
  try {
19575
19670
  return JSON.parse(raw);
19576
19671
  } catch (error) {
@@ -19581,7 +19676,7 @@ var AgentCommandHandler = class {
19581
19676
  readJsonObjectFile(filePath) {
19582
19677
  const parsed = this.readJsonFile(filePath);
19583
19678
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
19584
- const absolutePath = import_node_path16.default.resolve(process.cwd(), filePath);
19679
+ const absolutePath = import_node_path17.default.resolve(process.cwd(), filePath);
19585
19680
  throw new Error(`Invalid JSON in ${absolutePath}: expected an object`);
19586
19681
  }
19587
19682
  return parsed;
@@ -19730,8 +19825,8 @@ var NsCommandHandler = class {
19730
19825
  };
19731
19826
 
19732
19827
  // src/commands/StoreCommandHandler.ts
19733
- var import_node_fs12 = require("fs");
19734
- var import_node_path17 = __toESM(require("path"));
19828
+ var import_node_fs13 = require("fs");
19829
+ var import_node_path18 = __toESM(require("path"));
19735
19830
  var StoreCommandHandler = class {
19736
19831
  async handle(args) {
19737
19832
  if (args.scope === "namespace") {
@@ -19873,11 +19968,11 @@ var StoreCommandHandler = class {
19873
19968
  return payload.data ?? [];
19874
19969
  }
19875
19970
  readJsonFile(filePath) {
19876
- const absolutePath = import_node_path17.default.resolve(process.cwd(), filePath);
19877
- if (!(0, import_node_fs12.existsSync)(absolutePath)) {
19971
+ const absolutePath = import_node_path18.default.resolve(process.cwd(), filePath);
19972
+ if (!(0, import_node_fs13.existsSync)(absolutePath)) {
19878
19973
  throw new Error(`JSON file not found: ${absolutePath}`);
19879
19974
  }
19880
- const raw = (0, import_node_fs12.readFileSync)(absolutePath, "utf8");
19975
+ const raw = (0, import_node_fs13.readFileSync)(absolutePath, "utf8");
19881
19976
  try {
19882
19977
  return JSON.parse(raw);
19883
19978
  } catch (error) {
@@ -19929,8 +20024,8 @@ var StoreCommandHandler = class {
19929
20024
  };
19930
20025
 
19931
20026
  // src/commands/AppCommandHandler.ts
19932
- var import_node_fs13 = require("fs");
19933
- var import_node_path18 = __toESM(require("path"));
20027
+ var import_node_fs14 = require("fs");
20028
+ var import_node_path19 = __toESM(require("path"));
19934
20029
  init_sessionStore();
19935
20030
  init_namespacedRef();
19936
20031
  var AppCommandHandler = class {
@@ -20018,6 +20113,24 @@ var AppCommandHandler = class {
20018
20113
  this.renderJson(record, args.json);
20019
20114
  return;
20020
20115
  }
20116
+ case "move": {
20117
+ const record = await this.request(
20118
+ baseUrl,
20119
+ token,
20120
+ "POST",
20121
+ `/apps/${encodeURIComponent(args.namespace)}/move`,
20122
+ {
20123
+ fromId: args.fromId,
20124
+ toNamespace: args.targetNamespace,
20125
+ ...args.toId ? { toId: args.toId } : {}
20126
+ }
20127
+ );
20128
+ ui.success(
20129
+ `Moved app ${formatNamespacedDisplayId(args.namespace, args.fromId)} -> ${formatNamespacedDisplayId(record.namespace, record.id)}`
20130
+ );
20131
+ this.renderJson(record, args.json);
20132
+ return;
20133
+ }
20021
20134
  }
20022
20135
  }
20023
20136
  resolveBaseUrl(baseUrl) {
@@ -20029,11 +20142,11 @@ var AppCommandHandler = class {
20029
20142
  }).token;
20030
20143
  }
20031
20144
  readJsonFile(filePath) {
20032
- const absolutePath = import_node_path18.default.resolve(process.cwd(), filePath);
20033
- if (!(0, import_node_fs13.existsSync)(absolutePath)) {
20145
+ const absolutePath = import_node_path19.default.resolve(process.cwd(), filePath);
20146
+ if (!(0, import_node_fs14.existsSync)(absolutePath)) {
20034
20147
  throw new Error(`JSON file not found: ${absolutePath}`);
20035
20148
  }
20036
- const raw = (0, import_node_fs13.readFileSync)(absolutePath, "utf8");
20149
+ const raw = (0, import_node_fs14.readFileSync)(absolutePath, "utf8");
20037
20150
  try {
20038
20151
  return JSON.parse(raw);
20039
20152
  } catch (error) {
@@ -20113,13 +20226,13 @@ function readNamespaceFromPayload(payload) {
20113
20226
  }
20114
20227
 
20115
20228
  // src/commands/ServiceCommandHandler.ts
20116
- var import_node_fs15 = require("fs");
20117
- var import_node_path20 = __toESM(require("path"));
20229
+ var import_node_fs16 = require("fs");
20230
+ var import_node_path21 = __toESM(require("path"));
20118
20231
 
20119
20232
  // src/services/ServiceRuntimeRunner.ts
20120
- var import_node_fs14 = require("fs");
20121
- var import_node_os6 = __toESM(require("os"));
20122
- var import_node_path19 = __toESM(require("path"));
20233
+ var import_node_fs15 = require("fs");
20234
+ var import_node_os7 = __toESM(require("os"));
20235
+ var import_node_path20 = __toESM(require("path"));
20123
20236
  var import_node_child_process9 = require("child_process");
20124
20237
  var import_node_readline = require("readline");
20125
20238
  var import_chalk3 = __toESM(require("chalk"));
@@ -20232,14 +20345,14 @@ var ServiceRuntimeRunner = class {
20232
20345
  }
20233
20346
  resolveRepoRoot(service, cwd) {
20234
20347
  if (cwd) {
20235
- return import_node_path19.default.resolve(process.cwd(), cwd);
20348
+ return import_node_path20.default.resolve(process.cwd(), cwd);
20236
20349
  }
20237
20350
  const repository = this.getDeploy(service).repository?.trim();
20238
20351
  if (repository) {
20239
20352
  const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
20240
20353
  if (repoName) {
20241
- const candidate = import_node_path19.default.join(import_node_os6.default.homedir(), "dev", "pmate", repoName);
20242
- if ((0, import_node_fs14.existsSync)(candidate)) {
20354
+ const candidate = import_node_path20.default.join(import_node_os7.default.homedir(), "dev", "pmate", repoName);
20355
+ if ((0, import_node_fs15.existsSync)(candidate)) {
20243
20356
  return candidate;
20244
20357
  }
20245
20358
  }
@@ -20252,12 +20365,12 @@ var ServiceRuntimeRunner = class {
20252
20365
  if (!dir) {
20253
20366
  throw new Error(`Missing deploy.dir for ${service.id}`);
20254
20367
  }
20255
- return import_node_path19.default.resolve(repoRoot, dir);
20368
+ return import_node_path20.default.resolve(repoRoot, dir);
20256
20369
  }
20257
20370
  async deployVite(service, options) {
20258
20371
  const appDir = this.resolveLocalDir(service, options.cwd);
20259
- const packageJsonPath = import_node_path19.default.join(appDir, "package.json");
20260
- if (!(0, import_node_fs14.existsSync)(packageJsonPath)) {
20372
+ const packageJsonPath = import_node_path20.default.join(appDir, "package.json");
20373
+ if (!(0, import_node_fs15.existsSync)(packageJsonPath)) {
20261
20374
  throw new Error(`No package.json found at ${packageJsonPath}`);
20262
20375
  }
20263
20376
  const pkg2 = this.loadPackageJson(packageJsonPath);
@@ -20266,8 +20379,8 @@ var ServiceRuntimeRunner = class {
20266
20379
  throw new Error(`Missing package name in ${packageJsonPath}`);
20267
20380
  }
20268
20381
  await this.runCommand("pnpm", ["--filter", pkgName, "build"], this.resolveRepoRoot(service, options.cwd));
20269
- const distDir = import_node_path19.default.join(appDir, "dist");
20270
- if (!(0, import_node_fs14.existsSync)(distDir)) {
20382
+ const distDir = import_node_path20.default.join(appDir, "dist");
20383
+ if (!(0, import_node_fs15.existsSync)(distDir)) {
20271
20384
  throw new Error(`No dist directory found at ${distDir}`);
20272
20385
  }
20273
20386
  const bucketName = this.getDeploy(service).bucket?.trim();
@@ -20278,8 +20391,8 @@ var ServiceRuntimeRunner = class {
20278
20391
  }
20279
20392
  async deployStatic(service, options) {
20280
20393
  const appDir = this.resolveLocalDir(service, options.cwd);
20281
- const srcDir = import_node_path19.default.join(appDir, "src");
20282
- if (!(0, import_node_fs14.existsSync)(srcDir)) {
20394
+ const srcDir = import_node_path20.default.join(appDir, "src");
20395
+ if (!(0, import_node_fs15.existsSync)(srcDir)) {
20283
20396
  throw new Error(`No src directory found at ${srcDir}`);
20284
20397
  }
20285
20398
  const bucketName = this.getDeploy(service).bucket?.trim();
@@ -20397,7 +20510,7 @@ var ServiceRuntimeRunner = class {
20397
20510
  const serverAddress = await resolveServerAddress(server);
20398
20511
  const templateName = serviceType === "ws" ? "nginx.ws.template" : "nginx.rest.template";
20399
20512
  const templatePath = this.resolveTemplatePath(templateName);
20400
- const template = (0, import_node_fs14.readFileSync)(templatePath, "utf8");
20513
+ const template = (0, import_node_fs15.readFileSync)(templatePath, "utf8");
20401
20514
  const host = `${subdomain}.${deploy.domain?.trim() || "pmate.chat"}`;
20402
20515
  const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
20403
20516
  const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
@@ -20429,11 +20542,11 @@ var ServiceRuntimeRunner = class {
20429
20542
  }
20430
20543
  if (config.ensurePackageJson) {
20431
20544
  const appDir = this.resolveLocalDir(service, options.cwd);
20432
- const packageJsonPath = import_node_path19.default.join(appDir, "package.json");
20433
- if (!(0, import_node_fs14.existsSync)(packageJsonPath)) {
20545
+ const packageJsonPath = import_node_path20.default.join(appDir, "package.json");
20546
+ if (!(0, import_node_fs15.existsSync)(packageJsonPath)) {
20434
20547
  throw new Error(`Missing package.json at ${packageJsonPath}`);
20435
20548
  }
20436
- const pkgStat = (0, import_node_fs14.statSync)(packageJsonPath);
20549
+ const pkgStat = (0, import_node_fs15.statSync)(packageJsonPath);
20437
20550
  if (!pkgStat.isFile()) {
20438
20551
  throw new Error(`package.json is not a file at ${packageJsonPath}`);
20439
20552
  }
@@ -20856,9 +20969,9 @@ var ServiceRuntimeRunner = class {
20856
20969
  return tokens;
20857
20970
  }
20858
20971
  readPathValue(source, pathExpr) {
20859
- const path22 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
20972
+ const path23 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
20860
20973
  let cursor = source;
20861
- for (const segment of path22) {
20974
+ for (const segment of path23) {
20862
20975
  if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
20863
20976
  return void 0;
20864
20977
  }
@@ -20901,12 +21014,12 @@ var ServiceRuntimeRunner = class {
20901
21014
  }
20902
21015
  resolveTemplatePath(templateName) {
20903
21016
  const candidates = [
20904
- import_node_path19.default.join(__dirname, "..", "templates", templateName),
20905
- import_node_path19.default.join(__dirname, "..", "src", "templates", templateName),
20906
- import_node_path19.default.join(__dirname, "templates", templateName)
21017
+ import_node_path20.default.join(__dirname, "..", "templates", templateName),
21018
+ import_node_path20.default.join(__dirname, "..", "src", "templates", templateName),
21019
+ import_node_path20.default.join(__dirname, "templates", templateName)
20907
21020
  ];
20908
21021
  for (const candidate of candidates) {
20909
- if ((0, import_node_fs14.existsSync)(candidate)) {
21022
+ if ((0, import_node_fs15.existsSync)(candidate)) {
20910
21023
  return candidate;
20911
21024
  }
20912
21025
  }
@@ -20938,7 +21051,7 @@ var ServiceRuntimeRunner = class {
20938
21051
  });
20939
21052
  }
20940
21053
  loadPackageJson(packageJsonPath) {
20941
- const raw = (0, import_node_fs14.readFileSync)(packageJsonPath, "utf8");
21054
+ const raw = (0, import_node_fs15.readFileSync)(packageJsonPath, "utf8");
20942
21055
  const parsed = JSON.parse(raw);
20943
21056
  if (!parsed || typeof parsed !== "object") {
20944
21057
  throw new Error(`Invalid package.json at ${packageJsonPath}`);
@@ -20947,7 +21060,7 @@ var ServiceRuntimeRunner = class {
20947
21060
  }
20948
21061
  writePackageJson(packageJsonPath, data) {
20949
21062
  const serialized = JSON.stringify(data, null, 2);
20950
- (0, import_node_fs14.writeFileSync)(packageJsonPath, `${serialized}
21063
+ (0, import_node_fs15.writeFileSync)(packageJsonPath, `${serialized}
20951
21064
  `, "utf8");
20952
21065
  }
20953
21066
  runCommand(command, args, cwd) {
@@ -21172,6 +21285,23 @@ var ServiceCommandHandler = class {
21172
21285
  this.renderJson(record, args.json);
21173
21286
  return;
21174
21287
  }
21288
+ case "move": {
21289
+ const record = await this.request(
21290
+ baseUrl,
21291
+ "POST",
21292
+ `/services/${encodeURIComponent(args.namespace)}/move`,
21293
+ {
21294
+ from: args.fromName,
21295
+ toNamespace: args.targetNamespace,
21296
+ ...args.toName ? { to: args.toName } : {}
21297
+ }
21298
+ );
21299
+ ui.success(
21300
+ `Moved service ${formatNamespacedDisplayId(args.namespace, args.fromName)} -> ${record.id}`
21301
+ );
21302
+ this.renderJson(record, args.json);
21303
+ return;
21304
+ }
21175
21305
  case "deploy": {
21176
21306
  const record = await registry.getService(args.namespace, args.name);
21177
21307
  await runtime.deploy(record, { cwd: args.cwd });
@@ -21198,11 +21328,11 @@ var ServiceCommandHandler = class {
21198
21328
  return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
21199
21329
  }
21200
21330
  readJsonFile(filePath) {
21201
- const absolutePath = import_node_path20.default.resolve(process.cwd(), filePath);
21202
- if (!(0, import_node_fs15.existsSync)(absolutePath)) {
21331
+ const absolutePath = import_node_path21.default.resolve(process.cwd(), filePath);
21332
+ if (!(0, import_node_fs16.existsSync)(absolutePath)) {
21203
21333
  throw new Error(`JSON file not found: ${absolutePath}`);
21204
21334
  }
21205
- const raw = (0, import_node_fs15.readFileSync)(absolutePath, "utf8");
21335
+ const raw = (0, import_node_fs16.readFileSync)(absolutePath, "utf8");
21206
21336
  try {
21207
21337
  return JSON.parse(raw);
21208
21338
  } catch (error) {
@@ -21913,6 +22043,54 @@ function parseAgentArgs(tokens) {
21913
22043
  json
21914
22044
  };
21915
22045
  }
22046
+ if (action === "move") {
22047
+ let namespace;
22048
+ let from;
22049
+ let targetNamespace;
22050
+ let to;
22051
+ while (rest.length > 0) {
22052
+ const token = rest.shift();
22053
+ switch (token) {
22054
+ case "--ns":
22055
+ case "--namespace":
22056
+ namespace = requireValue(rest, token);
22057
+ break;
22058
+ case "--from":
22059
+ from = parseBareRenameId(requireValue(rest, token), "agent");
22060
+ break;
22061
+ case "--to-ns":
22062
+ case "--target-namespace":
22063
+ targetNamespace = requireValue(rest, token);
22064
+ break;
22065
+ case "--to":
22066
+ to = parseBareRenameId(requireValue(rest, token), "agent");
22067
+ break;
22068
+ case "--base-url":
22069
+ baseUrl = requireValue(rest, token);
22070
+ break;
22071
+ case "--json":
22072
+ json = true;
22073
+ break;
22074
+ default:
22075
+ throw new Error(`Unknown agent move option: ${token}`);
22076
+ }
22077
+ }
22078
+ if (!namespace || !from || !targetNamespace) {
22079
+ throw new Error(
22080
+ "Usage: agent move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]"
22081
+ );
22082
+ }
22083
+ return {
22084
+ type: "agent" /* Agent */,
22085
+ action,
22086
+ namespace,
22087
+ fromName: from,
22088
+ targetNamespace,
22089
+ toName: to,
22090
+ baseUrl,
22091
+ json
22092
+ };
22093
+ }
21916
22094
  throw new Error(`Unknown agent action: ${action}`);
21917
22095
  }
21918
22096
  function requireValue(tokens, optionName) {
@@ -22228,7 +22406,7 @@ function parseAppArgs(tokens) {
22228
22406
  const rawAction = rest.shift();
22229
22407
  const action = rawAction === "view" ? "view" : rawAction;
22230
22408
  if (!action) {
22231
- throw new Error("Missing app action. Use: app list|get|view|create|update|rename|delete");
22409
+ throw new Error("Missing app action. Use: app list|get|view|create|update|rename|move|delete");
22232
22410
  }
22233
22411
  let baseUrl;
22234
22412
  let json = false;
@@ -22394,6 +22572,45 @@ function parseAppArgs(tokens) {
22394
22572
  }
22395
22573
  return { type: "app" /* App */, action, namespace, fromId, toId, baseUrl, json };
22396
22574
  }
22575
+ if (action === "move") {
22576
+ let namespace;
22577
+ let fromId;
22578
+ let targetNamespace;
22579
+ let toId;
22580
+ while (rest.length > 0) {
22581
+ const token = rest.shift();
22582
+ switch (token) {
22583
+ case "--ns":
22584
+ case "--namespace":
22585
+ namespace = requireValue4(rest, token);
22586
+ break;
22587
+ case "--from":
22588
+ fromId = parseBareRenameId2(requireValue4(rest, token), "app");
22589
+ break;
22590
+ case "--to-ns":
22591
+ case "--target-namespace":
22592
+ targetNamespace = requireValue4(rest, token);
22593
+ break;
22594
+ case "--to":
22595
+ toId = parseBareRenameId2(requireValue4(rest, token), "app");
22596
+ break;
22597
+ case "--base-url":
22598
+ baseUrl = requireValue4(rest, token);
22599
+ break;
22600
+ case "--json":
22601
+ json = true;
22602
+ break;
22603
+ default:
22604
+ throw new Error(`Unknown app move option: ${token}`);
22605
+ }
22606
+ }
22607
+ if (!namespace || !fromId || !targetNamespace) {
22608
+ throw new Error(
22609
+ "Usage: app move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]"
22610
+ );
22611
+ }
22612
+ return { type: "app" /* App */, action, namespace, fromId, targetNamespace, toId, baseUrl, json };
22613
+ }
22397
22614
  throw new Error(`Unknown app action: ${action}`);
22398
22615
  }
22399
22616
  function requireValue4(tokens, optionName) {
@@ -22622,6 +22839,54 @@ function parseServiceArgs(tokens) {
22622
22839
  json
22623
22840
  };
22624
22841
  }
22842
+ if (action === "move") {
22843
+ let namespace;
22844
+ let from;
22845
+ let targetNamespace;
22846
+ let to;
22847
+ while (rest.length > 0) {
22848
+ const token = rest.shift();
22849
+ switch (token) {
22850
+ case "--ns":
22851
+ case "--namespace":
22852
+ namespace = requireValue5(rest, token);
22853
+ break;
22854
+ case "--from":
22855
+ from = parseBareRenameId3(requireValue5(rest, token), "service");
22856
+ break;
22857
+ case "--to-ns":
22858
+ case "--target-namespace":
22859
+ targetNamespace = requireValue5(rest, token);
22860
+ break;
22861
+ case "--to":
22862
+ to = parseBareRenameId3(requireValue5(rest, token), "service");
22863
+ break;
22864
+ case "--base-url":
22865
+ baseUrl = requireValue5(rest, token);
22866
+ break;
22867
+ case "--json":
22868
+ json = true;
22869
+ break;
22870
+ default:
22871
+ throw new Error(`Unknown service move option: ${token}`);
22872
+ }
22873
+ }
22874
+ if (!namespace || !from || !targetNamespace) {
22875
+ throw new Error(
22876
+ "Usage: service move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]"
22877
+ );
22878
+ }
22879
+ return {
22880
+ type: "service" /* Service */,
22881
+ action,
22882
+ namespace,
22883
+ fromName: from,
22884
+ targetNamespace,
22885
+ toName: to,
22886
+ baseUrl,
22887
+ json
22888
+ };
22889
+ }
22625
22890
  throw new Error(`Unknown service action: ${action}`);
22626
22891
  }
22627
22892
  function requireValue5(tokens, optionName) {
@@ -22866,9 +23131,59 @@ function requireValue7(tokens, optionName) {
22866
23131
  return value;
22867
23132
  }
22868
23133
 
23134
+ // src/collectCommandParser.ts
23135
+ function parseCollectArgs(tokens) {
23136
+ const rest = [...tokens];
23137
+ const options = {
23138
+ action: "sync",
23139
+ source: void 0,
23140
+ endpoint: void 0
23141
+ };
23142
+ const action = rest.shift();
23143
+ if (action !== "sync") {
23144
+ throw new Error(
23145
+ "Usage: collect sync (--source <cc|yelling> | --endpoint <url>)"
23146
+ );
23147
+ }
23148
+ while (rest.length > 0) {
23149
+ const token = rest.shift();
23150
+ switch (token) {
23151
+ case "--source": {
23152
+ const value = requireValue8(rest, token);
23153
+ if (value !== "cc" && value !== "yelling") {
23154
+ throw new Error(`Unsupported collect source: ${value}`);
23155
+ }
23156
+ options.source = value;
23157
+ break;
23158
+ }
23159
+ case "--endpoint":
23160
+ options.endpoint = requireValue8(rest, token);
23161
+ break;
23162
+ default:
23163
+ throw new Error(`Unknown collect option: ${token}`);
23164
+ }
23165
+ }
23166
+ if (options.source && options.endpoint) {
23167
+ throw new Error("Use either --source or --endpoint, not both.");
23168
+ }
23169
+ if (!options.source && !options.endpoint) {
23170
+ throw new Error(
23171
+ "Usage: collect sync (--source <cc|yelling> | --endpoint <url>)"
23172
+ );
23173
+ }
23174
+ return { type: "collect" /* Collect */, ...options };
23175
+ }
23176
+ function requireValue8(tokens, optionName) {
23177
+ const value = tokens.shift();
23178
+ if (!value) {
23179
+ throw new Error(`Missing value for ${optionName}`);
23180
+ }
23181
+ return value;
23182
+ }
23183
+
22869
23184
  // src/index.ts
22870
23185
  var pkg = JSON.parse(
22871
- (0, import_node_fs16.readFileSync)(import_node_path21.default.resolve(__dirname, "..", "package.json"), "utf8")
23186
+ (0, import_node_fs17.readFileSync)(import_node_path22.default.resolve(__dirname, "..", "package.json"), "utf8")
22872
23187
  );
22873
23188
  var HELP_TEXT = [
22874
23189
  import_chalk4.default.bold(`pmate v${pkg.version}`),
@@ -22947,8 +23262,7 @@ var HELP_TEXT = [
22947
23262
  ` ${import_chalk4.default.gray(" [--count <n>]")}`,
22948
23263
  ` ${import_chalk4.default.gray(" --easy [--words <n>] [--digits <n>] [--separator <s>] [--count <n>]")}`,
22949
23264
  ` ${import_chalk4.default.cyan("collect")} Collect threads/messages from Electron chat app via CDP`,
22950
- ` ${import_chalk4.default.gray(" --list [--endpoint <url>] [--json]")}`,
22951
- ` ${import_chalk4.default.gray(" --thread <name> [--endpoint <url>] [--json]")}`,
23265
+ ` ${import_chalk4.default.gray(" sync (--source <cc|yelling> | --endpoint <url>)")}`,
22952
23266
  ` ${import_chalk4.default.cyan("agent")} Manage agent registry entries and call agents for debugging`,
22953
23267
  ` ${import_chalk4.default.gray(" namespaces [--base-url <url>] [--json]")}`,
22954
23268
  ` ${import_chalk4.default.gray(" list [--namespace <ns>] [--base-url <url>] [--json]")}`,
@@ -22957,6 +23271,7 @@ var HELP_TEXT = [
22957
23271
  ` ${import_chalk4.default.gray(" create [<namespace>] --file <path> [--base-url <url>] [--json]")}`,
22958
23272
  ` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
22959
23273
  ` ${import_chalk4.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
23274
+ ` ${import_chalk4.default.gray(" move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]")}`,
22960
23275
  ` ${import_chalk4.default.gray(" call <ns:objectId> [--payload <json>] [--file <path>] [--base-url <url>] [--hub-base-url <url>] [--from <id>] [--json]")}`,
22961
23276
  ` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
22962
23277
  ` ${import_chalk4.default.gray(" list defaults to all namespaces; create defaults to namespace: pmate; default base URL: https://agent-api.pmate.chat; call uses pmate:cli session and default hub: https://hub.pmate.chat")}`,
@@ -22986,6 +23301,7 @@ var HELP_TEXT = [
22986
23301
  ` ${import_chalk4.default.gray(" create --file <path> [--base-url <url>] [--json]")}`,
22987
23302
  ` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
22988
23303
  ` ${import_chalk4.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
23304
+ ` ${import_chalk4.default.gray(" move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]")}`,
22989
23305
  ` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
22990
23306
  ` ${import_chalk4.default.gray(" default base URL: https://apps-api.pmate.chat")}`,
22991
23307
  ` ${import_chalk4.default.cyan("service")} Manage service registry entries via apps-api`,
@@ -22995,6 +23311,7 @@ var HELP_TEXT = [
22995
23311
  ` ${import_chalk4.default.gray(" create --file <path> [--base-url <url>] [--json]")}`,
22996
23312
  ` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
22997
23313
  ` ${import_chalk4.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
23314
+ ` ${import_chalk4.default.gray(" move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]")}`,
22998
23315
  ` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
22999
23316
  ` ${import_chalk4.default.gray(" deploy <ns:objectId> [--cwd <dir>] [--base-url <url>]")}`,
23000
23317
  ` ${import_chalk4.default.gray(" init <ns:objectId> [--cwd <dir>] [--base-url <url>]")}`,
@@ -23060,7 +23377,7 @@ function parseCommandArgs(args) {
23060
23377
  const token = rest.shift();
23061
23378
  switch (token) {
23062
23379
  case "--app":
23063
- app = requireValue8(rest, token);
23380
+ app = requireValue9(rest, token);
23064
23381
  break;
23065
23382
  default:
23066
23383
  throw new Error(`Unknown login option: ${token}`);
@@ -23157,7 +23474,7 @@ function parseVercelArgs(tokens) {
23157
23474
  const token = rest.shift();
23158
23475
  switch (token) {
23159
23476
  case "--scope":
23160
- scope = requireValue8(rest, token);
23477
+ scope = requireValue9(rest, token);
23161
23478
  break;
23162
23479
  default:
23163
23480
  throw new Error(`Unknown vercel option: ${token}`);
@@ -23177,10 +23494,10 @@ function parseVercelArgs(tokens) {
23177
23494
  const token = rest.shift();
23178
23495
  switch (token) {
23179
23496
  case "--scope":
23180
- scope = requireValue8(rest, token);
23497
+ scope = requireValue9(rest, token);
23181
23498
  break;
23182
23499
  case "--project":
23183
- project = requireValue8(rest, token);
23500
+ project = requireValue9(rest, token);
23184
23501
  break;
23185
23502
  case "--last-week":
23186
23503
  lastWeek = true;
@@ -23211,16 +23528,16 @@ function parseAddDnsArgs(tokens) {
23211
23528
  const token = rest.shift();
23212
23529
  switch (token) {
23213
23530
  case "--type":
23214
- options.dnsType = requireValue8(rest, token);
23531
+ options.dnsType = requireValue9(rest, token);
23215
23532
  break;
23216
23533
  case "--value":
23217
- options.dnsValue = requireValue8(rest, token);
23534
+ options.dnsValue = requireValue9(rest, token);
23218
23535
  break;
23219
23536
  case "--rr":
23220
- options.dnsRr = requireValue8(rest, token);
23537
+ options.dnsRr = requireValue9(rest, token);
23221
23538
  break;
23222
23539
  case "--ttl": {
23223
- const ttlValue = requireValue8(rest, token);
23540
+ const ttlValue = requireValue9(rest, token);
23224
23541
  const ttl = Number.parseInt(ttlValue, 10);
23225
23542
  if (!Number.isFinite(ttl) || ttl <= 0) {
23226
23543
  throw new Error(`Invalid --ttl value: ${ttlValue}`);
@@ -23229,7 +23546,7 @@ function parseAddDnsArgs(tokens) {
23229
23546
  break;
23230
23547
  }
23231
23548
  case "--domain":
23232
- options.dnsDomain = requireValue8(rest, token);
23549
+ options.dnsDomain = requireValue9(rest, token);
23233
23550
  break;
23234
23551
  default:
23235
23552
  throw new Error(`Unknown add-dns option: ${token}`);
@@ -23262,13 +23579,13 @@ function parseBucketArgs(tokens) {
23262
23579
  options.bucketCreate = true;
23263
23580
  break;
23264
23581
  case "--name":
23265
- options.bucketName = requireValue8(rest, token);
23582
+ options.bucketName = requireValue9(rest, token);
23266
23583
  break;
23267
23584
  case "--subdomain":
23268
- options.bucketSubdomain = requireValue8(rest, token);
23585
+ options.bucketSubdomain = requireValue9(rest, token);
23269
23586
  break;
23270
23587
  case "--domain":
23271
- options.bucketDomain = requireValue8(rest, token);
23588
+ options.bucketDomain = requireValue9(rest, token);
23272
23589
  break;
23273
23590
  default:
23274
23591
  throw new Error(`Unknown bucket option: ${token}`);
@@ -23300,7 +23617,7 @@ function parseDevArgs(tokens) {
23300
23617
  const token = rest.shift();
23301
23618
  switch (token) {
23302
23619
  case "--cwd":
23303
- options.devCwd = requireValue8(rest, token);
23620
+ options.devCwd = requireValue9(rest, token);
23304
23621
  break;
23305
23622
  default:
23306
23623
  throw new Error(`Unknown dev option: ${token}`);
@@ -23320,7 +23637,7 @@ function parseDeleteArgs(tokens) {
23320
23637
  const token = rest.shift();
23321
23638
  switch (token) {
23322
23639
  case "--cwd":
23323
- deleteCwd = requireValue8(rest, token);
23640
+ deleteCwd = requireValue9(rest, token);
23324
23641
  break;
23325
23642
  default:
23326
23643
  throw new Error(`Unknown delete option: ${token}`);
@@ -23354,13 +23671,13 @@ function parseOssArgs(tokens) {
23354
23671
  const token = rest.shift();
23355
23672
  switch (token) {
23356
23673
  case "--bucket":
23357
- bucket = requireValue8(rest, token);
23674
+ bucket = requireValue9(rest, token);
23358
23675
  break;
23359
23676
  case "--file":
23360
- filePath = requireValue8(rest, token);
23677
+ filePath = requireValue9(rest, token);
23361
23678
  break;
23362
23679
  case "--key":
23363
- objectKey = requireValue8(rest, token);
23680
+ objectKey = requireValue9(rest, token);
23364
23681
  break;
23365
23682
  default:
23366
23683
  throw new Error(`Unknown oss option: ${token}`);
@@ -23393,7 +23710,7 @@ function parseEnvArgs(tokens) {
23393
23710
  throw new Error("Only one env action is allowed.");
23394
23711
  }
23395
23712
  action = "set";
23396
- key = requireValue8(rest, token);
23713
+ key = requireValue9(rest, token);
23397
23714
  break;
23398
23715
  case "--list":
23399
23716
  if (action) {
@@ -23406,17 +23723,17 @@ function parseEnvArgs(tokens) {
23406
23723
  throw new Error("Only one env action is allowed.");
23407
23724
  }
23408
23725
  action = "delete";
23409
- key = requireValue8(rest, token);
23726
+ key = requireValue9(rest, token);
23410
23727
  break;
23411
23728
  case "--value":
23412
- value = requireValue8(rest, token);
23729
+ value = requireValue9(rest, token);
23413
23730
  break;
23414
23731
  case "--verbose":
23415
23732
  case "-v":
23416
23733
  verbose = true;
23417
23734
  break;
23418
23735
  case "--cwd":
23419
- cwd = requireValue8(rest, token);
23736
+ cwd = requireValue9(rest, token);
23420
23737
  break;
23421
23738
  default:
23422
23739
  throw new Error(`Unknown env option: ${token}`);
@@ -23474,7 +23791,7 @@ function parseCommitArgs(tokens) {
23474
23791
  push = true;
23475
23792
  break;
23476
23793
  case "--cwd":
23477
- cwd = requireValue8(rest, token);
23794
+ cwd = requireValue9(rest, token);
23478
23795
  break;
23479
23796
  default:
23480
23797
  throw new Error(`Unknown commit option: ${token}`);
@@ -23490,10 +23807,10 @@ function parseSummaryArgs(tokens) {
23490
23807
  const token = rest.shift();
23491
23808
  switch (token) {
23492
23809
  case "--pr":
23493
- prRef = requireValue8(rest, token);
23810
+ prRef = requireValue9(rest, token);
23494
23811
  break;
23495
23812
  case "--cwd":
23496
- cwd = requireValue8(rest, token);
23813
+ cwd = requireValue9(rest, token);
23497
23814
  break;
23498
23815
  default:
23499
23816
  throw new Error(`Unknown summary option: ${token}`);
@@ -23518,13 +23835,13 @@ function parseQuizArgs(tokens) {
23518
23835
  const token = rest.shift();
23519
23836
  switch (token) {
23520
23837
  case "--paper-id":
23521
- paperId = requireValue8(rest, token);
23838
+ paperId = requireValue9(rest, token);
23522
23839
  break;
23523
23840
  case "--base-url":
23524
- apiBaseUrl = requireValue8(rest, token);
23841
+ apiBaseUrl = requireValue9(rest, token);
23525
23842
  break;
23526
23843
  case "--link-base":
23527
- linkBaseUrl = requireValue8(rest, token);
23844
+ linkBaseUrl = requireValue9(rest, token);
23528
23845
  break;
23529
23846
  default:
23530
23847
  throw new Error(`Unknown quiz create-draft option: ${token}`);
@@ -23550,16 +23867,16 @@ function parseQuizArgs(tokens) {
23550
23867
  const token = rest.shift();
23551
23868
  switch (token) {
23552
23869
  case "--paper-id":
23553
- paperId = requireValue8(rest, token);
23870
+ paperId = requireValue9(rest, token);
23554
23871
  break;
23555
23872
  case "--file":
23556
- filePath = requireValue8(rest, token);
23873
+ filePath = requireValue9(rest, token);
23557
23874
  break;
23558
23875
  case "--base-url":
23559
- apiBaseUrl = requireValue8(rest, token);
23876
+ apiBaseUrl = requireValue9(rest, token);
23560
23877
  break;
23561
23878
  case "--link-base":
23562
- linkBaseUrl = requireValue8(rest, token);
23879
+ linkBaseUrl = requireValue9(rest, token);
23563
23880
  break;
23564
23881
  default:
23565
23882
  throw new Error(`Unknown quiz update-meta option: ${token}`);
@@ -23589,16 +23906,16 @@ function parseQuizArgs(tokens) {
23589
23906
  const token = rest.shift();
23590
23907
  switch (token) {
23591
23908
  case "--paper-id":
23592
- paperId = requireValue8(rest, token);
23909
+ paperId = requireValue9(rest, token);
23593
23910
  break;
23594
23911
  case "--file":
23595
- filePath = requireValue8(rest, token);
23912
+ filePath = requireValue9(rest, token);
23596
23913
  break;
23597
23914
  case "--base-url":
23598
- apiBaseUrl = requireValue8(rest, token);
23915
+ apiBaseUrl = requireValue9(rest, token);
23599
23916
  break;
23600
23917
  case "--link-base":
23601
- linkBaseUrl = requireValue8(rest, token);
23918
+ linkBaseUrl = requireValue9(rest, token);
23602
23919
  break;
23603
23920
  default:
23604
23921
  throw new Error(`Unknown quiz append-step option: ${token}`);
@@ -23629,19 +23946,19 @@ function parseQuizArgs(tokens) {
23629
23946
  const token = rest.shift();
23630
23947
  switch (token) {
23631
23948
  case "--paper-id":
23632
- paperId = requireValue8(rest, token);
23949
+ paperId = requireValue9(rest, token);
23633
23950
  break;
23634
23951
  case "--step-id":
23635
- stepId = requireValue8(rest, token);
23952
+ stepId = requireValue9(rest, token);
23636
23953
  break;
23637
23954
  case "--file":
23638
- filePath = requireValue8(rest, token);
23955
+ filePath = requireValue9(rest, token);
23639
23956
  break;
23640
23957
  case "--base-url":
23641
- apiBaseUrl = requireValue8(rest, token);
23958
+ apiBaseUrl = requireValue9(rest, token);
23642
23959
  break;
23643
23960
  case "--link-base":
23644
- linkBaseUrl = requireValue8(rest, token);
23961
+ linkBaseUrl = requireValue9(rest, token);
23645
23962
  break;
23646
23963
  default:
23647
23964
  throw new Error(`Unknown quiz update-step option: ${token}`);
@@ -23675,16 +23992,16 @@ function parseQuizArgs(tokens) {
23675
23992
  const token = rest.shift();
23676
23993
  switch (token) {
23677
23994
  case "--paper-id":
23678
- paperId = requireValue8(rest, token);
23995
+ paperId = requireValue9(rest, token);
23679
23996
  break;
23680
23997
  case "--step-ids":
23681
- stepIdsRaw = requireValue8(rest, token);
23998
+ stepIdsRaw = requireValue9(rest, token);
23682
23999
  break;
23683
24000
  case "--base-url":
23684
- apiBaseUrl = requireValue8(rest, token);
24001
+ apiBaseUrl = requireValue9(rest, token);
23685
24002
  break;
23686
24003
  case "--link-base":
23687
- linkBaseUrl = requireValue8(rest, token);
24004
+ linkBaseUrl = requireValue9(rest, token);
23688
24005
  break;
23689
24006
  default:
23690
24007
  throw new Error(`Unknown quiz reorder option: ${token}`);
@@ -23717,13 +24034,13 @@ function parseQuizArgs(tokens) {
23717
24034
  const token = rest.shift();
23718
24035
  switch (token) {
23719
24036
  case "--paper-id":
23720
- paperId = requireValue8(rest, token);
24037
+ paperId = requireValue9(rest, token);
23721
24038
  break;
23722
24039
  case "--base-url":
23723
- apiBaseUrl = requireValue8(rest, token);
24040
+ apiBaseUrl = requireValue9(rest, token);
23724
24041
  break;
23725
24042
  case "--link-base":
23726
- linkBaseUrl = requireValue8(rest, token);
24043
+ linkBaseUrl = requireValue9(rest, token);
23727
24044
  break;
23728
24045
  default:
23729
24046
  throw new Error(`Unknown quiz activate option: ${token}`);
@@ -23748,13 +24065,13 @@ function parseQuizArgs(tokens) {
23748
24065
  const token = rest.shift();
23749
24066
  switch (token) {
23750
24067
  case "--paper-id":
23751
- paperId = requireValue8(rest, token);
24068
+ paperId = requireValue9(rest, token);
23752
24069
  break;
23753
24070
  case "--base-url":
23754
- apiBaseUrl = requireValue8(rest, token);
24071
+ apiBaseUrl = requireValue9(rest, token);
23755
24072
  break;
23756
24073
  case "--link-base":
23757
- linkBaseUrl = requireValue8(rest, token);
24074
+ linkBaseUrl = requireValue9(rest, token);
23758
24075
  break;
23759
24076
  default:
23760
24077
  throw new Error(`Unknown quiz view option: ${token}`);
@@ -23783,22 +24100,22 @@ function parseQuizArgs(tokens) {
23783
24100
  const token = rest.shift();
23784
24101
  switch (token) {
23785
24102
  case "--paper-id":
23786
- paperId = requireValue8(rest, token);
24103
+ paperId = requireValue9(rest, token);
23787
24104
  break;
23788
24105
  case "--step-id":
23789
- stepId = requireValue8(rest, token);
24106
+ stepId = requireValue9(rest, token);
23790
24107
  break;
23791
24108
  case "--file":
23792
- filePath = requireValue8(rest, token);
24109
+ filePath = requireValue9(rest, token);
23793
24110
  break;
23794
24111
  case "--new-paper-id":
23795
- newPaperId = requireValue8(rest, token);
24112
+ newPaperId = requireValue9(rest, token);
23796
24113
  break;
23797
24114
  case "--base-url":
23798
- apiBaseUrl = requireValue8(rest, token);
24115
+ apiBaseUrl = requireValue9(rest, token);
23799
24116
  break;
23800
24117
  case "--link-base":
23801
- linkBaseUrl = requireValue8(rest, token);
24118
+ linkBaseUrl = requireValue9(rest, token);
23802
24119
  break;
23803
24120
  case "--activate":
23804
24121
  activate = true;
@@ -23888,10 +24205,10 @@ function parseLinearPrArgs(tokens) {
23888
24205
  const token = rest.shift();
23889
24206
  switch (token) {
23890
24207
  case "--account":
23891
- account = requireValue8(rest, token);
24208
+ account = requireValue9(rest, token);
23892
24209
  break;
23893
24210
  case "--cwd":
23894
- cwd = requireValue8(rest, token);
24211
+ cwd = requireValue9(rest, token);
23895
24212
  break;
23896
24213
  default:
23897
24214
  throw new Error(`Unknown linear option: ${token}`);
@@ -23920,35 +24237,35 @@ function parseLinearCreateArgs(tokens) {
23920
24237
  const token = rest.shift();
23921
24238
  switch (token) {
23922
24239
  case "--account":
23923
- account = requireValue8(rest, token);
24240
+ account = requireValue9(rest, token);
23924
24241
  break;
23925
24242
  case "--repl":
23926
24243
  useRepl = true;
23927
24244
  break;
23928
24245
  case "--title":
23929
- title = requireValue8(rest, token);
24246
+ title = requireValue9(rest, token);
23930
24247
  break;
23931
24248
  case "--desc":
23932
24249
  case "--description":
23933
- description = decodeEscapedNewlines(requireValue8(rest, token));
24250
+ description = decodeEscapedNewlines(requireValue9(rest, token));
23934
24251
  break;
23935
24252
  case "--team-id":
23936
- teamId = requireValue8(rest, token);
24253
+ teamId = requireValue9(rest, token);
23937
24254
  break;
23938
24255
  case "--team-key":
23939
- teamKey = requireValue8(rest, token);
24256
+ teamKey = requireValue9(rest, token);
23940
24257
  break;
23941
24258
  case "--priority":
23942
- priority = parseLinearPriority(requireValue8(rest, token));
24259
+ priority = parseLinearPriority(requireValue9(rest, token));
23943
24260
  break;
23944
24261
  case "--parent-id":
23945
- parentId = requireValue8(rest, token);
24262
+ parentId = requireValue9(rest, token);
23946
24263
  break;
23947
24264
  case "--state-id":
23948
- stateId = requireValue8(rest, token);
24265
+ stateId = requireValue9(rest, token);
23949
24266
  break;
23950
24267
  case "--cwd":
23951
- cwd = requireValue8(rest, token);
24268
+ cwd = requireValue9(rest, token);
23952
24269
  break;
23953
24270
  default:
23954
24271
  throw new Error(`Unknown linear option: ${token}`);
@@ -23983,10 +24300,10 @@ function parseLinearWhoamiArgs(tokens) {
23983
24300
  const token = rest.shift();
23984
24301
  switch (token) {
23985
24302
  case "--account":
23986
- account = requireValue8(rest, token);
24303
+ account = requireValue9(rest, token);
23987
24304
  break;
23988
24305
  case "--cwd":
23989
- cwd = requireValue8(rest, token);
24306
+ cwd = requireValue9(rest, token);
23990
24307
  break;
23991
24308
  default:
23992
24309
  throw new Error(`Unknown linear option: ${token}`);
@@ -24011,10 +24328,10 @@ function parseLinearViewArgs(tokens) {
24011
24328
  const token = rest.shift();
24012
24329
  switch (token) {
24013
24330
  case "--account":
24014
- account = requireValue8(rest, token);
24331
+ account = requireValue9(rest, token);
24015
24332
  break;
24016
24333
  case "--cwd":
24017
- cwd = requireValue8(rest, token);
24334
+ cwd = requireValue9(rest, token);
24018
24335
  break;
24019
24336
  default:
24020
24337
  throw new Error(`Unknown linear option: ${token}`);
@@ -24049,32 +24366,32 @@ function parseLinearUpdateArgs(tokens) {
24049
24366
  const token = rest.shift();
24050
24367
  switch (token) {
24051
24368
  case "--account":
24052
- account = requireValue8(rest, token);
24369
+ account = requireValue9(rest, token);
24053
24370
  break;
24054
24371
  case "--title":
24055
- title = requireValue8(rest, token);
24372
+ title = requireValue9(rest, token);
24056
24373
  break;
24057
24374
  case "--desc":
24058
24375
  case "--description":
24059
- description = decodeEscapedNewlines(requireValue8(rest, token));
24376
+ description = decodeEscapedNewlines(requireValue9(rest, token));
24060
24377
  break;
24061
24378
  case "--team-id":
24062
- teamId = requireValue8(rest, token);
24379
+ teamId = requireValue9(rest, token);
24063
24380
  break;
24064
24381
  case "--team-key":
24065
- teamKey = requireValue8(rest, token);
24382
+ teamKey = requireValue9(rest, token);
24066
24383
  break;
24067
24384
  case "--priority":
24068
- priority = parseLinearPriority(requireValue8(rest, token));
24385
+ priority = parseLinearPriority(requireValue9(rest, token));
24069
24386
  break;
24070
24387
  case "--parent-id":
24071
- parentId = requireValue8(rest, token);
24388
+ parentId = requireValue9(rest, token);
24072
24389
  break;
24073
24390
  case "--state-id":
24074
- stateId = requireValue8(rest, token);
24391
+ stateId = requireValue9(rest, token);
24075
24392
  break;
24076
24393
  case "--cwd":
24077
- cwd = requireValue8(rest, token);
24394
+ cwd = requireValue9(rest, token);
24078
24395
  break;
24079
24396
  default:
24080
24397
  throw new Error(`Unknown linear option: ${token}`);
@@ -24112,10 +24429,10 @@ function parseLinearSubIssuesArgs(tokens) {
24112
24429
  const token = rest.shift();
24113
24430
  switch (token) {
24114
24431
  case "--account":
24115
- account = requireValue8(rest, token);
24432
+ account = requireValue9(rest, token);
24116
24433
  break;
24117
24434
  case "--cwd":
24118
- cwd = requireValue8(rest, token);
24435
+ cwd = requireValue9(rest, token);
24119
24436
  break;
24120
24437
  default:
24121
24438
  throw new Error(`Unknown linear option: ${token}`);
@@ -24142,15 +24459,15 @@ function parseLinearCommentArgs(tokens) {
24142
24459
  const token = rest.shift();
24143
24460
  switch (token) {
24144
24461
  case "--account":
24145
- account = requireValue8(rest, token);
24462
+ account = requireValue9(rest, token);
24146
24463
  break;
24147
24464
  case "--body":
24148
24465
  case "--desc":
24149
24466
  case "--description":
24150
- body = decodeEscapedNewlines(requireValue8(rest, token));
24467
+ body = decodeEscapedNewlines(requireValue9(rest, token));
24151
24468
  break;
24152
24469
  case "--cwd":
24153
- cwd = requireValue8(rest, token);
24470
+ cwd = requireValue9(rest, token);
24154
24471
  break;
24155
24472
  default:
24156
24473
  throw new Error(`Unknown linear option: ${token}`);
@@ -24180,10 +24497,10 @@ function parseLinearCommentsArgs(tokens) {
24180
24497
  const token = rest.shift();
24181
24498
  switch (token) {
24182
24499
  case "--account":
24183
- account = requireValue8(rest, token);
24500
+ account = requireValue9(rest, token);
24184
24501
  break;
24185
24502
  case "--cwd":
24186
- cwd = requireValue8(rest, token);
24503
+ cwd = requireValue9(rest, token);
24187
24504
  break;
24188
24505
  default:
24189
24506
  throw new Error(`Unknown linear option: ${token}`);
@@ -24207,16 +24524,16 @@ function parseLinearCycleArgs(tokens) {
24207
24524
  const token = rest.shift();
24208
24525
  switch (token) {
24209
24526
  case "--account":
24210
- account = requireValue8(rest, token);
24527
+ account = requireValue9(rest, token);
24211
24528
  break;
24212
24529
  case "--team-id":
24213
- teamId = requireValue8(rest, token);
24530
+ teamId = requireValue9(rest, token);
24214
24531
  break;
24215
24532
  case "--team-key":
24216
- teamKey = requireValue8(rest, token);
24533
+ teamKey = requireValue9(rest, token);
24217
24534
  break;
24218
24535
  case "--cwd":
24219
- cwd = requireValue8(rest, token);
24536
+ cwd = requireValue9(rest, token);
24220
24537
  break;
24221
24538
  default:
24222
24539
  throw new Error(`Unknown linear option: ${token}`);
@@ -24239,10 +24556,10 @@ function parseLinearTeamsArgs(tokens) {
24239
24556
  const token = rest.shift();
24240
24557
  switch (token) {
24241
24558
  case "--account":
24242
- account = requireValue8(rest, token);
24559
+ account = requireValue9(rest, token);
24243
24560
  break;
24244
24561
  case "--cwd":
24245
- cwd = requireValue8(rest, token);
24562
+ cwd = requireValue9(rest, token);
24246
24563
  break;
24247
24564
  default:
24248
24565
  throw new Error(`Unknown linear option: ${token}`);
@@ -24269,16 +24586,16 @@ function parseLinearUserIssuesArgs(tokens) {
24269
24586
  const token = rest.shift();
24270
24587
  switch (token) {
24271
24588
  case "--account":
24272
- account = requireValue8(rest, token);
24589
+ account = requireValue9(rest, token);
24273
24590
  break;
24274
24591
  case "--cycle":
24275
- cycle = parseLinearCycle(requireValue8(rest, token));
24592
+ cycle = parseLinearCycle(requireValue9(rest, token));
24276
24593
  break;
24277
24594
  case "--status":
24278
- status = parseLinearStatus(requireValue8(rest, token));
24595
+ status = parseLinearStatus(requireValue9(rest, token));
24279
24596
  break;
24280
24597
  case "--cwd":
24281
- cwd = requireValue8(rest, token);
24598
+ cwd = requireValue9(rest, token);
24282
24599
  break;
24283
24600
  default:
24284
24601
  throw new Error(`Unknown linear option: ${token}`);
@@ -24312,28 +24629,28 @@ function parseLinearIssuesArgs(tokens) {
24312
24629
  const token = rest.shift();
24313
24630
  switch (token) {
24314
24631
  case "--account":
24315
- account = requireValue8(rest, token);
24632
+ account = requireValue9(rest, token);
24316
24633
  break;
24317
24634
  case "--team-id":
24318
- teamId = requireValue8(rest, token);
24635
+ teamId = requireValue9(rest, token);
24319
24636
  break;
24320
24637
  case "--team-key":
24321
- teamKey = requireValue8(rest, token);
24638
+ teamKey = requireValue9(rest, token);
24322
24639
  break;
24323
24640
  case "--user":
24324
- user = requireValue8(rest, token);
24641
+ user = requireValue9(rest, token);
24325
24642
  break;
24326
24643
  case "--cycle":
24327
- cycle = parseLinearCycle(requireValue8(rest, token));
24644
+ cycle = parseLinearCycle(requireValue9(rest, token));
24328
24645
  break;
24329
24646
  case "--status":
24330
- status = parseLinearStatus(requireValue8(rest, token));
24647
+ status = parseLinearStatus(requireValue9(rest, token));
24331
24648
  break;
24332
24649
  case "--query":
24333
- query = requireValue8(rest, token).trim();
24650
+ query = requireValue9(rest, token).trim();
24334
24651
  break;
24335
24652
  case "--limit": {
24336
- const value = Number.parseInt(requireValue8(rest, token), 10);
24653
+ const value = Number.parseInt(requireValue9(rest, token), 10);
24337
24654
  if (!Number.isInteger(value) || value < 1 || value > 250) {
24338
24655
  throw new Error("Invalid --limit. Expected an integer between 1 and 250.");
24339
24656
  }
@@ -24341,7 +24658,7 @@ function parseLinearIssuesArgs(tokens) {
24341
24658
  break;
24342
24659
  }
24343
24660
  case "--cwd":
24344
- cwd = requireValue8(rest, token);
24661
+ cwd = requireValue9(rest, token);
24345
24662
  break;
24346
24663
  default:
24347
24664
  throw new Error(`Unknown linear option: ${token}`);
@@ -24382,10 +24699,10 @@ function parseLinearLegacyArgs(tokens) {
24382
24699
  useScreenshot = true;
24383
24700
  break;
24384
24701
  case "--account":
24385
- account = requireValue8(rest, token);
24702
+ account = requireValue9(rest, token);
24386
24703
  break;
24387
24704
  case "--cwd":
24388
- cwd = requireValue8(rest, token);
24705
+ cwd = requireValue9(rest, token);
24389
24706
  break;
24390
24707
  default:
24391
24708
  throw new Error(`Unknown linear option: ${token}`);
@@ -24479,19 +24796,19 @@ function parseNotionArgs(tokens) {
24479
24796
  const token = rest.shift();
24480
24797
  switch (token) {
24481
24798
  case "--parent":
24482
- parentPageId = requireValue8(rest, token);
24799
+ parentPageId = requireValue9(rest, token);
24483
24800
  break;
24484
24801
  case "--title":
24485
- title = requireValue8(rest, token);
24802
+ title = requireValue9(rest, token);
24486
24803
  break;
24487
24804
  case "--private":
24488
24805
  isPrivate = true;
24489
24806
  break;
24490
24807
  case "--content":
24491
- content2 = requireValue8(rest, token);
24808
+ content2 = requireValue9(rest, token);
24492
24809
  break;
24493
24810
  case "--file":
24494
- filePath2 = requireValue8(rest, token);
24811
+ filePath2 = requireValue9(rest, token);
24495
24812
  break;
24496
24813
  default:
24497
24814
  throw new Error(`Unknown notion option: ${token}`);
@@ -24535,10 +24852,10 @@ function parseNotionArgs(tokens) {
24535
24852
  const token = rest.shift();
24536
24853
  switch (token) {
24537
24854
  case "--content":
24538
- content = requireValue8(rest, token);
24855
+ content = requireValue9(rest, token);
24539
24856
  break;
24540
24857
  case "--file":
24541
- filePath = requireValue8(rest, token);
24858
+ filePath = requireValue9(rest, token);
24542
24859
  break;
24543
24860
  case "--append":
24544
24861
  append = true;
@@ -24583,11 +24900,11 @@ function parseRandomArgs(tokens) {
24583
24900
  mode = "easy";
24584
24901
  break;
24585
24902
  case "--length":
24586
- length = parsePositiveInt(requireValue8(rest, token), token);
24903
+ length = parsePositiveInt(requireValue9(rest, token), token);
24587
24904
  seenLength = true;
24588
24905
  break;
24589
24906
  case "--charset": {
24590
- const value = requireValue8(rest, token);
24907
+ const value = requireValue9(rest, token);
24591
24908
  if (!["base64url", "hex", "alnum", "ascii"].includes(value)) {
24592
24909
  throw new Error(
24593
24910
  `Invalid --charset value: ${value}. Use base64url|hex|alnum|ascii.`
@@ -24598,18 +24915,18 @@ function parseRandomArgs(tokens) {
24598
24915
  break;
24599
24916
  }
24600
24917
  case "--count":
24601
- count = parsePositiveInt(requireValue8(rest, token), token);
24918
+ count = parsePositiveInt(requireValue9(rest, token), token);
24602
24919
  break;
24603
24920
  case "--words":
24604
- words = parsePositiveInt(requireValue8(rest, token), token);
24921
+ words = parsePositiveInt(requireValue9(rest, token), token);
24605
24922
  seenWords = true;
24606
24923
  break;
24607
24924
  case "--digits":
24608
- digits = parseNonNegativeInt(requireValue8(rest, token), token);
24925
+ digits = parseNonNegativeInt(requireValue9(rest, token), token);
24609
24926
  seenDigits = true;
24610
24927
  break;
24611
24928
  case "--separator":
24612
- separator = requireValue8(rest, token);
24929
+ separator = requireValue9(rest, token);
24613
24930
  seenSeparator = true;
24614
24931
  break;
24615
24932
  default:
@@ -24640,40 +24957,7 @@ function parseRandomArgs(tokens) {
24640
24957
  count
24641
24958
  };
24642
24959
  }
24643
- function parseCollectArgs(tokens) {
24644
- const rest = [...tokens];
24645
- const options = {
24646
- endpoint: "http://localhost:9222",
24647
- json: false,
24648
- mode: "list",
24649
- threadName: void 0
24650
- };
24651
- while (rest.length > 0) {
24652
- const token = rest.shift();
24653
- switch (token) {
24654
- case "--endpoint":
24655
- options.endpoint = requireValue8(rest, token);
24656
- break;
24657
- case "--json":
24658
- options.json = true;
24659
- break;
24660
- case "--list":
24661
- options.mode = "list";
24662
- break;
24663
- case "--thread":
24664
- options.mode = "thread";
24665
- options.threadName = requireValue8(rest, token);
24666
- break;
24667
- default:
24668
- throw new Error(`Unknown collect option: ${token}`);
24669
- }
24670
- }
24671
- if (options.mode === "thread" && !options.threadName) {
24672
- throw new Error("Missing thread name. Usage: collect --thread <name>.");
24673
- }
24674
- return { type: "collect" /* Collect */, ...options };
24675
- }
24676
- function requireValue8(tokens, optionName) {
24960
+ function requireValue9(tokens, optionName) {
24677
24961
  const value = tokens.shift();
24678
24962
  if (!value) {
24679
24963
  throw new Error(`Missing value for ${optionName}`);