feat: 更新待办任务功能,添加初始化、列出、完成、添加和清理任务的路由

This commit is contained in:
2026-01-20 23:04:09 +08:00
parent 7a99b69887
commit dc4bd6ca91
4 changed files with 166 additions and 43 deletions

View File

@@ -4,7 +4,7 @@ include:
.common_env: &common_env .common_env: &common_env
env: env:
TO_REPO: kevisual/template-docs TO_REPO: kevisual/frontend-starter-skill
TO_URL: git.xiongxiao.me TO_URL: git.xiongxiao.me
imports: imports:
- https://cnb.cool/kevisual/env/-/blob/main/.env.development - https://cnb.cool/kevisual/env/-/blob/main/.env.development

View File

@@ -1 +1 @@
import './md.ts'; import './todo.ts';

View File

@@ -1,41 +0,0 @@
import * as docs from '../generated/docs.ts';
import { app } from '../app.ts'
import path from 'path';
import fs from 'fs';
import { createSkill, tool } from '@kevisual/router';
// 初始化init-web-todo 任务, 使用astro
app.route({
path: 'web-todo',
key: 'init',
description: '初始化需要做的任务',
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'init-web-todo',
title: '初始化 Web Todo 项目',
summary: '初始化需要做的任务',
args: {
type: tool.schema.string().describe('初始化类型, astro 或者 nextjs'),
force: tool.schema.boolean().optional().describe('是否强制覆盖已存在的 TODO.md 文件'),
}
})
}
}).define(async (ctx) => {
const type = ctx.query?.type || 'astro';
const force = ctx.query?.force ?? false;
const todo = path.join(process.cwd(), 'TODO.md');
if (fs.existsSync(todo)) {
if (!force) {
ctx.body = {
content: 'TODO.md 文件已经存在。如需覆盖,请使用 --force 参数。',
}
return;
}
}
const template = type === 'nextjs' ? docs.enterprise_website_features : docs.website_features_breakdown;
ctx.body = {
content: `根据下面的文档生成一个任务清单写入到TODO.md 文件中, 使用技术:${type}:\n\n${template}`,
}
}).addTo(app);

164
src/routes/todo.ts Normal file
View File

@@ -0,0 +1,164 @@
import * as docs from '../generated/docs.ts';
import { app } from '../app.ts'
import path from 'path';
import fs from 'fs';
import { createSkill, tool } from '@kevisual/router';
// 初始化init-web-todo 任务, 使用astro
app.route({
path: 'web-todo',
key: 'init',
description: '初始化需要做的任务',
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'init-web-todo',
title: '初始化 Web Todo 项目',
summary: '初始化需要做的任务',
args: {
type: tool.schema.string().describe('初始化类型, astro 或者 nextjs'),
force: tool.schema.boolean().optional().describe('是否强制覆盖已存在的 TODO.md 文件'),
}
})
}
}).define(async (ctx) => {
const type = ctx.query?.type || 'astro';
const force = ctx.query?.force ?? false;
const todo = path.join(process.cwd(), 'TODO.md');
if (fs.existsSync(todo)) {
if (!force) {
ctx.body = {
content: 'TODO.md 文件已经存在。如需覆盖,请使用 forec 参数。',
}
return;
}
}
const template = type === 'nextjs' ? docs.enterprise_website_features : docs.website_features_breakdown;
ctx.body = {
content: `根据下面的文档生成一个任务清单写入到TODO.md 文件中, 使用技术:${type}:\n\n${template}`,
}
}).addTo(app);
app.route({
path: 'web-todo',
key: 'list',
description: '列出当前的待办任务',
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'list-web-todo',
title: '列出当前的待办任务',
summary: '列出当前的待办任务',
})
}
}).define(async (ctx) => {
const todo = path.join(process.cwd(), 'TODO.md');
if (!fs.existsSync(todo)) {
ctx.body = {
content: '当前没有待办任务。请先初始化任务列表。',
}
return;
}
const content = fs.readFileSync(todo, 'utf-8');
ctx.body = {
content,
}
}).addTo(app);
app.route({
path: 'web-todo',
key: 'complete',
description: '完成一个待办任务',
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'complete-web-todo',
title: '完成一个待办任务',
summary: '完成一个待办任务',
args: {
task: tool.schema.string().describe('要完成的任务描述'),
}
})
}
}).define(async (ctx) => {
const task = ctx.query?.task;
if (!task) {
ctx.body = {
content: '请提供要完成的任务描述。',
}
return;
}
const todo = path.join(process.cwd(), 'TODO.md');
if (!fs.existsSync(todo)) {
ctx.body = {
content: '当前没有待办任务。请先初始化任务列表。',
}
return;
}
ctx.body = {
content: `当前的任务已经完成对TODO.md的内容进行修改。${task}`,
}
}).addTo(app);
app.route({
path: 'web-todo',
key: 'add',
description: '添加一个待办任务',
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'add-web-todo',
title: '添加一个待办任务',
summary: '添加一个待办任务',
args: {
task: tool.schema.string().describe('要添加的任务描述'),
}
})
}
}).define(async (ctx) => {
const task = ctx.query?.task;
if (!task) {
ctx.body = {
content: '请提供要添加的任务描述。',
}
return;
}
const todo = path.join(process.cwd(), 'TODO.md');
if (!fs.existsSync(todo)) {
ctx.body = {
content: '当前没有待办任务。请先初始化任务列表。',
}
return;
}
ctx.body = {
content: `添加一个新的任务到TODO.md文件中。${task}`,
}
}).addTo(app);
app.route({
path: 'web-todo',
key: 'clear',
description: '清理已经完成的待办任务',
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'clear-web-todo',
title: '清理已经完成的待办任务',
summary: '清理已经完成的待办任务',
})
}
}).define(async (ctx) => {
const todo = path.join(process.cwd(), 'TODO.md');
if (!fs.existsSync(todo)) {
ctx.body = {
content: '当前没有待办任务。请先初始化任务列表。',
}
return;
}
ctx.body = {
content: `清理TODO.md文件中已经完成的任务只保留未完成的任务。`,
}
}).addTo(app);