cognova 0.1.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.
Files changed (205) hide show
  1. package/.env.example +58 -0
  2. package/Claude/CLAUDE.md +92 -0
  3. package/Claude/hooks/lib/__init__.py +1 -0
  4. package/Claude/hooks/lib/hook_client.py +207 -0
  5. package/Claude/hooks/log-event.py +97 -0
  6. package/Claude/hooks/pre-compact.py +46 -0
  7. package/Claude/hooks/session-end.py +26 -0
  8. package/Claude/hooks/session-start.py +35 -0
  9. package/Claude/hooks/stop-extract.py +40 -0
  10. package/Claude/rules/frontmatter.md +54 -0
  11. package/Claude/rules/markdown.md +43 -0
  12. package/Claude/rules/note-organization.md +33 -0
  13. package/Claude/settings.json +54 -0
  14. package/Claude/skills/README.md +136 -0
  15. package/Claude/skills/_lib/__init__.py +1 -0
  16. package/Claude/skills/_lib/api.py +164 -0
  17. package/Claude/skills/_lib/output.py +95 -0
  18. package/Claude/skills/environment/SKILL.md +73 -0
  19. package/Claude/skills/environment/environment.py +239 -0
  20. package/Claude/skills/memory/SKILL.md +153 -0
  21. package/Claude/skills/memory/memory.py +270 -0
  22. package/Claude/skills/project/SKILL.md +105 -0
  23. package/Claude/skills/project/project.py +203 -0
  24. package/Claude/skills/skill-creator/SKILL.md +261 -0
  25. package/Claude/skills/task/SKILL.md +135 -0
  26. package/Claude/skills/task/task.py +310 -0
  27. package/LICENSE +21 -0
  28. package/README.md +176 -0
  29. package/app/app.config.ts +8 -0
  30. package/app/app.vue +39 -0
  31. package/app/assets/css/main.css +10 -0
  32. package/app/components/AppLogo.vue +40 -0
  33. package/app/components/AssistantPanel.client.vue +518 -0
  34. package/app/components/ConfirmModal.vue +84 -0
  35. package/app/components/TemplateMenu.vue +49 -0
  36. package/app/components/agents/AgentActivityChart.client.vue +105 -0
  37. package/app/components/agents/AgentActivityChart.server.vue +25 -0
  38. package/app/components/agents/AgentForm.vue +304 -0
  39. package/app/components/agents/AgentRunModal.vue +154 -0
  40. package/app/components/agents/AgentStatsCards.vue +98 -0
  41. package/app/components/chat/ChatInput.vue +85 -0
  42. package/app/components/chat/ConversationList.vue +78 -0
  43. package/app/components/chat/MessageBubble.vue +81 -0
  44. package/app/components/chat/StreamingMessage.vue +36 -0
  45. package/app/components/chat/ToolCallBlock.vue +77 -0
  46. package/app/components/editor/CodeEditor.client.vue +212 -0
  47. package/app/components/editor/CodeEditorFallback.vue +12 -0
  48. package/app/components/editor/DocumentEditor.vue +326 -0
  49. package/app/components/editor/DocumentMetadata.vue +140 -0
  50. package/app/components/editor/MarkdownEditor.vue +146 -0
  51. package/app/components/files/FileTree.vue +436 -0
  52. package/app/components/hooks/HookActivityChart.client.vue +117 -0
  53. package/app/components/hooks/HookActivityChart.server.vue +25 -0
  54. package/app/components/hooks/HookStatsCards.vue +63 -0
  55. package/app/components/hooks/RecentEventsTable.vue +123 -0
  56. package/app/components/hooks/ToolBreakdownTable.vue +72 -0
  57. package/app/components/search/DashboardSearch.vue +122 -0
  58. package/app/components/tasks/ProjectSelect.vue +35 -0
  59. package/app/components/tasks/TaskCard.vue +182 -0
  60. package/app/components/tasks/TaskDetail.vue +160 -0
  61. package/app/components/tasks/TaskForm.vue +280 -0
  62. package/app/components/tasks/TaskList.vue +69 -0
  63. package/app/components/view/ViewToc.vue +85 -0
  64. package/app/composables/useAgents.ts +153 -0
  65. package/app/composables/useAuth.ts +73 -0
  66. package/app/composables/useChat.ts +298 -0
  67. package/app/composables/useDocument.ts +141 -0
  68. package/app/composables/useEditor.ts +100 -0
  69. package/app/composables/useFileTree.ts +220 -0
  70. package/app/composables/useHookEvents.ts +68 -0
  71. package/app/composables/useMemories.ts +83 -0
  72. package/app/composables/useNotificationBus.ts +154 -0
  73. package/app/composables/usePreferences.ts +131 -0
  74. package/app/composables/useProjects.ts +97 -0
  75. package/app/composables/useSearch.ts +52 -0
  76. package/app/composables/useTasks.ts +201 -0
  77. package/app/composables/useTerminal.ts +135 -0
  78. package/app/layouts/auth.vue +20 -0
  79. package/app/layouts/dashboard.vue +186 -0
  80. package/app/layouts/view.vue +60 -0
  81. package/app/middleware/auth.ts +9 -0
  82. package/app/pages/agents/[id].vue +602 -0
  83. package/app/pages/agents/index.vue +412 -0
  84. package/app/pages/chat.vue +146 -0
  85. package/app/pages/dashboard.vue +80 -0
  86. package/app/pages/docs.vue +131 -0
  87. package/app/pages/hooks.vue +163 -0
  88. package/app/pages/index.vue +249 -0
  89. package/app/pages/login.vue +60 -0
  90. package/app/pages/memories.vue +282 -0
  91. package/app/pages/settings.vue +625 -0
  92. package/app/pages/tasks.vue +312 -0
  93. package/app/pages/view/[uuid].vue +376 -0
  94. package/dist/cli/index.js +2711 -0
  95. package/drizzle.config.ts +10 -0
  96. package/nuxt.config.ts +98 -0
  97. package/package.json +107 -0
  98. package/server/api/agents/[id]/cancel.post.ts +27 -0
  99. package/server/api/agents/[id]/run.post.ts +34 -0
  100. package/server/api/agents/[id]/runs.get.ts +45 -0
  101. package/server/api/agents/[id]/stats.get.ts +94 -0
  102. package/server/api/agents/[id].delete.ts +29 -0
  103. package/server/api/agents/[id].get.ts +25 -0
  104. package/server/api/agents/[id].patch.ts +55 -0
  105. package/server/api/agents/index.get.ts +15 -0
  106. package/server/api/agents/index.post.ts +48 -0
  107. package/server/api/agents/stats.get.ts +86 -0
  108. package/server/api/auth/[...all].ts +5 -0
  109. package/server/api/conversations/[id].delete.ts +16 -0
  110. package/server/api/conversations/[id].get.ts +34 -0
  111. package/server/api/conversations/index.get.ts +17 -0
  112. package/server/api/documents/[id]/index.delete.ts +47 -0
  113. package/server/api/documents/[id]/index.put.ts +102 -0
  114. package/server/api/documents/[id]/public.get.ts +60 -0
  115. package/server/api/documents/[id]/restore.post.ts +65 -0
  116. package/server/api/documents/by-path.post.ts +168 -0
  117. package/server/api/documents/index.get.ts +48 -0
  118. package/server/api/fs/delete.post.ts +41 -0
  119. package/server/api/fs/list.get.ts +99 -0
  120. package/server/api/fs/mkdir.post.ts +44 -0
  121. package/server/api/fs/move.post.ts +68 -0
  122. package/server/api/fs/read.post.ts +48 -0
  123. package/server/api/fs/rename.post.ts +55 -0
  124. package/server/api/fs/write.post.ts +51 -0
  125. package/server/api/health.get.ts +40 -0
  126. package/server/api/home.get.ts +26 -0
  127. package/server/api/hooks/events/index.get.ts +56 -0
  128. package/server/api/hooks/events/index.post.ts +36 -0
  129. package/server/api/hooks/stats.get.ts +99 -0
  130. package/server/api/memory/[id].delete.ts +26 -0
  131. package/server/api/memory/context.get.ts +83 -0
  132. package/server/api/memory/extract.post.ts +42 -0
  133. package/server/api/memory/search.get.ts +70 -0
  134. package/server/api/memory/store.post.ts +31 -0
  135. package/server/api/projects/[id]/index.delete.ts +40 -0
  136. package/server/api/projects/[id]/index.get.ts +25 -0
  137. package/server/api/projects/[id]/index.put.ts +50 -0
  138. package/server/api/projects/index.get.ts +20 -0
  139. package/server/api/projects/index.post.ts +34 -0
  140. package/server/api/secrets/[key].delete.ts +31 -0
  141. package/server/api/secrets/[key].get.ts +30 -0
  142. package/server/api/secrets/[key].put.ts +52 -0
  143. package/server/api/secrets/index.get.ts +20 -0
  144. package/server/api/secrets/index.post.ts +58 -0
  145. package/server/api/tasks/[id]/index.delete.ts +46 -0
  146. package/server/api/tasks/[id]/index.get.ts +24 -0
  147. package/server/api/tasks/[id]/index.put.ts +70 -0
  148. package/server/api/tasks/[id]/restore.post.ts +49 -0
  149. package/server/api/tasks/index.get.ts +53 -0
  150. package/server/api/tasks/index.post.ts +47 -0
  151. package/server/api/tasks/tags.get.ts +21 -0
  152. package/server/api/user/email.patch.ts +56 -0
  153. package/server/db/index.ts +76 -0
  154. package/server/db/migrate.ts +41 -0
  155. package/server/db/schema.ts +345 -0
  156. package/server/db/seed.ts +46 -0
  157. package/server/db/types.ts +28 -0
  158. package/server/drizzle/migrations/0000_brown_george_stacy.sql +34 -0
  159. package/server/drizzle/migrations/0001_stormy_pyro.sql +16 -0
  160. package/server/drizzle/migrations/0002_clean_colossus.sql +50 -0
  161. package/server/drizzle/migrations/0003_fine_joystick.sql +12 -0
  162. package/server/drizzle/migrations/0004_tan_groot.sql +26 -0
  163. package/server/drizzle/migrations/0005_cloudy_lilith.sql +33 -0
  164. package/server/drizzle/migrations/0006_ordinary_retro_girl.sql +13 -0
  165. package/server/drizzle/migrations/0007_flowery_venus.sql +15 -0
  166. package/server/drizzle/migrations/0008_talented_zombie.sql +13 -0
  167. package/server/drizzle/migrations/0009_gray_shen.sql +15 -0
  168. package/server/drizzle/migrations/meta/0000_snapshot.json +230 -0
  169. package/server/drizzle/migrations/meta/0001_snapshot.json +306 -0
  170. package/server/drizzle/migrations/meta/0002_snapshot.json +615 -0
  171. package/server/drizzle/migrations/meta/0003_snapshot.json +730 -0
  172. package/server/drizzle/migrations/meta/0004_snapshot.json +916 -0
  173. package/server/drizzle/migrations/meta/0005_snapshot.json +1127 -0
  174. package/server/drizzle/migrations/meta/0006_snapshot.json +1213 -0
  175. package/server/drizzle/migrations/meta/0007_snapshot.json +1307 -0
  176. package/server/drizzle/migrations/meta/0008_snapshot.json +1390 -0
  177. package/server/drizzle/migrations/meta/0009_snapshot.json +1487 -0
  178. package/server/drizzle/migrations/meta/_journal.json +76 -0
  179. package/server/middleware/auth.ts +79 -0
  180. package/server/plugins/00.env-validate.ts +38 -0
  181. package/server/plugins/01.api-token.ts +31 -0
  182. package/server/plugins/02.database.ts +54 -0
  183. package/server/plugins/03.file-watcher.ts +65 -0
  184. package/server/plugins/04.cron-agents.ts +26 -0
  185. package/server/routes/_ws/chat.ts +252 -0
  186. package/server/routes/notifications.ts +47 -0
  187. package/server/routes/terminal.ts +98 -0
  188. package/server/services/agent-executor.ts +218 -0
  189. package/server/services/cron-scheduler.ts +78 -0
  190. package/server/services/memory-extractor.ts +120 -0
  191. package/server/utils/agent-cleanup.ts +91 -0
  192. package/server/utils/agent-registry.ts +95 -0
  193. package/server/utils/auth.ts +33 -0
  194. package/server/utils/chat-session-manager.ts +59 -0
  195. package/server/utils/crypto.ts +40 -0
  196. package/server/utils/db-guard.ts +12 -0
  197. package/server/utils/db-state.ts +63 -0
  198. package/server/utils/document-sync.ts +207 -0
  199. package/server/utils/frontmatter.ts +84 -0
  200. package/server/utils/notification-bus.ts +60 -0
  201. package/server/utils/path-validator.ts +55 -0
  202. package/server/utils/pty-manager.ts +130 -0
  203. package/shared/types/index.ts +604 -0
  204. package/shared/utils/language-detection.ts +87 -0
  205. package/tsconfig.json +10 -0
@@ -0,0 +1,2711 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+
28
+ // ../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
29
+ var require_picocolors = __commonJS({
30
+ "../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
31
+ "use strict";
32
+ var p = process || {};
33
+ var argv = p.argv || [];
34
+ var env = p.env || {};
35
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
36
+ var formatter = (open, close, replace = open) => (input) => {
37
+ let string = "" + input, index = string.indexOf(close, open.length);
38
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
39
+ };
40
+ var replaceClose = (string, close, replace, index) => {
41
+ let result = "", cursor = 0;
42
+ do {
43
+ result += string.substring(cursor, index) + replace;
44
+ cursor = index + close.length;
45
+ index = string.indexOf(close, cursor);
46
+ } while (~index);
47
+ return result + string.substring(cursor);
48
+ };
49
+ var createColors = (enabled = isColorSupported) => {
50
+ let f = enabled ? formatter : () => String;
51
+ return {
52
+ isColorSupported: enabled,
53
+ reset: f("\x1B[0m", "\x1B[0m"),
54
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
55
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
56
+ italic: f("\x1B[3m", "\x1B[23m"),
57
+ underline: f("\x1B[4m", "\x1B[24m"),
58
+ inverse: f("\x1B[7m", "\x1B[27m"),
59
+ hidden: f("\x1B[8m", "\x1B[28m"),
60
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
61
+ black: f("\x1B[30m", "\x1B[39m"),
62
+ red: f("\x1B[31m", "\x1B[39m"),
63
+ green: f("\x1B[32m", "\x1B[39m"),
64
+ yellow: f("\x1B[33m", "\x1B[39m"),
65
+ blue: f("\x1B[34m", "\x1B[39m"),
66
+ magenta: f("\x1B[35m", "\x1B[39m"),
67
+ cyan: f("\x1B[36m", "\x1B[39m"),
68
+ white: f("\x1B[37m", "\x1B[39m"),
69
+ gray: f("\x1B[90m", "\x1B[39m"),
70
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
71
+ bgRed: f("\x1B[41m", "\x1B[49m"),
72
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
73
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
74
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
75
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
76
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
77
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
78
+ blackBright: f("\x1B[90m", "\x1B[39m"),
79
+ redBright: f("\x1B[91m", "\x1B[39m"),
80
+ greenBright: f("\x1B[92m", "\x1B[39m"),
81
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
82
+ blueBright: f("\x1B[94m", "\x1B[39m"),
83
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
84
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
85
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
86
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
87
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
88
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
89
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
90
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
91
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
92
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
93
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
94
+ };
95
+ };
96
+ module.exports = createColors();
97
+ module.exports.createColors = createColors;
98
+ }
99
+ });
100
+
101
+ // ../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
102
+ var require_src = __commonJS({
103
+ "../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module) {
104
+ "use strict";
105
+ var ESC = "\x1B";
106
+ var CSI = `${ESC}[`;
107
+ var beep = "\x07";
108
+ var cursor = {
109
+ to(x3, y2) {
110
+ if (!y2) return `${CSI}${x3 + 1}G`;
111
+ return `${CSI}${y2 + 1};${x3 + 1}H`;
112
+ },
113
+ move(x3, y2) {
114
+ let ret = "";
115
+ if (x3 < 0) ret += `${CSI}${-x3}D`;
116
+ else if (x3 > 0) ret += `${CSI}${x3}C`;
117
+ if (y2 < 0) ret += `${CSI}${-y2}A`;
118
+ else if (y2 > 0) ret += `${CSI}${y2}B`;
119
+ return ret;
120
+ },
121
+ up: (count = 1) => `${CSI}${count}A`,
122
+ down: (count = 1) => `${CSI}${count}B`,
123
+ forward: (count = 1) => `${CSI}${count}C`,
124
+ backward: (count = 1) => `${CSI}${count}D`,
125
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
126
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
127
+ left: `${CSI}G`,
128
+ hide: `${CSI}?25l`,
129
+ show: `${CSI}?25h`,
130
+ save: `${ESC}7`,
131
+ restore: `${ESC}8`
132
+ };
133
+ var scroll = {
134
+ up: (count = 1) => `${CSI}S`.repeat(count),
135
+ down: (count = 1) => `${CSI}T`.repeat(count)
136
+ };
137
+ var erase = {
138
+ screen: `${CSI}2J`,
139
+ up: (count = 1) => `${CSI}1J`.repeat(count),
140
+ down: (count = 1) => `${CSI}J`.repeat(count),
141
+ line: `${CSI}2K`,
142
+ lineEnd: `${CSI}K`,
143
+ lineStart: `${CSI}1K`,
144
+ lines(count) {
145
+ let clear = "";
146
+ for (let i = 0; i < count; i++)
147
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
148
+ if (count)
149
+ clear += cursor.left;
150
+ return clear;
151
+ }
152
+ };
153
+ module.exports = { cursor, scroll, erase, beep };
154
+ }
155
+ });
156
+
157
+ // src/index.ts
158
+ import { readFileSync as readFileSync3 } from "fs";
159
+ import { join as join11, dirname as dirname2 } from "path";
160
+ import { fileURLToPath as fileURLToPath2 } from "url";
161
+
162
+ // src/commands/init.ts
163
+ import { execSync as execSync5 } from "child_process";
164
+ import { join as join7 } from "path";
165
+ import crypto3 from "crypto";
166
+
167
+ // ../node_modules/.pnpm/@clack+core@1.0.1/node_modules/@clack/core/dist/index.mjs
168
+ var import_picocolors = __toESM(require_picocolors(), 1);
169
+ var import_sisteransi = __toESM(require_src(), 1);
170
+ import { stdout as R, stdin as q } from "process";
171
+ import * as k from "readline";
172
+ import ot from "readline";
173
+ import { ReadStream as J } from "tty";
174
+ function B(t, e2, s) {
175
+ if (!s.some((u) => !u.disabled)) return t;
176
+ const i = t + e2, r = Math.max(s.length - 1, 0), n = i < 0 ? r : i > r ? 0 : i;
177
+ return s[n].disabled ? B(n, e2 < 0 ? -1 : 1, s) : n;
178
+ }
179
+ var at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109;
180
+ var lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510;
181
+ var ht = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141;
182
+ var O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
183
+ var y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
184
+ var L = /\t{1,1000}/y;
185
+ var P = new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*", "yu");
186
+ var M = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
187
+ var ct = new RegExp("\\p{M}+", "gu");
188
+ var ft = { limit: 1 / 0, ellipsis: "" };
189
+ var X = (t, e2 = {}, s = {}) => {
190
+ const i = e2.limit ?? 1 / 0, r = e2.ellipsis ?? "", n = e2?.ellipsisWidth ?? (r ? X(r, ft, s).width : 0), u = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V2 = s.wideWidth ?? 2;
191
+ let h = 0, o = 0, p = t.length, v = 0, F = false, d2 = p, b = Math.max(0, i - n), C2 = 0, w = 0, c = 0, f = 0;
192
+ t: for (; ; ) {
193
+ if (w > C2 || o >= p && o > h) {
194
+ const ut2 = t.slice(C2, w) || t.slice(h, o);
195
+ v = 0;
196
+ for (const Y of ut2.replaceAll(ct, "")) {
197
+ const $ = Y.codePointAt(0) || 0;
198
+ if (lt($) ? f = m : ht($) ? f = V2 : E !== A && at($) ? f = E : f = A, c + f > b && (d2 = Math.min(d2, Math.max(C2, h) + v)), c + f > i) {
199
+ F = true;
200
+ break t;
201
+ }
202
+ v += Y.length, c += f;
203
+ }
204
+ C2 = w = 0;
205
+ }
206
+ if (o >= p) break;
207
+ if (M.lastIndex = o, M.test(t)) {
208
+ if (v = M.lastIndex - o, f = v * A, c + f > b && (d2 = Math.min(d2, o + Math.floor((b - c) / A))), c + f > i) {
209
+ F = true;
210
+ break;
211
+ }
212
+ c += f, C2 = h, w = o, o = h = M.lastIndex;
213
+ continue;
214
+ }
215
+ if (O.lastIndex = o, O.test(t)) {
216
+ if (c + u > b && (d2 = Math.min(d2, o)), c + u > i) {
217
+ F = true;
218
+ break;
219
+ }
220
+ c += u, C2 = h, w = o, o = h = O.lastIndex;
221
+ continue;
222
+ }
223
+ if (y.lastIndex = o, y.test(t)) {
224
+ if (v = y.lastIndex - o, f = v * a, c + f > b && (d2 = Math.min(d2, o + Math.floor((b - c) / a))), c + f > i) {
225
+ F = true;
226
+ break;
227
+ }
228
+ c += f, C2 = h, w = o, o = h = y.lastIndex;
229
+ continue;
230
+ }
231
+ if (L.lastIndex = o, L.test(t)) {
232
+ if (v = L.lastIndex - o, f = v * l, c + f > b && (d2 = Math.min(d2, o + Math.floor((b - c) / l))), c + f > i) {
233
+ F = true;
234
+ break;
235
+ }
236
+ c += f, C2 = h, w = o, o = h = L.lastIndex;
237
+ continue;
238
+ }
239
+ if (P.lastIndex = o, P.test(t)) {
240
+ if (c + g > b && (d2 = Math.min(d2, o)), c + g > i) {
241
+ F = true;
242
+ break;
243
+ }
244
+ c += g, C2 = h, w = o, o = h = P.lastIndex;
245
+ continue;
246
+ }
247
+ o += 1;
248
+ }
249
+ return { width: F ? b : c, index: F ? d2 : p, truncated: F, ellipsed: F && i >= n };
250
+ };
251
+ var pt = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
252
+ var S = (t, e2 = {}) => X(t, pt, e2).width;
253
+ var W = "\x1B";
254
+ var Z = "\x9B";
255
+ var Ft = 39;
256
+ var j = "\x07";
257
+ var Q = "[";
258
+ var dt = "]";
259
+ var tt = "m";
260
+ var U = `${dt}8;;`;
261
+ var et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
262
+ var mt = (t) => {
263
+ if (t >= 30 && t <= 37 || t >= 90 && t <= 97) return 39;
264
+ if (t >= 40 && t <= 47 || t >= 100 && t <= 107) return 49;
265
+ if (t === 1 || t === 2) return 22;
266
+ if (t === 3) return 23;
267
+ if (t === 4) return 24;
268
+ if (t === 7) return 27;
269
+ if (t === 8) return 28;
270
+ if (t === 9) return 29;
271
+ if (t === 0) return 0;
272
+ };
273
+ var st = (t) => `${W}${Q}${t}${tt}`;
274
+ var it = (t) => `${W}${U}${t}${j}`;
275
+ var gt = (t) => t.map((e2) => S(e2));
276
+ var G = (t, e2, s) => {
277
+ const i = e2[Symbol.iterator]();
278
+ let r = false, n = false, u = t.at(-1), a = u === void 0 ? 0 : S(u), l = i.next(), E = i.next(), g = 0;
279
+ for (; !l.done; ) {
280
+ const m = l.value, A = S(m);
281
+ a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === W || m === Z) && (r = true, n = e2.startsWith(U, g + 1)), r ? n ? m === j && (r = false, n = false) : m === tt && (r = false) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
282
+ }
283
+ u = t.at(-1), !a && u !== void 0 && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
284
+ };
285
+ var vt = (t) => {
286
+ const e2 = t.split(" ");
287
+ let s = e2.length;
288
+ for (; s > 0 && !(S(e2[s - 1]) > 0); ) s--;
289
+ return s === e2.length ? t : e2.slice(0, s).join(" ") + e2.slice(s).join("");
290
+ };
291
+ var Et = (t, e2, s = {}) => {
292
+ if (s.trim !== false && t.trim() === "") return "";
293
+ let i = "", r, n;
294
+ const u = t.split(" "), a = gt(u);
295
+ let l = [""];
296
+ for (const [h, o] of u.entries()) {
297
+ s.trim !== false && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
298
+ let p = S(l.at(-1) ?? "");
299
+ if (h !== 0 && (p >= e2 && (s.wordWrap === false || s.trim === false) && (l.push(""), p = 0), (p > 0 || s.trim === false) && (l[l.length - 1] += " ", p++)), s.hard && a[h] > e2) {
300
+ const v = e2 - p, F = 1 + Math.floor((a[h] - v - 1) / e2);
301
+ Math.floor((a[h] - 1) / e2) < F && l.push(""), G(l, o, e2);
302
+ continue;
303
+ }
304
+ if (p + a[h] > e2 && p > 0 && a[h] > 0) {
305
+ if (s.wordWrap === false && p < e2) {
306
+ G(l, o, e2);
307
+ continue;
308
+ }
309
+ l.push("");
310
+ }
311
+ if (p + a[h] > e2 && s.wordWrap === false) {
312
+ G(l, o, e2);
313
+ continue;
314
+ }
315
+ l[l.length - 1] += o;
316
+ }
317
+ s.trim !== false && (l = l.map((h) => vt(h)));
318
+ const E = l.join(`
319
+ `), g = E[Symbol.iterator]();
320
+ let m = g.next(), A = g.next(), V2 = 0;
321
+ for (; !m.done; ) {
322
+ const h = m.value, o = A.value;
323
+ if (i += h, h === W || h === Z) {
324
+ et.lastIndex = V2 + 1;
325
+ const F = et.exec(E)?.groups;
326
+ if (F?.code !== void 0) {
327
+ const d2 = Number.parseFloat(F.code);
328
+ r = d2 === Ft ? void 0 : d2;
329
+ } else F?.uri !== void 0 && (n = F.uri.length === 0 ? void 0 : F.uri);
330
+ }
331
+ const p = r ? mt(r) : void 0;
332
+ o === `
333
+ ` ? (n && (i += it("")), r && p && (i += st(p))) : h === `
334
+ ` && (r && p && (i += st(r)), n && (i += it(n))), V2 += h.length, m = A, A = g.next();
335
+ }
336
+ return i;
337
+ };
338
+ function K(t, e2, s) {
339
+ return String(t).normalize().replaceAll(`\r
340
+ `, `
341
+ `).split(`
342
+ `).map((i) => Et(i, e2, s)).join(`
343
+ `);
344
+ }
345
+ var At = ["up", "down", "left", "right", "space", "enter", "cancel"];
346
+ var _ = { actions: new Set(At), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
347
+ function H(t, e2) {
348
+ if (typeof t == "string") return _.aliases.get(t) === e2;
349
+ for (const s of t) if (s !== void 0 && H(s, e2)) return true;
350
+ return false;
351
+ }
352
+ function _t(t, e2) {
353
+ if (t === e2) return;
354
+ const s = t.split(`
355
+ `), i = e2.split(`
356
+ `), r = Math.max(s.length, i.length), n = [];
357
+ for (let u = 0; u < r; u++) s[u] !== i[u] && n.push(u);
358
+ return { lines: n, numLinesBefore: s.length, numLinesAfter: i.length, numLines: r };
359
+ }
360
+ var bt = globalThis.process.platform.startsWith("win");
361
+ var z = /* @__PURE__ */ Symbol("clack:cancel");
362
+ function Ct(t) {
363
+ return t === z;
364
+ }
365
+ function T(t, e2) {
366
+ const s = t;
367
+ s.isTTY && s.setRawMode(e2);
368
+ }
369
+ function Bt({ input: t = q, output: e2 = R, overwrite: s = true, hideCursor: i = true } = {}) {
370
+ const r = k.createInterface({ input: t, output: e2, prompt: "", tabSize: 1 });
371
+ k.emitKeypressEvents(t, r), t instanceof J && t.isTTY && t.setRawMode(true);
372
+ const n = (u, { name: a, sequence: l }) => {
373
+ const E = String(u);
374
+ if (H([E, a, l], "cancel")) {
375
+ i && e2.write(import_sisteransi.cursor.show), process.exit(0);
376
+ return;
377
+ }
378
+ if (!s) return;
379
+ const g = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
380
+ k.moveCursor(e2, g, m, () => {
381
+ k.clearLine(e2, 1, () => {
382
+ t.once("keypress", n);
383
+ });
384
+ });
385
+ };
386
+ return i && e2.write(import_sisteransi.cursor.hide), t.once("keypress", n), () => {
387
+ t.off("keypress", n), i && e2.write(import_sisteransi.cursor.show), t instanceof J && t.isTTY && !bt && t.setRawMode(false), r.terminal = false, r.close();
388
+ };
389
+ }
390
+ var rt = (t) => "columns" in t && typeof t.columns == "number" ? t.columns : 80;
391
+ var nt = (t) => "rows" in t && typeof t.rows == "number" ? t.rows : 20;
392
+ function xt(t, e2, s, i = s) {
393
+ const r = rt(t ?? R);
394
+ return K(e2, r - s.length, { hard: true, trim: false }).split(`
395
+ `).map((n, u) => `${u === 0 ? i : s}${n}`).join(`
396
+ `);
397
+ }
398
+ var x = class {
399
+ input;
400
+ output;
401
+ _abortSignal;
402
+ rl;
403
+ opts;
404
+ _render;
405
+ _track = false;
406
+ _prevFrame = "";
407
+ _subscribers = /* @__PURE__ */ new Map();
408
+ _cursor = 0;
409
+ state = "initial";
410
+ error = "";
411
+ value;
412
+ userInput = "";
413
+ constructor(e2, s = true) {
414
+ const { input: i = q, output: r = R, render: n, signal: u, ...a } = e2;
415
+ this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = u, this.input = i, this.output = r;
416
+ }
417
+ unsubscribe() {
418
+ this._subscribers.clear();
419
+ }
420
+ setSubscriber(e2, s) {
421
+ const i = this._subscribers.get(e2) ?? [];
422
+ i.push(s), this._subscribers.set(e2, i);
423
+ }
424
+ on(e2, s) {
425
+ this.setSubscriber(e2, { cb: s });
426
+ }
427
+ once(e2, s) {
428
+ this.setSubscriber(e2, { cb: s, once: true });
429
+ }
430
+ emit(e2, ...s) {
431
+ const i = this._subscribers.get(e2) ?? [], r = [];
432
+ for (const n of i) n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
433
+ for (const n of r) n();
434
+ }
435
+ prompt() {
436
+ return new Promise((e2) => {
437
+ if (this._abortSignal) {
438
+ if (this._abortSignal.aborted) return this.state = "cancel", this.close(), e2(z);
439
+ this._abortSignal.addEventListener("abort", () => {
440
+ this.state = "cancel", this.close();
441
+ }, { once: true });
442
+ }
443
+ this.rl = ot.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), T(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
444
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e2(this.value);
445
+ }), this.once("cancel", () => {
446
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e2(z);
447
+ });
448
+ });
449
+ }
450
+ _isActionKey(e2, s) {
451
+ return e2 === " ";
452
+ }
453
+ _setValue(e2) {
454
+ this.value = e2, this.emit("value", this.value);
455
+ }
456
+ _setUserInput(e2, s) {
457
+ this.userInput = e2 ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
458
+ }
459
+ _clearUserInput() {
460
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
461
+ }
462
+ onKeypress(e2, s) {
463
+ if (this._track && s.name !== "return" && (s.name && this._isActionKey(e2, s) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e2 && (e2.toLowerCase() === "y" || e2.toLowerCase() === "n") && this.emit("confirm", e2.toLowerCase() === "y"), this.emit("key", e2?.toLowerCase(), s), s?.name === "return") {
464
+ if (this.opts.validate) {
465
+ const i = this.opts.validate(this.value);
466
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
467
+ }
468
+ this.state !== "error" && (this.state = "submit");
469
+ }
470
+ H([e2, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
471
+ }
472
+ close() {
473
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
474
+ `), T(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
475
+ }
476
+ restoreCursor() {
477
+ const e2 = K(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
478
+ `).length - 1;
479
+ this.output.write(import_sisteransi.cursor.move(-999, e2 * -1));
480
+ }
481
+ render() {
482
+ const e2 = K(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
483
+ if (e2 !== this._prevFrame) {
484
+ if (this.state === "initial") this.output.write(import_sisteransi.cursor.hide);
485
+ else {
486
+ const s = _t(this._prevFrame, e2), i = nt(this.output);
487
+ if (this.restoreCursor(), s) {
488
+ const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
489
+ let u = s.lines.find((a) => a >= r);
490
+ if (u === void 0) {
491
+ this._prevFrame = e2;
492
+ return;
493
+ }
494
+ if (s.lines.length === 1) {
495
+ this.output.write(import_sisteransi.cursor.move(0, u - n)), this.output.write(import_sisteransi.erase.lines(1));
496
+ const a = e2.split(`
497
+ `);
498
+ this.output.write(a[u]), this._prevFrame = e2, this.output.write(import_sisteransi.cursor.move(0, a.length - u - 1));
499
+ return;
500
+ } else if (s.lines.length > 1) {
501
+ if (r < n) u = r;
502
+ else {
503
+ const l = u - n;
504
+ l > 0 && this.output.write(import_sisteransi.cursor.move(0, l));
505
+ }
506
+ this.output.write(import_sisteransi.erase.down());
507
+ const a = e2.split(`
508
+ `).slice(u);
509
+ this.output.write(a.join(`
510
+ `)), this._prevFrame = e2;
511
+ return;
512
+ }
513
+ }
514
+ this.output.write(import_sisteransi.erase.down());
515
+ }
516
+ this.output.write(e2), this.state === "initial" && (this.state = "active"), this._prevFrame = e2;
517
+ }
518
+ }
519
+ };
520
+ var kt = class extends x {
521
+ get cursor() {
522
+ return this.value ? 0 : 1;
523
+ }
524
+ get _value() {
525
+ return this.cursor === 0;
526
+ }
527
+ constructor(e2) {
528
+ super(e2, false), this.value = !!e2.initialValue, this.on("userInput", () => {
529
+ this.value = this._value;
530
+ }), this.on("confirm", (s) => {
531
+ this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
532
+ }), this.on("cursor", () => {
533
+ this.value = !this.value;
534
+ });
535
+ }
536
+ };
537
+ var Lt = class extends x {
538
+ options;
539
+ cursor = 0;
540
+ get _value() {
541
+ return this.options[this.cursor].value;
542
+ }
543
+ get _enabledOptions() {
544
+ return this.options.filter((e2) => e2.disabled !== true);
545
+ }
546
+ toggleAll() {
547
+ const e2 = this._enabledOptions, s = this.value !== void 0 && this.value.length === e2.length;
548
+ this.value = s ? [] : e2.map((i) => i.value);
549
+ }
550
+ toggleInvert() {
551
+ const e2 = this.value;
552
+ if (!e2) return;
553
+ const s = this._enabledOptions.filter((i) => !e2.includes(i.value));
554
+ this.value = s.map((i) => i.value);
555
+ }
556
+ toggleValue() {
557
+ this.value === void 0 && (this.value = []);
558
+ const e2 = this.value.includes(this._value);
559
+ this.value = e2 ? this.value.filter((s) => s !== this._value) : [...this.value, this._value];
560
+ }
561
+ constructor(e2) {
562
+ super(e2, false), this.options = e2.options, this.value = [...e2.initialValues ?? []];
563
+ const s = Math.max(this.options.findIndex(({ value: i }) => i === e2.cursorAt), 0);
564
+ this.cursor = this.options[s].disabled ? B(s, 1, this.options) : s, this.on("key", (i) => {
565
+ i === "a" && this.toggleAll(), i === "i" && this.toggleInvert();
566
+ }), this.on("cursor", (i) => {
567
+ switch (i) {
568
+ case "left":
569
+ case "up":
570
+ this.cursor = B(this.cursor, -1, this.options);
571
+ break;
572
+ case "down":
573
+ case "right":
574
+ this.cursor = B(this.cursor, 1, this.options);
575
+ break;
576
+ case "space":
577
+ this.toggleValue();
578
+ break;
579
+ }
580
+ });
581
+ }
582
+ };
583
+ var Mt = class extends x {
584
+ _mask = "\u2022";
585
+ get cursor() {
586
+ return this._cursor;
587
+ }
588
+ get masked() {
589
+ return this.userInput.replaceAll(/./g, this._mask);
590
+ }
591
+ get userInputWithCursor() {
592
+ if (this.state === "submit" || this.state === "cancel") return this.masked;
593
+ const e2 = this.userInput;
594
+ if (this.cursor >= e2.length) return `${this.masked}${import_picocolors.default.inverse(import_picocolors.default.hidden("_"))}`;
595
+ const s = this.masked, i = s.slice(0, this.cursor), r = s.slice(this.cursor);
596
+ return `${i}${import_picocolors.default.inverse(r[0])}${r.slice(1)}`;
597
+ }
598
+ clear() {
599
+ this._clearUserInput();
600
+ }
601
+ constructor({ mask: e2, ...s }) {
602
+ super(s), this._mask = e2 ?? "\u2022", this.on("userInput", (i) => {
603
+ this._setValue(i);
604
+ });
605
+ }
606
+ };
607
+ var Wt = class extends x {
608
+ options;
609
+ cursor = 0;
610
+ get _selectedValue() {
611
+ return this.options[this.cursor];
612
+ }
613
+ changeValue() {
614
+ this.value = this._selectedValue.value;
615
+ }
616
+ constructor(e2) {
617
+ super(e2, false), this.options = e2.options;
618
+ const s = this.options.findIndex(({ value: r }) => r === e2.initialValue), i = s === -1 ? 0 : s;
619
+ this.cursor = this.options[i].disabled ? B(i, 1, this.options) : i, this.changeValue(), this.on("cursor", (r) => {
620
+ switch (r) {
621
+ case "left":
622
+ case "up":
623
+ this.cursor = B(this.cursor, -1, this.options);
624
+ break;
625
+ case "down":
626
+ case "right":
627
+ this.cursor = B(this.cursor, 1, this.options);
628
+ break;
629
+ }
630
+ this.changeValue();
631
+ });
632
+ }
633
+ };
634
+ var $t = class extends x {
635
+ get userInputWithCursor() {
636
+ if (this.state === "submit") return this.userInput;
637
+ const e2 = this.userInput;
638
+ if (this.cursor >= e2.length) return `${this.userInput}\u2588`;
639
+ const s = e2.slice(0, this.cursor), [i, ...r] = e2.slice(this.cursor);
640
+ return `${s}${import_picocolors.default.inverse(i)}${r.join("")}`;
641
+ }
642
+ get cursor() {
643
+ return this._cursor;
644
+ }
645
+ constructor(e2) {
646
+ super({ ...e2, initialUserInput: e2.initialUserInput ?? e2.initialValue }), this.on("userInput", (s) => {
647
+ this._setValue(s);
648
+ }), this.on("finalize", () => {
649
+ this.value || (this.value = e2.defaultValue), this.value === void 0 && (this.value = "");
650
+ });
651
+ }
652
+ };
653
+
654
+ // ../node_modules/.pnpm/@clack+prompts@1.0.1/node_modules/@clack/prompts/dist/index.mjs
655
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
656
+ var import_sisteransi2 = __toESM(require_src(), 1);
657
+ import N2 from "process";
658
+ import { readdirSync as de, existsSync as $e, lstatSync as xt2 } from "fs";
659
+ import { dirname as _t2, join as he } from "path";
660
+ import { stripVTControlCharacters as ut } from "util";
661
+ function me() {
662
+ return N2.platform !== "win32" ? N2.env.TERM !== "linux" : !!N2.env.CI || !!N2.env.WT_SESSION || !!N2.env.TERMINUS_SUBLIME || N2.env.ConEmuTask === "{cmd::Cmder}" || N2.env.TERM_PROGRAM === "Terminus-Sublime" || N2.env.TERM_PROGRAM === "vscode" || N2.env.TERM === "xterm-256color" || N2.env.TERM === "alacritty" || N2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
663
+ }
664
+ var et2 = me();
665
+ var ct2 = () => process.env.CI === "true";
666
+ var C = (t, r) => et2 ? t : r;
667
+ var Rt = C("\u25C6", "*");
668
+ var dt2 = C("\u25A0", "x");
669
+ var $t2 = C("\u25B2", "x");
670
+ var V = C("\u25C7", "o");
671
+ var ht2 = C("\u250C", "T");
672
+ var d = C("\u2502", "|");
673
+ var x2 = C("\u2514", "\u2014");
674
+ var Ot = C("\u2510", "T");
675
+ var Pt = C("\u2518", "\u2014");
676
+ var Q2 = C("\u25CF", ">");
677
+ var H2 = C("\u25CB", " ");
678
+ var st2 = C("\u25FB", "[\u2022]");
679
+ var U2 = C("\u25FC", "[+]");
680
+ var q2 = C("\u25FB", "[ ]");
681
+ var Nt = C("\u25AA", "\u2022");
682
+ var rt2 = C("\u2500", "-");
683
+ var mt2 = C("\u256E", "+");
684
+ var Wt2 = C("\u251C", "+");
685
+ var pt2 = C("\u256F", "+");
686
+ var gt2 = C("\u2570", "+");
687
+ var Lt2 = C("\u256D", "+");
688
+ var ft2 = C("\u25CF", "\u2022");
689
+ var Ft2 = C("\u25C6", "*");
690
+ var yt2 = C("\u25B2", "!");
691
+ var Et2 = C("\u25A0", "x");
692
+ var W2 = (t) => {
693
+ switch (t) {
694
+ case "initial":
695
+ case "active":
696
+ return import_picocolors2.default.cyan(Rt);
697
+ case "cancel":
698
+ return import_picocolors2.default.red(dt2);
699
+ case "error":
700
+ return import_picocolors2.default.yellow($t2);
701
+ case "submit":
702
+ return import_picocolors2.default.green(V);
703
+ }
704
+ };
705
+ var vt2 = (t) => {
706
+ switch (t) {
707
+ case "initial":
708
+ case "active":
709
+ return import_picocolors2.default.cyan(d);
710
+ case "cancel":
711
+ return import_picocolors2.default.red(d);
712
+ case "error":
713
+ return import_picocolors2.default.yellow(d);
714
+ case "submit":
715
+ return import_picocolors2.default.green(d);
716
+ }
717
+ };
718
+ var pe = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109;
719
+ var ge = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510;
720
+ var fe = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141;
721
+ var At2 = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
722
+ var it2 = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
723
+ var nt2 = /\t{1,1000}/y;
724
+ var wt = new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*", "yu");
725
+ var at2 = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
726
+ var Fe = new RegExp("\\p{M}+", "gu");
727
+ var ye = { limit: 1 / 0, ellipsis: "" };
728
+ var jt = (t, r = {}, s = {}) => {
729
+ const i = r.limit ?? 1 / 0, a = r.ellipsis ?? "", o = r?.ellipsisWidth ?? (a ? jt(a, ye, s).width : 0), u = s.ansiWidth ?? 0, l = s.controlWidth ?? 0, n = s.tabWidth ?? 8, c = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, F = s.fullWidthWidth ?? 2, p = s.regularWidth ?? 1, E = s.wideWidth ?? 2;
730
+ let $ = 0, m = 0, h = t.length, y2 = 0, f = false, v = h, S2 = Math.max(0, i - o), I2 = 0, B2 = 0, A = 0, w = 0;
731
+ t: for (; ; ) {
732
+ if (B2 > I2 || m >= h && m > $) {
733
+ const _2 = t.slice(I2, B2) || t.slice($, m);
734
+ y2 = 0;
735
+ for (const D2 of _2.replaceAll(Fe, "")) {
736
+ const T2 = D2.codePointAt(0) || 0;
737
+ if (ge(T2) ? w = F : fe(T2) ? w = E : c !== p && pe(T2) ? w = c : w = p, A + w > S2 && (v = Math.min(v, Math.max(I2, $) + y2)), A + w > i) {
738
+ f = true;
739
+ break t;
740
+ }
741
+ y2 += D2.length, A += w;
742
+ }
743
+ I2 = B2 = 0;
744
+ }
745
+ if (m >= h) break;
746
+ if (at2.lastIndex = m, at2.test(t)) {
747
+ if (y2 = at2.lastIndex - m, w = y2 * p, A + w > S2 && (v = Math.min(v, m + Math.floor((S2 - A) / p))), A + w > i) {
748
+ f = true;
749
+ break;
750
+ }
751
+ A += w, I2 = $, B2 = m, m = $ = at2.lastIndex;
752
+ continue;
753
+ }
754
+ if (At2.lastIndex = m, At2.test(t)) {
755
+ if (A + u > S2 && (v = Math.min(v, m)), A + u > i) {
756
+ f = true;
757
+ break;
758
+ }
759
+ A += u, I2 = $, B2 = m, m = $ = At2.lastIndex;
760
+ continue;
761
+ }
762
+ if (it2.lastIndex = m, it2.test(t)) {
763
+ if (y2 = it2.lastIndex - m, w = y2 * l, A + w > S2 && (v = Math.min(v, m + Math.floor((S2 - A) / l))), A + w > i) {
764
+ f = true;
765
+ break;
766
+ }
767
+ A += w, I2 = $, B2 = m, m = $ = it2.lastIndex;
768
+ continue;
769
+ }
770
+ if (nt2.lastIndex = m, nt2.test(t)) {
771
+ if (y2 = nt2.lastIndex - m, w = y2 * n, A + w > S2 && (v = Math.min(v, m + Math.floor((S2 - A) / n))), A + w > i) {
772
+ f = true;
773
+ break;
774
+ }
775
+ A += w, I2 = $, B2 = m, m = $ = nt2.lastIndex;
776
+ continue;
777
+ }
778
+ if (wt.lastIndex = m, wt.test(t)) {
779
+ if (A + g > S2 && (v = Math.min(v, m)), A + g > i) {
780
+ f = true;
781
+ break;
782
+ }
783
+ A += g, I2 = $, B2 = m, m = $ = wt.lastIndex;
784
+ continue;
785
+ }
786
+ m += 1;
787
+ }
788
+ return { width: f ? S2 : A, index: f ? v : h, truncated: f, ellipsed: f && i >= o };
789
+ };
790
+ var Ee = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
791
+ var M2 = (t, r = {}) => jt(t, Ee, r).width;
792
+ var ot2 = "\x1B";
793
+ var Gt = "\x9B";
794
+ var ve = 39;
795
+ var Ct2 = "\x07";
796
+ var kt2 = "[";
797
+ var Ae = "]";
798
+ var Vt2 = "m";
799
+ var St = `${Ae}8;;`;
800
+ var Ht = new RegExp(`(?:\\${kt2}(?<code>\\d+)m|\\${St}(?<uri>.*)${Ct2})`, "y");
801
+ var we = (t) => {
802
+ if (t >= 30 && t <= 37 || t >= 90 && t <= 97) return 39;
803
+ if (t >= 40 && t <= 47 || t >= 100 && t <= 107) return 49;
804
+ if (t === 1 || t === 2) return 22;
805
+ if (t === 3) return 23;
806
+ if (t === 4) return 24;
807
+ if (t === 7) return 27;
808
+ if (t === 8) return 28;
809
+ if (t === 9) return 29;
810
+ if (t === 0) return 0;
811
+ };
812
+ var Ut = (t) => `${ot2}${kt2}${t}${Vt2}`;
813
+ var Kt = (t) => `${ot2}${St}${t}${Ct2}`;
814
+ var Ce = (t) => t.map((r) => M2(r));
815
+ var It2 = (t, r, s) => {
816
+ const i = r[Symbol.iterator]();
817
+ let a = false, o = false, u = t.at(-1), l = u === void 0 ? 0 : M2(u), n = i.next(), c = i.next(), g = 0;
818
+ for (; !n.done; ) {
819
+ const F = n.value, p = M2(F);
820
+ l + p <= s ? t[t.length - 1] += F : (t.push(F), l = 0), (F === ot2 || F === Gt) && (a = true, o = r.startsWith(St, g + 1)), a ? o ? F === Ct2 && (a = false, o = false) : F === Vt2 && (a = false) : (l += p, l === s && !c.done && (t.push(""), l = 0)), n = c, c = i.next(), g += F.length;
821
+ }
822
+ u = t.at(-1), !l && u !== void 0 && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
823
+ };
824
+ var Se = (t) => {
825
+ const r = t.split(" ");
826
+ let s = r.length;
827
+ for (; s > 0 && !(M2(r[s - 1]) > 0); ) s--;
828
+ return s === r.length ? t : r.slice(0, s).join(" ") + r.slice(s).join("");
829
+ };
830
+ var Ie = (t, r, s = {}) => {
831
+ if (s.trim !== false && t.trim() === "") return "";
832
+ let i = "", a, o;
833
+ const u = t.split(" "), l = Ce(u);
834
+ let n = [""];
835
+ for (const [$, m] of u.entries()) {
836
+ s.trim !== false && (n[n.length - 1] = (n.at(-1) ?? "").trimStart());
837
+ let h = M2(n.at(-1) ?? "");
838
+ if ($ !== 0 && (h >= r && (s.wordWrap === false || s.trim === false) && (n.push(""), h = 0), (h > 0 || s.trim === false) && (n[n.length - 1] += " ", h++)), s.hard && l[$] > r) {
839
+ const y2 = r - h, f = 1 + Math.floor((l[$] - y2 - 1) / r);
840
+ Math.floor((l[$] - 1) / r) < f && n.push(""), It2(n, m, r);
841
+ continue;
842
+ }
843
+ if (h + l[$] > r && h > 0 && l[$] > 0) {
844
+ if (s.wordWrap === false && h < r) {
845
+ It2(n, m, r);
846
+ continue;
847
+ }
848
+ n.push("");
849
+ }
850
+ if (h + l[$] > r && s.wordWrap === false) {
851
+ It2(n, m, r);
852
+ continue;
853
+ }
854
+ n[n.length - 1] += m;
855
+ }
856
+ s.trim !== false && (n = n.map(($) => Se($)));
857
+ const c = n.join(`
858
+ `), g = c[Symbol.iterator]();
859
+ let F = g.next(), p = g.next(), E = 0;
860
+ for (; !F.done; ) {
861
+ const $ = F.value, m = p.value;
862
+ if (i += $, $ === ot2 || $ === Gt) {
863
+ Ht.lastIndex = E + 1;
864
+ const f = Ht.exec(c)?.groups;
865
+ if (f?.code !== void 0) {
866
+ const v = Number.parseFloat(f.code);
867
+ a = v === ve ? void 0 : v;
868
+ } else f?.uri !== void 0 && (o = f.uri.length === 0 ? void 0 : f.uri);
869
+ }
870
+ const h = a ? we(a) : void 0;
871
+ m === `
872
+ ` ? (o && (i += Kt("")), a && h && (i += Ut(h))) : $ === `
873
+ ` && (a && h && (i += Ut(a)), o && (i += Kt(o))), E += $.length, F = p, p = g.next();
874
+ }
875
+ return i;
876
+ };
877
+ function J2(t, r, s) {
878
+ return String(t).normalize().replaceAll(`\r
879
+ `, `
880
+ `).split(`
881
+ `).map((i) => Ie(i, r, s)).join(`
882
+ `);
883
+ }
884
+ var be = (t, r, s, i, a) => {
885
+ let o = r, u = 0;
886
+ for (let l = s; l < i; l++) {
887
+ const n = t[l];
888
+ if (o = o - n.length, u++, o <= a) break;
889
+ }
890
+ return { lineCount: o, removals: u };
891
+ };
892
+ var X2 = (t) => {
893
+ const { cursor: r, options: s, style: i } = t, a = t.output ?? process.stdout, o = rt(a), u = t.columnPadding ?? 0, l = t.rowPadding ?? 4, n = o - u, c = nt(a), g = import_picocolors2.default.dim("..."), F = t.maxItems ?? Number.POSITIVE_INFINITY, p = Math.max(c - l, 0), E = Math.max(Math.min(F, p), 5);
894
+ let $ = 0;
895
+ r >= E - 3 && ($ = Math.max(Math.min(r - E + 3, s.length - E), 0));
896
+ let m = E < s.length && $ > 0, h = E < s.length && $ + E < s.length;
897
+ const y2 = Math.min($ + E, s.length), f = [];
898
+ let v = 0;
899
+ m && v++, h && v++;
900
+ const S2 = $ + (m ? 1 : 0), I2 = y2 - (h ? 1 : 0);
901
+ for (let A = S2; A < I2; A++) {
902
+ const w = J2(i(s[A], A === r), n, { hard: true, trim: false }).split(`
903
+ `);
904
+ f.push(w), v += w.length;
905
+ }
906
+ if (v > p) {
907
+ let A = 0, w = 0, _2 = v;
908
+ const D2 = r - S2, T2 = (Y, L2) => be(f, _2, Y, L2, p);
909
+ m ? ({ lineCount: _2, removals: A } = T2(0, D2), _2 > p && ({ lineCount: _2, removals: w } = T2(D2 + 1, f.length))) : ({ lineCount: _2, removals: w } = T2(D2 + 1, f.length), _2 > p && ({ lineCount: _2, removals: A } = T2(0, D2))), A > 0 && (m = true, f.splice(0, A)), w > 0 && (h = true, f.splice(f.length - w, w));
910
+ }
911
+ const B2 = [];
912
+ m && B2.push(g);
913
+ for (const A of f) for (const w of A) B2.push(w);
914
+ return h && B2.push(g), B2;
915
+ };
916
+ var Re = (t) => {
917
+ const r = t.active ?? "Yes", s = t.inactive ?? "No";
918
+ return new kt({ active: r, inactive: s, signal: t.signal, input: t.input, output: t.output, initialValue: t.initialValue ?? true, render() {
919
+ const i = t.withGuide ?? _.withGuide, a = `${i ? `${import_picocolors2.default.gray(d)}
920
+ ` : ""}${W2(this.state)} ${t.message}
921
+ `, o = this.value ? r : s;
922
+ switch (this.state) {
923
+ case "submit": {
924
+ const u = i ? `${import_picocolors2.default.gray(d)} ` : "";
925
+ return `${a}${u}${import_picocolors2.default.dim(o)}`;
926
+ }
927
+ case "cancel": {
928
+ const u = i ? `${import_picocolors2.default.gray(d)} ` : "";
929
+ return `${a}${u}${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o))}${i ? `
930
+ ${import_picocolors2.default.gray(d)}` : ""}`;
931
+ }
932
+ default: {
933
+ const u = i ? `${import_picocolors2.default.cyan(d)} ` : "", l = i ? import_picocolors2.default.cyan(x2) : "";
934
+ return `${a}${u}${this.value ? `${import_picocolors2.default.green(Q2)} ${r}` : `${import_picocolors2.default.dim(H2)} ${import_picocolors2.default.dim(r)}`}${t.vertical ? i ? `
935
+ ${import_picocolors2.default.cyan(d)} ` : `
936
+ ` : ` ${import_picocolors2.default.dim("/")} `}${this.value ? `${import_picocolors2.default.dim(H2)} ${import_picocolors2.default.dim(s)}` : `${import_picocolors2.default.green(Q2)} ${s}`}
937
+ ${l}
938
+ `;
939
+ }
940
+ }
941
+ } }).prompt();
942
+ };
943
+ var R2 = { message: (t = [], { symbol: r = import_picocolors2.default.gray(d), secondarySymbol: s = import_picocolors2.default.gray(d), output: i = process.stdout, spacing: a = 1, withGuide: o } = {}) => {
944
+ const u = [], l = o ?? _.withGuide, n = l ? s : "", c = l ? `${r} ` : "", g = l ? `${s} ` : "";
945
+ for (let p = 0; p < a; p++) u.push(n);
946
+ const F = Array.isArray(t) ? t : t.split(`
947
+ `);
948
+ if (F.length > 0) {
949
+ const [p, ...E] = F;
950
+ p.length > 0 ? u.push(`${c}${p}`) : u.push(l ? r : "");
951
+ for (const $ of E) $.length > 0 ? u.push(`${g}${$}`) : u.push(l ? s : "");
952
+ }
953
+ i.write(`${u.join(`
954
+ `)}
955
+ `);
956
+ }, info: (t, r) => {
957
+ R2.message(t, { ...r, symbol: import_picocolors2.default.blue(ft2) });
958
+ }, success: (t, r) => {
959
+ R2.message(t, { ...r, symbol: import_picocolors2.default.green(Ft2) });
960
+ }, step: (t, r) => {
961
+ R2.message(t, { ...r, symbol: import_picocolors2.default.green(V) });
962
+ }, warn: (t, r) => {
963
+ R2.message(t, { ...r, symbol: import_picocolors2.default.yellow(yt2) });
964
+ }, warning: (t, r) => {
965
+ R2.warn(t, r);
966
+ }, error: (t, r) => {
967
+ R2.message(t, { ...r, symbol: import_picocolors2.default.red(Et2) });
968
+ } };
969
+ var Ne = (t = "", r) => {
970
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray(x2)} ${import_picocolors2.default.red(t)}
971
+
972
+ `);
973
+ };
974
+ var We = (t = "", r) => {
975
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray(ht2)} ${t}
976
+ `);
977
+ };
978
+ var Le = (t = "", r) => {
979
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray(d)}
980
+ ${import_picocolors2.default.gray(x2)} ${t}
981
+
982
+ `);
983
+ };
984
+ var Z2 = (t, r) => t.split(`
985
+ `).map((s) => r(s)).join(`
986
+ `);
987
+ var je = (t) => {
988
+ const r = (i, a) => {
989
+ const o = i.label ?? String(i.value);
990
+ return a === "disabled" ? `${import_picocolors2.default.gray(q2)} ${Z2(o, (u) => import_picocolors2.default.strikethrough(import_picocolors2.default.gray(u)))}${i.hint ? ` ${import_picocolors2.default.dim(`(${i.hint ?? "disabled"})`)}` : ""}` : a === "active" ? `${import_picocolors2.default.cyan(st2)} ${o}${i.hint ? ` ${import_picocolors2.default.dim(`(${i.hint})`)}` : ""}` : a === "selected" ? `${import_picocolors2.default.green(U2)} ${Z2(o, import_picocolors2.default.dim)}${i.hint ? ` ${import_picocolors2.default.dim(`(${i.hint})`)}` : ""}` : a === "cancelled" ? `${Z2(o, (u) => import_picocolors2.default.strikethrough(import_picocolors2.default.dim(u)))}` : a === "active-selected" ? `${import_picocolors2.default.green(U2)} ${o}${i.hint ? ` ${import_picocolors2.default.dim(`(${i.hint})`)}` : ""}` : a === "submitted" ? `${Z2(o, import_picocolors2.default.dim)}` : `${import_picocolors2.default.dim(q2)} ${Z2(o, import_picocolors2.default.dim)}`;
991
+ }, s = t.required ?? true;
992
+ return new Lt({ options: t.options, signal: t.signal, input: t.input, output: t.output, initialValues: t.initialValues, required: s, cursorAt: t.cursorAt, validate(i) {
993
+ if (s && (i === void 0 || i.length === 0)) return `Please select at least one option.
994
+ ${import_picocolors2.default.reset(import_picocolors2.default.dim(`Press ${import_picocolors2.default.gray(import_picocolors2.default.bgWhite(import_picocolors2.default.inverse(" space ")))} to select, ${import_picocolors2.default.gray(import_picocolors2.default.bgWhite(import_picocolors2.default.inverse(" enter ")))} to submit`))}`;
995
+ }, render() {
996
+ const i = xt(t.output, t.message, `${vt2(this.state)} `, `${W2(this.state)} `), a = `${import_picocolors2.default.gray(d)}
997
+ ${i}
998
+ `, o = this.value ?? [], u = (l, n) => {
999
+ if (l.disabled) return r(l, "disabled");
1000
+ const c = o.includes(l.value);
1001
+ return n && c ? r(l, "active-selected") : c ? r(l, "selected") : r(l, n ? "active" : "inactive");
1002
+ };
1003
+ switch (this.state) {
1004
+ case "submit": {
1005
+ const l = this.options.filter(({ value: c }) => o.includes(c)).map((c) => r(c, "submitted")).join(import_picocolors2.default.dim(", ")) || import_picocolors2.default.dim("none"), n = xt(t.output, l, `${import_picocolors2.default.gray(d)} `);
1006
+ return `${a}${n}`;
1007
+ }
1008
+ case "cancel": {
1009
+ const l = this.options.filter(({ value: c }) => o.includes(c)).map((c) => r(c, "cancelled")).join(import_picocolors2.default.dim(", "));
1010
+ if (l.trim() === "") return `${a}${import_picocolors2.default.gray(d)}`;
1011
+ const n = xt(t.output, l, `${import_picocolors2.default.gray(d)} `);
1012
+ return `${a}${n}
1013
+ ${import_picocolors2.default.gray(d)}`;
1014
+ }
1015
+ case "error": {
1016
+ const l = `${import_picocolors2.default.yellow(d)} `, n = this.error.split(`
1017
+ `).map((F, p) => p === 0 ? `${import_picocolors2.default.yellow(x2)} ${import_picocolors2.default.yellow(F)}` : ` ${F}`).join(`
1018
+ `), c = a.split(`
1019
+ `).length, g = n.split(`
1020
+ `).length + 1;
1021
+ return `${a}${l}${X2({ output: t.output, options: this.options, cursor: this.cursor, maxItems: t.maxItems, columnPadding: l.length, rowPadding: c + g, style: u }).join(`
1022
+ ${l}`)}
1023
+ ${n}
1024
+ `;
1025
+ }
1026
+ default: {
1027
+ const l = `${import_picocolors2.default.cyan(d)} `, n = a.split(`
1028
+ `).length;
1029
+ return `${a}${l}${X2({ output: t.output, options: this.options, cursor: this.cursor, maxItems: t.maxItems, columnPadding: l.length, rowPadding: n + 2, style: u }).join(`
1030
+ ${l}`)}
1031
+ ${import_picocolors2.default.cyan(x2)}
1032
+ `;
1033
+ }
1034
+ }
1035
+ } }).prompt();
1036
+ };
1037
+ var He = (t) => new Mt({ validate: t.validate, mask: t.mask ?? Nt, signal: t.signal, input: t.input, output: t.output, render() {
1038
+ const r = t.withGuide ?? _.withGuide, s = `${r ? `${import_picocolors2.default.gray(d)}
1039
+ ` : ""}${W2(this.state)} ${t.message}
1040
+ `, i = this.userInputWithCursor, a = this.masked;
1041
+ switch (this.state) {
1042
+ case "error": {
1043
+ const o = r ? `${import_picocolors2.default.yellow(d)} ` : "", u = r ? `${import_picocolors2.default.yellow(x2)} ` : "", l = a ?? "";
1044
+ return t.clearOnError && this.clear(), `${s.trim()}
1045
+ ${o}${l}
1046
+ ${u}${import_picocolors2.default.yellow(this.error)}
1047
+ `;
1048
+ }
1049
+ case "submit": {
1050
+ const o = r ? `${import_picocolors2.default.gray(d)} ` : "", u = a ? import_picocolors2.default.dim(a) : "";
1051
+ return `${s}${o}${u}`;
1052
+ }
1053
+ case "cancel": {
1054
+ const o = r ? `${import_picocolors2.default.gray(d)} ` : "", u = a ? import_picocolors2.default.strikethrough(import_picocolors2.default.dim(a)) : "";
1055
+ return `${s}${o}${u}${a && r ? `
1056
+ ${import_picocolors2.default.gray(d)}` : ""}`;
1057
+ }
1058
+ default: {
1059
+ const o = r ? `${import_picocolors2.default.cyan(d)} ` : "", u = r ? import_picocolors2.default.cyan(x2) : "";
1060
+ return `${s}${o}${i}
1061
+ ${u}
1062
+ `;
1063
+ }
1064
+ }
1065
+ } }).prompt();
1066
+ var Ke = import_picocolors2.default.magenta;
1067
+ var bt2 = ({ indicator: t = "dots", onCancel: r, output: s = process.stdout, cancelMessage: i, errorMessage: a, frames: o = et2 ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], delay: u = et2 ? 80 : 120, signal: l, ...n } = {}) => {
1068
+ const c = ct2();
1069
+ let g, F, p = false, E = false, $ = "", m, h = performance.now();
1070
+ const y2 = rt(s), f = n?.styleFrame ?? Ke, v = (b) => {
1071
+ const O2 = b > 1 ? a ?? _.messages.error : i ?? _.messages.cancel;
1072
+ E = b === 1, p && (L2(O2, b), E && typeof r == "function" && r());
1073
+ }, S2 = () => v(2), I2 = () => v(1), B2 = () => {
1074
+ process.on("uncaughtExceptionMonitor", S2), process.on("unhandledRejection", S2), process.on("SIGINT", I2), process.on("SIGTERM", I2), process.on("exit", v), l && l.addEventListener("abort", I2);
1075
+ }, A = () => {
1076
+ process.removeListener("uncaughtExceptionMonitor", S2), process.removeListener("unhandledRejection", S2), process.removeListener("SIGINT", I2), process.removeListener("SIGTERM", I2), process.removeListener("exit", v), l && l.removeEventListener("abort", I2);
1077
+ }, w = () => {
1078
+ if (m === void 0) return;
1079
+ c && s.write(`
1080
+ `);
1081
+ const b = J2(m, y2, { hard: true, trim: false }).split(`
1082
+ `);
1083
+ b.length > 1 && s.write(import_sisteransi2.cursor.up(b.length - 1)), s.write(import_sisteransi2.cursor.to(0)), s.write(import_sisteransi2.erase.down());
1084
+ }, _2 = (b) => b.replace(/\.+$/, ""), D2 = (b) => {
1085
+ const O2 = (performance.now() - b) / 1e3, j2 = Math.floor(O2 / 60), G2 = Math.floor(O2 % 60);
1086
+ return j2 > 0 ? `[${j2}m ${G2}s]` : `[${G2}s]`;
1087
+ }, T2 = n.withGuide ?? _.withGuide, Y = (b = "") => {
1088
+ p = true, g = Bt({ output: s }), $ = _2(b), h = performance.now(), T2 && s.write(`${import_picocolors2.default.gray(d)}
1089
+ `);
1090
+ let O2 = 0, j2 = 0;
1091
+ B2(), F = setInterval(() => {
1092
+ if (c && $ === m) return;
1093
+ w(), m = $;
1094
+ const G2 = f(o[O2]);
1095
+ let tt2;
1096
+ if (c) tt2 = `${G2} ${$}...`;
1097
+ else if (t === "timer") tt2 = `${G2} ${$} ${D2(h)}`;
1098
+ else {
1099
+ const te = ".".repeat(Math.floor(j2)).slice(0, 3);
1100
+ tt2 = `${G2} ${$}${te}`;
1101
+ }
1102
+ const Zt = J2(tt2, y2, { hard: true, trim: false });
1103
+ s.write(Zt), O2 = O2 + 1 < o.length ? O2 + 1 : 0, j2 = j2 < 4 ? j2 + 0.125 : 0;
1104
+ }, u);
1105
+ }, L2 = (b = "", O2 = 0, j2 = false) => {
1106
+ if (!p) return;
1107
+ p = false, clearInterval(F), w();
1108
+ const G2 = O2 === 0 ? import_picocolors2.default.green(V) : O2 === 1 ? import_picocolors2.default.red(dt2) : import_picocolors2.default.red($t2);
1109
+ $ = b ?? $, j2 || (t === "timer" ? s.write(`${G2} ${$} ${D2(h)}
1110
+ `) : s.write(`${G2} ${$}
1111
+ `)), A(), g();
1112
+ };
1113
+ return { start: Y, stop: (b = "") => L2(b, 0), message: (b = "") => {
1114
+ $ = _2(b ?? $);
1115
+ }, cancel: (b = "") => L2(b, 1), error: (b = "") => L2(b, 2), clear: () => L2("", 0, true), get isCancelled() {
1116
+ return E;
1117
+ } };
1118
+ };
1119
+ var zt = { light: C("\u2500", "-"), heavy: C("\u2501", "="), block: C("\u2588", "#") };
1120
+ var lt2 = (t, r) => t.includes(`
1121
+ `) ? t.split(`
1122
+ `).map((s) => r(s)).join(`
1123
+ `) : r(t);
1124
+ var Je = (t) => {
1125
+ const r = (s, i) => {
1126
+ const a = s.label ?? String(s.value);
1127
+ switch (i) {
1128
+ case "disabled":
1129
+ return `${import_picocolors2.default.gray(H2)} ${lt2(a, import_picocolors2.default.gray)}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint ?? "disabled"})`)}` : ""}`;
1130
+ case "selected":
1131
+ return `${lt2(a, import_picocolors2.default.dim)}`;
1132
+ case "active":
1133
+ return `${import_picocolors2.default.green(Q2)} ${a}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint})`)}` : ""}`;
1134
+ case "cancelled":
1135
+ return `${lt2(a, (o) => import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o)))}`;
1136
+ default:
1137
+ return `${import_picocolors2.default.dim(H2)} ${lt2(a, import_picocolors2.default.dim)}`;
1138
+ }
1139
+ };
1140
+ return new Wt({ options: t.options, signal: t.signal, input: t.input, output: t.output, initialValue: t.initialValue, render() {
1141
+ const s = t.withGuide ?? _.withGuide, i = `${W2(this.state)} `, a = `${vt2(this.state)} `, o = xt(t.output, t.message, a, i), u = `${s ? `${import_picocolors2.default.gray(d)}
1142
+ ` : ""}${o}
1143
+ `;
1144
+ switch (this.state) {
1145
+ case "submit": {
1146
+ const l = s ? `${import_picocolors2.default.gray(d)} ` : "", n = xt(t.output, r(this.options[this.cursor], "selected"), l);
1147
+ return `${u}${n}`;
1148
+ }
1149
+ case "cancel": {
1150
+ const l = s ? `${import_picocolors2.default.gray(d)} ` : "", n = xt(t.output, r(this.options[this.cursor], "cancelled"), l);
1151
+ return `${u}${n}${s ? `
1152
+ ${import_picocolors2.default.gray(d)}` : ""}`;
1153
+ }
1154
+ default: {
1155
+ const l = s ? `${import_picocolors2.default.cyan(d)} ` : "", n = s ? import_picocolors2.default.cyan(x2) : "", c = u.split(`
1156
+ `).length, g = s ? 2 : 1;
1157
+ return `${u}${l}${X2({ output: t.output, cursor: this.cursor, options: this.options, maxItems: t.maxItems, columnPadding: l.length, rowPadding: c + g, style: (F, p) => r(F, F.disabled ? "disabled" : p ? "active" : "inactive") }).join(`
1158
+ ${l}`)}
1159
+ ${n}
1160
+ `;
1161
+ }
1162
+ }
1163
+ } }).prompt();
1164
+ };
1165
+ var Qt = `${import_picocolors2.default.gray(d)} `;
1166
+ var Ze = (t) => new $t({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, output: t.output, signal: t.signal, input: t.input, render() {
1167
+ const r = t?.withGuide ?? _.withGuide, s = `${`${r ? `${import_picocolors2.default.gray(d)}
1168
+ ` : ""}${W2(this.state)} `}${t.message}
1169
+ `, i = t.placeholder ? import_picocolors2.default.inverse(t.placeholder[0]) + import_picocolors2.default.dim(t.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), a = this.userInput ? this.userInputWithCursor : i, o = this.value ?? "";
1170
+ switch (this.state) {
1171
+ case "error": {
1172
+ const u = this.error ? ` ${import_picocolors2.default.yellow(this.error)}` : "", l = r ? `${import_picocolors2.default.yellow(d)} ` : "", n = r ? import_picocolors2.default.yellow(x2) : "";
1173
+ return `${s.trim()}
1174
+ ${l}${a}
1175
+ ${n}${u}
1176
+ `;
1177
+ }
1178
+ case "submit": {
1179
+ const u = o ? ` ${import_picocolors2.default.dim(o)}` : "", l = r ? import_picocolors2.default.gray(d) : "";
1180
+ return `${s}${l}${u}`;
1181
+ }
1182
+ case "cancel": {
1183
+ const u = o ? ` ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o))}` : "", l = r ? import_picocolors2.default.gray(d) : "";
1184
+ return `${s}${l}${u}${o.trim() ? `
1185
+ ${l}` : ""}`;
1186
+ }
1187
+ default: {
1188
+ const u = r ? `${import_picocolors2.default.cyan(d)} ` : "", l = r ? import_picocolors2.default.cyan(x2) : "";
1189
+ return `${s}${u}${a}
1190
+ ${l}
1191
+ `;
1192
+ }
1193
+ }
1194
+ } }).prompt();
1195
+
1196
+ // src/commands/init.ts
1197
+ var import_picocolors5 = __toESM(require_picocolors(), 1);
1198
+
1199
+ // src/lib/prerequisites.ts
1200
+ import { execSync } from "child_process";
1201
+ var import_picocolors3 = __toESM(require_picocolors(), 1);
1202
+ function checkCommand(cmd) {
1203
+ try {
1204
+ return execSync(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
1205
+ } catch {
1206
+ return null;
1207
+ }
1208
+ }
1209
+ async function checkPrerequisites() {
1210
+ R2.step("Checking prerequisites...");
1211
+ const nodeOut = checkCommand("node --version");
1212
+ const pythonOut = checkCommand("python3 --version");
1213
+ const pnpmOut = checkCommand("pnpm --version");
1214
+ let claudeOut = checkCommand("claude --version");
1215
+ const dockerOut = checkCommand("docker --version");
1216
+ const nodeMajor = nodeOut ? parseInt(nodeOut.replace("v", "")) : 0;
1217
+ if (nodeMajor < 22) {
1218
+ R2.error(`Node.js >= 22 required (found: ${nodeOut || "not installed"})`);
1219
+ R2.info("Install from https://nodejs.org/");
1220
+ process.exit(1);
1221
+ }
1222
+ R2.success(`Node.js ${nodeOut}`);
1223
+ if (!pythonOut) {
1224
+ R2.error("Python 3 is required (used by skills and hooks)");
1225
+ R2.info("Install from https://python.org/");
1226
+ process.exit(1);
1227
+ }
1228
+ R2.success(`${pythonOut}`);
1229
+ if (!pnpmOut) {
1230
+ R2.error("pnpm is required");
1231
+ R2.info("Install with: npm install -g pnpm");
1232
+ process.exit(1);
1233
+ }
1234
+ R2.success(`pnpm ${pnpmOut}`);
1235
+ if (!claudeOut) {
1236
+ const install = await Re({
1237
+ message: "Claude Code CLI not found. Install it now?"
1238
+ });
1239
+ if (Ct(install)) process.exit(0);
1240
+ if (install) {
1241
+ const s = bt2();
1242
+ s.start("Installing Claude Code CLI");
1243
+ try {
1244
+ const cmd = process.platform === "linux" ? "sudo npm install -g @anthropic-ai/claude-code" : "npm install -g @anthropic-ai/claude-code";
1245
+ execSync(cmd, { stdio: "inherit" });
1246
+ claudeOut = checkCommand("claude --version");
1247
+ s.stop(`Claude Code installed (${claudeOut})`);
1248
+ } catch {
1249
+ s.stop("Installation failed");
1250
+ R2.warn("Claude Code could not be installed. Install manually: npm install -g @anthropic-ai/claude-code");
1251
+ }
1252
+ } else {
1253
+ R2.warn("Claude Code CLI not installed \u2014 terminal features will be limited");
1254
+ }
1255
+ } else {
1256
+ R2.success(`Claude Code ${claudeOut}`);
1257
+ }
1258
+ if (dockerOut) {
1259
+ R2.success(`Docker available ${import_picocolors3.default.dim("(for local PostgreSQL)")}`);
1260
+ } else {
1261
+ R2.info(`Docker not found ${import_picocolors3.default.dim("(needed only for local PostgreSQL)")}`);
1262
+ }
1263
+ return {
1264
+ ok: true,
1265
+ hasDocker: !!dockerOut,
1266
+ nodeVersion: nodeOut || "",
1267
+ pythonVersion: pythonOut || "",
1268
+ pnpmVersion: pnpmOut || "",
1269
+ claudeInstalled: !!claudeOut
1270
+ };
1271
+ }
1272
+
1273
+ // src/lib/personality.ts
1274
+ async function promptPersonality() {
1275
+ const agentName = await Ze({
1276
+ message: "What should your agent be called?",
1277
+ placeholder: "Cognova",
1278
+ defaultValue: "Cognova"
1279
+ });
1280
+ if (Ct(agentName)) process.exit(0);
1281
+ const userName = await Ze({
1282
+ message: "What should the agent call you?",
1283
+ placeholder: "your name"
1284
+ });
1285
+ if (Ct(userName)) process.exit(0);
1286
+ const tone = await Je({
1287
+ message: "Agent tone",
1288
+ options: [
1289
+ { value: "concise", label: "Concise", hint: "Brief, to-the-point responses" },
1290
+ { value: "casual", label: "Casual", hint: "Friendly and conversational" },
1291
+ { value: "formal", label: "Formal", hint: "Professional and detailed" },
1292
+ { value: "custom", label: "Custom", hint: "Describe your own tone" }
1293
+ ]
1294
+ });
1295
+ if (Ct(tone)) process.exit(0);
1296
+ let customTone;
1297
+ if (tone === "custom") {
1298
+ const custom = await Ze({
1299
+ message: "Describe the tone you want",
1300
+ placeholder: "e.g., Dry humor, slightly sarcastic, but helpful"
1301
+ });
1302
+ if (Ct(custom)) process.exit(0);
1303
+ customTone = custom;
1304
+ }
1305
+ const traits = await je({
1306
+ message: "Agent traits (select all that apply)",
1307
+ options: [
1308
+ { value: "proactive", label: "Proactive", hint: "Suggests actions before being asked" },
1309
+ { value: "opinionated", label: "Opinionated", hint: "Has strong preferences on organization" },
1310
+ { value: "cautious", label: "Cautious", hint: "Asks before making changes" },
1311
+ { value: "curious", label: "Curious", hint: "Asks follow-up questions to understand context" },
1312
+ { value: "organized", label: "Organized", hint: "Prioritizes structure and consistency" }
1313
+ ],
1314
+ required: true
1315
+ });
1316
+ if (Ct(traits)) process.exit(0);
1317
+ const communicationStyle = await Je({
1318
+ message: "Communication style",
1319
+ options: [
1320
+ { value: "bullets", label: "Bullets first", hint: "Lists and structured output" },
1321
+ { value: "narrative", label: "Narrative", hint: "Flowing prose and explanations" },
1322
+ { value: "mixed", label: "Mixed", hint: "Adapts to the situation" }
1323
+ ]
1324
+ });
1325
+ if (Ct(communicationStyle)) process.exit(0);
1326
+ const proactivity = await Je({
1327
+ message: "How proactive should the agent be?",
1328
+ options: [
1329
+ { value: "reactive", label: "Reactive", hint: "Only acts when explicitly asked" },
1330
+ { value: "balanced", label: "Balanced", hint: "Suggests when relevant, waits otherwise" },
1331
+ { value: "proactive", label: "Proactive", hint: "Actively suggests tasks, organization, reminders" }
1332
+ ]
1333
+ });
1334
+ if (Ct(proactivity)) process.exit(0);
1335
+ return {
1336
+ agentName,
1337
+ userName,
1338
+ tone,
1339
+ customTone,
1340
+ traits,
1341
+ communicationStyle,
1342
+ proactivity
1343
+ };
1344
+ }
1345
+
1346
+ // src/lib/install.ts
1347
+ import { cpSync, mkdirSync, existsSync as existsSync2, writeFileSync, readdirSync } from "fs";
1348
+ import { join as join2 } from "path";
1349
+
1350
+ // src/lib/paths.ts
1351
+ import { homedir } from "os";
1352
+ import { join, dirname } from "path";
1353
+ import { existsSync, readFileSync } from "fs";
1354
+ import { fileURLToPath } from "url";
1355
+ var __filename = fileURLToPath(import.meta.url);
1356
+ var __dirname = dirname(__filename);
1357
+ function getPackageDir() {
1358
+ return join(__dirname, "..", "..");
1359
+ }
1360
+ function getClaudeDir() {
1361
+ return join(homedir(), ".claude");
1362
+ }
1363
+ function getMetadataPath(installDir) {
1364
+ const dir = installDir || findInstallDir();
1365
+ return join(dir, ".cognova");
1366
+ }
1367
+ function readMetadata(installDir) {
1368
+ try {
1369
+ const metaPath = getMetadataPath(installDir);
1370
+ if (!existsSync(metaPath))
1371
+ return null;
1372
+ return JSON.parse(readFileSync(metaPath, "utf-8"));
1373
+ } catch {
1374
+ return null;
1375
+ }
1376
+ }
1377
+ function findInstallDir() {
1378
+ const cwdMeta = join(process.cwd(), ".cognova");
1379
+ if (existsSync(cwdMeta)) return process.cwd();
1380
+ const homeMeta = join(homedir(), ".cognova");
1381
+ if (existsSync(homeMeta)) {
1382
+ try {
1383
+ const meta = JSON.parse(readFileSync(homeMeta, "utf-8"));
1384
+ if (meta.installDir && existsSync(meta.installDir))
1385
+ return meta.installDir;
1386
+ } catch {
1387
+ }
1388
+ }
1389
+ return process.cwd();
1390
+ }
1391
+
1392
+ // src/lib/install.ts
1393
+ var PRESERVE_ON_UPDATE = /* @__PURE__ */ new Set([
1394
+ ".env",
1395
+ ".api-token",
1396
+ ".cognova",
1397
+ "node_modules",
1398
+ ".output",
1399
+ "ecosystem.config.cjs",
1400
+ "logs",
1401
+ ".update-backup"
1402
+ ]);
1403
+ function copyAppSource(sourceDir, installDir) {
1404
+ mkdirSync(installDir, { recursive: true });
1405
+ const appItems = [
1406
+ "app",
1407
+ "server",
1408
+ "shared",
1409
+ "Claude",
1410
+ "nuxt.config.ts",
1411
+ "tsconfig.json",
1412
+ "drizzle.config.ts",
1413
+ "package.json",
1414
+ "pnpm-lock.yaml",
1415
+ ".env.example"
1416
+ ];
1417
+ for (const item of appItems) {
1418
+ const src = join2(sourceDir, item);
1419
+ if (!existsSync2(src)) continue;
1420
+ const dest = join2(installDir, item);
1421
+ if (PRESERVE_ON_UPDATE.has(item) && existsSync2(dest)) continue;
1422
+ cpSync(src, dest, { recursive: true, force: true });
1423
+ }
1424
+ }
1425
+ async function setupInstallDir(installDir) {
1426
+ if (existsSync2(installDir) && readdirSync(installDir).length > 0) {
1427
+ const overwrite = await Re({
1428
+ message: `${installDir} already exists and is not empty. Continue?`,
1429
+ initialValue: false
1430
+ });
1431
+ if (Ct(overwrite) || !overwrite) process.exit(0);
1432
+ }
1433
+ const packageDir = getPackageDir();
1434
+ const s = bt2();
1435
+ s.start("Copying application files");
1436
+ copyAppSource(packageDir, installDir);
1437
+ s.stop("Application files installed");
1438
+ }
1439
+ function writeMetadata(installDir, vaultPath, version) {
1440
+ const metadata = {
1441
+ version,
1442
+ installedAt: (/* @__PURE__ */ new Date()).toISOString(),
1443
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1444
+ installDir,
1445
+ vaultPath
1446
+ };
1447
+ writeFileSync(join2(installDir, ".cognova"), JSON.stringify(metadata, null, 2));
1448
+ const homeMeta = join2(process.env.HOME || "~", ".cognova");
1449
+ writeFileSync(homeMeta, JSON.stringify(metadata, null, 2));
1450
+ }
1451
+
1452
+ // src/lib/vault.ts
1453
+ import { mkdirSync as mkdirSync2, existsSync as existsSync3 } from "fs";
1454
+ import { join as join3 } from "path";
1455
+ var PARA_FOLDERS = ["inbox", "areas", "projects", "resources", "archive"];
1456
+ async function setupVault() {
1457
+ const defaultPath = join3(process.env.HOME || "~", "vault");
1458
+ const vaultPath = await Ze({
1459
+ message: "Where should your vault be stored?",
1460
+ placeholder: defaultPath,
1461
+ defaultValue: defaultPath
1462
+ });
1463
+ if (Ct(vaultPath)) process.exit(0);
1464
+ const resolvedPath = vaultPath.replace("~", process.env.HOME || "");
1465
+ if (existsSync3(resolvedPath)) {
1466
+ R2.info(`Vault directory exists: ${resolvedPath}`);
1467
+ } else {
1468
+ const s = bt2();
1469
+ s.start("Creating vault with PARA structure");
1470
+ mkdirSync2(resolvedPath, { recursive: true });
1471
+ for (const folder of PARA_FOLDERS)
1472
+ mkdirSync2(join3(resolvedPath, folder), { recursive: true });
1473
+ s.stop("Vault created with PARA folders (inbox, areas, projects, resources, archive)");
1474
+ }
1475
+ for (const folder of PARA_FOLDERS) {
1476
+ const folderPath = join3(resolvedPath, folder);
1477
+ if (!existsSync3(folderPath))
1478
+ mkdirSync2(folderPath, { recursive: true });
1479
+ }
1480
+ return { path: resolvedPath };
1481
+ }
1482
+
1483
+ // src/lib/database.ts
1484
+ import { execSync as execSync2 } from "child_process";
1485
+ import crypto from "crypto";
1486
+ var import_picocolors4 = __toESM(require_picocolors(), 1);
1487
+ async function setupDatabase(hasDocker) {
1488
+ const dbType = await Je({
1489
+ message: "Database setup",
1490
+ options: [
1491
+ { value: "local", label: "Local PostgreSQL", hint: "Docker container (requires Docker)" },
1492
+ { value: "remote", label: "Remote PostgreSQL", hint: "Neon, Supabase, or other hosted" }
1493
+ ]
1494
+ });
1495
+ if (Ct(dbType)) process.exit(0);
1496
+ if (dbType === "local") {
1497
+ if (!hasDocker) {
1498
+ R2.error("Docker is required for local PostgreSQL.");
1499
+ R2.info("Install Docker: https://docs.docker.com/get-docker/");
1500
+ R2.info('Or choose "Remote PostgreSQL" and use Neon: https://neon.tech');
1501
+ process.exit(1);
1502
+ }
1503
+ const password = crypto.randomBytes(16).toString("hex");
1504
+ const containerName = "cognova-db";
1505
+ try {
1506
+ const existing = execSync2(`docker ps -a --filter name=${containerName} --format "{{.Status}}"`, {
1507
+ encoding: "utf-8"
1508
+ }).trim();
1509
+ if (existing) {
1510
+ R2.warn(`Container "${containerName}" already exists (${existing})`);
1511
+ const reuse = await Re({
1512
+ message: "Use existing container?",
1513
+ initialValue: true
1514
+ });
1515
+ if (Ct(reuse)) process.exit(0);
1516
+ if (reuse) {
1517
+ if (!existing.startsWith("Up"))
1518
+ execSync2(`docker start ${containerName}`, { stdio: "pipe" });
1519
+ R2.info("Using existing container. Ensure DATABASE_URL in .env matches its credentials.");
1520
+ const connStr = await Ze({
1521
+ message: "Connection string for existing container",
1522
+ placeholder: "postgres://postgres:password@localhost:5432/cognova",
1523
+ defaultValue: "postgres://postgres:postgres@localhost:5432/cognova"
1524
+ });
1525
+ if (Ct(connStr)) process.exit(0);
1526
+ return { type: "local", connectionString: connStr };
1527
+ }
1528
+ execSync2(`docker rm -f ${containerName}`, { stdio: "pipe" });
1529
+ }
1530
+ } catch {
1531
+ }
1532
+ const s = bt2();
1533
+ s.start("Starting PostgreSQL container");
1534
+ try {
1535
+ execSync2([
1536
+ "docker run -d",
1537
+ `--name ${containerName}`,
1538
+ `-e POSTGRES_USER=postgres`,
1539
+ `-e POSTGRES_PASSWORD=${password}`,
1540
+ `-e POSTGRES_DB=cognova`,
1541
+ `-p 5432:5432`,
1542
+ `--restart unless-stopped`,
1543
+ `postgres:16-alpine`
1544
+ ].join(" "), { stdio: "pipe" });
1545
+ let ready = false;
1546
+ for (let i = 0; i < 30; i++) {
1547
+ try {
1548
+ execSync2(`docker exec ${containerName} pg_isready -U postgres`, { stdio: "pipe" });
1549
+ ready = true;
1550
+ break;
1551
+ } catch {
1552
+ await sleep(1e3);
1553
+ }
1554
+ }
1555
+ if (!ready) {
1556
+ s.stop("PostgreSQL container started but not yet ready");
1557
+ R2.warn("Database may need a few more seconds to initialize");
1558
+ } else {
1559
+ s.stop("PostgreSQL is running");
1560
+ }
1561
+ } catch (err) {
1562
+ s.stop("Failed to start PostgreSQL");
1563
+ R2.error(`Docker error: ${err}`);
1564
+ process.exit(1);
1565
+ }
1566
+ const connectionString2 = `postgres://postgres:${password}@localhost:5432/cognova`;
1567
+ R2.info(`Connection: ${import_picocolors4.default.dim(connectionString2)}`);
1568
+ return { type: "local", connectionString: connectionString2 };
1569
+ }
1570
+ const connectionString = await Ze({
1571
+ message: "PostgreSQL connection string",
1572
+ placeholder: "postgres://user:pass@ep-xxx.us-east-2.aws.neon.tech/cognova?sslmode=require",
1573
+ validate: (v) => {
1574
+ if (!v.startsWith("postgres://") && !v.startsWith("postgresql://"))
1575
+ return "Must be a postgres:// or postgresql:// URL";
1576
+ }
1577
+ });
1578
+ if (Ct(connectionString)) process.exit(0);
1579
+ return { type: "remote", connectionString };
1580
+ }
1581
+ function sleep(ms) {
1582
+ return new Promise((resolve) => setTimeout(resolve, ms));
1583
+ }
1584
+
1585
+ // src/lib/config.ts
1586
+ import { writeFileSync as writeFileSync2 } from "fs";
1587
+ import { join as join4 } from "path";
1588
+
1589
+ // src/templates/env.ts
1590
+ import crypto2 from "crypto";
1591
+ function generateEnvFile(config) {
1592
+ const lines = [
1593
+ "# Cognova Configuration",
1594
+ "# Generated by cognova init",
1595
+ "",
1596
+ "# Database",
1597
+ `DATABASE_URL=${config.database.connectionString}`,
1598
+ "",
1599
+ "# Vault",
1600
+ `VAULT_PATH=${config.vault.path}`,
1601
+ "",
1602
+ "# Network",
1603
+ `ACCESS_MODE=${config.accessMode}`,
1604
+ ...config.accessMode !== "localhost" ? ["HOST=0.0.0.0"] : [],
1605
+ "",
1606
+ "# Auth",
1607
+ `BETTER_AUTH_SECRET=${config.auth.authSecret || crypto2.randomBytes(32).toString("base64")}`,
1608
+ `BETTER_AUTH_URL=${config.accessMode === "any" ? "" : config.appUrl}`,
1609
+ "",
1610
+ "# Admin (used on first startup to seed database)",
1611
+ `ADMIN_EMAIL=${config.auth.adminEmail}`,
1612
+ `ADMIN_PASSWORD=${config.auth.adminPassword}`,
1613
+ `ADMIN_NAME=${config.auth.adminName}`
1614
+ ];
1615
+ lines.push("");
1616
+ return lines.join("\n");
1617
+ }
1618
+
1619
+ // src/lib/config.ts
1620
+ function writeEnvFile(config) {
1621
+ const content = generateEnvFile(config);
1622
+ writeFileSync2(join4(config.installDir, ".env"), content);
1623
+ }
1624
+
1625
+ // src/lib/claude-config.ts
1626
+ import { cpSync as cpSync2, mkdirSync as mkdirSync3, existsSync as existsSync4, writeFileSync as writeFileSync3, readFileSync as readFileSync2 } from "fs";
1627
+ import { join as join5 } from "path";
1628
+
1629
+ // src/templates/claude-md.ts
1630
+ function generateClaudeMd(config) {
1631
+ const { personality, vault, database, appUrl, installDir } = config;
1632
+ const p = personality;
1633
+ return `# ${p.agentName}
1634
+
1635
+ You are ${p.agentName}, ${p.userName}'s personal knowledge management assistant running through **Cognova**. You operate directly on ${p.userName}'s machine via the Claude Agent SDK \u2014 you are not sandboxed.
1636
+
1637
+ ## What You Are
1638
+
1639
+ You are a Claude-powered agent embedded in a Cognova installation. ${p.userName} has granted you full system access: file system, shell, local services, and the Cognova API. You can read and write files, execute commands, manage processes, and interact with all Cognova features.
1640
+
1641
+ You run as a persistent service managed by PM2. Your conversations are streamed to ${p.userName} through the Cognova web dashboard.
1642
+
1643
+ ## Identity
1644
+
1645
+ - **Tone:** ${getToneDescription(p.tone, p.customTone)}
1646
+ - **Traits:** ${getTraitDescriptions(p.traits)}
1647
+ - **Communication:** ${getCommunicationDescription(p.communicationStyle)}
1648
+ - **Proactivity:** ${getProactivityDescription(p.proactivity)}
1649
+
1650
+ ## Environment
1651
+
1652
+ | Resource | Location |
1653
+ |----------|----------|
1654
+ | App URL | ${appUrl} |
1655
+ | API Base | ${appUrl}/api |
1656
+ | Install Dir | ${installDir} |
1657
+ | Vault | ${vault.path} (PARA method) |
1658
+ | Database | ${database.type === "local" ? "Local PostgreSQL (Docker)" : "Remote PostgreSQL"} |
1659
+ | Skills | ~/.claude/skills/ |
1660
+ | Process Manager | PM2 \u2014 \`pm2 status\`, \`pm2 logs cognova\` |
1661
+
1662
+ ## Skills
1663
+
1664
+ | Skill | Command | Purpose |
1665
+ |-------|---------|---------|
1666
+ | Task Management | \`/task\` | Create, list, update, complete tasks |
1667
+ | Project Management | \`/project\` | Organize tasks into projects |
1668
+ | Memory | \`/memory\` | Search past decisions, store insights |
1669
+ | Environment | \`/environment\` | Check system status, troubleshoot issues |
1670
+ | Skill Creator | \`/skill-creator\` | Create new Claude Code skills |
1671
+
1672
+ ## Hooks
1673
+
1674
+ | Hook | Trigger | Purpose |
1675
+ |------|---------|---------|
1676
+ | session-start | Session begins | Injects memory context |
1677
+ | pre-compact | Before compaction | Extracts memories before context trim |
1678
+ | stop-extract | After response | Async memory extraction |
1679
+ | session-end | Session ends | Logs session completion |
1680
+ | log-event | Tool use | Logs tool usage analytics |
1681
+
1682
+ ## Behaviors
1683
+
1684
+ ### Task Management
1685
+ ${getTaskBehavior(p)}
1686
+
1687
+ ### Note Organization
1688
+ - Vault uses PARA method: projects/, areas/, resources/, archive/, inbox/
1689
+ - Use lowercase-hyphenated filenames: \`project-ideas.md\`
1690
+ - Add frontmatter to all documents:
1691
+ \`\`\`yaml
1692
+ ---
1693
+ tags: []
1694
+ shared: false
1695
+ ---
1696
+ \`\`\`
1697
+ - Use wiki-style \`[[links]]\` for internal references
1698
+ - Split notes at ~500 lines or when covering multiple topics
1699
+
1700
+ ### Memory
1701
+ - Use the **database** for structured memory \u2014 not markdown context files
1702
+ - Store key decisions: \`/memory store --type decision "chose X because Y"\`
1703
+ - Check history before major changes: \`/memory about "topic"\`
1704
+ - Memory types: decision, fact, solution, pattern, preference, summary
1705
+ - Memories are auto-extracted from conversations via hooks
1706
+
1707
+ ### Troubleshooting
1708
+ - Use \`/environment status\` or \`/environment health\` to diagnose issues
1709
+ - Check logs: \`pm2 logs cognova --lines 50\`
1710
+ - Restart: \`pm2 restart cognova\`
1711
+
1712
+ ### Self-Modification
1713
+ - You MAY update this CLAUDE.md to refine your own behavior
1714
+ - You MAY create new skills in ~/.claude/skills/
1715
+ - You MAY update existing skills when you find improvements
1716
+ - Always inform ${p.userName} when modifying your own configuration
1717
+
1718
+ ## Vault Structure
1719
+
1720
+ \`\`\`
1721
+ ${vault.path}/
1722
+ inbox/ # Quick captures, unsorted notes
1723
+ areas/ # Ongoing responsibilities (health, finance, career)
1724
+ projects/ # Active projects with deadlines
1725
+ resources/ # Reference material, guides, templates
1726
+ archive/ # Completed or inactive items
1727
+ \`\`\`
1728
+ `;
1729
+ }
1730
+ function getToneDescription(tone, custom) {
1731
+ if (tone === "custom" && custom) return custom;
1732
+ const tones = {
1733
+ concise: "Be brief and to-the-point. Skip unnecessary preamble. Answer directly.",
1734
+ casual: "Be friendly and conversational. Use natural language. Light humor is fine.",
1735
+ formal: "Be professional and thorough. Provide context and reasoning."
1736
+ };
1737
+ return tones[tone] || tones.concise;
1738
+ }
1739
+ function getTraitDescriptions(traits) {
1740
+ const descriptions = {
1741
+ proactive: "Suggest actions and improvements without being asked",
1742
+ opinionated: "Have strong preferences on organization and push back on bad patterns",
1743
+ cautious: "Ask before making significant changes or deletions",
1744
+ curious: "Ask follow-up questions to understand the full picture",
1745
+ organized: "Prioritize consistency, naming conventions, and structure"
1746
+ };
1747
+ return traits.map((t) => descriptions[t] || t).join(". ") + ".";
1748
+ }
1749
+ function getCommunicationDescription(style) {
1750
+ const styles = {
1751
+ bullets: "Default to bulleted lists and structured output. Use tables for comparisons.",
1752
+ narrative: "Use flowing prose. Explain reasoning in paragraphs.",
1753
+ mixed: "Adapt format to the content \u2014 lists for action items, prose for explanations."
1754
+ };
1755
+ return styles[style] || styles.mixed;
1756
+ }
1757
+ function getProactivityDescription(level) {
1758
+ const levels = {
1759
+ reactive: "Only act when explicitly asked. Never create tasks or notes unsolicited.",
1760
+ balanced: "Suggest when context is clear \u2014 offer to create tasks for mentioned action items, but wait for confirmation.",
1761
+ proactive: "Actively create tasks for action items. Suggest note organization. Flag overdue items. Recommend archiving stale content."
1762
+ };
1763
+ return levels[level] || levels.balanced;
1764
+ }
1765
+ function getTaskBehavior(p) {
1766
+ if (p.proactivity === "proactive") {
1767
+ return `- When ${p.userName} mentions action items, create tasks automatically
1768
+ - Use \`/task create\` with appropriate priority and due dates
1769
+ - Associate with relevant projects when context is clear
1770
+ - Flag overdue tasks at the start of conversations
1771
+ - Suggest breaking large tasks into subtasks`;
1772
+ }
1773
+ if (p.proactivity === "reactive") {
1774
+ return `- Only create tasks when ${p.userName} explicitly asks
1775
+ - Use \`/task create\` with the details provided
1776
+ - Ask which project to associate with if unclear`;
1777
+ }
1778
+ return `- When ${p.userName} mentions action items, offer to create tasks
1779
+ - Use \`/task create\` with appropriate priority
1780
+ - Associate with relevant projects when context is clear
1781
+ - Confirm before creating tasks from implied action items`;
1782
+ }
1783
+
1784
+ // src/templates/settings-json.ts
1785
+ function generateSettingsJson(config) {
1786
+ const settings = {
1787
+ hooks: {
1788
+ SessionStart: [{
1789
+ hooks: [
1790
+ { type: "command", command: "python3 ~/.claude/hooks/session-start.py" }
1791
+ ]
1792
+ }],
1793
+ PreCompact: [{
1794
+ hooks: [
1795
+ { type: "command", command: "python3 ~/.claude/hooks/pre-compact.py" }
1796
+ ]
1797
+ }],
1798
+ Stop: [{
1799
+ hooks: [
1800
+ { type: "command", command: "python3 ~/.claude/hooks/stop-extract.py", timeout: 6e4 }
1801
+ ]
1802
+ }],
1803
+ SessionEnd: [{
1804
+ hooks: [
1805
+ { type: "command", command: "python3 ~/.claude/hooks/session-end.py" }
1806
+ ]
1807
+ }],
1808
+ PreToolUse: [
1809
+ {
1810
+ matcher: "Edit|Write|NotebookEdit",
1811
+ hooks: [
1812
+ { type: "command", command: "python3 ~/.claude/hooks/log-event.py PreToolUse" }
1813
+ ]
1814
+ },
1815
+ {
1816
+ matcher: "Bash",
1817
+ hooks: [
1818
+ { type: "command", command: "python3 ~/.claude/hooks/log-event.py PreToolUse" }
1819
+ ]
1820
+ }
1821
+ ],
1822
+ PostToolUse: [{
1823
+ matcher: "",
1824
+ hooks: [
1825
+ { type: "command", command: "python3 ~/.claude/hooks/log-event.py PostToolUse" }
1826
+ ]
1827
+ }]
1828
+ },
1829
+ env: {
1830
+ COGNOVA_API_URL: config.appUrl,
1831
+ COGNOVA_PROJECT_DIR: config.installDir
1832
+ }
1833
+ };
1834
+ return JSON.stringify(settings, null, 2) + "\n";
1835
+ }
1836
+
1837
+ // src/lib/claude-config.ts
1838
+ async function installClaudeConfig(config, options) {
1839
+ const claudeDir = getClaudeDir();
1840
+ const sourceDir = join5(getPackageDir(), "Claude");
1841
+ const installAll = !options;
1842
+ mkdirSync3(claudeDir, { recursive: true });
1843
+ if (installAll || options?.skills) {
1844
+ const skillsSrc = join5(sourceDir, "skills");
1845
+ if (existsSync4(skillsSrc))
1846
+ cpSync2(skillsSrc, join5(claudeDir, "skills"), { recursive: true, force: true });
1847
+ }
1848
+ if (installAll || options?.hooks) {
1849
+ const hooksSrc = join5(sourceDir, "hooks");
1850
+ if (existsSync4(hooksSrc))
1851
+ cpSync2(hooksSrc, join5(claudeDir, "hooks"), { recursive: true, force: true });
1852
+ }
1853
+ if (installAll || options?.rules) {
1854
+ const rulesSrc = join5(sourceDir, "rules");
1855
+ if (existsSync4(rulesSrc))
1856
+ cpSync2(rulesSrc, join5(claudeDir, "rules"), { recursive: true, force: true });
1857
+ }
1858
+ if (installAll || options?.claudeMd) {
1859
+ const claudeMdPath = join5(claudeDir, "CLAUDE.md");
1860
+ if (existsSync4(claudeMdPath) && installAll) {
1861
+ const overwrite = await Re({
1862
+ message: "~/.claude/CLAUDE.md already exists. Overwrite?",
1863
+ initialValue: false
1864
+ });
1865
+ if (Ct(overwrite)) process.exit(0);
1866
+ if (!overwrite) {
1867
+ R2.info("Keeping existing CLAUDE.md");
1868
+ } else {
1869
+ writeFileSync3(claudeMdPath, generateClaudeMd(config));
1870
+ }
1871
+ } else {
1872
+ writeFileSync3(claudeMdPath, generateClaudeMd(config));
1873
+ }
1874
+ }
1875
+ if (installAll || options?.settings) {
1876
+ const settingsPath = join5(claudeDir, "settings.json");
1877
+ if (existsSync4(settingsPath) && installAll) {
1878
+ try {
1879
+ const existing = JSON.parse(readFileSync2(settingsPath, "utf-8"));
1880
+ const generated = JSON.parse(generateSettingsJson(config));
1881
+ const merged = mergeSettings(existing, generated);
1882
+ writeFileSync3(settingsPath, JSON.stringify(merged, null, 2) + "\n");
1883
+ R2.info("Merged Cognova hooks into existing settings.json");
1884
+ } catch {
1885
+ writeFileSync3(settingsPath, generateSettingsJson(config));
1886
+ }
1887
+ } else {
1888
+ writeFileSync3(settingsPath, generateSettingsJson(config));
1889
+ }
1890
+ }
1891
+ }
1892
+ function syncClaudeConfig(sourceDir) {
1893
+ const claudeDir = getClaudeDir();
1894
+ const claudeSrc = join5(sourceDir, "Claude");
1895
+ if (!existsSync4(claudeSrc)) return;
1896
+ mkdirSync3(claudeDir, { recursive: true });
1897
+ const skillsSrc = join5(claudeSrc, "skills");
1898
+ if (existsSync4(skillsSrc)) {
1899
+ mkdirSync3(join5(claudeDir, "skills"), { recursive: true });
1900
+ cpSync2(skillsSrc, join5(claudeDir, "skills"), { recursive: true, force: true });
1901
+ }
1902
+ const hooksSrc = join5(claudeSrc, "hooks");
1903
+ if (existsSync4(hooksSrc)) {
1904
+ mkdirSync3(join5(claudeDir, "hooks"), { recursive: true });
1905
+ cpSync2(hooksSrc, join5(claudeDir, "hooks"), { recursive: true, force: true });
1906
+ }
1907
+ const rulesSrc = join5(claudeSrc, "rules");
1908
+ if (existsSync4(rulesSrc)) {
1909
+ mkdirSync3(join5(claudeDir, "rules"), { recursive: true });
1910
+ cpSync2(rulesSrc, join5(claudeDir, "rules"), { recursive: true, force: true });
1911
+ }
1912
+ }
1913
+ function mergeSettings(existing, generated) {
1914
+ const result = { ...existing };
1915
+ if (generated.env) {
1916
+ result.env = { ...existing.env || {}, ...generated.env };
1917
+ }
1918
+ if (generated.hooks) {
1919
+ result.hooks = generated.hooks;
1920
+ }
1921
+ return result;
1922
+ }
1923
+
1924
+ // src/lib/process-manager.ts
1925
+ import { execSync as execSync3 } from "child_process";
1926
+ import { writeFileSync as writeFileSync4, mkdirSync as mkdirSync4, existsSync as existsSync5 } from "fs";
1927
+ import { join as join6 } from "path";
1928
+
1929
+ // src/templates/pm2-ecosystem.ts
1930
+ function generatePm2Ecosystem(config) {
1931
+ return `const { readFileSync } = require('fs')
1932
+ const { join } = require('path')
1933
+
1934
+ // Load .env file into env vars for PM2
1935
+ function loadEnv(dir) {
1936
+ try {
1937
+ const content = readFileSync(join(dir, '.env'), 'utf-8')
1938
+ const env = {}
1939
+ for (const line of content.split('\\n')) {
1940
+ const trimmed = line.trim()
1941
+ if (!trimmed || trimmed.startsWith('#')) continue
1942
+ const eq = trimmed.indexOf('=')
1943
+ if (eq === -1) continue
1944
+ env[trimmed.slice(0, eq)] = trimmed.slice(eq + 1)
1945
+ }
1946
+ return env
1947
+ } catch { return {} }
1948
+ }
1949
+
1950
+ const dotenv = loadEnv('${config.installDir}')
1951
+
1952
+ module.exports = {
1953
+ apps: [{
1954
+ name: 'cognova',
1955
+ script: '.output/server/index.mjs',
1956
+ cwd: '${config.installDir}',
1957
+ node_args: '--max-old-space-size=4096',
1958
+ env: {
1959
+ ...dotenv,
1960
+ NODE_ENV: 'production',
1961
+ PORT: 3000,
1962
+ COGNOVA_PROJECT_DIR: '${config.installDir}'
1963
+ },
1964
+ // Restart on crash
1965
+ autorestart: true,
1966
+ max_restarts: 10,
1967
+ restart_delay: 5000,
1968
+ // Logging
1969
+ log_date_format: 'YYYY-MM-DD HH:mm:ss',
1970
+ error_file: '${config.installDir}/logs/error.log',
1971
+ out_file: '${config.installDir}/logs/out.log',
1972
+ merge_logs: true
1973
+ }]
1974
+ }
1975
+ `;
1976
+ }
1977
+
1978
+ // src/lib/process-manager.ts
1979
+ async function setupAndStart(config) {
1980
+ try {
1981
+ execSync3("pm2 --version", { stdio: "pipe" });
1982
+ } catch {
1983
+ const install = await Re({
1984
+ message: "PM2 not found. Install it globally?",
1985
+ initialValue: true
1986
+ });
1987
+ if (Ct(install)) process.exit(0);
1988
+ if (install) {
1989
+ const s2 = bt2();
1990
+ s2.start("Installing PM2");
1991
+ const cmd = process.platform === "linux" ? "sudo npm install -g pm2" : "npm install -g pm2";
1992
+ execSync3(cmd, { stdio: "inherit" });
1993
+ s2.stop("PM2 installed");
1994
+ } else {
1995
+ R2.warn("Skipping PM2. Start manually with: node .output/server/index.mjs");
1996
+ return;
1997
+ }
1998
+ }
1999
+ const logsDir = join6(config.installDir, "logs");
2000
+ if (!existsSync5(logsDir))
2001
+ mkdirSync4(logsDir, { recursive: true });
2002
+ const ecosystem = generatePm2Ecosystem(config);
2003
+ writeFileSync4(join6(config.installDir, "ecosystem.config.cjs"), ecosystem);
2004
+ const s = bt2();
2005
+ s.start("Starting Cognova with PM2");
2006
+ try {
2007
+ execSync3("pm2 start ecosystem.config.cjs", {
2008
+ cwd: config.installDir,
2009
+ stdio: "pipe"
2010
+ });
2011
+ s.stop("Cognova is running");
2012
+ } catch (err) {
2013
+ s.stop("Failed to start");
2014
+ R2.error(`PM2 error: ${err}`);
2015
+ }
2016
+ }
2017
+
2018
+ // src/lib/health.ts
2019
+ import { execSync as execSync4 } from "child_process";
2020
+ async function waitForHealth(url, maxWaitSeconds = 30) {
2021
+ const s = bt2();
2022
+ s.start("Waiting for app to become healthy");
2023
+ for (let i = 0; i < maxWaitSeconds; i++) {
2024
+ try {
2025
+ const result = execSync4(`curl -sf ${url}/api/health`, { encoding: "utf-8", timeout: 3e3 });
2026
+ const data = JSON.parse(result);
2027
+ if (data.status === "ok") {
2028
+ s.stop("App is healthy");
2029
+ return true;
2030
+ }
2031
+ } catch {
2032
+ }
2033
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
2034
+ }
2035
+ s.stop("App did not become healthy in time");
2036
+ R2.warn(`Check logs: pm2 logs cognova`);
2037
+ return false;
2038
+ }
2039
+
2040
+ // src/commands/init.ts
2041
+ async function init() {
2042
+ We(import_picocolors5.default.bgCyan(import_picocolors5.default.black(" Cognova Setup ")));
2043
+ const prereqs = await checkPrerequisites();
2044
+ R2.step(import_picocolors5.default.bold("Agent Personality"));
2045
+ const personality = await promptPersonality();
2046
+ R2.step(import_picocolors5.default.bold("Installation"));
2047
+ const defaultDir = join7(process.env.HOME || "~", "cognova");
2048
+ const installDir = await Ze({
2049
+ message: "Where should Cognova be installed?",
2050
+ placeholder: defaultDir,
2051
+ defaultValue: defaultDir
2052
+ });
2053
+ if (Ct(installDir)) process.exit(0);
2054
+ const resolvedInstallDir = installDir.replace("~", process.env.HOME || "");
2055
+ await setupInstallDir(resolvedInstallDir);
2056
+ R2.step(import_picocolors5.default.bold("Vault"));
2057
+ const vault = await setupVault();
2058
+ R2.step(import_picocolors5.default.bold("Database"));
2059
+ const database = await setupDatabase(prereqs.hasDocker);
2060
+ R2.step(import_picocolors5.default.bold("Network Access"));
2061
+ const accessMode = await Je({
2062
+ message: "How will you access Cognova?",
2063
+ options: [
2064
+ { value: "localhost", label: "Local only", hint: "http://localhost:3000" },
2065
+ { value: "specific", label: "Specific IP or domain", hint: "LAN IP, hostname, or domain" },
2066
+ { value: "any", label: "Any connection", hint: "Accepts requests from any origin (0.0.0.0)" }
2067
+ ]
2068
+ });
2069
+ if (Ct(accessMode)) process.exit(0);
2070
+ let appUrl = "http://localhost:3000";
2071
+ if (accessMode === "specific") {
2072
+ const host = await Ze({
2073
+ message: "IP address or domain (include port if not 80/443)",
2074
+ placeholder: "192.168.1.100:3000"
2075
+ });
2076
+ if (Ct(host)) process.exit(0);
2077
+ appUrl = host.startsWith("http") ? host : `http://${host}`;
2078
+ }
2079
+ R2.warn(import_picocolors5.default.yellow(import_picocolors5.default.bold("Security Notice")));
2080
+ R2.warn([
2081
+ "Cognova gives an AI agent unrestricted access to this machine.",
2082
+ "It can read, write, and execute anything via the embedded terminal",
2083
+ "and Claude Code CLI.",
2084
+ "",
2085
+ ` ${import_picocolors5.default.dim("\u2022")} Do not run on a personal machine or alongside sensitive data`,
2086
+ ` ${import_picocolors5.default.dim("\u2022")} Use a dedicated VM, container, or isolated environment`,
2087
+ ` ${import_picocolors5.default.dim("\u2022")} Put a reverse proxy with TLS in front for remote access`,
2088
+ ` ${import_picocolors5.default.dim("\u2022")} Do not store SSH keys, cloud creds, or production secrets here`
2089
+ ].join("\n"));
2090
+ if (accessMode === "any") {
2091
+ R2.warn(import_picocolors5.default.red(
2092
+ "Binding to 0.0.0.0 exposes this to your entire network."
2093
+ ));
2094
+ }
2095
+ const proceed = await Re({
2096
+ message: "I understand the risks. Continue?",
2097
+ initialValue: false
2098
+ });
2099
+ if (Ct(proceed) || !proceed) process.exit(0);
2100
+ R2.step(import_picocolors5.default.bold("Authentication"));
2101
+ const adminEmail = await Ze({
2102
+ message: "Admin email",
2103
+ placeholder: "admin@example.com",
2104
+ defaultValue: "admin@example.com"
2105
+ });
2106
+ if (Ct(adminEmail)) process.exit(0);
2107
+ let adminPassword;
2108
+ while (true) {
2109
+ const pw = await He({
2110
+ message: "Admin password",
2111
+ validate: (v) => {
2112
+ if (!v || v.length < 8) return "Minimum 8 characters";
2113
+ }
2114
+ });
2115
+ if (Ct(pw)) process.exit(0);
2116
+ const confirm = await He({
2117
+ message: "Confirm password"
2118
+ });
2119
+ if (Ct(confirm)) process.exit(0);
2120
+ if (pw === confirm) {
2121
+ adminPassword = pw;
2122
+ break;
2123
+ }
2124
+ R2.warn("Passwords do not match. Try again.");
2125
+ }
2126
+ const adminName = await Ze({
2127
+ message: "Admin display name",
2128
+ placeholder: personality.userName,
2129
+ defaultValue: personality.userName
2130
+ });
2131
+ if (Ct(adminName)) process.exit(0);
2132
+ const config = {
2133
+ personality,
2134
+ vault,
2135
+ database,
2136
+ auth: {
2137
+ adminEmail,
2138
+ adminPassword,
2139
+ adminName,
2140
+ authSecret: crypto3.randomBytes(32).toString("base64")
2141
+ },
2142
+ appUrl,
2143
+ accessMode,
2144
+ installDir: resolvedInstallDir
2145
+ };
2146
+ R2.step(import_picocolors5.default.bold("Configuration"));
2147
+ const s = bt2();
2148
+ s.start("Writing .env");
2149
+ writeEnvFile(config);
2150
+ s.stop(".env created");
2151
+ s.start("Installing Claude Code configuration");
2152
+ await installClaudeConfig(config);
2153
+ s.stop("Claude config installed to ~/.claude/");
2154
+ writeMetadata(resolvedInstallDir, vault.path, "0.1.0");
2155
+ R2.step(import_picocolors5.default.bold("Build"));
2156
+ s.start("Installing dependencies");
2157
+ execSync5("pnpm install", { cwd: resolvedInstallDir, stdio: "pipe" });
2158
+ s.stop("Dependencies installed");
2159
+ s.start("Building application (this may take a few minutes)");
2160
+ execSync5("pnpm build", {
2161
+ cwd: resolvedInstallDir,
2162
+ stdio: "pipe",
2163
+ timeout: 6e5,
2164
+ env: { ...process.env, NODE_OPTIONS: "--max-old-space-size=4096" }
2165
+ });
2166
+ s.stop("Build complete");
2167
+ R2.step(import_picocolors5.default.bold("Launch"));
2168
+ await setupAndStart(config);
2169
+ await waitForHealth("http://localhost:3000");
2170
+ R2.step(import_picocolors5.default.bold("Summary"));
2171
+ R2.info([
2172
+ "",
2173
+ ` ${import_picocolors5.default.cyan("App URL:")} ${config.appUrl}`,
2174
+ ` ${import_picocolors5.default.cyan("Admin Login:")} ${config.auth.adminEmail}`,
2175
+ ` ${import_picocolors5.default.cyan("Vault:")} ${vault.path}`,
2176
+ ` ${import_picocolors5.default.cyan("Install Dir:")} ${resolvedInstallDir}`,
2177
+ ` ${import_picocolors5.default.cyan("Agent:")} ${personality.agentName}`,
2178
+ "",
2179
+ ` ${import_picocolors5.default.dim("Manage:")}`,
2180
+ ` cognova start Start the app`,
2181
+ ` cognova stop Stop the app`,
2182
+ ` cognova restart Restart the app`,
2183
+ ` cognova update Update to latest version`,
2184
+ ` cognova doctor Check health`,
2185
+ ` cognova reset Re-generate configs`,
2186
+ "",
2187
+ ` pm2 logs cognova View logs`,
2188
+ ` pm2 monit Monitor resources`,
2189
+ ""
2190
+ ].join("\n"));
2191
+ Le(`${personality.agentName} is ready. Open ${import_picocolors5.default.underline(config.appUrl)} to get started.`);
2192
+ }
2193
+
2194
+ // src/commands/start.ts
2195
+ import { execSync as execSync6 } from "child_process";
2196
+ import { existsSync as existsSync6 } from "fs";
2197
+ import { join as join8 } from "path";
2198
+ async function start() {
2199
+ const installDir = findInstallDir();
2200
+ const ecosystem = join8(installDir, "ecosystem.config.cjs");
2201
+ if (!existsSync6(ecosystem)) {
2202
+ console.error("No ecosystem.config.cjs found. Run `cognova init` first.");
2203
+ process.exit(1);
2204
+ }
2205
+ execSync6("pm2 start ecosystem.config.cjs", { cwd: installDir, stdio: "inherit" });
2206
+ console.log("Cognova started.");
2207
+ }
2208
+ async function stop() {
2209
+ try {
2210
+ execSync6("pm2 stop cognova", { stdio: "inherit" });
2211
+ console.log("Cognova stopped.");
2212
+ } catch {
2213
+ console.error("Failed to stop. Is Cognova running?");
2214
+ }
2215
+ }
2216
+ async function restart() {
2217
+ try {
2218
+ execSync6("pm2 restart cognova", { stdio: "inherit" });
2219
+ console.log("Cognova restarted.");
2220
+ } catch {
2221
+ console.error("Failed to restart. Is Cognova running?");
2222
+ }
2223
+ }
2224
+
2225
+ // src/commands/update.ts
2226
+ import { execSync as execSync7 } from "child_process";
2227
+ import { existsSync as existsSync7, cpSync as cpSync3, rmSync } from "fs";
2228
+ import { join as join9 } from "path";
2229
+ var import_picocolors6 = __toESM(require_picocolors(), 1);
2230
+ var BACKUP_ITEMS = [
2231
+ "app",
2232
+ "server",
2233
+ "shared",
2234
+ "Claude",
2235
+ "nuxt.config.ts",
2236
+ "tsconfig.json",
2237
+ "drizzle.config.ts",
2238
+ "package.json",
2239
+ "pnpm-lock.yaml"
2240
+ ];
2241
+ function createBackup(installDir) {
2242
+ const backupDir = join9(installDir, ".update-backup");
2243
+ if (existsSync7(backupDir))
2244
+ rmSync(backupDir, { recursive: true });
2245
+ for (const item of BACKUP_ITEMS) {
2246
+ const src = join9(installDir, item);
2247
+ if (!existsSync7(src)) continue;
2248
+ const dest = join9(backupDir, item);
2249
+ cpSync3(src, dest, { recursive: true });
2250
+ }
2251
+ return backupDir;
2252
+ }
2253
+ function restoreBackup(installDir, backupDir) {
2254
+ for (const item of BACKUP_ITEMS) {
2255
+ const src = join9(backupDir, item);
2256
+ if (!existsSync7(src)) continue;
2257
+ const dest = join9(installDir, item);
2258
+ if (existsSync7(dest))
2259
+ rmSync(dest, { recursive: true });
2260
+ cpSync3(src, dest, { recursive: true });
2261
+ }
2262
+ }
2263
+ function cleanupBackup(backupDir) {
2264
+ if (existsSync7(backupDir))
2265
+ rmSync(backupDir, { recursive: true });
2266
+ }
2267
+ async function update() {
2268
+ We(import_picocolors6.default.bgCyan(import_picocolors6.default.black(" Cognova Update ")));
2269
+ const installDir = findInstallDir();
2270
+ const metadata = readMetadata(installDir);
2271
+ if (!metadata) {
2272
+ R2.error("No Cognova installation found. Run `cognova init` first.");
2273
+ process.exit(1);
2274
+ }
2275
+ const s = bt2();
2276
+ s.start("Checking for updates");
2277
+ let latestVersion;
2278
+ try {
2279
+ latestVersion = execSync7("npm view cognova version", { encoding: "utf-8" }).trim();
2280
+ } catch {
2281
+ s.stop("Could not check npm registry");
2282
+ R2.warn("Unable to check for updates. Rebuilding current version.");
2283
+ latestVersion = metadata.version;
2284
+ }
2285
+ if (latestVersion === metadata.version) {
2286
+ s.stop(`Already on latest version (${metadata.version})`);
2287
+ } else {
2288
+ s.stop(`Update available: ${metadata.version} \u2192 ${import_picocolors6.default.green(latestVersion)}`);
2289
+ }
2290
+ s.start("Creating backup");
2291
+ const backupDir = createBackup(installDir);
2292
+ s.stop("Backup created");
2293
+ let updateFailed = false;
2294
+ try {
2295
+ if (latestVersion !== metadata.version) {
2296
+ s.start("Downloading latest version");
2297
+ const tmpDir = execSync7("mktemp -d", { encoding: "utf-8" }).trim();
2298
+ try {
2299
+ execSync7(`npm pack cognova@${latestVersion} --pack-destination ${tmpDir}`, { stdio: "pipe" });
2300
+ execSync7(`tar -xzf ${tmpDir}/cognova-${latestVersion}.tgz -C ${tmpDir}`, { stdio: "pipe" });
2301
+ copyAppSource(`${tmpDir}/package`, installDir);
2302
+ s.stop("Source files updated");
2303
+ } finally {
2304
+ rmSync(tmpDir, { recursive: true, force: true });
2305
+ }
2306
+ }
2307
+ s.start("Syncing Claude config");
2308
+ syncClaudeConfig(installDir);
2309
+ s.stop("Claude config synced (skills, hooks, rules)");
2310
+ s.start("Installing dependencies");
2311
+ execSync7("pnpm install", { cwd: installDir, stdio: "pipe" });
2312
+ s.stop("Dependencies installed");
2313
+ s.start("Running database migrations");
2314
+ try {
2315
+ execSync7("pnpm db:migrate", { cwd: installDir, stdio: "pipe" });
2316
+ s.stop("Migrations complete");
2317
+ } catch (migErr) {
2318
+ s.stop(import_picocolors6.default.yellow("Migration warning"));
2319
+ R2.warn(`Database migration issue: ${migErr instanceof Error ? migErr.message : migErr}`);
2320
+ R2.warn("The app may still work. Check logs after starting.");
2321
+ }
2322
+ s.start("Building application");
2323
+ execSync7("pnpm build", {
2324
+ cwd: installDir,
2325
+ stdio: "pipe",
2326
+ timeout: 6e5,
2327
+ env: { ...process.env, NODE_OPTIONS: "--max-old-space-size=4096" }
2328
+ });
2329
+ s.stop("Build complete");
2330
+ } catch (err) {
2331
+ updateFailed = true;
2332
+ s.stop(import_picocolors6.default.red("Update failed"));
2333
+ R2.error(`Error: ${err instanceof Error ? err.message : err}`);
2334
+ R2.step(import_picocolors6.default.bold("Rolling back"));
2335
+ const rollbackSpinner = bt2();
2336
+ rollbackSpinner.start("Restoring previous version");
2337
+ try {
2338
+ restoreBackup(installDir, backupDir);
2339
+ execSync7("pnpm install", { cwd: installDir, stdio: "pipe" });
2340
+ rollbackSpinner.stop("Previous version restored");
2341
+ R2.info("Your previous installation has been restored.");
2342
+ } catch (rollbackErr) {
2343
+ rollbackSpinner.stop(import_picocolors6.default.red("Rollback failed"));
2344
+ R2.error(`Rollback failed: ${rollbackErr instanceof Error ? rollbackErr.message : rollbackErr}`);
2345
+ R2.error(`Manual recovery: backup is at ${backupDir}`);
2346
+ Le("Update and rollback both failed. See errors above.");
2347
+ process.exit(1);
2348
+ }
2349
+ }
2350
+ if (!updateFailed)
2351
+ cleanupBackup(backupDir);
2352
+ if (updateFailed) {
2353
+ Le("Update failed. Previous version has been restored. Try again later.");
2354
+ process.exit(1);
2355
+ }
2356
+ s.start("Restarting application");
2357
+ try {
2358
+ execSync7("pm2 restart cognova", { stdio: "pipe" });
2359
+ s.stop("Application restarted");
2360
+ } catch {
2361
+ s.stop("PM2 restart failed \u2014 start manually with `cognova start`");
2362
+ }
2363
+ R2.info(`Run ${import_picocolors6.default.cyan("cognova reset")} to regenerate CLAUDE.md or settings.json.`);
2364
+ Le(`Updated to v${latestVersion}`);
2365
+ }
2366
+
2367
+ // src/commands/doctor.ts
2368
+ import { execSync as execSync8 } from "child_process";
2369
+ import { existsSync as existsSync8 } from "fs";
2370
+ import { join as join10 } from "path";
2371
+ var import_picocolors7 = __toESM(require_picocolors(), 1);
2372
+ async function doctor() {
2373
+ We(import_picocolors7.default.bgCyan(import_picocolors7.default.black(" Cognova Doctor ")));
2374
+ const installDir = findInstallDir();
2375
+ const claudeDir = getClaudeDir();
2376
+ const metadata = readMetadata(installDir);
2377
+ if (metadata) {
2378
+ R2.info(`Install: ${metadata.installDir} (v${metadata.version})`);
2379
+ }
2380
+ const checks = [
2381
+ {
2382
+ name: ".env file",
2383
+ check: () => existsSync8(join10(installDir, ".env"))
2384
+ },
2385
+ {
2386
+ name: "node_modules",
2387
+ check: () => existsSync8(join10(installDir, "node_modules"))
2388
+ },
2389
+ {
2390
+ name: "Build output",
2391
+ check: () => existsSync8(join10(installDir, ".output", "server", "index.mjs"))
2392
+ },
2393
+ {
2394
+ name: "~/.claude/CLAUDE.md",
2395
+ check: () => existsSync8(join10(claudeDir, "CLAUDE.md"))
2396
+ },
2397
+ {
2398
+ name: "~/.claude/skills/",
2399
+ check: () => existsSync8(join10(claudeDir, "skills"))
2400
+ },
2401
+ {
2402
+ name: "~/.claude/hooks/",
2403
+ check: () => existsSync8(join10(claudeDir, "hooks"))
2404
+ },
2405
+ {
2406
+ name: "~/.claude/rules/",
2407
+ check: () => existsSync8(join10(claudeDir, "rules"))
2408
+ },
2409
+ {
2410
+ name: "~/.claude/settings.json",
2411
+ check: () => existsSync8(join10(claudeDir, "settings.json"))
2412
+ },
2413
+ {
2414
+ name: "Claude Code CLI",
2415
+ check: () => {
2416
+ try {
2417
+ execSync8("claude --version", { stdio: "pipe" });
2418
+ return true;
2419
+ } catch {
2420
+ return false;
2421
+ }
2422
+ }
2423
+ },
2424
+ {
2425
+ name: "Python 3",
2426
+ check: () => {
2427
+ try {
2428
+ execSync8("python3 --version", { stdio: "pipe" });
2429
+ return true;
2430
+ } catch {
2431
+ return false;
2432
+ }
2433
+ }
2434
+ },
2435
+ {
2436
+ name: "PM2 process",
2437
+ check: () => {
2438
+ try {
2439
+ const out = execSync8("pm2 jlist", { encoding: "utf-8" });
2440
+ const procs = JSON.parse(out);
2441
+ return procs.some(
2442
+ (proc) => proc.name === "cognova" && proc.pm2_env?.status === "online"
2443
+ );
2444
+ } catch {
2445
+ return false;
2446
+ }
2447
+ }
2448
+ },
2449
+ {
2450
+ name: "App health endpoint",
2451
+ check: () => {
2452
+ try {
2453
+ const result = execSync8("curl -sf http://localhost:3000/api/health", { encoding: "utf-8" });
2454
+ const data = JSON.parse(result);
2455
+ return data.status === "ok";
2456
+ } catch {
2457
+ return false;
2458
+ }
2459
+ }
2460
+ },
2461
+ {
2462
+ name: "Database connection",
2463
+ check: () => {
2464
+ try {
2465
+ const result = execSync8("curl -sf http://localhost:3000/api/health", { encoding: "utf-8" });
2466
+ const data = JSON.parse(result);
2467
+ return data.database?.available === true;
2468
+ } catch {
2469
+ return false;
2470
+ }
2471
+ }
2472
+ },
2473
+ {
2474
+ name: "Vault directory",
2475
+ check: () => {
2476
+ if (!metadata) return false;
2477
+ return existsSync8(metadata.vaultPath);
2478
+ }
2479
+ },
2480
+ {
2481
+ name: "Version up to date",
2482
+ check: () => {
2483
+ if (!metadata) return "unknown";
2484
+ try {
2485
+ const latest = execSync8("npm view cognova version", { encoding: "utf-8" }).trim();
2486
+ return latest === metadata.version ? true : `outdated (${metadata.version} \u2192 ${latest})`;
2487
+ } catch {
2488
+ return "could not check";
2489
+ }
2490
+ }
2491
+ }
2492
+ ];
2493
+ let passed = 0;
2494
+ let failed = 0;
2495
+ for (const { name, check } of checks) {
2496
+ try {
2497
+ const result = check();
2498
+ if (result === true) {
2499
+ R2.success(`${import_picocolors7.default.green("PASS")} ${name}`);
2500
+ passed++;
2501
+ } else if (result === false) {
2502
+ R2.error(`${import_picocolors7.default.red("FAIL")} ${name}`);
2503
+ failed++;
2504
+ } else {
2505
+ R2.warn(`${import_picocolors7.default.yellow("WARN")} ${name}: ${result}`);
2506
+ }
2507
+ } catch {
2508
+ R2.error(`${import_picocolors7.default.red("FAIL")} ${name}`);
2509
+ failed++;
2510
+ }
2511
+ }
2512
+ Le(`${passed} passed, ${failed} failed`);
2513
+ }
2514
+
2515
+ // src/commands/reset.ts
2516
+ var import_picocolors8 = __toESM(require_picocolors(), 1);
2517
+ async function reset() {
2518
+ We(import_picocolors8.default.bgCyan(import_picocolors8.default.black(" Cognova Reset ")));
2519
+ const installDir = findInstallDir();
2520
+ const metadata = readMetadata(installDir);
2521
+ if (!metadata) {
2522
+ R2.error("No Cognova installation found. Run `cognova init` first.");
2523
+ process.exit(1);
2524
+ }
2525
+ const what = await je({
2526
+ message: "What do you want to reset?",
2527
+ options: [
2528
+ { value: "claude-md", label: "CLAUDE.md", hint: "Re-generate agent identity (re-runs personality prompts)" },
2529
+ { value: "skills", label: "Skills", hint: "Re-copy skills to ~/.claude/skills/" },
2530
+ { value: "hooks", label: "Hooks", hint: "Re-copy hooks to ~/.claude/hooks/" },
2531
+ { value: "rules", label: "Rules", hint: "Re-copy rules to ~/.claude/rules/" },
2532
+ { value: "settings", label: "Settings", hint: "Re-generate ~/.claude/settings.json" }
2533
+ ],
2534
+ required: true
2535
+ });
2536
+ if (Ct(what)) {
2537
+ Ne("Reset cancelled.");
2538
+ process.exit(0);
2539
+ }
2540
+ const items = what;
2541
+ let personality = null;
2542
+ if (items.includes("claude-md")) {
2543
+ R2.info("Let's reconfigure your agent personality.");
2544
+ personality = await promptPersonality();
2545
+ }
2546
+ const s = bt2();
2547
+ s.start("Resetting configuration");
2548
+ await installClaudeConfig({
2549
+ personality: personality || {
2550
+ agentName: "Cognova",
2551
+ userName: "User",
2552
+ tone: "concise",
2553
+ traits: ["organized"],
2554
+ communicationStyle: "mixed",
2555
+ proactivity: "balanced"
2556
+ },
2557
+ vault: { path: metadata.vaultPath },
2558
+ database: { type: "remote", connectionString: "" },
2559
+ auth: { adminEmail: "", adminPassword: "", adminName: "", authSecret: "" },
2560
+ appUrl: "http://localhost:3000",
2561
+ accessMode: "localhost",
2562
+ installDir: metadata.installDir
2563
+ }, {
2564
+ claudeMd: items.includes("claude-md"),
2565
+ skills: items.includes("skills"),
2566
+ hooks: items.includes("hooks"),
2567
+ rules: items.includes("rules"),
2568
+ settings: items.includes("settings")
2569
+ });
2570
+ s.stop("Configuration reset");
2571
+ Le("Done! Changes will take effect in your next Claude Code session.");
2572
+ }
2573
+
2574
+ // src/index.ts
2575
+ var __filename2 = fileURLToPath2(import.meta.url);
2576
+ var __dirname2 = dirname2(__filename2);
2577
+ function getVersion() {
2578
+ try {
2579
+ const pkg = JSON.parse(readFileSync3(join11(__dirname2, "..", "..", "package.json"), "utf-8"));
2580
+ return pkg.version || "0.0.0";
2581
+ } catch {
2582
+ return "0.0.0";
2583
+ }
2584
+ }
2585
+ var HELP_TEXT = `
2586
+ cognova v${getVersion()} \u2014 Personal knowledge management with Claude Code
2587
+
2588
+ Usage: cognova <command> [options]
2589
+
2590
+ Commands:
2591
+ init Interactive setup wizard
2592
+ start Start Cognova (PM2)
2593
+ stop Stop Cognova
2594
+ restart Restart Cognova
2595
+ update Update to latest version
2596
+ doctor Check health of all components
2597
+ reset Re-generate configuration files
2598
+
2599
+ Options:
2600
+ --help, -h Show this help message
2601
+ --version, -v Show version number
2602
+
2603
+ Run 'cognova <command> --help' for command-specific help.
2604
+ `;
2605
+ var COMMAND_HELP = {
2606
+ init: `
2607
+ cognova init \u2014 Interactive setup wizard
2608
+
2609
+ Sets up a new Cognova installation:
2610
+ 1. Checks prerequisites (Node 22+, Python 3, pnpm, Docker)
2611
+ 2. Configures agent personality (name, tone, traits)
2612
+ 3. Chooses install directory
2613
+ 4. Sets up vault (PARA folder structure)
2614
+ 5. Configures database (local Docker or remote PostgreSQL)
2615
+ 6. Sets network access mode
2616
+ 7. Creates admin credentials
2617
+ 8. Installs dependencies, builds, and starts with PM2
2618
+
2619
+ Usage: cognova init
2620
+ `,
2621
+ start: `
2622
+ cognova start \u2014 Start Cognova
2623
+
2624
+ Starts the application using PM2 process manager.
2625
+ Requires a prior 'cognova init' to have been run.
2626
+
2627
+ Usage: cognova start
2628
+ `,
2629
+ stop: `
2630
+ cognova stop \u2014 Stop Cognova
2631
+
2632
+ Stops the PM2 process. Data and configuration are preserved.
2633
+
2634
+ Usage: cognova stop
2635
+ `,
2636
+ restart: `
2637
+ cognova restart \u2014 Restart Cognova
2638
+
2639
+ Restarts the PM2 process. Useful after manual config changes.
2640
+
2641
+ Usage: cognova restart
2642
+ `,
2643
+ update: `
2644
+ cognova update \u2014 Update to latest version
2645
+
2646
+ Checks npm registry for a newer version, downloads and installs it.
2647
+ Preserves: .env, .api-token, ecosystem.config.cjs, logs/
2648
+ Runs database migrations and rebuilds automatically.
2649
+ Creates a backup before updating so failed updates can be rolled back.
2650
+
2651
+ Usage: cognova update
2652
+ `,
2653
+ doctor: `
2654
+ cognova doctor \u2014 Check health of all components
2655
+
2656
+ Runs diagnostic checks on your installation:
2657
+ - Configuration files (.env, Claude config)
2658
+ - Dependencies (Node, Python, Claude Code CLI)
2659
+ - Build output
2660
+ - PM2 process status
2661
+ - App health endpoint
2662
+ - Database connection
2663
+ - Vault directory
2664
+ - Version status
2665
+
2666
+ Usage: cognova doctor
2667
+ `,
2668
+ reset: `
2669
+ cognova reset \u2014 Re-generate configuration files
2670
+
2671
+ Interactively choose which config files to regenerate:
2672
+ - CLAUDE.md (agent identity \u2014 re-runs personality prompts)
2673
+ - Skills, Hooks, Rules (re-copy from bundled defaults)
2674
+ - settings.json (Claude Code hook configuration)
2675
+
2676
+ Usage: cognova reset
2677
+ `
2678
+ };
2679
+ var args = process.argv.slice(2);
2680
+ var command = args.find((a) => !a.startsWith("-"));
2681
+ var flags = new Set(args.filter((a) => a.startsWith("-")));
2682
+ if (flags.has("--version") || flags.has("-v")) {
2683
+ console.log(getVersion());
2684
+ process.exit(0);
2685
+ }
2686
+ if (flags.has("--help") || flags.has("-h")) {
2687
+ if (command && COMMAND_HELP[command]) {
2688
+ console.log(COMMAND_HELP[command]);
2689
+ } else {
2690
+ console.log(HELP_TEXT);
2691
+ }
2692
+ process.exit(0);
2693
+ }
2694
+ var commands = {
2695
+ init,
2696
+ start,
2697
+ stop,
2698
+ restart,
2699
+ update,
2700
+ doctor,
2701
+ reset
2702
+ };
2703
+ var handler = commands[command || ""];
2704
+ if (!handler) {
2705
+ console.log(HELP_TEXT);
2706
+ process.exit(command ? 1 : 0);
2707
+ }
2708
+ handler().catch((err) => {
2709
+ console.error(err.message);
2710
+ process.exit(1);
2711
+ });