dsh-department 0.1.2 → 0.2.1
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/CHANGELOG.md +25 -0
- package/README.md +15 -6
- package/README.ru.md +7 -5
- package/assets/editor.html +621 -0
- package/client.js +240 -13
- package/package.json +1 -1
- package/src/approval.js +40 -0
- package/src/browse-dirs.js +40 -0
- package/src/create-task.js +79 -0
- package/src/discussion.js +48 -0
- package/src/handover.js +138 -0
- package/src/panel-api.js +6 -2
- package/src/routes.js +211 -1
- package/src/settings.js +49 -0
- package/src/store.js +30 -27
- package/src/tools.js +121 -27
- package/src/verify.js +8 -9
- package/src/watchdog.js +4 -0
package/src/tools.js
CHANGED
|
@@ -42,6 +42,11 @@ import {
|
|
|
42
42
|
} from './store.js';
|
|
43
43
|
import { addWorktree, amendCommit, currentBranch, ensureBranch, commitAll, isRepo, listWorktrees, push, removeWorktree, runGit, tag } from './git.js';
|
|
44
44
|
import { isHumanApprover } from './roles.js';
|
|
45
|
+
import { createDepartmentTask } from './create-task.js';
|
|
46
|
+
import { assertDepartmentEnabled } from './settings.js';
|
|
47
|
+
import { buildHandover } from './handover.js';
|
|
48
|
+
import { assertApprovalReady } from './approval.js';
|
|
49
|
+
import { writeDiscussion } from './discussion.js';
|
|
45
50
|
import { runTestGate } from './gates.js';
|
|
46
51
|
import { encodePng } from './png.js';
|
|
47
52
|
import { runBrowse } from './browse.js';
|
|
@@ -52,7 +57,7 @@ import { assertRetryReady, failurePath, hasSection, writeFailureData } from './a
|
|
|
52
57
|
import { formatReport, missingArtifacts, verifyChecklist } from './verify.js';
|
|
53
58
|
|
|
54
59
|
async function collectArtifacts(root, taskId) {
|
|
55
|
-
const names = ['task.md', 'analysis.md', 'concept.md', 'spec.md', 'plan.md'];
|
|
60
|
+
const names = ['task.md', 'analysis.md', 'discussion.md', 'concept.md', 'spec.md', 'plan.md'];
|
|
56
61
|
const files = {};
|
|
57
62
|
for (const name of names) {
|
|
58
63
|
try {
|
|
@@ -62,6 +67,20 @@ async function collectArtifacts(root, taskId) {
|
|
|
62
67
|
files[name] = false;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
70
|
+
for (const name of ['RUN.md', 'MANUAL-QA.md', 'CHANGELOG.md']) {
|
|
71
|
+
try {
|
|
72
|
+
await access(join(taskDir(root, taskId), 'delivery', name));
|
|
73
|
+
files['delivery/' + name] = true;
|
|
74
|
+
} catch {
|
|
75
|
+
files['delivery/' + name] = false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
await access(join(root, 'README.md'));
|
|
80
|
+
files['README.md'] = true;
|
|
81
|
+
} catch {
|
|
82
|
+
files['README.md'] = false;
|
|
83
|
+
}
|
|
65
84
|
return files;
|
|
66
85
|
}
|
|
67
86
|
|
|
@@ -141,6 +160,8 @@ export function registerTools(ctx, activity) {
|
|
|
141
160
|
disposers.push(ctx.tools.register(correctionTool()));
|
|
142
161
|
disposers.push(ctx.tools.register(budgetTool()));
|
|
143
162
|
disposers.push(ctx.tools.register(pauseTool(ctx)));
|
|
163
|
+
disposers.push(ctx.tools.register(handoverTool()));
|
|
164
|
+
disposers.push(ctx.tools.register(discussionTool()));
|
|
144
165
|
disposers.push(ctx.tools.register(sectionTool()));
|
|
145
166
|
disposers.push(ctx.tools.register(ideasTool()));
|
|
146
167
|
disposers.push(ctx.tools.register(critiqueTool()));
|
|
@@ -187,36 +208,19 @@ function startTool() {
|
|
|
187
208
|
render: (_args, value) => text(value.summary),
|
|
188
209
|
},
|
|
189
210
|
async execute(args) {
|
|
211
|
+
await assertDepartmentEnabled('создание задачи');
|
|
190
212
|
const root = requireString(args, 'root');
|
|
191
213
|
const taskId = requireString(args, 'taskId');
|
|
192
|
-
|
|
193
|
-
const existing = await readState(root, taskId);
|
|
194
|
-
if (existing) throw new Error(`task already exists: ${taskId}`);
|
|
195
|
-
let brief = typeof args?.brief === 'string' ? args.brief.trim() : '';
|
|
196
|
-
if (args?.release === true) {
|
|
197
|
-
const template = await readFile(new URL('../templates/release.md', import.meta.url), 'utf8');
|
|
198
|
-
brief = (brief ? brief + '\n\n' : '') + 'Подготовка к релизу (шаблон):\n\n' + template;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let state = createState({
|
|
202
|
-
root,
|
|
203
|
-
taskId,
|
|
214
|
+
const state = await createDepartmentTask(root, taskId, {
|
|
204
215
|
title: args?.title,
|
|
216
|
+
brief: args?.brief,
|
|
205
217
|
branch: args?.branch,
|
|
206
|
-
origin: args?.origin
|
|
207
|
-
testCommand: args?.testCommand
|
|
218
|
+
origin: args?.origin,
|
|
219
|
+
testCommand: args?.testCommand,
|
|
208
220
|
maxAttempts: args?.maxAttempts,
|
|
209
221
|
budgetTokens: args?.budgetTokens,
|
|
222
|
+
release: args?.release === true,
|
|
210
223
|
});
|
|
211
|
-
const branch = await ensureBranch(root, state.branch);
|
|
212
|
-
if (!branch.ok) throw new Error(`cannot create branch ${state.branch}: ${branch.error ?? ''}`);
|
|
213
|
-
state = appendEvent(state, { actor: 'manager', action: 'branch_ready', detail: branch.branch });
|
|
214
|
-
|
|
215
|
-
await mkdir(taskDir(root, taskId), { recursive: true });
|
|
216
|
-
if (brief !== '') {
|
|
217
|
-
await writeFile(join(taskDir(root, taskId), 'task.md'), `${brief}\n`, 'utf8');
|
|
218
|
-
}
|
|
219
|
-
state = await writeState(root, state);
|
|
220
224
|
return summaryOutput(state);
|
|
221
225
|
},
|
|
222
226
|
};
|
|
@@ -279,6 +283,12 @@ function approveTool() {
|
|
|
279
283
|
render: (_args, value) => text(value.summary),
|
|
280
284
|
},
|
|
281
285
|
async execute(args) {
|
|
286
|
+
const approvalRoot = requireString(args, 'root');
|
|
287
|
+
const approvalTask = requireString(args, 'taskId');
|
|
288
|
+
const approvalDoc = requireString(args, 'doc');
|
|
289
|
+
const approvalState = await readState(approvalRoot, approvalTask);
|
|
290
|
+
if (!approvalState) throw new Error(`task not found: ${approvalTask}`);
|
|
291
|
+
await assertApprovalReady(approvalRoot, approvalTask, approvalDoc, approvalState);
|
|
282
292
|
const root = requireString(args, 'root');
|
|
283
293
|
const taskId = requireString(args, 'taskId');
|
|
284
294
|
const doc = requireString(args, 'doc');
|
|
@@ -326,6 +336,7 @@ function gateTool() {
|
|
|
326
336
|
render: (_args, value) => text(value.summary),
|
|
327
337
|
},
|
|
328
338
|
async execute(args) {
|
|
339
|
+
await assertDepartmentEnabled('гейт');
|
|
329
340
|
const root = requireString(args, 'root');
|
|
330
341
|
const taskId = requireString(args, 'taskId');
|
|
331
342
|
const kind = requireString(args, 'kind');
|
|
@@ -394,6 +405,7 @@ function commitTool(activity) {
|
|
|
394
405
|
render: (_args, value) => text(value.summary),
|
|
395
406
|
},
|
|
396
407
|
async execute(args) {
|
|
408
|
+
await assertDepartmentEnabled('коммит этапа');
|
|
397
409
|
const root = requireString(args, 'root');
|
|
398
410
|
const taskId = requireString(args, 'taskId');
|
|
399
411
|
const state = await readState(root, taskId);
|
|
@@ -488,13 +500,13 @@ function commitTool(activity) {
|
|
|
488
500
|
function stageTool() {
|
|
489
501
|
return {
|
|
490
502
|
name: 'dept_stage',
|
|
491
|
-
description: 'Перевести задачу на следующую
|
|
503
|
+
description: 'Перевести задачу на следующую стадию. Порядок гибкий: можно сначала концепцию или сначала ТЗ; проект запускается только после утверждения обоих через dept_approve.',
|
|
492
504
|
parameters: {
|
|
493
505
|
type: 'object',
|
|
494
506
|
properties: {
|
|
495
507
|
root: { type: 'string', description: 'Корень проекта.' },
|
|
496
508
|
taskId: { type: 'string', description: 'Идентификатор задачи.' },
|
|
497
|
-
stage: { type: 'string', enum: ['analysis', '
|
|
509
|
+
stage: { type: 'string', enum: ['analysis', 'spec', 'spec_review', 'concept', 'concept_review', 'executing', 'release', 'done', 'blocked'], description: 'Целевая стадия.' },
|
|
498
510
|
reason: { type: 'string', description: 'Причина перехода.' },
|
|
499
511
|
},
|
|
500
512
|
required: ['root', 'taskId', 'stage'],
|
|
@@ -509,12 +521,22 @@ function stageTool() {
|
|
|
509
521
|
render: (_args, value) => text(value.summary),
|
|
510
522
|
},
|
|
511
523
|
async execute(args) {
|
|
524
|
+
await assertDepartmentEnabled('переход стадии');
|
|
512
525
|
const root = requireString(args, 'root');
|
|
513
526
|
const taskId = requireString(args, 'taskId');
|
|
514
527
|
const target = requireString(args, 'stage');
|
|
515
528
|
const state = await readState(root, taskId);
|
|
516
529
|
if (!state) throw new Error(`task not found: ${taskId}`);
|
|
517
530
|
assertActive(state, 'переход стадии');
|
|
531
|
+
if (target === 'done' && state.stage === 'release') {
|
|
532
|
+
for (const name of ['RUN.md', 'MANUAL-QA.md', 'CHANGELOG.md']) {
|
|
533
|
+
try {
|
|
534
|
+
await access(join(taskDir(root, taskId), 'delivery', name));
|
|
535
|
+
} catch {
|
|
536
|
+
throw new Error(`нельзя завершить: нет delivery/${name}. Собери пакет через dept_handover`);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
518
540
|
|
|
519
541
|
// Переход разрешён только когда артефакты целевой стадии на месте.
|
|
520
542
|
const files = await collectArtifacts(root, taskId);
|
|
@@ -556,7 +578,7 @@ function verifyTool() {
|
|
|
556
578
|
const state = await readState(root, taskId);
|
|
557
579
|
if (!state) throw new Error(`task not found: ${taskId}`);
|
|
558
580
|
|
|
559
|
-
const names = ['task.md', 'analysis.md', 'concept.md', 'spec.md', 'plan.md'];
|
|
581
|
+
const names = ['task.md', 'analysis.md', 'discussion.md', 'concept.md', 'spec.md', 'plan.md'];
|
|
560
582
|
const files = {};
|
|
561
583
|
for (const name of names) {
|
|
562
584
|
try {
|
|
@@ -615,6 +637,7 @@ function amendTool() {
|
|
|
615
637
|
render: (_args, value) => text(value.summary),
|
|
616
638
|
},
|
|
617
639
|
async execute(args) {
|
|
640
|
+
await assertDepartmentEnabled('поправка документа');
|
|
618
641
|
const root = requireString(args, 'root');
|
|
619
642
|
const taskId = requireString(args, 'taskId');
|
|
620
643
|
const by = requireString(args, 'by');
|
|
@@ -1711,6 +1734,7 @@ function pauseTool(ctx) {
|
|
|
1711
1734
|
render: (_args, value) => text(value.summary),
|
|
1712
1735
|
},
|
|
1713
1736
|
async execute(args) {
|
|
1737
|
+
await assertDepartmentEnabled('пауза');
|
|
1714
1738
|
const root = requireString(args, 'root');
|
|
1715
1739
|
const taskId = requireString(args, 'taskId');
|
|
1716
1740
|
const paused = Boolean(args?.paused);
|
|
@@ -1727,3 +1751,73 @@ function pauseTool(ctx) {
|
|
|
1727
1751
|
},
|
|
1728
1752
|
};
|
|
1729
1753
|
}
|
|
1754
|
+
|
|
1755
|
+
function handoverTool() {
|
|
1756
|
+
return {
|
|
1757
|
+
name: 'dept_handover',
|
|
1758
|
+
description: 'Подготовка к продакшену: собирает delivery/ с RUN.md (как запустить), MANUAL-QA.md (ручное тестирование), CHANGELOG.md, RELEASE.md и копиями ТЗ/концепции/плана. Вызывай на стадии release перед done.',
|
|
1759
|
+
parameters: {
|
|
1760
|
+
type: 'object',
|
|
1761
|
+
properties: {
|
|
1762
|
+
root: { type: 'string', description: 'Корень проекта.' },
|
|
1763
|
+
taskId: { type: 'string', description: 'Идентификатор задачи.' },
|
|
1764
|
+
version: { type: 'string', description: 'Версия продукта, например 1.0.0.' },
|
|
1765
|
+
run: { type: 'string', description: 'Команда запуска, например "python3 -m http.server 8000".' },
|
|
1766
|
+
port: { type: 'string', description: 'Адрес/порт после запуска.' },
|
|
1767
|
+
notes: { type: 'string', description: 'Дополнительные заметки для передачи.' },
|
|
1768
|
+
},
|
|
1769
|
+
required: ['root', 'taskId'],
|
|
1770
|
+
},
|
|
1771
|
+
output: {
|
|
1772
|
+
schema: { type: 'object', additionalProperties: false, properties: { dir: { type: 'string' }, version: { type: 'string' }, summary: { type: 'string' } }, required: ['dir', 'version', 'summary'] },
|
|
1773
|
+
render: (_args, value) => text(value.summary),
|
|
1774
|
+
},
|
|
1775
|
+
async execute(args) {
|
|
1776
|
+
await assertDepartmentEnabled('подготовка к продакшену');
|
|
1777
|
+
const root = requireString(args, 'root');
|
|
1778
|
+
const taskId = requireString(args, 'taskId');
|
|
1779
|
+
const result = await buildHandover(root, taskId, {
|
|
1780
|
+
version: args?.version,
|
|
1781
|
+
run: args?.run,
|
|
1782
|
+
port: args?.port,
|
|
1783
|
+
notes: args?.notes,
|
|
1784
|
+
});
|
|
1785
|
+
return { dir: result.dir, version: result.version, summary: `пакет готов: ${result.dir} (RUN.md, MANUAL-QA.md, CHANGELOG.md, RELEASE.md)` };
|
|
1786
|
+
},
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
function discussionTool() {
|
|
1791
|
+
return {
|
|
1792
|
+
name: 'dept_discussion',
|
|
1793
|
+
description: 'Записать обсуждение задачи в discussion.md: цели, не цели, пользователи, ограничения, риски, открытые вопросы, решения. ТЗ нельзя утвердить, пока есть открытые вопросы.',
|
|
1794
|
+
parameters: {
|
|
1795
|
+
type: 'object',
|
|
1796
|
+
properties: {
|
|
1797
|
+
root: { type: 'string', description: 'Корень проекта.' },
|
|
1798
|
+
taskId: { type: 'string', description: 'Идентификатор задачи.' },
|
|
1799
|
+
goals: { type: 'array', items: { type: 'string' }, description: 'Цели.' },
|
|
1800
|
+
nonGoals: { type: 'array', items: { type: 'string' }, description: 'Что НЕ входит в задачу.' },
|
|
1801
|
+
users: { type: 'array', items: { type: 'string' }, description: 'Пользователи и сценарии.' },
|
|
1802
|
+
constraints: { type: 'array', items: { type: 'string' }, description: 'Ограничения.' },
|
|
1803
|
+
risks: { type: 'array', items: { type: 'string' }, description: 'Риски.' },
|
|
1804
|
+
questions: { type: 'array', items: { type: 'string' }, description: 'Открытые вопросы к человеку.' },
|
|
1805
|
+
decisions: { type: 'array', items: { type: 'string' }, description: 'Принятые решения.' },
|
|
1806
|
+
},
|
|
1807
|
+
required: ['root', 'taskId'],
|
|
1808
|
+
},
|
|
1809
|
+
output: {
|
|
1810
|
+
schema: { type: 'object', additionalProperties: false, properties: { path: { type: 'string' }, summary: { type: 'string' } }, required: ['path', 'summary'] },
|
|
1811
|
+
render: (_args, value) => text(value.summary),
|
|
1812
|
+
},
|
|
1813
|
+
async execute(args) {
|
|
1814
|
+
await assertDepartmentEnabled('обсуждение задачи');
|
|
1815
|
+
const root = requireString(args, 'root');
|
|
1816
|
+
const taskId = requireString(args, 'taskId');
|
|
1817
|
+
const state = await readState(root, taskId);
|
|
1818
|
+
if (!state) throw new Error(`task not found: ${taskId}`);
|
|
1819
|
+
const result = await writeDiscussion(root, taskId, state, args ?? {});
|
|
1820
|
+
return { path: result.path, summary: `обсуждение записано: ${result.path}` };
|
|
1821
|
+
},
|
|
1822
|
+
};
|
|
1823
|
+
}
|
package/src/verify.js
CHANGED
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
/** Артефакты, обязательные для стадии. */
|
|
7
7
|
const REQUIRED_ARTIFACTS = Object.freeze({
|
|
8
8
|
analysis: ['task.md'],
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
executing: ['task.md', '
|
|
14
|
-
|
|
9
|
+
spec: ['task.md', 'analysis.md', 'discussion.md'],
|
|
10
|
+
spec_review: ['task.md', 'analysis.md', 'discussion.md', 'spec.md'],
|
|
11
|
+
concept: ['task.md', 'analysis.md', 'discussion.md', 'spec.md'],
|
|
12
|
+
concept_review: ['task.md', 'analysis.md', 'discussion.md', 'spec.md', 'concept.md'],
|
|
13
|
+
executing: ['task.md', 'analysis.md', 'discussion.md', 'spec.md', 'concept.md', 'plan.md', 'README.md'],
|
|
14
|
+
release: ['task.md', 'analysis.md', 'discussion.md', 'spec.md', 'concept.md', 'plan.md', 'delivery/RUN.md', 'delivery/MANUAL-QA.md', 'delivery/CHANGELOG.md'],
|
|
15
|
+
done: ['task.md', 'analysis.md', 'discussion.md', 'spec.md', 'concept.md', 'plan.md', 'delivery/RUN.md', 'delivery/MANUAL-QA.md', 'delivery/CHANGELOG.md'],
|
|
15
16
|
blocked: ['task.md'],
|
|
16
17
|
});
|
|
17
18
|
|
|
@@ -38,11 +39,9 @@ export function verifyChecklist({ state, files, currentBranch }) {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const approved = new Set((state.approvals ?? []).map((item) => item.doc));
|
|
41
|
-
if (['spec', 'spec_review', 'executing', 'done'].includes(state.stage)) {
|
|
42
|
-
check('approval:concept', approved.has('concept'), approved.has('concept') ? 'approved' : 'not approved');
|
|
43
|
-
}
|
|
44
42
|
if (['executing', 'done'].includes(state.stage)) {
|
|
45
43
|
check('approval:spec', approved.has('spec'), approved.has('spec') ? 'approved' : 'not approved');
|
|
44
|
+
check('approval:concept', approved.has('concept'), approved.has('concept') ? 'approved' : 'not approved');
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
if (state.stage === 'executing') {
|
package/src/watchdog.js
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import { readdir, readFile } from 'node:fs/promises';
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
|
|
11
|
+
import { readSettings } from './settings.js';
|
|
12
|
+
|
|
11
13
|
const INTERVAL_MS = 5 * 60 * 1000;
|
|
12
14
|
const IDLE_MINUTES = 15;
|
|
13
15
|
const WAKE_COOLDOWN_MS = 30 * 60 * 1000;
|
|
@@ -80,6 +82,8 @@ export function createWatchdog({ ctx, intervalMs = INTERVAL_MS }) {
|
|
|
80
82
|
if (running) return;
|
|
81
83
|
running = true;
|
|
82
84
|
try {
|
|
85
|
+
const settings = await readSettings();
|
|
86
|
+
if (!settings.enabled) return;
|
|
83
87
|
const registry = typeof ctx?.get === 'function' ? ctx.get('agents') : null;
|
|
84
88
|
if (!registry || typeof registry.list !== 'function') return;
|
|
85
89
|
const agents = registry.list();
|