dsh-department 0.1.2 → 0.2.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/CHANGELOG.md +17 -0
- package/README.md +15 -6
- package/README.ru.md +7 -5
- package/assets/editor.html +621 -0
- package/client.js +158 -13
- package/package.json +1 -1
- package/src/approval.js +40 -0
- package/src/create-task.js +61 -0
- package/src/discussion.js +48 -0
- package/src/handover.js +138 -0
- package/src/panel-api.js +6 -2
- package/src/routes.js +114 -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/panel-api.js
CHANGED
|
@@ -11,11 +11,12 @@ import { currentBranch, runGit } from './git.js';
|
|
|
11
11
|
/** Стадии в порядке конвейера — для прогресса. */
|
|
12
12
|
export const STAGE_ORDER = [
|
|
13
13
|
'analysis',
|
|
14
|
-
'concept',
|
|
15
|
-
'concept_review',
|
|
16
14
|
'spec',
|
|
17
15
|
'spec_review',
|
|
16
|
+
'concept',
|
|
17
|
+
'concept_review',
|
|
18
18
|
'executing',
|
|
19
|
+
'release',
|
|
19
20
|
'done',
|
|
20
21
|
];
|
|
21
22
|
|
|
@@ -134,6 +135,9 @@ export async function taskPayload(root, taskId) {
|
|
|
134
135
|
files[name] = await fileExists(join(root, DEPARTMENT_DIR, taskId, name));
|
|
135
136
|
}
|
|
136
137
|
files['README.md'] = await fileExists(join(root, 'README.md'));
|
|
138
|
+
for (const name of ['RUN.md', 'MANUAL-QA.md', 'CHANGELOG.md']) {
|
|
139
|
+
files['delivery/' + name] = await fileExists(join(root, DEPARTMENT_DIR, taskId, 'delivery', name));
|
|
140
|
+
}
|
|
137
141
|
const stageNo = String((state.stageIndex ?? 0) + 1).padStart(2, '0');
|
|
138
142
|
for (const name of ['review.md', 'report.md']) {
|
|
139
143
|
files['stage:' + name.replace('.md', '')] = await fileExists(join(root, DEPARTMENT_DIR, taskId, 'stages', stageNo, name));
|
package/src/routes.js
CHANGED
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
* HTTP-маршруты Web-панели отдела на общем канале `/api`.
|
|
3
3
|
* Только чтение: доска и карточка задачи.
|
|
4
4
|
*/
|
|
5
|
-
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { dirname, join } from 'node:path';
|
|
8
8
|
import { listProjects, listTasks, resolveRoots, rootsWithTasks, taskPayload } from './panel-api.js';
|
|
9
|
+
import { createDepartmentTask } from './create-task.js';
|
|
10
|
+
import { encodePng } from './png.js';
|
|
11
|
+
import { assertApprovalReady } from './approval.js';
|
|
12
|
+
import { readSettings, writeSettings } from './settings.js';
|
|
9
13
|
import { addCorrection, amendDocument, answerQuestion, approveDocument, listRoles, readState, reviewMemo, setBudget, setPaused, setRole, writeState } from './store.js';
|
|
10
14
|
import { isHumanApprover } from './roles.js';
|
|
11
15
|
import { buildBlueprint } from './blueprint.js';
|
|
@@ -26,6 +30,11 @@ export const DEPARTMENT_ROUTES = {
|
|
|
26
30
|
review: '/api/department/review',
|
|
27
31
|
correction: '/api/department/correction',
|
|
28
32
|
pause: '/api/department/pause',
|
|
33
|
+
settings: '/api/department/settings',
|
|
34
|
+
createTask: '/api/department/task/create',
|
|
35
|
+
editor: '/api/department/editor',
|
|
36
|
+
editorSave: '/api/department/editor/save',
|
|
37
|
+
editorHandoff: '/api/department/editor/handoff',
|
|
29
38
|
documents: '/api/department/documents',
|
|
30
39
|
document: '/api/department/document',
|
|
31
40
|
answer: '/api/department/answer',
|
|
@@ -116,6 +125,109 @@ export function registerDepartmentRoutes(ctx, activity) {
|
|
|
116
125
|
},
|
|
117
126
|
});
|
|
118
127
|
|
|
128
|
+
add({
|
|
129
|
+
path: DEPARTMENT_ROUTES.settings,
|
|
130
|
+
methods: ['GET', 'POST'],
|
|
131
|
+
requestBody: 'buffered',
|
|
132
|
+
fetch: async (request) => {
|
|
133
|
+
if (request.method === 'GET') return Response.json(await readSettings());
|
|
134
|
+
const body = await request.json().catch(() => ({}));
|
|
135
|
+
const { enabled, by } = body ?? {};
|
|
136
|
+
if (typeof enabled !== 'boolean' || !isHumanApprover(by)) {
|
|
137
|
+
return Response.json({ error: 'enabled boolean and human signature required' }, { status: 400 });
|
|
138
|
+
}
|
|
139
|
+
const next = await writeSettings({ enabled });
|
|
140
|
+
return Response.json(next);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
add({
|
|
145
|
+
path: DEPARTMENT_ROUTES.createTask,
|
|
146
|
+
methods: ['POST'],
|
|
147
|
+
requestBody: 'buffered',
|
|
148
|
+
fetch: async (request) => {
|
|
149
|
+
const body = await request.json().catch(() => ({}));
|
|
150
|
+
const { root, taskId, title, brief, testCommand, branch, by } = body ?? {};
|
|
151
|
+
if (!root || !taskId) return Response.json({ error: 'root, taskId required' }, { status: 400 });
|
|
152
|
+
if (!isHumanApprover(by)) return Response.json({ error: 'task must be created by the human' }, { status: 403 });
|
|
153
|
+
try {
|
|
154
|
+
const state = await createDepartmentTask(root, taskId, { title, brief, testCommand, branch });
|
|
155
|
+
return Response.json({ ok: true, taskId: state.taskId, stage: state.stage });
|
|
156
|
+
} catch (error) {
|
|
157
|
+
return Response.json({ error: error.message }, { status: 400 });
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
add({
|
|
164
|
+
path: DEPARTMENT_ROUTES.editor,
|
|
165
|
+
methods: ['GET'],
|
|
166
|
+
requestBody: 'buffered',
|
|
167
|
+
fetch: async () => {
|
|
168
|
+
const html = await readFile(join(dirname(fileURLToPath(import.meta.url)), '..', 'assets', 'editor.html'), 'utf8');
|
|
169
|
+
return new Response(html, { headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' } });
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
add({
|
|
174
|
+
path: DEPARTMENT_ROUTES.editorSave,
|
|
175
|
+
methods: ['POST'],
|
|
176
|
+
requestBody: 'buffered',
|
|
177
|
+
fetch: async (request) => {
|
|
178
|
+
const body = await request.json().catch(() => ({}));
|
|
179
|
+
const { root, taskId, name, rows, palette } = body ?? {};
|
|
180
|
+
if (!root || !taskId || !Array.isArray(rows) || !palette) return Response.json({ error: 'root, taskId, rows, palette required' }, { status: 400 });
|
|
181
|
+
const safe = String(name ?? 'sprite').replace(/[^a-z0-9._-]/gi, '_').slice(0, 60) || 'sprite';
|
|
182
|
+
const state = await readState(root, taskId);
|
|
183
|
+
if (!state) return Response.json({ error: 'task not found' }, { status: 404 });
|
|
184
|
+
const height = rows.length;
|
|
185
|
+
const width = rows[0]?.length ?? 0;
|
|
186
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
187
|
+
for (let y = 0; y < height; y += 1) {
|
|
188
|
+
for (let x = 0; x < width; x += 1) {
|
|
189
|
+
const symbol = rows[y][x];
|
|
190
|
+
if (!symbol || symbol === '.') continue;
|
|
191
|
+
const hex = palette[symbol];
|
|
192
|
+
if (!hex) continue;
|
|
193
|
+
const value = parseInt(String(hex).replace('#', ''), 16);
|
|
194
|
+
const i = (y * width + x) * 4;
|
|
195
|
+
rgba[i] = (value >> 16) & 255;
|
|
196
|
+
rgba[i + 1] = (value >> 8) & 255;
|
|
197
|
+
rgba[i + 2] = value & 255;
|
|
198
|
+
rgba[i + 3] = 255;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const dir = join(root, 'assets', 'office', 'editor');
|
|
202
|
+
await mkdir(dir, { recursive: true });
|
|
203
|
+
const png = join(dir, `${safe}.png`);
|
|
204
|
+
await writeFile(png, encodePng(width, height, rgba));
|
|
205
|
+
await writeFile(join(dir, `${safe}.json`), JSON.stringify({ rows, palette }, null, 2) + '\n', 'utf8');
|
|
206
|
+
return Response.json({ ok: true, path: `assets/office/editor/${safe}.png`, width, height });
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
add({
|
|
211
|
+
path: DEPARTMENT_ROUTES.editorHandoff,
|
|
212
|
+
methods: ['POST'],
|
|
213
|
+
requestBody: 'buffered',
|
|
214
|
+
fetch: async (request) => {
|
|
215
|
+
const body = await request.json().catch(() => ({}));
|
|
216
|
+
const { root, taskId, name, note, by } = body ?? {};
|
|
217
|
+
if (!root || !taskId || !isHumanApprover(by)) return Response.json({ error: 'root, taskId, human signature required' }, { status: 400 });
|
|
218
|
+
const state = await readState(root, taskId);
|
|
219
|
+
if (!state) return Response.json({ error: 'task not found' }, { status: 404 });
|
|
220
|
+
const result = addCorrection(state, {
|
|
221
|
+
doc: 'interface',
|
|
222
|
+
subject: `Спрайт: ${name || 'sprite'}`,
|
|
223
|
+
text: note || 'Дорисовать спрайт в assets/office/editor/' + (name || 'sprite') + '.png',
|
|
224
|
+
by: String(by),
|
|
225
|
+
});
|
|
226
|
+
await writeState(root, result.state);
|
|
227
|
+
return Response.json({ ok: true, correctionId: result.correction.id });
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
119
231
|
add({
|
|
120
232
|
path: DEPARTMENT_ROUTES.pause,
|
|
121
233
|
methods: ['POST'],
|
|
@@ -256,6 +368,7 @@ export function registerDepartmentRoutes(ctx, activity) {
|
|
|
256
368
|
const state = await readState(root, taskId);
|
|
257
369
|
if (!state) return Response.json({ error: 'task not found' }, { status: 404 });
|
|
258
370
|
try {
|
|
371
|
+
await assertApprovalReady(root, taskId, doc, state);
|
|
259
372
|
const next = await writeState(root, approveDocument(state, { doc, by }));
|
|
260
373
|
return Response.json({ stage: next.stage, summary: next.approvals });
|
|
261
374
|
} catch (error) {
|
package/src/settings.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Глобальные настройки отдела: включён ли отдел как процесс.
|
|
3
|
+
*
|
|
4
|
+
* Файл лежит вне проектов, чтобы одна кнопка управляла всеми задачами.
|
|
5
|
+
*/
|
|
6
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
const SETTINGS_FILE = join(homedir(), '.dsh', 'department-settings.json');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Читает настройки (по умолчанию отдел включён).
|
|
14
|
+
*
|
|
15
|
+
* @returns {Promise<{ enabled: boolean }>}
|
|
16
|
+
*/
|
|
17
|
+
export async function readSettings() {
|
|
18
|
+
try {
|
|
19
|
+
const data = JSON.parse(await readFile(SETTINGS_FILE, 'utf8'));
|
|
20
|
+
return { enabled: data.enabled !== false };
|
|
21
|
+
} catch {
|
|
22
|
+
return { enabled: true };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Сохраняет настройки.
|
|
28
|
+
*
|
|
29
|
+
* @param {{ enabled?: boolean }} patch Изменения.
|
|
30
|
+
* @returns {Promise<{ enabled: boolean }>}
|
|
31
|
+
*/
|
|
32
|
+
export async function writeSettings(patch) {
|
|
33
|
+
const current = await readSettings();
|
|
34
|
+
const next = { ...current, ...(patch ?? {}) };
|
|
35
|
+
next.enabled = next.enabled !== false;
|
|
36
|
+
await mkdir(join(homedir(), '.dsh'), { recursive: true });
|
|
37
|
+
await writeFile(SETTINGS_FILE, JSON.stringify(next, null, 2) + '\n', 'utf8');
|
|
38
|
+
return next;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Бросает ошибку, если отдел выключен.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} action Что пытались сделать.
|
|
45
|
+
*/
|
|
46
|
+
export async function assertDepartmentEnabled(action = 'работа отдела') {
|
|
47
|
+
const settings = await readSettings();
|
|
48
|
+
if (!settings.enabled) throw new Error(`отдел выключен человеком: ${action} недоступно (включи в панели «Отдел») `);
|
|
49
|
+
}
|
package/src/store.js
CHANGED
|
@@ -13,19 +13,20 @@ export const DEPARTMENT_DIR = 'docs/department';
|
|
|
13
13
|
/** Допустимые стадии задачи. */
|
|
14
14
|
export const STAGES = Object.freeze([
|
|
15
15
|
'analysis',
|
|
16
|
-
'concept',
|
|
17
|
-
'concept_review',
|
|
18
16
|
'spec',
|
|
19
17
|
'spec_review',
|
|
18
|
+
'concept',
|
|
19
|
+
'concept_review',
|
|
20
20
|
'executing',
|
|
21
|
+
'release',
|
|
21
22
|
'done',
|
|
22
23
|
'blocked',
|
|
23
24
|
]);
|
|
24
25
|
|
|
25
|
-
/** Документы, которые человек
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
/** Документы, которые человек утверждает, и стадии, где это разрешено. */
|
|
27
|
+
const APPROVAL_STAGE = Object.freeze({
|
|
28
|
+
spec: 'spec_review',
|
|
29
|
+
concept: 'concept_review',
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -196,25 +197,26 @@ export function appendEvent(state, event) {
|
|
|
196
197
|
* @returns {object} Новое состояние.
|
|
197
198
|
*/
|
|
198
199
|
export function approveDocument(state, input) {
|
|
199
|
-
const
|
|
200
|
-
if (!
|
|
201
|
-
if (
|
|
202
|
-
throw new Error(`cannot approve ${input.doc} in stage ${state.stage}`);
|
|
200
|
+
const stage = APPROVAL_STAGE[input.doc];
|
|
201
|
+
if (!stage) throw new Error(`unknown document: ${input.doc}`);
|
|
202
|
+
if (state.stage !== stage) {
|
|
203
|
+
throw new Error(`cannot approve ${input.doc} in stage ${state.stage}; move to ${stage} first`);
|
|
203
204
|
}
|
|
204
205
|
const now = new Date().toISOString();
|
|
205
|
-
const
|
|
206
|
-
...state,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
const approvals = [
|
|
207
|
+
...(state.approvals ?? []),
|
|
208
|
+
{ doc: input.doc, by: input.by, via: input.via ?? 'chat', ts: now },
|
|
209
|
+
];
|
|
210
|
+
const approvedDocs = new Set(approvals.map((item) => item.doc));
|
|
211
|
+
// Оба документа утверждены → проект запускается. Иначе — переходим к другому документу.
|
|
212
|
+
const nextStage = approvedDocs.has('spec') && approvedDocs.has('concept')
|
|
213
|
+
? 'executing'
|
|
214
|
+
: input.doc === 'spec' ? 'concept' : 'spec';
|
|
215
|
+
const approved = { ...state, stage: nextStage, updatedAt: now, approvals };
|
|
214
216
|
return appendEvent(approved, {
|
|
215
217
|
actor: input.by,
|
|
216
218
|
action: `approved_${input.doc}`,
|
|
217
|
-
detail: `stage=${
|
|
219
|
+
detail: `stage=${nextStage}`,
|
|
218
220
|
});
|
|
219
221
|
}
|
|
220
222
|
|
|
@@ -340,19 +342,20 @@ export function summarize(state) {
|
|
|
340
342
|
|
|
341
343
|
/** Разрешённые переходы стадий без утверждения человеком. */
|
|
342
344
|
const STAGE_FLOW = Object.freeze({
|
|
343
|
-
analysis: ['concept'],
|
|
344
|
-
concept: ['concept_review', '
|
|
345
|
-
concept_review: ['concept'
|
|
345
|
+
analysis: ['concept', 'spec'],
|
|
346
|
+
concept: ['concept_review', 'spec'],
|
|
347
|
+
concept_review: ['concept'],
|
|
346
348
|
spec: ['spec_review', 'concept'],
|
|
347
|
-
spec_review: ['spec'
|
|
348
|
-
executing: ['
|
|
349
|
+
spec_review: ['spec'],
|
|
350
|
+
executing: ['release', 'blocked', 'spec', 'concept'],
|
|
351
|
+
release: ['done', 'executing'],
|
|
349
352
|
done: [],
|
|
350
353
|
blocked: ['analysis', 'executing'],
|
|
351
354
|
});
|
|
352
355
|
|
|
353
356
|
/**
|
|
354
357
|
* Переводит задачу на следующую стадию с проверкой допустимости перехода.
|
|
355
|
-
*
|
|
358
|
+
* Запуск проекта (executing) — только после утверждения и ТЗ, и концепции, через
|
|
356
359
|
* `approveDocument`, чтобы нельзя было проскочить человеческий гейт.
|
|
357
360
|
*
|
|
358
361
|
* @param {object} state Состояние.
|
|
@@ -365,7 +368,7 @@ export function advanceStage(state, target, reason = '') {
|
|
|
365
368
|
if (!allowed.includes(target)) {
|
|
366
369
|
throw new Error(`cannot move ${state.stage} -> ${target}; allowed: ${allowed.join(', ') || 'none'}`);
|
|
367
370
|
}
|
|
368
|
-
if (target === '
|
|
371
|
+
if (target === 'executing') {
|
|
369
372
|
throw new Error(`${target} requires a human approval, use dept_approve`);
|
|
370
373
|
}
|
|
371
374
|
return appendEvent({ ...state, stage: target }, { actor: 'manager', action: `stage_${target}`, detail: reason });
|
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();
|