| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #!/usr/bin/env node
- /**
- * status.mjs — 进度/成果查询(AgentTaskStatus + AgentDeliverable)
- *
- * 视角:
- * node status.mjs mine --agent <agentId> 本 agent 最近任务+交付
- * node status.mjs all [--agent <agentId>] [--limit N] 全集群(masterKey 视角)
- *
- * 输出 JSON:tasks(四态时间线倒序)+ deliverables(成果时间线倒序)。
- */
- import {
- resolveCredentials, failNoCredentials, queryObjects,
- } from './parse-client.mjs';
- const argv = process.argv.slice(2);
- const scope = argv[0] === 'all' ? 'all' : 'mine';
- // 选项从 argv[1] 起按对解析: --agent x --limit 20
- const args = {};
- for (let i = 1; i < argv.length; i += 2) {
- const key = (argv[i] || '').replace(/^--/, '');
- args[key] = argv[i + 1];
- }
- const limit = Math.min(parseInt(args.limit || '20', 10) || 20, 200);
- const cred = resolveCredentials();
- if (!cred) failNoCredentials();
- const taskWhere = args.agent ? { agentId: args.agent } : {};
- const delivWhere = args.agent ? { agentId: args.agent } : {};
- const [tasks, deliverables] = await Promise.all([
- queryObjects('AgentTaskStatus', cred, { where: taskWhere, limit, order: '-updatedAt' }),
- queryObjects('AgentDeliverable', cred, { where: delivWhere, limit, order: '-deliveredAt' }),
- ]);
- const fmtTask = (t) => ({
- agentId: t.agentId, taskId: t.taskId, taskName: t.taskName,
- status: t.status,
- startedAt: t.startedAt && t.startedAt.iso,
- endedAt: t.endedAt && t.endedAt.iso,
- heartbeatAt: t.heartbeatAt && t.heartbeatAt.iso,
- resultNote: t.resultNote,
- });
- const fmtDeliv = (d) => ({
- agentId: d.agentId, taskId: d.taskId, title: d.title,
- project: d.project, deliverableType: d.deliverableType,
- url: d.url, summary: d.summary,
- deliveredAt: d.deliveredAt && d.deliveredAt.iso,
- });
- console.log(JSON.stringify({
- ok: true,
- scope,
- agentId: args.agent || null,
- taskCount: tasks.length,
- deliverableCount: deliverables.length,
- tasks: tasks.map(fmtTask),
- deliverables: deliverables.map(fmtDeliv),
- }, null, 2));
|