@opentask/taskin-task-manager 3.0.2 → 3.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 +119 -0
- package/dist/completion-blockers.test.d.ts +1 -0
- package/dist/completion-blockers.test.js +57 -0
- package/dist/completion-blockers.test.js.map +1 -0
- package/dist/filter-tasks/filter-criteria.d.ts +181 -0
- package/dist/filter-tasks/filter-criteria.js +115 -0
- package/dist/filter-tasks/filter-criteria.js.map +1 -0
- package/dist/filter-tasks/filter-criteria.test.d.ts +1 -0
- package/dist/filter-tasks/filter-criteria.test.js +86 -0
- package/dist/filter-tasks/filter-criteria.test.js.map +1 -0
- package/dist/filter-tasks/filter-tasks.d.ts +26 -0
- package/dist/filter-tasks/filter-tasks.js +99 -0
- package/dist/filter-tasks/filter-tasks.js.map +1 -0
- package/dist/filter-tasks/filter-tasks.test.d.ts +1 -0
- package/dist/filter-tasks/filter-tasks.test.js +110 -0
- package/dist/filter-tasks/filter-tasks.test.js.map +1 -0
- package/dist/filter-tasks/filter-tasks.types.d.ts +27 -0
- package/dist/filter-tasks/filter-tasks.types.js +2 -0
- package/dist/filter-tasks/filter-tasks.types.js.map +1 -0
- package/dist/filter-tasks/index.d.ts +4 -0
- package/dist/filter-tasks/index.js +3 -0
- package/dist/filter-tasks/index.js.map +1 -0
- package/dist/group-registry.contract.d.ts +18 -0
- package/dist/group-registry.contract.js +73 -0
- package/dist/group-registry.contract.js.map +1 -0
- package/dist/group-registry.types.d.ts +44 -0
- package/dist/group-registry.types.js +2 -0
- package/dist/group-registry.types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/numerar-prioridade/index.d.ts +1 -0
- package/dist/numerar-prioridade/index.js +2 -0
- package/dist/numerar-prioridade/index.js.map +1 -0
- package/dist/numerar-prioridade/numerar-prioridade.d.ts +36 -0
- package/dist/numerar-prioridade/numerar-prioridade.js +75 -0
- package/dist/numerar-prioridade/numerar-prioridade.js.map +1 -0
- package/dist/numerar-prioridade/numerar-prioridade.test.d.ts +1 -0
- package/dist/numerar-prioridade/numerar-prioridade.test.js +55 -0
- package/dist/numerar-prioridade/numerar-prioridade.test.js.map +1 -0
- package/dist/ordenar-tarefas/index.d.ts +1 -0
- package/dist/ordenar-tarefas/index.js +2 -0
- package/dist/ordenar-tarefas/index.js.map +1 -0
- package/dist/ordenar-tarefas/ordenar-tarefas.d.ts +70 -0
- package/dist/ordenar-tarefas/ordenar-tarefas.js +79 -0
- package/dist/ordenar-tarefas/ordenar-tarefas.js.map +1 -0
- package/dist/ordenar-tarefas/ordenar-tarefas.test.d.ts +1 -0
- package/dist/ordenar-tarefas/ordenar-tarefas.test.js +70 -0
- package/dist/ordenar-tarefas/ordenar-tarefas.test.js.map +1 -0
- package/dist/task-manager.d.ts +34 -1
- package/dist/task-manager.js +58 -0
- package/dist/task-manager.js.map +1 -1
- package/dist/task-manager.types.d.ts +93 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.js +9 -0
- package/dist/testing.js.map +1 -0
- package/dist/user-registry.contract.js +6 -6
- package/dist/user-registry.contract.js.map +1 -1
- package/package.json +7 -6
- package/src/completion-blockers.test.ts +77 -0
- package/src/filter-tasks/filter-criteria.test.ts +113 -0
- package/src/filter-tasks/filter-criteria.ts +175 -0
- package/src/filter-tasks/filter-tasks.test.ts +129 -0
- package/src/filter-tasks/filter-tasks.ts +106 -0
- package/src/filter-tasks/filter-tasks.types.ts +26 -0
- package/src/filter-tasks/index.ts +16 -0
- package/src/group-registry.contract.ts +99 -0
- package/src/group-registry.types.ts +47 -0
- package/src/index.ts +4 -0
- package/src/numerar-prioridade/index.ts +1 -0
- package/src/numerar-prioridade/numerar-prioridade.test.ts +69 -0
- package/src/numerar-prioridade/numerar-prioridade.ts +80 -0
- package/src/ordenar-tarefas/index.ts +1 -0
- package/src/ordenar-tarefas/ordenar-tarefas.test.ts +92 -0
- package/src/ordenar-tarefas/ordenar-tarefas.ts +135 -0
- package/src/task-manager.ts +70 -0
- package/src/task-manager.types.ts +95 -0
- package/src/testing.ts +8 -0
- package/src/user-registry.contract.ts +6 -6
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GroupId, TaskId, TaskStatus, TaskType } from '@opentask/taskin-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* O que restringe uma listagem de tarefas — derivado do schema unico.
|
|
5
|
+
*
|
|
6
|
+
* Vive em `filter-criteria.ts`, onde os criterios sao definidos uma vez so e as
|
|
7
|
+
* superficies (CLI e MCP) derivam. Reexportado aqui para nao mudar os imports
|
|
8
|
+
* existentes.
|
|
9
|
+
*/
|
|
10
|
+
export type { TaskFilterCriteria } from './filter-criteria.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A forma de uma tarefa numa listagem — o que identifica, nao o que ela diz.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface TaskSummary {
|
|
18
|
+
readonly id: TaskId;
|
|
19
|
+
readonly title: string;
|
|
20
|
+
readonly status: TaskStatus;
|
|
21
|
+
readonly type: TaskType;
|
|
22
|
+
readonly assignee?: { readonly id: string; readonly name: string };
|
|
23
|
+
readonly priority?: number;
|
|
24
|
+
readonly groupId?: GroupId;
|
|
25
|
+
readonly difficulty?: number;
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
CriterionCli,
|
|
3
|
+
CriterionSurface,
|
|
4
|
+
FilterCliOption,
|
|
5
|
+
FilterJsonSchema,
|
|
6
|
+
TaskFilterCriteria,
|
|
7
|
+
} from './filter-criteria.js';
|
|
8
|
+
export {
|
|
9
|
+
FILTER_CRITERIA_SURFACES,
|
|
10
|
+
FilterCriteriaSchema,
|
|
11
|
+
filterCriteriaCliOptions,
|
|
12
|
+
filterCriteriaJsonSchema,
|
|
13
|
+
parseFilterCriteria,
|
|
14
|
+
} from './filter-criteria.js';
|
|
15
|
+
export { filterTasks, summarizeTask } from './filter-tasks.js';
|
|
16
|
+
export type { TaskSummary } from './filter-tasks.types.js';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { parseGroupId } from '@opentask/taskin-types';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import type { IGroupRegistry } from './group-registry.types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Contrato que toda implementacao de {@link IGroupRegistry} precisa cumprir.
|
|
7
|
+
*
|
|
8
|
+
* Vive no pacote agnostico pelo mesmo motivo do contrato de usuarios: um
|
|
9
|
+
* provider de arquivos, um do Redmine e um do GitHub provam o mesmo
|
|
10
|
+
* comportamento sem depender do pacote um do outro. Exportado pelo subcaminho
|
|
11
|
+
* `./testing`, para o `vitest` nunca entrar no grafo de execucao.
|
|
12
|
+
*
|
|
13
|
+
* @param createSubject - Devolve um registro vazio, e uma forma de saber quantas
|
|
14
|
+
* tarefas pertencem a um grupo — porque apagar precisa dizer quantas foram
|
|
15
|
+
* afetadas, e isso e o unico ponto onde o contrato toca em tarefas.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export function runGroupRegistryContractTests(
|
|
19
|
+
createSubject: () => Promise<{
|
|
20
|
+
registry: IGroupRegistry;
|
|
21
|
+
atribuir: (groupId: string, quantas: number) => Promise<void>;
|
|
22
|
+
}>,
|
|
23
|
+
): void {
|
|
24
|
+
const g = (id: string) => parseGroupId(id);
|
|
25
|
+
|
|
26
|
+
describe('IGroupRegistry contract', () => {
|
|
27
|
+
it('cria e lista', async () => {
|
|
28
|
+
const { registry } = await createSubject();
|
|
29
|
+
|
|
30
|
+
await registry.createGroup({ id: g('g-1'), name: 'Sprint' });
|
|
31
|
+
|
|
32
|
+
expect(await registry.listGroups()).toEqual([{ id: 'g-1', name: 'Sprint' }]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('acha pelo id, e devolve indefinido para o que nao existe', async () => {
|
|
36
|
+
const { registry } = await createSubject();
|
|
37
|
+
await registry.createGroup({ id: g('g-1'), name: 'Sprint' });
|
|
38
|
+
|
|
39
|
+
expect(await registry.findGroup(g('g-1'))).toEqual({ id: 'g-1', name: 'Sprint' });
|
|
40
|
+
expect(await registry.findGroup(g('g-2'))).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('recusa id repetido', async () => {
|
|
44
|
+
const { registry } = await createSubject();
|
|
45
|
+
await registry.createGroup({ id: g('g-1'), name: 'Sprint' });
|
|
46
|
+
|
|
47
|
+
await expect(registry.createGroup({ id: g('g-1'), name: 'Outro' })).rejects.toThrow();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* O ponto da entidade: o nome vive num lugar so, entao renomear e uma
|
|
52
|
+
* escrita — e nenhuma tarefa e tocada.
|
|
53
|
+
*/
|
|
54
|
+
it('renomeia sem tocar em tarefa nenhuma', async () => {
|
|
55
|
+
const { registry, atribuir } = await createSubject();
|
|
56
|
+
await registry.createGroup({ id: g('g-1'), name: 'Sprint' });
|
|
57
|
+
await atribuir('g-1', 3);
|
|
58
|
+
|
|
59
|
+
await registry.renameGroup(g('g-1'), 'Sprint de outubro');
|
|
60
|
+
|
|
61
|
+
expect(await registry.findGroup(g('g-1'))).toEqual({ id: 'g-1', name: 'Sprint de outubro' });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('recusa renomear o que nao existe', async () => {
|
|
65
|
+
const { registry } = await createSubject();
|
|
66
|
+
|
|
67
|
+
await expect(registry.renameGroup(g('g-404'), 'Qualquer')).rejects.toThrow();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('apagar sem destino solta os membros, e diz quantos eram', async () => {
|
|
71
|
+
const { registry, atribuir } = await createSubject();
|
|
72
|
+
await registry.createGroup({ id: g('g-1'), name: 'Sprint' });
|
|
73
|
+
await atribuir('g-1', 3);
|
|
74
|
+
|
|
75
|
+
const resultado = await registry.deleteGroup(g('g-1'));
|
|
76
|
+
|
|
77
|
+
expect(resultado.reassigned).toBe(3);
|
|
78
|
+
expect(await registry.findGroup(g('g-1'))).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('apagar com destino move os membros para la', async () => {
|
|
82
|
+
const { registry, atribuir } = await createSubject();
|
|
83
|
+
await registry.createGroup({ id: g('g-1'), name: 'Sprint' });
|
|
84
|
+
await registry.createGroup({ id: g('g-2'), name: 'Backlog' });
|
|
85
|
+
await atribuir('g-1', 2);
|
|
86
|
+
|
|
87
|
+
const resultado = await registry.deleteGroup(g('g-1'), { reassignTo: g('g-2') });
|
|
88
|
+
|
|
89
|
+
expect(resultado.reassigned).toBe(2);
|
|
90
|
+
expect(await registry.findGroup(g('g-2'))).toBeDefined();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('recusa apagar o que nao existe', async () => {
|
|
94
|
+
const { registry } = await createSubject();
|
|
95
|
+
|
|
96
|
+
await expect(registry.deleteGroup(g('g-404'))).rejects.toThrow();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Group, GroupId } from '@opentask/taskin-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* O que acontece com os membros quando o grupo e apagado.
|
|
5
|
+
*
|
|
6
|
+
* Nao ha opcao de "nao dizer": tarefa apontando para grupo inexistente em
|
|
7
|
+
* silencio foi o unico resultado considerado inaceitavel ao decidir isto. As
|
|
8
|
+
* duas escolhas cobrem o que Redmine (`reassign_to_id`) e Jira (`moveIssuesTo`)
|
|
9
|
+
* ja oferecem na propria chamada de exclusao.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface DeleteGroupOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Para onde os membros vao. Ausente, eles ficam **sem grupo** — e a operacao
|
|
16
|
+
* informa quantos foram afetados, para o efeito nunca ser invisivel.
|
|
17
|
+
*/
|
|
18
|
+
reassignTo?: GroupId;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export interface DeleteGroupResult {
|
|
23
|
+
/** Quantas tarefas pertenciam ao grupo apagado. */
|
|
24
|
+
reassigned: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Operacoes de grupo que um provider oferece.
|
|
29
|
+
*
|
|
30
|
+
* Separado de `ITaskProvider` de proposito: nem toda fonte tem o conceito. Um
|
|
31
|
+
* provider que tenha implementa isto; um que nao tenha simplesmente nao o
|
|
32
|
+
* expoe, e quem consome descobre pela ausencia em vez de receber uma operacao
|
|
33
|
+
* que falha — o mesmo erro do `-t sse` do `mcp-server`, que existia na flag e
|
|
34
|
+
* nao na implementacao.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface IGroupRegistry {
|
|
39
|
+
listGroups: () => Promise<Group[]>;
|
|
40
|
+
findGroup: (id: GroupId) => Promise<Group | undefined>;
|
|
41
|
+
/** Falha quando o id ja existe. */
|
|
42
|
+
createGroup: (group: Group) => Promise<void>;
|
|
43
|
+
/** Falha quando o grupo nao existe. */
|
|
44
|
+
renameGroup: (id: GroupId, name: string) => Promise<void>;
|
|
45
|
+
/** Falha quando o grupo nao existe. */
|
|
46
|
+
deleteGroup: (id: GroupId, options?: DeleteGroupOptions) => Promise<DeleteGroupResult>;
|
|
47
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// Re-export commonly used types from @opentask/taskin-types for convenience
|
|
2
2
|
export type { Task, TaskStatus, TaskType, User } from '@opentask/taskin-types';
|
|
3
|
+
export * from './filter-tasks/index';
|
|
4
|
+
export * from './group-registry.types';
|
|
3
5
|
export * from './metrics.types';
|
|
6
|
+
export * from './numerar-prioridade/index';
|
|
7
|
+
export * from './ordenar-tarefas/index';
|
|
4
8
|
export * from './task-manager';
|
|
5
9
|
export * from './task-manager.types';
|
|
6
10
|
export * from './user-registry.types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './numerar-prioridade.js';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Task } from '@opentask/taskin-types';
|
|
2
|
+
import { parseTaskId } from '@opentask/taskin-types';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { numerarPrioridade } from './numerar-prioridade.js';
|
|
5
|
+
|
|
6
|
+
const tarefa = (id: string, order?: number): Task =>
|
|
7
|
+
({ id: parseTaskId(id), title: `Tarefa ${id}`, status: 'pending', type: 'feat', order }) as Task;
|
|
8
|
+
|
|
9
|
+
const ids = (ts: readonly Task[]) => ts.map((t) => String(t.id));
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Numeracao inicial de prioridade.
|
|
13
|
+
*
|
|
14
|
+
* Existe para eliminar o estado que custa caro: um projeto **meio numerado**.
|
|
15
|
+
* Enquanto metade das tarefas nao tem `order`, dar numero a uma do meio obriga a
|
|
16
|
+
* numerar todos os antecessores — 124 arquivos num projeto de 500, medido. Com o
|
|
17
|
+
* projeto inteiro numerado de uma vez, num ato deliberado, todo movimento
|
|
18
|
+
* seguinte custa um arquivo.
|
|
19
|
+
*
|
|
20
|
+
* A funcao devolve **so** o que precisa mudar, e nao a lista inteira: quem chama
|
|
21
|
+
* grava exatamente isso.
|
|
22
|
+
*/
|
|
23
|
+
describe('numerarPrioridade', () => {
|
|
24
|
+
it('num projeto sem nenhuma prioridade, numera todas preservando a ordem', () => {
|
|
25
|
+
const tarefas = [tarefa('001'), tarefa('002'), tarefa('003')];
|
|
26
|
+
|
|
27
|
+
const mudancas = numerarPrioridade(tarefas);
|
|
28
|
+
|
|
29
|
+
expect(ids(mudancas)).toEqual(['001', '002', '003']);
|
|
30
|
+
expect(mudancas.map((t) => t.order)).toEqual([100, 200, 300]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* Quem ja priorizou tomou uma decisao, e o comando preenche as lacunas em
|
|
35
|
+
* volta dela em vez de reescreve-la.
|
|
36
|
+
*/
|
|
37
|
+
it('mantem o numero de quem ja tem, e so preenche as lacunas', () => {
|
|
38
|
+
const tarefas = [tarefa('001', 50), tarefa('002'), tarefa('003', 900)];
|
|
39
|
+
|
|
40
|
+
const mudancas = numerarPrioridade(tarefas);
|
|
41
|
+
|
|
42
|
+
expect(ids(mudancas)).toEqual(['002']);
|
|
43
|
+
const nova = mudancas[0]?.order ?? 0;
|
|
44
|
+
expect(nova).toBeGreaterThan(50);
|
|
45
|
+
expect(nova).toBeLessThan(900);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Seguro de pôr num script ou num hook: a segunda passada nao escreve nada.
|
|
50
|
+
*/
|
|
51
|
+
it('rodar de novo nao muda nada', () => {
|
|
52
|
+
const tarefas = [tarefa('001'), tarefa('002'), tarefa('003')];
|
|
53
|
+
|
|
54
|
+
const primeira = numerarPrioridade(tarefas);
|
|
55
|
+
const segunda = numerarPrioridade(primeira.length ? aplicar(tarefas, primeira) : tarefas);
|
|
56
|
+
|
|
57
|
+
expect(segunda).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('nao devolve nada quando todas ja estao numeradas e em ordem', () => {
|
|
61
|
+
expect(numerarPrioridade([tarefa('001', 100), tarefa('002', 200)])).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** Aplica as mudancas devolvidas, como quem grava faria. */
|
|
66
|
+
function aplicar(tarefas: readonly Task[], mudancas: readonly Task[]): Task[] {
|
|
67
|
+
const por = new Map(mudancas.map((t) => [String(t.id), t]));
|
|
68
|
+
return tarefas.map((t) => por.get(String(t.id)) ?? t);
|
|
69
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Task } from '@opentask/taskin-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Passo largo de proposito.
|
|
5
|
+
*
|
|
6
|
+
* Com 100 cabem muitos movimentos entre dois vizinhos antes de a renumeracao
|
|
7
|
+
* local precisar acontecer. Com 10 — o passo que o quadro de priorizacao usava —
|
|
8
|
+
* o espaco acaba depressa, e cada esgotamento custa escrita em arquivo.
|
|
9
|
+
*/
|
|
10
|
+
export const PASSO_DE_PRIORIDADE = 100;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Devolve as tarefas que precisam de um `order` novo, e so elas.
|
|
14
|
+
*
|
|
15
|
+
* ## Por que isto existe
|
|
16
|
+
*
|
|
17
|
+
* O custo de reordenar no quadro de priorizacao ja e de um arquivo por
|
|
18
|
+
* movimento — **exceto** num projeto meio numerado. Ali, dar numero a uma tarefa
|
|
19
|
+
* do meio obriga a numerar todos os antecessores, porque uma tarefa sem `order`
|
|
20
|
+
* ordena por ultimo e nao tem posicao propria entre as numeradas. Num projeto de
|
|
21
|
+
* 500 tarefas com metade sem numero, isso chegou a 124 arquivos.
|
|
22
|
+
*
|
|
23
|
+
* A saida nao e um algoritmo mais esperto: e acabar com o estado meio numerado.
|
|
24
|
+
* Depois desta passada, ou o projeto inteiro tem numero, ou nunca foi priorizado
|
|
25
|
+
* — e todo movimento seguinte custa um arquivo.
|
|
26
|
+
*
|
|
27
|
+
* ## O que ela preserva
|
|
28
|
+
*
|
|
29
|
+
* A ordem relativa em que as tarefas chegaram, e o numero de quem ja tem um.
|
|
30
|
+
* Quem priorizou tomou uma decisao; o comando preenche as lacunas em volta dela
|
|
31
|
+
* em vez de reescreve-la.
|
|
32
|
+
*
|
|
33
|
+
* @param tarefas - Na ordem em que devem ficar
|
|
34
|
+
* @returns Copias apenas das tarefas que mudaram, prontas para gravar. Vazio
|
|
35
|
+
* quando nao ha nada a fazer — o que torna uma segunda passada inofensiva.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export function numerarPrioridade(tarefas: readonly Task[], passo = PASSO_DE_PRIORIDADE): Task[] {
|
|
39
|
+
const mudancas: Task[] = [];
|
|
40
|
+
let anterior = 0;
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < tarefas.length; i++) {
|
|
43
|
+
const atual = tarefas[i];
|
|
44
|
+
if (!atual) continue;
|
|
45
|
+
|
|
46
|
+
if (atual.order !== undefined && atual.order > anterior) {
|
|
47
|
+
anterior = atual.order;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* Precisa de numero. O teto e o proximo valor ja existente que ainda esta a
|
|
53
|
+
* frente — respeita-lo e o que preserva a decisao de quem priorizou.
|
|
54
|
+
*/
|
|
55
|
+
const teto = tarefas.slice(i + 1).find((t) => t?.order !== undefined && t.order > anterior)?.order;
|
|
56
|
+
const valor = teto === undefined ? anterior + passo : Math.floor((anterior + teto) / 2);
|
|
57
|
+
|
|
58
|
+
if (!(valor > anterior) || (teto !== undefined && valor >= teto)) {
|
|
59
|
+
/*
|
|
60
|
+
* Sem espaco entre os vizinhos: abre espaco andando para a frente e para
|
|
61
|
+
* no primeiro que ja estiver alem. A renumeracao fica na vizinhanca.
|
|
62
|
+
*/
|
|
63
|
+
let corrido = anterior;
|
|
64
|
+
for (let j = i; j < tarefas.length; j++) {
|
|
65
|
+
const item = tarefas[j];
|
|
66
|
+
if (!item) continue;
|
|
67
|
+
if (j > i && item.order !== undefined && item.order > corrido) break;
|
|
68
|
+
corrido += passo;
|
|
69
|
+
mudancas.push({ ...item, order: corrido });
|
|
70
|
+
}
|
|
71
|
+
anterior = corrido;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
mudancas.push({ ...atual, order: valor });
|
|
76
|
+
anterior = valor;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return mudancas;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ordenar-tarefas.js';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Task } from '@opentask/taskin-types';
|
|
2
|
+
import { parseGroupId, parseTaskId } from '@opentask/taskin-types';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { agruparTarefas, ordenarTarefas } from './ordenar-tarefas.js';
|
|
5
|
+
|
|
6
|
+
const t = (id: string, extra: Partial<Task> = {}): Task =>
|
|
7
|
+
({ id: parseTaskId(id), title: `Tarefa ${id}`, status: 'pending', type: 'feat', ...extra }) as Task;
|
|
8
|
+
|
|
9
|
+
const ids = (ts: readonly Task[]) => ts.map((x) => String(x.id));
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A ordenacao que o dashboard ja usava, agora onde as tres superficies alcancam.
|
|
13
|
+
*
|
|
14
|
+
* Ela vivia em `use-prioritization.ts`, dentro do pacote **Vue** — inalcancavel
|
|
15
|
+
* para a CLI e para o servidor MCP. O `taskin list` devolvia as tarefas na
|
|
16
|
+
* ordem em que o provider as achava, que na pratica e por id: a coluna de
|
|
17
|
+
* prioridade subia e descia sem padrao, e quem lia precisava reordenar de
|
|
18
|
+
* cabeca. Foi assim que um agente autonomo escolheu uma tarefa de prioridade 30
|
|
19
|
+
* tendo uma de 255 na mesma lista.
|
|
20
|
+
*/
|
|
21
|
+
describe('ordenarTarefas', () => {
|
|
22
|
+
it('manual ordena por prioridade, com quem nao tem por ultimo', () => {
|
|
23
|
+
const tarefas = [t('001', { order: 30 }), t('002'), t('003', { order: 10 })];
|
|
24
|
+
|
|
25
|
+
expect(ids(ordenarTarefas(tarefas, 'manual'))).toEqual(['003', '001', '002']);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('manual e estavel entre empatados', () => {
|
|
29
|
+
const tarefas = [t('001', { order: 10 }), t('002', { order: 10 }), t('003', { order: 10 })];
|
|
30
|
+
|
|
31
|
+
expect(ids(ordenarTarefas(tarefas, 'manual'))).toEqual(['001', '002', '003']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('difficulty ordena do mais facil ao mais dificil, e o inverso', () => {
|
|
35
|
+
const tarefas = [t('001', { difficulty: 5 }), t('002', { difficulty: 1 }), t('003', { difficulty: 3 })];
|
|
36
|
+
|
|
37
|
+
expect(ids(ordenarTarefas(tarefas, 'diff-asc'))).toEqual(['002', '003', '001']);
|
|
38
|
+
expect(ids(ordenarTarefas(tarefas, 'diff-desc'))).toEqual(['001', '003', '002']);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('nao altera a lista recebida', () => {
|
|
42
|
+
const tarefas = [t('001', { order: 30 }), t('002', { order: 10 })];
|
|
43
|
+
ordenarTarefas(tarefas, 'manual');
|
|
44
|
+
|
|
45
|
+
expect(ids(tarefas)).toEqual(['001', '002']);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Agrupar e separado de ordenar, e de proposito.
|
|
51
|
+
*
|
|
52
|
+
* No dashboard as duas coisas vinham juntas porque a arvore era so para
|
|
53
|
+
* desenhar caixas. Na saida de maquina quem consome decide — e separar deixa a
|
|
54
|
+
* CLI ordenar sem agrupar quando ninguem pediu grupo.
|
|
55
|
+
*/
|
|
56
|
+
describe('agruparTarefas', () => {
|
|
57
|
+
const g1 = parseGroupId('g-1');
|
|
58
|
+
|
|
59
|
+
it('junta membros do mesmo grupo, esteja onde estiver na ordem', () => {
|
|
60
|
+
const tarefas = [t('001', { groupId: g1 }), t('002'), t('003', { groupId: g1 })];
|
|
61
|
+
|
|
62
|
+
const nos = agruparTarefas(tarefas, { 'g-1': 'Sprint' });
|
|
63
|
+
|
|
64
|
+
expect(nos).toHaveLength(2);
|
|
65
|
+
expect(nos[0]).toMatchObject({ kind: 'group', groupId: 'g-1', groupName: 'Sprint', hidden: 0 });
|
|
66
|
+
expect(nos[0]?.kind === 'group' && ids(nos[0].tasks)).toEqual(['001', '003']);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
* O grupo parcial, decidido: mostra os membros que casam, e diz quantos o
|
|
71
|
+
* filtro escondeu. Nunca alarga o filtro para trazer o grupo inteiro.
|
|
72
|
+
*/
|
|
73
|
+
it('diz quantos membros o filtro deixou de fora', () => {
|
|
74
|
+
const tarefas = [t('001', { groupId: g1 })];
|
|
75
|
+
|
|
76
|
+
const nos = agruparTarefas(tarefas, { 'g-1': 'Sprint' }, { 'g-1': 7 });
|
|
77
|
+
|
|
78
|
+
expect(nos[0]).toMatchObject({ kind: 'group', hidden: 6 });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('tarefa sem grupo fica solta, na ordem em que veio', () => {
|
|
82
|
+
const nos = agruparTarefas([t('001'), t('002')], {});
|
|
83
|
+
|
|
84
|
+
expect(nos.map((n) => n.kind)).toEqual(['task', 'task']);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('grupo sem nome no registro ainda aparece, pelo id', () => {
|
|
88
|
+
const nos = agruparTarefas([t('001', { groupId: g1 })], {});
|
|
89
|
+
|
|
90
|
+
expect(nos[0]).toMatchObject({ kind: 'group', groupId: 'g-1', groupName: undefined });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { Task } from '@opentask/taskin-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Como uma listagem pode ser ordenada.
|
|
5
|
+
*
|
|
6
|
+
* O mesmo vocabulario que o quadro de priorizacao do dashboard usa. Manter as
|
|
7
|
+
* grafias iguais entre as superficies vale mais que elegancia local: quem le a
|
|
8
|
+
* documentacao de uma reconhece a outra.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type ModoDeOrdenacao = 'manual' | 'diff-asc' | 'diff-desc';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* O que a ordenacao precisa saber, e nada alem disso.
|
|
16
|
+
*
|
|
17
|
+
* Exigir `Task` inteira deixaria a funcao inalcancavel para quem tem outra
|
|
18
|
+
* forma de tarefa — o quadro de priorizacao do dashboard, por exemplo, usa um
|
|
19
|
+
* modelo de tela proprio. Pedir so os dois campos que ela le e o que permite as
|
|
20
|
+
* duas superficies compartilharem a regra em vez de cada uma ter a sua copia.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface OrdenavelPorPrioridade {
|
|
25
|
+
readonly order?: number;
|
|
26
|
+
readonly difficulty?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Um no da listagem: uma tarefa solta, ou um grupo com os membros que casaram. */
|
|
30
|
+
export type NoDaListagem<TTask extends Task = Task> =
|
|
31
|
+
| { readonly kind: 'task'; readonly task: TTask }
|
|
32
|
+
| {
|
|
33
|
+
readonly kind: 'group';
|
|
34
|
+
readonly groupId: string;
|
|
35
|
+
/** `undefined` quando o registro nao conhece o grupo. */
|
|
36
|
+
readonly groupName: string | undefined;
|
|
37
|
+
readonly tasks: readonly TTask[];
|
|
38
|
+
/** Quantos membros o filtro deixou de fora. Zero quando o grupo veio inteiro. */
|
|
39
|
+
readonly hidden: number;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Ordena uma listagem, sem alterar a lista recebida.
|
|
44
|
+
*
|
|
45
|
+
* Vivia dentro do pacote Vue do dashboard, inalcancavel para a CLI e para o
|
|
46
|
+
* servidor MCP — e por isso `taskin list` devolvia as tarefas na ordem em que o
|
|
47
|
+
* provider as achava, que na pratica e por id.
|
|
48
|
+
*
|
|
49
|
+
* `manual` usa o `order`, com quem nao tem por ultimo e estabilidade no resto.
|
|
50
|
+
* Os dois modos de dificuldade usam o `difficulty`.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export function ordenarTarefas<TTask extends OrdenavelPorPrioridade>(
|
|
55
|
+
tarefas: readonly TTask[],
|
|
56
|
+
modo: ModoDeOrdenacao = 'manual',
|
|
57
|
+
): TTask[] {
|
|
58
|
+
const comIndice = tarefas.map((task, index) => ({ task, index }));
|
|
59
|
+
|
|
60
|
+
const campo = (t: TTask) => (modo === 'manual' ? t.order : t.difficulty);
|
|
61
|
+
const sinal = modo === 'diff-desc' ? -1 : 1;
|
|
62
|
+
|
|
63
|
+
comIndice.sort((a, b) => {
|
|
64
|
+
const va = campo(a.task);
|
|
65
|
+
const vb = campo(b.task);
|
|
66
|
+
|
|
67
|
+
// Quem nao tem valor vai para o fim, qualquer que seja a direcao.
|
|
68
|
+
if (va === undefined && vb === undefined) return a.index - b.index;
|
|
69
|
+
if (va === undefined) return 1;
|
|
70
|
+
if (vb === undefined) return -1;
|
|
71
|
+
if (va !== vb) return (va - vb) * sinal;
|
|
72
|
+
|
|
73
|
+
return a.index - b.index;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return comIndice.map(({ task }) => task);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Junta os membros de um grupo num no so, **por identidade**.
|
|
81
|
+
*
|
|
82
|
+
* Separado de {@link ordenarTarefas} de proposito. No dashboard as duas coisas
|
|
83
|
+
* vinham juntas porque a arvore existia para desenhar caixas; aqui quem consome
|
|
84
|
+
* decide se quer agrupar.
|
|
85
|
+
*
|
|
86
|
+
* Agrupa pelo `groupId`, e nao por adjacencia: membros separados por um filtro
|
|
87
|
+
* ou por uma ordenacao continuam sendo **um** grupo. Agrupar por adjacencia era
|
|
88
|
+
* o defeito da task-072, que partia o mesmo grupo em dois nos com o mesmo nome.
|
|
89
|
+
*
|
|
90
|
+
* @param tarefas - Ja ordenadas; a ordem dos grupos segue a do primeiro membro
|
|
91
|
+
* @param nomes - O que o registro de grupos sabe, por id
|
|
92
|
+
* @param totais - Quantos membros cada grupo tem **antes** do filtro. O que
|
|
93
|
+
* falta vira `hidden`, para o leitor saber que nao esta vendo o grupo inteiro
|
|
94
|
+
* em vez de o filtro se alargar sozinho e trazer o resto.
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export function agruparTarefas<TTask extends Task>(
|
|
98
|
+
tarefas: readonly TTask[],
|
|
99
|
+
nomes: Readonly<Record<string, string>> = {},
|
|
100
|
+
totais: Readonly<Record<string, number>> = {},
|
|
101
|
+
): NoDaListagem<TTask>[] {
|
|
102
|
+
const nos: NoDaListagem<TTask>[] = [];
|
|
103
|
+
const porGrupo = new Map<string, TTask[]>();
|
|
104
|
+
|
|
105
|
+
for (const task of tarefas) {
|
|
106
|
+
const id = task.groupId === undefined ? undefined : String(task.groupId);
|
|
107
|
+
|
|
108
|
+
if (id === undefined) {
|
|
109
|
+
nos.push({ kind: 'task', task });
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const existente = porGrupo.get(id);
|
|
114
|
+
if (existente) {
|
|
115
|
+
existente.push(task);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const membros = [task];
|
|
120
|
+
porGrupo.set(id, membros);
|
|
121
|
+
nos.push({
|
|
122
|
+
kind: 'group',
|
|
123
|
+
groupId: id,
|
|
124
|
+
groupName: nomes[id],
|
|
125
|
+
tasks: membros,
|
|
126
|
+
hidden: 0,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return nos.map((no) =>
|
|
131
|
+
no.kind === 'group'
|
|
132
|
+
? { ...no, hidden: Math.max(0, (totais[no.groupId] ?? no.tasks.length) - no.tasks.length) }
|
|
133
|
+
: no,
|
|
134
|
+
);
|
|
135
|
+
}
|
package/src/task-manager.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Task, TaskId, TaskStatus } from '@opentask/taskin-types';
|
|
2
|
+
import type { IGroupRegistry } from './group-registry.types';
|
|
3
|
+
import { numerarPrioridade } from './numerar-prioridade/index';
|
|
2
4
|
import type {
|
|
3
5
|
CreateTaskOptions,
|
|
4
6
|
CreateTaskResult,
|
|
7
|
+
CriterioEmAberto,
|
|
5
8
|
ITaskManager,
|
|
6
9
|
ITaskProvider,
|
|
7
10
|
LintResult,
|
|
@@ -65,6 +68,73 @@ export class TaskManager<TTask extends Task = Task> implements ITaskManager<TTas
|
|
|
65
68
|
return updatedTask;
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Every task the configured provider knows about.
|
|
73
|
+
*
|
|
74
|
+
* Pass-through on purpose: the manager owns the state transitions, not the
|
|
75
|
+
* storage. Having it here is what lets a consumer holding only the manager —
|
|
76
|
+
* the MCP server — answer "what work exists?".
|
|
77
|
+
*/
|
|
78
|
+
async getAllTasks(): Promise<TTask[]> {
|
|
79
|
+
return await this.taskProvider.getAllTasks();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Repassa o registro do provider, quando ele tem um. */
|
|
83
|
+
get groupRegistry(): IGroupRegistry | undefined {
|
|
84
|
+
return (this.taskProvider as { groupRegistry?: IGroupRegistry }).groupRegistry;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async prioritizeAll(options: { dryRun?: boolean } = {}): Promise<{
|
|
88
|
+
total: number;
|
|
89
|
+
withoutPriority: number;
|
|
90
|
+
changed: number;
|
|
91
|
+
}> {
|
|
92
|
+
const tarefas = await this.taskProvider.getAllTasks();
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* Quem ja tem numero define a ordem; quem nao tem entra depois, na sequencia
|
|
96
|
+
* em que o provider devolveu.
|
|
97
|
+
*/
|
|
98
|
+
const ordenadas = [...tarefas].sort((a, b) => {
|
|
99
|
+
if (a.order === undefined && b.order === undefined) return 0;
|
|
100
|
+
if (a.order === undefined) return 1;
|
|
101
|
+
if (b.order === undefined) return -1;
|
|
102
|
+
return a.order - b.order;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const mudancas = numerarPrioridade(ordenadas);
|
|
106
|
+
const semNumero = tarefas.filter((t) => t.order === undefined).length;
|
|
107
|
+
|
|
108
|
+
if (!options.dryRun) {
|
|
109
|
+
for (const tarefa of mudancas) {
|
|
110
|
+
await this.taskProvider.updateTask(tarefa as TTask);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { total: tarefas.length, withoutPriority: semNumero, changed: mudancas.length };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Conclui a tarefa e **relata** o que ficou em aberto.
|
|
119
|
+
*
|
|
120
|
+
* Avisa, e nao recusa. Fechar uma tarefa e um gesto que acontece uma vez,
|
|
121
|
+
* muitas vezes com pressa; recusar ali torna o comando fragil e ensina a
|
|
122
|
+
* contornar. O portao duro vive no `lint`, que roda em CI e quebra o build —
|
|
123
|
+
* aqui o papel e dizer, no momento em que a pessoa ainda esta olhando, o que
|
|
124
|
+
* ficou para tras.
|
|
125
|
+
*
|
|
126
|
+
* Um provider sem a capacidade conclui sem portao nenhum.
|
|
127
|
+
*/
|
|
128
|
+
async finishTaskComRelato(taskId: TaskId): Promise<{ task: TTask; blockers: CriterioEmAberto[] }> {
|
|
129
|
+
const task = await this.taskProvider.findTask(taskId);
|
|
130
|
+
if (!task) throw new Error(`Task with ID '${taskId}' not found.`);
|
|
131
|
+
|
|
132
|
+
const blockers = (await this.taskProvider.getCompletionBlockers?.(task)) ?? [];
|
|
133
|
+
const atualizada = await this.finishTask(taskId);
|
|
134
|
+
|
|
135
|
+
return { task: atualizada, blockers };
|
|
136
|
+
}
|
|
137
|
+
|
|
68
138
|
async finishTask(taskId: TaskId): Promise<TTask> {
|
|
69
139
|
const task = await this.taskProvider.findTask(taskId);
|
|
70
140
|
|