@cchistory/lite 0.8.1 → 0.8.3

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.
Files changed (232) hide show
  1. package/INSTALL.md +1 -1
  2. package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
  3. package/apps/lite-cli/dist/agent-contract.js +60 -21
  4. package/apps/lite-cli/dist/agent-contract.js.map +1 -1
  5. package/apps/lite-cli/dist/help.d.ts +7 -0
  6. package/apps/lite-cli/dist/help.d.ts.map +1 -0
  7. package/apps/lite-cli/dist/help.js +77 -0
  8. package/apps/lite-cli/dist/help.js.map +1 -0
  9. package/apps/lite-cli/dist/index.d.ts.map +1 -1
  10. package/apps/lite-cli/dist/index.js +483 -201
  11. package/apps/lite-cli/dist/index.js.map +1 -1
  12. package/apps/lite-cli/dist/index.test.js +39 -76
  13. package/apps/lite-cli/dist/index.test.js.map +1 -1
  14. package/apps/lite-cli/dist/json-v2.d.ts.map +1 -1
  15. package/apps/lite-cli/dist/json-v2.js +43 -1
  16. package/apps/lite-cli/dist/json-v2.js.map +1 -1
  17. package/apps/lite-cli/dist/query.d.ts +24 -2
  18. package/apps/lite-cli/dist/query.d.ts.map +1 -1
  19. package/apps/lite-cli/dist/query.js +204 -7
  20. package/apps/lite-cli/dist/query.js.map +1 -1
  21. package/apps/lite-cli/dist/shell.js +24 -1
  22. package/apps/lite-cli/dist/shell.js.map +1 -1
  23. package/apps/lite-cli/dist/stats-command.d.ts +7 -1
  24. package/apps/lite-cli/dist/stats-command.d.ts.map +1 -1
  25. package/apps/lite-cli/dist/stats-command.js +95 -17
  26. package/apps/lite-cli/dist/stats-command.js.map +1 -1
  27. package/apps/lite-cli/dist/stats-command.test.js +33 -3
  28. package/apps/lite-cli/dist/stats-command.test.js.map +1 -1
  29. package/apps/lite-cli/dist/stats-diagnostics-render.d.ts +21 -0
  30. package/apps/lite-cli/dist/stats-diagnostics-render.d.ts.map +1 -0
  31. package/apps/lite-cli/dist/stats-diagnostics-render.js +245 -0
  32. package/apps/lite-cli/dist/stats-diagnostics-render.js.map +1 -0
  33. package/apps/lite-cli/dist/stats-render.d.ts +11 -3
  34. package/apps/lite-cli/dist/stats-render.d.ts.map +1 -1
  35. package/apps/lite-cli/dist/stats-render.js +344 -79
  36. package/apps/lite-cli/dist/stats-render.js.map +1 -1
  37. package/apps/lite-cli/dist/stats-visuals.d.ts +49 -0
  38. package/apps/lite-cli/dist/stats-visuals.d.ts.map +1 -0
  39. package/apps/lite-cli/dist/stats-visuals.js +333 -0
  40. package/apps/lite-cli/dist/stats-visuals.js.map +1 -0
  41. package/apps/lite-cli/dist/trace-command.d.ts +28 -0
  42. package/apps/lite-cli/dist/trace-command.d.ts.map +1 -0
  43. package/apps/lite-cli/dist/trace-command.js +394 -0
  44. package/apps/lite-cli/dist/trace-command.js.map +1 -0
  45. package/apps/lite-cli/dist/trace-command.test.d.ts +2 -0
  46. package/apps/lite-cli/dist/trace-command.test.d.ts.map +1 -0
  47. package/apps/lite-cli/dist/trace-command.test.js +374 -0
  48. package/apps/lite-cli/dist/trace-command.test.js.map +1 -0
  49. package/apps/lite-cli/dist/usability.test.d.ts +2 -0
  50. package/apps/lite-cli/dist/usability.test.d.ts.map +1 -0
  51. package/apps/lite-cli/dist/usability.test.js +170 -0
  52. package/apps/lite-cli/dist/usability.test.js.map +1 -0
  53. package/apps/lite-cli/dist/version.d.ts +1 -1
  54. package/apps/lite-cli/dist/version.js +1 -1
  55. package/apps/lite-tui/dist/clipboard.d.ts +18 -0
  56. package/apps/lite-tui/dist/clipboard.d.ts.map +1 -0
  57. package/apps/lite-tui/dist/clipboard.js +85 -0
  58. package/apps/lite-tui/dist/clipboard.js.map +1 -0
  59. package/apps/lite-tui/dist/index.d.ts +2 -0
  60. package/apps/lite-tui/dist/index.d.ts.map +1 -1
  61. package/apps/lite-tui/dist/index.js +282 -7
  62. package/apps/lite-tui/dist/index.js.map +1 -1
  63. package/apps/lite-tui/dist/input.d.ts +11 -0
  64. package/apps/lite-tui/dist/input.d.ts.map +1 -1
  65. package/apps/lite-tui/dist/input.js +68 -3
  66. package/apps/lite-tui/dist/input.js.map +1 -1
  67. package/apps/lite-tui/dist/model.d.ts +17 -1
  68. package/apps/lite-tui/dist/model.d.ts.map +1 -1
  69. package/apps/lite-tui/dist/model.js +97 -8
  70. package/apps/lite-tui/dist/model.js.map +1 -1
  71. package/apps/lite-tui/dist/render.d.ts +1 -1
  72. package/apps/lite-tui/dist/render.d.ts.map +1 -1
  73. package/apps/lite-tui/dist/render.js +31 -9
  74. package/apps/lite-tui/dist/render.js.map +1 -1
  75. package/apps/lite-tui/dist/state.d.ts +15 -1
  76. package/apps/lite-tui/dist/state.d.ts.map +1 -1
  77. package/apps/lite-tui/dist/state.js +141 -5
  78. package/apps/lite-tui/dist/state.js.map +1 -1
  79. package/apps/lite-tui/dist/stats-anomalies-render.d.ts +11 -0
  80. package/apps/lite-tui/dist/stats-anomalies-render.d.ts.map +1 -0
  81. package/apps/lite-tui/dist/stats-anomalies-render.js +231 -0
  82. package/apps/lite-tui/dist/stats-anomalies-render.js.map +1 -0
  83. package/apps/lite-tui/dist/stats-dashboard.test.js +183 -2
  84. package/apps/lite-tui/dist/stats-dashboard.test.js.map +1 -1
  85. package/apps/lite-tui/dist/stats-matrix-render.d.ts +9 -0
  86. package/apps/lite-tui/dist/stats-matrix-render.d.ts.map +1 -0
  87. package/apps/lite-tui/dist/stats-matrix-render.js +239 -0
  88. package/apps/lite-tui/dist/stats-matrix-render.js.map +1 -0
  89. package/apps/lite-tui/dist/stats-query.d.ts +4 -3
  90. package/apps/lite-tui/dist/stats-query.d.ts.map +1 -1
  91. package/apps/lite-tui/dist/stats-query.js +40 -3
  92. package/apps/lite-tui/dist/stats-query.js.map +1 -1
  93. package/apps/lite-tui/dist/stats-render.d.ts.map +1 -1
  94. package/apps/lite-tui/dist/stats-render.js +149 -104
  95. package/apps/lite-tui/dist/stats-render.js.map +1 -1
  96. package/apps/lite-tui/dist/stats-state.d.ts +48 -4
  97. package/apps/lite-tui/dist/stats-state.d.ts.map +1 -1
  98. package/apps/lite-tui/dist/stats-state.js +129 -3
  99. package/apps/lite-tui/dist/stats-state.js.map +1 -1
  100. package/apps/lite-tui/dist/stats-trace-render.d.ts +9 -0
  101. package/apps/lite-tui/dist/stats-trace-render.d.ts.map +1 -0
  102. package/apps/lite-tui/dist/stats-trace-render.js +213 -0
  103. package/apps/lite-tui/dist/stats-trace-render.js.map +1 -0
  104. package/apps/lite-tui/dist/stats-visuals.d.ts +29 -0
  105. package/apps/lite-tui/dist/stats-visuals.d.ts.map +1 -0
  106. package/apps/lite-tui/dist/stats-visuals.js +289 -0
  107. package/apps/lite-tui/dist/stats-visuals.js.map +1 -0
  108. package/apps/lite-tui/dist/usability.test.d.ts +2 -0
  109. package/apps/lite-tui/dist/usability.test.d.ts.map +1 -0
  110. package/apps/lite-tui/dist/usability.test.js +269 -0
  111. package/apps/lite-tui/dist/usability.test.js.map +1 -0
  112. package/apps/lite-tui/dist/version.d.ts +1 -1
  113. package/apps/lite-tui/dist/version.js +1 -1
  114. package/docs/guide/for-agents.md +17 -8
  115. package/docs/guide/lite.md +99 -34
  116. package/docs/guide/queries/anomaly-calls.sql +18 -0
  117. package/docs/guide/query.md +9 -4
  118. package/node_modules/@cchistory/canonical/dist/conversation-evidence.d.ts +1 -0
  119. package/node_modules/@cchistory/canonical/dist/conversation-evidence.d.ts.map +1 -1
  120. package/node_modules/@cchistory/canonical/dist/conversation-evidence.js +6 -0
  121. package/node_modules/@cchistory/canonical/dist/conversation-evidence.js.map +1 -1
  122. package/node_modules/@cchistory/canonical/dist/index.d.ts +5 -1
  123. package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
  124. package/node_modules/@cchistory/canonical/dist/index.js +5 -1
  125. package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
  126. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.d.ts +2 -2
  127. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.d.ts.map +1 -1
  128. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.js +4 -4
  129. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.js.map +1 -1
  130. package/node_modules/@cchistory/canonical/dist/query.d.ts +4 -1
  131. package/node_modules/@cchistory/canonical/dist/query.d.ts.map +1 -1
  132. package/node_modules/@cchistory/canonical/dist/query.js +130 -1
  133. package/node_modules/@cchistory/canonical/dist/query.js.map +1 -1
  134. package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -1
  135. package/node_modules/@cchistory/canonical/dist/session-interpreter.js +21 -13
  136. package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -1
  137. package/node_modules/@cchistory/canonical/dist/tool-call-summary.d.ts +32 -0
  138. package/node_modules/@cchistory/canonical/dist/tool-call-summary.d.ts.map +1 -0
  139. package/node_modules/@cchistory/canonical/dist/tool-call-summary.js +499 -0
  140. package/node_modules/@cchistory/canonical/dist/tool-call-summary.js.map +1 -0
  141. package/node_modules/@cchistory/canonical/dist/usage-anomalies.d.ts +27 -0
  142. package/node_modules/@cchistory/canonical/dist/usage-anomalies.d.ts.map +1 -0
  143. package/node_modules/@cchistory/canonical/dist/usage-anomalies.js +383 -0
  144. package/node_modules/@cchistory/canonical/dist/usage-anomalies.js.map +1 -0
  145. package/node_modules/@cchistory/canonical/dist/usage-breakdown.d.ts.map +1 -1
  146. package/node_modules/@cchistory/canonical/dist/usage-breakdown.js +113 -20
  147. package/node_modules/@cchistory/canonical/dist/usage-breakdown.js.map +1 -1
  148. package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.d.ts +41 -0
  149. package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.d.ts.map +1 -0
  150. package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.js +330 -0
  151. package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.js.map +1 -0
  152. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.d.ts +47 -0
  153. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.d.ts.map +1 -0
  154. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.js +424 -0
  155. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.js.map +1 -0
  156. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.test.d.ts +2 -0
  157. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.test.d.ts.map +1 -0
  158. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.test.js +325 -0
  159. package/node_modules/@cchistory/canonical/dist/usage-diagnostics.test.js.map +1 -0
  160. package/node_modules/@cchistory/canonical/dist/usage-pricing.d.ts.map +1 -1
  161. package/node_modules/@cchistory/canonical/dist/usage-pricing.js +21 -2
  162. package/node_modules/@cchistory/canonical/dist/usage-pricing.js.map +1 -1
  163. package/node_modules/@cchistory/canonical/dist/usage-pricing.test.js +112 -0
  164. package/node_modules/@cchistory/canonical/dist/usage-pricing.test.js.map +1 -1
  165. package/node_modules/@cchistory/canonical/dist/usage-time.d.ts +25 -1
  166. package/node_modules/@cchistory/canonical/dist/usage-time.d.ts.map +1 -1
  167. package/node_modules/@cchistory/canonical/dist/usage-time.js +82 -1
  168. package/node_modules/@cchistory/canonical/dist/usage-time.js.map +1 -1
  169. package/node_modules/@cchistory/canonical/dist/usage-tool-patterns.d.ts +14 -0
  170. package/node_modules/@cchistory/canonical/dist/usage-tool-patterns.d.ts.map +1 -0
  171. package/node_modules/@cchistory/canonical/dist/usage-tool-patterns.js +243 -0
  172. package/node_modules/@cchistory/canonical/dist/usage-tool-patterns.js.map +1 -0
  173. package/node_modules/@cchistory/canonical/dist/usage-trace.d.ts +18 -0
  174. package/node_modules/@cchistory/canonical/dist/usage-trace.d.ts.map +1 -0
  175. package/node_modules/@cchistory/canonical/dist/usage-trace.js +405 -0
  176. package/node_modules/@cchistory/canonical/dist/usage-trace.js.map +1 -0
  177. package/node_modules/@cchistory/canonical/dist/usage-trace.test.d.ts +2 -0
  178. package/node_modules/@cchistory/canonical/dist/usage-trace.test.d.ts.map +1 -0
  179. package/node_modules/@cchistory/canonical/dist/usage-trace.test.js +346 -0
  180. package/node_modules/@cchistory/canonical/dist/usage-trace.test.js.map +1 -0
  181. package/node_modules/@cchistory/canonical/dist/usage.d.ts +18 -1
  182. package/node_modules/@cchistory/canonical/dist/usage.d.ts.map +1 -1
  183. package/node_modules/@cchistory/canonical/dist/usage.js +77 -5
  184. package/node_modules/@cchistory/canonical/dist/usage.js.map +1 -1
  185. package/node_modules/@cchistory/canonical/package.json +1 -1
  186. package/node_modules/@cchistory/domain/dist/index.d.ts +18 -1
  187. package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
  188. package/node_modules/@cchistory/domain/dist/index.js +1 -0
  189. package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
  190. package/node_modules/@cchistory/domain/dist/query.d.ts +1 -1
  191. package/node_modules/@cchistory/domain/dist/query.d.ts.map +1 -1
  192. package/node_modules/@cchistory/domain/dist/usage-pricing.d.ts +83 -1
  193. package/node_modules/@cchistory/domain/dist/usage-pricing.d.ts.map +1 -1
  194. package/node_modules/@cchistory/domain/dist/usage-trace.d.ts +245 -0
  195. package/node_modules/@cchistory/domain/dist/usage-trace.d.ts.map +1 -0
  196. package/node_modules/@cchistory/domain/dist/usage-trace.js +8 -0
  197. package/node_modules/@cchistory/domain/dist/usage-trace.js.map +1 -0
  198. package/node_modules/@cchistory/domain/package.json +1 -1
  199. package/node_modules/@cchistory/live-runtime/dist/index.d.ts +12 -4
  200. package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
  201. package/node_modules/@cchistory/live-runtime/dist/index.js +81 -3
  202. package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
  203. package/node_modules/@cchistory/live-runtime/dist/index.test.js +8 -6
  204. package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
  205. package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts.map +1 -1
  206. package/node_modules/@cchistory/live-runtime/dist/sql-query.js +3 -2
  207. package/node_modules/@cchistory/live-runtime/dist/sql-query.js.map +1 -1
  208. package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js +46 -2
  209. package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js.map +1 -1
  210. package/node_modules/@cchistory/live-runtime/package.json +1 -1
  211. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
  212. package/node_modules/@cchistory/source-adapters/dist/core/parser.js +3 -2
  213. package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
  214. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/sqlite.d.ts.map +1 -1
  215. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/sqlite.js +21 -7
  216. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/sqlite.js.map +1 -1
  217. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code/runtime.d.ts.map +1 -1
  218. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code/runtime.js +18 -2
  219. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code/runtime.js.map +1 -1
  220. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/runtime.d.ts.map +1 -1
  221. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/runtime.js +22 -1
  222. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/runtime.js.map +1 -1
  223. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.d.ts.map +1 -1
  224. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js +12 -1
  225. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js.map +1 -1
  226. package/node_modules/@cchistory/source-adapters/package.json +1 -1
  227. package/package.json +5 -5
  228. package/schemas/cchistory-lite-agent-v1.schema.json +2 -1
  229. package/schemas/cchistory-lite-query-result-v2.schema.json +3 -1
  230. package/schemas/cchistory-lite-query-v2.schema.json +41 -1
  231. package/schemas/cchistory-lite-v2.schema.json +1 -1
  232. package/skills/using-cchistory-lite/SKILL.md +26 -4
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Role: Zero-dependency terminal clipboard helper (OSC 52 sequence + best-effort native
3
+ * OS clipboard command fallback) for copying resume commands and Q&A text from the Lite TUI.
4
+ * Excludes TUI state and rendering (owned by state.ts and render.ts).
5
+ */
6
+ export interface ClipboardCopyResult {
7
+ ok: boolean;
8
+ via: "system+osc52" | "osc52" | "system" | "none";
9
+ }
10
+ export interface ClipboardCopyOptions {
11
+ writeOsc52?: (sequence: string) => void;
12
+ platform?: NodeJS.Platform;
13
+ runCommand?: (command: string, args: readonly string[], input: string) => Promise<boolean>;
14
+ }
15
+ /** Build an OSC 52 clipboard escape sequence supported by modern local and SSH terminals. */
16
+ export declare function buildOsc52Sequence(text: string): string;
17
+ export declare function copyTextToClipboard(text: string, options?: ClipboardCopyOptions): Promise<ClipboardCopyResult>;
18
+ //# sourceMappingURL=clipboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,GAAG,EAAE,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;CACnD;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5F;AAED,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGvD;AA2CD,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAyB9B"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Role: Zero-dependency terminal clipboard helper (OSC 52 sequence + best-effort native
3
+ * OS clipboard command fallback) for copying resume commands and Q&A text from the Lite TUI.
4
+ * Excludes TUI state and rendering (owned by state.ts and render.ts).
5
+ */
6
+ import { spawn } from "node:child_process";
7
+ import process from "node:process";
8
+ /** Build an OSC 52 clipboard escape sequence supported by modern local and SSH terminals. */
9
+ export function buildOsc52Sequence(text) {
10
+ const encoded = Buffer.from(text, "utf8").toString("base64");
11
+ return `\x1b]52;c;${encoded}\x07`;
12
+ }
13
+ function candidateClipboardCommands(platform) {
14
+ if (platform === "darwin")
15
+ return [{ cmd: "pbcopy", args: [] }];
16
+ if (platform === "win32")
17
+ return [{ cmd: "clip", args: [] }];
18
+ return [
19
+ { cmd: "wl-copy", args: [] },
20
+ { cmd: "xclip", args: ["-selection", "clipboard"] },
21
+ { cmd: "xsel", args: ["--clipboard", "--input"] },
22
+ ];
23
+ }
24
+ function defaultRunClipboardCommand(command, args, text) {
25
+ return new Promise((resolve) => {
26
+ let settled = false;
27
+ const finish = (ok) => {
28
+ if (settled)
29
+ return;
30
+ settled = true;
31
+ clearTimeout(timer);
32
+ resolve(ok);
33
+ };
34
+ let child;
35
+ try {
36
+ child = spawn(command, [...args], { stdio: ["pipe", "ignore", "ignore"] });
37
+ }
38
+ catch {
39
+ resolve(false);
40
+ return;
41
+ }
42
+ const timer = setTimeout(() => {
43
+ child.kill();
44
+ finish(false);
45
+ }, 1500);
46
+ timer.unref?.();
47
+ child.once("error", () => finish(false));
48
+ child.once("exit", (code) => finish(code === 0));
49
+ try {
50
+ child.stdin?.end(text, "utf8");
51
+ }
52
+ catch {
53
+ finish(false);
54
+ }
55
+ });
56
+ }
57
+ export async function copyTextToClipboard(text, options = {}) {
58
+ let osc52Sent = false;
59
+ if (options.writeOsc52) {
60
+ try {
61
+ options.writeOsc52(buildOsc52Sequence(text));
62
+ osc52Sent = true;
63
+ }
64
+ catch {
65
+ osc52Sent = false;
66
+ }
67
+ }
68
+ const run = options.runCommand ?? defaultRunClipboardCommand;
69
+ const platform = options.platform ?? process.platform;
70
+ let systemOk = false;
71
+ for (const candidate of candidateClipboardCommands(platform)) {
72
+ if (await run(candidate.cmd, candidate.args, text)) {
73
+ systemOk = true;
74
+ break;
75
+ }
76
+ }
77
+ if (systemOk && osc52Sent)
78
+ return { ok: true, via: "system+osc52" };
79
+ if (systemOk)
80
+ return { ok: true, via: "system" };
81
+ if (osc52Sent)
82
+ return { ok: true, via: "osc52" };
83
+ return { ok: false, via: "none" };
84
+ }
85
+ //# sourceMappingURL=clipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,OAAO,MAAM,cAAc,CAAC;AAanC,6FAA6F;AAC7F,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7D,OAAO,aAAa,OAAO,MAAM,CAAC;AACpC,CAAC;AAED,SAAS,0BAA0B,CAAC,QAAyB;IAC3D,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAChE,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,OAAO;QACL,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;QAC5B,EAAE,GAAG,EAAE,OAAO,EAAE,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AAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACpC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { type LiveHistorySnapshot, type ScanLiteHistoryOptions } from "@cchistory/live-runtime";
3
+ import { type ClipboardCopyResult } from "./clipboard.js";
3
4
  export { VERSION } from "./version.js";
4
5
  /** How long a lone `ESC` waits before it stops looking like a cursor sequence. */
5
6
  export declare const ESCAPE_FLUSH_MS = 40;
@@ -17,6 +18,7 @@ export interface LiteTuiIo {
17
18
  rows?: number;
18
19
  now?: () => number;
19
20
  scan?: (options: ScanLiteHistoryOptions) => Promise<LiveHistorySnapshot>;
21
+ copyToClipboard?: (text: string) => Promise<ClipboardCopyResult>;
20
22
  }
21
23
  export declare function runLiteTui(argv: string[], io?: LiteTuiIo): Promise<number>;
22
24
  export declare function renderHelp(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AASA,OAAO,EAML,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AAejC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,kFAAkF;AAClF,eAAO,MAAM,eAAe,KAAK,CAAC;AAalC,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IAC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C;IACzE,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAClE;AAsDD,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,GAAE,SAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CA2E7F;AA0nBD,wBAAgB,UAAU,IAAI,MAAM,CAmDnC"}
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import { realpathSync } from "node:fs";
3
- import { readFile } from "node:fs/promises";
3
+ import { lstat, readFile, realpath, writeFile } from "node:fs/promises";
4
4
  import os from "node:os";
5
5
  import path from "node:path";
6
6
  import process from "node:process";
7
7
  import { pathToFileURL } from "node:url";
8
- import { formatScanGuardWarning, mergeUsagePricingConfigs, parseUsagePricingInput, scanLiteHistory, } from "@cchistory/live-runtime";
8
+ import { buildPricingConfigTemplate, formatScanGuardWarning, mergeUsagePricingConfigs, parseUsagePricingInput, scanLiteHistory, } from "@cchistory/live-runtime";
9
+ import { copyTextToClipboard } from "./clipboard.js";
9
10
  import { configureColorPolicy } from "./colors.js";
10
11
  import { KeyDecoder } from "./keys.js";
11
12
  import { resolveLiteInputEffect } from "./input.js";
12
13
  import { LiteBrowserModel } from "./model.js";
13
14
  import { BANNER_TITLE, DEFAULT_HEIGHT, DEFAULT_WIDTH, renderLiteFrame } from "./render.js";
14
- import { createLiteBrowserState, getSelectedTurn, reduceLiteBrowserState, } from "./state.js";
15
+ import { createLiteBrowserState, getSelectedSession, getSelectedTurn, reduceLiteBrowserState, } from "./state.js";
15
16
  import { VERSION } from "./version.js";
16
17
  export { VERSION } from "./version.js";
17
18
  /** How long a lone `ESC` waits before it stops looking like a cursor sequence. */
@@ -61,7 +62,7 @@ async function loadTuiPricingConfig(pricingFiles, cwd, homeDir) {
61
62
  export async function runLiteTui(argv, io = defaultIo()) {
62
63
  let parsed;
63
64
  try {
64
- parsed = parseArgs(argv, io.cwd);
65
+ parsed = parseArgs(argv, io.cwd, io.homeDir);
65
66
  }
66
67
  catch (error) {
67
68
  io.stderr(`${errorMessage(error)}\n`);
@@ -86,6 +87,7 @@ export async function runLiteTui(argv, io = defaultIo()) {
86
87
  hostname: io.hostname,
87
88
  sourceRoots: parsed.sourceRoots,
88
89
  sourceRefs: parsed.sourceRefs,
90
+ directoryScope: parsed.directoryScope,
89
91
  safeMode: parsed.safeMode,
90
92
  limitFiles: parsed.limitFiles,
91
93
  contextMode: "none",
@@ -106,6 +108,7 @@ export async function runLiteTui(argv, io = defaultIo()) {
106
108
  includeSessionRefs,
107
109
  pricingConfig,
108
110
  quotaLimitUsd: parsed.quotaUsd,
111
+ directoryScope: parsed.directoryScope,
109
112
  });
110
113
  const state = applyEntryPoints(model, createLiteBrowserState(model), parsed);
111
114
  if (!io.isInteractiveTerminal) {
@@ -121,6 +124,7 @@ export async function runLiteTui(argv, io = defaultIo()) {
121
124
  includeSessionRefs,
122
125
  pricingConfig,
123
126
  quotaLimitUsd: parsed.quotaUsd,
127
+ directoryScope: parsed.directoryScope,
124
128
  });
125
129
  }
126
130
  catch (error) {
@@ -139,6 +143,7 @@ async function runInteractive(options) {
139
143
  let previousFrame = "";
140
144
  let interrupted = false;
141
145
  let finished = false;
146
+ let exitPrintLine;
142
147
  let resolveExit;
143
148
  const exited = new Promise((resolve) => {
144
149
  resolveExit = resolve;
@@ -204,6 +209,7 @@ async function runInteractive(options) {
204
209
  includeSessionRefs: options.includeSessionRefs,
205
210
  pricingConfig: options.pricingConfig,
206
211
  quotaLimitUsd: options.quotaLimitUsd,
212
+ directoryScope: options.directoryScope,
207
213
  });
208
214
  state = createLiteBrowserState(model);
209
215
  dispatch({
@@ -284,12 +290,162 @@ async function runInteractive(options) {
284
290
  };
285
291
  const decoder = new KeyDecoder();
286
292
  let escapeTimer;
293
+ const exportPricing = async (destination) => {
294
+ dispatch({ type: "stats-edit-cancel" });
295
+ const home = io.homeDir ?? os.homedir();
296
+ const expanded = destination === "~"
297
+ ? home
298
+ : destination.startsWith("~/") || destination.startsWith("~\\")
299
+ ? path.join(home, destination.slice(2))
300
+ : destination;
301
+ const resolved = path.resolve(io.cwd, expanded);
302
+ try {
303
+ await assertSafeTuiExportDestination(resolved, model.snapshot, home);
304
+ const effectiveQuota = state.stats.quotaUsdOverride ?? options.quotaLimitUsd;
305
+ const merged = mergeUsagePricingConfigs(options.pricingConfig, {
306
+ schema: "cchistory-lite-pricing/v1",
307
+ timezone: model.defaultTimezone,
308
+ aliases: { ...state.stats.customAliases },
309
+ multipliers: { ...state.stats.multiplierOverrides },
310
+ quota: {
311
+ week_mode: state.stats.weekMode,
312
+ ...(effectiveQuota !== undefined ? { custom_usd: effectiveQuota } : {}),
313
+ },
314
+ });
315
+ const breakdown = model.getUsageBreakdown({
316
+ timePreset: state.stats.timePreset,
317
+ timeBucket: state.stats.timeBucket,
318
+ weekMode: state.stats.weekMode,
319
+ customAliases: state.stats.customAliases,
320
+ multiplierOverrides: state.stats.multiplierOverrides,
321
+ quotaUsdOverride: state.stats.quotaUsdOverride,
322
+ });
323
+ const template = buildPricingConfigTemplate(breakdown.model_resolutions, merged, model.defaultTimezone);
324
+ await writeFile(resolved, `${JSON.stringify(template, null, 2)}\n`, "utf8");
325
+ dispatch({
326
+ type: "set-status",
327
+ status: { kind: "info", text: `Exported pricing config to ${resolved} (reuse via --pricing)` },
328
+ });
329
+ }
330
+ catch (error) {
331
+ dispatch({
332
+ type: "set-status",
333
+ status: { kind: "error", text: `Pricing export failed: ${errorMessage(error)}` },
334
+ });
335
+ }
336
+ };
337
+ const resolveSelectedSessionForAction = () => {
338
+ const turn = getSelectedTurn(model, state);
339
+ if (turn?.session)
340
+ return turn.session;
341
+ if (turn)
342
+ return model.getSession(turn.turn.session_id);
343
+ return getSelectedSession(model, state)?.session;
344
+ };
345
+ const performCopy = async (text, label) => {
346
+ const result = io.copyToClipboard
347
+ ? await io.copyToClipboard(text)
348
+ : await copyTextToClipboard(text, {
349
+ writeOsc52: io.isInteractiveTerminal ? (seq) => io.stdout(seq) : undefined,
350
+ });
351
+ if (result.ok) {
352
+ dispatch({ type: "set-status", status: { kind: "info", text: `Copied ${label} (${result.via}).` } });
353
+ }
354
+ else {
355
+ dispatch({ type: "set-status", status: { kind: "error", text: `Clipboard unavailable; press R to print resume on exit.` } });
356
+ }
357
+ };
358
+ const copyResume = async () => {
359
+ const session = resolveSelectedSessionForAction();
360
+ if (!session) {
361
+ dispatch({ type: "set-status", status: { kind: "error", text: "No session selected to copy." } });
362
+ return;
363
+ }
364
+ const text = session.resume_command ?? session.id;
365
+ const label = session.resume_command ? "resume command" : "session ID";
366
+ await performCopy(text, label);
367
+ };
368
+ const copyContent = async () => {
369
+ const entry = getSelectedTurn(model, state);
370
+ if (!entry) {
371
+ dispatch({ type: "set-status", status: { kind: "error", text: "No turn selected to copy." } });
372
+ return;
373
+ }
374
+ const parts = [`User:\n${entry.turn.canonical_text.trim()}`];
375
+ const ctx = model.getTurnContext(entry.turn.id);
376
+ if (ctx && ctx.assistant_replies.length > 0) {
377
+ for (const reply of ctx.assistant_replies) {
378
+ parts.push(`Assistant (${reply.model}):\n${(reply.canonical_text || reply.content || reply.content_preview).trim()}`);
379
+ }
380
+ await performCopy(parts.join("\n\n"), "turn Q&A");
381
+ }
382
+ else {
383
+ await performCopy(parts.join("\n\n"), "prompt (press Enter on Detail first to include replies)");
384
+ }
385
+ };
386
+ const toggleSearchScope = async () => {
387
+ if (state.searchScope === "conversation") {
388
+ dispatch({ type: "set-search-scope", scope: "prompts" });
389
+ dispatch({ type: "set-status", status: { kind: "info", text: "Search scope: titles & prompts." } });
390
+ return;
391
+ }
392
+ if (model.hasConversationEvidence) {
393
+ dispatch({ type: "set-search-scope", scope: "conversation" });
394
+ dispatch({ type: "set-status", status: { kind: "info", text: "Search scope: prompts + assistant replies." } });
395
+ return;
396
+ }
397
+ if (busy)
398
+ return;
399
+ busy = true;
400
+ dispatch({
401
+ type: "set-status",
402
+ status: { kind: "busy", text: "Loading assistant replies for full-conversation search…" },
403
+ });
404
+ try {
405
+ const replacement = await scan({
406
+ ...scanOptions,
407
+ contextMode: "none",
408
+ retainConversationEvidence: true,
409
+ onProgress: undefined,
410
+ });
411
+ model = new LiteBrowserModel(replacement, {
412
+ includeSessionRefs: options.includeSessionRefs,
413
+ pricingConfig: options.pricingConfig,
414
+ quotaLimitUsd: options.quotaLimitUsd,
415
+ directoryScope: options.directoryScope,
416
+ });
417
+ state = reduceLiteBrowserState(model, state, { type: "set-search-scope", scope: "conversation" });
418
+ dispatch({
419
+ type: "set-status",
420
+ status: { kind: "info", text: "Search scope: prompts + assistant replies." },
421
+ });
422
+ }
423
+ catch (error) {
424
+ dispatch({
425
+ type: "set-status",
426
+ status: { kind: "error", text: `Reply search load failed: ${errorMessage(error)}` },
427
+ });
428
+ }
429
+ finally {
430
+ busy = false;
431
+ }
432
+ };
287
433
  const handleKey = (key) => {
288
434
  const effect = resolveLiteInputEffect(state, key);
289
435
  if (effect.type === "exit") {
290
436
  finish();
291
437
  return;
292
438
  }
439
+ if (effect.type === "exit-print-resume") {
440
+ const session = resolveSelectedSessionForAction();
441
+ if (!session) {
442
+ dispatch({ type: "set-status", status: { kind: "error", text: "No session selected to resume." } });
443
+ return;
444
+ }
445
+ exitPrintLine = session.resume_command ?? session.id;
446
+ finish();
447
+ return;
448
+ }
293
449
  if (effect.type === "action") {
294
450
  dispatch(effect.action);
295
451
  return;
@@ -300,6 +456,22 @@ async function runInteractive(options) {
300
456
  }
301
457
  if (effect.type === "load-context") {
302
458
  void loadContext();
459
+ return;
460
+ }
461
+ if (effect.type === "export-pricing") {
462
+ void exportPricing(effect.destination);
463
+ return;
464
+ }
465
+ if (effect.type === "copy-resume") {
466
+ void copyResume();
467
+ return;
468
+ }
469
+ if (effect.type === "copy-content") {
470
+ void copyContent();
471
+ return;
472
+ }
473
+ if (effect.type === "toggle-search-scope") {
474
+ void toggleSearchScope();
303
475
  }
304
476
  };
305
477
  const onData = (chunk) => {
@@ -365,7 +537,12 @@ async function runInteractive(options) {
365
537
  }
366
538
  if (interrupted)
367
539
  io.stdout("Interrupted; releasing snapshot.\n");
368
- io.stdout("CC History Lite snapshot released.\n");
540
+ if (exitPrintLine) {
541
+ io.stdout(`${exitPrintLine}\n`);
542
+ }
543
+ else {
544
+ io.stdout("CC History Lite snapshot released.\n");
545
+ }
369
546
  return 0;
370
547
  }
371
548
  // ── Entry points and helpers ──
@@ -379,6 +556,9 @@ function applyEntryPoints(model, initial, parsed) {
379
556
  state = reduceLiteBrowserState(model, state, { type: "open-turn-ref", ref: parsed.turnRef });
380
557
  if (parsed.searchQuery)
381
558
  state = reduceLiteBrowserState(model, state, { type: "open-search", query: parsed.searchQuery });
559
+ if (parsed.openStats || parsed.statsSince) {
560
+ state = reduceLiteBrowserState(model, state, { type: "open-stats", timePreset: parsed.statsSince });
561
+ }
382
562
  return state;
383
563
  }
384
564
  function resolveDimensions(io) {
@@ -406,12 +586,14 @@ function formatProgress(event) {
406
586
  }
407
587
  // ── Argument parsing ──
408
588
  const REF_FLAGS = new Set(["project", "session", "turn", "search"]);
409
- function parseArgs(argv, cwd) {
589
+ const STATS_PRESET_SET = new Set(["all", "today", "24h", "7d", "30d", "week", "month"]);
590
+ function parseArgs(argv, cwd, homeDir) {
410
591
  const parsed = {
411
592
  sourceRoots: [],
412
593
  sourceRefs: [],
413
594
  pricingFiles: [],
414
595
  safeMode: false,
596
+ openStats: false,
415
597
  help: false,
416
598
  version: false,
417
599
  };
@@ -421,6 +603,34 @@ function parseArgs(argv, cwd) {
421
603
  parsed.safeMode = true;
422
604
  continue;
423
605
  }
606
+ if (argument === "--stats") {
607
+ parsed.openStats = true;
608
+ continue;
609
+ }
610
+ if (argument === "--no-dir") {
611
+ parsed.directoryScope = undefined;
612
+ continue;
613
+ }
614
+ if (argument === "--dir" || argument.startsWith("--dir=")) {
615
+ const raw = readOptionValue(argv, index, argument, "dir");
616
+ if (argument === "--dir")
617
+ index += 1;
618
+ const home = homeDir ?? os.homedir();
619
+ const expanded = raw === "~" ? home : raw.startsWith("~/") || raw.startsWith("~\\") ? path.join(home, raw.slice(2)) : raw;
620
+ parsed.directoryScope = path.resolve(cwd, expanded);
621
+ continue;
622
+ }
623
+ if (argument === "--since" || argument.startsWith("--since=")) {
624
+ const raw = readOptionValue(argv, index, argument, "since").trim().toLowerCase();
625
+ if (argument === "--since")
626
+ index += 1;
627
+ if (!STATS_PRESET_SET.has(raw)) {
628
+ throw new TuiUsageError(`--since must be one of all, today, 24h, 7d, 30d, week, month; received ${JSON.stringify(raw)}.`);
629
+ }
630
+ parsed.statsSince = raw;
631
+ parsed.openStats = true;
632
+ continue;
633
+ }
424
634
  if (argument === "--help" || argument === "-h") {
425
635
  parsed.help = true;
426
636
  continue;
@@ -542,12 +752,16 @@ Usage:
542
752
  Source options:
543
753
  --source-root <slot-or-id>=<path> Override one registered adapter root; repeatable
544
754
  --source <slot-or-id> Scan only the named adapters; repeatable
755
+ --dir <path> Scope initial scan and browser to one working directory
756
+ --no-dir Disable directory scoping (default: whole machine)
545
757
  --limit-files <n> Limit source files scanned per adapter
546
758
  --safe Enable adapter safe mode
547
759
  --pricing <file> Local JSON pricing/multiplier/quota file; repeatable
548
760
  --quota <usd> Initial period quota limit in USD for stats
549
761
 
550
762
  Entry points (at most one of --project/--session/--turn):
763
+ --stats Open directly on the Statistics dashboard
764
+ --since <preset> Open Statistics focused on all|today|24h|7d|30d|week|month
551
765
  --project <ref> Open focused on a project's turns
552
766
  --session <ref> Open at the first turn of a session
553
767
  --turn <ref> Open at a turn's detail
@@ -565,7 +779,7 @@ Keys:
565
779
  p / S browse by project / by session
566
780
  t / d focus turns / detail pane
567
781
  / search i stats s sources ? help
568
- Stats (i): Tab/1-4 quadrant · Space filter · v matrix · m calibrate · t/b window · $ quota
782
+ Stats (i): Tab/1-4 quadrant · Space filter · S top sessions (Enter open) · v matrix · m calibrate · E export · t/b window · $ quota
569
783
  r refresh the snapshot from disk
570
784
  q quit and release the snapshot
571
785
 
@@ -590,6 +804,67 @@ function defaultIo() {
590
804
  function errorMessage(error) {
591
805
  return error instanceof Error ? error.message : String(error);
592
806
  }
807
+ async function assertSafeTuiExportDestination(outputPath, snapshot, homeDir) {
808
+ assertNotFullStorePath(outputPath);
809
+ try {
810
+ const info = await lstat(outputPath);
811
+ if (info.isSymbolicLink()) {
812
+ throw new TuiUsageError("Pricing export destination cannot be a symbolic link.");
813
+ }
814
+ }
815
+ catch (error) {
816
+ if (!isMissingPathError(error))
817
+ throw error;
818
+ }
819
+ const resolvedOutput = await resolvePathForContainment(outputPath);
820
+ assertNotFullStorePath(resolvedOutput);
821
+ const fullStoreRoot = await resolvePathForContainment(path.resolve(homeDir, ".cchistory"));
822
+ if (isPathWithin(fullStoreRoot, resolvedOutput)) {
823
+ throw new TuiUsageError("Pricing export cannot write into a Full store path.");
824
+ }
825
+ for (const source of snapshot.listSources()) {
826
+ const sourceRoot = await resolvePathForContainment(path.resolve(source.base_dir));
827
+ if (isPathWithin(sourceRoot, resolvedOutput)) {
828
+ throw new TuiUsageError("Pricing export must be written outside native source roots.");
829
+ }
830
+ }
831
+ }
832
+ function assertNotFullStorePath(targetPath) {
833
+ const normalized = targetPath.replace(/\\/gu, "/").toLowerCase();
834
+ const segments = normalized.split("/").filter(Boolean);
835
+ if (path.basename(normalized) === "cchistory.sqlite" || segments.includes(".cchistory")) {
836
+ throw new TuiUsageError("Pricing export cannot write into a Full store path.");
837
+ }
838
+ }
839
+ async function resolvePathForContainment(targetPath) {
840
+ let current = path.resolve(targetPath);
841
+ const missing = [];
842
+ while (true) {
843
+ try {
844
+ const resolved = await realpath(current);
845
+ return path.resolve(resolved, ...missing);
846
+ }
847
+ catch (error) {
848
+ if (!isMissingPathError(error))
849
+ throw error;
850
+ const parent = path.dirname(current);
851
+ if (parent === current)
852
+ return path.resolve(targetPath);
853
+ missing.unshift(path.basename(current));
854
+ current = parent;
855
+ }
856
+ }
857
+ }
858
+ function isPathWithin(parentPath, childPath) {
859
+ const relative = path.relative(parentPath, childPath);
860
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
861
+ }
862
+ function isMissingPathError(error) {
863
+ return Boolean(error &&
864
+ typeof error === "object" &&
865
+ "code" in error &&
866
+ (error.code === "ENOENT" || error.code === "ENOTDIR"));
867
+ }
593
868
  function isDirectEntry() {
594
869
  const entry = process.argv[1];
595
870
  if (!entry)