docs(release): seal and deliver task agreement 1.25 with retained production state
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# Delivery Report:已验证的四模块交付样本
|
||||
|
||||
本例由工作台内用户配置的gpt-6.1-sol完成。封存初始输入见[工程基准](../../benchmarks/node-delivery-v1/README.md):先取得13项真实测试失败,再产生四模块提案,审查应用后继续同一个Task,实际测试14/14通过并完成构建。验收文件与原工程的既有改动保留。
|
||||
|
||||
```powershell
|
||||
npm test
|
||||
npm run build
|
||||
node dist/cli.mjs fixtures/tasks.json
|
||||
node dist/cli.mjs fixtures/tasks.json --json
|
||||
```
|
||||
|
||||
没有第三方依赖。Node24下默认输出:
|
||||
|
||||
```text
|
||||
交付进度:2/4(50%)
|
||||
待办 0 · 进行中 1 · 已完成 2 · 阻塞 1
|
||||
剩余预计:50 分钟
|
||||
```
|
||||
|
||||
CLI接受JSON任务数组;无效参数、JSON、数据或文件返回退出码2与中文错误。normalize/summary/render/cli分别负责输入校验、统计、中文渲染和命令行入口。14项测试覆盖输入边界、数据独立性、统计、输出、CLI参数与错误退出;build核对语法并生成dist。
|
||||
|
||||
这是一个受控Node样本,不能代表所有真实项目的完成率。实现来自实际配置模型;验收器负责限定脚本确认、提案审查与应用,最后保存源文件Git提交。详细结果见[真实模型验收](../../docs/m1-live-delivery-validation.json)。
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import fs from 'node:fs';
|
||||
import { normalizeTasks } from './normalize.mjs';
|
||||
import { summarize } from './summary.mjs';
|
||||
import { renderText } from './render.mjs';
|
||||
|
||||
try {
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 1 || args.length > 2 || !args[0] || args[0].startsWith('-') ||
|
||||
(args.length === 2 && args[1] !== '--json')) {
|
||||
throw new TypeError('用法:node src/cli.mjs <JSON文件> [--json]');
|
||||
}
|
||||
|
||||
const source = fs.readFileSync(args[0], 'utf8');
|
||||
const tasks = normalizeTasks(JSON.parse(source));
|
||||
const summary = summarize(tasks);
|
||||
const output = args[1] === '--json' ? JSON.stringify(summary) : renderText(summary);
|
||||
process.stdout.write(output + '\n');
|
||||
process.exitCode = 0;
|
||||
} catch (error) {
|
||||
process.stderr.write(`输入错误:${error.message}\n`);
|
||||
process.exitCode = 2;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
const statuses = new Set(['todo', 'doing', 'done', 'blocked']);
|
||||
|
||||
export function normalizeTasks(input) {
|
||||
if (!Array.isArray(input)) throw new TypeError('任务必须是数组');
|
||||
if (input.length > 10000) throw new RangeError('任务数量不能超过10000项');
|
||||
|
||||
const ids = new Set();
|
||||
const tasks = [];
|
||||
for (const task of input) {
|
||||
if (task === null || typeof task !== 'object' || Array.isArray(task)) {
|
||||
throw new TypeError('每项任务必须是对象');
|
||||
}
|
||||
if (typeof task.id !== 'string' || typeof task.title !== 'string') {
|
||||
throw new TypeError('任务id和title必须是字符串');
|
||||
}
|
||||
const id = task.id.trim();
|
||||
const title = task.title.trim();
|
||||
if (!id || !title) throw new TypeError('任务id和title不能为空');
|
||||
if (ids.has(id)) throw new TypeError(`任务id重复:${id}`);
|
||||
|
||||
const { status, minutes } = task;
|
||||
if (!statuses.has(status)) {
|
||||
throw new TypeError('任务status必须是todo、doing、done或blocked');
|
||||
}
|
||||
if (!Number.isSafeInteger(minutes) || minutes < 0 || minutes > 1000000) {
|
||||
throw new RangeError('任务minutes必须是0到1000000之间的安全整数');
|
||||
}
|
||||
ids.add(id);
|
||||
tasks.push({ id, title, status, minutes });
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"type":"module"}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
export function renderText(summary) {
|
||||
const { total, counts, completedPercent, remainingMinutes } = summary;
|
||||
return [
|
||||
`交付进度:${counts.done}/${total}(${completedPercent}%)`,
|
||||
`待办 ${counts.todo} · 进行中 ${counts.doing} · 已完成 ${counts.done} · 阻塞 ${counts.blocked}`,
|
||||
`剩余预计:${remainingMinutes} 分钟`,
|
||||
].join('\n');
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
export function summarize(tasks) {
|
||||
const counts = { todo: 0, doing: 0, done: 0, blocked: 0 };
|
||||
let remainingMinutes = 0;
|
||||
for (const task of tasks) {
|
||||
counts[task.status] += 1;
|
||||
if (task.status !== 'done') remainingMinutes += task.minutes;
|
||||
}
|
||||
|
||||
const total = tasks.length;
|
||||
return {
|
||||
total,
|
||||
counts,
|
||||
completedPercent: total === 0 ? 0 : Math.round(counts.done / total * 100),
|
||||
remainingMinutes,
|
||||
};
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{ "unfinished":
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{ "id": " docs ", "title": " 编写交付文档 ", "status": "done", "minutes": 30 },
|
||||
{ "id": "api", "title": "接口回归", "status": "doing", "minutes": 40 },
|
||||
{ "id": "release", "title": "准备发行包", "status": "blocked", "minutes": 10 },
|
||||
{ "id": "review", "title": "代码审查", "status": "done", "minutes": 20 }
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "delivery-report-lab",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": { "test": "node --test test/*.test.mjs", "build": "node scripts/build.mjs" }
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import fs from 'node:fs';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
const modules = ['normalize.mjs', 'summary.mjs', 'render.mjs', 'cli.mjs'];
|
||||
for (const name of modules) {
|
||||
const check = spawnSync(process.execPath, ['--check', 'src/' + name], { encoding: 'utf8', windowsHide: true });
|
||||
if (check.status !== 0) { process.stderr.write(check.stderr); process.exit(1); }
|
||||
}
|
||||
fs.mkdirSync('dist', { recursive: true });
|
||||
for (const name of modules) fs.copyFileSync('src/' + name, 'dist/' + name);
|
||||
fs.writeFileSync('dist/package.json', '{"type":"module"}\n');
|
||||
console.log('四个模块语法检查及可运行构建完成。');
|
||||
@@ -0,0 +1,22 @@
|
||||
import fs from 'node:fs';
|
||||
import { normalizeTasks } from './normalize.mjs';
|
||||
import { summarize } from './summary.mjs';
|
||||
import { renderText } from './render.mjs';
|
||||
|
||||
try {
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 1 || args.length > 2 || !args[0] || args[0].startsWith('-') ||
|
||||
(args.length === 2 && args[1] !== '--json')) {
|
||||
throw new TypeError('用法:node src/cli.mjs <JSON文件> [--json]');
|
||||
}
|
||||
|
||||
const source = fs.readFileSync(args[0], 'utf8');
|
||||
const tasks = normalizeTasks(JSON.parse(source));
|
||||
const summary = summarize(tasks);
|
||||
const output = args[1] === '--json' ? JSON.stringify(summary) : renderText(summary);
|
||||
process.stdout.write(output + '\n');
|
||||
process.exitCode = 0;
|
||||
} catch (error) {
|
||||
process.stderr.write(`输入错误:${error.message}\n`);
|
||||
process.exitCode = 2;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
const statuses = new Set(['todo', 'doing', 'done', 'blocked']);
|
||||
|
||||
export function normalizeTasks(input) {
|
||||
if (!Array.isArray(input)) throw new TypeError('任务必须是数组');
|
||||
if (input.length > 10000) throw new RangeError('任务数量不能超过10000项');
|
||||
|
||||
const ids = new Set();
|
||||
const tasks = [];
|
||||
for (const task of input) {
|
||||
if (task === null || typeof task !== 'object' || Array.isArray(task)) {
|
||||
throw new TypeError('每项任务必须是对象');
|
||||
}
|
||||
if (typeof task.id !== 'string' || typeof task.title !== 'string') {
|
||||
throw new TypeError('任务id和title必须是字符串');
|
||||
}
|
||||
const id = task.id.trim();
|
||||
const title = task.title.trim();
|
||||
if (!id || !title) throw new TypeError('任务id和title不能为空');
|
||||
if (ids.has(id)) throw new TypeError(`任务id重复:${id}`);
|
||||
|
||||
const { status, minutes } = task;
|
||||
if (!statuses.has(status)) {
|
||||
throw new TypeError('任务status必须是todo、doing、done或blocked');
|
||||
}
|
||||
if (!Number.isSafeInteger(minutes) || minutes < 0 || minutes > 1000000) {
|
||||
throw new RangeError('任务minutes必须是0到1000000之间的安全整数');
|
||||
}
|
||||
ids.add(id);
|
||||
tasks.push({ id, title, status, minutes });
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export function renderText(summary) {
|
||||
const { total, counts, completedPercent, remainingMinutes } = summary;
|
||||
return [
|
||||
`交付进度:${counts.done}/${total}(${completedPercent}%)`,
|
||||
`待办 ${counts.todo} · 进行中 ${counts.doing} · 已完成 ${counts.done} · 阻塞 ${counts.blocked}`,
|
||||
`剩余预计:${remainingMinutes} 分钟`,
|
||||
].join('\n');
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
export function summarize(tasks) {
|
||||
const counts = { todo: 0, doing: 0, done: 0, blocked: 0 };
|
||||
let remainingMinutes = 0;
|
||||
for (const task of tasks) {
|
||||
counts[task.status] += 1;
|
||||
if (task.status !== 'done') remainingMinutes += task.minutes;
|
||||
}
|
||||
|
||||
const total = tasks.length;
|
||||
return {
|
||||
total,
|
||||
counts,
|
||||
completedPercent: total === 0 ? 0 : Math.round(counts.done / total * 100),
|
||||
remainingMinutes,
|
||||
};
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { normalizeTasks } from '../src/normalize.mjs';
|
||||
import { summarize } from '../src/summary.mjs';
|
||||
import { renderText } from '../src/render.mjs';
|
||||
const input = () => JSON.parse(fs.readFileSync('fixtures/tasks.json', 'utf8'));
|
||||
const record = overrides => ({ id: 'one', title: '任务', status: 'todo', minutes: 5, ...overrides });
|
||||
const expected = { total: 4, counts: { todo: 0, doing: 1, done: 2, blocked: 1 }, completedPercent: 50, remainingMinutes: 50 };
|
||||
const invoke = (...args) => spawnSync(process.execPath, ['src/cli.mjs', ...args], { encoding: 'utf8', windowsHide: true });
|
||||
|
||||
test('normalize trims identifiers and titles into independent records', () => { const original = input(), before = structuredClone(original), result = normalizeTasks(original); assert.equal(result[0].id, 'docs'); assert.equal(result[0].title, '编写交付文档'); assert.notEqual(result, original); assert.notEqual(result[1], original[1]); assert.deepEqual(original, before); });
|
||||
test('normalize rejects blank and duplicate normalized identifiers', () => { assert.throws(() => normalizeTasks([record({ id: ' ' })])); assert.throws(() => normalizeTasks([record({ title: ' ' })])); assert.throws(() => normalizeTasks([record(), record({ id: ' one ' })])); });
|
||||
test('normalize validates record shape and bounded collection size', () => { assert.throws(() => normalizeTasks({})); assert.throws(() => normalizeTasks([null])); assert.throws(() => normalizeTasks(Array.from({ length: 10001 }, (_, i) => record({ id: String(i) })))); });
|
||||
test('normalize supports all four states and rejects unknown states', () => { for (const status of ['todo', 'doing', 'done', 'blocked']) assert.equal(normalizeTasks([record({ status })])[0].status, status); assert.throws(() => normalizeTasks([record({ status: 'completed' })])); });
|
||||
test('normalize rejects noninteger and out-of-range estimates', () => { for (const minutes of ['5', null, -1, 0.5, NaN, Infinity, 1000001]) assert.throws(() => normalizeTasks([record({ minutes })])); assert.equal(normalizeTasks([record({ minutes: 0 })])[0].minutes, 0); assert.equal(normalizeTasks([record({ minutes: 1000000 })])[0].minutes, 1000000); });
|
||||
test('normalize emits only the declared four-field contract', () => assert.deepEqual(normalizeTasks([record({ unrelated: true })])[0], record()));
|
||||
test('summary reports complete state counts and excludes completed work from remaining time', () => assert.deepEqual(summarize(normalizeTasks(input())), expected));
|
||||
test('summary rounds progress instead of truncating percentages', () => assert.equal(summarize([record({ status: 'done' }), record({ id: 'two', status: 'done' }), record({ id: 'three' })]).completedPercent, 67));
|
||||
test('summary handles an empty plan with every state present', () => assert.deepEqual(summarize([]), { total: 0, counts: { todo: 0, doing: 0, done: 0, blocked: 0 }, completedPercent: 0, remainingMinutes: 0 }));
|
||||
test('text rendering keeps the required three readable Chinese lines', () => assert.equal(renderText(expected), '交付进度:2/4(50%)\n待办 0 · 进行中 1 · 已完成 2 · 阻塞 1\n剩余预计:50 分钟'));
|
||||
test('CLI JSON output matches the summary contract and has a trailing newline', () => { const result = invoke('fixtures/tasks.json', '--json'); assert.equal(result.status, 0); assert.equal(result.stderr, ''); assert.deepEqual(JSON.parse(result.stdout), expected); assert.ok(result.stdout.endsWith('\n')); });
|
||||
test('CLI text output is readable and matches the shared rendering', () => { const result = invoke('fixtures/tasks.json'); assert.equal(result.status, 0); assert.equal(result.stdout, renderText(expected) + '\n'); assert.equal(result.stderr, ''); });
|
||||
test('CLI missing arguments and unknown options return exit 2 without output', () => { for (const args of [[], ['fixtures/tasks.json', '--unknown'], ['fixtures/tasks.json', '--json', '--json']]) { const result = invoke(...args); assert.equal(result.status, 2); assert.equal(result.stdout, ''); assert.match(result.stderr, /^输入错误:/); } });
|
||||
test('CLI invalid JSON and missing files preserve the failure exit code', () => { for (const file of ['fixtures/invalid.json', 'fixtures/not-found.json']) { const result = invoke(file); assert.equal(result.status, 2); assert.equal(result.stdout, ''); assert.match(result.stderr, /^输入错误:/); } });
|
||||
@@ -0,0 +1,9 @@
|
||||
# 研究任务看板
|
||||
|
||||
这是 Agent Workbench 自带的小型示例项目,用来体验读取文件、提出修改、审查差异和执行验证。
|
||||
|
||||
## 运行
|
||||
使用 `node --test` 执行测试。项目不需要安装依赖。
|
||||
|
||||
## 目标
|
||||
把研究记录整理为可搜索的任务目录,每个条目具有标题、状态和标签。
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"research-board-example","private":true,"type":"module","scripts":{"test":"node --test"}}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
export const catalog = [
|
||||
{ id: 'agent-loop', title: '工具执行循环', status: 'in_progress', tags: ['agent', 'tools'] },
|
||||
{ id: 'session-recovery', title: '会话恢复', status: 'planned', tags: ['session', 'recovery'] },
|
||||
{ id: 'change-review', title: '改动审查', status: 'done', tags: ['editor', 'diff'] },
|
||||
];
|
||||
|
||||
export function searchCatalog(query) {
|
||||
const normalized = query.trim().toLocaleLowerCase();
|
||||
const keywords = normalized ? normalized.split(/\s+/) : [];
|
||||
|
||||
return catalog.filter(item => {
|
||||
const searchableText = `${item.title} ${item.tags.join(' ')}`.toLocaleLowerCase();
|
||||
return keywords.every(keyword => searchableText.includes(keyword));
|
||||
});
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { catalog, searchCatalog } from '../src/catalog.js';
|
||||
|
||||
test('标题与标签均可检索,忽略大小写与首尾空白', () => {
|
||||
assert.deepEqual(searchCatalog('会话').map(item => item.id), ['session-recovery']);
|
||||
assert.deepEqual(searchCatalog(' TOOLs ').map(item => item.id), ['agent-loop']);
|
||||
});
|
||||
|
||||
test('多关键词搜索不受词序影响,支持跨标题与标签匹配', () => {
|
||||
for (const query of ['agent tools', 'tools agent', ' TOOLs \t agent\n', 'tools 工具']) {
|
||||
assert.deepEqual(searchCatalog(query).map(item => item.id), ['agent-loop']);
|
||||
}
|
||||
});
|
||||
|
||||
test('所有关键词都必须匹配同一条目', () => {
|
||||
assert.deepEqual(searchCatalog('agent recovery'), []);
|
||||
assert.deepEqual(searchCatalog('不存在的关键词'), []);
|
||||
});
|
||||
|
||||
test('空查询与纯空白查询返回全部条目', () => {
|
||||
assert.deepEqual(searchCatalog(''), catalog);
|
||||
assert.deepEqual(searchCatalog(' \t\n '), catalog);
|
||||
});
|
||||
Reference in New Issue
Block a user