@otea/cli 0.0.0-stage → 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.
- package/LICENSE +661 -0
- package/README.es.md +151 -0
- package/README.md +252 -2
- package/THIRD_PARTY_NOTICES.md +114 -0
- package/bin/otea.mjs +28 -0
- package/dist/app/agent-detail.js +26 -0
- package/dist/app/agent-draft.js +429 -0
- package/dist/app/agent-prompts.js +52 -0
- package/dist/app/agents.js +77 -0
- package/dist/app/asking.js +43 -0
- package/dist/app/board-archive.js +243 -0
- package/dist/app/board-migration.js +272 -0
- package/dist/app/boards.js +870 -0
- package/dist/app/branch-owner.js +48 -0
- package/dist/app/brief.js +53 -0
- package/dist/app/choices.js +61 -0
- package/dist/app/collections.js +101 -0
- package/dist/app/context.js +1 -0
- package/dist/app/crop.js +56 -0
- package/dist/app/devices.js +62 -0
- package/dist/app/draft-request.js +82 -0
- package/dist/app/events.js +12 -0
- package/dist/app/evidence.js +287 -0
- package/dist/app/gates.js +610 -0
- package/dist/app/guide.js +37 -0
- package/dist/app/home.js +145 -0
- package/dist/app/init-boards.js +36 -0
- package/dist/app/intake.js +25 -0
- package/dist/app/item-search.js +141 -0
- package/dist/app/items.js +318 -0
- package/dist/app/keep-waiting.js +44 -0
- package/dist/app/land-order.js +107 -0
- package/dist/app/language.js +52 -0
- package/dist/app/launcher.js +56 -0
- package/dist/app/lease-take.js +54 -0
- package/dist/app/leases.js +86 -0
- package/dist/app/machine.js +39 -0
- package/dist/app/merged.js +89 -0
- package/dist/app/migrate.js +171 -0
- package/dist/app/next.js +1637 -0
- package/dist/app/notes.js +319 -0
- package/dist/app/notify-targets.js +113 -0
- package/dist/app/opened.js +25 -0
- package/dist/app/owner-only.js +34 -0
- package/dist/app/performance.js +28 -0
- package/dist/app/phone.js +97 -0
- package/dist/app/presence.js +596 -0
- package/dist/app/preset-views.js +25 -0
- package/dist/app/presets.js +129 -0
- package/dist/app/priority.js +156 -0
- package/dist/app/profile.js +86 -0
- package/dist/app/project.js +247 -0
- package/dist/app/proofs.js +179 -0
- package/dist/app/questions.js +215 -0
- package/dist/app/reader-filter.js +58 -0
- package/dist/app/relations.js +164 -0
- package/dist/app/relay.js +98 -0
- package/dist/app/repos.js +176 -0
- package/dist/app/restart.js +92 -0
- package/dist/app/set-aside.js +64 -0
- package/dist/app/system-locale.js +6 -0
- package/dist/app/tailscale-cli.js +77 -0
- package/dist/app/tailscale-testing.js +41 -0
- package/dist/app/tailscale.js +177 -0
- package/dist/app/tips.js +30 -0
- package/dist/app/topics-everywhere.js +53 -0
- package/dist/app/topics.js +453 -0
- package/dist/app/undo.js +52 -0
- package/dist/app/validate.js +131 -0
- package/dist/app/watch.js +48 -0
- package/dist/cli/command.js +44 -0
- package/dist/cli/commands.js +3303 -0
- package/dist/cli/exit-codes.js +70 -0
- package/dist/cli/forge.js +176 -0
- package/dist/cli/format.js +340 -0
- package/dist/cli/gh.js +17 -0
- package/dist/cli/gitrepo.js +489 -0
- package/dist/cli/help.js +101 -0
- package/dist/cli/hooks.js +232 -0
- package/dist/cli/main.js +37 -0
- package/dist/cli/merged-outside.js +58 -0
- package/dist/cli/names.js +154 -0
- package/dist/cli/opener.js +21 -0
- package/dist/cli/owner.js +154 -0
- package/dist/cli/phone.js +221 -0
- package/dist/cli/ports.js +24 -0
- package/dist/cli/probe.js +18 -0
- package/dist/cli/run.js +246 -0
- package/dist/cli/serve-file.js +21 -0
- package/dist/cli/stats.js +55 -0
- package/dist/cli/version.js +3 -0
- package/dist/core/agent-guide.js +31 -0
- package/dist/core/agent-prompts.js +139 -0
- package/dist/core/authority.js +94 -0
- package/dist/core/board/analysis.js +86 -0
- package/dist/core/board/choices.js +100 -0
- package/dist/core/board/compile.js +362 -0
- package/dist/core/board/engine.js +523 -0
- package/dist/core/board/hints.js +46 -0
- package/dist/core/board/history.js +146 -0
- package/dist/core/board/ids.js +87 -0
- package/dist/core/board/joins.js +30 -0
- package/dist/core/board/mentions.js +68 -0
- package/dist/core/board/merged.js +18 -0
- package/dist/core/board/model.js +135 -0
- package/dist/core/board/next.js +1116 -0
- package/dist/core/board/notes.js +298 -0
- package/dist/core/board/performance.js +218 -0
- package/dist/core/board/plan.js +299 -0
- package/dist/core/board/problems.js +232 -0
- package/dist/core/board/proofs.js +84 -0
- package/dist/core/board/questions.js +114 -0
- package/dist/core/board/reading.js +220 -0
- package/dist/core/board/readings.js +534 -0
- package/dist/core/board/schema.js +335 -0
- package/dist/core/board/shape-words.js +179 -0
- package/dist/core/board/template-words.js +23 -0
- package/dist/core/board/templates-catalogue.js +965 -0
- package/dist/core/board/templates-coverage.js +261 -0
- package/dist/core/board/templates-flows.js +779 -0
- package/dist/core/board/templates.js +586 -0
- package/dist/core/brief.js +93 -0
- package/dist/core/diagram.js +80 -0
- package/dist/core/errors.js +12 -0
- package/dist/core/evidence.js +33 -0
- package/dist/core/fields.js +129 -0
- package/dist/core/hierarchy.js +30 -0
- package/dist/core/icons.js +181 -0
- package/dist/core/image-crop.js +166 -0
- package/dist/core/item.js +49 -0
- package/dist/core/lease.js +31 -0
- package/dist/core/modules.js +318 -0
- package/dist/core/notify/planner.js +117 -0
- package/dist/core/notify/signals.js +66 -0
- package/dist/core/notify/text.js +60 -0
- package/dist/core/path-key.js +22 -0
- package/dist/core/placement.js +161 -0
- package/dist/core/preset-labels.js +66 -0
- package/dist/core/preset-notes.js +109 -0
- package/dist/core/preset.js +541 -0
- package/dist/core/profile.js +55 -0
- package/dist/core/project-id.js +20 -0
- package/dist/core/refusal.js +1 -0
- package/dist/core/relations.js +208 -0
- package/dist/core/repo.js +54 -0
- package/dist/core/samples.js +161 -0
- package/dist/core/search-words.js +68 -0
- package/dist/core/test-report.js +120 -0
- package/dist/core/time.js +8 -0
- package/dist/core/validation.js +60 -0
- package/dist/core/views.js +171 -0
- package/dist/core/workflow.js +51 -0
- package/dist/mcp/commands.js +101 -0
- package/dist/mcp/server.js +239 -0
- package/dist/mcp/words.js +95 -0
- package/dist/server/boards.js +232 -0
- package/dist/server/changes.js +42 -0
- package/dist/server/diff-tip.js +83 -0
- package/dist/server/drift.js +87 -0
- package/dist/server/errors.js +87 -0
- package/dist/server/evidence.js +82 -0
- package/dist/server/hosts.js +6 -0
- package/dist/server/hub.js +98 -0
- package/dist/server/lan-access.js +62 -0
- package/dist/server/lan.js +164 -0
- package/dist/server/listen.js +70 -0
- package/dist/server/notifier.js +156 -0
- package/dist/server/notify-api.js +151 -0
- package/dist/server/pairing.js +124 -0
- package/dist/server/projects.js +191 -0
- package/dist/server/push.js +199 -0
- package/dist/server/server.js +960 -0
- package/dist/server/session.js +43 -0
- package/dist/server/stream.js +36 -0
- package/dist/server/test-push.js +38 -0
- package/dist/server/token.js +37 -0
- package/dist/server/transports.js +54 -0
- package/dist/server/ui.js +44 -0
- package/dist/server/writes.js +361 -0
- package/dist/server/wrong-address.js +36 -0
- package/dist/store/boards.js +111 -0
- package/dist/store/database.js +45 -0
- package/dist/store/machine.js +77 -0
- package/dist/store/migrations.js +493 -0
- package/dist/store/queries.js +585 -0
- package/dist/store/registry.js +72 -0
- package/package.json +73 -4
- package/presets/architecture/playbook.md +69 -0
- package/presets/architecture/preset.yaml +80 -0
- package/presets/architecture/samples.yaml +23 -0
- package/presets/bug-triage/playbook.md +129 -0
- package/presets/bug-triage/preset.yaml +127 -0
- package/presets/bug-triage/samples/wall-slide-after.png +0 -0
- package/presets/bug-triage/samples/wall-slide-before.png +0 -0
- package/presets/bug-triage/samples.yaml +72 -0
- package/presets/change/playbook.md +115 -0
- package/presets/change/preset.yaml +141 -0
- package/presets/change/samples.yaml +62 -0
- package/presets/review/playbook.md +51 -0
- package/presets/review/preset.yaml +62 -0
- package/presets/review/samples.yaml +27 -0
- package/presets/tasks/playbook.md +78 -0
- package/presets/tasks/preset.yaml +61 -0
- package/presets/tasks/samples.yaml +46 -0
- package/schemas/board.schema.json +764 -0
- package/ui/dist/THIRD_PARTY_NOTICES.md +114 -0
- package/ui/dist/assets/dm-mono-latin-400-normal--0xN8mdc.woff +0 -0
- package/ui/dist/assets/dm-mono-latin-400-normal-4GdczIuU.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-500-normal-CN8Miw6E.woff +0 -0
- package/ui/dist/assets/dm-mono-latin-500-normal-DRMDZjhP.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-400-normal-1aZr6b2b.woff +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-400-normal-C2zvOubV.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-500-normal-BtRyHRi6.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-500-normal-Dw3M13d8.woff +0 -0
- package/ui/dist/assets/index-C3OzJope.js +103 -0
- package/ui/dist/assets/index-COdEjckQ.css +1 -0
- package/ui/dist/assets/newsreader-latin-ext-opsz-italic-CSPGnFdO.woff2 +0 -0
- package/ui/dist/assets/newsreader-latin-ext-opsz-normal-BQn1nviT.woff2 +0 -0
- package/ui/dist/assets/newsreader-latin-opsz-italic-kJKFiXvB.woff2 +0 -0
- package/ui/dist/assets/newsreader-latin-opsz-normal-s-izfB6B.woff2 +0 -0
- package/ui/dist/assets/newsreader-vietnamese-opsz-italic-DTr-ymY4.woff2 +0 -0
- package/ui/dist/assets/newsreader-vietnamese-opsz-normal-BjhtXyW2.woff2 +0 -0
- package/ui/dist/assets/pdf-YwugTw7Y.js +54 -0
- package/ui/dist/assets/pdf-engine-CkBopwck.js +1 -0
- package/ui/dist/assets/pdf-rELvHkft.js +56 -0
- package/ui/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
- package/ui/dist/assets/pdf.worker.min-B7U8ptvh.js +1 -0
- package/ui/dist/assets/pdf.worker.min-CIqJB0yW.mjs +28 -0
- package/ui/dist/assets/pdf.worker.min-UqOn5EDC.js +1 -0
- package/ui/dist/assets/schibsted-grotesk-latin-ext-wght-normal-hsMS0n0O.woff2 +0 -0
- package/ui/dist/assets/schibsted-grotesk-latin-wght-normal-Bb8VGrTG.woff2 +0 -0
- package/ui/dist/icons/apple-touch-icon.png +0 -0
- package/ui/dist/icons/otea-192.png +0 -0
- package/ui/dist/icons/otea-512.png +0 -0
- package/ui/dist/icons/otea-badge.png +0 -0
- package/ui/dist/icons/otea-maskable-512.png +0 -0
- package/ui/dist/index.html +25 -0
- package/ui/dist/manifest.webmanifest +24 -0
- package/ui/dist/otea-idle.svg +5 -0
- package/ui/dist/otea-working.svg +5 -0
- package/ui/dist/otea-yours-working.svg +5 -0
- package/ui/dist/otea-yours.svg +5 -0
- package/ui/dist/sw.js +1 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { OteaError } from '../core/errors.js';
|
|
5
|
+
import { readPreset } from '../core/preset.js';
|
|
6
|
+
import { readSamples, SAMPLES_DIR, SAMPLES_FILE } from '../core/samples.js';
|
|
7
|
+
export const OFFICIAL_PRESETS_DIR = fileURLToPath(new URL('../../presets/', import.meta.url));
|
|
8
|
+
export function projectPresetsDir(dataDir) {
|
|
9
|
+
return join(dataDir, 'presets');
|
|
10
|
+
}
|
|
11
|
+
function subdirectories(dir) {
|
|
12
|
+
if (!existsSync(dir))
|
|
13
|
+
return [];
|
|
14
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
15
|
+
.filter((entry) => entry.isDirectory())
|
|
16
|
+
.map((entry) => entry.name)
|
|
17
|
+
.sort();
|
|
18
|
+
}
|
|
19
|
+
// The texts of the playbooks the preset points to, by path.
|
|
20
|
+
function playbookTexts(dir, preset) {
|
|
21
|
+
const paths = [preset.playbook, ...preset.types.map(({ playbook }) => playbook)];
|
|
22
|
+
return Object.fromEntries([...new Set(paths)]
|
|
23
|
+
.filter((path) => path !== undefined)
|
|
24
|
+
.map((path) => [path, readFileSync(resolve(dir, path), 'utf8')]));
|
|
25
|
+
}
|
|
26
|
+
// The files of a preset's samples folder.
|
|
27
|
+
export function sampleFiles(dir) {
|
|
28
|
+
const folder = join(dir, SAMPLES_DIR);
|
|
29
|
+
if (!existsSync(folder))
|
|
30
|
+
return [];
|
|
31
|
+
return readdirSync(folder, { withFileTypes: true })
|
|
32
|
+
.filter((entry) => entry.isFile())
|
|
33
|
+
.map((entry) => entry.name)
|
|
34
|
+
.sort();
|
|
35
|
+
}
|
|
36
|
+
// A preset's samples.yaml, or undefined without one.
|
|
37
|
+
export function samplesText(dir) {
|
|
38
|
+
const path = join(dir, SAMPLES_FILE);
|
|
39
|
+
return existsSync(path) ? readFileSync(path, 'utf8') : undefined;
|
|
40
|
+
}
|
|
41
|
+
function notesOf(dir, preset, notes) {
|
|
42
|
+
const samples = readSamples(samplesText(dir), preset, sampleFiles(dir));
|
|
43
|
+
return [
|
|
44
|
+
...notes.map((note) => [join(dir, 'preset.yaml'), note]),
|
|
45
|
+
...samples.notes.map((note) => [join(dir, SAMPLES_FILE), note]),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
function loadOne(dir, name, origin) {
|
|
49
|
+
const path = join(dir, name, 'preset.yaml');
|
|
50
|
+
const problem = (message) => ({ preset: name, origin, path, message });
|
|
51
|
+
if (!existsSync(path))
|
|
52
|
+
return { problems: [problem('missing preset.yaml')] };
|
|
53
|
+
const reading = readPreset(readFileSync(path, 'utf8'));
|
|
54
|
+
if (!reading.ok)
|
|
55
|
+
return { problems: reading.problems.map(problem) };
|
|
56
|
+
const { preset } = reading;
|
|
57
|
+
const problems = [];
|
|
58
|
+
if (preset.name !== name) {
|
|
59
|
+
problems.push(problem(`preset: "${preset.name}" does not match its directory "${name}"`));
|
|
60
|
+
}
|
|
61
|
+
const missing = (playbook) => playbook !== undefined && !existsSync(resolve(dir, name, playbook));
|
|
62
|
+
if (missing(preset.playbook)) {
|
|
63
|
+
problems.push(problem(`playbook: ${preset.playbook} does not exist`));
|
|
64
|
+
}
|
|
65
|
+
for (const type of preset.types.filter(({ playbook }) => missing(playbook))) {
|
|
66
|
+
problems.push(problem(`types.${type.name}.playbook: ${type.playbook} does not exist`));
|
|
67
|
+
}
|
|
68
|
+
if (problems.length > 0)
|
|
69
|
+
return { problems };
|
|
70
|
+
const warnings = notesOf(join(dir, name), preset, reading.notes).map(([file, { code, level, message, path: at }]) => ({
|
|
71
|
+
preset: name,
|
|
72
|
+
origin,
|
|
73
|
+
path: file,
|
|
74
|
+
code,
|
|
75
|
+
level,
|
|
76
|
+
at,
|
|
77
|
+
message,
|
|
78
|
+
}));
|
|
79
|
+
const playbookText = Object.values(playbookTexts(join(dir, name), preset))
|
|
80
|
+
.map((text) => text.trim())
|
|
81
|
+
.filter((text) => text !== '')
|
|
82
|
+
.join('\n\n');
|
|
83
|
+
return {
|
|
84
|
+
preset: { ...preset, origin, ...(playbookText === '' ? {} : { playbookText }) },
|
|
85
|
+
problems,
|
|
86
|
+
warnings,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function loadPresets(dataDir, officialDir = OFFICIAL_PRESETS_DIR) {
|
|
90
|
+
const presets = new Map();
|
|
91
|
+
const problems = [];
|
|
92
|
+
const warnings = [];
|
|
93
|
+
const add = ({ preset, problems: found, warnings: warned = [] }) => {
|
|
94
|
+
if (preset)
|
|
95
|
+
presets.set(preset.name, preset);
|
|
96
|
+
problems.push(...found);
|
|
97
|
+
warnings.push(...warned);
|
|
98
|
+
};
|
|
99
|
+
for (const name of subdirectories(officialDir))
|
|
100
|
+
add(loadOne(officialDir, name, 'official'));
|
|
101
|
+
if (dataDir === undefined)
|
|
102
|
+
return { presets, problems, warnings };
|
|
103
|
+
const projectDir = projectPresetsDir(dataDir);
|
|
104
|
+
for (const name of subdirectories(projectDir)) {
|
|
105
|
+
if (presets.has(name)) {
|
|
106
|
+
problems.push({
|
|
107
|
+
preset: name,
|
|
108
|
+
origin: 'project',
|
|
109
|
+
path: join(projectDir, name, 'preset.yaml'),
|
|
110
|
+
message: `"${name}" is an official preset name; rename the project preset`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
add(loadOne(projectDir, name, 'project'));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { presets, problems, warnings };
|
|
118
|
+
}
|
|
119
|
+
export function requirePreset(catalog, name) {
|
|
120
|
+
const preset = catalog.presets.get(name);
|
|
121
|
+
if (preset)
|
|
122
|
+
return preset;
|
|
123
|
+
const problems = catalog.problems.filter((problem) => problem.preset === name);
|
|
124
|
+
if (problems.length > 0) {
|
|
125
|
+
const details = problems.map(({ message }) => message).join('; ');
|
|
126
|
+
throw new OteaError('invalid_preset', `Preset "${name}" is invalid: ${details}`);
|
|
127
|
+
}
|
|
128
|
+
throw new OteaError('not_found', `Preset "${name}" not found`);
|
|
129
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { isScaleRole, ROLES } from '../core/board/analysis.js';
|
|
2
|
+
import { isClosed, positionOf } from '../core/board/engine.js';
|
|
3
|
+
import { OteaError } from '../core/errors.js';
|
|
4
|
+
import { transaction } from '../store/database.js';
|
|
5
|
+
import { findCollection, findItem, selectEvents, selectEventsOfTypes, selectItems, } from '../store/queries.js';
|
|
6
|
+
import { systemClock } from './items.js';
|
|
7
|
+
import { liftSetAside } from './set-aside.js';
|
|
8
|
+
// Numbered over open items only, as the Matrix's «Tu orden» counts them: a closed item keeps no
|
|
9
|
+
// place, and the ones after it move up (pins across the project, a fixed order per board). The
|
|
10
|
+
// stored values stay, so the order between open items never changes.
|
|
11
|
+
export function priorityOf(db) {
|
|
12
|
+
const rows = db
|
|
13
|
+
.prepare(`SELECT p.item_id, i.collection, i.state, p.pin, p.rank
|
|
14
|
+
FROM item_priority p JOIN items i ON i.id = p.item_id`)
|
|
15
|
+
.all().filter(({ state }) => !isClosed(positionOf(state)));
|
|
16
|
+
const out = new Map(rows.map(({ item_id }) => [item_id, {}]));
|
|
17
|
+
const pins = rows.flatMap(({ item_id, pin }) => (pin === null ? [] : [{ item_id, pin }]));
|
|
18
|
+
for (const [index, { item_id }] of pins.sort((a, b) => a.pin - b.pin).entries())
|
|
19
|
+
out.set(item_id, { ...out.get(item_id), pin: index + 1 });
|
|
20
|
+
const ranks = rows.flatMap(({ item_id, collection, rank }) => rank === null ? [] : [{ item_id, collection, rank }]);
|
|
21
|
+
ranks.sort((a, b) => a.collection.localeCompare(b.collection) || a.rank - b.rank);
|
|
22
|
+
const placed = new Map();
|
|
23
|
+
for (const { item_id, collection } of ranks) {
|
|
24
|
+
const rank = (placed.get(collection) ?? 0) + 1;
|
|
25
|
+
placed.set(collection, rank);
|
|
26
|
+
out.set(item_id, { ...out.get(item_id), rank });
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
// Only the person orders the work: an agent asking is refused.
|
|
31
|
+
function assertPerson(actor) {
|
|
32
|
+
if (actor.kind !== 'human')
|
|
33
|
+
throw new OteaError('forbidden', 'Only the person sets the order of the work');
|
|
34
|
+
}
|
|
35
|
+
function requireItemsOf(db, ids, collection) {
|
|
36
|
+
for (const id of ids) {
|
|
37
|
+
const item = findItem(db, id);
|
|
38
|
+
if (!item)
|
|
39
|
+
throw new OteaError('not_found', `There is no item ${id}`);
|
|
40
|
+
if (collection !== undefined && item.collection !== collection)
|
|
41
|
+
throw new OteaError('invalid_id', `${id} is not on this board`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function upsert(db, id, column, value, at) {
|
|
45
|
+
db.prepare(`INSERT INTO item_priority (item_id, ${column}, set_at) VALUES (?, ?, ?)
|
|
46
|
+
ON CONFLICT (item_id) DO UPDATE SET ${column} = excluded.${column}, set_at = excluded.set_at`).run(id, value, at);
|
|
47
|
+
}
|
|
48
|
+
// "Fijar el orden": the items picked on a board's matrix, in the order given, become its fixed
|
|
49
|
+
// order; the board's earlier order is dropped. An empty list clears it.
|
|
50
|
+
export function setOrder(ctx, input, now = systemClock) {
|
|
51
|
+
assertPerson(input.actor);
|
|
52
|
+
const ids = [...new Set(input.ids)];
|
|
53
|
+
transaction(ctx.db, () => {
|
|
54
|
+
requireItemsOf(ctx.db, ids, input.collection);
|
|
55
|
+
if (!findCollection(ctx.db, input.collection))
|
|
56
|
+
throw new OteaError('not_found', `Collection "${input.collection}" not found`);
|
|
57
|
+
const at = now();
|
|
58
|
+
for (const item of selectItems(ctx.db, { collection: input.collection }))
|
|
59
|
+
upsert(ctx.db, item.id, 'rank', null, at);
|
|
60
|
+
for (const [index, id] of ids.entries())
|
|
61
|
+
upsert(ctx.db, id, 'rank', index + 1, at);
|
|
62
|
+
// Each item the person picked for the order is one they want now: one set aside for later
|
|
63
|
+
// is taken up again (P7-R3-1).
|
|
64
|
+
for (const id of ids)
|
|
65
|
+
liftSetAside(ctx.db, { id, actor: input.actor, at, cause: 'order' });
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// "Poner arriba": puts items on top of the work, after the ones already pinned, in the order given;
|
|
69
|
+
// `pinned: false` takes them down.
|
|
70
|
+
export function pinItems(ctx, input, now = systemClock) {
|
|
71
|
+
assertPerson(input.actor);
|
|
72
|
+
const ids = [...new Set(input.ids)];
|
|
73
|
+
transaction(ctx.db, () => {
|
|
74
|
+
requireItemsOf(ctx.db, ids);
|
|
75
|
+
const at = now();
|
|
76
|
+
if (!input.pinned) {
|
|
77
|
+
for (const id of ids)
|
|
78
|
+
upsert(ctx.db, id, 'pin', null, at);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const top = ctx.db.prepare('SELECT MAX(pin) AS top FROM item_priority').get();
|
|
82
|
+
let next = (top.top ?? 0) + 1;
|
|
83
|
+
const current = priorityOf(ctx.db);
|
|
84
|
+
for (const id of ids) {
|
|
85
|
+
// Put on top, an item set aside for later is taken up again (P7-R3-1).
|
|
86
|
+
liftSetAside(ctx.db, { id, actor: input.actor, at, cause: 'pin' });
|
|
87
|
+
if (current.get(id)?.pin !== undefined)
|
|
88
|
+
continue;
|
|
89
|
+
upsert(ctx.db, id, 'pin', next, at);
|
|
90
|
+
next += 1;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export function estimatesOf(ctx, item, def) {
|
|
95
|
+
const refs = scaleRefs(def.analysis);
|
|
96
|
+
if (refs.length === 0)
|
|
97
|
+
return {};
|
|
98
|
+
const updates = selectEvents(ctx.db, item.id).filter(({ type }) => type === 'updated');
|
|
99
|
+
return estimatesFrom(item, refs, updates);
|
|
100
|
+
}
|
|
101
|
+
// The same for a whole list (the board's items in /api/items): every item's updates come from one
|
|
102
|
+
// query instead of one per item. An item without estimates is left out of the map.
|
|
103
|
+
export function estimatesOfItems(ctx, items, defOf) {
|
|
104
|
+
const refsOf = new Map();
|
|
105
|
+
for (const { collection } of items) {
|
|
106
|
+
if (!refsOf.has(collection))
|
|
107
|
+
refsOf.set(collection, scaleRefs(defOf(collection)?.analysis));
|
|
108
|
+
}
|
|
109
|
+
const out = new Map();
|
|
110
|
+
if (![...refsOf.values()].some((refs) => refs.length > 0))
|
|
111
|
+
return out;
|
|
112
|
+
const updates = new Map();
|
|
113
|
+
for (const event of selectEventsOfTypes(ctx.db, ['updated'])) {
|
|
114
|
+
const list = updates.get(event.itemId);
|
|
115
|
+
if (list)
|
|
116
|
+
list.push(event);
|
|
117
|
+
else
|
|
118
|
+
updates.set(event.itemId, [event]);
|
|
119
|
+
}
|
|
120
|
+
for (const item of items) {
|
|
121
|
+
const refs = refsOf.get(item.collection) ?? [];
|
|
122
|
+
if (refs.length === 0)
|
|
123
|
+
continue;
|
|
124
|
+
const estimates = estimatesFrom(item, refs, updates.get(item.id) ?? []);
|
|
125
|
+
if (Object.keys(estimates).length > 0)
|
|
126
|
+
out.set(item.id, estimates);
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
// Who last set each role's field: its creator for a value set at creation, else the last update.
|
|
131
|
+
function estimatesFrom(item, refs, updates) {
|
|
132
|
+
const by = new Map();
|
|
133
|
+
for (const ref of refs)
|
|
134
|
+
if (item.fields[ref] !== undefined)
|
|
135
|
+
by.set(ref, item.createdBy);
|
|
136
|
+
for (const event of updates) {
|
|
137
|
+
const changes = (event.data.changes ?? {});
|
|
138
|
+
for (const ref of refs)
|
|
139
|
+
if (ref in changes)
|
|
140
|
+
by.set(ref, event.actor);
|
|
141
|
+
}
|
|
142
|
+
const out = {};
|
|
143
|
+
for (const ref of refs) {
|
|
144
|
+
const actor = by.get(ref);
|
|
145
|
+
if (actor?.kind === 'agent' && item.fields[ref] !== undefined)
|
|
146
|
+
out[ref] = actor.name;
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
function scaleRefs(analysis) {
|
|
151
|
+
if (!analysis)
|
|
152
|
+
return [];
|
|
153
|
+
return ROLES.filter((role) => isScaleRole(role))
|
|
154
|
+
.map((role) => analysis[role])
|
|
155
|
+
.filter((ref) => ref !== undefined);
|
|
156
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { OteaError } from '../core/errors.js';
|
|
2
|
+
import { assertProfileValue, profileLine } from '../core/profile.js';
|
|
3
|
+
import { transaction } from '../store/database.js';
|
|
4
|
+
import { findAgent, findProfile, profileView, saveProfile, } from '../store/queries.js';
|
|
5
|
+
import { systemClock } from './items.js';
|
|
6
|
+
import { CLI_HARNESS } from './presence.js';
|
|
7
|
+
const named = (harness) => harness && harness.name !== CLI_HARNESS.name ? harness.name : undefined;
|
|
8
|
+
// The harness of a declaration: the MCP client's, else the one named, else the one known.
|
|
9
|
+
function harnessOf(db, input) {
|
|
10
|
+
if (input.channel === 'mcp' && named(input.harness))
|
|
11
|
+
return named(input.harness);
|
|
12
|
+
if (input.given !== undefined)
|
|
13
|
+
return input.given;
|
|
14
|
+
const known = findProfile(db, input.agent)?.profile.harness;
|
|
15
|
+
if (known)
|
|
16
|
+
return known;
|
|
17
|
+
const seen = findAgent(db, input.agent)?.harness;
|
|
18
|
+
return seen && seen !== CLI_HARNESS.name ? seen : undefined;
|
|
19
|
+
}
|
|
20
|
+
export function declareProfile(db, input, now = systemClock) {
|
|
21
|
+
const model = assertProfileValue('model', input.model);
|
|
22
|
+
const effort = assertProfileValue('effort', input.effort);
|
|
23
|
+
if (input.given !== undefined)
|
|
24
|
+
assertProfileValue('harness', input.given);
|
|
25
|
+
return transaction(db, () => {
|
|
26
|
+
const harness = harnessOf(db, input);
|
|
27
|
+
if (harness === undefined) {
|
|
28
|
+
throw new OteaError('invalid_profile', 'Name the harness you run in too: --harness <name>, such as claude-code, codex or gemini-cli');
|
|
29
|
+
}
|
|
30
|
+
const profile = { harness, model, effort };
|
|
31
|
+
const at = now();
|
|
32
|
+
const changed = saveProfile(db, input.agent, profile, {
|
|
33
|
+
at,
|
|
34
|
+
channel: input.channel,
|
|
35
|
+
confirmed: true,
|
|
36
|
+
});
|
|
37
|
+
return { agent: input.agent, profile: profileView(profile), confirmed: true, changed };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// The exact way to declare a profile on the surface the agent uses.
|
|
41
|
+
export function profileCommand(agent, channel) {
|
|
42
|
+
return channel === 'mcp'
|
|
43
|
+
? `the profile tool with as "${agent}", model <id> and effort <level>`
|
|
44
|
+
: `otea profile --model <id> --effort <level> --as ${agent}`;
|
|
45
|
+
}
|
|
46
|
+
// The profile the agent stands on, refused when it declared none; with `confirmed`, also when it
|
|
47
|
+
// has not declared it again in this session (next offers no work until it does).
|
|
48
|
+
export function requireProfile(db, agent, { channel, confirmed = false }) {
|
|
49
|
+
const declared = findProfile(db, agent);
|
|
50
|
+
const how = profileCommand(agent, channel);
|
|
51
|
+
if (!declared) {
|
|
52
|
+
const harness = channel === 'cli' ? ' (add --harness <name> the first time, such as claude-code)' : '';
|
|
53
|
+
throw new OteaError('profile_required', `${agent} has no profile yet: declare the model and effort you run as, exactly as your harness names them (unknown for one this session does not tell you; never guess), with ${how}${harness}`);
|
|
54
|
+
}
|
|
55
|
+
if (confirmed && !declared.confirmed) {
|
|
56
|
+
throw new OteaError('profile_required', `${agent}'s profile (${profileLine(declared.profile)}) is not confirmed in this session: declare the model and effort you run as now with ${how}`);
|
|
57
|
+
}
|
|
58
|
+
return declared.profile;
|
|
59
|
+
}
|
|
60
|
+
// The line every next ends with: the profile on record and how to update it.
|
|
61
|
+
export function profileReminder(profile, agent, channel) {
|
|
62
|
+
return `Your profile: ${profileLine(profile)}. If you changed model or effort, update it: ${profileCommand(agent, channel)}`;
|
|
63
|
+
}
|
|
64
|
+
// The profile a person gives an agent they connect (otea connect): its harness is the MCP client's,
|
|
65
|
+
// named once the client connects, and the agent confirms it in its first session. Without a harness
|
|
66
|
+
// named it keeps the one the agent declared (else the command line); the same profile it declared
|
|
67
|
+
// already stays as confirmed as it was, so connecting after `otea profile` undoes nothing (P8-R2-3).
|
|
68
|
+
export function presetProfile(db, { agent, model, effort, given }, now = systemClock) {
|
|
69
|
+
if (given !== undefined)
|
|
70
|
+
assertProfileValue('harness', given);
|
|
71
|
+
return transaction(db, () => {
|
|
72
|
+
const known = findProfile(db, agent);
|
|
73
|
+
const profile = {
|
|
74
|
+
harness: given ?? known?.profile.harness ?? CLI_HARNESS.name,
|
|
75
|
+
model: assertProfileValue('model', model),
|
|
76
|
+
effort: assertProfileValue('effort', effort),
|
|
77
|
+
};
|
|
78
|
+
const same = known !== undefined &&
|
|
79
|
+
known.profile.harness === profile.harness &&
|
|
80
|
+
known.profile.model === profile.model &&
|
|
81
|
+
known.profile.effort === profile.effort;
|
|
82
|
+
const confirmed = same && known.confirmed;
|
|
83
|
+
saveProfile(db, agent, profile, { at: now(), channel: 'cli', confirmed });
|
|
84
|
+
return profileView(profile);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { OteaError } from '../core/errors.js';
|
|
6
|
+
import { assertIconName } from '../core/icons.js';
|
|
7
|
+
import { PROJECT_ID_RANDOM_BYTES, projectId } from '../core/project-id.js';
|
|
8
|
+
import { openDatabase, transaction } from '../store/database.js';
|
|
9
|
+
import { migrate } from '../store/migrations.js';
|
|
10
|
+
import { insertProjectIdentity, selectProjectIcon, selectProjectIdentity, updateProjectIcon, } from '../store/queries.js';
|
|
11
|
+
import { selectRegisteredProject, selectRegisteredProjects, } from '../store/registry.js';
|
|
12
|
+
import { migrateProjectBoards } from './board-migration.js';
|
|
13
|
+
import { ensureRequestsBoard, syncBoardPresets } from './boards.js';
|
|
14
|
+
import { nameImplicitTypes } from './collections.js';
|
|
15
|
+
import { addProjectPath, findProject, keyOf, kindOf, linkAt, openRegistry, oteaHome, registerProject, withRegistry, } from './home.js';
|
|
16
|
+
import { defaultLang } from './language.js';
|
|
17
|
+
import { loadPresets } from './presets.js';
|
|
18
|
+
const OTEA_DIR = '.otea';
|
|
19
|
+
const EXCLUDE_ENTRY = `${OTEA_DIR}/`;
|
|
20
|
+
export function gitCommonDir(cwd) {
|
|
21
|
+
try {
|
|
22
|
+
const output = execFileSync('git', ['rev-parse', '--git-common-dir'], {
|
|
23
|
+
cwd,
|
|
24
|
+
encoding: 'utf8',
|
|
25
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
26
|
+
});
|
|
27
|
+
return resolve(cwd, output.trim());
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function locate(cwd) {
|
|
34
|
+
const commonDir = gitCommonDir(cwd);
|
|
35
|
+
if (!commonDir)
|
|
36
|
+
return { root: resolve(cwd) };
|
|
37
|
+
return { root: dirname(commonDir), gitCommonDir: commonDir };
|
|
38
|
+
}
|
|
39
|
+
export function oteaDir(root) {
|
|
40
|
+
return join(root, OTEA_DIR);
|
|
41
|
+
}
|
|
42
|
+
export function databasePath(dataDir) {
|
|
43
|
+
return join(dataDir, 'otea.db');
|
|
44
|
+
}
|
|
45
|
+
function hasLocalProject(dir) {
|
|
46
|
+
return existsSync(databasePath(oteaDir(dir)));
|
|
47
|
+
}
|
|
48
|
+
export function excludeFromGit(gitCommonDir, entry = EXCLUDE_ENTRY) {
|
|
49
|
+
const infoDir = join(gitCommonDir, 'info');
|
|
50
|
+
const excludePath = join(infoDir, 'exclude');
|
|
51
|
+
const current = existsSync(excludePath) ? readFileSync(excludePath, 'utf8') : '';
|
|
52
|
+
if (current.split(/\r?\n/).some((line) => line.trim() === entry))
|
|
53
|
+
return;
|
|
54
|
+
mkdirSync(infoDir, { recursive: true });
|
|
55
|
+
const separator = current === '' || current.endsWith('\n') ? '' : '\n';
|
|
56
|
+
appendFileSync(excludePath, `${separator}${entry}\n`);
|
|
57
|
+
}
|
|
58
|
+
// Named after its folder.
|
|
59
|
+
function newIdentity(root) {
|
|
60
|
+
const name = basename(root) || root;
|
|
61
|
+
return { id: projectId(name, randomBytes(PROJECT_ID_RANDOM_BYTES)), name };
|
|
62
|
+
}
|
|
63
|
+
// A database from before identities gets one the first time it is opened; reading first keeps
|
|
64
|
+
// every later open from taking the write lock.
|
|
65
|
+
function ensureIdentity(db, identity) {
|
|
66
|
+
const existing = selectProjectIdentity(db);
|
|
67
|
+
if (existing)
|
|
68
|
+
return existing;
|
|
69
|
+
insertProjectIdentity(db, identity());
|
|
70
|
+
return selectProjectIdentity(db);
|
|
71
|
+
}
|
|
72
|
+
function open(found, env, identity = () => newIdentity(found.root)) {
|
|
73
|
+
const db = openDatabase(databasePath(found.dataDir));
|
|
74
|
+
migrate(db);
|
|
75
|
+
const presets = loadPresets(found.dataDir);
|
|
76
|
+
nameImplicitTypes({ db, presets });
|
|
77
|
+
const project = {
|
|
78
|
+
...found,
|
|
79
|
+
db,
|
|
80
|
+
presets,
|
|
81
|
+
identity: ensureIdentity(db, identity),
|
|
82
|
+
};
|
|
83
|
+
// Published boards join the catalog as compiled presets (app/boards.ts); a collection still on a
|
|
84
|
+
// preset file is read as a published board, and every project has its Pedidos board.
|
|
85
|
+
syncBoardPresets(project);
|
|
86
|
+
// What it makes now, with no desk to ask, is in the language the person uses (app/language.ts).
|
|
87
|
+
const lang = defaultLang(env);
|
|
88
|
+
migrateProjectBoards(project, lang);
|
|
89
|
+
ensureRequestsBoard(project, lang);
|
|
90
|
+
return project;
|
|
91
|
+
}
|
|
92
|
+
// A common project's data lives apart from its folders, so it can go missing on its own.
|
|
93
|
+
function openFound(found, env) {
|
|
94
|
+
if (found.storage === 'common' && !existsSync(databasePath(found.dataDir))) {
|
|
95
|
+
throw new OteaError('not_found', `The data of the Otea project at ${found.root} is missing`);
|
|
96
|
+
}
|
|
97
|
+
return open(found, env);
|
|
98
|
+
}
|
|
99
|
+
// Opens a registered project's data, as seen from `root` (one of its folders).
|
|
100
|
+
export function openRegistered(project, root, env = process.env) {
|
|
101
|
+
return openFound({ root, dataDir: project.dataDir, storage: project.storage }, env);
|
|
102
|
+
}
|
|
103
|
+
const local = (root) => ({ root, dataDir: oteaDir(root), storage: 'local' });
|
|
104
|
+
const linked = ({ link, project }) => ({
|
|
105
|
+
root: link.path,
|
|
106
|
+
dataDir: project.dataDir,
|
|
107
|
+
storage: project.storage,
|
|
108
|
+
});
|
|
109
|
+
// The nearest folder, from `start` up to the filesystem root, holding a local project database.
|
|
110
|
+
// Matching the database rather than `.otea/` keeps a user-level `~/.otea` from passing for one.
|
|
111
|
+
function findAbove(start) {
|
|
112
|
+
for (let dir = start;; dir = dirname(dir)) {
|
|
113
|
+
if (hasLocalProject(dir))
|
|
114
|
+
return dir;
|
|
115
|
+
if (dirname(dir) === dir)
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// The nearest project: the deepest of the registered folders containing `cwd` or the repo `root`,
|
|
120
|
+
// and the local project found walking up from `root`. On a tie the registered folder wins.
|
|
121
|
+
function nearest(cwd, root, env) {
|
|
122
|
+
const links = withRegistry(env, (registry) => [linkAt(registry, cwd), linkAt(registry, root)]);
|
|
123
|
+
const candidates = (links ?? []).flatMap((link) => link ? [{ found: linked(link), length: link.link.pathKey.length }] : []);
|
|
124
|
+
const above = findAbove(root);
|
|
125
|
+
if (above !== undefined)
|
|
126
|
+
candidates.push({ found: local(above), length: keyOf(above).pathKey.length });
|
|
127
|
+
let best;
|
|
128
|
+
for (const candidate of candidates) {
|
|
129
|
+
if (!best || candidate.length > best.length)
|
|
130
|
+
best = candidate;
|
|
131
|
+
}
|
|
132
|
+
return best?.found;
|
|
133
|
+
}
|
|
134
|
+
const samePath = (a, b) => keyOf(a).pathKey === keyOf(b).pathKey;
|
|
135
|
+
// OTEA_PROJECT names a folder holding a local project, a registered folder, or a project id.
|
|
136
|
+
function named(cwd, value, env) {
|
|
137
|
+
const path = resolve(cwd, value);
|
|
138
|
+
if (hasLocalProject(path))
|
|
139
|
+
return local(path);
|
|
140
|
+
const found = withRegistry(env, (registry) => {
|
|
141
|
+
const link = existsSync(path) ? linkAt(registry, path) : undefined;
|
|
142
|
+
if (link && samePath(link.link.path, path))
|
|
143
|
+
return linked(link);
|
|
144
|
+
const project = selectRegisteredProject(registry, value);
|
|
145
|
+
return (project && { root: locate(cwd).root, dataDir: project.dataDir, storage: project.storage });
|
|
146
|
+
});
|
|
147
|
+
if (!found) {
|
|
148
|
+
throw new OteaError('not_found', `No Otea project at ${path} (OTEA_PROJECT); run otea init first`);
|
|
149
|
+
}
|
|
150
|
+
return found;
|
|
151
|
+
}
|
|
152
|
+
// Opens the project named by OTEA_PROJECT, or else the nearest one to the working directory.
|
|
153
|
+
export function openProject(cwd, env = process.env) {
|
|
154
|
+
const override = env.OTEA_PROJECT;
|
|
155
|
+
if (override)
|
|
156
|
+
return openFound(named(cwd, override, env), env);
|
|
157
|
+
const { root } = locate(cwd);
|
|
158
|
+
const found = nearest(cwd, root, env);
|
|
159
|
+
if (found === undefined) {
|
|
160
|
+
const registered = withRegistry(env, (registry) => selectRegisteredProjects(registry).length);
|
|
161
|
+
const join = registered
|
|
162
|
+
? '\nTo use an existing project instead, run otea init --join <id> (ids: otea projects list)'
|
|
163
|
+
: '';
|
|
164
|
+
throw new OteaError('not_found', `No Otea project at ${root} or above it; run otea init first${join}`, { kind: 'no_project', root });
|
|
165
|
+
}
|
|
166
|
+
return openFound(found, env);
|
|
167
|
+
}
|
|
168
|
+
function createLocal({ root, gitCommonDir }, env) {
|
|
169
|
+
mkdirSync(oteaDir(root), { recursive: true });
|
|
170
|
+
if (gitCommonDir)
|
|
171
|
+
excludeFromGit(gitCommonDir);
|
|
172
|
+
return open(local(root), env);
|
|
173
|
+
}
|
|
174
|
+
// Common storage leaves no trace in the folder: the data goes to the Otea home and the registry
|
|
175
|
+
// links the folder to it.
|
|
176
|
+
function createCommon({ root }, env) {
|
|
177
|
+
const identity = newIdentity(root);
|
|
178
|
+
const dataDir = join(oteaHome(env), 'data', identity.id);
|
|
179
|
+
const registry = openRegistry(env);
|
|
180
|
+
try {
|
|
181
|
+
transaction(registry, () => {
|
|
182
|
+
registerProject(registry, { ...identity, storage: 'common', dataDir });
|
|
183
|
+
addProjectPath(registry, identity.id, root, kindOf(root));
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
registry.close();
|
|
188
|
+
}
|
|
189
|
+
mkdirSync(dataDir, { recursive: true });
|
|
190
|
+
return open({ root, dataDir, storage: 'common' }, env, () => identity);
|
|
191
|
+
}
|
|
192
|
+
// Links `path` to a registered project; linking it again to the same project changes nothing.
|
|
193
|
+
function link(registry, project, path) {
|
|
194
|
+
if (hasLocalProject(path)) {
|
|
195
|
+
throw new OteaError('already_exists', `${path} has its own Otea project in ${OTEA_DIR}/`);
|
|
196
|
+
}
|
|
197
|
+
const current = linkAt(registry, path);
|
|
198
|
+
if (current && samePath(current.link.path, path) && current.project.id === project.id) {
|
|
199
|
+
return current.link;
|
|
200
|
+
}
|
|
201
|
+
return addProjectPath(registry, project.id, path, kindOf(path));
|
|
202
|
+
}
|
|
203
|
+
// Links an existing folder (another repo, say) to a registered project.
|
|
204
|
+
export function addPathToProject(path, ref, env = process.env) {
|
|
205
|
+
const registry = openRegistry(env);
|
|
206
|
+
try {
|
|
207
|
+
return link(registry, findProject(registry, ref), path);
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
registry.close();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function joinProject({ root }, ref, env) {
|
|
214
|
+
const registry = openRegistry(env);
|
|
215
|
+
let project;
|
|
216
|
+
try {
|
|
217
|
+
project = findProject(registry, ref);
|
|
218
|
+
link(registry, project, root);
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
registry.close();
|
|
222
|
+
}
|
|
223
|
+
return openFound({ root, dataDir: project.dataDir, storage: project.storage }, env);
|
|
224
|
+
}
|
|
225
|
+
// Creates the project at the repo root (or the folder itself outside git), in common storage unless
|
|
226
|
+
// `local` keeps it in .otea/ there, or links the root to an existing project with `join`. Inside a
|
|
227
|
+
// folder that a project above already covers, it refuses unless `here` asks for a separate project.
|
|
228
|
+
export function initProject(cwd, options = {}, env = process.env) {
|
|
229
|
+
const location = locate(cwd);
|
|
230
|
+
const { root } = location;
|
|
231
|
+
if (options.join !== undefined)
|
|
232
|
+
return joinProject(location, options.join, env);
|
|
233
|
+
const existing = nearest(root, root, env);
|
|
234
|
+
if (existing && samePath(existing.root, root))
|
|
235
|
+
return openFound(existing, env);
|
|
236
|
+
if (existing && !options.here) {
|
|
237
|
+
throw new OteaError('already_exists', `The Otea project at ${existing.root} already covers ${root}; run init --here to create a separate project at ${root}`, { kind: 'covered', root, covering: existing.root });
|
|
238
|
+
}
|
|
239
|
+
return options.local ? createLocal(location, env) : createCommon(location, env);
|
|
240
|
+
}
|
|
241
|
+
export function projectView(project) {
|
|
242
|
+
return { ...project.identity, icon: selectProjectIcon(project.db) };
|
|
243
|
+
}
|
|
244
|
+
export function setProjectIcon(project, icon) {
|
|
245
|
+
updateProjectIcon(project.db, icon === null ? null : assertIconName(icon));
|
|
246
|
+
return projectView(project);
|
|
247
|
+
}
|