@otea/cli 0.0.1 → 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 (243) hide show
  1. package/LICENSE +661 -0
  2. package/README.es.md +151 -0
  3. package/README.md +251 -3
  4. package/THIRD_PARTY_NOTICES.md +114 -0
  5. package/bin/otea.mjs +28 -0
  6. package/dist/app/agent-detail.js +26 -0
  7. package/dist/app/agent-draft.js +429 -0
  8. package/dist/app/agent-prompts.js +52 -0
  9. package/dist/app/agents.js +77 -0
  10. package/dist/app/asking.js +43 -0
  11. package/dist/app/board-archive.js +243 -0
  12. package/dist/app/board-migration.js +272 -0
  13. package/dist/app/boards.js +870 -0
  14. package/dist/app/branch-owner.js +48 -0
  15. package/dist/app/brief.js +53 -0
  16. package/dist/app/choices.js +61 -0
  17. package/dist/app/collections.js +101 -0
  18. package/dist/app/context.js +1 -0
  19. package/dist/app/crop.js +56 -0
  20. package/dist/app/devices.js +62 -0
  21. package/dist/app/draft-request.js +82 -0
  22. package/dist/app/events.js +12 -0
  23. package/dist/app/evidence.js +287 -0
  24. package/dist/app/gates.js +610 -0
  25. package/dist/app/guide.js +37 -0
  26. package/dist/app/home.js +145 -0
  27. package/dist/app/init-boards.js +36 -0
  28. package/dist/app/intake.js +25 -0
  29. package/dist/app/item-search.js +141 -0
  30. package/dist/app/items.js +318 -0
  31. package/dist/app/keep-waiting.js +44 -0
  32. package/dist/app/land-order.js +107 -0
  33. package/dist/app/language.js +52 -0
  34. package/dist/app/launcher.js +56 -0
  35. package/dist/app/lease-take.js +54 -0
  36. package/dist/app/leases.js +86 -0
  37. package/dist/app/machine.js +39 -0
  38. package/dist/app/merged.js +89 -0
  39. package/dist/app/migrate.js +171 -0
  40. package/dist/app/next.js +1637 -0
  41. package/dist/app/notes.js +319 -0
  42. package/dist/app/notify-targets.js +113 -0
  43. package/dist/app/opened.js +25 -0
  44. package/dist/app/owner-only.js +34 -0
  45. package/dist/app/performance.js +28 -0
  46. package/dist/app/phone.js +97 -0
  47. package/dist/app/presence.js +596 -0
  48. package/dist/app/preset-views.js +25 -0
  49. package/dist/app/presets.js +129 -0
  50. package/dist/app/priority.js +156 -0
  51. package/dist/app/profile.js +86 -0
  52. package/dist/app/project.js +247 -0
  53. package/dist/app/proofs.js +179 -0
  54. package/dist/app/questions.js +215 -0
  55. package/dist/app/reader-filter.js +58 -0
  56. package/dist/app/relations.js +164 -0
  57. package/dist/app/relay.js +98 -0
  58. package/dist/app/repos.js +176 -0
  59. package/dist/app/restart.js +92 -0
  60. package/dist/app/set-aside.js +64 -0
  61. package/dist/app/system-locale.js +6 -0
  62. package/dist/app/tailscale-cli.js +77 -0
  63. package/dist/app/tailscale-testing.js +41 -0
  64. package/dist/app/tailscale.js +177 -0
  65. package/dist/app/tips.js +30 -0
  66. package/dist/app/topics-everywhere.js +53 -0
  67. package/dist/app/topics.js +453 -0
  68. package/dist/app/undo.js +52 -0
  69. package/dist/app/validate.js +131 -0
  70. package/dist/app/watch.js +48 -0
  71. package/dist/cli/command.js +44 -0
  72. package/dist/cli/commands.js +3303 -0
  73. package/dist/cli/exit-codes.js +70 -0
  74. package/dist/cli/forge.js +176 -0
  75. package/dist/cli/format.js +340 -0
  76. package/dist/cli/gh.js +17 -0
  77. package/dist/cli/gitrepo.js +489 -0
  78. package/dist/cli/help.js +101 -0
  79. package/dist/cli/hooks.js +232 -0
  80. package/dist/cli/main.js +37 -0
  81. package/dist/cli/merged-outside.js +58 -0
  82. package/dist/cli/names.js +154 -0
  83. package/dist/cli/opener.js +21 -0
  84. package/dist/cli/owner.js +154 -0
  85. package/dist/cli/phone.js +221 -0
  86. package/dist/cli/ports.js +24 -0
  87. package/dist/cli/probe.js +18 -0
  88. package/dist/cli/run.js +246 -0
  89. package/dist/cli/serve-file.js +21 -0
  90. package/dist/cli/stats.js +55 -0
  91. package/dist/cli/version.js +3 -0
  92. package/dist/core/agent-guide.js +31 -0
  93. package/dist/core/agent-prompts.js +139 -0
  94. package/dist/core/authority.js +94 -0
  95. package/dist/core/board/analysis.js +86 -0
  96. package/dist/core/board/choices.js +100 -0
  97. package/dist/core/board/compile.js +362 -0
  98. package/dist/core/board/engine.js +523 -0
  99. package/dist/core/board/hints.js +46 -0
  100. package/dist/core/board/history.js +146 -0
  101. package/dist/core/board/ids.js +87 -0
  102. package/dist/core/board/joins.js +30 -0
  103. package/dist/core/board/mentions.js +68 -0
  104. package/dist/core/board/merged.js +18 -0
  105. package/dist/core/board/model.js +135 -0
  106. package/dist/core/board/next.js +1116 -0
  107. package/dist/core/board/notes.js +298 -0
  108. package/dist/core/board/performance.js +218 -0
  109. package/dist/core/board/plan.js +299 -0
  110. package/dist/core/board/problems.js +232 -0
  111. package/dist/core/board/proofs.js +84 -0
  112. package/dist/core/board/questions.js +114 -0
  113. package/dist/core/board/reading.js +220 -0
  114. package/dist/core/board/readings.js +534 -0
  115. package/dist/core/board/schema.js +335 -0
  116. package/dist/core/board/shape-words.js +179 -0
  117. package/dist/core/board/template-words.js +23 -0
  118. package/dist/core/board/templates-catalogue.js +965 -0
  119. package/dist/core/board/templates-coverage.js +261 -0
  120. package/dist/core/board/templates-flows.js +779 -0
  121. package/dist/core/board/templates.js +586 -0
  122. package/dist/core/brief.js +93 -0
  123. package/dist/core/diagram.js +80 -0
  124. package/dist/core/errors.js +12 -0
  125. package/dist/core/evidence.js +33 -0
  126. package/dist/core/fields.js +129 -0
  127. package/dist/core/hierarchy.js +30 -0
  128. package/dist/core/icons.js +181 -0
  129. package/dist/core/image-crop.js +166 -0
  130. package/dist/core/item.js +49 -0
  131. package/dist/core/lease.js +31 -0
  132. package/dist/core/modules.js +318 -0
  133. package/dist/core/notify/planner.js +117 -0
  134. package/dist/core/notify/signals.js +66 -0
  135. package/dist/core/notify/text.js +60 -0
  136. package/dist/core/path-key.js +22 -0
  137. package/dist/core/placement.js +161 -0
  138. package/dist/core/preset-labels.js +66 -0
  139. package/dist/core/preset-notes.js +109 -0
  140. package/dist/core/preset.js +541 -0
  141. package/dist/core/profile.js +55 -0
  142. package/dist/core/project-id.js +20 -0
  143. package/dist/core/refusal.js +1 -0
  144. package/dist/core/relations.js +208 -0
  145. package/dist/core/repo.js +54 -0
  146. package/dist/core/samples.js +161 -0
  147. package/dist/core/search-words.js +68 -0
  148. package/dist/core/test-report.js +120 -0
  149. package/dist/core/time.js +8 -0
  150. package/dist/core/validation.js +60 -0
  151. package/dist/core/views.js +171 -0
  152. package/dist/core/workflow.js +51 -0
  153. package/dist/mcp/commands.js +101 -0
  154. package/dist/mcp/server.js +239 -0
  155. package/dist/mcp/words.js +95 -0
  156. package/dist/server/boards.js +232 -0
  157. package/dist/server/changes.js +42 -0
  158. package/dist/server/diff-tip.js +83 -0
  159. package/dist/server/drift.js +87 -0
  160. package/dist/server/errors.js +87 -0
  161. package/dist/server/evidence.js +82 -0
  162. package/dist/server/hosts.js +6 -0
  163. package/dist/server/hub.js +98 -0
  164. package/dist/server/lan-access.js +62 -0
  165. package/dist/server/lan.js +164 -0
  166. package/dist/server/listen.js +70 -0
  167. package/dist/server/notifier.js +156 -0
  168. package/dist/server/notify-api.js +151 -0
  169. package/dist/server/pairing.js +124 -0
  170. package/dist/server/projects.js +191 -0
  171. package/dist/server/push.js +199 -0
  172. package/dist/server/server.js +960 -0
  173. package/dist/server/session.js +43 -0
  174. package/dist/server/stream.js +36 -0
  175. package/dist/server/test-push.js +38 -0
  176. package/dist/server/token.js +37 -0
  177. package/dist/server/transports.js +54 -0
  178. package/dist/server/ui.js +44 -0
  179. package/dist/server/writes.js +361 -0
  180. package/dist/server/wrong-address.js +36 -0
  181. package/dist/store/boards.js +111 -0
  182. package/dist/store/database.js +45 -0
  183. package/dist/store/machine.js +77 -0
  184. package/dist/store/migrations.js +493 -0
  185. package/dist/store/queries.js +585 -0
  186. package/dist/store/registry.js +72 -0
  187. package/package.json +72 -4
  188. package/presets/architecture/playbook.md +69 -0
  189. package/presets/architecture/preset.yaml +80 -0
  190. package/presets/architecture/samples.yaml +23 -0
  191. package/presets/bug-triage/playbook.md +129 -0
  192. package/presets/bug-triage/preset.yaml +127 -0
  193. package/presets/bug-triage/samples/wall-slide-after.png +0 -0
  194. package/presets/bug-triage/samples/wall-slide-before.png +0 -0
  195. package/presets/bug-triage/samples.yaml +72 -0
  196. package/presets/change/playbook.md +115 -0
  197. package/presets/change/preset.yaml +141 -0
  198. package/presets/change/samples.yaml +62 -0
  199. package/presets/review/playbook.md +51 -0
  200. package/presets/review/preset.yaml +62 -0
  201. package/presets/review/samples.yaml +27 -0
  202. package/presets/tasks/playbook.md +78 -0
  203. package/presets/tasks/preset.yaml +61 -0
  204. package/presets/tasks/samples.yaml +46 -0
  205. package/schemas/board.schema.json +764 -0
  206. package/ui/dist/THIRD_PARTY_NOTICES.md +114 -0
  207. package/ui/dist/assets/dm-mono-latin-400-normal--0xN8mdc.woff +0 -0
  208. package/ui/dist/assets/dm-mono-latin-400-normal-4GdczIuU.woff2 +0 -0
  209. package/ui/dist/assets/dm-mono-latin-500-normal-CN8Miw6E.woff +0 -0
  210. package/ui/dist/assets/dm-mono-latin-500-normal-DRMDZjhP.woff2 +0 -0
  211. package/ui/dist/assets/dm-mono-latin-ext-400-normal-1aZr6b2b.woff +0 -0
  212. package/ui/dist/assets/dm-mono-latin-ext-400-normal-C2zvOubV.woff2 +0 -0
  213. package/ui/dist/assets/dm-mono-latin-ext-500-normal-BtRyHRi6.woff2 +0 -0
  214. package/ui/dist/assets/dm-mono-latin-ext-500-normal-Dw3M13d8.woff +0 -0
  215. package/ui/dist/assets/index-C3OzJope.js +103 -0
  216. package/ui/dist/assets/index-COdEjckQ.css +1 -0
  217. package/ui/dist/assets/newsreader-latin-ext-opsz-italic-CSPGnFdO.woff2 +0 -0
  218. package/ui/dist/assets/newsreader-latin-ext-opsz-normal-BQn1nviT.woff2 +0 -0
  219. package/ui/dist/assets/newsreader-latin-opsz-italic-kJKFiXvB.woff2 +0 -0
  220. package/ui/dist/assets/newsreader-latin-opsz-normal-s-izfB6B.woff2 +0 -0
  221. package/ui/dist/assets/newsreader-vietnamese-opsz-italic-DTr-ymY4.woff2 +0 -0
  222. package/ui/dist/assets/newsreader-vietnamese-opsz-normal-BjhtXyW2.woff2 +0 -0
  223. package/ui/dist/assets/pdf-YwugTw7Y.js +54 -0
  224. package/ui/dist/assets/pdf-engine-CkBopwck.js +1 -0
  225. package/ui/dist/assets/pdf-rELvHkft.js +56 -0
  226. package/ui/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
  227. package/ui/dist/assets/pdf.worker.min-B7U8ptvh.js +1 -0
  228. package/ui/dist/assets/pdf.worker.min-CIqJB0yW.mjs +28 -0
  229. package/ui/dist/assets/pdf.worker.min-UqOn5EDC.js +1 -0
  230. package/ui/dist/assets/schibsted-grotesk-latin-ext-wght-normal-hsMS0n0O.woff2 +0 -0
  231. package/ui/dist/assets/schibsted-grotesk-latin-wght-normal-Bb8VGrTG.woff2 +0 -0
  232. package/ui/dist/icons/apple-touch-icon.png +0 -0
  233. package/ui/dist/icons/otea-192.png +0 -0
  234. package/ui/dist/icons/otea-512.png +0 -0
  235. package/ui/dist/icons/otea-badge.png +0 -0
  236. package/ui/dist/icons/otea-maskable-512.png +0 -0
  237. package/ui/dist/index.html +25 -0
  238. package/ui/dist/manifest.webmanifest +24 -0
  239. package/ui/dist/otea-idle.svg +5 -0
  240. package/ui/dist/otea-working.svg +5 -0
  241. package/ui/dist/otea-yours-working.svg +5 -0
  242. package/ui/dist/otea-yours.svg +5 -0
  243. package/ui/dist/sw.js +1 -0
@@ -0,0 +1,171 @@
1
+ import { cpSync, existsSync, mkdirSync, readdirSync, renameSync, rmSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { isDeepStrictEqual } from 'node:util';
4
+ import { OteaError } from '../core/errors.js';
5
+ import { integrityCheck, openDatabase, tableSummary, transaction, vacuumInto, } from '../store/database.js';
6
+ import { selectProjectIdentity } from '../store/queries.js';
7
+ import { deleteRegisteredProject, selectProjectPaths, selectRegisteredProject, } from '../store/registry.js';
8
+ import { addProjectPath, keyOf, kindOf, linkAt, openRegistry, oteaHome, registerProject, withRegistry, } from './home.js';
9
+ import { restrictToOwner } from './owner-only.js';
10
+ import { databasePath, excludeFromGit, gitCommonDir, openProject, oteaDir, } from './project.js';
11
+ const BACKUP_PREFIX = '.otea.migrated-';
12
+ // The folders and files copied next to the database; ui-token and serve.json are made again when served
13
+ // (ensureUiToken keeps the new token to its owner).
14
+ // The push keys go along: the phones' subscriptions are bound to them.
15
+ const PUSH_KEYS = 'push-keys.json';
16
+ const COPIED = ['evidence', 'presets', PUSH_KEYS];
17
+ function summaryOf(dataDir) {
18
+ const db = openDatabase(databasePath(dataDir));
19
+ try {
20
+ return tableSummary(db);
21
+ }
22
+ finally {
23
+ db.close();
24
+ }
25
+ }
26
+ function countFiles(dir) {
27
+ if (!existsSync(dir))
28
+ return 0;
29
+ if (!statSync(dir).isDirectory())
30
+ return 1;
31
+ return readdirSync(dir, { withFileTypes: true, recursive: true }).filter((e) => e.isFile())
32
+ .length;
33
+ }
34
+ function backupName(now) {
35
+ return `${BACKUP_PREFIX}${now.toISOString().slice(0, 19).replace(/[-:]/g, '').replace('T', '-')}`;
36
+ }
37
+ function unregister(env, id) {
38
+ withRegistry(env, (registry) => deleteRegisteredProject(registry, id));
39
+ }
40
+ function undoSteps(root, from, backup, to) {
41
+ return [
42
+ `otea projects forget ${root}`,
43
+ `rename ${backup} back to ${from}`,
44
+ `delete ${to} once you no longer need it`,
45
+ ];
46
+ }
47
+ // Moves the old folder aside, unless another process still holds it (Windows refuses the rename)
48
+ // or wrote to it since it was copied; either way the move is undone and the caller told.
49
+ function moveAside(from, to, root, now) {
50
+ const backup = join(root, backupName(now));
51
+ try {
52
+ renameSync(from, backup);
53
+ }
54
+ catch {
55
+ throw new OteaError('in_use', `${from} is in use by another process; stop it and run again`);
56
+ }
57
+ if (!isDeepStrictEqual(summaryOf(backup), summaryOf(to))) {
58
+ renameSync(backup, from);
59
+ throw new OteaError('in_use', `${from} was written to during the migration; run it again`);
60
+ }
61
+ const commonDir = gitCommonDir(root);
62
+ if (commonDir)
63
+ excludeFromGit(commonDir, `${BACKUP_PREFIX}*/`);
64
+ return backup;
65
+ }
66
+ function migrate(project, env, now) {
67
+ const { root, identity } = project;
68
+ const from = project.dataDir;
69
+ const to = join(oteaHome(env), 'data', identity.id);
70
+ withRegistry(env, (registry) => {
71
+ const link = linkAt(registry, root);
72
+ if (link && link.link.pathKey === keyOf(root).pathKey) {
73
+ throw new OteaError('already_exists', `${root} is already linked to ${link.project.id}`);
74
+ }
75
+ if (!selectRegisteredProject(registry, identity.id))
76
+ return;
77
+ // Left registered by an undone migration: reusable once its copy is gone, as the undo says.
78
+ const linked = selectProjectPaths(registry).some((path) => path.projectId === identity.id);
79
+ if (linked || existsSync(to)) {
80
+ throw new OteaError('already_exists', `${identity.id} is already registered with data in ${to}; delete that folder first if it is an undone migration`);
81
+ }
82
+ deleteRegisteredProject(registry, identity.id);
83
+ });
84
+ // A folder left by a run that failed before registering holds nothing the source lacks.
85
+ rmSync(to, { recursive: true, force: true });
86
+ mkdirSync(to, { recursive: true });
87
+ try {
88
+ vacuumInto(project.db, databasePath(to));
89
+ const copy = openDatabase(databasePath(to));
90
+ let tables;
91
+ try {
92
+ const integrity = integrityCheck(copy);
93
+ if (integrity !== 'ok')
94
+ throw new Error(`The copy failed its integrity check: ${integrity}`);
95
+ tables = tableSummary(copy);
96
+ }
97
+ finally {
98
+ copy.close();
99
+ }
100
+ if (!isDeepStrictEqual(tables, tableSummary(project.db))) {
101
+ throw new OteaError('in_use', `${from} was written to during the copy; run it again`);
102
+ }
103
+ for (const name of COPIED) {
104
+ if (existsSync(join(from, name)))
105
+ cpSync(join(from, name), join(to, name), { recursive: true });
106
+ }
107
+ // A copy takes the new folder's ACL on Windows: the push keys are kept to their owner again.
108
+ if (existsSync(join(to, PUSH_KEYS)))
109
+ restrictToOwner(join(to, PUSH_KEYS));
110
+ project.db.close();
111
+ const registry = openRegistry(env);
112
+ try {
113
+ transaction(registry, () => {
114
+ registerProject(registry, { ...identity, storage: 'common', dataDir: to });
115
+ addProjectPath(registry, identity.id, root, kindOf(root));
116
+ });
117
+ }
118
+ finally {
119
+ registry.close();
120
+ }
121
+ let backup;
122
+ try {
123
+ backup = moveAside(from, to, root, now);
124
+ }
125
+ catch (error) {
126
+ unregister(env, identity.id);
127
+ throw error;
128
+ }
129
+ const files = COPIED.reduce((sum, name) => sum + countFiles(join(to, name)), 0);
130
+ const undo = undoSteps(root, from, backup, to);
131
+ return { status: 'migrated', id: identity.id, root, to, from, backup, tables, files, undo };
132
+ }
133
+ catch (error) {
134
+ rmSync(to, { recursive: true, force: true });
135
+ throw error;
136
+ }
137
+ }
138
+ // The project is already common. A local copy of the same project still at its root means an
139
+ // earlier run stopped after registering; it is moved aside once it matches the common data.
140
+ function finish(project, now) {
141
+ const { root, identity, dataDir: to } = project;
142
+ const from = oteaDir(root);
143
+ const tables = tableSummary(project.db);
144
+ const report = { id: identity.id, root, to, tables, files: 0, undo: [] };
145
+ if (!existsSync(databasePath(from))) {
146
+ return { ...report, status: 'already', from: null, backup: null };
147
+ }
148
+ const local = openDatabase(databasePath(from));
149
+ const sameProject = selectProjectIdentity(local)?.id === identity.id;
150
+ local.close();
151
+ if (!sameProject)
152
+ return { ...report, status: 'already', from: null, backup: null };
153
+ if (!isDeepStrictEqual(summaryOf(from), tables)) {
154
+ throw new OteaError('in_use', `${from} differs from the migrated copy in ${to}; it may hold writes made after the migration, so keep the one you want by hand`);
155
+ }
156
+ project.db.close();
157
+ const backup = moveAside(from, to, root, now);
158
+ return { ...report, status: 'finished', from, backup, undo: undoSteps(root, from, backup, to) };
159
+ }
160
+ // Moves the local project the working directory resolves to into common storage. Never run
161
+ // implicitly: only `otea migrate --to common` calls it.
162
+ export function migrateToCommon(cwd, env = process.env, now = new Date()) {
163
+ const project = openProject(cwd, env);
164
+ try {
165
+ return project.storage === 'common' ? finish(project, now) : migrate(project, env, now);
166
+ }
167
+ finally {
168
+ if (project.db.isOpen)
169
+ project.db.close();
170
+ }
171
+ }