orca-multiagent-kit 1.6.0 → 1.7.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 (71) hide show
  1. package/AI_INSTALL.md +4 -3
  2. package/CHANGELOG.md +41 -1
  3. package/GUIA.html +11 -9
  4. package/README.md +22 -23
  5. package/VERSION +1 -1
  6. package/bin/backup.js +44 -0
  7. package/bin/fetch.js +243 -0
  8. package/bin/hooks.js +187 -0
  9. package/bin/omk.js +127 -51
  10. package/bin/run/cleanup.js +402 -0
  11. package/bin/run/git.js +641 -0
  12. package/bin/run/glob.js +193 -0
  13. package/bin/run/ledger.js +243 -0
  14. package/bin/run/plan.js +328 -0
  15. package/bin/run/units.js +101 -0
  16. package/bin/run/util.js +116 -0
  17. package/bin/run.js +224 -0
  18. package/bin/setup.js +81 -8
  19. package/bin/sync.js +222 -0
  20. package/bin/ui.js +8 -4
  21. package/bin/update.js +169 -0
  22. package/core/AGENTS.md +7 -7
  23. package/docs/EJECUTABLE.md +5 -4
  24. package/docs/MANUAL.md +16 -3
  25. package/docs/ORQUESTADOR.md +59 -1
  26. package/docs/PLUGIN-ORCA.md +34 -16
  27. package/hooks/orca-gate.cjs +402 -0
  28. package/install.sh +26 -13
  29. package/orca-plugin/README.md +3 -1
  30. package/orca-plugin/orca-plugin.json +2 -2
  31. package/orca-plugin/src/kit.test.ts +35 -13
  32. package/orca-plugin/src/kit.ts +64 -19
  33. package/orca-plugin/src/panel-state.ts +11 -3
  34. package/orca-plugin/src/panel.check.ts +71 -0
  35. package/orca-plugin/src/panel.test.tsx +69 -4
  36. package/orca-plugin/src/panel.tsx +32 -16
  37. package/orca-plugin/src/protocol.ts +39 -0
  38. package/orca-plugin/src/tabs/autonomy.tsx +3 -1
  39. package/orca-plugin/src/tabs/history.test.tsx +1 -0
  40. package/orca-plugin/src/tabs/history.tsx +1 -0
  41. package/orca-plugin/src/tabs/notices.test.tsx +1 -0
  42. package/orca-plugin/src/tabs/worktrees.test.tsx +1 -0
  43. package/orca-plugin/src/ui/action-card.tsx +112 -0
  44. package/orca-plugin/src/worker/actions.test.ts +288 -0
  45. package/orca-plugin/src/worker/actions.ts +292 -0
  46. package/orca-plugin/src/worker/context.ts +4 -1
  47. package/orca-plugin/src/worker/history.ts +3 -3
  48. package/orca-plugin/src/worker/notices.ts +1 -4
  49. package/orca-plugin/src/worker.test.ts +24 -6
  50. package/orca-plugin/src/worker.ts +79 -83
  51. package/output-styles/csr-minimal.md +1 -0
  52. package/package.json +3 -3
  53. package/rules/50-done-gate.md +1 -1
  54. package/rules/95-multi-agent.md +13 -3
  55. package/skills/kit-init/SKILL.md +16 -4
  56. package/skills/orca/SKILL.md +27 -5
  57. package/skills/orca/references/adapters/artifact.md +2 -0
  58. package/skills/orca/references/adapters/chat.md +2 -0
  59. package/skills/orca/references/adapters/native-plan.md +6 -0
  60. package/skills/orca/references/adapters/plan-file.md +2 -0
  61. package/skills/orca/references/engine-manual.md +7 -5
  62. package/skills/orca/references/engine-subagents.md +4 -4
  63. package/skills/orca/references/integrate.md +14 -2
  64. package/skills/orca/references/ledger.md +1 -1
  65. package/skills/orca/references/olimpo.md +1 -1
  66. package/skills/orca/references/plan.md +2 -1
  67. package/skills/orca/references/units.md +1 -1
  68. package/skills/orca/references/worker-contract.md +2 -2
  69. package/templates/AGENTS.md +2 -2
  70. package/templates/CLAUDE.md +1 -1
  71. package/templates/claude-settings.json +25 -0
@@ -0,0 +1,193 @@
1
+ // Globs de units.md (write, shared) sin dependencias: `**` (cero o más segmentos), `*` y `?` dentro de
2
+ // un segmento, `{a,b}` y `[abc]` / `[a-z]` / `[!abc]`. Las rutas van con «/», como las da git. `*` y `?`
3
+ // también encajan con ficheros que empiezan por punto (como las pathspecs de git, no como un shell).
4
+ 'use strict';
5
+
6
+ const { RunError } = require('./util');
7
+
8
+ /** Tope de patrones que salen de expandir llaves: `{a,b}{c,d}…` crece exponencialmente. */
9
+ const MAX_EXPANSION = 256;
10
+ const META = /[*?[{\\]/;
11
+
12
+ /** Ruta tal como la compara el matcher: sin `./` delante ni «/» repetidas. */
13
+ function normalizePath(p) {
14
+ return String(p).replace(/\/{2,}/g, '/').replace(/^(\.\/)+/, '');
15
+ }
16
+
17
+ /** Primera alternativa `{…,…}` de primer nivel de `pattern`: {start, end, parts} o null. */
18
+ function findBrace(pattern) {
19
+ for (let i = 0; i < pattern.length; i += 1) {
20
+ const ch = pattern[i];
21
+ if (ch === '\\') { i += 1; continue; }
22
+ if (ch !== '{') continue;
23
+ let depth = 0;
24
+ let partStart = i + 1;
25
+ const parts = [];
26
+ for (let j = i; j < pattern.length; j += 1) {
27
+ const c = pattern[j];
28
+ if (c === '\\') { j += 1; continue; }
29
+ if (c === '{') depth += 1;
30
+ else if (c === '}') {
31
+ depth -= 1;
32
+ if (depth === 0) {
33
+ parts.push(pattern.slice(partStart, j));
34
+ if (parts.length > 1) return { start: i, end: j, parts };
35
+ break; // `{a}` sin coma es literal: sigue buscando después.
36
+ }
37
+ } else if (c === ',' && depth === 1) {
38
+ parts.push(pattern.slice(partStart, j));
39
+ partStart = j + 1;
40
+ }
41
+ }
42
+ }
43
+ return null;
44
+ }
45
+
46
+ /** Expande las llaves de un patrón, en orden: `a{b,c}` → [ab, ac]. */
47
+ function expandBraces(pattern) {
48
+ const out = [];
49
+ const pending = [String(pattern)];
50
+ while (pending.length) {
51
+ const current = pending.shift();
52
+ const brace = findBrace(current);
53
+ if (!brace) {
54
+ out.push(current);
55
+ } else {
56
+ const head = current.slice(0, brace.start);
57
+ const tail = current.slice(brace.end + 1);
58
+ pending.unshift(...brace.parts.map((part) => head + part + tail));
59
+ }
60
+ if (out.length + pending.length > MAX_EXPANSION) {
61
+ throw new RunError(`el glob «${pattern}» se expande a más de ${MAX_EXPANSION} patrones`);
62
+ }
63
+ }
64
+ return out;
65
+ }
66
+
67
+ /** `[…]` que empieza en chars[i]: {token, next} o null si no se cierra (entonces «[» es literal). */
68
+ function parseClass(chars, i) {
69
+ let j = i + 1;
70
+ let negate = false;
71
+ if (chars[j] === '!' || chars[j] === '^') { negate = true; j += 1; }
72
+ const ranges = [];
73
+ let first = true;
74
+ while (j < chars.length && (chars[j] !== ']' || first)) {
75
+ first = false;
76
+ let lo = chars[j];
77
+ if (lo === '\\' && j + 1 < chars.length) { j += 1; lo = chars[j]; }
78
+ let hi = lo;
79
+ if (chars[j + 1] === '-' && j + 2 < chars.length && chars[j + 2] !== ']') {
80
+ hi = chars[j + 2];
81
+ if (hi === '\\' && j + 3 < chars.length) { hi = chars[j + 3]; j += 1; }
82
+ j += 2;
83
+ }
84
+ ranges.push([lo.codePointAt(0), hi.codePointAt(0)]);
85
+ j += 1;
86
+ }
87
+ if (j >= chars.length) return null;
88
+ return { token: { type: 'class', negate, ranges }, next: j + 1 };
89
+ }
90
+
91
+ /** Un segmento del patrón (sin «/») en tokens: lit, any (`?`), star (`*`) y class. */
92
+ function tokenize(segment) {
93
+ const chars = Array.from(segment);
94
+ const tokens = [];
95
+ for (let i = 0; i < chars.length; i += 1) {
96
+ const ch = chars[i];
97
+ if (ch === '\\' && i + 1 < chars.length) { i += 1; tokens.push({ type: 'lit', ch: chars[i] }); continue; }
98
+ if (ch === '*') {
99
+ if (!tokens.length || tokens[tokens.length - 1].type !== 'star') tokens.push({ type: 'star' });
100
+ continue;
101
+ }
102
+ if (ch === '?') { tokens.push({ type: 'any' }); continue; }
103
+ if (ch === '[') {
104
+ const parsed = parseClass(chars, i);
105
+ if (parsed) { tokens.push(parsed.token); i = parsed.next - 1; continue; }
106
+ }
107
+ tokens.push({ type: 'lit', ch });
108
+ }
109
+ return tokens;
110
+ }
111
+
112
+ function matchOne(token, ch) {
113
+ if (token.type === 'any') return true;
114
+ if (token.type === 'lit') return token.ch === ch;
115
+ const code = ch.codePointAt(0);
116
+ const inside = token.ranges.some(([lo, hi]) => code >= lo && code <= hi);
117
+ return token.negate ? !inside : inside;
118
+ }
119
+
120
+ /**
121
+ * Comodín clásico sin recursión: avanza y, al fallar, vuelve al último «*» (O(n·m), sin
122
+ * retroceso exponencial). Lo usan tanto los caracteres de un segmento como los segmentos con `**`.
123
+ */
124
+ function wildcard(items, subject, isStar, matchItem) {
125
+ let ti = 0;
126
+ let si = 0;
127
+ let starTi = -1;
128
+ let starSi = 0;
129
+ while (si < subject.length) {
130
+ if (ti < items.length && isStar(items[ti])) {
131
+ starTi = ti;
132
+ starSi = si;
133
+ ti += 1;
134
+ } else if (ti < items.length && matchItem(items[ti], subject[si])) {
135
+ ti += 1;
136
+ si += 1;
137
+ } else if (starTi !== -1) {
138
+ ti = starTi + 1;
139
+ starSi += 1;
140
+ si = starSi;
141
+ } else {
142
+ return false;
143
+ }
144
+ }
145
+ while (ti < items.length && isStar(items[ti])) ti += 1;
146
+ return ti === items.length;
147
+ }
148
+
149
+ function matchSegment(tokens, segment) {
150
+ return wildcard(tokens, Array.from(segment), (t) => t.type === 'star', matchOne);
151
+ }
152
+
153
+ /** Patrón ya sin llaves en segmentos compilados; `**` como segmento entero es «cero o más». */
154
+ function compile(pattern) {
155
+ let text = normalizePath(pattern);
156
+ if (text.endsWith('/')) text += '**';
157
+ return text.split('/').map((segment) => (segment === '**' ? { globstar: true } : { tokens: tokenize(segment) }));
158
+ }
159
+
160
+ /** Si la ruta (relativa, con «/») encaja en el patrón. */
161
+ function matches(filePath, pattern) {
162
+ if (typeof filePath !== 'string' || typeof pattern !== 'string' || !filePath || !pattern.trim()) return false;
163
+ const segments = normalizePath(filePath).split('/');
164
+ return expandBraces(pattern.trim()).some((expanded) => wildcard(
165
+ compile(expanded),
166
+ segments,
167
+ (item) => Boolean(item.globstar),
168
+ (item, segment) => matchSegment(item.tokens, segment),
169
+ ));
170
+ }
171
+
172
+ /** Si el patrón tiene algún comodín (si no, es una ruta literal). */
173
+ function isGlob(pattern) {
174
+ return META.test(String(pattern));
175
+ }
176
+
177
+ /**
178
+ * Los segmentos literales del principio del patrón, con «/» final si el patrón sigue:
179
+ * `src/**\/*.ts` → `src/`, `*.md` → ``. Un patrón sin comodines se devuelve entero.
180
+ */
181
+ function literalPrefix(pattern) {
182
+ const text = normalizePath(String(pattern).trim());
183
+ if (!isGlob(text)) return text;
184
+ const segments = text.split('/');
185
+ const literal = [];
186
+ for (const segment of segments) {
187
+ if (isGlob(segment)) break;
188
+ literal.push(segment);
189
+ }
190
+ return literal.length ? `${literal.join('/')}/` : '';
191
+ }
192
+
193
+ module.exports = { matches, literalPrefix, isGlob, expandBraces, normalizePath, MAX_EXPANSION };
@@ -0,0 +1,243 @@
1
+ // run.md (skills/orca/references/ledger.md): el estado del run en un fichero, no en la conversación.
2
+ // Lee y escribe su cabecera, la tabla de unidades y el log sin perder lo que no entiende.
3
+ 'use strict';
4
+
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+ const { RunError, checkRunId, checkUnitId, runDir, writeAtomic, clock } = require('./util');
8
+
9
+ /** Columnas de la tabla, en orden: clave corta (la de `omk run set`) y cabecera en run.md. */
10
+ const COLUMNS = [
11
+ ['unit', 'unit'], ['round', 'round'], ['status', 'status'], ['role', 'role'], ['agent', 'agent · model'],
12
+ ['ref', 'ref'], ['branch', 'branch'], ['worktree', 'worktree'], ['base', 'base'], ['head', 'head'],
13
+ ['attempts', 'attempts'], ['updated', 'updated'],
14
+ ];
15
+ const META_KEYS = ['input', 'engine', 'orca_run', 'autonomy', 'integration', 'base_ref', 'cleanup', 'status', 'confirm1'];
16
+ const RUN_STATUS = ['planned', 'active', 'closing', 'done', 'cancelled'];
17
+ const CLEANUP = ['—', 'pending', 'done'];
18
+ const AUTONOMY = ['manual', 'semi', 'auto'];
19
+ const ENGINES = ['orca', 'subagents', 'manual', 'mixto'];
20
+ const EMPTY = '—';
21
+
22
+ // Estados de una unidad: el camino normal y las salidas laterales (ledger.md §Estados).
23
+ const FLOW = ['pending', 'dispatching', 'dispatched', 'reported', 'accepted', 'merged'];
24
+ const SIDE = ['rework', 'blocked', 'discarded', 'reverted'];
25
+ const UNIT_STATUS = [...FLOW, ...SIDE];
26
+
27
+ /**
28
+ * Si se puede pasar de `from` a `to`. Hacia delante en el camino normal se puede saltar pasos (la
29
+ * unidad del coordinador va de `pending` a `merged`); hacia atrás, solo por las salidas laterales.
30
+ */
31
+ function canMove(from, to) {
32
+ if (from === to) return true;
33
+ const a = FLOW.indexOf(from);
34
+ const b = FLOW.indexOf(to);
35
+ if (a !== -1 && b !== -1) return b > a;
36
+ switch (to) {
37
+ case 'rework': return ['reported', 'accepted'].includes(from);
38
+ case 'blocked': return from !== 'merged' && from !== 'discarded' && from !== 'reverted';
39
+ case 'discarded': return from !== 'merged' && from !== 'reverted';
40
+ case 'reverted': return from === 'merged';
41
+ default: break;
42
+ }
43
+ if (from === 'rework') return ['dispatching', 'dispatched'].includes(to);
44
+ if (from === 'blocked') return ['pending', 'dispatching', 'dispatched'].includes(to);
45
+ return false;
46
+ }
47
+
48
+ const TABLE_ROW = /^\s*\|(.*)\|\s*$/;
49
+ const SEPARATOR = /^\s*\|(\s*:?-+:?\s*\|)+\s*$/;
50
+ const META_LINE = /^- ([a-z_0-9]+):\s*(.*?)\s*$/;
51
+
52
+ function cells(line) {
53
+ return TABLE_ROW.exec(line)[1].split('|').map((cell) => cell.trim());
54
+ }
55
+
56
+ /**
57
+ * Lee run.md. Devuelve {id, meta, metaComments, units, log, problems}. `meta` guarda las claves en el
58
+ * orden del fichero; un comentario `# …` al final de una línea de cabecera se conserva, con su sangría, en metaComments.
59
+ */
60
+ function parseRun(text) {
61
+ const lines = String(text).replace(/^/, '').split(/\r?\n/);
62
+ const run = { id: null, meta: {}, metaComments: {}, units: [], log: [], problems: [] };
63
+ let section = 'head';
64
+ let header = null;
65
+ lines.forEach((line, index) => {
66
+ const lineNo = index + 1;
67
+ const title = /^#\s+run\s+(\S+)\s*$/.exec(line);
68
+ if (title && run.id === null) { run.id = title[1]; return; }
69
+ if (/^##\s+Log\s*$/i.test(line)) { section = 'log'; return; }
70
+ if (section === 'log') {
71
+ const entry = /^- (.*)$/.exec(line);
72
+ if (entry) run.log.push(entry[1]);
73
+ return;
74
+ }
75
+ if (TABLE_ROW.test(line)) {
76
+ section = 'table';
77
+ if (SEPARATOR.test(line)) return;
78
+ const row = cells(line);
79
+ if (!header) {
80
+ header = row;
81
+ const expected = COLUMNS.map(([, title]) => title);
82
+ if (row.join('|') !== expected.join('|')) run.problems.push({ line: lineNo, message: `columnas inesperadas en la tabla: ${row.join(' | ')}` });
83
+ return;
84
+ }
85
+ const unit = {};
86
+ COLUMNS.forEach(([key], i) => { unit[key] = row[i] ?? EMPTY; });
87
+ if (row.length !== COLUMNS.length) run.problems.push({ line: lineNo, message: `fila con ${row.length} columnas: ${unit.unit}` });
88
+ run.units.push(unit);
89
+ return;
90
+ }
91
+ if (section !== 'head') return;
92
+ const meta = META_LINE.exec(line);
93
+ if (!meta) return;
94
+ const [, key, raw] = meta;
95
+ const comment = /^(.*?)(\s{2,}#\s.*)$/.exec(raw);
96
+ run.meta[key] = comment ? comment[1] : raw;
97
+ if (comment) run.metaComments[key] = comment[2];
98
+ });
99
+ if (!run.id) run.problems.push({ line: 1, message: 'falta la cabecera «# run <id>»' });
100
+ return run;
101
+ }
102
+
103
+ function serializeRun(run) {
104
+ const out = [`# run ${run.id}`];
105
+ for (const [key, value] of Object.entries(run.meta)) {
106
+ const comment = run.metaComments && run.metaComments[key];
107
+ out.push(`- ${key}: ${value}${comment || ''}`);
108
+ }
109
+ out.push('');
110
+ out.push(`| ${COLUMNS.map(([, title]) => title).join(' | ')} |`);
111
+ out.push(`|${COLUMNS.map(() => '---').join('|')}|`);
112
+ for (const unit of run.units) out.push(`| ${COLUMNS.map(([key]) => unit[key] ?? EMPTY).join(' | ')} |`);
113
+ out.push('');
114
+ out.push('## Log');
115
+ for (const entry of run.log) out.push(`- ${entry}`);
116
+ return `${out.join('\n')}\n`;
117
+ }
118
+
119
+ /** Un valor de celda o de cabecera: una línea, sin «|» (rompería la tabla). */
120
+ function cleanValue(key, value) {
121
+ const text = String(value).trim();
122
+ if (/[|\r\n]/.test(text)) throw new RunError(`${key}: el valor no puede llevar «|» ni saltos de línea`, 2);
123
+ return text === '' ? EMPTY : text;
124
+ }
125
+
126
+ function runFile(root, id) {
127
+ return path.join(runDir(root, id), 'run.md');
128
+ }
129
+
130
+ function readRun(root, id) {
131
+ const file = runFile(root, id);
132
+ let text;
133
+ try {
134
+ text = fs.readFileSync(file, 'utf8');
135
+ } catch (error) {
136
+ if (error.code === 'ENOENT') throw new RunError(`no existe el run ${id} (${file})`);
137
+ throw error;
138
+ }
139
+ const run = parseRun(text);
140
+ if (run.id !== id) run.problems.push({ line: 1, message: `la cabecera dice «${run.id}» y la carpeta es ${id}` });
141
+ return run;
142
+ }
143
+
144
+ function writeRun(root, run) {
145
+ writeAtomic(runFile(root, checkRunId(run.id)), serializeRun(run));
146
+ }
147
+
148
+ /** Ids de los runs de .work/runs con run.md, ordenados. */
149
+ function listRuns(root) {
150
+ const dir = path.join(root, '.work', 'runs');
151
+ let names;
152
+ try {
153
+ names = fs.readdirSync(dir, { withFileTypes: true });
154
+ } catch (error) {
155
+ if (error.code === 'ENOENT') return [];
156
+ throw error;
157
+ }
158
+ return names
159
+ .filter((entry) => entry.isDirectory() && fs.existsSync(path.join(dir, entry.name, 'run.md')))
160
+ .map((entry) => entry.name)
161
+ .sort();
162
+ }
163
+
164
+ function newRun({ id, meta = {}, units = [] }) {
165
+ checkRunId(id);
166
+ const run = {
167
+ id,
168
+ meta: {
169
+ input: EMPTY, engine: EMPTY, autonomy: 'semi', integration: EMPTY, base_ref: EMPTY,
170
+ cleanup: EMPTY, status: 'planned', confirm1: EMPTY,
171
+ },
172
+ metaComments: {},
173
+ units: [],
174
+ log: [],
175
+ problems: [],
176
+ };
177
+ for (const [key, value] of Object.entries(meta)) setMeta(run, key, value);
178
+ for (const unit of units) {
179
+ checkUnitId(unit.id);
180
+ if (run.units.some((u) => u.unit === unit.id)) throw new RunError(`unidad repetida: ${unit.id}`, 2);
181
+ const row = Object.fromEntries(COLUMNS.map(([key]) => [key, EMPTY]));
182
+ Object.assign(row, {
183
+ unit: unit.id,
184
+ round: unit.round === null || unit.round === undefined ? EMPTY : String(unit.round),
185
+ status: 'pending',
186
+ role: unit.role ? cleanValue('role', unit.role) : EMPTY,
187
+ agent: unit.agent ? cleanValue('agent', unit.agent) : EMPTY,
188
+ attempts: '0',
189
+ });
190
+ run.units.push(row);
191
+ }
192
+ return run;
193
+ }
194
+
195
+ function setMeta(run, key, value) {
196
+ if (!META_KEYS.includes(key)) throw new RunError(`clave de cabecera desconocida: ${key} (${META_KEYS.join(', ')})`, 2);
197
+ const text = cleanValue(key, value);
198
+ const allowed = { status: RUN_STATUS, cleanup: CLEANUP, autonomy: AUTONOMY, engine: [EMPTY, ...ENGINES] }[key];
199
+ if (allowed && !allowed.includes(text)) throw new RunError(`${key} no admite «${text}» (${allowed.join(', ')})`, 2);
200
+ run.meta[key] = text;
201
+ return run;
202
+ }
203
+
204
+ /**
205
+ * Cambia campos de una unidad. `status` respeta las transiciones (salvo `force`); pasar a
206
+ * `dispatching` cuenta un intento; `updated` se pone solo.
207
+ */
208
+ function setUnit(run, unitId, fields, { force = false, now = new Date() } = {}) {
209
+ checkUnitId(unitId);
210
+ const unit = run.units.find((u) => u.unit === unitId);
211
+ if (!unit) throw new RunError(`el run ${run.id} no tiene la unidad ${unitId}`);
212
+ const keys = COLUMNS.map(([key]) => key);
213
+ const changes = {};
214
+ for (const [key, value] of Object.entries(fields)) {
215
+ if (!keys.includes(key) || key === 'unit' || key === 'updated') {
216
+ throw new RunError(`campo desconocido o de solo lectura: ${key} (${keys.filter((k) => k !== 'unit' && k !== 'updated').join(', ')})`, 2);
217
+ }
218
+ changes[key] = cleanValue(key, value);
219
+ }
220
+ if (changes.status !== undefined) {
221
+ if (!UNIT_STATUS.includes(changes.status)) throw new RunError(`estado desconocido: ${changes.status} (${UNIT_STATUS.join(', ')})`, 2);
222
+ if (!force && !canMove(unit.status, changes.status)) {
223
+ throw new RunError(`${unitId}: no se pasa de ${unit.status} a ${changes.status} (usa --force si de verdad toca)`);
224
+ }
225
+ if (changes.status === 'dispatching' && unit.status !== 'dispatching' && changes.attempts === undefined) {
226
+ changes.attempts = String((Number.parseInt(unit.attempts, 10) || 0) + 1);
227
+ }
228
+ }
229
+ if (changes.round !== undefined && changes.round !== EMPTY && !/^[0-9]+$/.test(changes.round)) throw new RunError('round tiene que ser un entero ≥0', 2);
230
+ if (changes.attempts !== undefined && !/^[0-9]+$/.test(changes.attempts)) throw new RunError('attempts tiene que ser un entero ≥0', 2);
231
+ Object.assign(unit, changes, { updated: clock(now) });
232
+ return unit;
233
+ }
234
+
235
+ function addLog(run, message, now = new Date()) {
236
+ run.log.push(`${clock(now)} ${cleanValue('log', message)}`);
237
+ return run;
238
+ }
239
+
240
+ module.exports = {
241
+ COLUMNS, META_KEYS, RUN_STATUS, UNIT_STATUS, FLOW, EMPTY,
242
+ canMove, parseRun, serializeRun, runFile, readRun, writeRun, listRuns, newRun, setMeta, setUnit, addLog,
243
+ };