cairnboard 0.0.0-stage → 0.4.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 (299) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +126 -2
  3. package/README.tr.md +129 -0
  4. package/agents/agents-md-template.md +20 -0
  5. package/agents/skill-template.md +123 -0
  6. package/cli/args.mjs +42 -0
  7. package/cli/body.mjs +59 -0
  8. package/cli/cairn.mjs +9 -0
  9. package/cli/commands/agent.mjs +53 -0
  10. package/cli/commands/changes.mjs +23 -0
  11. package/cli/commands/config.mjs +252 -0
  12. package/cli/commands/start.mjs +98 -0
  13. package/cli/commands/write.mjs +435 -0
  14. package/cli/confirm.mjs +21 -0
  15. package/cli/main.mjs +102 -0
  16. package/cli/output.mjs +131 -0
  17. package/cli/registry.mjs +345 -0
  18. package/cli/views.mjs +291 -0
  19. package/core/agent.mjs +337 -0
  20. package/core/build-globals.d.ts +4 -0
  21. package/core/card.mjs +196 -0
  22. package/core/changes.mjs +543 -0
  23. package/core/check.mjs +74 -0
  24. package/core/clock.mjs +13 -0
  25. package/core/code-drift.mjs +29 -0
  26. package/core/config.mjs +166 -0
  27. package/core/context-pack.mjs +202 -0
  28. package/core/context.mjs +71 -0
  29. package/core/dates.mjs +15 -0
  30. package/core/detect.mjs +317 -0
  31. package/core/diff.mjs +74 -0
  32. package/core/doctor.mjs +123 -0
  33. package/core/entity.mjs +293 -0
  34. package/core/errors.mjs +34 -0
  35. package/core/events.mjs +223 -0
  36. package/core/evidence.mjs +108 -0
  37. package/core/export.mjs +26 -0
  38. package/core/extract.mjs +62 -0
  39. package/core/frontmatter.mjs +269 -0
  40. package/core/fsx.mjs +73 -0
  41. package/core/history.mjs +37 -0
  42. package/core/hook.mjs +120 -0
  43. package/core/ids.mjs +48 -0
  44. package/core/index.mjs +863 -0
  45. package/core/ingest.mjs +131 -0
  46. package/core/journal.mjs +161 -0
  47. package/core/links.mjs +179 -0
  48. package/core/lint-checks.mjs +366 -0
  49. package/core/lint.mjs +62 -0
  50. package/core/lock.mjs +164 -0
  51. package/core/mentions.mjs +200 -0
  52. package/core/note.mjs +8 -0
  53. package/core/paths.mjs +144 -0
  54. package/core/position.mjs +151 -0
  55. package/core/presets.mjs +53 -0
  56. package/core/project-links.mjs +94 -0
  57. package/core/project.mjs +8 -0
  58. package/core/render.mjs +243 -0
  59. package/core/research.mjs +8 -0
  60. package/core/roots.mjs +188 -0
  61. package/core/rules.mjs +78 -0
  62. package/core/runtime.mjs +31 -0
  63. package/core/schema.mjs +207 -0
  64. package/core/settings.mjs +318 -0
  65. package/core/shadow.mjs +269 -0
  66. package/core/store.mjs +576 -0
  67. package/core/text.mjs +114 -0
  68. package/core/tools.mjs +150 -0
  69. package/core/trash.mjs +93 -0
  70. package/core/watch.mjs +187 -0
  71. package/core/wiki.mjs +73 -0
  72. package/dist/app/client/_astro/AppShell.UStfWF6-.css +1 -0
  73. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_0_lang.DiMqZHRs.js +1 -0
  74. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_1_lang.DyY3pJeN.js +1 -0
  75. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_2_lang.DUwAwrvk.js +1 -0
  76. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_3_lang.C97NX_SN.js +1 -0
  77. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_4_lang.D-Qx8WO_.js +1 -0
  78. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_5_lang.BdMGVNko.js +1 -0
  79. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_6_lang.BHOG9dqh.js +1 -0
  80. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_7_lang.DzUrCiIa.js +1 -0
  81. package/dist/app/client/_astro/AppShell.astro_astro_type_script_index_8_lang.B8U1qSws.js +1 -0
  82. package/dist/app/client/_astro/_date_.astro_astro_type_script_index_0_lang.mIfxaXWK.js +1 -0
  83. package/dist/app/client/_astro/_id_.astro_astro_type_script_index_0_lang.mIfxaXWK.js +1 -0
  84. package/dist/app/client/_astro/agents.astro_astro_type_script_index_0_lang.CfY2SKh9.js +1 -0
  85. package/dist/app/client/_astro/board-focus.CY8TFJtP.js +1 -0
  86. package/dist/app/client/_astro/board.astro_astro_type_script_index_0_lang.DD2NY2yg.js +1 -0
  87. package/dist/app/client/_astro/board.astro_astro_type_script_index_1_lang.CfY2SKh9.js +1 -0
  88. package/dist/app/client/_astro/board.astro_astro_type_script_index_2_lang.B19y8H5r.js +1 -0
  89. package/dist/app/client/_astro/cam-dark-clouds-far.D7_-3oX6.png +0 -0
  90. package/dist/app/client/_astro/cam-dark-clouds-near.tCSCoUWs.png +0 -0
  91. package/dist/app/client/_astro/cam-dark-mist.DL6gwmKA.png +0 -0
  92. package/dist/app/client/_astro/cam-dark-twinkle-a.jrwr5OyX.png +0 -0
  93. package/dist/app/client/_astro/cam-dark-twinkle-b.CHQrh2xp.png +0 -0
  94. package/dist/app/client/_astro/cam-dark.fugRmc_Q.png +0 -0
  95. package/dist/app/client/_astro/cam-light-clouds-far.J2pzQHuG.png +0 -0
  96. package/dist/app/client/_astro/cam-light-clouds-near.DRnvD9VW.png +0 -0
  97. package/dist/app/client/_astro/cam-light-mist.Bip-Fylw.png +0 -0
  98. package/dist/app/client/_astro/cam-light-twinkle-a.B9qBFNcC.png +0 -0
  99. package/dist/app/client/_astro/cam-light-twinkle-b.C9wO8isI.png +0 -0
  100. package/dist/app/client/_astro/cam-light.BiSE3vxK.png +0 -0
  101. package/dist/app/client/_astro/card-dialog.Ci66JlvP.js +200 -0
  102. package/dist/app/client/_astro/doc-toc.DWfiIg0P.js +1 -0
  103. package/dist/app/client/_astro/doc-toc.l6xuDimi.css +1 -0
  104. package/dist/app/client/_astro/favicon.KcH_zzdF.svg +17 -0
  105. package/dist/app/client/_astro/index.astro_astro_type_script_index_0_lang.2kax2AE0.js +1 -0
  106. package/dist/app/client/_astro/index.astro_astro_type_script_index_0_lang.DRjYYIMm.js +1 -0
  107. package/dist/app/client/_astro/index.astro_astro_type_script_index_0_lang.Di0vlufN.js +1 -0
  108. package/dist/app/client/_astro/inter-latin-ext-wght-normal.DO1Apj_S.woff2 +0 -0
  109. package/dist/app/client/_astro/inter-latin-wght-normal.Dx4kXJAl.woff2 +0 -0
  110. package/dist/app/client/_astro/journal.CJJVtKwN.css +1 -0
  111. package/dist/app/client/_astro/live-pause.CrNCUUM3.js +1 -0
  112. package/dist/app/client/_astro/live-updates.C75FK0Dq.js +204 -0
  113. package/dist/app/client/_astro/research.DMSwWHyL.css +1 -0
  114. package/dist/app/client/_astro/search-text.DnJKHyd1.js +1 -0
  115. package/dist/app/client/_astro/theme-boot.DO4ZcKl2.js +22 -0
  116. package/dist/app/client/_astro/toast.BvwI1izN.js +1 -0
  117. package/dist/app/client/_astro/tools.DurxddJo.css +1 -0
  118. package/dist/app/client/_astro/tools.astro_astro_type_script_index_0_lang.DL0n5fmx.js +1 -0
  119. package/dist/app/client/_astro/typing.Ba11k4qT.js +1 -0
  120. package/dist/app/server/chunks/404_CIkUnth0.mjs +23 -0
  121. package/dist/app/server/chunks/500_eesZzMAG.mjs +23 -0
  122. package/dist/app/server/chunks/AppShell_C9rHcTBn.mjs +1324 -0
  123. package/dist/app/server/chunks/BoardColumns_VhDRTVrB.mjs +91 -0
  124. package/dist/app/server/chunks/CardStatus_yGnKNh5v.mjs +17 -0
  125. package/dist/app/server/chunks/DocToc_BlSizQjF.mjs +19 -0
  126. package/dist/app/server/chunks/EntityMeta_8kVxJCqL.mjs +35 -0
  127. package/dist/app/server/chunks/JournalForm_ZSx9-x22.mjs +12 -0
  128. package/dist/app/server/chunks/PageState_D-WOQXH8.mjs +12 -0
  129. package/dist/app/server/chunks/ProjectBox_vONMadq5.mjs +40 -0
  130. package/dist/app/server/chunks/ProjectForm_DxYFs1vi.mjs +13 -0
  131. package/dist/app/server/chunks/ReadDocument_Lf__kQHh.mjs +22 -0
  132. package/dist/app/server/chunks/ReadWarnings_rddSoeeg.mjs +13 -0
  133. package/dist/app/server/chunks/_date__BeRz7knE.mjs +120 -0
  134. package/dist/app/server/chunks/_id__B4rSjLC4.mjs +152 -0
  135. package/dist/app/server/chunks/_id__DTJs0T6K.mjs +93 -0
  136. package/dist/app/server/chunks/_id__Dl-3IYuu.mjs +99 -0
  137. package/dist/app/server/chunks/_id__v_3jKccS.mjs +217 -0
  138. package/dist/app/server/chunks/_virtual_astro_server-island-manifest_BhTW5IeR.mjs +4 -0
  139. package/dist/app/server/chunks/_virtual_astro_session-driver_HzKX7Wn1.mjs +5 -0
  140. package/dist/app/server/chunks/agents_D9BavrDh.mjs +47 -0
  141. package/dist/app/server/chunks/board_DdPu9hPy.mjs +159 -0
  142. package/dist/app/server/chunks/compiler_CLECgPZt.mjs +95 -0
  143. package/dist/app/server/chunks/console_ClfCadOL.mjs +192 -0
  144. package/dist/app/server/chunks/edit_BP_402lh.mjs +56 -0
  145. package/dist/app/server/chunks/edit_TvPaA2l_.mjs +62 -0
  146. package/dist/app/server/chunks/edit_Z3TE1n4l.mjs +66 -0
  147. package/dist/app/server/chunks/errors_C31JmGjG.mjs +844 -0
  148. package/dist/app/server/chunks/index_CKWmLgoW.mjs +95 -0
  149. package/dist/app/server/chunks/index_ChEHf9CB.mjs +144 -0
  150. package/dist/app/server/chunks/index_CjDRpgF7.mjs +381 -0
  151. package/dist/app/server/chunks/index_DmZ03CRL.mjs +60 -0
  152. package/dist/app/server/chunks/index_zYDSPqVN.mjs +96 -0
  153. package/dist/app/server/chunks/new_BhuobxNY.mjs +46 -0
  154. package/dist/app/server/chunks/new_DZFHbmgE.mjs +52 -0
  155. package/dist/app/server/chunks/new_K-Keuaqb.mjs +52 -0
  156. package/dist/app/server/chunks/node_DctE_xNW.mjs +1566 -0
  157. package/dist/app/server/chunks/noop-entrypoint_CxXy0p4B.mjs +3 -0
  158. package/dist/app/server/chunks/noop_DTpNBtJP.mjs +19 -0
  159. package/dist/app/server/chunks/research-filter_CGDNVWyl.mjs +159 -0
  160. package/dist/app/server/chunks/rolldown-runtime_782esTHO.mjs +26 -0
  161. package/dist/app/server/chunks/search_FSECq5LD.mjs +123 -0
  162. package/dist/app/server/chunks/server_LY3So-FE.mjs +7366 -0
  163. package/dist/app/server/chunks/server_SOl4RhQq.mjs +2463 -0
  164. package/dist/app/server/chunks/settings_CcWHQZm5.mjs +71 -0
  165. package/dist/app/server/chunks/tools_DEK_y5j0.mjs +112 -0
  166. package/dist/app/server/entry.mjs +1 -0
  167. package/dist/app/server/virtual_astro_middleware.mjs +3 -0
  168. package/dist/cairn-main.mjs +17376 -0
  169. package/dist/cairn.mjs +5 -0
  170. package/dist/cairnboard.mjs +5 -0
  171. package/package.json +76 -4
  172. package/server/api.mjs +81 -0
  173. package/server/app.mjs +148 -0
  174. package/server/card-controls.mjs +28 -0
  175. package/server/cards.mjs +231 -0
  176. package/server/events.mjs +69 -0
  177. package/server/guard.mjs +102 -0
  178. package/server/journal.mjs +79 -0
  179. package/server/listen.mjs +51 -0
  180. package/server/live.mjs +45 -0
  181. package/server/notes.mjs +297 -0
  182. package/server/open-browser.mjs +64 -0
  183. package/server/port.mjs +27 -0
  184. package/server/projects.mjs +104 -0
  185. package/server/read.mjs +659 -0
  186. package/server/render-pool.mjs +133 -0
  187. package/server/render-worker.mjs +19 -0
  188. package/server/search.mjs +141 -0
  189. package/server/session.mjs +143 -0
  190. package/server/settings.mjs +133 -0
  191. package/server/shutdown.mjs +31 -0
  192. package/server/start.mjs +101 -0
  193. package/server/state.mjs +53 -0
  194. package/server/writes.mjs +195 -0
  195. package/src/assets/favicon.svg +17 -0
  196. package/src/components/AgentsBox.astro +14 -0
  197. package/src/components/BoardColumns.astro +105 -0
  198. package/src/components/CardStatus.astro +11 -0
  199. package/src/components/DocToc.astro +58 -0
  200. package/src/components/EntityMeta.astro +28 -0
  201. package/src/components/GlassChoice.astro +47 -0
  202. package/src/components/HomeList.astro +28 -0
  203. package/src/components/HomeOverview.astro +48 -0
  204. package/src/components/JournalDialog.astro +42 -0
  205. package/src/components/JournalForm.astro +29 -0
  206. package/src/components/JournalPreview.astro +22 -0
  207. package/src/components/PageState.astro +12 -0
  208. package/src/components/PinnedRail.astro +83 -0
  209. package/src/components/ProjectBox.astro +36 -0
  210. package/src/components/ProjectForm.astro +35 -0
  211. package/src/components/ProjectJobs.astro +21 -0
  212. package/src/components/ProjectLinks.astro +19 -0
  213. package/src/components/ProjectOpen.astro +51 -0
  214. package/src/components/ReadDocument.astro +27 -0
  215. package/src/components/ReadWarnings.astro +8 -0
  216. package/src/components/ResearchBox.astro +58 -0
  217. package/src/components/ResearchMeta.astro +77 -0
  218. package/src/components/SearchResults.astro +41 -0
  219. package/src/components/SettingsPanel.astro +125 -0
  220. package/src/components/bento-pack.mjs +84 -0
  221. package/src/components/board-lanes.mjs +36 -0
  222. package/src/components/relative-time.mjs +33 -0
  223. package/src/i18n/en.json +576 -0
  224. package/src/i18n/index.mjs +14 -0
  225. package/src/i18n/tr.json +579 -0
  226. package/src/layouts/AppShell.astro +297 -0
  227. package/src/pages/404.astro +10 -0
  228. package/src/pages/500.astro +10 -0
  229. package/src/pages/agents.astro +42 -0
  230. package/src/pages/board.astro +147 -0
  231. package/src/pages/cards/[id]/edit.astro +83 -0
  232. package/src/pages/cards/[id].astro +85 -0
  233. package/src/pages/cards/new.astro +56 -0
  234. package/src/pages/index.astro +132 -0
  235. package/src/pages/journal/[date].astro +109 -0
  236. package/src/pages/journal/index.astro +140 -0
  237. package/src/pages/notes/[id]/edit.astro +67 -0
  238. package/src/pages/notes/[id].astro +60 -0
  239. package/src/pages/notes/index.astro +209 -0
  240. package/src/pages/notes/new.astro +50 -0
  241. package/src/pages/projects/[id]/edit.astro +27 -0
  242. package/src/pages/projects/[id].astro +77 -0
  243. package/src/pages/projects/index.astro +45 -0
  244. package/src/pages/projects/new.astro +24 -0
  245. package/src/pages/research/[id].astro +94 -0
  246. package/src/pages/research/index.astro +189 -0
  247. package/src/pages/search.astro +83 -0
  248. package/src/pages/settings.astro +22 -0
  249. package/src/pages/tools.astro +224 -0
  250. package/src/scripts/board-drag.js +236 -0
  251. package/src/scripts/board-filter.js +171 -0
  252. package/src/scripts/board-focus.js +11 -0
  253. package/src/scripts/card-dialog.js +200 -0
  254. package/src/scripts/confirm-dialog.js +35 -0
  255. package/src/scripts/css-time.js +9 -0
  256. package/src/scripts/doc-toc.js +115 -0
  257. package/src/scripts/glass-choice.js +39 -0
  258. package/src/scripts/journal-dialog.js +268 -0
  259. package/src/scripts/live-pause.js +32 -0
  260. package/src/scripts/live-updates.js +204 -0
  261. package/src/scripts/note-dialog.js +135 -0
  262. package/src/scripts/note-view.js +203 -0
  263. package/src/scripts/notes-list.js +120 -0
  264. package/src/scripts/pinned-rail.js +245 -0
  265. package/src/scripts/research-filter.js +160 -0
  266. package/src/scripts/scene-motion-choice.js +36 -0
  267. package/src/scripts/search-dialog.js +500 -0
  268. package/src/scripts/search-text.js +9 -0
  269. package/src/scripts/settings-dialog.js +106 -0
  270. package/src/scripts/shell-tabs.js +6 -0
  271. package/src/scripts/theme-boot.js +22 -0
  272. package/src/scripts/theme-toggle.js +46 -0
  273. package/src/scripts/toast.js +27 -0
  274. package/src/scripts/tools-filter.js +111 -0
  275. package/src/scripts/typing.js +3 -0
  276. package/src/styles/app.css +1961 -0
  277. package/src/styles/doc-toc.css +145 -0
  278. package/src/styles/fonts/OFL.txt +93 -0
  279. package/src/styles/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  280. package/src/styles/fonts/inter-latin-wght-normal.woff2 +0 -0
  281. package/src/styles/fonts.css +18 -0
  282. package/src/styles/glass.css +759 -0
  283. package/src/styles/journal.css +204 -0
  284. package/src/styles/research.css +261 -0
  285. package/src/styles/scene/cam-dark-clouds-far.png +0 -0
  286. package/src/styles/scene/cam-dark-clouds-near.png +0 -0
  287. package/src/styles/scene/cam-dark-mist.png +0 -0
  288. package/src/styles/scene/cam-dark-twinkle-a.png +0 -0
  289. package/src/styles/scene/cam-dark-twinkle-b.png +0 -0
  290. package/src/styles/scene/cam-dark.png +0 -0
  291. package/src/styles/scene/cam-light-clouds-far.png +0 -0
  292. package/src/styles/scene/cam-light-clouds-near.png +0 -0
  293. package/src/styles/scene/cam-light-mist.png +0 -0
  294. package/src/styles/scene/cam-light-twinkle-a.png +0 -0
  295. package/src/styles/scene/cam-light-twinkle-b.png +0 -0
  296. package/src/styles/scene/cam-light.png +0 -0
  297. package/src/styles/settings.css +306 -0
  298. package/src/styles/tokens.css +1110 -0
  299. package/src/styles/tools.css +84 -0
@@ -0,0 +1,252 @@
1
+ import { platform } from 'node:os';
2
+ import { resolve } from 'node:path';
3
+ import { createInterface } from 'node:readline';
4
+ import { CairnError } from '../../core/errors.mjs';
5
+ import { features, loadConfig } from '../../core/config.mjs';
6
+ import { readChecked, realRoot } from '../../core/paths.mjs';
7
+ import { findDataDir } from '../../core/roots.mjs';
8
+ import { clearShadow, LANGUAGES, readSettings, setFeature, setLanguage } from '../../core/settings.mjs';
9
+ import { shadowStats } from '../../core/shadow.mjs';
10
+ import { revision } from '../../core/store.mjs';
11
+ import { oneLine, stripHidden } from '../../core/text.mjs';
12
+ import { actorPattern } from '../output.mjs';
13
+
14
+ const FEATURES = [
15
+ ['change-trail', 'changeTrail'],
16
+ ['change-content', 'changeContent'],
17
+ ['live-updates', 'liveUpdates'],
18
+ ['mentions', 'mentions'],
19
+ ];
20
+ const cliToKey = new Map(FEATURES);
21
+ const keyToCli = new Map(FEATURES.map(([cli, key]) => [key, cli]));
22
+ const AGENT_MARKERS = [
23
+ 'CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', 'CODEX_SANDBOX', 'CODEX_THREAD_ID', 'GEMINI_CLI', 'CURSOR_AGENT',
24
+ ];
25
+ const OWNER_ONLY = 'Change settings from your own terminal or the Settings page.';
26
+
27
+ function dataLocation(opts, io) {
28
+ const env = io.env ?? {};
29
+ const cwd = io.cwd ?? process.cwd();
30
+ const resolved = { ...env, ...(env.CAIRN_DATA ? { CAIRN_DATA: resolve(cwd, env.CAIRN_DATA) } : {}) };
31
+ return findDataDir({
32
+ flag: opts.data && resolve(cwd, opts.data),
33
+ env: resolved,
34
+ home: env.HOME ?? env.USERPROFILE,
35
+ platform: platform(),
36
+ }).path;
37
+ }
38
+
39
+ export function readConfiguredFeatures(opts = {}, io = {}) {
40
+ try {
41
+ return features(loadConfig(realRoot(dataLocation(opts, io))));
42
+ } catch {
43
+ return features({});
44
+ }
45
+ }
46
+
47
+ // `language` is the one setting that is not an on/off feature; it shares `config get` and `config set`.
48
+ const LANGUAGE = 'language';
49
+
50
+ function parseFeature(name) {
51
+ if (name === LANGUAGE) return { cli: name, key: name, language: true };
52
+ const key = cliToKey.get(name);
53
+ if (!key) {
54
+ throw new CairnError('validation',
55
+ 'Unknown setting. Use change-trail, change-content, live-updates, mentions or language.');
56
+ }
57
+ return { cli: name, key };
58
+ }
59
+
60
+ function parseLanguage(value) {
61
+ if (LANGUAGES.includes(value)) return value;
62
+ throw new CairnError('validation', 'Invalid language. Use tr or en.');
63
+ }
64
+
65
+ function parseToggle(value) {
66
+ if (value === 'on') return true;
67
+ if (value === 'off') return false;
68
+ throw new CairnError('validation', 'Invalid feature value. Use on or off.');
69
+ }
70
+
71
+ function writeActor(opts) {
72
+ if (opts.actor === undefined) return 'cli:owner';
73
+ if (!actorPattern.test(opts.actor)) throw new CairnError('usage', 'Invalid actor name.');
74
+ return `cli:${opts.actor}`;
75
+ }
76
+
77
+ function requireOwnerTerminal(io) {
78
+ const agent = AGENT_MARKERS.find((name) => io.env?.[name]);
79
+ const tty = Boolean(io.isTTY) && io.stdin?.isTTY === true && io.stdout?.isTTY === true;
80
+ if (agent || !tty) throw new CairnError('owner_only', OWNER_ONLY);
81
+ }
82
+
83
+ async function confirmWord(io, message, expected) {
84
+ io.stderr.write(`${oneLine(stripHidden(message).text)} Type ${expected}: `);
85
+ const lines = createInterface({ input: io.stdin, crlfDelay: Infinity, terminal: false });
86
+ let answer = null;
87
+ try {
88
+ for await (const line of lines) {
89
+ answer = line.trim();
90
+ break;
91
+ }
92
+ } finally {
93
+ lines.close();
94
+ }
95
+ if (answer !== expected) throw new CairnError('usage', `Confirmation did not match "${expected}".`);
96
+ }
97
+
98
+ function currentSettings(ctx) {
99
+ if (ctx.ephemeral) {
100
+ return { features: features(ctx.config), language: ctx.config.language, revision: null,
101
+ shadow: { blobs: 0, bytes: 0 }, lastChange: null };
102
+ }
103
+ return readSettings(ctx);
104
+ }
105
+
106
+ function formatChange(change) {
107
+ if (!change) return 'none';
108
+ const when = oneLine(String(change.ts ?? ''));
109
+ const who = oneLine(String(change.actor ?? 'unknown'));
110
+ if (Array.isArray(change.feature)) {
111
+ const items = change.feature.map((key) => `${keyToCli.get(key) ?? key}=${change.after?.[key] ? 'on' : 'off'}`);
112
+ return `${when} ${who} (${items.join(', ')})`;
113
+ }
114
+ const name = keyToCli.get(change.feature) ?? change.feature;
115
+ return `${when} ${who} (${name}=${change.after ? 'on' : 'off'})`;
116
+ }
117
+
118
+ function formatSettings(settings) {
119
+ const { blobs, bytes } = settings.shadow;
120
+ return [
121
+ ...FEATURES.map(([cli, key]) => `${cli}: ${settings.features[key] ? 'on' : 'off'}`),
122
+ `${LANGUAGE}: ${settings.language}`,
123
+ `shadow: ${blobs} ${blobs === 1 ? 'blob' : 'blobs'}, ${bytes} ${bytes === 1 ? 'byte' : 'bytes'}`,
124
+ `last-change: ${formatChange(settings.lastChange)}`,
125
+ ].join('\n');
126
+ }
127
+
128
+ function diskRevision(ctx) {
129
+ const bytes = readChecked(ctx.root, '.cairn/config.json');
130
+ return bytes === null ? null : revision(bytes);
131
+ }
132
+
133
+ export function configCommands() {
134
+ return [
135
+ {
136
+ name: 'config',
137
+ summary: 'Show feature settings, shadow size and last change.',
138
+ args: [],
139
+ options: {},
140
+ mode: 'read',
141
+ needsData: true,
142
+ dangerous: false,
143
+ run: (ctx, args, opts) => {
144
+ const data = currentSettings(ctx);
145
+ return { data: opts.json ? data : formatSettings(data) };
146
+ },
147
+ },
148
+ {
149
+ name: 'config get',
150
+ summary: 'Get one feature setting or the language.',
151
+ args: ['<feature>'],
152
+ options: {},
153
+ mode: 'read',
154
+ needsData: true,
155
+ dangerous: false,
156
+ prepare: ([name]) => parseFeature(name),
157
+ run: (ctx, args, opts, io, feature) => {
158
+ const settings = currentSettings(ctx);
159
+ if (feature.language) {
160
+ const data = { name: LANGUAGE, value: settings.language, revision: settings.revision };
161
+ return { data: opts.json ? data : settings.language };
162
+ }
163
+ const value = settings.features[feature.key];
164
+ const data = { name: feature.cli, feature: feature.key, value, revision: settings.revision };
165
+ return { data: opts.json ? data : (value ? 'on' : 'off') };
166
+ },
167
+ },
168
+ {
169
+ name: 'config set',
170
+ summary: 'Enable or disable a feature, or set the language.',
171
+ args: ['<feature>', '<value>'],
172
+ options: {},
173
+ mode: 'write',
174
+ actor: false,
175
+ agentVisible: false,
176
+ needsData: true,
177
+ dangerous: false,
178
+ prepare: async ([name, value], opts, io) => {
179
+ const feature = parseFeature(name);
180
+ const enabled = feature.language ? parseLanguage(value) : parseToggle(value);
181
+ const actor = writeActor(opts);
182
+ if (!opts['dry-run']) {
183
+ requireOwnerTerminal(io);
184
+ let where = null;
185
+ try { where = dataLocation(opts, io); } catch {}
186
+ const target = where ? ` (data: ${where})` : '';
187
+ await confirmWord(io, `Set ${feature.cli} to ${value}${target}?`, feature.cli);
188
+ }
189
+ return { feature, enabled, value, actor };
190
+ },
191
+ run: (ctx, args, opts, io, prepared) => {
192
+ const { feature, enabled, value, actor } = prepared;
193
+ if (opts['dry-run']) {
194
+ const rev = diskRevision(ctx);
195
+ if (opts['if-revision'] !== undefined && opts['if-revision'] !== rev) {
196
+ throw new CairnError('conflict', 'Configuration changed since it was read.');
197
+ }
198
+ const current = feature.language ? ctx.config.language : features(ctx.config)[feature.key];
199
+ const data = { name: feature.cli, ...(feature.language ? {} : { feature: feature.key }), value: enabled,
200
+ changed: current !== enabled, revision: rev };
201
+ return { data: opts.json ? data : `${feature.cli}: ${value} (dry-run)` };
202
+ }
203
+ const expectedRevision = opts['if-revision'] ?? readSettings(ctx).revision;
204
+ if (feature.language) {
205
+ const saved = setLanguage({ ...ctx, actor }, { language: enabled, expectedRevision, actor });
206
+ const data = { name: LANGUAGE, value: enabled, changed: saved.changed, revision: saved.revision };
207
+ // A running web server keeps its interface language until it restarts or the Settings page saves it.
208
+ const text = saved.changed ? `${LANGUAGE}: ${value}` : `${LANGUAGE}: ${value} (unchanged)`;
209
+ return { data: opts.json ? data : text };
210
+ }
211
+ const result = setFeature({ ...ctx, actor }, { name: feature.key, value: enabled, expectedRevision, actor });
212
+ if (feature.key === 'changeTrail' && enabled) {
213
+ ctx.warnings = ctx.warnings.filter((warning) => warning !== 'trail_disabled');
214
+ }
215
+ const data = {
216
+ name: feature.cli, feature: feature.key, value: enabled, changed: result.changed, revision: result.revision,
217
+ };
218
+ const text = result.changed ? `${feature.cli}: ${value}` : `${feature.cli}: ${value} (unchanged)`;
219
+ return { data: opts.json ? data : text, ...(result.warnings?.length ? { warnings: result.warnings } : {}) };
220
+ },
221
+ },
222
+ {
223
+ name: 'config clear-shadow',
224
+ summary: 'Delete stored shadow content blobs while keeping change-trail revisions.',
225
+ args: [],
226
+ options: {},
227
+ mode: 'write',
228
+ actor: false,
229
+ agentVisible: false,
230
+ needsData: true,
231
+ dangerous: false,
232
+ prepare: async (args, opts, io) => {
233
+ const actor = writeActor(opts);
234
+ if (!opts['dry-run']) {
235
+ requireOwnerTerminal(io);
236
+ let where = null;
237
+ try { where = dataLocation(opts, io); } catch {}
238
+ const target = where ? ` (data: ${where})` : '';
239
+ await confirmWord(io, `Clear shadow content blobs${target}?`, 'clear');
240
+ }
241
+ return { actor };
242
+ },
243
+ run: (ctx, args, opts, io, prepared) => {
244
+ const cleared = opts['dry-run'] ? shadowStats(ctx) : clearShadow({ ...ctx, actor: prepared.actor }, prepared);
245
+ const { blobs, bytes } = cleared;
246
+ const unit = `${blobs} ${blobs === 1 ? 'blob' : 'blobs'} (${bytes} ${bytes === 1 ? 'byte' : 'bytes'})`;
247
+ const text = opts['dry-run'] ? `${unit} to clear (dry-run).` : `Cleared ${unit}.`;
248
+ return { data: opts.json ? cleared : text };
249
+ },
250
+ },
251
+ ];
252
+ }
@@ -0,0 +1,98 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { once } from 'node:events';
3
+ import { mkdirSync, statSync } from 'node:fs';
4
+ import { constants, homedir, userInfo } from 'node:os';
5
+ import { join, resolve } from 'node:path';
6
+ import { repoRoot } from '../../core/agent.mjs';
7
+ import { loadConfig } from '../../core/config.mjs';
8
+ import { CairnError } from '../../core/errors.mjs';
9
+ import { realRoot } from '../../core/paths.mjs';
10
+ import { findDataDir, initDataDir } from '../../core/roots.mjs';
11
+ import { oneLine } from '../../core/text.mjs';
12
+ import { clean } from '../output.mjs';
13
+
14
+ export function serverHome(env) {
15
+ // On POSIX, os.homedir() can return the empty HOME it inherited; on Windows it throws when USERPROFILE is empty.
16
+ let home = env.HOME || env.USERPROFILE;
17
+ try { home ||= homedir(); } catch { /* fall back to the account database below */ }
18
+ return home || userInfo().homedir;
19
+ }
20
+
21
+ function initDefault(path, settings, language, stdout) {
22
+ let created = true;
23
+ try {
24
+ // Reserve the name before initializing so a directory created by someone else is checked first.
25
+ mkdirSync(path, { mode: 0o700 });
26
+ } catch (error) {
27
+ if (error.code !== 'EEXIST') throw error;
28
+ created = false;
29
+ try {
30
+ loadConfig(realRoot(path));
31
+ } catch {
32
+ throw new CairnError('validation',
33
+ `The default folder ${path} already exists and is not a Cairnboard data folder. Choose another with --data.`);
34
+ }
35
+ }
36
+ initDataDir(path, { ...settings, language, register: 'if-unset' });
37
+ if (created) {
38
+ stdout.write(`Created the data folder at ${oneLine(clean(path))}. Use --data <path> to choose another.\n`);
39
+ }
40
+ }
41
+
42
+ export async function runStart(ctx, args, opts, io) {
43
+ if (opts.json || opts['dry-run']) throw new CairnError('usage', 'Start does not support --json or --dry-run.');
44
+ if (opts.language !== undefined && !['en', 'tr'].includes(opts.language)) {
45
+ throw new CairnError('usage', '--language must be en or tr.');
46
+ }
47
+ if (opts.data === '') throw new CairnError('usage', '--data needs a folder path.');
48
+ if (!statSync(join(repoRoot, 'dist/app/server/entry.mjs'), { throwIfNoEntry: false })?.isFile()) {
49
+ throw new CairnError('validation', 'The web app is missing. Build it first with npm run build:app.');
50
+ }
51
+
52
+ const home = serverHome(io.env);
53
+ const env = { ...io.env, HOME: home, USERPROFILE: home,
54
+ ...(io.env.CAIRN_DATA ? { CAIRN_DATA: resolve(io.cwd, io.env.CAIRN_DATA) } : {}) };
55
+ const settings = { home, env };
56
+ const found = findDataDir({ ...settings, flag: opts.data && resolve(io.cwd, opts.data) });
57
+ if (found.source === 'default') {
58
+ const language = opts.language ?? (Intl.DateTimeFormat().resolvedOptions().locale.startsWith('tr') ? 'tr' : 'en');
59
+ initDefault(found.path, settings, language, io.stdout);
60
+ }
61
+
62
+ // A separate POSIX process group ensures that only the launcher gets terminal Ctrl-C.
63
+ // On Windows both share the console and Node's child.kill() would forcibly terminate the server.
64
+ const detached = process.platform !== 'win32';
65
+ const child = spawn(process.execPath, [join(repoRoot, 'server/start.mjs'), ...(opts['no-open'] ? ['--no-open'] : [])],
66
+ { cwd: io.cwd, env: { ...env, CAIRN_DATA: found.path }, stdio: 'inherit', detached });
67
+ const forceStop = () => {
68
+ if (!child.pid || child.exitCode !== null || child.signalCode !== null) return;
69
+ try {
70
+ if (detached) process.kill(-child.pid, 'SIGKILL');
71
+ else child.kill('SIGKILL');
72
+ } catch (error) {
73
+ if (error.code !== 'ESRCH') throw error;
74
+ }
75
+ };
76
+ let interrupted = false;
77
+ const interrupt = () => {
78
+ if (!detached) return;
79
+ if (interrupted) process.exit(130); // The exit handler kills the server and its group.
80
+ interrupted = true;
81
+ child.kill('SIGINT');
82
+ };
83
+ const terminate = () => child.kill('SIGTERM');
84
+ process.on('exit', forceStop);
85
+ process.on('SIGINT', interrupt);
86
+ process.on('SIGTERM', terminate);
87
+ if (detached) process.on('SIGHUP', terminate);
88
+ try {
89
+ const [code, signal] = await once(child, 'exit');
90
+ return { data: null, stdout: '', exit: code ?? 128 + constants.signals[signal] };
91
+ } finally {
92
+ process.off('SIGINT', interrupt);
93
+ process.off('SIGTERM', terminate);
94
+ if (detached) process.off('SIGHUP', terminate);
95
+ process.off('exit', forceStop);
96
+ forceStop();
97
+ }
98
+ }