@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,429 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { isClosed, positionOf, stateOf } from '../core/board/engine.js';
|
|
3
|
+
import { clone, isEvidence, usedRefs, } from '../core/board/model.js';
|
|
4
|
+
import { parseDefinition } from '../core/board/schema.js';
|
|
5
|
+
import { boardLang, isSetKey } from '../core/board/templates.js';
|
|
6
|
+
import { OteaError } from '../core/errors.js';
|
|
7
|
+
import { leaseExpiry } from '../core/lease.js';
|
|
8
|
+
import { findDraft, listBoards, upsertDraft } from '../store/boards.js';
|
|
9
|
+
import { transaction } from '../store/database.js';
|
|
10
|
+
import { appendEvent, clearLease, findCollection, findEvidence, findItem, takeLease, updateItemState, } from '../store/queries.js';
|
|
11
|
+
import { boardProblems, ensureRequestsBoard, getBoardRecord, insertNewBoard, insertNewBoardSet, saveDraft, } from './boards.js';
|
|
12
|
+
import { BOARD_JSON_SCHEMA, DRAFT_FILENAME, draftTitle } from './draft-request.js';
|
|
13
|
+
import { evidenceFile, placeFile, recordEvidence } from './evidence.js';
|
|
14
|
+
import { insertNewItem, requireItem, systemClock } from './items.js';
|
|
15
|
+
import { liveBoardOf } from './next.js';
|
|
16
|
+
// "Que lo esboce un agente": the person asks on a Pedido (their words its field; how to hand the
|
|
17
|
+
// draft in, its step's instructions: draft-request.ts), the board waits as a draft, the agent
|
|
18
|
+
// hands in a board.json on that Pedido (checked as a board, kept as evidence), and the person
|
|
19
|
+
// merges it into the draft, which says what the agent added.
|
|
20
|
+
// The module the draft is kept under on the Pedido.
|
|
21
|
+
export const DRAFT_MODULE = 'files';
|
|
22
|
+
// The drafting agent holds the Pedido for the whole conversation with the person, which can run
|
|
23
|
+
// far longer than a step's lease: a draft not handed in yet is no stuck work (ONB3-3).
|
|
24
|
+
export const DRAFT_LEASE_TTL_MS = 24 * 60 * 60_000;
|
|
25
|
+
const HANDED_IN = {
|
|
26
|
+
en: (name) => `The draft of ${name} is in: try it in Studio and publish it`,
|
|
27
|
+
es: (name) => `El esbozo de ${name} está listo: pruébalo en Studio y publícalo`,
|
|
28
|
+
};
|
|
29
|
+
const PERSON = { actor: { kind: 'human', name: 'human' }, channel: 'ui' };
|
|
30
|
+
// Creates the Pedido (assigned to the agent when one is named: it holds the item) and the board,
|
|
31
|
+
// waiting on it.
|
|
32
|
+
export function requestAgentDraft(project, input, now = systemClock) {
|
|
33
|
+
ensureRequestsBoard(project, input.lang, now);
|
|
34
|
+
return transaction(project.db, () => {
|
|
35
|
+
const at = now();
|
|
36
|
+
const item = insertPedido(project, {
|
|
37
|
+
title: draftTitle(input.lang, input.name),
|
|
38
|
+
need: input.need,
|
|
39
|
+
agent: input.agent,
|
|
40
|
+
by: input.by ?? PERSON,
|
|
41
|
+
}, at);
|
|
42
|
+
if (input.template !== undefined && isSetKey(input.template)) {
|
|
43
|
+
// A set's boards are drafted together: the first waits on the Pedido, named as asked, and
|
|
44
|
+
// the others come with it under the template's names, for the person to publish as one.
|
|
45
|
+
const [board, ...others] = insertNewBoardSet(project, {
|
|
46
|
+
set: input.template,
|
|
47
|
+
lang: input.lang,
|
|
48
|
+
boards: [{ name: input.name }],
|
|
49
|
+
requestItem: item.id,
|
|
50
|
+
}, now);
|
|
51
|
+
if (!board)
|
|
52
|
+
throw new OteaError('not_found', `There is no template ${input.template}`);
|
|
53
|
+
return { board, item: item.id, others };
|
|
54
|
+
}
|
|
55
|
+
const board = insertNewBoard(project, {
|
|
56
|
+
name: input.name,
|
|
57
|
+
lang: input.lang,
|
|
58
|
+
requestItem: item.id,
|
|
59
|
+
...(input.template === undefined ? {} : { template: input.template }),
|
|
60
|
+
}, now);
|
|
61
|
+
return { board, item: item.id, others: [] };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// The Pedido a board is drafted on, on the project's Pedidos board: the need its first field, held
|
|
65
|
+
// by the agent when one is named. Inside the caller's transaction.
|
|
66
|
+
function insertPedido(project, input, at) {
|
|
67
|
+
const requests = listBoards(project.db).find(({ builtin }) => builtin);
|
|
68
|
+
const collection = requests?.collection;
|
|
69
|
+
const live = collection ? liveBoardOf(project, collection) : undefined;
|
|
70
|
+
if (!collection || !live)
|
|
71
|
+
throw new OteaError('not_found', 'The project has no Pedidos board');
|
|
72
|
+
const need = input.need.trim();
|
|
73
|
+
if (need === '')
|
|
74
|
+
throw new OteaError('missing_fields', 'Say what the board is for');
|
|
75
|
+
const first = live.def.form[0]?.ref;
|
|
76
|
+
const { actor, channel } = input.by;
|
|
77
|
+
const { item } = insertNewItem(project, { collection, title: input.title, fields: first ? { [first]: need } : {}, actor, channel }, at);
|
|
78
|
+
if (input.agent) {
|
|
79
|
+
const lease = { holder: input.agent, expiresAt: leaseExpiry(at, DRAFT_LEASE_TTL_MS) };
|
|
80
|
+
takeLease(project.db, item.id, lease, at);
|
|
81
|
+
appendEvent(project.db, {
|
|
82
|
+
itemId: item.id,
|
|
83
|
+
type: 'claimed',
|
|
84
|
+
actor,
|
|
85
|
+
at,
|
|
86
|
+
data: { ...lease, cause: 'assigned' },
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return item;
|
|
90
|
+
}
|
|
91
|
+
// The board waiting on a Pedido, when there is one.
|
|
92
|
+
export function waitingDraftOf(project, pedido) {
|
|
93
|
+
const row = listBoards(project.db).find(({ id }) => findDraft(project.db, id)?.requestItem === pedido);
|
|
94
|
+
return row ? getBoardRecord(project, row.id) : undefined;
|
|
95
|
+
}
|
|
96
|
+
function requireWaiting(project, pedido) {
|
|
97
|
+
requireItem(project.db, pedido);
|
|
98
|
+
const board = waitingDraftOf(project, pedido);
|
|
99
|
+
if (!board?.draft)
|
|
100
|
+
throw new OteaError('not_found', `No board waits for a draft on ${pedido}`);
|
|
101
|
+
return board;
|
|
102
|
+
}
|
|
103
|
+
// The draft an agent starts from: the board as it stands.
|
|
104
|
+
export function draftToStartFrom(project, pedido) {
|
|
105
|
+
const board = requireWaiting(project, pedido);
|
|
106
|
+
if (!board.draft)
|
|
107
|
+
throw new OteaError('not_found', `No board waits for a draft on ${pedido}`);
|
|
108
|
+
return board.draft.definition;
|
|
109
|
+
}
|
|
110
|
+
const closeWords = (close) => Array.isArray(close) && close.length > 0 ? ` (did you mean ${close.join(', ')}?)` : '';
|
|
111
|
+
// A problem of the board in English, for the agent that drafted it.
|
|
112
|
+
export function problemWords(problem) {
|
|
113
|
+
const quoted = (key) => {
|
|
114
|
+
const value = problem.params[key];
|
|
115
|
+
return typeof value === 'string' ? ` "${value}"` : '';
|
|
116
|
+
};
|
|
117
|
+
const [step, name] = [quoted('step'), quoted('name')];
|
|
118
|
+
const [part, board, other] = [quoted('part'), quoted('board'), quoted('other')];
|
|
119
|
+
const words = {
|
|
120
|
+
board_unnamed: 'the board has no name',
|
|
121
|
+
board_name_taken: `another board is called${name}`,
|
|
122
|
+
icon_unknown: `the icon${quoted('icon')} is not one Otea draws${closeWords(problem.params.close)}; the icons are listed in ${BOARD_JSON_SCHEMA}`,
|
|
123
|
+
no_steps: 'the board has no steps',
|
|
124
|
+
step_unnamed: 'a step has no name',
|
|
125
|
+
part_unnamed: 'a field or piece of evidence has no name',
|
|
126
|
+
duplicate_name: `two things are called${name}`,
|
|
127
|
+
part_missing: 'a step or the form names a part the board does not have',
|
|
128
|
+
reserved_name: `${name.trim() || 'a name'} is a word Otea uses for itself`,
|
|
129
|
+
when_unreadable: 'a "required only when" reads a part that is not a choice',
|
|
130
|
+
way_invalid: `a way out of step${step} leads to itself or to a step the board does not have`,
|
|
131
|
+
back_invalid: `step${step} sends work back to a later step`,
|
|
132
|
+
cap_invalid: 'the cap on new items is not a whole number above zero',
|
|
133
|
+
self_review: `step${step} has the person doing and reviewing it`,
|
|
134
|
+
agent_closes: `step${step} would let an agent close the item: only the person says Done (an agent may close it only in a last step every way into it comes from a step the person closes)`,
|
|
135
|
+
wait_no_split: `step${step} waits for its parts, but${board} divides into nothing`,
|
|
136
|
+
skip_invalid: `step${step} starts new items past it, which only a first step nobody reviews may do`,
|
|
137
|
+
step_always_skipped: `every new item skips step${step}: the form requires everything it hands, so it never runs`,
|
|
138
|
+
split_cycle: `${board.trim() || 'the board'} and${other} divide into each other`,
|
|
139
|
+
split_unknown: `${board.trim() || 'the board'} divides into a board that does not exist`,
|
|
140
|
+
guard_no_push: `the branch${part} is protected but no step lets it be pushed`,
|
|
141
|
+
guard_base: `the base branch the branch${part} protects too is not a branch name`,
|
|
142
|
+
initial_invalid: `the field${part} starts with a value it does not have`,
|
|
143
|
+
mention_raw: `step${step} mentions something as @{…}: write it @[id], the id of the step or part`,
|
|
144
|
+
mention_unknown: `step${step} mentions an @[id] the board does not have`,
|
|
145
|
+
analysis_missing: `the analysis role${quoted('role')} names a field the board does not use`,
|
|
146
|
+
analysis_kind: `the analysis role${quoted('role')} names${part}, which it cannot read: effort, risk and impact read a level, number or choice; area a choice, several or short text; due a date`,
|
|
147
|
+
};
|
|
148
|
+
return `${problem.level}: ${words[problem.code]}`;
|
|
149
|
+
}
|
|
150
|
+
const SHOWN_PROBLEMS = 12;
|
|
151
|
+
// A board.json of the wrong shape, for the agent that wrote it: what is wrong, one line each, then
|
|
152
|
+
// where to start from (`start`), the published shape, and Studio, where the person can finish it.
|
|
153
|
+
function notABoard(start, problems) {
|
|
154
|
+
const more = problems.length - SHOWN_PROBLEMS;
|
|
155
|
+
return [
|
|
156
|
+
'The file is not a board:',
|
|
157
|
+
...problems.slice(0, SHOWN_PROBLEMS).map((problem) => ` ${problem}`),
|
|
158
|
+
...(more > 0 ? [` and ${more} more`] : []),
|
|
159
|
+
`${start}: it has every key a board takes. Each key, with what it is for and an example, is in ${BOARD_JSON_SCHEMA}. A board you cannot get right in JSON, the person can finish in Studio.`,
|
|
160
|
+
].join('\n');
|
|
161
|
+
}
|
|
162
|
+
const BOM = String.fromCharCode(0xfeff);
|
|
163
|
+
const withoutBom = (text) => (text.startsWith(BOM) ? text.slice(1) : text);
|
|
164
|
+
// The agent's board.json read as a board, or what is wrong with it; `start`: where to start from.
|
|
165
|
+
function readDraftFile(text, start) {
|
|
166
|
+
let raw;
|
|
167
|
+
try {
|
|
168
|
+
// PowerShell 5 writes utf8 with a BOM, which JSON.parse refuses.
|
|
169
|
+
raw = JSON.parse(withoutBom(text));
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
throw new OteaError('invalid_board', `${DRAFT_FILENAME} is not JSON`);
|
|
173
|
+
}
|
|
174
|
+
const reading = parseDefinition(raw);
|
|
175
|
+
if (!reading.ok)
|
|
176
|
+
throw new OteaError('invalid_board', notABoard(start, reading.problems));
|
|
177
|
+
return reading;
|
|
178
|
+
}
|
|
179
|
+
// The parts a draft defines but places nowhere (form, a step's handoff, anytime): no item would
|
|
180
|
+
// get them, and Studio does not show them on the board, so the agent is told, by their names.
|
|
181
|
+
function unplacedNote(def) {
|
|
182
|
+
const used = usedRefs(def);
|
|
183
|
+
const names = Object.values(def.parts)
|
|
184
|
+
.filter(({ id }) => !used.has(id))
|
|
185
|
+
.map(({ name }) => name);
|
|
186
|
+
if (names.length === 0)
|
|
187
|
+
return [];
|
|
188
|
+
const listed = names.length === 1 ? names[0] : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
|
189
|
+
return [
|
|
190
|
+
`parts: ${listed} ${names.length === 1 ? 'is' : 'are'} on no form, handoff or anytime, so no item gets ${names.length === 1 ? 'it' : 'them'}: place each, or remove it [parts]`,
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
const nameNote = (kept, file) => `name: the board keeps the name "${kept}" it was asked for; the file's ${file.trim() ? `"${file.trim()}"` : 'empty name'} is not used [name]`;
|
|
194
|
+
// The agent hands in its draft: it must read as a board; then it is kept on the Pedido as
|
|
195
|
+
// board.json and merged by id into the board's draft at once (handing it in is the agent's
|
|
196
|
+
// handoff of the draft: Studio's home sees it arrive and opens it with what the agent added), and
|
|
197
|
+
// what is still wrong with it (problems the person sees in Studio) comes back.
|
|
198
|
+
export function submitAgentDraft(project, input, now = systemClock) {
|
|
199
|
+
const board = requireWaiting(project, input.id);
|
|
200
|
+
const reading = readDraftFile(input.text, `Start from what otea board draft ${input.id} prints`);
|
|
201
|
+
// The name is the person's (the one asked for, or since given in Studio): the file is checked
|
|
202
|
+
// under it, so a name the file left empty or took from another board is no problem, and is said.
|
|
203
|
+
const name = board.draft?.definition.name ?? reading.definition.name;
|
|
204
|
+
const kept = reading.definition.name.trim() === name.trim() ? [] : [nameNote(name, reading.definition.name)];
|
|
205
|
+
const checked = { ...reading.definition, name };
|
|
206
|
+
const problems = boardProblems(project, board.id, checked).map(problemWords);
|
|
207
|
+
const evidence = transaction(project.db, () => {
|
|
208
|
+
const item = requireItem(project.db, input.id);
|
|
209
|
+
const at = now();
|
|
210
|
+
const file = { filename: DRAFT_FILENAME, bytes: Buffer.from(withoutBom(input.text), 'utf8') };
|
|
211
|
+
// The Pedido's page has no module for it: it is kept under files, found by its name.
|
|
212
|
+
const placed = { ...placeFile(project, item, file, input.actor, at), module: DRAFT_MODULE };
|
|
213
|
+
const recorded = recordEvidence(project, item.id, placed, input, at);
|
|
214
|
+
waitForPerson(project, item, name, input, at);
|
|
215
|
+
return recorded;
|
|
216
|
+
});
|
|
217
|
+
mergeAgentDraft(project, board.id, evidence.id, now);
|
|
218
|
+
return {
|
|
219
|
+
board: board.id,
|
|
220
|
+
evidence,
|
|
221
|
+
problems,
|
|
222
|
+
notes: [...kept, ...(reading.notes ?? []), ...unplacedNote(checked)],
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
// Handing the draft in is the agent's handoff: the Pedido goes to the person's review of its step
|
|
226
|
+
// (trying the board and publishing it, which closes the Pedido), and the agent's lease goes with
|
|
227
|
+
// the work it ended. Handed in again from there, it stays where it waits.
|
|
228
|
+
function waitForPerson(project, item, name, input, at) {
|
|
229
|
+
const position = positionOf(item.state);
|
|
230
|
+
if (isClosed(position) || position.phase !== 'doing')
|
|
231
|
+
return;
|
|
232
|
+
const live = liveBoardOf(project, item.collection);
|
|
233
|
+
const step = live?.def.steps.find(({ id }) => id === position.step);
|
|
234
|
+
if (!live || !step || step.reviewer !== 'you')
|
|
235
|
+
return;
|
|
236
|
+
const to = stateOf({ step: step.id, phase: 'review' });
|
|
237
|
+
updateItemState(project.db, item.id, to, at);
|
|
238
|
+
appendEvent(project.db, {
|
|
239
|
+
itemId: item.id,
|
|
240
|
+
type: 'transitioned',
|
|
241
|
+
actor: input.actor,
|
|
242
|
+
at,
|
|
243
|
+
data: {
|
|
244
|
+
from: item.state,
|
|
245
|
+
to,
|
|
246
|
+
reason: HANDED_IN[boardLang(live.def)](name.trim()),
|
|
247
|
+
channel: input.channel,
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
const held = item.lease;
|
|
251
|
+
if (!held)
|
|
252
|
+
return;
|
|
253
|
+
clearLease(project.db, item.id);
|
|
254
|
+
appendEvent(project.db, {
|
|
255
|
+
itemId: item.id,
|
|
256
|
+
type: 'released',
|
|
257
|
+
actor: input.actor,
|
|
258
|
+
at,
|
|
259
|
+
data: { holder: held.holder, cause: 'handed_in' },
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
// An agent the person asked for a board starts what Studio's "Que lo esboce un agente" does: the
|
|
263
|
+
// Pedido, held by the agent, and the board waiting on it; with a board.json, handed in at once.
|
|
264
|
+
// A file that is not a board makes nothing. Publishing stays the person's, in Studio.
|
|
265
|
+
export function proposeAgentDraft(project, input, now = systemClock) {
|
|
266
|
+
if (input.text !== undefined)
|
|
267
|
+
readDraftFile(input.text, 'Nothing was made. Without --file it makes the board and its Pedido; then start from what otea board draft <id> prints');
|
|
268
|
+
const { actor, channel } = input;
|
|
269
|
+
const asked = requestAgentDraft(project, {
|
|
270
|
+
name: input.name,
|
|
271
|
+
need: input.need,
|
|
272
|
+
agent: actor.name,
|
|
273
|
+
lang: input.lang,
|
|
274
|
+
by: { actor, channel },
|
|
275
|
+
...(input.template === undefined ? {} : { template: input.template }),
|
|
276
|
+
}, now);
|
|
277
|
+
if (input.text === undefined)
|
|
278
|
+
return asked;
|
|
279
|
+
const submitted = submitAgentDraft(project, { id: asked.item, text: input.text, actor, channel }, now);
|
|
280
|
+
return { ...asked, board: getBoardRecord(project, asked.board.id), submitted };
|
|
281
|
+
}
|
|
282
|
+
// The Pedido's title when an agent proposes a change to a board already published.
|
|
283
|
+
const CHANGE_TITLE = {
|
|
284
|
+
en: (name) => `Change the board ${name}`,
|
|
285
|
+
es: (name) => `Cambiar el tablero ${name}`,
|
|
286
|
+
};
|
|
287
|
+
// An agent the person asked to change a published board (a field, a step) proposes it as it
|
|
288
|
+
// proposes a new one (otea board draft --change): a Pedido it holds, and the board's draft waiting
|
|
289
|
+
// on it, from the draft the person already has in Studio or else the board as published. The live
|
|
290
|
+
// board keeps working as it is; the agent hands its board.json in on the Pedido, and the person
|
|
291
|
+
// publishes the change in Studio, which closes the Pedido. A file that is not a board makes nothing.
|
|
292
|
+
export function proposeBoardChange(project, input, now = systemClock) {
|
|
293
|
+
if (input.text !== undefined)
|
|
294
|
+
readDraftFile(input.text, 'Nothing was made. Without --file it opens the change and its Pedido; then start from what otea board draft <id> prints');
|
|
295
|
+
ensureRequestsBoard(project, input.lang, now);
|
|
296
|
+
const asked = transaction(project.db, () => {
|
|
297
|
+
const collection = findCollection(project.db, input.board)?.name;
|
|
298
|
+
const live = collection ? liveBoardOf(project, collection) : undefined;
|
|
299
|
+
if (!live)
|
|
300
|
+
throw new OteaError('not_found', `There is no published board "${input.board}"`);
|
|
301
|
+
const kept = findDraft(project.db, live.id);
|
|
302
|
+
const waiting = kept?.requestItem ? findItem(project.db, kept.requestItem) : undefined;
|
|
303
|
+
if (waiting && !isClosed(positionOf(waiting.state)))
|
|
304
|
+
throw new OteaError('already_exists', `A draft of ${live.def.name} already waits on ${waiting.id}: hand it in there with otea board draft ${waiting.id} --file <board.json>`);
|
|
305
|
+
const at = now();
|
|
306
|
+
const { id: item } = insertPedido(project, {
|
|
307
|
+
title: CHANGE_TITLE[input.lang](live.def.name),
|
|
308
|
+
need: input.need,
|
|
309
|
+
agent: input.actor.name,
|
|
310
|
+
by: input,
|
|
311
|
+
}, at);
|
|
312
|
+
upsertDraft(project.db, {
|
|
313
|
+
boardId: live.id,
|
|
314
|
+
definition: kept?.definition ?? JSON.stringify(live.def),
|
|
315
|
+
baseVersion: kept ? kept.baseVersion : live.version,
|
|
316
|
+
updatedAt: at,
|
|
317
|
+
requestItem: item,
|
|
318
|
+
agentNote: null,
|
|
319
|
+
});
|
|
320
|
+
return { board: getBoardRecord(project, live.id), item };
|
|
321
|
+
});
|
|
322
|
+
if (input.text === undefined)
|
|
323
|
+
return asked;
|
|
324
|
+
const { actor, channel } = input;
|
|
325
|
+
const submitted = submitAgentDraft(project, { id: asked.item, text: input.text, actor, channel }, now);
|
|
326
|
+
return { ...asked, board: getBoardRecord(project, asked.board.id), submitted };
|
|
327
|
+
}
|
|
328
|
+
const NOTE_WORDS = {
|
|
329
|
+
en: {
|
|
330
|
+
step: '+ step',
|
|
331
|
+
gone: '− step',
|
|
332
|
+
evidence: '+ evidence',
|
|
333
|
+
field: '+ field',
|
|
334
|
+
instructions: 'instructions in',
|
|
335
|
+
changed: 'changes in',
|
|
336
|
+
item: 'item:',
|
|
337
|
+
about: 'About this board',
|
|
338
|
+
idle: 'When there is nothing to do',
|
|
339
|
+
unplaced: 'placed nowhere, not added:',
|
|
340
|
+
},
|
|
341
|
+
es: {
|
|
342
|
+
step: '+ paso',
|
|
343
|
+
gone: '− paso',
|
|
344
|
+
evidence: '+ evidencia',
|
|
345
|
+
field: '+ campo',
|
|
346
|
+
instructions: 'instrucciones en',
|
|
347
|
+
changed: 'cambios en',
|
|
348
|
+
item: 'ítem:',
|
|
349
|
+
about: 'Sobre este tablero',
|
|
350
|
+
idle: 'Cuando no hay nada que hacer',
|
|
351
|
+
unplaced: 'sin lugar, no se agregó:',
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
355
|
+
// The agent's board is what it was asked for, whole: its steps (in its order) replace the draft's,
|
|
356
|
+
// so a step it left out is gone; its item, form, instructions and texts are taken as they are.
|
|
357
|
+
// Only the name stays the person's. The draft's parts the agent's board uses are kept, so a step put
|
|
358
|
+
// back finds its own; the rest go with what it left out. The note says what changed, removals
|
|
359
|
+
// included.
|
|
360
|
+
export function mergeDefinitions(draft, agent) {
|
|
361
|
+
const words = NOTE_WORDS[boardLang(draft)];
|
|
362
|
+
// A part the agent adds and places nowhere would reach no item and wait unseen in the draft: it
|
|
363
|
+
// is left out, and the note says so by name.
|
|
364
|
+
const placed = usedRefs(agent);
|
|
365
|
+
const unplaced = Object.values(agent.parts).filter((part) => !draft.parts[part.id] && !placed.has(part.id));
|
|
366
|
+
const parts = clone(agent.parts);
|
|
367
|
+
for (const { id } of unplaced)
|
|
368
|
+
delete parts[id];
|
|
369
|
+
// A part of the draft the agent's board leaves out and does not use is gone with it: kept, it
|
|
370
|
+
// stood beside the copy the agent renamed, each part twice on the board (P5-R3-9).
|
|
371
|
+
const left = Object.values(draft.parts).filter(({ id }) => !agent.parts[id] && !placed.has(id));
|
|
372
|
+
const kept = clone(draft.parts);
|
|
373
|
+
for (const { id } of left)
|
|
374
|
+
delete kept[id];
|
|
375
|
+
const layout = { ...draft.layout, ...agent.layout };
|
|
376
|
+
for (const { id } of [...unplaced, ...left])
|
|
377
|
+
delete layout[id];
|
|
378
|
+
const out = {
|
|
379
|
+
...clone(agent),
|
|
380
|
+
name: draft.name,
|
|
381
|
+
parts: { ...kept, ...parts },
|
|
382
|
+
layout,
|
|
383
|
+
};
|
|
384
|
+
const added = Object.values(agent.parts).filter((part) => !draft.parts[part.id] && placed.has(part.id));
|
|
385
|
+
const before = new Map(draft.steps.map((step) => [step.id, step]));
|
|
386
|
+
const fresh = agent.steps.filter(({ id }) => !before.has(id));
|
|
387
|
+
const gone = draft.steps.filter(({ id }) => !agent.steps.some((step) => step.id === id));
|
|
388
|
+
const changes = agent.steps.flatMap((step) => {
|
|
389
|
+
const was = before.get(step.id);
|
|
390
|
+
if (!was || same(was, step))
|
|
391
|
+
return [];
|
|
392
|
+
const onlyInstructions = same({ ...was, instructions: null }, { ...step, instructions: null });
|
|
393
|
+
return [`${onlyInstructions ? words.instructions : words.changed} ${step.name}`];
|
|
394
|
+
});
|
|
395
|
+
const note = [
|
|
396
|
+
...fresh.map((step) => `${words.step} ${step.name}`),
|
|
397
|
+
...gone.map((step) => `${words.gone} ${step.name}`),
|
|
398
|
+
...added.map((part) => `${isEvidence(part) ? words.evidence : words.field} ${part.name}`),
|
|
399
|
+
...changes,
|
|
400
|
+
...(agent.item !== draft.item ? [`${words.item} ${agent.item}`] : []),
|
|
401
|
+
...(agent.about !== draft.about ? [`${words.changed} ${words.about}`] : []),
|
|
402
|
+
...(agent.idle !== draft.idle ? [`${words.changed} ${words.idle}`] : []),
|
|
403
|
+
...(unplaced.length
|
|
404
|
+
? [`${words.unplaced} ${unplaced.map(({ name }) => name).join(', ')}`]
|
|
405
|
+
: []),
|
|
406
|
+
];
|
|
407
|
+
return { definition: out, note };
|
|
408
|
+
}
|
|
409
|
+
// Reads the agent's board.json (evidence on the board's Pedido) into the draft, with what it added.
|
|
410
|
+
export function mergeAgentDraft(project, boardId, evidenceId, now = systemClock) {
|
|
411
|
+
const record = getBoardRecord(project, boardId);
|
|
412
|
+
const draft = record.draft;
|
|
413
|
+
const evidence = findEvidence(project.db, evidenceId);
|
|
414
|
+
if (!draft?.requestItem || !evidence || evidence.itemId !== draft.requestItem)
|
|
415
|
+
throw new OteaError('not_found', `Evidence ${evidenceId} is not a draft handed in for this board`);
|
|
416
|
+
let text;
|
|
417
|
+
try {
|
|
418
|
+
text = readFileSync(evidenceFile(project.dataDir, evidence.sha256), 'utf8');
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
throw new OteaError('not_found', `The file of evidence ${evidenceId} is missing`);
|
|
422
|
+
}
|
|
423
|
+
const reading = parseDefinition(JSON.parse(text));
|
|
424
|
+
if (!reading.ok)
|
|
425
|
+
throw new OteaError('invalid_board', `The file is not a board: ${reading.problems.join('; ')}`);
|
|
426
|
+
const { definition, note } = mergeDefinitions(draft.definition, reading.definition);
|
|
427
|
+
const saved = saveDraft(project, boardId, { definition, baseVersion: draft.baseVersion }, now, note);
|
|
428
|
+
return saved.record;
|
|
429
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { listBoardSummaries } from './boards.js';
|
|
4
|
+
import { listItems, systemClock } from './items.js';
|
|
5
|
+
import { liveBoardOf } from './next.js';
|
|
6
|
+
import { listAgents } from './presence.js';
|
|
7
|
+
// Whether the project's folder is a git repository: a plain folder (a page kept by someone who
|
|
8
|
+
// never uses git) gets prompts with no repository, history, CI or worktree in them.
|
|
9
|
+
function isRepo({ root }) {
|
|
10
|
+
return root === undefined || existsSync(join(root, '.git'));
|
|
11
|
+
}
|
|
12
|
+
// The project as an agent joining it reads it: each published board of the person's (Pedidos
|
|
13
|
+
// aside) with the steps an agent does and how many items wait for an agent with nobody holding
|
|
14
|
+
// them, and the names of the agents working now.
|
|
15
|
+
export function joinFacts(ctx, now = systemClock) {
|
|
16
|
+
const boards = listBoardSummaries(ctx)
|
|
17
|
+
.filter(({ builtin, liveVersion, collection }) => !builtin && liveVersion !== null && collection)
|
|
18
|
+
.flatMap(({ collection }) => {
|
|
19
|
+
const live = collection ? liveBoardOf(ctx, collection) : undefined;
|
|
20
|
+
if (!collection || !live)
|
|
21
|
+
return [];
|
|
22
|
+
const agentSteps = live.def.steps
|
|
23
|
+
.filter(({ doer }) => doer === 'any')
|
|
24
|
+
.map(({ name }) => name);
|
|
25
|
+
const waiting = listItems(ctx, { collection, turn: 'agent' }, now).filter(({ lease }) => !lease).length;
|
|
26
|
+
return [{ name: live.def.name, agentSteps, waiting }];
|
|
27
|
+
});
|
|
28
|
+
// Working: connected now, or holding an item while Otea cannot tell its session ended: a long
|
|
29
|
+
// step runs with no wait and no otea call. Its name is taken either way.
|
|
30
|
+
const working = listAgents(ctx.db, now)
|
|
31
|
+
.filter(({ live, holding, sessionEnded }) => live || (holding.length > 0 && !sessionEnded))
|
|
32
|
+
.map(({ name }) => name);
|
|
33
|
+
// Nobody works there now: the one joining has nobody to join.
|
|
34
|
+
return {
|
|
35
|
+
boards,
|
|
36
|
+
working,
|
|
37
|
+
...(working.length === 0 ? { first: true } : {}),
|
|
38
|
+
repo: isRepo(ctx),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// The facts a prompt of the moment is written from: the join prompt reads the whole project; the
|
|
42
|
+
// others only whether it is a git repository.
|
|
43
|
+
export function promptFacts(ctx, moment, now = systemClock) {
|
|
44
|
+
if (moment === 'join')
|
|
45
|
+
return joinFacts(ctx, now);
|
|
46
|
+
return { boards: [], working: [], repo: isRepo(ctx) };
|
|
47
|
+
}
|
|
48
|
+
// The moment a project is in: no board of its own yet is a first contact, any board makes a new
|
|
49
|
+
// agent one more to join it.
|
|
50
|
+
export function promptKindOf(ctx) {
|
|
51
|
+
return listBoardSummaries(ctx).some(({ builtin }) => !builtin) ? 'join' : 'start';
|
|
52
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { OteaError } from '../core/errors.js';
|
|
4
|
+
const BEGIN = '<!-- otea:begin -->';
|
|
5
|
+
const END = '<!-- otea:end -->';
|
|
6
|
+
// The marked block `otea init --agents-md` and `otea connect` keep in the project's AGENTS.md: it
|
|
7
|
+
// says where Otea's agent guide is, and holds no copy of it. Each agent then reads the guide once,
|
|
8
|
+
// as it stands now (agentGuideFor): an MCP agent in the server's instructions, any other in otea
|
|
9
|
+
// board, which a copy here would only repeat, and which went stale (MCP-TOKENS). Only the text
|
|
10
|
+
// between the markers is Otea's.
|
|
11
|
+
export const AGENTS_BLOCK = [
|
|
12
|
+
BEGIN,
|
|
13
|
+
'## Otea',
|
|
14
|
+
'',
|
|
15
|
+
"This project hands work between people and agents through Otea. Follow Otea's agent guide to the letter. Over MCP it is the Otea server's instructions. On the command line, or when your client shows no instructions, read it first with `otea board` (MCP: the `board` tool with no name), which also lists the boards. Then `otea next` gives the item to take and what its step asks.",
|
|
16
|
+
END,
|
|
17
|
+
].join('\n');
|
|
18
|
+
function withBlock(current) {
|
|
19
|
+
const begin = current.indexOf(BEGIN);
|
|
20
|
+
const end = current.indexOf(END, begin);
|
|
21
|
+
if (begin >= 0 && end >= 0) {
|
|
22
|
+
return `${current.slice(0, begin)}${AGENTS_BLOCK}${current.slice(end + END.length)}`;
|
|
23
|
+
}
|
|
24
|
+
const separator = current.endsWith('\n') ? '\n' : '\n\n';
|
|
25
|
+
return `${current}${separator}${AGENTS_BLOCK}\n`;
|
|
26
|
+
}
|
|
27
|
+
// Adds the block to AGENTS.md at the project root, or replaces the one already there: running it
|
|
28
|
+
// again never adds a second block.
|
|
29
|
+
export function writeAgentsMd(root) {
|
|
30
|
+
const path = join(root, 'AGENTS.md');
|
|
31
|
+
if (!existsSync(path)) {
|
|
32
|
+
writeFileSync(path, `${AGENTS_BLOCK}\n`);
|
|
33
|
+
return { path, action: 'created' };
|
|
34
|
+
}
|
|
35
|
+
const current = readFileSync(path, 'utf8');
|
|
36
|
+
const next = withBlock(current);
|
|
37
|
+
if (next === current)
|
|
38
|
+
return { path, action: 'unchanged' };
|
|
39
|
+
writeFileSync(path, next);
|
|
40
|
+
return { path, action: current.includes(BEGIN) ? 'updated' : 'added' };
|
|
41
|
+
}
|
|
42
|
+
export const MCP_SERVER = 'otea';
|
|
43
|
+
// The project an agent is pinned to: `otea mcp --project <id>`, or this variable in the
|
|
44
|
+
// environment of its shell or MCP server.
|
|
45
|
+
export const PIN_ENV = 'OTEA_PROJECT_ID';
|
|
46
|
+
// A write by an agent pinned to another project than the one its folder resolves to: refused.
|
|
47
|
+
export function assertPinned(pin, project) {
|
|
48
|
+
if (pin === undefined || pin === project.id)
|
|
49
|
+
return;
|
|
50
|
+
throw new OteaError('forbidden', `This agent is pinned to the project ${pin} (otea mcp --project, or ${PIN_ENV}), but this folder is the project ${project.name} (${project.id}); nothing was written. Work from a folder of ${pin}, or point the agent's MCP server at ${project.id}`);
|
|
51
|
+
}
|
|
52
|
+
// The MCP server an agent adds to its own harness's config (Otea writes none: it works with any
|
|
53
|
+
// harness, and each keeps its config its own way): named otea, it runs this Otea's `mcp` for the
|
|
54
|
+
// project `project`, pinned to it, so a server started from another project's folder refuses to
|
|
55
|
+
// write there. It names no agent: every session names itself, so two terminals never share a name.
|
|
56
|
+
export function mcpEntry(launcher, project) {
|
|
57
|
+
return {
|
|
58
|
+
command: launcher.command,
|
|
59
|
+
args: [...launcher.args, 'mcp', '--project', project],
|
|
60
|
+
...(launcher.env && Object.keys(launcher.env).length > 0 ? { env: { ...launcher.env } } : {}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// The otea entry an older `otea connect` wrote in the project's .mcp.json, which named one agent
|
|
64
|
+
// for every session started there; undefined when there is none.
|
|
65
|
+
export function oldMcpEntry(root) {
|
|
66
|
+
const path = join(root, '.mcp.json');
|
|
67
|
+
if (!existsSync(path))
|
|
68
|
+
return undefined;
|
|
69
|
+
try {
|
|
70
|
+
const config = JSON.parse(readFileSync(path, 'utf8'));
|
|
71
|
+
const args = config.mcpServers?.[MCP_SERVER]?.args;
|
|
72
|
+
return Array.isArray(args) && args.includes('--as') ? path : undefined;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { openQuestion, QUESTION_ANSWERED, QUESTION_ASKED, } from '../core/board/questions.js';
|
|
2
|
+
import { selectEvents, selectEventsOfTypes } from '../store/queries.js';
|
|
3
|
+
// The open question of every item that has one, by item id, read in one query.
|
|
4
|
+
export function askingItems(db) {
|
|
5
|
+
const events = selectEventsOfTypes(db, [QUESTION_ASKED, QUESTION_ANSWERED, 'transitioned']);
|
|
6
|
+
const byItem = new Map();
|
|
7
|
+
for (const event of events) {
|
|
8
|
+
const list = byItem.get(event.itemId) ?? [];
|
|
9
|
+
list.push(event);
|
|
10
|
+
byItem.set(event.itemId, list);
|
|
11
|
+
}
|
|
12
|
+
const out = new Map();
|
|
13
|
+
for (const [id, each] of byItem) {
|
|
14
|
+
const open = openQuestion(each);
|
|
15
|
+
if (open)
|
|
16
|
+
out.set(id, open);
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
// The open question of one item, if any.
|
|
21
|
+
export function askingItem(db, id) {
|
|
22
|
+
return openQuestion(selectEvents(db, id));
|
|
23
|
+
}
|
|
24
|
+
// An item as readers see it while a question waits: the person's turn, and the question.
|
|
25
|
+
export function withAsks(item, open) {
|
|
26
|
+
if (!open || item.turn !== 'agent')
|
|
27
|
+
return item;
|
|
28
|
+
const asks = { question: open.question, by: open.by, text: open.text, at: open.at };
|
|
29
|
+
return { ...item, turn: 'human', asks };
|
|
30
|
+
}
|
|
31
|
+
// The item an agent holds while its own question waits for the person on another one (P7-R3-9):
|
|
32
|
+
// the desk says it waits for the answer there, not that it is doing this one. `asking`: from
|
|
33
|
+
// askingItems, read once for a whole list. Undefined while the item has no live lease, or its
|
|
34
|
+
// holder asks nothing elsewhere.
|
|
35
|
+
export function holderAsksOf(asking, item, now) {
|
|
36
|
+
const holder = item.lease && item.lease.expiresAt > now ? item.lease.holder : undefined;
|
|
37
|
+
if (holder === undefined || asking.has(item.id))
|
|
38
|
+
return undefined;
|
|
39
|
+
const asked = [...asking]
|
|
40
|
+
.filter(([, open]) => open.by === holder)
|
|
41
|
+
.sort(([, a], [, b]) => a.at.localeCompare(b.at))[0];
|
|
42
|
+
return asked ? { by: holder, item: asked[0] } : undefined;
|
|
43
|
+
}
|