miantiao.me 0.4.0 → 0.5.0

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.
@@ -2,16 +2,17 @@ import {
2
2
  define_TERMINAL_CODE_COLORS_default,
3
3
  define_TERMINAL_HOME_default,
4
4
  define_TERMINAL_PALETTES_default
5
- } from "./chunk-CPSJKI42.js";
5
+ } from "./chunk-WZFV5ZVF.js";
6
6
 
7
7
  // packages/cli/src/app.tsx
8
8
  import { AssistantRuntimeProvider } from "@assistant-ui/react-ink";
9
- import { Box as Box22, render, Text as Text25, useApp as useApp2, useInput as useInput11, useWindowSize as useWindowSize3 } from "ink";
9
+ import { Box as Box23, render, Text as Text26, useApp as useApp2, useInput as useInput11, useWindowSize as useWindowSize3 } from "ink";
10
10
  import { useEffect as useEffect11, useState as useState14 } from "react";
11
+ import { MemoryRouter } from "react-router";
11
12
 
12
- // src/terminal/schema.ts
13
+ // src/shared/terminal.ts
13
14
  import { z } from "zod";
14
- var terminalApiPath = "/api/terminal/v1";
15
+ var terminalApiPath = "/api/terminal/v2";
15
16
  var linkSchema = z.object({ title: z.string(), href: z.string() });
16
17
  var pageSchema = z.object({
17
18
  path: z.string(),
@@ -37,15 +38,15 @@ var terminalPostSchema = z.object({
37
38
  documentUrl: z.string()
38
39
  });
39
40
  var terminalIndexSchema = z.object({
40
- schemaVersion: z.literal(1),
41
+ schemaVersion: z.literal(2),
41
42
  revision: z.string().min(1),
42
43
  site: z.object({
43
44
  name: z.string(),
44
45
  description: z.string(),
45
46
  url: z.string(),
46
47
  feedUrl: z.string(),
47
- sponsorUrl: z.string().optional(),
48
- pageSize: z.number().int().positive().optional(),
48
+ sponsorUrl: z.string(),
49
+ pageSize: z.number().int().positive(),
49
50
  author: z.object({ name: z.string(), roles: z.array(z.string()) }),
50
51
  nav: z.array(linkSchema),
51
52
  socials: z.array(linkSchema),
@@ -60,43 +61,39 @@ var terminalIndexSchema = z.object({
60
61
  ),
61
62
  searchIndexUrl: z.string()
62
63
  });
63
- var sectionSchema = z.discriminatedUnion("kind", [
64
+ var listSchema = z.discriminatedUnion("kind", [
64
65
  z.object({
65
- kind: z.literal("welcome"),
66
- markdown: z.string(),
67
- logo: z.string().optional(),
68
- menu: z.array(linkSchema.extend({ command: z.string() })).optional()
66
+ kind: z.literal("projects"),
67
+ before: z.string(),
68
+ after: z.string(),
69
+ items: z.array(terminalProjectSchema)
69
70
  }),
70
71
  z.object({
71
- kind: z.literal("turn"),
72
- prompt: z.string(),
73
- markdown: z.string(),
74
- list: z.discriminatedUnion("kind", [
75
- z.object({
76
- kind: z.literal("projects"),
77
- before: z.string(),
78
- after: z.string(),
79
- items: z.array(terminalProjectSchema)
80
- }),
81
- z.object({
82
- kind: z.literal("posts"),
83
- before: z.string(),
84
- after: z.string(),
85
- items: z.array(terminalPostSchema)
86
- })
87
- ]).optional()
72
+ kind: z.literal("posts"),
73
+ before: z.string(),
74
+ after: z.string(),
75
+ items: z.array(terminalPostSchema)
88
76
  })
89
77
  ]);
78
+ var sectionSchema = z.union([
79
+ z.object({
80
+ kind: z.literal("welcome"),
81
+ markdown: z.string(),
82
+ logo: z.string(),
83
+ menu: z.array(linkSchema.extend({ command: z.string() }))
84
+ }),
85
+ z.object({ kind: z.literal("turn"), prompt: z.string(), list: listSchema }),
86
+ z.object({ kind: z.literal("turn"), prompt: z.string(), markdown: z.string() })
87
+ ]);
90
88
  var terminalDocumentSchema = z.object({
91
- schemaVersion: z.literal(1),
89
+ schemaVersion: z.literal(2),
92
90
  revision: z.string().min(1),
93
91
  path: z.string(),
94
92
  title: z.string(),
95
- markdown: z.string().min(1),
96
- sections: z.array(sectionSchema).optional()
93
+ content: z.union([z.string().min(1), z.array(sectionSchema).nonempty()])
97
94
  });
98
95
 
99
- // src/utils/search-core.ts
96
+ // src/shared/search/manager.ts
100
97
  import { Document } from "flexsearch";
101
98
  var SearchManager = class _SearchManager {
102
99
  index;
@@ -173,7 +170,7 @@ var SearchManager = class _SearchManager {
173
170
  }
174
171
  };
175
172
 
176
- // src/utils/search-schema.ts
173
+ // src/shared/search/schema.ts
177
174
  import { z as z2 } from "zod";
178
175
  var searchIndexSchema = z2.array(
179
176
  z2.object({
@@ -191,7 +188,7 @@ var searchIndexSchema = z2.array(
191
188
  })
192
189
  );
193
190
 
194
- // packages/cli/src/client.ts
191
+ // packages/cli/src/content/client.ts
195
192
  var ContentError = class extends Error {
196
193
  constructor(message, status) {
197
194
  super(message);
@@ -209,6 +206,7 @@ var TerminalClient = class {
209
206
  cache = /* @__PURE__ */ new Map();
210
207
  pending = /* @__PURE__ */ new Map();
211
208
  revision;
209
+ requestOrder = 0;
212
210
  searchLoad;
213
211
  warning = "";
214
212
  async request(path, schema, signal) {
@@ -225,6 +223,7 @@ var TerminalClient = class {
225
223
  }
226
224
  }
227
225
  async fetchDocument(url, schema, signal) {
226
+ const order = ++this.requestOrder;
228
227
  const cached = this.cache.get(url);
229
228
  const headers = new Headers({ Accept: "application/json" });
230
229
  if (cached?.etag) headers.set("If-None-Match", cached.etag);
@@ -234,30 +233,34 @@ var TerminalClient = class {
234
233
  headers,
235
234
  signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(15e3)]) : AbortSignal.timeout(15e3)
236
235
  });
236
+ signal?.throwIfAborted();
237
237
  if (response.status >= 500) {
238
238
  await response.body?.cancel();
239
239
  throw new Error(`HTTP ${response.status}`);
240
240
  }
241
- if (response.status === 304 && cached) return cached.value;
242
- if (!response.ok) {
243
- await response.body?.cancel();
244
- throw new ContentError(
245
- response.status === 404 ? "\u5B98\u7F51\u5C1A\u672A\u63D0\u4F9B\u8BE5\u5185\u5BB9\uFF0C\u6216\u5185\u5BB9\u5DF2\u66F4\u65B0\uFF1B\u8BF7\u4F7F\u7528 /refresh \u91CD\u8BD5\u3002" : `\u5B98\u7F51\u5185\u5BB9\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${response.status}\uFF09\u3002`,
246
- response.status
247
- );
241
+ let result;
242
+ if (response.status === 304 && cached) result = cached;
243
+ else {
244
+ if (!response.ok) {
245
+ await response.body?.cancel();
246
+ throw new ContentError(
247
+ response.status === 404 ? "\u5B98\u7F51\u5C1A\u672A\u63D0\u4F9B\u8BE5\u5185\u5BB9\uFF0C\u6216\u5185\u5BB9\u5DF2\u66F4\u65B0\uFF1B\u8BF7\u4F7F\u7528 /refresh \u91CD\u8BD5\u3002" : `\u5B98\u7F51\u5185\u5BB9\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${response.status}\uFF09\u3002`,
248
+ response.status
249
+ );
250
+ }
251
+ const body = await response.json();
252
+ signal?.throwIfAborted();
253
+ const value = schema.safeParse(body);
254
+ if (!value.success)
255
+ throw new ContentError("\u5B98\u7F51\u5185\u5BB9\u683C\u5F0F\u4E0E\u5F53\u524D CLI \u4E0D\u517C\u5BB9\uFF0C\u8BF7\u8FD0\u884C npx miantiao.me@latest\u3002");
256
+ result = {
257
+ value: value.data,
258
+ etag: response.headers.get("etag"),
259
+ modified: response.headers.get("last-modified")
260
+ };
248
261
  }
249
- signal?.throwIfAborted();
250
- const body = await response.json();
251
- signal?.throwIfAborted();
252
- const value = schema.safeParse(body);
253
- if (!value.success)
254
- throw new ContentError("\u5B98\u7F51\u5185\u5BB9\u683C\u5F0F\u4E0E\u5F53\u524D CLI \u4E0D\u517C\u5BB9\uFF0C\u8BF7\u8FD0\u884C npx miantiao.me@latest\u3002");
255
- this.cache.set(url, {
256
- value: value.data,
257
- etag: response.headers.get("etag"),
258
- modified: response.headers.get("last-modified")
259
- });
260
- return value.data;
262
+ if ((this.cache.get(url)?.order ?? 0) < order) this.cache.set(url, { ...result, order });
263
+ return result.value;
261
264
  } catch (error) {
262
265
  if (signal?.aborted || error instanceof ContentError) throw error;
263
266
  if (error instanceof SyntaxError)
@@ -271,9 +274,11 @@ var TerminalClient = class {
271
274
  }
272
275
  async getIndex(signal) {
273
276
  this.warning = "";
274
- const index = await this.request(`${terminalApiPath}/index.json`, terminalIndexSchema, signal);
277
+ const path = `${terminalApiPath}/index.json`;
278
+ const loaded = await this.request(path, terminalIndexSchema, signal);
279
+ const indexUrl = new URL(path, this.site).href;
280
+ const index = this.cache.get(indexUrl)?.value ?? loaded;
275
281
  if (this.revision && this.revision !== index.revision) {
276
- const indexUrl = new URL(`${terminalApiPath}/index.json`, this.site).href;
277
282
  for (const key of this.cache.keys()) {
278
283
  if (key !== indexUrl) this.cache.delete(key);
279
284
  }
@@ -333,46 +338,13 @@ var TerminalClient = class {
333
338
  }
334
339
  };
335
340
 
336
- // packages/cli/src/pages.ts
337
- import { lexer } from "marked";
338
- function homeSections(index, sections) {
339
- return sections?.map((section) => {
340
- if (section.kind !== "turn" || section.list) return section;
341
- for (const token of lexer(section.markdown)) {
342
- if (token.type !== "list") continue;
343
- const links = token.items.map((item) => {
344
- const heading = item.tokens.find(
345
- (child) => child.type === "heading"
346
- );
347
- return heading?.tokens.find((child) => child.type === "link")?.href;
348
- });
349
- const projects = links.map(
350
- (href) => index.projects.find((project) => new URL(project.url).href === href)
351
- );
352
- const posts = links.map(
353
- (href) => index.posts.find((post) => new URL(post.path, index.site.url).href === href)
354
- );
355
- const list = projects.length && projects.every((project) => project !== void 0) ? { kind: "projects", items: projects } : posts.length && posts.every((post) => post !== void 0) ? { kind: "posts", items: posts } : void 0;
356
- if (!list) continue;
357
- const start = section.markdown.indexOf(token.raw);
358
- return {
359
- ...section,
360
- list: {
361
- ...list,
362
- before: section.markdown.slice(0, start),
363
- after: section.markdown.slice(start + token.raw.length)
364
- }
365
- };
366
- }
367
- return section;
368
- });
369
- }
341
+ // packages/cli/src/content/document-page.ts
370
342
  function documentPage(index, document, site, search = "") {
371
343
  const page = {
372
344
  path: document.path + search,
373
345
  title: document.title,
374
- markdown: document.markdown,
375
- sections: document.sections,
346
+ markdown: typeof document.content === "string" ? document.content : void 0,
347
+ sections: Array.isArray(document.content) ? document.content : void 0,
376
348
  verb: "Read",
377
349
  items: [],
378
350
  command: document.path === "/" ? "/home" : document.path.replace(/\/$/, "")
@@ -383,13 +355,8 @@ function documentPage(index, document, site, search = "") {
383
355
  page.tool = { verb: "Read", target: `${post.path.replace(/^\//, "").replace(/\/$/, "")}.md` };
384
356
  page.description = post.description;
385
357
  }
386
- if (document.path === "/about/") {
387
- page.markdown = document.markdown.replace(/^\/about\s*\n+/, "").replace("~/.config/miantiao/PROFILE.md", "~/.config/miantiao/ABOUT.md");
388
- }
389
358
  if (document.path === index.pages.home.path) {
390
- page.sections = homeSections(index, page.sections);
391
- const welcome = page.sections?.find((section) => section.kind === "welcome");
392
- const menu = welcome?.menu ?? index.site.nav.map((link) => ({ ...link, command: void 0 }));
359
+ const menu = page.sections?.flatMap((section) => section.kind === "welcome" ? section.menu : []) ?? [];
393
360
  const origins = new Set([site, index.site.url].map((url) => new URL(url).origin));
394
361
  page.items = menu.map((link) => {
395
362
  const destination = new URL(link.href, site);
@@ -404,112 +371,8 @@ function documentPage(index, document, site, search = "") {
404
371
  }
405
372
  return page;
406
373
  }
407
- async function loadPage(client, path, signal, cachedIndex) {
408
- signal?.throwIfAborted();
409
- const index = cachedIndex ?? await client.getIndex(signal);
410
- const url = new URL(path, client.site);
411
- const pathname = url.pathname.endsWith("/") ? url.pathname : `${url.pathname}/`;
412
- const page = { path: pathname + url.search, title: "", verb: "List", items: [] };
413
- const document = [...Object.values(index.pages), ...index.posts].find(
414
- (item) => new URL(item.path, client.site).pathname === pathname
415
- );
416
- if (document) {
417
- const result = await client.getDocument(document.path, index, signal);
418
- return {
419
- index: result.index,
420
- page: documentPage(result.index, result.document, client.site, url.search)
421
- };
422
- } else if (pathname === "/blog/" || /^\/blog\/\d+\/$/.test(pathname)) {
423
- const size = index.site.pageSize ?? 10;
424
- const total = Math.max(1, Math.ceil(index.posts.length / size));
425
- const current = Number(pathname.match(/\d+/)?.[0] ?? 1);
426
- if (current < 1 || current > total) throw new Error("\u627E\u4E0D\u5230\u8FD9\u4E00\u9875\uFF0C\u8BF7\u4F7F\u7528 /blog \u6D4F\u89C8\u6587\u7AE0\u3002");
427
- const start = (current - 1) * size;
428
- page.title = "\u535A\u5BA2";
429
- page.command = current === 1 ? "/blog" : `/blog ${current}`;
430
- page.aside = `${current}/${total}`;
431
- page.tool = {
432
- verb: "List",
433
- target: "posts/",
434
- detail: `${start + 1}\u2013${Math.min(start + size, index.posts.length)} of ${index.posts.length}`
435
- };
436
- page.items = index.posts.slice(start, start + size).map((post) => ({
437
- title: post.title,
438
- date: post.date,
439
- description: post.description,
440
- path: post.path
441
- }));
442
- page.pagination = {
443
- current,
444
- total,
445
- previous: current > 1 ? current === 2 ? "/blog/" : `/blog/${current - 1}/` : void 0,
446
- next: current < total ? `/blog/${current + 1}/` : void 0
447
- };
448
- } else if (pathname === "/projects/") {
449
- page.title = "\u9879\u76EE";
450
- page.command = "/projects";
451
- page.tool = {
452
- verb: "List",
453
- target: "projects/",
454
- detail: `\u6309 Star \u6392\u5E8F\uFF0C${index.projects.length} \u4E2A`
455
- };
456
- page.description = "\u8FD9\u91CC\u8BB0\u5F55\u6211\u5728\u5DE5\u4F5C\u4E4B\u5916\u6301\u7EED\u6298\u817E\u7684\u5C0F\u9879\u76EE\uFF1A\u6709\u4E9B\u662F\u5DE5\u5177\uFF0C\u6709\u4E9B\u662F\u5B9E\u9A8C\uFF0C\u4E5F\u6709\u4E9B\u53EA\u662F\u597D\u5947\u5FC3\u7684\u526F\u4EA7\u7269\u3002";
457
- page.projects = index.projects;
458
- page.items = index.projects.map((project) => ({
459
- title: `${project.title} \xB7 \u2605 ${project.stars}`,
460
- description: project.description,
461
- path: project.url,
462
- external: true
463
- }));
464
- } else if (pathname === "/tags/") {
465
- page.title = "\u6807\u7B7E";
466
- page.command = "/tags";
467
- page.tool = { verb: "List", target: "tags/", detail: `${index.tags.length} \u4E2A` };
468
- page.tags = index.tags;
469
- page.items = index.tags.map((tag) => ({
470
- title: `#${tag.name}`,
471
- description: String(tag.count),
472
- path: tag.path
473
- }));
474
- } else if (pathname.startsWith("/tags/")) {
475
- const tag = index.tags.find((tag2) => tag2.path === pathname);
476
- if (!tag) throw new Error("\u627E\u4E0D\u5230\u8FD9\u4E2A\u6807\u7B7E\uFF0C\u8BF7\u4F7F\u7528 /tags \u67E5\u627E\u3002");
477
- page.title = `\u6807\u7B7E\uFF1A${tag.name}`;
478
- page.command = `/tags ${tag.name}`;
479
- page.items = index.posts.filter((post) => post.tags.includes(tag.name)).map((post) => ({
480
- title: post.title,
481
- date: post.date,
482
- description: post.description,
483
- path: post.path
484
- }));
485
- page.tool = { verb: "Grep", target: `#${tag.name}`, detail: `${page.items.length} \u7BC7` };
486
- page.more = { title: "\u5168\u90E8\u6807\u7B7E", path: "/tags/" };
487
- } else if (pathname === "/search/") {
488
- const query = url.searchParams.get("q") ?? "";
489
- page.title = "\u641C\u7D22";
490
- page.command = query ? `/search ${query}` : "/search";
491
- page.verb = "Search";
492
- if (query) {
493
- const results = await client.search(query, index, signal);
494
- page.items = results.map((post) => ({
495
- title: post.title,
496
- description: post.description,
497
- date: post.date,
498
- path: post.url
499
- }));
500
- }
501
- if (query) page.aside = `${page.items.length} \u6761`;
502
- if (query && !page.items.length) page.markdown = `\u6CA1\u6709\u627E\u5230\u4E0E\u300C${query}\u300D\u76F8\u5173\u7684\u6587\u7AE0`;
503
- } else if (pathname === "/rss/") {
504
- page.title = "\u8BA2\u9605 RSS";
505
- page.items = [{ title: index.site.feedUrl, path: index.site.feedUrl, external: true }];
506
- } else {
507
- throw new Error("\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762\uFF0C\u8BF7\u4F7F\u7528 /help \u67E5\u770B\u547D\u4EE4\u3002");
508
- }
509
- return { index, page };
510
- }
511
374
 
512
- // packages/cli/src/home.ts
375
+ // packages/cli/src/content/home.ts
513
376
  function bundledHome(site) {
514
377
  if (typeof define_TERMINAL_HOME_default === "undefined" || new URL(site).origin !== new URL(define_TERMINAL_HOME_default.index.site.url).origin)
515
378
  return;
@@ -525,7 +388,7 @@ function withHomePosts(page, index) {
525
388
  ...page,
526
389
  postsStatus: void 0,
527
390
  sections: page.sections?.map((section) => {
528
- if (section.kind !== "turn" || section.list?.kind !== "posts") return section;
391
+ if (!("list" in section) || section.list.kind !== "posts") return section;
529
392
  return {
530
393
  ...section,
531
394
  list: {
@@ -541,15 +404,15 @@ function withHomePosts(page, index) {
541
404
  };
542
405
  }
543
406
 
544
- // packages/cli/src/console.tsx
407
+ // packages/cli/src/terminal/console.tsx
545
408
  import { ThreadPrimitive as ThreadPrimitive2 } from "@assistant-ui/react-ink";
546
409
  import { useRef as useRef11 } from "react";
547
410
 
548
- // packages/cli/src/chat.tsx
411
+ // packages/cli/src/components/chat.tsx
549
412
  import { ThreadPrimitive, useAuiState } from "@assistant-ui/react-ink";
550
- import { Box as Box10, Text as Text10 } from "ink";
413
+ import { Box as Box11, Text as Text11 } from "ink";
551
414
 
552
- // src/theme-data.ts
415
+ // src/shared/theme.ts
553
416
  var themes = [
554
417
  {
555
418
  id: "ayu-dark",
@@ -586,32 +449,10 @@ var themeOptions = [
586
449
  ...themes,
587
450
  { id: "auto", name: "Auto", description: "\u8DDF\u968F\u7CFB\u7EDF\u5207\u6362 Ayu \u6DF1\u6D45\u8272" }
588
451
  ];
589
- var themeAliases = {
590
- dark: "ayu-dark",
591
- night: "ayu-dark",
592
- ayu: "ayu-dark",
593
- light: "ayu-light",
594
- day: "ayu-light",
595
- solarized: "solarized-light",
596
- groknight: "ayu-dark",
597
- "grok-night": "ayu-dark",
598
- grokday: "ayu-light",
599
- "grok-day": "ayu-light",
600
- tokyonight: "nord",
601
- tokyo: "nord",
602
- "tokyo-night": "nord",
603
- rosepine: "dracula",
604
- "rose-pine": "dracula",
605
- "rosepine-moon": "dracula",
606
- "rose-pine-moon": "dracula",
607
- oscura: "ayu-dark",
608
- "oscura-midnight": "ayu-dark",
609
- system: "auto"
610
- };
611
452
  function parseThemePreference(input) {
612
453
  const name = input?.trim().toLowerCase();
613
454
  if (!name) return void 0;
614
- return themeOptions.find((option) => option.id === name)?.id ?? (Object.hasOwn(themeAliases, name) ? themeAliases[name] : void 0);
455
+ return themeOptions.find((option) => option.id === name)?.id;
615
456
  }
616
457
  function resolveTheme(preference, prefersDark2) {
617
458
  return preference === "auto" ? prefersDark2 ? "ayu-dark" : "ayu-light" : preference;
@@ -620,7 +461,7 @@ function getThemeName(id) {
620
461
  return themeOptions.find((option) => option.id === id)?.name ?? id;
621
462
  }
622
463
 
623
- // src/agent/tool-header.ts
464
+ // src/shared/agent/tool-header.ts
624
465
  function getToolHeader({ toolName, args }) {
625
466
  switch (toolName) {
626
467
  case "set_theme": {
@@ -635,10 +476,10 @@ function getToolHeader({ toolName, args }) {
635
476
  }
636
477
  }
637
478
 
638
- // packages/cli/src/theme.tsx
479
+ // packages/cli/src/terminal/theme.tsx
639
480
  import { createContext, useContext, useMemo } from "react";
640
481
 
641
- // packages/cli/src/code-highlighter.ts
482
+ // packages/cli/src/components/markdown/highlighter.ts
642
483
  import { Chalk } from "chalk";
643
484
  import { useEffect, useState } from "react";
644
485
  var ansi = new Chalk({ level: 3 });
@@ -703,7 +544,7 @@ function useCodeHighlighter(id) {
703
544
  return result?.id === id ? result.highlight : void 0;
704
545
  }
705
546
 
706
- // packages/cli/src/theme.tsx
547
+ // packages/cli/src/terminal/theme.tsx
707
548
  import { stripVTControlCharacters } from "node:util";
708
549
  import { jsx } from "react/jsx-runtime";
709
550
  function cleanText(text) {
@@ -751,13 +592,17 @@ function useTerminalStyle() {
751
592
  return style;
752
593
  }
753
594
 
754
- // packages/cli/src/markdown.tsx
755
- import { MarkdownText } from "@assistant-ui/react-ink-markdown";
756
- import { Box as Box6, Text as Text6, useBoxMetrics } from "ink";
595
+ // packages/cli/src/components/markdown/markdown.tsx
596
+ import { Box as Box7, useBoxMetrics } from "ink";
757
597
  import { lexer as lexer2 } from "marked";
758
598
  import { useMemo as useMemo2, useRef as useRef3 } from "react";
759
599
 
760
- // packages/cli/src/home-links.tsx
600
+ // packages/cli/src/components/markdown/blocks.tsx
601
+ import { MarkdownText } from "@assistant-ui/react-ink-markdown";
602
+ import { Box as Box6, Text as Text7 } from "ink";
603
+ import { lexer } from "marked";
604
+
605
+ // packages/cli/src/components/home-links.tsx
761
606
  import { Text as Text2 } from "ink";
762
607
 
763
608
  // packages/cli/src/components/ui/grid.tsx
@@ -780,7 +625,7 @@ import { Text, useFocus, useFocusManager, useInput } from "ink";
780
625
  import InkLink from "ink-link";
781
626
  import { useId, useLayoutEffect as useLayoutEffect2 } from "react";
782
627
 
783
- // packages/cli/src/mouse.tsx
628
+ // packages/cli/src/terminal/mouse.tsx
784
629
  import { Box as Box2, useStdin, useStdout } from "ink";
785
630
  import {
786
631
  createContext as createContext2,
@@ -791,7 +636,7 @@ import {
791
636
  useState as useState2
792
637
  } from "react";
793
638
 
794
- // packages/cli/src/mouse-hit.ts
639
+ // packages/cli/src/terminal/mouse-hit.ts
795
640
  import { measureElement } from "ink";
796
641
  function bounds(element) {
797
642
  const rect = measureElement(element);
@@ -831,12 +676,14 @@ function paintOrder(a, b) {
831
676
  return siblings.indexOf(left[index]) - siblings.indexOf(right[index]);
832
677
  }
833
678
 
834
- // packages/cli/src/mouse-input.ts
679
+ // packages/cli/src/terminal/mouse-input.ts
835
680
  function mouseParser(onEvent) {
836
681
  let pending = "";
837
682
  return (chunk2) => {
838
- const input = pending + chunk2.toString();
839
- for (const match of input.matchAll(/\x1b\[<(\d+);(\d+);(\d+)([Mm])/g)) {
683
+ const sequences = (pending + chunk2.toString()).split("\x1B").slice(1);
684
+ for (const sequence of sequences) {
685
+ const match = /^\[<(\d+);(\d+);(\d+)([Mm])/.exec(sequence);
686
+ if (!match) continue;
840
687
  onEvent({
841
688
  button: Number(match[1]),
842
689
  x: Number(match[2]) - 1,
@@ -844,12 +691,12 @@ function mouseParser(onEvent) {
844
691
  release: match[4] === "m"
845
692
  });
846
693
  }
847
- const tail = input.slice(input.lastIndexOf("\x1B"));
848
- pending = /^\x1b(?:\[(?:<[\d;]*)?)?$/.test(tail) ? tail : "";
694
+ const tail = sequences.at(-1);
695
+ pending = tail !== void 0 && /^(?:\[(?:<[\d;]*)?)?$/.test(tail) ? "\x1B" + tail : "";
849
696
  };
850
697
  }
851
698
 
852
- // packages/cli/src/mouse.tsx
699
+ // packages/cli/src/terminal/mouse.tsx
853
700
  import { jsx as jsx3 } from "react/jsx-runtime";
854
701
  var MouseContext = createContext2(null);
855
702
  function MouseProvider({ children }) {
@@ -956,7 +803,7 @@ function Link({
956
803
  );
957
804
  }
958
805
 
959
- // packages/cli/src/link.tsx
806
+ // packages/cli/src/terminal/link.tsx
960
807
  import {
961
808
  createContext as createContext3,
962
809
  useContext as useContext3,
@@ -1029,7 +876,7 @@ function TerminalLink({
1029
876
  );
1030
877
  }
1031
878
 
1032
- // packages/cli/src/home-links.tsx
879
+ // packages/cli/src/components/home-links.tsx
1033
880
  import { jsx as jsx6, jsxs } from "react/jsx-runtime";
1034
881
  function homeLinks(list) {
1035
882
  if (list.ordered || !list.items.length) return;
@@ -1057,9 +904,57 @@ function HomeLinks({ items, width }) {
1057
904
  ] }, link.href)) });
1058
905
  }
1059
906
 
1060
- // packages/cli/src/tool.tsx
1061
- import { Box as Box3, Text as Text3 } from "ink";
1062
- import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
907
+ // packages/cli/src/components/markdown/inline.tsx
908
+ import { Text as Text3 } from "ink";
909
+ import { jsx as jsx7 } from "react/jsx-runtime";
910
+ function Inline({ tokens, plainLinks = false }) {
911
+ const { colors } = useTerminalStyle();
912
+ return tokens.map((token, index) => {
913
+ if (token.type === "link" || token.type === "image")
914
+ return /* @__PURE__ */ jsx7(
915
+ TerminalLink,
916
+ {
917
+ inline: true,
918
+ href: token.href,
919
+ color: plainLinks ? colors.fg : void 0,
920
+ underline: !plainLinks,
921
+ children: "tokens" in token && token.tokens ? /* @__PURE__ */ jsx7(Inline, { tokens: token.tokens, plainLinks }) : cleanText(token.text)
922
+ },
923
+ index
924
+ );
925
+ if (token.type === "br") return "\n";
926
+ if (!("text" in token)) return token.raw;
927
+ const children = "tokens" in token && token.tokens ? /* @__PURE__ */ jsx7(Inline, { tokens: token.tokens, plainLinks }) : cleanText(token.text);
928
+ let color = plainLinks ? colors.muted : void 0;
929
+ if (token.type === "codespan") color = colors.code;
930
+ else if (token.type === "strong") color = colors["fg-soft"];
931
+ return /* @__PURE__ */ jsx7(
932
+ Text3,
933
+ {
934
+ bold: token.type === "strong" || token.type === "codespan",
935
+ italic: token.type === "em",
936
+ strikethrough: token.type === "del",
937
+ color,
938
+ children
939
+ },
940
+ index
941
+ );
942
+ });
943
+ }
944
+ function hasLink(token) {
945
+ if (token.type === "link" || token.type === "image") return true;
946
+ if (token.type === "list")
947
+ return token.items.some((item) => item.tokens.some((child) => hasLink(child)));
948
+ if (token.type === "table")
949
+ return [token.header, ...token.rows].some(
950
+ (row) => row.some((cell) => cell.tokens.some((child) => hasLink(child)))
951
+ );
952
+ return "tokens" in token && !!token.tokens?.some((child) => hasLink(child));
953
+ }
954
+
955
+ // packages/cli/src/components/tool.tsx
956
+ import { Box as Box3, Text as Text4 } from "ink";
957
+ import { jsx as jsx8, jsxs as jsxs2 } from "react/jsx-runtime";
1063
958
  function parseTool(text) {
1064
959
  const match = /^◆\s+\*\*([^*]+)\*\*\s+(\S+)(?:\s+\((.+)\))?\s*$/.exec(text.trim());
1065
960
  if (match) return { verb: match[1], target: match[2], detail: match[3] };
@@ -1074,27 +969,27 @@ function Tool({
1074
969
  const { colors } = useTerminalStyle();
1075
970
  const description = state === "running" ? "\u6267\u884C\u4E2D\u2026" : detail;
1076
971
  return /* @__PURE__ */ jsxs2(Box3, { children: [
1077
- /* @__PURE__ */ jsx7(Text3, { color: state === "error" ? colors.err : colors.muted, children: state === "error" ? "\u2717 " : "\u25C6 " }),
1078
- /* @__PURE__ */ jsx7(Box3, { flexGrow: 1, flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsxs2(Text3, { children: [
1079
- /* @__PURE__ */ jsx7(Text3, { color: colors.fg, bold: true, children: cleanText(verb) }),
1080
- /* @__PURE__ */ jsxs2(Text3, { color: colors.path, children: [
972
+ /* @__PURE__ */ jsx8(Text4, { color: state === "error" ? colors.err : colors.muted, children: state === "error" ? "\u2717 " : "\u25C6 " }),
973
+ /* @__PURE__ */ jsx8(Box3, { flexGrow: 1, flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsxs2(Text4, { children: [
974
+ /* @__PURE__ */ jsx8(Text4, { color: colors.fg, bold: true, children: cleanText(verb) }),
975
+ /* @__PURE__ */ jsxs2(Text4, { color: colors.path, children: [
1081
976
  " ",
1082
977
  cleanText(target)
1083
978
  ] }),
1084
- description && /* @__PURE__ */ jsxs2(Text3, { color: colors.muted, children: [
979
+ description && /* @__PURE__ */ jsxs2(Text4, { color: colors.muted, children: [
1085
980
  " (",
1086
981
  cleanText(description),
1087
982
  ")"
1088
983
  ] })
1089
984
  ] }) }),
1090
- aside && /* @__PURE__ */ jsx7(Box3, { paddingLeft: 2, flexShrink: 0, children: /* @__PURE__ */ jsx7(Text3, { color: colors.muted, children: cleanText(aside) }) })
985
+ aside && /* @__PURE__ */ jsx8(Box3, { paddingLeft: 2, flexShrink: 0, children: /* @__PURE__ */ jsx8(Text4, { color: colors.muted, children: cleanText(aside) }) })
1091
986
  ] });
1092
987
  }
1093
988
 
1094
989
  // packages/cli/src/components/ui/table.tsx
1095
- import { Box as Box4, Text as Text4 } from "ink";
990
+ import { Box as Box4, Text as Text5 } from "ink";
1096
991
  import stringWidth from "string-width";
1097
- import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
992
+ import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
1098
993
  function Table({ header, rows, width }) {
1099
994
  const { colors } = useTerminalStyle();
1100
995
  const count = header.length;
@@ -1115,22 +1010,22 @@ function Table({ header, rows, width }) {
1115
1010
  remaining--;
1116
1011
  }
1117
1012
  if (width < count * 4 + 1) {
1118
- return /* @__PURE__ */ jsx8(Box4, { flexDirection: "column", gap: 1, children: rows.map((row, index) => /* @__PURE__ */ jsx8(LinkRow, { flexDirection: "column", children: row.map((cell, column) => /* @__PURE__ */ jsxs3(Text4, { color: colors["fg-soft"], children: [
1119
- /* @__PURE__ */ jsxs3(Text4, { bold: true, children: [
1013
+ return /* @__PURE__ */ jsx9(Box4, { flexDirection: "column", gap: 1, children: rows.map((row, index) => /* @__PURE__ */ jsx9(LinkRow, { flexDirection: "column", children: row.map((cell, column) => /* @__PURE__ */ jsxs3(Text5, { color: colors["fg-soft"], children: [
1014
+ /* @__PURE__ */ jsxs3(Text5, { bold: true, children: [
1120
1015
  header[column]?.text,
1121
1016
  ": "
1122
1017
  ] }),
1123
1018
  cell.content
1124
1019
  ] }, column)) }, index)) });
1125
1020
  }
1126
- return /* @__PURE__ */ jsx8(
1021
+ return /* @__PURE__ */ jsx9(
1127
1022
  Box4,
1128
1023
  {
1129
1024
  borderStyle: "single",
1130
1025
  borderColor: colors.line,
1131
1026
  flexDirection: "column",
1132
1027
  alignSelf: "flex-start",
1133
- children: [header, ...rows].map((row, rowIndex) => /* @__PURE__ */ jsx8(LinkRow, { children: row.map((cell, column) => /* @__PURE__ */ jsx8(
1028
+ children: [header, ...rows].map((row, rowIndex) => /* @__PURE__ */ jsx9(LinkRow, { children: row.map((cell, column) => /* @__PURE__ */ jsx9(
1134
1029
  Box4,
1135
1030
  {
1136
1031
  width: widths[column] + 2 + Number(column < count - 1),
@@ -1141,7 +1036,7 @@ function Table({ header, rows, width }) {
1141
1036
  borderLeft: false,
1142
1037
  borderRight: column < count - 1,
1143
1038
  borderColor: colors.line,
1144
- children: /* @__PURE__ */ jsx8(Text4, { bold: rowIndex === 0, color: rowIndex === 0 ? colors.fg : colors["fg-soft"], children: cell.content })
1039
+ children: /* @__PURE__ */ jsx9(Text5, { bold: rowIndex === 0, color: rowIndex === 0 ? colors.fg : colors["fg-soft"], children: cell.content })
1145
1040
  },
1146
1041
  column
1147
1042
  )) }, rowIndex))
@@ -1150,10 +1045,10 @@ function Table({ header, rows, width }) {
1150
1045
  }
1151
1046
 
1152
1047
  // packages/cli/src/components/ui/thinking-block.tsx
1153
- import { Box as Box5, Text as Text5, useFocus as useFocus2, useInput as useInput2 } from "ink";
1048
+ import { Box as Box5, Text as Text6, useFocus as useFocus2, useInput as useInput2 } from "ink";
1154
1049
  import { useContext as useContext4, useId as useId2, useState as useState4 } from "react";
1155
1050
 
1156
- // src/agent/useElapsedTime.ts
1051
+ // src/shared/hooks/useElapsedTime.ts
1157
1052
  import { useEffect as useEffect3, useState as useState3 } from "react";
1158
1053
  function useElapsedTime(active, live = false) {
1159
1054
  const [seconds, setSeconds] = useState3(0);
@@ -1176,7 +1071,7 @@ function useElapsedTime(active, live = false) {
1176
1071
  }
1177
1072
 
1178
1073
  // packages/cli/src/components/ui/thinking-block.tsx
1179
- import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
1074
+ import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
1180
1075
  function Summary({
1181
1076
  label,
1182
1077
  collapsed,
@@ -1193,7 +1088,7 @@ function Summary({
1193
1088
  },
1194
1089
  { isActive: active && isFocused }
1195
1090
  );
1196
- return /* @__PURE__ */ jsx9(
1091
+ return /* @__PURE__ */ jsx10(
1197
1092
  LinkRow,
1198
1093
  {
1199
1094
  reveal: isFocused,
@@ -1203,7 +1098,7 @@ function Summary({
1203
1098
  },
1204
1099
  "aria-role": "button",
1205
1100
  "aria-state": { expanded: !collapsed, busy: streaming },
1206
- children: /* @__PURE__ */ jsxs4(Text5, { color: colors.muted, inverse: isFocused, children: [
1101
+ children: /* @__PURE__ */ jsxs4(Text6, { color: colors.muted, inverse: isFocused, children: [
1207
1102
  "\u25C6 ",
1208
1103
  label,
1209
1104
  " ",
@@ -1223,7 +1118,7 @@ function ThinkingBlock({
1223
1118
  const [collapsed, setCollapsed] = useState4(true);
1224
1119
  const seconds = useElapsedTime(streaming);
1225
1120
  return /* @__PURE__ */ jsxs4(Box5, { flexDirection: "column", children: [
1226
- /* @__PURE__ */ jsx9(
1121
+ /* @__PURE__ */ jsx10(
1227
1122
  Summary,
1228
1123
  {
1229
1124
  label: label ?? (streaming ? "\u601D\u8003\u4E2D\u2026" : `\u601D\u8003 ${seconds.toFixed(1)}s`),
@@ -1232,7 +1127,7 @@ function ThinkingBlock({
1232
1127
  onToggle: () => setCollapsed((value) => !value)
1233
1128
  }
1234
1129
  ),
1235
- /* @__PURE__ */ jsx9(LinkScope, { value: active && !collapsed, children: /* @__PURE__ */ jsx9(
1130
+ /* @__PURE__ */ jsx10(LinkScope, { value: active && !collapsed, children: /* @__PURE__ */ jsx10(
1236
1131
  Box5,
1237
1132
  {
1238
1133
  display: collapsed ? "none" : "flex",
@@ -1245,58 +1140,17 @@ function ThinkingBlock({
1245
1140
  borderColor: colors.dim,
1246
1141
  paddingLeft: 2,
1247
1142
  marginTop: 1,
1248
- children: children ?? /* @__PURE__ */ jsx9(Text5, { color: colors.muted, children: cleanText(content) })
1143
+ children: children ?? /* @__PURE__ */ jsx10(Text6, { color: colors.muted, children: cleanText(content) })
1249
1144
  }
1250
1145
  ) })
1251
1146
  ] });
1252
1147
  }
1253
1148
 
1254
- // packages/cli/src/markdown.tsx
1255
- import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
1256
- function Inline({ tokens, plainLinks = false }) {
1257
- const { colors } = useTerminalStyle();
1258
- return tokens.map((token, index) => {
1259
- if (token.type === "link" || token.type === "image")
1260
- return /* @__PURE__ */ jsx10(
1261
- TerminalLink,
1262
- {
1263
- inline: true,
1264
- href: token.href,
1265
- color: plainLinks ? colors.fg : void 0,
1266
- underline: !plainLinks,
1267
- children: "tokens" in token && token.tokens ? /* @__PURE__ */ jsx10(Inline, { tokens: token.tokens, plainLinks }) : cleanText(token.text)
1268
- },
1269
- index
1270
- );
1271
- if (token.type === "br") return "\n";
1272
- if (!("text" in token)) return token.raw;
1273
- const children = "tokens" in token && token.tokens ? /* @__PURE__ */ jsx10(Inline, { tokens: token.tokens, plainLinks }) : cleanText(token.text);
1274
- return /* @__PURE__ */ jsx10(
1275
- Text6,
1276
- {
1277
- bold: token.type === "strong" || token.type === "codespan",
1278
- italic: token.type === "em",
1279
- strikethrough: token.type === "del",
1280
- color: token.type === "codespan" ? colors.code : token.type === "strong" ? colors["fg-soft"] : plainLinks ? colors.muted : void 0,
1281
- children
1282
- },
1283
- index
1284
- );
1285
- });
1286
- }
1287
- function hasLink(token) {
1288
- if (token.type === "link" || token.type === "image") return true;
1289
- if (token.type === "list")
1290
- return token.items.some((item) => item.tokens.some((child) => hasLink(child)));
1291
- if (token.type === "table")
1292
- return [token.header, ...token.rows].some(
1293
- (row) => row.some((cell) => cell.tokens.some((child) => hasLink(child)))
1294
- );
1295
- return "tokens" in token && !!token.tokens?.some((child) => hasLink(child));
1296
- }
1149
+ // packages/cli/src/components/markdown/blocks.tsx
1150
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
1297
1151
  function PlainMarkdown({ text, width }) {
1298
1152
  const { colors, markdownTheme, highlighter } = useTerminalStyle();
1299
- return /* @__PURE__ */ jsx10(Text6, { color: colors["fg-soft"], children: /* @__PURE__ */ jsx10(
1153
+ return /* @__PURE__ */ jsx11(Text7, { color: colors["fg-soft"], children: /* @__PURE__ */ jsx11(
1300
1154
  MarkdownText,
1301
1155
  {
1302
1156
  text,
@@ -1319,17 +1173,17 @@ function Blocks({
1319
1173
  const { colors } = useTerminalStyle();
1320
1174
  return tokens.filter((token) => token.type !== "space").map((token, index) => {
1321
1175
  const tool2 = token.type === "paragraph" ? parseTool(token.text) : void 0;
1322
- if (tool2) return /* @__PURE__ */ jsx10(Tool, { ...tool2 }, index);
1176
+ if (tool2) return /* @__PURE__ */ jsx11(Tool, { ...tool2 }, index);
1323
1177
  if (!home && !tone && !["heading", "table", "blockquote", "code"].includes(token.type) && !hasLink(token))
1324
- return /* @__PURE__ */ jsx10(PlainMarkdown, { text: token.raw, width }, index);
1178
+ return /* @__PURE__ */ jsx11(PlainMarkdown, { text: token.raw, width }, index);
1325
1179
  if (token.type === "code")
1326
- return /* @__PURE__ */ jsx10(Box6, { backgroundColor: colors.well, paddingX: 2, children: /* @__PURE__ */ jsx10(PlainMarkdown, { text: token.raw, width: Math.max(1, width - 4) }) }, index);
1180
+ return /* @__PURE__ */ jsx11(Box6, { backgroundColor: colors.well, paddingX: 2, children: /* @__PURE__ */ jsx11(PlainMarkdown, { text: token.raw, width: Math.max(1, width - 4) }) }, index);
1327
1181
  if (token.type === "list") {
1328
1182
  const links = home ? homeLinks(token) : void 0;
1329
- if (links) return /* @__PURE__ */ jsx10(HomeLinks, { items: links, width }, index);
1330
- return /* @__PURE__ */ jsx10(Box6, { flexDirection: "column", gap: !home && token.loose ? 1 : 0, children: token.items.map((item, itemIndex) => /* @__PURE__ */ jsxs5(Box6, { children: [
1331
- /* @__PURE__ */ jsx10(Text6, { color: colors.muted, children: token.ordered ? `${Number(token.start) + itemIndex}. ` : "\u2022 " }),
1332
- /* @__PURE__ */ jsx10(Box6, { flexDirection: "column", flexShrink: 1, gap: 1, minWidth: 0, children: /* @__PURE__ */ jsx10(
1183
+ if (links) return /* @__PURE__ */ jsx11(HomeLinks, { items: links, width }, index);
1184
+ return /* @__PURE__ */ jsx11(Box6, { flexDirection: "column", gap: !home && token.loose ? 1 : 0, children: token.items.map((item, itemIndex) => /* @__PURE__ */ jsxs5(Box6, { children: [
1185
+ /* @__PURE__ */ jsx11(Text7, { color: colors.muted, children: token.ordered ? `${Number(token.start) + itemIndex}. ` : "\u2022 " }),
1186
+ /* @__PURE__ */ jsx11(Box6, { flexDirection: "column", flexShrink: 1, gap: 1, minWidth: 0, children: /* @__PURE__ */ jsx11(
1333
1187
  Blocks,
1334
1188
  {
1335
1189
  tokens: item.tokens,
@@ -1342,10 +1196,10 @@ function Blocks({
1342
1196
  }
1343
1197
  if (token.type === "blockquote") {
1344
1198
  if (token.text.startsWith("[!DETAILS]")) {
1345
- const content = lexer2(token.text.slice("[!DETAILS]".length).trim()).filter((child) => child.type !== "space");
1199
+ const content = lexer(token.text.slice("[!DETAILS]".length).trim()).filter((child) => child.type !== "space");
1346
1200
  const summary = content[0];
1347
1201
  const label = summary?.type === "paragraph" ? summary.tokens.map((child) => "text" in child ? child.text : child.raw).join("") : "\u8BE6\u7EC6\u5185\u5BB9";
1348
- return /* @__PURE__ */ jsx10(ThinkingBlock, { label: cleanText(label), children: /* @__PURE__ */ jsx10(
1202
+ return /* @__PURE__ */ jsx11(ThinkingBlock, { label: cleanText(label), children: /* @__PURE__ */ jsx11(
1349
1203
  Blocks,
1350
1204
  {
1351
1205
  tokens: content.slice(1),
@@ -1356,7 +1210,7 @@ function Blocks({
1356
1210
  ) }, index);
1357
1211
  }
1358
1212
  const alert = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*\n?/i.exec(token.text);
1359
- return /* @__PURE__ */ jsx10(
1213
+ return /* @__PURE__ */ jsx11(
1360
1214
  Box6,
1361
1215
  {
1362
1216
  borderStyle: "single",
@@ -1367,10 +1221,10 @@ function Blocks({
1367
1221
  paddingLeft: 2,
1368
1222
  flexDirection: "column",
1369
1223
  gap: 1,
1370
- children: /* @__PURE__ */ jsx10(
1224
+ children: /* @__PURE__ */ jsx11(
1371
1225
  Blocks,
1372
1226
  {
1373
- tokens: alert ? lexer2(token.text.slice(alert[0].length)) : token.tokens,
1227
+ tokens: alert ? lexer(token.text.slice(alert[0].length)) : token.tokens,
1374
1228
  width: width - 3,
1375
1229
  home,
1376
1230
  plainLinks,
@@ -1384,9 +1238,9 @@ function Blocks({
1384
1238
  if (token.type === "table") {
1385
1239
  const cells = (row) => row.map((cell) => ({
1386
1240
  text: cleanText(cell.text),
1387
- content: /* @__PURE__ */ jsx10(Inline, { tokens: cell.tokens })
1241
+ content: /* @__PURE__ */ jsx11(Inline, { tokens: cell.tokens })
1388
1242
  }));
1389
- return /* @__PURE__ */ jsx10(
1243
+ return /* @__PURE__ */ jsx11(
1390
1244
  Table,
1391
1245
  {
1392
1246
  header: cells(token.header),
@@ -1402,7 +1256,7 @@ function Blocks({
1402
1256
  color = colors[level <= 3 ? `h${level}` : "muted"];
1403
1257
  if (home && token.depth === 1) color = colors.fg;
1404
1258
  }
1405
- return /* @__PURE__ */ jsx10(LinkRow, { children: /* @__PURE__ */ jsx10(Text6, { bold: token.type === "heading", color, children: /* @__PURE__ */ jsx10(
1259
+ return /* @__PURE__ */ jsx11(LinkRow, { children: /* @__PURE__ */ jsx11(Text7, { bold: token.type === "heading", color, children: /* @__PURE__ */ jsx11(
1406
1260
  Inline,
1407
1261
  {
1408
1262
  tokens: "tokens" in token ? token.tokens ?? [] : [],
@@ -1411,6 +1265,9 @@ function Blocks({
1411
1265
  ) }) }, index);
1412
1266
  });
1413
1267
  }
1268
+
1269
+ // packages/cli/src/components/markdown/markdown.tsx
1270
+ import { jsx as jsx12 } from "react/jsx-runtime";
1414
1271
  function Markdown({
1415
1272
  text,
1416
1273
  width: availableWidth,
@@ -1425,17 +1282,17 @@ function Markdown({
1425
1282
  const native = tokens.some(
1426
1283
  (token) => home && token.type === "list" || ["heading", "table", "blockquote", "code"].includes(token.type) || hasLink(token)
1427
1284
  );
1428
- return /* @__PURE__ */ jsx10(Box6, { ref: container, flexDirection: "column", gap: compact ? 0 : 1, minWidth: 0, children: native ? /* @__PURE__ */ jsx10(Blocks, { tokens, width: available, home }) : /* @__PURE__ */ jsx10(PlainMarkdown, { text, width: available }) });
1285
+ return /* @__PURE__ */ jsx12(Box7, { ref: container, flexDirection: "column", gap: compact ? 0 : 1, minWidth: 0, children: native ? /* @__PURE__ */ jsx12(Blocks, { tokens, width: available, home }) : /* @__PURE__ */ jsx12(PlainMarkdown, { text, width: available }) });
1429
1286
  }
1430
1287
 
1431
- // packages/cli/src/blocks.tsx
1432
- import { Box as Box9, Text as Text9 } from "ink";
1288
+ // packages/cli/src/components/blocks.tsx
1289
+ import { Box as Box10, Text as Text10 } from "ink";
1433
1290
 
1434
- // packages/cli/src/page-list.tsx
1435
- import { Box as Box7, Text as Text7, useBoxMetrics as useBoxMetrics2 } from "ink";
1291
+ // packages/cli/src/components/page-list.tsx
1292
+ import { Box as Box8, Text as Text8, useBoxMetrics as useBoxMetrics2 } from "ink";
1436
1293
  import { useRef as useRef4 } from "react";
1437
1294
 
1438
- // src/utils/time.ts
1295
+ // src/shared/time.ts
1439
1296
  import { parseISO } from "date-fns/parseISO";
1440
1297
  var shortDateFormatter = new Intl.DateTimeFormat("en-CA", {
1441
1298
  timeZone: "Asia/Shanghai",
@@ -1448,15 +1305,15 @@ function formatShortDate(date) {
1448
1305
  return shortDateFormatter.format(value);
1449
1306
  }
1450
1307
 
1451
- // packages/cli/src/page-list.tsx
1452
- import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
1308
+ // packages/cli/src/components/page-list.tsx
1309
+ import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
1453
1310
  function PageList({ items, compact = false }) {
1454
1311
  const { colors, width } = useTerminalStyle();
1455
1312
  const container = useRef4(null);
1456
1313
  const { clientWidth } = useBoxMetrics2(container);
1457
1314
  const stacked = !compact && (clientWidth || width - 6) < 55;
1458
- return /* @__PURE__ */ jsx11(
1459
- Box7,
1315
+ return /* @__PURE__ */ jsx13(
1316
+ Box8,
1460
1317
  {
1461
1318
  ref: container,
1462
1319
  flexDirection: "column",
@@ -1469,17 +1326,17 @@ function PageList({ items, compact = false }) {
1469
1326
  justifyContent: compact ? "space-between" : void 0,
1470
1327
  marginBottom: compact ? 0 : 1,
1471
1328
  children: [
1472
- /* @__PURE__ */ jsxs6(Box7, { flexDirection: stacked ? "column" : "row", children: [
1473
- item.date && /* @__PURE__ */ jsxs6(Text7, { color: colors.muted, children: [
1329
+ /* @__PURE__ */ jsxs6(Box8, { flexDirection: stacked ? "column" : "row", children: [
1330
+ item.date && /* @__PURE__ */ jsxs6(Text8, { color: colors.muted, children: [
1474
1331
  formatShortDate(item.date),
1475
1332
  " "
1476
1333
  ] }),
1477
- /* @__PURE__ */ jsxs6(Box7, { flexShrink: 1, minWidth: 0, children: [
1478
- !compact && /* @__PURE__ */ jsx11(Text7, { color: colors.muted, children: "\u2022 " }),
1479
- /* @__PURE__ */ jsx11(Box7, { flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsx11(TerminalLink, { href: item.path, color: colors.fg, bold: compact, underline: false, children: cleanText(item.title) }) })
1334
+ /* @__PURE__ */ jsxs6(Box8, { flexShrink: 1, minWidth: 0, children: [
1335
+ !compact && /* @__PURE__ */ jsx13(Text8, { color: colors.muted, children: "\u2022 " }),
1336
+ /* @__PURE__ */ jsx13(Box8, { flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsx13(TerminalLink, { href: item.path, color: colors.fg, bold: compact, underline: false, children: cleanText(item.title) }) })
1480
1337
  ] })
1481
1338
  ] }),
1482
- item.description && /* @__PURE__ */ jsx11(Box7, { paddingLeft: compact ? 0 : item.date && !stacked ? 13 : 2, children: /* @__PURE__ */ jsx11(Text7, { color: colors.muted, children: cleanText(item.description) }) })
1339
+ item.description && /* @__PURE__ */ jsx13(Box8, { paddingLeft: compact ? 0 : item.date && !stacked ? 13 : 2, children: /* @__PURE__ */ jsx13(Text8, { color: colors.muted, children: cleanText(item.description) }) })
1483
1340
  ]
1484
1341
  },
1485
1342
  item.path
@@ -1488,10 +1345,10 @@ function PageList({ items, compact = false }) {
1488
1345
  );
1489
1346
  }
1490
1347
 
1491
- // packages/cli/src/home-list.tsx
1492
- import { Box as Box8, Text as Text8, useBoxMetrics as useBoxMetrics3 } from "ink";
1348
+ // packages/cli/src/components/home-list.tsx
1349
+ import { Box as Box9, Text as Text9, useBoxMetrics as useBoxMetrics3 } from "ink";
1493
1350
  import { useContext as useContext5, useRef as useRef5 } from "react";
1494
- import { jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
1351
+ import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
1495
1352
  function formatStars(stars) {
1496
1353
  return stars >= 1e3 ? `${(stars / 1e3).toFixed(1)}k` : String(stars);
1497
1354
  }
@@ -1502,31 +1359,31 @@ function HomeList({ list }) {
1502
1359
  const { clientWidth } = useBoxMetrics3(container);
1503
1360
  const width = clientWidth || availableWidth - 6;
1504
1361
  if (list.kind === "posts")
1505
- return /* @__PURE__ */ jsx12(Box8, { ref: container, flexDirection: "column", children: Array.from({ length: Math.max(5, list.items.length) }, (_, slot) => slot).map((slot) => {
1362
+ return /* @__PURE__ */ jsx14(Box9, { ref: container, flexDirection: "column", children: Array.from({ length: Math.max(5, list.items.length) }, (_, slot) => slot).map((slot) => {
1506
1363
  const post = list.items[slot];
1507
- return /* @__PURE__ */ jsx12(LinkScope, { value: active && !!post, children: /* @__PURE__ */ jsxs7(
1364
+ return /* @__PURE__ */ jsx14(LinkScope, { value: active && !!post, children: /* @__PURE__ */ jsxs7(
1508
1365
  LinkRow,
1509
1366
  {
1510
1367
  display: post ? "flex" : "none",
1511
1368
  flexDirection: width < 55 ? "column" : "row",
1512
1369
  children: [
1513
- /* @__PURE__ */ jsxs7(Text8, { color: colors.muted, children: [
1370
+ /* @__PURE__ */ jsxs7(Text9, { color: colors.muted, children: [
1514
1371
  post ? formatShortDate(post.date) : "",
1515
1372
  " "
1516
1373
  ] }),
1517
- /* @__PURE__ */ jsxs7(Box8, { flexShrink: 1, minWidth: 0, children: [
1518
- /* @__PURE__ */ jsx12(Text8, { color: colors.muted, children: "\u2022 " }),
1519
- /* @__PURE__ */ jsx12(Box8, { flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsx12(TerminalLink, { href: post?.path ?? "/", color: colors.fg, underline: false, children: post ? cleanText(post.title) : "" }) })
1374
+ /* @__PURE__ */ jsxs7(Box9, { flexShrink: 1, minWidth: 0, children: [
1375
+ /* @__PURE__ */ jsx14(Text9, { color: colors.muted, children: "\u2022 " }),
1376
+ /* @__PURE__ */ jsx14(Box9, { flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsx14(TerminalLink, { href: post?.path ?? "/", color: colors.fg, underline: false, children: post ? cleanText(post.title) : "" }) })
1520
1377
  ] })
1521
1378
  ]
1522
1379
  }
1523
1380
  ) }, slot);
1524
1381
  }) });
1525
1382
  const nameWidth = 20;
1526
- return /* @__PURE__ */ jsx12(Box8, { ref: container, flexDirection: "column", children: list.items.map((project) => /* @__PURE__ */ jsxs7(LinkRow, { flexDirection: width >= 55 ? "row" : "column", children: [
1527
- /* @__PURE__ */ jsxs7(Box8, { flexShrink: 0, children: [
1528
- /* @__PURE__ */ jsx12(Box8, { width: nameWidth, flexShrink: 1, children: /* @__PURE__ */ jsx12(TerminalLink, { href: project.url, color: colors.fg, bold: true, underline: false, children: cleanText(project.title) }) }),
1529
- /* @__PURE__ */ jsx12(Box8, { width: 10, flexShrink: 0, children: project.repo ? /* @__PURE__ */ jsxs7(
1383
+ return /* @__PURE__ */ jsx14(Box9, { ref: container, flexDirection: "column", children: list.items.map((project) => /* @__PURE__ */ jsxs7(LinkRow, { flexDirection: width >= 55 ? "row" : "column", children: [
1384
+ /* @__PURE__ */ jsxs7(Box9, { flexShrink: 0, children: [
1385
+ /* @__PURE__ */ jsx14(Box9, { width: nameWidth, flexShrink: 1, children: /* @__PURE__ */ jsx14(TerminalLink, { href: project.url, color: colors.fg, bold: true, underline: false, children: cleanText(project.title) }) }),
1386
+ /* @__PURE__ */ jsx14(Box9, { width: 10, flexShrink: 0, children: project.repo ? /* @__PURE__ */ jsxs7(
1530
1387
  TerminalLink,
1531
1388
  {
1532
1389
  href: `https://github.com/miantiao-me/${project.repo}`,
@@ -1537,27 +1394,27 @@ function HomeList({ list }) {
1537
1394
  formatStars(project.stars)
1538
1395
  ]
1539
1396
  }
1540
- ) : /* @__PURE__ */ jsxs7(Text8, { color: colors.warn, children: [
1397
+ ) : /* @__PURE__ */ jsxs7(Text9, { color: colors.warn, children: [
1541
1398
  "\u2605 ",
1542
1399
  formatStars(project.stars)
1543
1400
  ] }) })
1544
1401
  ] }),
1545
- /* @__PURE__ */ jsx12(Box8, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsx12(Text8, { color: colors["fg-soft"], children: cleanText(project.description) }) })
1402
+ /* @__PURE__ */ jsx14(Box9, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsx14(Text9, { color: colors["fg-soft"], children: cleanText(project.description) }) })
1546
1403
  ] }, project.url)) });
1547
1404
  }
1548
1405
 
1549
- // packages/cli/src/blocks.tsx
1550
- import { Fragment, jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
1406
+ // packages/cli/src/components/blocks.tsx
1407
+ import { Fragment, jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
1551
1408
  function Prompt({
1552
1409
  text,
1553
1410
  command = false,
1554
1411
  aside
1555
1412
  }) {
1556
1413
  const { colors } = useTerminalStyle();
1557
- return /* @__PURE__ */ jsxs8(Box9, { width: "100%", backgroundColor: colors.band, paddingX: 3, paddingY: 1, children: [
1558
- /* @__PURE__ */ jsx13(Text9, { color: colors.prompt, children: "\u276F " }),
1559
- /* @__PURE__ */ jsx13(Box9, { flexGrow: 1, flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsx13(Text9, { color: command ? colors.skill : colors.fg, children: cleanText(text) }) }),
1560
- aside && /* @__PURE__ */ jsx13(Box9, { paddingLeft: 2, flexShrink: 0, children: /* @__PURE__ */ jsx13(Text9, { color: colors.muted, children: cleanText(aside) }) })
1414
+ return /* @__PURE__ */ jsxs8(Box10, { width: "100%", backgroundColor: colors.band, paddingX: 3, paddingY: 1, children: [
1415
+ /* @__PURE__ */ jsx15(Text10, { color: colors.prompt, children: "\u276F " }),
1416
+ /* @__PURE__ */ jsx15(Box10, { flexGrow: 1, flexShrink: 1, minWidth: 0, children: /* @__PURE__ */ jsx15(Text10, { color: command ? colors.skill : colors.fg, children: cleanText(text) }) }),
1417
+ aside && /* @__PURE__ */ jsx15(Box10, { paddingLeft: 2, flexShrink: 0, children: /* @__PURE__ */ jsx15(Text10, { color: colors.muted, children: cleanText(aside) }) })
1561
1418
  ] });
1562
1419
  }
1563
1420
  function Welcome({
@@ -1566,7 +1423,7 @@ function Welcome({
1566
1423
  }) {
1567
1424
  const { colors, width } = useTerminalStyle();
1568
1425
  return /* @__PURE__ */ jsxs8(
1569
- Box9,
1426
+ Box10,
1570
1427
  {
1571
1428
  borderStyle: "round",
1572
1429
  borderColor: colors.line,
@@ -1575,10 +1432,10 @@ function Welcome({
1575
1432
  gap: 5,
1576
1433
  alignItems: "center",
1577
1434
  children: [
1578
- section.logo && width >= 90 && /* @__PURE__ */ jsx13(Text9, { color: colors.muted, children: cleanText(section.logo) }),
1579
- /* @__PURE__ */ jsxs8(Box9, { flexDirection: "column", flexGrow: 1, flexShrink: 1, minWidth: 0, children: [
1580
- /* @__PURE__ */ jsx13(Markdown, { text: section.markdown, home: true, compact: true }),
1581
- section.menu && selection.items.length > 0 && /* @__PURE__ */ jsx13(PageList, { ...selection, compact: true })
1435
+ section.logo && width >= 90 && /* @__PURE__ */ jsx15(Text10, { color: colors.muted, children: cleanText(section.logo) }),
1436
+ /* @__PURE__ */ jsxs8(Box10, { flexDirection: "column", flexGrow: 1, flexShrink: 1, minWidth: 0, children: [
1437
+ /* @__PURE__ */ jsx15(Markdown, { text: section.markdown, home: true, compact: true }),
1438
+ selection.items.length > 0 && /* @__PURE__ */ jsx15(PageList, { ...selection, compact: true })
1582
1439
  ] })
1583
1440
  ]
1584
1441
  }
@@ -1586,25 +1443,25 @@ function Welcome({
1586
1443
  }
1587
1444
  function HomeSections({ page }) {
1588
1445
  const { colors } = useTerminalStyle();
1589
- return /* @__PURE__ */ jsx13(Box9, { flexDirection: "column", gap: 1, children: page.sections?.map(
1590
- (section) => section.kind === "welcome" ? /* @__PURE__ */ jsx13(Welcome, { section, items: page.items }, "welcome") : /* @__PURE__ */ jsxs8(Box9, { flexDirection: "column", gap: 1, children: [
1591
- /* @__PURE__ */ jsx13(Prompt, { text: section.prompt }),
1592
- /* @__PURE__ */ jsx13(Box9, { flexDirection: "column", paddingX: 3, gap: 1, children: section.list ? /* @__PURE__ */ jsxs8(Fragment, { children: [
1593
- section.list.before && /* @__PURE__ */ jsx13(Markdown, { text: section.list.before, home: true }),
1594
- section.list.kind === "posts" && !section.list.items.length && /* @__PURE__ */ jsx13(Text9, { color: colors.muted, children: page.postsStatus === "error" ? "\u6587\u7AE0\u6682\u65F6\u65E0\u6CD5\u52A0\u8F7D\uFF0C\u8F93\u5165 /refresh \u91CD\u8BD5\u3002" : page.postsStatus === "loading" ? "\u6B63\u5728\u52A0\u8F7D\u6587\u7AE0\u2026" : "\u6682\u65E0\u6587\u7AE0\u3002" }),
1595
- /* @__PURE__ */ jsx13(HomeList, { list: section.list }),
1596
- section.list.after && /* @__PURE__ */ jsx13(Markdown, { text: section.list.after, home: true })
1597
- ] }) : /* @__PURE__ */ jsx13(Markdown, { text: section.markdown, home: true }) })
1446
+ return /* @__PURE__ */ jsx15(Box10, { flexDirection: "column", gap: 1, children: page.sections?.map(
1447
+ (section) => section.kind === "welcome" ? /* @__PURE__ */ jsx15(Welcome, { section, items: page.items }, "welcome") : /* @__PURE__ */ jsxs8(Box10, { flexDirection: "column", gap: 1, children: [
1448
+ /* @__PURE__ */ jsx15(Prompt, { text: section.prompt }),
1449
+ /* @__PURE__ */ jsx15(Box10, { flexDirection: "column", paddingX: 3, gap: 1, children: "list" in section ? /* @__PURE__ */ jsxs8(Fragment, { children: [
1450
+ section.list.before && /* @__PURE__ */ jsx15(Markdown, { text: section.list.before, home: true }),
1451
+ section.list.kind === "posts" && !section.list.items.length && /* @__PURE__ */ jsx15(Text10, { color: colors.muted, children: page.postsStatus === "error" ? "\u6587\u7AE0\u6682\u65F6\u65E0\u6CD5\u52A0\u8F7D\uFF0C\u8F93\u5165 /refresh \u91CD\u8BD5\u3002" : page.postsStatus === "loading" ? "\u6B63\u5728\u52A0\u8F7D\u6587\u7AE0\u2026" : "\u6682\u65E0\u6587\u7AE0\u3002" }),
1452
+ /* @__PURE__ */ jsx15(HomeList, { list: section.list }),
1453
+ section.list.after && /* @__PURE__ */ jsx15(Markdown, { text: section.list.after, home: true })
1454
+ ] }) : /* @__PURE__ */ jsx15(Markdown, { text: section.markdown, home: true }) })
1598
1455
  ] }, section.prompt)
1599
1456
  ) });
1600
1457
  }
1601
1458
 
1602
- // packages/cli/src/chat.tsx
1603
- import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
1459
+ // packages/cli/src/components/chat.tsx
1460
+ import { jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime";
1604
1461
  function MessageBody({ message }) {
1605
1462
  const { colors } = useTerminalStyle();
1606
1463
  if (message.role === "user") {
1607
- return /* @__PURE__ */ jsx14(Box10, { flexDirection: "column", marginY: 1, children: /* @__PURE__ */ jsx14(
1464
+ return /* @__PURE__ */ jsx16(Box11, { flexDirection: "column", marginY: 1, children: /* @__PURE__ */ jsx16(
1608
1465
  Prompt,
1609
1466
  {
1610
1467
  aside: message.createdAt.toLocaleTimeString("zh-CN", {
@@ -1616,11 +1473,11 @@ function MessageBody({ message }) {
1616
1473
  ) });
1617
1474
  }
1618
1475
  if (message.role !== "assistant") return null;
1619
- return /* @__PURE__ */ jsxs9(Box10, { flexDirection: "column", paddingX: 3, marginBottom: 1, children: [
1476
+ return /* @__PURE__ */ jsxs9(Box11, { flexDirection: "column", paddingX: 3, marginBottom: 1, children: [
1620
1477
  message.content.map((part, index) => {
1621
- if (part.type === "text") return /* @__PURE__ */ jsx14(Markdown, { text: part.text }, index);
1478
+ if (part.type === "text") return /* @__PURE__ */ jsx16(Markdown, { text: part.text }, index);
1622
1479
  if (part.type === "reasoning") {
1623
- return /* @__PURE__ */ jsx14(
1480
+ return /* @__PURE__ */ jsx16(
1624
1481
  ThinkingBlock,
1625
1482
  {
1626
1483
  content: part.text,
@@ -1632,7 +1489,7 @@ function MessageBody({ message }) {
1632
1489
  if (part.type === "tool-call") {
1633
1490
  const { verb, target } = getToolHeader(part);
1634
1491
  const failed = part.isError || part.result === void 0 && message.status.type === "incomplete";
1635
- return /* @__PURE__ */ jsx14(
1492
+ return /* @__PURE__ */ jsx16(
1636
1493
  Tool,
1637
1494
  {
1638
1495
  verb,
@@ -1645,22 +1502,22 @@ function MessageBody({ message }) {
1645
1502
  }
1646
1503
  return null;
1647
1504
  }),
1648
- message.status.type === "incomplete" && message.status.reason === "error" && /* @__PURE__ */ jsx14(Text10, { color: colors.err, children: "\u25C6 AI \u6682\u65F6\u65E0\u6CD5\u56DE\u590D\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002" })
1505
+ message.status.type === "incomplete" && message.status.reason === "error" && /* @__PURE__ */ jsx16(Text11, { color: colors.err, children: "\u25C6 AI \u6682\u65F6\u65E0\u6CD5\u56DE\u590D\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002" })
1649
1506
  ] });
1650
1507
  }
1651
1508
  function Message() {
1652
1509
  const message = useAuiState((state) => state.message);
1653
- return /* @__PURE__ */ jsx14(MessageBody, { message });
1510
+ return /* @__PURE__ */ jsx16(MessageBody, { message });
1654
1511
  }
1655
1512
  function ChatThread() {
1656
- return /* @__PURE__ */ jsx14(ThreadPrimitive.Messages, { components: { Message } });
1513
+ return /* @__PURE__ */ jsx16(ThreadPrimitive.Messages, { components: { Message } });
1657
1514
  }
1658
1515
 
1659
- // packages/cli/src/composer.tsx
1516
+ // packages/cli/src/components/composer.tsx
1660
1517
  import { useAui, useAuiState as useAuiState2 } from "@assistant-ui/react-ink";
1661
1518
  import {
1662
- Box as Box18,
1663
- Text as Text18,
1519
+ Box as Box19,
1520
+ Text as Text19,
1664
1521
  useBoxMetrics as useBoxMetrics7,
1665
1522
  useFocus as useFocus5,
1666
1523
  useFocusManager as useFocusManager2,
@@ -1668,11 +1525,11 @@ import {
1668
1525
  } from "ink";
1669
1526
  import { useEffect as useEffect6, useEffectEvent, useRef as useRef9 } from "react";
1670
1527
 
1671
- // src/agent/appearance.ts
1528
+ // src/shared/agent/appearance.ts
1672
1529
  var composerPlaceholder = "\u95EE\u70B9\u4EC0\u4E48\uFF0C\u6216\u8F93\u5165 / \u67E5\u770B\u547D\u4EE4";
1673
1530
  var composerBrand = { mark: "<MT/>", model: "V3.14 Pro" };
1674
1531
 
1675
- // src/utils/tags.ts
1532
+ // src/shared/tags.ts
1676
1533
  function getTagSlug(tag) {
1677
1534
  return encodeURIComponent(tag);
1678
1535
  }
@@ -1680,7 +1537,7 @@ function getTagPath(tag) {
1680
1537
  return `/tags/${getTagSlug(tag)}/`;
1681
1538
  }
1682
1539
 
1683
- // src/agent/commands.ts
1540
+ // src/shared/agent/commands.ts
1684
1541
  var commands = [
1685
1542
  { id: "help", description: "\u67E5\u770B\u53EF\u7528\u547D\u4EE4" },
1686
1543
  { id: "theme", args: "[\u4E3B\u9898]", description: "\u5207\u6362\u4E3B\u9898\uFF0C\u4E0D\u5E26\u53C2\u6570\u65F6\u6253\u5F00\u9009\u62E9\u5668" },
@@ -1719,11 +1576,11 @@ function getSearchPath(query) {
1719
1576
  return query ? `/search/?q=${encodeURIComponent(query)}` : "/search/";
1720
1577
  }
1721
1578
 
1722
- // packages/cli/src/command-menu.tsx
1723
- import { Box as Box11, Text as Text11, useInput as useInput3 } from "ink";
1579
+ // packages/cli/src/components/command-menu.tsx
1580
+ import { Box as Box12, Text as Text12, useInput as useInput3 } from "ink";
1724
1581
  import { useImperativeHandle, useState as useState5 } from "react";
1725
1582
 
1726
- // packages/cli/src/commands.ts
1583
+ // packages/cli/src/app/commands.ts
1727
1584
  var terminalCommands = [
1728
1585
  ...commands,
1729
1586
  { id: "read", args: "<slug \u6216\u8DEF\u5F84>", description: "\u9605\u8BFB\u6587\u7AE0\u5168\u6587" },
@@ -1765,8 +1622,8 @@ function resolveTagPath(input, index) {
1765
1622
  return tag.path;
1766
1623
  }
1767
1624
 
1768
- // packages/cli/src/command-menu.tsx
1769
- import { jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
1625
+ // packages/cli/src/components/command-menu.tsx
1626
+ import { jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
1770
1627
  function CommandMenu({
1771
1628
  text,
1772
1629
  focused,
@@ -1795,11 +1652,14 @@ function CommandMenu({
1795
1652
  return true;
1796
1653
  }
1797
1654
  }));
1655
+ function moveSelection(direction) {
1656
+ if (matches.length)
1657
+ setSelected((index) => (index + direction + matches.length) % matches.length);
1658
+ }
1798
1659
  useInput3(
1799
1660
  (_input, key) => {
1800
- if (!matches.length) return;
1801
1661
  const direction = Number(key.downArrow) - Number(key.upArrow);
1802
- if (direction) setSelected((index) => (index + direction + matches.length) % matches.length);
1662
+ if (direction) moveSelection(direction);
1803
1663
  },
1804
1664
  { isActive: open }
1805
1665
  );
@@ -1809,10 +1669,7 @@ function CommandMenu({
1809
1669
  {
1810
1670
  onClick: () => {
1811
1671
  },
1812
- onWheel: (direction) => {
1813
- if (matches.length)
1814
- setSelected((index) => (index + direction + matches.length) % matches.length);
1815
- },
1672
+ onWheel: moveSelection,
1816
1673
  flexDirection: "column",
1817
1674
  borderStyle: "round",
1818
1675
  borderColor: colors.line,
@@ -1820,7 +1677,7 @@ function CommandMenu({
1820
1677
  paddingX: 1,
1821
1678
  marginBottom: 1,
1822
1679
  children: [
1823
- matches.length === 0 && /* @__PURE__ */ jsx15(Text11, { color: colors.muted, children: "\u6CA1\u6709\u5339\u914D\u7684\u547D\u4EE4" }),
1680
+ matches.length === 0 && /* @__PURE__ */ jsx17(Text12, { color: colors.muted, children: "\u6CA1\u6709\u5339\u914D\u7684\u547D\u4EE4" }),
1824
1681
  matches.slice(start, start + visibleCount).map((command, index) => {
1825
1682
  const active = start + index === selected;
1826
1683
  return /* @__PURE__ */ jsxs10(
@@ -1830,28 +1687,28 @@ function CommandMenu({
1830
1687
  height: 1,
1831
1688
  backgroundColor: active ? colors.band : void 0,
1832
1689
  children: [
1833
- /* @__PURE__ */ jsx15(Box11, { width: 14, flexShrink: 0, children: /* @__PURE__ */ jsxs10(Text11, { color: colors.skill, children: [
1690
+ /* @__PURE__ */ jsx17(Box12, { width: 14, flexShrink: 0, children: /* @__PURE__ */ jsxs10(Text12, { color: colors.skill, children: [
1834
1691
  active ? "\u25B8" : " ",
1835
1692
  " /",
1836
1693
  command.id
1837
1694
  ] }) }),
1838
- /* @__PURE__ */ jsx15(Box11, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsx15(Text11, { color: colors.muted, wrap: "truncate-end", children: command.description }) })
1695
+ /* @__PURE__ */ jsx17(Box12, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsx17(Text12, { color: colors.muted, wrap: "truncate-end", children: command.description }) })
1839
1696
  ]
1840
1697
  },
1841
1698
  command.id
1842
1699
  );
1843
1700
  }),
1844
- /* @__PURE__ */ jsx15(Text11, { color: colors.muted, wrap: "truncate-end", children: "\u2191\u2193 \u9009\u62E9 \xB7 Enter \u786E\u8BA4 \xB7 Tab \u5207\u6362\u7126\u70B9 \xB7 Esc \u5173\u95ED" })
1701
+ /* @__PURE__ */ jsx17(Text12, { color: colors.muted, wrap: "truncate-end", children: "\u2191\u2193 \u9009\u62E9 \xB7 Enter \u786E\u8BA4 \xB7 Tab \u5207\u6362\u7126\u70B9 \xB7 Esc \u5173\u95ED" })
1845
1702
  ]
1846
1703
  }
1847
1704
  );
1848
1705
  }
1849
1706
 
1850
- // packages/cli/src/composer-input.tsx
1851
- import { Box as Box12, Text as Text12, useBoxMetrics as useBoxMetrics4, useInput as useInput4, useWindowSize } from "ink";
1707
+ // packages/cli/src/components/composer-input.tsx
1708
+ import { Box as Box13, Text as Text13, useBoxMetrics as useBoxMetrics4, useInput as useInput4, useWindowSize } from "ink";
1852
1709
  import { useRef as useRef6, useState as useState6 } from "react";
1853
1710
 
1854
- // packages/cli/src/input-editor.ts
1711
+ // packages/cli/src/terminal/input-editor.ts
1855
1712
  import stringWidth2 from "string-width";
1856
1713
  var segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
1857
1714
  function editorLines(text, width) {
@@ -1940,8 +1797,8 @@ function updateEditor(state, input, key, width) {
1940
1797
  if (inserted) return editText(state, cursor, cursor, inserted);
1941
1798
  }
1942
1799
 
1943
- // packages/cli/src/composer-input.tsx
1944
- import { Fragment as Fragment2, jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
1800
+ // packages/cli/src/components/composer-input.tsx
1801
+ import { Fragment as Fragment2, jsx as jsx18, jsxs as jsxs11 } from "react/jsx-runtime";
1945
1802
  function ComposerInput({
1946
1803
  value,
1947
1804
  focused,
@@ -1980,29 +1837,29 @@ function ComposerInput({
1980
1837
  },
1981
1838
  { isActive: focused }
1982
1839
  );
1983
- return /* @__PURE__ */ jsx16(Box12, { ref: container, flexGrow: 1, minWidth: 0, height, flexDirection: "column", children: lines.slice(visibleStart, visibleStart + height).map((line, index) => {
1840
+ return /* @__PURE__ */ jsx18(Box13, { ref: container, flexGrow: 1, minWidth: 0, height, flexDirection: "column", children: lines.slice(visibleStart, visibleStart + height).map((line, index) => {
1984
1841
  const current = visibleStart + index === row;
1985
1842
  const cursor = current ? state.cursor - line.start : -1;
1986
1843
  const after = current ? moveCursor(state, 1).cursor - line.start : -1;
1987
- return /* @__PURE__ */ jsx16(Text12, { color: colors.fg, wrap: "truncate-end", children: !value ? /* @__PURE__ */ jsxs11(Text12, { color: colors.muted, children: [
1988
- /* @__PURE__ */ jsx16(Text12, { inverse: focused, children: placeholder[0] }),
1844
+ return /* @__PURE__ */ jsx18(Text13, { color: colors.fg, wrap: "truncate-end", children: !value ? /* @__PURE__ */ jsxs11(Text13, { color: colors.muted, children: [
1845
+ /* @__PURE__ */ jsx18(Text13, { inverse: focused, children: placeholder[0] }),
1989
1846
  placeholder.slice(1)
1990
1847
  ] }) : current && focused ? /* @__PURE__ */ jsxs11(Fragment2, { children: [
1991
1848
  line.text.slice(0, cursor),
1992
- /* @__PURE__ */ jsx16(Text12, { inverse: true, children: line.text.slice(cursor, after) || " " }),
1849
+ /* @__PURE__ */ jsx18(Text13, { inverse: true, children: line.text.slice(cursor, after) || " " }),
1993
1850
  line.text.slice(after)
1994
1851
  ] }) : line.text || " " }, line.start);
1995
1852
  }) });
1996
1853
  }
1997
1854
 
1998
- // packages/cli/src/panels.tsx
1999
- import { Box as Box15, Text as Text15, useBoxMetrics as useBoxMetrics6, useInput as useInput7 } from "ink";
1855
+ // packages/cli/src/components/panels.tsx
1856
+ import { Box as Box16, Text as Text16, useBoxMetrics as useBoxMetrics6, useInput as useInput7 } from "ink";
2000
1857
  import { useContext as useContext6, useImperativeHandle as useImperativeHandle3, useRef as useRef8, useState as useState9 } from "react";
2001
1858
 
2002
- // packages/cli/src/scroll-area.tsx
2003
- import { Box as Box13, Text as Text13, measureElement as measureElement2, useBoxMetrics as useBoxMetrics5, useFocus as useFocus3, useInput as useInput5 } from "ink";
1859
+ // packages/cli/src/terminal/scroll-area.tsx
1860
+ import { Box as Box14, Text as Text14, measureElement as measureElement2, useBoxMetrics as useBoxMetrics5, useFocus as useFocus3, useInput as useInput5 } from "ink";
2004
1861
  import { useImperativeHandle as useImperativeHandle2, useRef as useRef7, useState as useState7 } from "react";
2005
- import { jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
1862
+ import { jsx as jsx19, jsxs as jsxs12 } from "react/jsx-runtime";
2006
1863
  function revealOffset(element, content, viewport, offset, height, maximum) {
2007
1864
  let parent = element;
2008
1865
  while (parent && parent !== content) parent = parent.parentNode;
@@ -2079,8 +1936,8 @@ function ScrollArea({
2079
1936
  minHeight: 1,
2080
1937
  marginX: 2,
2081
1938
  children: [
2082
- /* @__PURE__ */ jsx17(
2083
- Box13,
1939
+ /* @__PURE__ */ jsx19(
1940
+ Box14,
2084
1941
  {
2085
1942
  ref: viewport,
2086
1943
  flexDirection: "column",
@@ -2088,13 +1945,13 @@ function ScrollArea({
2088
1945
  flexShrink: 1,
2089
1946
  overflow: "hidden",
2090
1947
  contentOffsetY: offset,
2091
- children: /* @__PURE__ */ jsx17(Box13, { ref: content, flexDirection: "column", flexShrink: 0, width: "100%", children })
1948
+ children: /* @__PURE__ */ jsx19(Box14, { ref: content, flexDirection: "column", flexShrink: 0, width: "100%", children })
2092
1949
  }
2093
1950
  ),
2094
- /* @__PURE__ */ jsx17(Box13, { width: 1, flexShrink: 0, "aria-hidden": true, children: /* @__PURE__ */ jsxs12(Text13, { color: colors.line, children: [
1951
+ /* @__PURE__ */ jsx19(Box14, { width: 1, flexShrink: 0, "aria-hidden": true, children: /* @__PURE__ */ jsxs12(Text14, { color: colors.line, children: [
2095
1952
  before,
2096
1953
  before && "\n",
2097
- /* @__PURE__ */ jsx17(Text13, { color: isFocused ? colors.accent : colors.muted, children: thumb }),
1954
+ /* @__PURE__ */ jsx19(Text14, { color: isFocused ? colors.accent : colors.muted, children: thumb }),
2098
1955
  after && "\n",
2099
1956
  after
2100
1957
  ] }) })
@@ -2103,10 +1960,10 @@ function ScrollArea({
2103
1960
  );
2104
1961
  }
2105
1962
 
2106
- // packages/cli/src/theme-picker.tsx
2107
- import { Box as Box14, Text as Text14, useFocus as useFocus4, useInput as useInput6 } from "ink";
1963
+ // packages/cli/src/components/theme-picker.tsx
1964
+ import { Box as Box15, Text as Text15, useFocus as useFocus4, useInput as useInput6 } from "ink";
2108
1965
  import { useEffect as useEffect4, useState as useState8 } from "react";
2109
- import { jsx as jsx18, jsxs as jsxs13 } from "react/jsx-runtime";
1966
+ import { jsx as jsx20, jsxs as jsxs13 } from "react/jsx-runtime";
2110
1967
  function ThemePicker({
2111
1968
  initial,
2112
1969
  visibleCount,
@@ -2125,13 +1982,16 @@ function ThemePicker({
2125
1982
  focus("theme-picker");
2126
1983
  return () => onPreview(void 0);
2127
1984
  }, [focus, onPreview]);
1985
+ function moveSelection(direction) {
1986
+ const next = (selected + direction + themeOptions.length) % themeOptions.length;
1987
+ setSelected(next);
1988
+ onPreview(themeOptions[next].id);
1989
+ }
2128
1990
  useInput6(
2129
1991
  (input, key) => {
2130
1992
  const direction = Number(key.downArrow || input === "j") - Number(key.upArrow || input === "k");
2131
1993
  if (direction) {
2132
- const next = (selected + direction + themeOptions.length) % themeOptions.length;
2133
- setSelected(next);
2134
- onPreview(themeOptions[next].id);
1994
+ moveSelection(direction);
2135
1995
  } else if (key.return) {
2136
1996
  onApply(themeOptions[selected].id);
2137
1997
  }
@@ -2139,15 +1999,11 @@ function ThemePicker({
2139
1999
  { isActive: isFocused }
2140
2000
  );
2141
2001
  const start = Math.max(0, selected - visibleCount + 1);
2142
- return /* @__PURE__ */ jsx18(
2002
+ return /* @__PURE__ */ jsx20(
2143
2003
  MouseArea,
2144
2004
  {
2145
2005
  flexDirection: "column",
2146
- onWheel: (direction) => {
2147
- const next = (selected + direction + themeOptions.length) % themeOptions.length;
2148
- setSelected(next);
2149
- onPreview(themeOptions[next].id);
2150
- },
2006
+ onWheel: moveSelection,
2151
2007
  children: themeOptions.slice(start, start + visibleCount).map((option, index) => /* @__PURE__ */ jsxs13(
2152
2008
  MouseArea,
2153
2009
  {
@@ -2158,12 +2014,12 @@ function ThemePicker({
2158
2014
  },
2159
2015
  backgroundColor: start + index === selected ? colors.band : void 0,
2160
2016
  children: [
2161
- /* @__PURE__ */ jsx18(Box14, { width: 20, flexShrink: 0, children: /* @__PURE__ */ jsxs13(Text14, { color: colors.fg, bold: true, children: [
2017
+ /* @__PURE__ */ jsx20(Box15, { width: 20, flexShrink: 0, children: /* @__PURE__ */ jsxs13(Text15, { color: colors.fg, bold: true, children: [
2162
2018
  start + index === selected ? "\u25B8" : " ",
2163
2019
  " ",
2164
2020
  option.name
2165
2021
  ] }) }),
2166
- /* @__PURE__ */ jsx18(Box14, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsxs13(Text14, { color: colors.muted, wrap: "truncate-end", children: [
2022
+ /* @__PURE__ */ jsx20(Box15, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsxs13(Text15, { color: colors.muted, wrap: "truncate-end", children: [
2167
2023
  option.description,
2168
2024
  option.id === initial ? "\uFF08\u5F53\u524D\uFF09" : ""
2169
2025
  ] }) })
@@ -2175,8 +2031,8 @@ function ThemePicker({
2175
2031
  );
2176
2032
  }
2177
2033
 
2178
- // packages/cli/src/panels.tsx
2179
- import { jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
2034
+ // packages/cli/src/components/panels.tsx
2035
+ import { jsx as jsx21, jsxs as jsxs14 } from "react/jsx-runtime";
2180
2036
  function PanelBox({
2181
2037
  title,
2182
2038
  availableHeight,
@@ -2209,7 +2065,7 @@ function PanelBox({
2209
2065
  (current) => Math.max(0, Math.min(maximum, current + direction * Math.max(1, height - 1)))
2210
2066
  );
2211
2067
  });
2212
- return /* @__PURE__ */ jsx19(LinkNavigation, { value: navigation ? { ...navigation, scroll } : null, children: /* @__PURE__ */ jsxs14(
2068
+ return /* @__PURE__ */ jsx21(LinkNavigation, { value: navigation ? { ...navigation, scroll } : null, children: /* @__PURE__ */ jsxs14(
2213
2069
  MouseArea,
2214
2070
  {
2215
2071
  onClick: () => {
@@ -2222,17 +2078,17 @@ function PanelBox({
2222
2078
  paddingX: 2,
2223
2079
  marginBottom: 1,
2224
2080
  children: [
2225
- /* @__PURE__ */ jsx19(Text15, { color: colors.fg, bold: true, children: title }),
2226
- /* @__PURE__ */ jsx19(
2227
- Box15,
2081
+ /* @__PURE__ */ jsx21(Text16, { color: colors.fg, bold: true, children: title }),
2082
+ /* @__PURE__ */ jsx21(
2083
+ Box16,
2228
2084
  {
2229
2085
  ref: viewport,
2230
2086
  flexDirection: "column",
2231
2087
  maxHeight: Math.max(1, availableHeight - 5),
2232
2088
  overflow: "hidden",
2233
2089
  contentOffsetY: Math.min(offset, maximum),
2234
- children: /* @__PURE__ */ jsx19(
2235
- Box15,
2090
+ children: /* @__PURE__ */ jsx21(
2091
+ Box16,
2236
2092
  {
2237
2093
  ref: content,
2238
2094
  flexDirection: "column",
@@ -2243,7 +2099,7 @@ function PanelBox({
2243
2099
  )
2244
2100
  }
2245
2101
  ),
2246
- /* @__PURE__ */ jsxs14(Text15, { color: colors.muted, wrap: "truncate-end", children: [
2102
+ /* @__PURE__ */ jsxs14(Text16, { color: colors.muted, wrap: "truncate-end", children: [
2247
2103
  hints,
2248
2104
  maximum > 0 ? " \u2502 PgUp/PgDn:\u6EDA\u52A8" : ""
2249
2105
  ] })
@@ -2262,13 +2118,13 @@ function TerminalPanels({
2262
2118
  const { colors } = useTerminalStyle();
2263
2119
  if (!panel) return null;
2264
2120
  if (panel.type === "theme") {
2265
- return /* @__PURE__ */ jsx19(
2121
+ return /* @__PURE__ */ jsx21(
2266
2122
  PanelBox,
2267
2123
  {
2268
2124
  title: "\u9009\u62E9\u4E3B\u9898",
2269
2125
  availableHeight,
2270
2126
  hints: "\u2191\u2193:\u9884\u89C8 \u2502 Enter:\u5E94\u7528 \u2502 Esc:\u53D6\u6D88",
2271
- children: /* @__PURE__ */ jsx19(
2127
+ children: /* @__PURE__ */ jsx21(
2272
2128
  ThemePicker,
2273
2129
  {
2274
2130
  initial: savedTheme,
@@ -2282,19 +2138,19 @@ function TerminalPanels({
2282
2138
  }
2283
2139
  if (panel.type === "help") {
2284
2140
  return /* @__PURE__ */ jsxs14(PanelBox, { title: "\u547D\u4EE4", availableHeight, children: [
2285
- terminalCommands.map((command) => /* @__PURE__ */ jsxs14(Box15, { children: [
2286
- /* @__PURE__ */ jsx19(Box15, { width: 20, flexShrink: 0, children: /* @__PURE__ */ jsxs14(Text15, { color: colors.skill, children: [
2141
+ terminalCommands.map((command) => /* @__PURE__ */ jsxs14(Box16, { children: [
2142
+ /* @__PURE__ */ jsx21(Box16, { width: 20, flexShrink: 0, children: /* @__PURE__ */ jsxs14(Text16, { color: colors.skill, children: [
2287
2143
  "/",
2288
2144
  command.id,
2289
- /* @__PURE__ */ jsx19(Text15, { color: colors.muted, children: command.args ? ` ${command.args}` : "" })
2145
+ /* @__PURE__ */ jsx21(Text16, { color: colors.muted, children: command.args ? ` ${command.args}` : "" })
2290
2146
  ] }) }),
2291
- /* @__PURE__ */ jsx19(Box15, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsx19(Text15, { color: colors.muted, wrap: "truncate-end", children: command.description }) })
2147
+ /* @__PURE__ */ jsx21(Box16, { flexGrow: 1, flexShrink: 1, children: /* @__PURE__ */ jsx21(Text16, { color: colors.muted, wrap: "truncate-end", children: command.description }) })
2292
2148
  ] }, command.id)),
2293
- /* @__PURE__ */ jsx19(Text15, { color: colors["fg-soft"], children: "\u76F4\u63A5\u8F93\u5165\u95EE\u9898\uFF0CAI \u4F1A\u68C0\u7D22\u5168\u7AD9\u6587\u7AE0\u540E\u56DE\u7B54\uFF0C\u4E5F\u80FD\u5E2E\u4F60\u5207\u6362\u4E3B\u9898\u3001\u6253\u5F00\u9875\u9762\u3002" })
2149
+ /* @__PURE__ */ jsx21(Text16, { color: colors["fg-soft"], children: "\u76F4\u63A5\u8F93\u5165\u95EE\u9898\uFF0CAI \u4F1A\u68C0\u7D22\u5168\u7AD9\u6587\u7AE0\u540E\u56DE\u7B54\uFF0C\u4E5F\u80FD\u5E2E\u4F60\u5207\u6362\u4E3B\u9898\u3001\u6253\u5F00\u9875\u9762\u3002" })
2294
2150
  ] });
2295
2151
  }
2296
2152
  if (panel.type === "rss") {
2297
- return /* @__PURE__ */ jsx19(PanelBox, { title: "\u8BA2\u9605", availableHeight, children: /* @__PURE__ */ jsx19(
2153
+ return /* @__PURE__ */ jsx21(PanelBox, { title: "\u8BA2\u9605", availableHeight, children: /* @__PURE__ */ jsx21(
2298
2154
  Markdown,
2299
2155
  {
2300
2156
  text: `RSS [${site.feedUrl}](${site.feedUrl})
@@ -2304,7 +2160,7 @@ function TerminalPanels({
2304
2160
  ) });
2305
2161
  }
2306
2162
  return /* @__PURE__ */ jsxs14(
2307
- Text15,
2163
+ Text16,
2308
2164
  {
2309
2165
  color: panel.tone === "error" ? colors.err : colors["fg-soft"],
2310
2166
  backgroundColor: colors.bg,
@@ -2318,7 +2174,7 @@ function TerminalPanels({
2318
2174
 
2319
2175
  // packages/cli/src/components/ui/spinner.tsx
2320
2176
  import cliSpinners from "cli-spinners";
2321
- import { Box as Box16, Text as Text16 } from "ink";
2177
+ import { Box as Box17, Text as Text17 } from "ink";
2322
2178
 
2323
2179
  // packages/cli/src/hooks/use-animation.ts
2324
2180
  import { useEffect as useEffect5, useState as useState10 } from "react";
@@ -2336,7 +2192,7 @@ function useAnimation({
2336
2192
  }
2337
2193
 
2338
2194
  // packages/cli/src/components/ui/spinner.tsx
2339
- import { jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
2195
+ import { jsx as jsx22, jsxs as jsxs15 } from "react/jsx-runtime";
2340
2196
  function Spinner({
2341
2197
  type = "dots",
2342
2198
  label,
@@ -2346,40 +2202,40 @@ function Spinner({
2346
2202
  const { colors } = useTerminalStyle();
2347
2203
  const spinner = cliSpinners[type];
2348
2204
  const frame = useAnimation({ intervalMs: spinner.interval, isActive });
2349
- return /* @__PURE__ */ jsxs15(Box16, { "aria-role": "progressbar", "aria-label": label ?? "\u52A0\u8F7D\u4E2D", "aria-state": { busy: isActive }, children: [
2350
- /* @__PURE__ */ jsx20(Text16, { "aria-hidden": true, color: color ?? colors.muted, children: spinner.frames[frame % spinner.frames.length] }),
2351
- label && /* @__PURE__ */ jsxs15(Text16, { color: colors.muted, children: [
2205
+ return /* @__PURE__ */ jsxs15(Box17, { "aria-role": "progressbar", "aria-label": label ?? "\u52A0\u8F7D\u4E2D", "aria-state": { busy: isActive }, children: [
2206
+ /* @__PURE__ */ jsx22(Text17, { "aria-hidden": true, color: color ?? colors.muted, children: spinner.frames[frame % spinner.frames.length] }),
2207
+ label && /* @__PURE__ */ jsxs15(Text17, { color: colors.muted, children: [
2352
2208
  " ",
2353
2209
  label
2354
2210
  ] })
2355
2211
  ] });
2356
2212
  }
2357
2213
 
2358
- // packages/cli/src/run-status.tsx
2359
- import { Box as Box17, Text as Text17 } from "ink";
2360
- import { jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
2214
+ // packages/cli/src/components/run-status.tsx
2215
+ import { Box as Box18, Text as Text18 } from "ink";
2216
+ import { jsx as jsx23, jsxs as jsxs16 } from "react/jsx-runtime";
2361
2217
  function RunStatus({ running, loading }) {
2362
2218
  const { colors } = useTerminalStyle();
2363
2219
  const seconds = useElapsedTime(running, true);
2364
2220
  if (!running && !loading) return null;
2365
- return /* @__PURE__ */ jsxs16(Box17, { paddingLeft: 3, height: 1, children: [
2366
- /* @__PURE__ */ jsx21(Spinner, {}),
2367
- /* @__PURE__ */ jsxs16(Text17, { color: colors.fg, children: [
2221
+ return /* @__PURE__ */ jsxs16(Box18, { paddingLeft: 3, height: 1, children: [
2222
+ /* @__PURE__ */ jsx23(Spinner, {}),
2223
+ /* @__PURE__ */ jsxs16(Text18, { color: colors.fg, children: [
2368
2224
  " ",
2369
2225
  loading ? "\u601D\u8003\u4E2D\u2026" : "\u56DE\u590D\u4E2D\u2026"
2370
2226
  ] }),
2371
- running && /* @__PURE__ */ jsxs16(Text17, { color: colors.muted, children: [
2227
+ running && /* @__PURE__ */ jsxs16(Text18, { color: colors.muted, children: [
2372
2228
  " ",
2373
2229
  Math.floor(seconds),
2374
2230
  "s"
2375
2231
  ] }),
2376
- /* @__PURE__ */ jsx21(Box17, { flexGrow: 1 }),
2377
- /* @__PURE__ */ jsx21(Text17, { color: colors.muted, children: "[Esc \u505C\u6B62]" })
2232
+ /* @__PURE__ */ jsx23(Box18, { flexGrow: 1 }),
2233
+ /* @__PURE__ */ jsx23(Text18, { color: colors.muted, children: "[Esc \u505C\u6B62]" })
2378
2234
  ] });
2379
2235
  }
2380
2236
 
2381
- // packages/cli/src/composer.tsx
2382
- import { jsx as jsx22, jsxs as jsxs17 } from "react/jsx-runtime";
2237
+ // packages/cli/src/components/composer.tsx
2238
+ import { jsx as jsx24, jsxs as jsxs17 } from "react/jsx-runtime";
2383
2239
  function Composer({
2384
2240
  runtime,
2385
2241
  loading,
@@ -2421,8 +2277,8 @@ function Composer({
2421
2277
  if (!text) aui.composer.setText("/");
2422
2278
  }
2423
2279
  });
2424
- return /* @__PURE__ */ jsxs17(Box18, { ref: dock, flexDirection: "column", marginX: 2, paddingTop: 1, flexShrink: 0, children: [
2425
- /* @__PURE__ */ jsx22(RunStatus, { loading, running }),
2280
+ return /* @__PURE__ */ jsxs17(Box19, { ref: dock, flexDirection: "column", marginX: 2, paddingTop: 1, flexShrink: 0, children: [
2281
+ /* @__PURE__ */ jsx24(RunStatus, { loading, running }),
2426
2282
  /* @__PURE__ */ jsxs17(
2427
2283
  MouseArea,
2428
2284
  {
@@ -2432,8 +2288,8 @@ function Composer({
2432
2288
  paddingX: 2,
2433
2289
  alignItems: "flex-start",
2434
2290
  children: [
2435
- /* @__PURE__ */ jsx22(Text18, { color: colors.prompt, children: "\u276F " }),
2436
- /* @__PURE__ */ jsx22(
2291
+ /* @__PURE__ */ jsx24(Text19, { color: colors.prompt, children: "\u276F " }),
2292
+ /* @__PURE__ */ jsx24(
2437
2293
  ComposerInput,
2438
2294
  {
2439
2295
  value: text,
@@ -2447,10 +2303,10 @@ function Composer({
2447
2303
  const input = text2.trim();
2448
2304
  if (!input) return;
2449
2305
  if (menu.current?.submit(text2)) return;
2450
- if (input.startsWith("/")) {
2451
- const command = parseCommand(input);
2306
+ const command = parseCommand(input);
2307
+ if (command) {
2452
2308
  aui.composer.setText("");
2453
- void onCommand(command?.name ?? "help", command?.args ?? "");
2309
+ void onCommand(command.name, command.args);
2454
2310
  } else if (!running) {
2455
2311
  onSubmit();
2456
2312
  runtime.thread.composer.send();
@@ -2458,7 +2314,7 @@ function Composer({
2458
2314
  }
2459
2315
  }
2460
2316
  ),
2461
- /* @__PURE__ */ jsx22(Box18, { position: "absolute", bottom: -1, right: 1, children: /* @__PURE__ */ jsxs17(Text18, { color: colors.muted, backgroundColor: colors.bg, children: [
2317
+ /* @__PURE__ */ jsx24(Box19, { position: "absolute", bottom: -1, right: 1, children: /* @__PURE__ */ jsxs17(Text19, { color: colors.muted, backgroundColor: colors.bg, children: [
2462
2318
  " ",
2463
2319
  composerBrand.mark,
2464
2320
  " \xB7 ",
@@ -2468,12 +2324,12 @@ function Composer({
2468
2324
  ]
2469
2325
  }
2470
2326
  ),
2471
- /* @__PURE__ */ jsxs17(Box18, { justifyContent: "space-between", flexWrap: "wrap", columnGap: 2, children: [
2472
- /* @__PURE__ */ jsx22(Text18, { color: colors.muted, children: "Tab/Shift+Tab:\u5207\u6362 \u2502 Enter:\u6253\u5F00/\u53D1\u9001 \u2502 /:\u547D\u4EE4 \u2502 Esc:\u5173\u95ED/\u505C\u6B62" }),
2473
- /* @__PURE__ */ jsxs17(Box18, { columnGap: 2, children: [
2474
- /* @__PURE__ */ jsx22(TerminalLink, { href: panels.site.feedUrl, color: colors.muted, underline: false, children: "RSS" }),
2475
- panels.site.sponsorUrl && /* @__PURE__ */ jsx22(TerminalLink, { href: panels.site.sponsorUrl, color: colors.muted, underline: false, children: "\u8D5E\u8D4F" }),
2476
- /* @__PURE__ */ jsxs17(Text18, { color: colors.muted, children: [
2327
+ /* @__PURE__ */ jsxs17(Box19, { justifyContent: "space-between", flexWrap: "wrap", columnGap: 2, children: [
2328
+ /* @__PURE__ */ jsx24(Text19, { color: colors.muted, children: "Tab/Shift+Tab:\u5207\u6362 \u2502 Enter:\u6253\u5F00/\u53D1\u9001 \u2502 /:\u547D\u4EE4 \u2502 Esc:\u5173\u95ED/\u505C\u6B62" }),
2329
+ /* @__PURE__ */ jsxs17(Box19, { columnGap: 2, children: [
2330
+ /* @__PURE__ */ jsx24(TerminalLink, { href: panels.site.feedUrl, color: colors.muted, underline: false, children: "RSS" }),
2331
+ panels.site.sponsorUrl && /* @__PURE__ */ jsx24(TerminalLink, { href: panels.site.sponsorUrl, color: colors.muted, underline: false, children: "\u8D5E\u8D4F" }),
2332
+ /* @__PURE__ */ jsxs17(Text19, { color: colors.muted, children: [
2477
2333
  "\xA9 ",
2478
2334
  (/* @__PURE__ */ new Date()).getFullYear(),
2479
2335
  " ",
@@ -2481,37 +2337,39 @@ function Composer({
2481
2337
  ] })
2482
2338
  ] })
2483
2339
  ] }),
2484
- /* @__PURE__ */ jsx22(Box18, { position: "absolute", bottom: height, width: "100%", flexDirection: "column", children: /* @__PURE__ */ jsx22(LinkScope, { value: true, children: /* @__PURE__ */ jsx22(TerminalPanels, { panel, availableHeight, ...panels }) }) }),
2485
- /* @__PURE__ */ jsx22(Box18, { position: "absolute", bottom: height, width: "100%", flexDirection: "column", children: /* @__PURE__ */ jsx22(
2486
- CommandMenu,
2487
- {
2488
- ref: menu,
2489
- text,
2490
- focused,
2491
- availableHeight,
2492
- onSelect: (command) => {
2493
- if (command.id === "read") aui.composer.setText("/read ");
2494
- else {
2495
- aui.composer.setText("");
2496
- void onCommand(command.id, "");
2340
+ /* @__PURE__ */ jsxs17(Box19, { position: "absolute", bottom: height, width: "100%", flexDirection: "column", children: [
2341
+ /* @__PURE__ */ jsx24(LinkScope, { value: true, children: /* @__PURE__ */ jsx24(TerminalPanels, { panel, availableHeight, ...panels }) }),
2342
+ /* @__PURE__ */ jsx24(
2343
+ CommandMenu,
2344
+ {
2345
+ ref: menu,
2346
+ text,
2347
+ focused,
2348
+ availableHeight,
2349
+ onSelect: (command) => {
2350
+ if (command.id === "read") aui.composer.setText("/read ");
2351
+ else {
2352
+ aui.composer.setText("");
2353
+ void onCommand(command.id, "");
2354
+ }
2497
2355
  }
2498
- }
2499
- },
2500
- text
2501
- ) })
2356
+ },
2357
+ text
2358
+ )
2359
+ ] })
2502
2360
  ] });
2503
2361
  }
2504
2362
 
2505
- // packages/cli/src/page-content.tsx
2506
- import { Box as Box20, Text as Text23 } from "ink";
2363
+ // packages/cli/src/components/page-content.tsx
2364
+ import { Box as Box21, Text as Text24 } from "ink";
2507
2365
  import { memo } from "react";
2508
2366
 
2509
- // packages/cli/src/article-page.tsx
2510
- import { Box as Box19, Text as Text20 } from "ink";
2367
+ // packages/cli/src/components/article-page.tsx
2368
+ import { Box as Box20, Text as Text21 } from "ink";
2511
2369
 
2512
2370
  // packages/cli/src/components/ui/heading.tsx
2513
- import { Text as Text19 } from "ink";
2514
- import { jsx as jsx23 } from "react/jsx-runtime";
2371
+ import { Text as Text20 } from "ink";
2372
+ import { jsx as jsx25 } from "react/jsx-runtime";
2515
2373
  function Heading({
2516
2374
  level = 1,
2517
2375
  children,
@@ -2519,11 +2377,11 @@ function Heading({
2519
2377
  }) {
2520
2378
  const { colors } = useTerminalStyle();
2521
2379
  const token = level <= 2 ? "h1" : level === 3 ? "h2" : level === 4 ? "h3" : "muted";
2522
- return /* @__PURE__ */ jsx23(Text19, { color: color ?? colors[token], bold: true, children });
2380
+ return /* @__PURE__ */ jsx25(Text20, { color: color ?? colors[token], bold: true, children });
2523
2381
  }
2524
2382
 
2525
- // packages/cli/src/article-page.tsx
2526
- import { jsx as jsx24, jsxs as jsxs18 } from "react/jsx-runtime";
2383
+ // packages/cli/src/components/article-page.tsx
2384
+ import { jsx as jsx26, jsxs as jsxs18 } from "react/jsx-runtime";
2527
2385
  function ArticlePage({
2528
2386
  post,
2529
2387
  title,
@@ -2532,26 +2390,26 @@ function ArticlePage({
2532
2390
  markdown
2533
2391
  }) {
2534
2392
  const { colors } = useTerminalStyle();
2535
- return /* @__PURE__ */ jsxs18(Box19, { flexDirection: "column", paddingX: 3, paddingTop: 1, marginBottom: 1, gap: 1, children: [
2536
- tool2 && /* @__PURE__ */ jsx24(Tool, { ...tool2, aside: formatShortDate(post.date) }),
2537
- /* @__PURE__ */ jsx24(Heading, { children: cleanText(title) }),
2538
- description && /* @__PURE__ */ jsx24(Text20, { color: colors.muted, children: cleanText(description) }),
2539
- /* @__PURE__ */ jsx24(Text20, { color: colors.muted, children: "\u2500\u2500\u2500" }),
2540
- /* @__PURE__ */ jsx24(Box19, { flexDirection: "column", maxWidth: 90, children: markdown && /* @__PURE__ */ jsx24(Markdown, { text: markdown }) }),
2393
+ return /* @__PURE__ */ jsxs18(Box20, { flexDirection: "column", paddingX: 3, paddingTop: 1, marginBottom: 1, gap: 1, children: [
2394
+ tool2 && /* @__PURE__ */ jsx26(Tool, { ...tool2, aside: formatShortDate(post.date) }),
2395
+ /* @__PURE__ */ jsx26(Heading, { children: cleanText(title) }),
2396
+ description && /* @__PURE__ */ jsx26(Text21, { color: colors.muted, children: cleanText(description) }),
2397
+ /* @__PURE__ */ jsx26(Text21, { color: colors.muted, children: "\u2500\u2500\u2500" }),
2398
+ /* @__PURE__ */ jsx26(Box20, { flexDirection: "column", maxWidth: 90, children: markdown && /* @__PURE__ */ jsx26(Markdown, { text: markdown }) }),
2541
2399
  /* @__PURE__ */ jsxs18(LinkRow, { columnGap: 2, flexWrap: "wrap", marginTop: 1, children: [
2542
2400
  post.tags.map((tag) => /* @__PURE__ */ jsxs18(TerminalLink, { href: getTagPath(tag), color: colors.muted, underline: false, children: [
2543
2401
  "#",
2544
2402
  cleanText(tag)
2545
2403
  ] }, tag)),
2546
- /* @__PURE__ */ jsx24(Box19, { flexGrow: 1, justifyContent: "flex-end", children: /* @__PURE__ */ jsx24(TerminalLink, { href: "/blog/", underline: false, children: "\u2039 \u5168\u90E8\u6587\u7AE0" }) })
2404
+ /* @__PURE__ */ jsx26(Box20, { flexGrow: 1, justifyContent: "flex-end", children: /* @__PURE__ */ jsx26(TerminalLink, { href: "/blog/", underline: false, children: "\u2039 \u5168\u90E8\u6587\u7AE0" }) })
2547
2405
  ] })
2548
2406
  ] });
2549
2407
  }
2550
2408
 
2551
- // packages/cli/src/search-input.tsx
2552
- import { Text as Text21, useFocus as useFocus6, useInput as useInput9 } from "ink";
2409
+ // packages/cli/src/components/search-input.tsx
2410
+ import { Text as Text22, useFocus as useFocus6, useInput as useInput9 } from "ink";
2553
2411
  import { useContext as useContext7, useEffect as useEffect7, useRef as useRef10, useState as useState11 } from "react";
2554
- import { jsx as jsx25, jsxs as jsxs19 } from "react/jsx-runtime";
2412
+ import { jsx as jsx27, jsxs as jsxs19 } from "react/jsx-runtime";
2555
2413
  function SearchInput({
2556
2414
  path,
2557
2415
  onSearch
@@ -2580,8 +2438,8 @@ function SearchInput({
2580
2438
  paddingX: 1,
2581
2439
  marginY: 1,
2582
2440
  children: [
2583
- /* @__PURE__ */ jsx25(Text21, { color: colors.prompt, children: "\u276F " }),
2584
- /* @__PURE__ */ jsx25(
2441
+ /* @__PURE__ */ jsx27(Text22, { color: colors.prompt, children: "\u276F " }),
2442
+ /* @__PURE__ */ jsx27(
2585
2443
  ComposerInput,
2586
2444
  {
2587
2445
  value: query,
@@ -2605,8 +2463,8 @@ function SearchInput({
2605
2463
  }
2606
2464
 
2607
2465
  // packages/cli/src/components/ui/pagination.tsx
2608
- import { Text as Text22 } from "ink";
2609
- import { jsx as jsx26, jsxs as jsxs20 } from "react/jsx-runtime";
2466
+ import { Text as Text23 } from "ink";
2467
+ import { jsx as jsx28, jsxs as jsxs20 } from "react/jsx-runtime";
2610
2468
  function Pagination({
2611
2469
  current,
2612
2470
  total,
@@ -2616,33 +2474,33 @@ function Pagination({
2616
2474
  const { colors } = useTerminalStyle();
2617
2475
  if (total <= 1) return null;
2618
2476
  return /* @__PURE__ */ jsxs20(LinkRow, { columnGap: 1, flexWrap: "wrap", children: [
2619
- previous ? /* @__PURE__ */ jsx26(TerminalLink, { href: previous, underline: false, children: "\u2039 \u4E0A\u4E00\u9875" }) : /* @__PURE__ */ jsx26(Text22, { color: colors.muted, children: "\u2039 \u4E0A\u4E00\u9875" }),
2620
- /* @__PURE__ */ jsx26(Text22, { color: colors.dim, children: "\u2502" }),
2621
- /* @__PURE__ */ jsxs20(Text22, { color: colors.muted, children: [
2477
+ previous ? /* @__PURE__ */ jsx28(TerminalLink, { href: previous, underline: false, children: "\u2039 \u4E0A\u4E00\u9875" }) : /* @__PURE__ */ jsx28(Text23, { color: colors.muted, children: "\u2039 \u4E0A\u4E00\u9875" }),
2478
+ /* @__PURE__ */ jsx28(Text23, { color: colors.dim, children: "\u2502" }),
2479
+ /* @__PURE__ */ jsxs20(Text23, { color: colors.muted, children: [
2622
2480
  "\u7B2C ",
2623
2481
  current,
2624
2482
  " \u9875\uFF0C\u5171 ",
2625
2483
  total,
2626
2484
  " \u9875"
2627
2485
  ] }),
2628
- /* @__PURE__ */ jsx26(Text22, { color: colors.dim, children: "\u2502" }),
2629
- next ? /* @__PURE__ */ jsx26(TerminalLink, { href: next, underline: false, children: "\u4E0B\u4E00\u9875 \u203A" }) : /* @__PURE__ */ jsx26(Text22, { color: colors.muted, children: "\u4E0B\u4E00\u9875 \u203A" })
2486
+ /* @__PURE__ */ jsx28(Text23, { color: colors.dim, children: "\u2502" }),
2487
+ next ? /* @__PURE__ */ jsx28(TerminalLink, { href: next, underline: false, children: "\u4E0B\u4E00\u9875 \u203A" }) : /* @__PURE__ */ jsx28(Text23, { color: colors.muted, children: "\u4E0B\u4E00\u9875 \u203A" })
2630
2488
  ] });
2631
2489
  }
2632
2490
 
2633
- // packages/cli/src/page-content.tsx
2634
- import { jsx as jsx27, jsxs as jsxs21 } from "react/jsx-runtime";
2491
+ // packages/cli/src/components/page-content.tsx
2492
+ import { jsx as jsx29, jsxs as jsxs21 } from "react/jsx-runtime";
2635
2493
  function PageEntries({ page }) {
2636
2494
  const { colors } = useTerminalStyle();
2637
2495
  if (page.projects)
2638
- return /* @__PURE__ */ jsx27(HomeList, { list: { kind: "projects", items: page.projects, before: "", after: "" } });
2639
- if (!page.tags) return page.items.length ? /* @__PURE__ */ jsx27(PageList, { items: page.items }) : null;
2640
- return /* @__PURE__ */ jsx27(Box20, { flexWrap: "wrap", columnGap: 3, children: page.tags.map((tag) => /* @__PURE__ */ jsxs21(LinkRow, { children: [
2496
+ return /* @__PURE__ */ jsx29(HomeList, { list: { kind: "projects", items: page.projects, before: "", after: "" } });
2497
+ if (!page.tags) return page.items.length ? /* @__PURE__ */ jsx29(PageList, { items: page.items }) : null;
2498
+ return /* @__PURE__ */ jsx29(Box21, { flexWrap: "wrap", columnGap: 3, children: page.tags.map((tag) => /* @__PURE__ */ jsxs21(LinkRow, { children: [
2641
2499
  /* @__PURE__ */ jsxs21(TerminalLink, { href: tag.path, color: colors.fg, underline: false, children: [
2642
2500
  "#",
2643
2501
  cleanText(tag.name)
2644
2502
  ] }),
2645
- /* @__PURE__ */ jsxs21(Text23, { color: colors.muted, children: [
2503
+ /* @__PURE__ */ jsxs21(Text24, { color: colors.muted, children: [
2646
2504
  " ",
2647
2505
  tag.count
2648
2506
  ] })
@@ -2654,29 +2512,29 @@ var PageContent = memo(function PageContent2({
2654
2512
  onSearch
2655
2513
  }) {
2656
2514
  const { colors } = useTerminalStyle();
2657
- if (page.sections) return /* @__PURE__ */ jsx27(HomeSections, { page });
2658
- if (page.post) return /* @__PURE__ */ jsx27(ArticlePage, { ...page, post: page.post });
2659
- return /* @__PURE__ */ jsxs21(Box20, { flexDirection: "column", marginBottom: 1, children: [
2660
- page.path !== "/" && /* @__PURE__ */ jsx27(Prompt, { text: page.command ?? prompt, command: true, aside: page.aside }),
2661
- /* @__PURE__ */ jsxs21(Box20, { flexDirection: "column", paddingX: 3, paddingTop: 1, gap: 1, children: [
2662
- page.tool && /* @__PURE__ */ jsx27(Tool, { ...page.tool }),
2663
- page.verb !== "Read" && /* @__PURE__ */ jsx27(Heading, { children: cleanText(page.title) }),
2664
- page.description && /* @__PURE__ */ jsx27(Text23, { color: colors["fg-soft"], children: cleanText(page.description) }),
2665
- page.path.startsWith("/search/") && /* @__PURE__ */ jsx27(SearchInput, { path: page.path, onSearch }),
2666
- page.markdown && /* @__PURE__ */ jsx27(Box20, { flexDirection: "column", maxWidth: page.verb === "Read" ? 90 : void 0, children: /* @__PURE__ */ jsx27(Markdown, { text: page.markdown }) }),
2667
- /* @__PURE__ */ jsx27(PageEntries, { page }),
2515
+ if (page.sections) return /* @__PURE__ */ jsx29(HomeSections, { page });
2516
+ if (page.post) return /* @__PURE__ */ jsx29(ArticlePage, { ...page, post: page.post });
2517
+ return /* @__PURE__ */ jsxs21(Box21, { flexDirection: "column", marginBottom: 1, children: [
2518
+ page.path !== "/" && /* @__PURE__ */ jsx29(Prompt, { text: page.command ?? prompt, command: true, aside: page.aside }),
2519
+ /* @__PURE__ */ jsxs21(Box21, { flexDirection: "column", paddingX: 3, paddingTop: 1, gap: 1, children: [
2520
+ page.tool && /* @__PURE__ */ jsx29(Tool, { ...page.tool }),
2521
+ page.verb !== "Read" && /* @__PURE__ */ jsx29(Heading, { children: cleanText(page.title) }),
2522
+ page.description && /* @__PURE__ */ jsx29(Text24, { color: colors["fg-soft"], children: cleanText(page.description) }),
2523
+ page.path.startsWith("/search/") && /* @__PURE__ */ jsx29(SearchInput, { path: page.path, onSearch }),
2524
+ page.markdown && /* @__PURE__ */ jsx29(Box21, { flexDirection: "column", maxWidth: page.verb === "Read" ? 90 : void 0, children: /* @__PURE__ */ jsx29(Markdown, { text: page.markdown }) }),
2525
+ /* @__PURE__ */ jsx29(PageEntries, { page }),
2668
2526
  page.more && /* @__PURE__ */ jsxs21(LinkRow, { children: [
2669
- /* @__PURE__ */ jsx27(Text23, { color: colors.muted, children: "\u203A " }),
2670
- /* @__PURE__ */ jsx27(TerminalLink, { href: page.more.path, children: page.more.title })
2527
+ /* @__PURE__ */ jsx29(Text24, { color: colors.muted, children: "\u203A " }),
2528
+ /* @__PURE__ */ jsx29(TerminalLink, { href: page.more.path, children: page.more.title })
2671
2529
  ] }),
2672
- page.pagination && /* @__PURE__ */ jsx27(Pagination, { ...page.pagination })
2530
+ page.pagination && /* @__PURE__ */ jsx29(Pagination, { ...page.pagination })
2673
2531
  ] })
2674
2532
  ] });
2675
2533
  });
2676
2534
 
2677
- // packages/cli/src/terminal-layout.tsx
2678
- import { Box as Box21, Text as Text24, useWindowSize as useWindowSize2 } from "ink";
2679
- import { jsx as jsx28, jsxs as jsxs22 } from "react/jsx-runtime";
2535
+ // packages/cli/src/terminal/terminal-layout.tsx
2536
+ import { Box as Box22, Text as Text25, useWindowSize as useWindowSize2 } from "ink";
2537
+ import { jsx as jsx30, jsxs as jsxs22 } from "react/jsx-runtime";
2680
2538
  function TerminalLayout({
2681
2539
  path,
2682
2540
  nav = [],
@@ -2686,7 +2544,7 @@ function TerminalLayout({
2686
2544
  const { colors } = useTerminalStyle();
2687
2545
  const segments = new URL(path, "https://miantiao.me").pathname.split("/").filter(Boolean);
2688
2546
  return /* @__PURE__ */ jsxs22(
2689
- Box21,
2547
+ Box22,
2690
2548
  {
2691
2549
  width: columns,
2692
2550
  height: rows,
@@ -2694,19 +2552,19 @@ function TerminalLayout({
2694
2552
  backgroundColor: colors.bg,
2695
2553
  overflow: "hidden",
2696
2554
  children: [
2697
- /* @__PURE__ */ jsxs22(Box21, { paddingX: 2, paddingY: 1, flexShrink: 0, flexDirection: columns < 70 ? "column" : "row", children: [
2698
- /* @__PURE__ */ jsxs22(Box21, { flexGrow: 1, flexShrink: 1, children: [
2699
- /* @__PURE__ */ jsx28(TerminalLink, { href: "/", color: colors.muted, underline: false, children: "~/miantiao.me" }),
2555
+ /* @__PURE__ */ jsxs22(Box22, { paddingX: 2, paddingY: 1, flexShrink: 0, flexDirection: columns < 70 ? "column" : "row", children: [
2556
+ /* @__PURE__ */ jsxs22(Box22, { flexGrow: 1, flexShrink: 1, children: [
2557
+ /* @__PURE__ */ jsx30(TerminalLink, { href: "/", color: colors.muted, underline: false, children: "~/miantiao.me" }),
2700
2558
  segments.map((segment, index) => {
2701
2559
  const prefix = `/${segments.slice(0, index + 1).join("/")}/`;
2702
2560
  const href = segments[0] === "posts" && index < segments.length - 1 ? "/blog/" : prefix;
2703
- return /* @__PURE__ */ jsxs22(Box21, { flexShrink: 1, minWidth: 0, children: [
2704
- /* @__PURE__ */ jsx28(Text24, { color: colors.muted, children: "/" }),
2705
- /* @__PURE__ */ jsx28(TerminalLink, { href, color: colors.muted, underline: false, children: cleanText(decodeURIComponent(segment)) })
2561
+ return /* @__PURE__ */ jsxs22(Box22, { flexShrink: 1, minWidth: 0, children: [
2562
+ /* @__PURE__ */ jsx30(Text25, { color: colors.muted, children: "/" }),
2563
+ /* @__PURE__ */ jsx30(TerminalLink, { href, color: colors.muted, underline: false, children: cleanText(decodeURIComponent(segment)) })
2706
2564
  ] }, prefix);
2707
2565
  })
2708
2566
  ] }),
2709
- /* @__PURE__ */ jsx28(Box21, { columnGap: 2, flexWrap: "wrap", flexShrink: 0, children: nav.map((link) => /* @__PURE__ */ jsx28(Box21, { flexShrink: 0, children: /* @__PURE__ */ jsx28(
2567
+ /* @__PURE__ */ jsx30(Box22, { columnGap: 2, flexWrap: "wrap", flexShrink: 0, children: nav.map((link) => /* @__PURE__ */ jsx30(Box22, { flexShrink: 0, children: /* @__PURE__ */ jsx30(
2710
2568
  TerminalLink,
2711
2569
  {
2712
2570
  href: link.href,
@@ -2722,8 +2580,8 @@ function TerminalLayout({
2722
2580
  );
2723
2581
  }
2724
2582
 
2725
- // packages/cli/src/console.tsx
2726
- import { jsx as jsx29, jsxs as jsxs23 } from "react/jsx-runtime";
2583
+ // packages/cli/src/terminal/console.tsx
2584
+ import { jsx as jsx31, jsxs as jsxs23 } from "react/jsx-runtime";
2727
2585
  function Console({
2728
2586
  runtime,
2729
2587
  page,
@@ -2742,12 +2600,12 @@ function Console({
2742
2600
  }) {
2743
2601
  const scroll = useRef11(null);
2744
2602
  const focusKey = String(locationKey);
2745
- return /* @__PURE__ */ jsx29(LinkNavigation, { value: { site: new URL(page.path, site.url).href, origin, onSelect, scroll }, children: /* @__PURE__ */ jsx29(LinkScope, { value: !panel || panel.type === "notice", children: /* @__PURE__ */ jsx29(TerminalLayout, { path: page.path, nav: site.nav, children: /* @__PURE__ */ jsxs23(ThreadPrimitive2.Root, { flexGrow: 1, flexShrink: 1, minHeight: 0, children: [
2603
+ return /* @__PURE__ */ jsx31(LinkNavigation, { value: { site: new URL(page.path, site.url).href, origin, onSelect, scroll }, children: /* @__PURE__ */ jsx31(LinkScope, { value: !panel || panel.type === "notice", children: /* @__PURE__ */ jsx31(TerminalLayout, { path: page.path, nav: site.nav, children: /* @__PURE__ */ jsxs23(ThreadPrimitive2.Root, { flexGrow: 1, flexShrink: 1, minHeight: 0, children: [
2746
2604
  /* @__PURE__ */ jsxs23(ScrollArea, { ref: scroll, active: !panel || panel.type === "notice", children: [
2747
- /* @__PURE__ */ jsx29(PageContent, { page, prompt, onSearch }),
2748
- /* @__PURE__ */ jsx29(ChatThread, {})
2605
+ /* @__PURE__ */ jsx31(PageContent, { page, prompt, onSearch }),
2606
+ /* @__PURE__ */ jsx31(ChatThread, {})
2749
2607
  ] }),
2750
- /* @__PURE__ */ jsx29(
2608
+ /* @__PURE__ */ jsx31(
2751
2609
  Composer,
2752
2610
  {
2753
2611
  runtime,
@@ -2768,11 +2626,144 @@ function Console({
2768
2626
  ] }) }, focusKey) }) });
2769
2627
  }
2770
2628
 
2771
- // packages/cli/src/session.ts
2629
+ // src/shared/pagination.ts
2630
+ function getPageCount(total, pageSize) {
2631
+ return Math.max(1, Math.ceil(total / pageSize));
2632
+ }
2633
+ function paginate(items, page, pageSize) {
2634
+ const lastPage = getPageCount(items.length, pageSize);
2635
+ const currentPage = Number.isSafeInteger(page) ? Math.min(Math.max(page, 1), lastPage) : 1;
2636
+ const start = (currentPage - 1) * pageSize;
2637
+ const data = items.slice(start, start + pageSize);
2638
+ const previousPath = currentPage === 2 ? "/blog/" : `/blog/${currentPage - 1}/`;
2639
+ return {
2640
+ data,
2641
+ first: items.length ? start + 1 : 0,
2642
+ last: start + data.length,
2643
+ total: items.length,
2644
+ currentPage,
2645
+ lastPage,
2646
+ url: {
2647
+ prev: currentPage > 1 ? previousPath : null,
2648
+ next: currentPage < lastPage ? `/blog/${currentPage + 1}/` : null
2649
+ }
2650
+ };
2651
+ }
2652
+
2653
+ // packages/cli/src/content/pages.ts
2654
+ async function loadPage(client, path, signal, cachedIndex) {
2655
+ signal?.throwIfAborted();
2656
+ const index = cachedIndex ?? await client.getIndex(signal);
2657
+ const url = new URL(path, client.site);
2658
+ const pathname = url.pathname.endsWith("/") ? url.pathname : `${url.pathname}/`;
2659
+ const page = { path: pathname + url.search, title: "", verb: "List", items: [] };
2660
+ const document = [...Object.values(index.pages), ...index.posts].find(
2661
+ (item) => new URL(item.path, client.site).pathname === pathname
2662
+ );
2663
+ if (document) {
2664
+ const result = await client.getDocument(document.path, index, signal);
2665
+ return {
2666
+ index: result.index,
2667
+ page: documentPage(result.index, result.document, client.site, url.search)
2668
+ };
2669
+ } else if (pathname === "/blog/" || /^\/blog\/\d+\/$/.test(pathname)) {
2670
+ const size = index.site.pageSize;
2671
+ const requested = Number(pathname.match(/\d+/)?.[0] ?? 1);
2672
+ const result = paginate(index.posts, requested, size);
2673
+ const canonicalPath = requested === 1 ? "/blog/" : `/blog/${requested}/`;
2674
+ if (!Number.isSafeInteger(requested) || requested !== result.currentPage || pathname !== canonicalPath)
2675
+ throw new Error("\u627E\u4E0D\u5230\u8FD9\u4E00\u9875\uFF0C\u8BF7\u4F7F\u7528 /blog \u6D4F\u89C8\u6587\u7AE0\u3002");
2676
+ const current = result.currentPage;
2677
+ const total = result.lastPage;
2678
+ page.title = "\u535A\u5BA2";
2679
+ page.command = current === 1 ? "/blog" : `/blog ${current}`;
2680
+ page.aside = `${current}/${total}`;
2681
+ page.tool = {
2682
+ verb: "List",
2683
+ target: "posts/",
2684
+ detail: `${result.first}\u2013${result.last} of ${result.total}`
2685
+ };
2686
+ page.items = result.data.map((post) => ({
2687
+ title: post.title,
2688
+ date: post.date,
2689
+ description: post.description,
2690
+ path: post.path
2691
+ }));
2692
+ page.pagination = {
2693
+ current,
2694
+ total,
2695
+ previous: result.url.prev ?? void 0,
2696
+ next: result.url.next ?? void 0
2697
+ };
2698
+ } else if (pathname === "/projects/") {
2699
+ page.title = "\u9879\u76EE";
2700
+ page.command = "/projects";
2701
+ page.tool = {
2702
+ verb: "List",
2703
+ target: "projects/",
2704
+ detail: `\u6309 Star \u6392\u5E8F\uFF0C${index.projects.length} \u4E2A`
2705
+ };
2706
+ page.description = "\u8FD9\u91CC\u8BB0\u5F55\u6211\u5728\u5DE5\u4F5C\u4E4B\u5916\u6301\u7EED\u6298\u817E\u7684\u5C0F\u9879\u76EE\uFF1A\u6709\u4E9B\u662F\u5DE5\u5177\uFF0C\u6709\u4E9B\u662F\u5B9E\u9A8C\uFF0C\u4E5F\u6709\u4E9B\u53EA\u662F\u597D\u5947\u5FC3\u7684\u526F\u4EA7\u7269\u3002";
2707
+ page.projects = index.projects;
2708
+ page.items = index.projects.map((project) => ({
2709
+ title: `${project.title} \xB7 \u2605 ${project.stars}`,
2710
+ description: project.description,
2711
+ path: project.url,
2712
+ external: true
2713
+ }));
2714
+ } else if (pathname === "/tags/") {
2715
+ page.title = "\u6807\u7B7E";
2716
+ page.command = "/tags";
2717
+ page.tool = { verb: "List", target: "tags/", detail: `${index.tags.length} \u4E2A` };
2718
+ page.tags = index.tags;
2719
+ page.items = index.tags.map((tag) => ({
2720
+ title: `#${tag.name}`,
2721
+ description: String(tag.count),
2722
+ path: tag.path
2723
+ }));
2724
+ } else if (pathname.startsWith("/tags/")) {
2725
+ const tag = index.tags.find((tag2) => tag2.path === pathname);
2726
+ if (!tag) throw new Error("\u627E\u4E0D\u5230\u8FD9\u4E2A\u6807\u7B7E\uFF0C\u8BF7\u4F7F\u7528 /tags \u67E5\u627E\u3002");
2727
+ page.title = `\u6807\u7B7E\uFF1A${tag.name}`;
2728
+ page.command = `/tags ${tag.name}`;
2729
+ page.items = index.posts.filter((post) => post.tags.includes(tag.name)).map((post) => ({
2730
+ title: post.title,
2731
+ date: post.date,
2732
+ description: post.description,
2733
+ path: post.path
2734
+ }));
2735
+ page.tool = { verb: "Grep", target: `#${tag.name}`, detail: `${page.items.length} \u7BC7` };
2736
+ page.more = { title: "\u5168\u90E8\u6807\u7B7E", path: "/tags/" };
2737
+ } else if (pathname === "/search/") {
2738
+ const query = url.searchParams.get("q") ?? "";
2739
+ page.title = "\u641C\u7D22";
2740
+ page.command = query ? `/search ${query}` : "/search";
2741
+ page.verb = "Search";
2742
+ if (query) {
2743
+ const results = await client.search(query, index, signal);
2744
+ page.items = results.map((post) => ({
2745
+ title: post.title,
2746
+ description: post.description,
2747
+ date: post.date,
2748
+ path: post.url
2749
+ }));
2750
+ }
2751
+ if (query) page.aside = `${page.items.length} \u6761`;
2752
+ if (query && !page.items.length) page.markdown = `\u6CA1\u6709\u627E\u5230\u4E0E\u300C${query}\u300D\u76F8\u5173\u7684\u6587\u7AE0`;
2753
+ } else if (pathname === "/rss/") {
2754
+ page.title = "\u8BA2\u9605 RSS";
2755
+ page.items = [{ title: index.site.feedUrl, path: index.site.feedUrl, external: true }];
2756
+ } else {
2757
+ throw new Error("\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762\uFF0C\u8BF7\u4F7F\u7528 /help \u67E5\u770B\u547D\u4EE4\u3002");
2758
+ }
2759
+ return { index, page };
2760
+ }
2761
+
2762
+ // packages/cli/src/app/session.ts
2772
2763
  import { useApp, useInput as useInput10 } from "ink";
2773
2764
  import { useCallback as useCallback2, useEffect as useEffect10, useState as useState13 } from "react";
2774
2765
 
2775
- // packages/cli/src/preferences.ts
2766
+ // packages/cli/src/terminal/preferences.ts
2776
2767
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
2777
2768
  import { homedir } from "node:os";
2778
2769
  import { dirname, join } from "node:path";
@@ -2795,7 +2786,7 @@ function saveTheme(theme) {
2795
2786
  }
2796
2787
  }
2797
2788
 
2798
- // src/agent/command-actions.ts
2789
+ // src/shared/agent/command-actions.ts
2799
2790
  async function runSharedCommand(name, args, actions) {
2800
2791
  const path = getCommandPath(name, args);
2801
2792
  if (path) {
@@ -2831,16 +2822,16 @@ async function runSharedCommand(name, args, actions) {
2831
2822
  }
2832
2823
  }
2833
2824
 
2834
- // packages/cli/src/agent.ts
2825
+ // packages/cli/src/app/agent.ts
2835
2826
  import { useChatRuntime } from "@assistant-ui/ai-sdk";
2836
2827
  import { useEffect as useEffect8, useMemo as useMemo3 } from "react";
2837
2828
 
2838
- // src/agent/transport.ts
2829
+ // src/shared/agent/transport.ts
2839
2830
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
2840
2831
  import { DirectChatTransport, isStepCount, tool, ToolLoopAgent } from "ai";
2841
2832
  import { z as z3 } from "zod";
2842
2833
 
2843
- // src/agent/context-core.ts
2834
+ // src/shared/agent/context.ts
2844
2835
  import { escapeRegExp } from "es-toolkit/string";
2845
2836
  function formatTime(now, timeZone) {
2846
2837
  const parts = Object.fromEntries(
@@ -2890,55 +2881,13 @@ function buildContextMessage(context, siteName) {
2890
2881
  ${lines.join("\n")}
2891
2882
  </context>`;
2892
2883
  }
2893
- function retryContextMessage(message) {
2894
- return message.replace("\n</context>", "\nretry: 1\n</context>");
2895
- }
2896
-
2897
- // src/agent/fetch.ts
2898
- function stripSseEvent(body, eventName) {
2899
- const pattern = new RegExp(`^event:\\s*${eventName}\\s*$`, "m");
2900
- let buffer = "";
2901
- return body.pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({
2902
- transform(text, controller) {
2903
- buffer += text;
2904
- const events = buffer.split(/\r?\n\r?\n/);
2905
- buffer = events.pop() ?? "";
2906
- for (const event of events) {
2907
- if (!pattern.test(event))
2908
- controller.enqueue(`${event}
2909
-
2910
- `);
2911
- }
2912
- },
2913
- flush(controller) {
2914
- if (buffer && !pattern.test(buffer))
2915
- controller.enqueue(buffer);
2916
- }
2917
- })).pipeThrough(new TextEncoderStream());
2918
- }
2919
- var aiSearchFetch = async (input, init) => {
2920
- let response = await fetch(input, init);
2921
- if (response.status >= 500 && typeof init?.body === "string") {
2922
- const body = JSON.parse(init.body);
2923
- const context = body.messages[0];
2924
- if (context?.role === "user" && typeof context.content === "string") {
2925
- context.content = retryContextMessage(context.content);
2926
- await response.body?.cancel();
2927
- response = await fetch(input, { ...init, body: JSON.stringify(body) });
2928
- }
2929
- }
2930
- if (!response.ok || !response.body || !response.headers.get("content-type")?.includes("text/event-stream"))
2931
- return response;
2932
- return new Response(stripSseEvent(response.body, "chunks"), response);
2933
- };
2934
2884
 
2935
- // src/agent/transport.ts
2885
+ // src/shared/agent/transport.ts
2936
2886
  var themeIds = themeOptions.map((option) => option.id);
2937
2887
  function createAgentTransport(handlers, options) {
2938
2888
  const provider = createOpenAICompatible({
2939
2889
  name: "miantiao",
2940
- baseURL: options.baseUrl,
2941
- fetch: aiSearchFetch
2890
+ baseURL: options.baseUrl
2942
2891
  });
2943
2892
  const agent = new ToolLoopAgent({
2944
2893
  model: provider(options.model),
@@ -2977,7 +2926,7 @@ function createAgentTransport(handlers, options) {
2977
2926
  return new DirectChatTransport({ agent, onError: () => "AI \u6682\u65F6\u65E0\u6CD5\u56DE\u590D\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002" });
2978
2927
  }
2979
2928
 
2980
- // packages/cli/src/agent.ts
2929
+ // packages/cli/src/app/agent.ts
2981
2930
  function useTerminalAgent({ site, index, page, theme, setTheme, navigate }) {
2982
2931
  const transport = useMemo3(
2983
2932
  () => createAgentTransport(
@@ -3026,7 +2975,7 @@ function useTerminalAgent({ site, index, page, theme, setTheme, navigate }) {
3026
2975
  return runtime;
3027
2976
  }
3028
2977
 
3029
- // packages/cli/src/browser.ts
2978
+ // packages/cli/src/terminal/browser.ts
3030
2979
  import { spawn } from "node:child_process";
3031
2980
  async function openBrowser(input, site) {
3032
2981
  const url = new URL(input, site);
@@ -3043,33 +2992,46 @@ async function openBrowser(input, site) {
3043
2992
  });
3044
2993
  }
3045
2994
 
3046
- // packages/cli/src/navigation.ts
3047
- import { useCallback, useEffect as useEffect9, useRef as useRef12, useState as useState12 } from "react";
2995
+ // packages/cli/src/app/navigation.ts
2996
+ import { useCallback, useEffect as useEffect9, useLayoutEffect as useLayoutEffect4, useMemo as useMemo4, useRef as useRef12, useState as useState12 } from "react";
2997
+ import { useLocation, useNavigate, useNavigationType } from "react-router";
3048
2998
  function useNavigation(client, initial) {
3049
- const [state, setState] = useState12({
3050
- ...initial,
3051
- status: "idle",
3052
- panel: client.warning ? { type: "notice", text: client.warning } : null,
2999
+ const location = useLocation();
3000
+ const routerNavigate = useNavigate();
3001
+ const navigationType = useNavigationType();
3002
+ const [home, setHome] = useState12(initial);
3003
+ const entry = useMemo4(() => location.state ?? {
3004
+ ...home,
3053
3005
  prompt: "/home",
3054
3006
  locationKey: 0
3055
- });
3007
+ }, [location.state, home]);
3008
+ const current = useRef12({ entry, routerNavigate });
3009
+ useLayoutEffect4(() => {
3010
+ current.current = { entry, routerNavigate };
3011
+ }, [entry, routerNavigate]);
3012
+ const [status, setStatus] = useState12("idle");
3013
+ const [panel, setPanel] = useState12(
3014
+ client.warning ? { type: "notice", text: client.warning } : null
3015
+ );
3056
3016
  useEffect9(() => {
3057
3017
  if (initial.page.postsStatus !== "loading") return;
3058
3018
  const controller = new AbortController();
3059
- void client.getIndex(controller.signal).then((index2) => {
3019
+ const updateHome = (content) => {
3060
3020
  if (controller.signal.aborted) return;
3061
- setState(
3062
- (current) => current.page === initial.page ? { ...current, index: index2, page: withHomePosts(current.page, index2) } : current
3063
- );
3021
+ setHome(content);
3022
+ if (current.current.entry.page !== initial.page) return;
3023
+ const state = { ...current.current.entry, ...content };
3024
+ current.current.routerNavigate(state.page.path, { replace: true, state });
3025
+ current.current.entry = state;
3026
+ };
3027
+ void client.getIndex(controller.signal).then((index2) => {
3028
+ updateHome({ index: index2, page: withHomePosts(initial.page, index2) });
3064
3029
  }).catch(() => {
3065
- if (controller.signal.aborted) return;
3066
- setState(
3067
- (current) => current.page === initial.page ? { ...current, page: { ...current.page, postsStatus: "error" } } : current
3068
- );
3030
+ updateHome({ ...initial, page: { ...initial.page, postsStatus: "error" } });
3069
3031
  });
3070
3032
  return () => controller.abort();
3071
3033
  }, [client, initial]);
3072
- const { index } = state;
3034
+ const { index } = entry;
3073
3035
  useEffect9(() => {
3074
3036
  if (index === initial.index && initial.page.postsStatus === "loading") return;
3075
3037
  void client.preloadSearch(index).catch(() => void 0);
@@ -3086,59 +3048,61 @@ function useNavigation(client, initial) {
3086
3048
  const cancel = useCallback(() => {
3087
3049
  active.current?.controller.abort();
3088
3050
  active.current = void 0;
3089
- setState((current) => current.status === "idle" ? current : { ...current, status: "idle" });
3051
+ setStatus("idle");
3090
3052
  }, []);
3091
- const setPanel = useCallback((panel) => {
3092
- setState((current) => ({ ...current, panel }));
3053
+ useLayoutEffect4(() => {
3054
+ if (navigationType === "POP") cancel();
3055
+ }, [location.key, navigationType, cancel]);
3056
+ const notify = useCallback((text, tone) => {
3057
+ setPanel({ type: "notice", text, tone });
3093
3058
  }, []);
3094
- const notify = useCallback(
3095
- (text, tone) => {
3096
- setPanel({ type: "notice", text, tone });
3097
- },
3098
- [setPanel]
3099
- );
3100
3059
  const navigate = useCallback(
3101
3060
  async (path, prompt = path, replace = false) => {
3102
3061
  if (replace && active.current && !active.current.replace) return false;
3103
3062
  active.current?.controller.abort();
3104
3063
  const request = { controller: new AbortController(), replace };
3105
3064
  active.current = request;
3106
- setState((current) => ({ ...current, status: "loading", panel: null }));
3065
+ setStatus("loading");
3066
+ setPanel(null);
3107
3067
  let next;
3108
3068
  try {
3109
- next = await loadPage(client, path, request.controller.signal, replace ? index : void 0);
3069
+ next = await loadPage(
3070
+ client,
3071
+ path,
3072
+ request.controller.signal,
3073
+ replace ? current.current.entry.index : void 0
3074
+ );
3110
3075
  } catch (error) {
3111
3076
  if (active.current === request) {
3112
3077
  active.current = void 0;
3113
- setState((current) => ({
3114
- ...current,
3115
- status: "idle",
3116
- panel: {
3117
- type: "notice",
3118
- tone: "error",
3119
- text: error instanceof Error ? error.message : "\u65E0\u6CD5\u8BFB\u53D6\u5B98\u7F51\u5185\u5BB9\u3002"
3120
- }
3121
- }));
3078
+ setStatus("idle");
3079
+ setPanel({
3080
+ type: "notice",
3081
+ tone: "error",
3082
+ text: error instanceof Error ? error.message : "\u65E0\u6CD5\u8BFB\u53D6\u5B98\u7F51\u5185\u5BB9\u3002"
3083
+ });
3122
3084
  }
3123
3085
  return false;
3124
3086
  }
3125
3087
  if (active.current !== request) return false;
3126
3088
  active.current = void 0;
3127
- setState((current) => ({
3089
+ const state = {
3128
3090
  ...next,
3129
- status: "idle",
3130
- panel: client.warning ? { type: "notice", text: client.warning } : null,
3131
3091
  prompt,
3132
- locationKey: current.locationKey + Number(!replace)
3133
- }));
3092
+ locationKey: current.current.entry.locationKey + Number(!replace)
3093
+ };
3094
+ current.current.routerNavigate(next.page.path, { replace, state });
3095
+ current.current.entry = state;
3096
+ setStatus("idle");
3097
+ setPanel(client.warning ? { type: "notice", text: client.warning } : null);
3134
3098
  return true;
3135
3099
  },
3136
- [client, index]
3100
+ [client]
3137
3101
  );
3138
- return { ...state, navigate, setPanel, cancel, notify };
3102
+ return { ...entry, status, panel, navigate, setPanel, cancel, notify };
3139
3103
  }
3140
3104
 
3141
- // packages/cli/src/session.ts
3105
+ // packages/cli/src/app/session.ts
3142
3106
  function useTerminalSession(client, initial) {
3143
3107
  const { exit } = useApp();
3144
3108
  const [theme, setTheme] = useState13(readTheme);
@@ -3224,7 +3188,7 @@ function useTerminalSession(client, initial) {
3224
3188
  revision: index.revision,
3225
3189
  locationKey,
3226
3190
  prompt,
3227
- site: { ...initial.index.site, ...index.site },
3191
+ site: index.site,
3228
3192
  origin: client.site,
3229
3193
  loading: status === "loading",
3230
3194
  panel,
@@ -3241,14 +3205,14 @@ function useTerminalSession(client, initial) {
3241
3205
  }
3242
3206
 
3243
3207
  // packages/cli/src/app.tsx
3244
- import { jsx as jsx30, jsxs as jsxs24 } from "react/jsx-runtime";
3208
+ import { jsx as jsx32, jsxs as jsxs24 } from "react/jsx-runtime";
3245
3209
  function Session({
3246
3210
  client,
3247
3211
  initial,
3248
3212
  width
3249
3213
  }) {
3250
3214
  const { theme, ...session } = useTerminalSession(client, initial);
3251
- return /* @__PURE__ */ jsx30(TerminalTheme, { preference: theme, width, children: /* @__PURE__ */ jsx30(AssistantRuntimeProvider, { runtime: session.runtime, children: /* @__PURE__ */ jsx30(Console, { ...session }) }) });
3215
+ return /* @__PURE__ */ jsx32(TerminalTheme, { preference: theme, width, children: /* @__PURE__ */ jsx32(AssistantRuntimeProvider, { runtime: session.runtime, children: /* @__PURE__ */ jsx32(Console, { ...session }) }) });
3252
3216
  }
3253
3217
  function App({ site }) {
3254
3218
  const { exit } = useApp2();
@@ -3285,18 +3249,18 @@ function App({ site }) {
3285
3249
  { isActive: state.status !== "ready" }
3286
3250
  );
3287
3251
  if (state.status === "ready")
3288
- return /* @__PURE__ */ jsx30(Session, { client, initial: state.content, width });
3289
- return /* @__PURE__ */ jsx30(TerminalTheme, { preference: "auto", width, children: /* @__PURE__ */ jsx30(TerminalLayout, { path: "/", children: /* @__PURE__ */ jsxs24(Box22, { flexDirection: "column", flexGrow: 1, padding: 2, children: [
3290
- /* @__PURE__ */ jsxs24(Text25, { children: [
3252
+ return /* @__PURE__ */ jsx32(MemoryRouter, { initialEntries: [state.content.page.path], useTransitions: false, children: /* @__PURE__ */ jsx32(Session, { client, initial: state.content, width }) });
3253
+ return /* @__PURE__ */ jsx32(TerminalTheme, { preference: "auto", width, children: /* @__PURE__ */ jsx32(TerminalLayout, { path: "/", children: /* @__PURE__ */ jsxs24(Box23, { flexDirection: "column", flexGrow: 1, padding: 2, children: [
3254
+ /* @__PURE__ */ jsxs24(Text26, { children: [
3291
3255
  "\u25C6 ",
3292
3256
  state.status === "error" ? state.message : "\u601D\u8003\u4E2D\u2026\u2026"
3293
3257
  ] }),
3294
- /* @__PURE__ */ jsx30(Text25, { children: state.status === "error" ? "Enter \u91CD\u8BD5 \xB7 q \u9000\u51FA" : "Ctrl+C \u9000\u51FA" })
3258
+ /* @__PURE__ */ jsx32(Text26, { children: state.status === "error" ? "Enter \u91CD\u8BD5 \xB7 q \u9000\u51FA" : "Ctrl+C \u9000\u51FA" })
3295
3259
  ] }) }) });
3296
3260
  }
3297
3261
  async function run(site) {
3298
3262
  const app = render(
3299
- /* @__PURE__ */ jsx30(MouseProvider, { children: /* @__PURE__ */ jsx30(App, { site }) }),
3263
+ /* @__PURE__ */ jsx32(MouseProvider, { children: /* @__PURE__ */ jsx32(App, { site }) }),
3300
3264
  {
3301
3265
  exitOnCtrlC: false,
3302
3266
  alternateScreen: true,