@immediately-run/dibber 0.3.0 → 0.5.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/README.md +64 -6
- package/SPEC.md +65 -44
- package/config.schema.json +26 -2
- package/package.json +11 -2
- package/skills/dibber-new-ticket/SKILL.md +8 -2
- package/skills/dibber-overview/SKILL.md +5 -2
- package/skills/dibber-triage-issues/SKILL.md +29 -0
- package/skills/dibber-work-ticket/SKILL.md +4 -1
- package/src/check.mjs +20 -5
- package/src/cli.mjs +48 -15
- package/src/coordinator.mjs +42 -0
- package/src/import.mjs +200 -0
- package/src/init.mjs +11 -8
- package/src/intake.mjs +41 -0
- package/src/migrate.mjs +61 -0
- package/src/store.mjs +11 -6
- package/src/tickets.mjs +183 -33
- package/templates/AGENTS.section.md +1 -0
- package/ticket.schema.json +7 -7
package/src/cli.mjs
CHANGED
|
@@ -7,12 +7,15 @@ import { resolve } from 'node:path';
|
|
|
7
7
|
import { checkStore } from './check.mjs';
|
|
8
8
|
import { Refusal, newTicket, setStatus, claim, listTickets, STATUSES } from './tickets.mjs';
|
|
9
9
|
import { init, defaultPrefix } from './init.mjs';
|
|
10
|
+
import { importTickets } from './import.mjs';
|
|
11
|
+
import { migrateStore } from './migrate.mjs';
|
|
12
|
+
import { intakeGitHub } from './intake.mjs';
|
|
10
13
|
|
|
11
14
|
const HELP = `dibber — Git as your issue tracker: an open format built on Markdown (https://github.com/immediately-run/dibber)
|
|
12
15
|
|
|
13
16
|
Usage: dibber <command> [options] (every command takes --json and --root <dir>)
|
|
14
17
|
|
|
15
|
-
init [--prefix P] [--store DIR] [--yes] [--no-agents] [--update-skills] [--link-skills]
|
|
18
|
+
init [--prefix P] [--ids numeric|random] [--store DIR] [--yes] [--no-agents] [--update-skills] [--link-skills]
|
|
16
19
|
[--no-immediately-run] set this repository up: .dibber/config.json, the store,
|
|
17
20
|
a first ticket, AGENTS.md, the agent skills, and the files
|
|
18
21
|
that open the store as a board on immediately.run;
|
|
@@ -21,13 +24,23 @@ Usage: dibber <command> [options] (every command takes --json and --root
|
|
|
21
24
|
files out
|
|
22
25
|
check [--strict] check the store against the Dibber spec; --strict fails
|
|
23
26
|
on warnings too
|
|
24
|
-
list [--ready] [--status S] [--all]
|
|
25
|
-
the overview: what is ready, in progress and waiting
|
|
27
|
+
list [--ready] [--status S] [--all] [--offline]
|
|
28
|
+
the overview: what is ready, in progress and waiting;
|
|
29
|
+
--offline does not ask the coordinator
|
|
26
30
|
new --title "…" [--why "…"] [--what "…"] [--criterion "…"]… [--depends-on ID,…]
|
|
31
|
+
[--id ID] [--offline] [--body-file PATH] [--field KEY=VALUE]…
|
|
27
32
|
[--parent ID] [--tags a,b] [--project P] [--order N] [--brief "…"] [--mdx]
|
|
28
|
-
|
|
33
|
+
[--status S]
|
|
34
|
+
file a ticket with the next free id; its status is
|
|
35
|
+
orchestrator with a coordinator, else available
|
|
36
|
+
migrate [--to-orchestrator] update legacy page markers and custom types in place;
|
|
37
|
+
--to-orchestrator hands a coordinated store's live
|
|
38
|
+
tickets to the coordinator
|
|
39
|
+
intake github <issue.json> file a quoted GitHub issue report
|
|
40
|
+
import github|linear|jira <export> [--source-url URL]
|
|
41
|
+
import tickets from a local export
|
|
29
42
|
claim <id> [--as NAME] [--force] available → in-progress, with you as assignee
|
|
30
|
-
set <id> <status> [--pr URL] [--note "…"]
|
|
43
|
+
set <id> [<status>] [--field KEY=VALUE]… [--pr URL] [--note "…"]
|
|
31
44
|
change a status; the file stays where it is
|
|
32
45
|
done <id> [--pr URL] [--note "…"]
|
|
33
46
|
close a ticket as done; the file stays where it is
|
|
@@ -38,8 +51,8 @@ several people or several LLM providers at once: add a coordinator such as Baton
|
|
|
38
51
|
(https://github.com/immediately-run/baton). Claims here are advisory, not locks.
|
|
39
52
|
`;
|
|
40
53
|
|
|
41
|
-
const FLAGS_WITH_VALUES = new Set(['prefix', 'store', 'status', 'title', 'why', 'what', 'criterion', 'depends-on', 'parent', 'tags', 'project', 'order', 'brief', 'as', 'pr', 'note', 'root', 'description', 'assignee']);
|
|
42
|
-
const REPEATABLE = new Set(['criterion']);
|
|
54
|
+
const FLAGS_WITH_VALUES = new Set(['source-url', 'id', 'body-file', 'field', 'prefix', 'ids', 'store', 'status', 'title', 'why', 'what', 'criterion', 'depends-on', 'parent', 'tags', 'project', 'order', 'brief', 'as', 'pr', 'note', 'root', 'description', 'assignee']);
|
|
55
|
+
const REPEATABLE = new Set(['criterion', 'field']);
|
|
43
56
|
|
|
44
57
|
export function parseArgs(argv) {
|
|
45
58
|
const flags = {};
|
|
@@ -75,6 +88,7 @@ function formatList(rows) {
|
|
|
75
88
|
['In review', (r) => r.status === 'in-review'],
|
|
76
89
|
['Waiting', (r) => r.status === 'available' && !r.ready],
|
|
77
90
|
['Parked', (r) => r.status === 'deprioritized'],
|
|
91
|
+
['Coordinated', (r) => r.status === 'orchestrator' && !r.ready && !r.closed],
|
|
78
92
|
['Closed', (r) => r.closed],
|
|
79
93
|
];
|
|
80
94
|
const out = [];
|
|
@@ -86,7 +100,8 @@ function formatList(rows) {
|
|
|
86
100
|
const extra = [];
|
|
87
101
|
if (r.assignee) extra.push(`@${r.assignee}`);
|
|
88
102
|
if (label === 'Waiting') extra.push(`waits on ${r.waits.map((w) => `${w.id} (${w.why})`).join(', ')}`);
|
|
89
|
-
if (label === '
|
|
103
|
+
if (label === 'Coordinated') extra.push(r.coordinator ? [r.coordinator.state, r.coordinator.reason].filter(Boolean).join(': ') : 'coordinated');
|
|
104
|
+
if (label === 'Closed') extra.push(r.coordinator?.state ?? r.status);
|
|
90
105
|
out.push(` ${r.title}${extra.length ? ` — ${extra.join('; ')}` : ''}`);
|
|
91
106
|
}
|
|
92
107
|
out.push('');
|
|
@@ -128,17 +143,35 @@ export async function run(argv, { cwd = process.cwd(), interactive = true } = {}
|
|
|
128
143
|
}
|
|
129
144
|
code = errors.length || (flags.strict && warnings.length) ? 1 : 0;
|
|
130
145
|
} else if (cmd === 'list') {
|
|
131
|
-
const rows = listTickets(root, { ready: flags.ready, status: flags.status, closed: flags.all });
|
|
146
|
+
const rows = listTickets(root, { ready: flags.ready, status: flags.status, closed: flags.all, offline: flags.offline, onError: (m) => stderr.push(`dibber: ${m}`) });
|
|
132
147
|
if (flags.json) json(rows);
|
|
133
148
|
else stdout.push(formatList(rows));
|
|
134
149
|
} else if (cmd === 'new') {
|
|
135
150
|
const r = newTicket(root, {
|
|
136
|
-
|
|
151
|
+
id: flags.id, offline: flags.offline, fields: flags.field,
|
|
152
|
+
bodyFile: flags['body-file'] === undefined ? undefined : resolve(cwd, flags['body-file']),
|
|
153
|
+
status: flags.status, title: flags.title, why: flags.why, what: flags.what, criteria: flags.criterion ?? [],
|
|
137
154
|
dependsOn: csv(flags['depends-on']), parent: flags.parent, tags: csv(flags.tags), project: flags.project,
|
|
138
155
|
order: flags.order, brief: flags.brief, description: flags.description, assignee: flags.assignee, mdx: flags.mdx,
|
|
139
156
|
});
|
|
140
157
|
if (flags.json) json(r);
|
|
141
|
-
else stdout.push(`filed ${r.id}: ${r.file}`);
|
|
158
|
+
else stdout.push(`filed ${r.id}: ${r.file}${r.offline ? ' (offline allocation)' : ''}`);
|
|
159
|
+
} else if (cmd === 'migrate') {
|
|
160
|
+
const updated = migrateStore(root, { toOrchestrator: flags['to-orchestrator'] });
|
|
161
|
+
if (flags.json) json({ updated });
|
|
162
|
+
else stdout.push(updated.length ? updated.map((path) => `migrated ${path}`).join('\n') : 'No migration needed.');
|
|
163
|
+
} else if (cmd === 'intake') {
|
|
164
|
+
const [source, file] = rest;
|
|
165
|
+
if (source !== 'github' || !file) throw new Refusal('usage: dibber intake github <issue.json>');
|
|
166
|
+
const r = intakeGitHub(root, resolve(cwd, file));
|
|
167
|
+
if (flags.json) json(r);
|
|
168
|
+
else stdout.push(`${r.existing ? 'already filed' : 'filed'} ${r.id}: ${r.file}`);
|
|
169
|
+
} else if (cmd === 'import') {
|
|
170
|
+
const [source, file] = rest;
|
|
171
|
+
if (!file) throw new Refusal('usage: dibber import github|linear|jira <export> [--source-url URL]');
|
|
172
|
+
const r = importTickets(root, source, resolve(cwd, file), flags['source-url']);
|
|
173
|
+
if (flags.json) json(r);
|
|
174
|
+
else stdout.push(`imported ${r.length} ticket${r.length === 1 ? '' : 's'}`);
|
|
142
175
|
} else if (cmd === 'claim') {
|
|
143
176
|
if (!rest[0]) throw new Refusal('which ticket? dibber claim <id>');
|
|
144
177
|
const r = claim(root, rest[0], { as: flags.as, force: flags.force });
|
|
@@ -147,21 +180,21 @@ export async function run(argv, { cwd = process.cwd(), interactive = true } = {}
|
|
|
147
180
|
} else if (cmd === 'set' || cmd === 'done') {
|
|
148
181
|
const id = rest[0];
|
|
149
182
|
const status = cmd === 'done' ? 'done' : rest[1];
|
|
150
|
-
if (!id || !status) throw new Refusal(cmd === 'done' ? 'which ticket? dibber done <id>' : 'dibber set <id> <status>');
|
|
151
|
-
const r = setStatus(root, id, status, { pr: flags.pr, note: flags.note });
|
|
183
|
+
if (!id || (!status && !flags.field?.length)) throw new Refusal(cmd === 'done' ? 'which ticket? dibber done <id>' : 'dibber set <id> <status>');
|
|
184
|
+
const r = setStatus(root, id, status, { pr: flags.pr, note: flags.note, fields: flags.field });
|
|
152
185
|
if (flags.json) json(r);
|
|
153
186
|
else stdout.push(`${r.id} is ${r.status}: ${r.file}`);
|
|
154
187
|
} else if (cmd === 'init') {
|
|
155
188
|
let prefix = flags.prefix;
|
|
156
189
|
if (!prefix && !flags.yes && interactive) prefix = (await ask('Ticket id prefix (e.g. APP for APP-1)?', defaultPrefix(root))).toUpperCase();
|
|
157
|
-
const r = init(root, { prefix, store: flags.store, agents: !flags['no-agents'], updateSkills: flags['update-skills'], linkSkills: flags['link-skills'], immediatelyRun: !flags['no-immediately-run'] });
|
|
190
|
+
const r = init(root, { prefix, ids: flags.ids, store: flags.store, agents: !flags['no-agents'], updateSkills: flags['update-skills'], linkSkills: flags['link-skills'], immediatelyRun: !flags['no-immediately-run'] });
|
|
158
191
|
if (flags.json) json(r);
|
|
159
192
|
else {
|
|
160
193
|
for (const f of r.created) stdout.push(` created ${f}`);
|
|
161
194
|
for (const f of r.updated) stdout.push(` updated ${f}`);
|
|
162
195
|
for (const f of r.repaired) stdout.push(` repaired ${f} (it was broken; written again)`);
|
|
163
196
|
for (const f of r.skipped) stdout.push(` kept ${f} (already there)`);
|
|
164
|
-
stdout.push(`\nDibber is set up: tickets in ${r.store}/, ids ${r.prefix}-1, ${r.prefix}-2,
|
|
197
|
+
stdout.push(`\nDibber is set up: tickets in ${r.store}/, ids ${r.ids === 'random' ? `${r.prefix}-<random>` : `${r.prefix}-1, ${r.prefix}-2, …`}\nNext: ask your agent "what's on the board?", or run: dibber list`);
|
|
165
198
|
if (r.created.includes(`${r.store}/immediately.run.json`)) {
|
|
166
199
|
stdout.push(`Once pushed to a public GitHub repository, the board opens at https://immediately.run/present/github/${r.repo ?? '<owner>/<repo>'}/main/bundle/${r.store}/home.mdx`);
|
|
167
200
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// coordinator.mjs — ask the coordinator where its tickets stand ([DIB-35](../tickets/DIB-35.md)).
|
|
2
|
+
// `coordinator.status` in .dibber/config.json is run from the repository root; its answer is
|
|
3
|
+
// data: checked, bounded and shown, never acted on beyond `state` and `closed`.
|
|
4
|
+
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
const MAX_TEXT = 200;
|
|
8
|
+
// Text a terminal would act on does not reach one.
|
|
9
|
+
const plain = (v) => (typeof v === 'string' ? v.replace(/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, ' ').trim().slice(0, MAX_TEXT) : '');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The coordinator's state of `ids`: `{ states: Map(id → { state, closed, reason }), error }`.
|
|
13
|
+
* With no query configured, or one that fails, `states` is empty and nothing throws.
|
|
14
|
+
*/
|
|
15
|
+
export function coordinatorStates(root, store, ids) {
|
|
16
|
+
const argv = store.settings.raw?.coordinator?.status;
|
|
17
|
+
const states = new Map();
|
|
18
|
+
if (!ids.length || argv === undefined) return { states, error: null };
|
|
19
|
+
if (!Array.isArray(argv) || !argv[0] || !argv.every((arg) => typeof arg === 'string')) {
|
|
20
|
+
return { states, error: 'coordinator.status must be an executable and its arguments' };
|
|
21
|
+
}
|
|
22
|
+
const args = argv.includes('<ids>') ? argv.flatMap((arg) => (arg === '<ids>' ? ids : [arg])) : [...argv, ...ids];
|
|
23
|
+
let answer;
|
|
24
|
+
try {
|
|
25
|
+
answer = JSON.parse(execFileSync(args[0], args.slice(1), {
|
|
26
|
+
cwd: root, encoding: 'utf8', timeout: 30_000, maxBuffer: 16 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'],
|
|
27
|
+
}));
|
|
28
|
+
} catch {
|
|
29
|
+
return { states, error: 'the coordinator did not answer the status query' };
|
|
30
|
+
}
|
|
31
|
+
const tickets = answer?.tickets;
|
|
32
|
+
if (typeof tickets !== 'object' || tickets === null || Array.isArray(tickets)) {
|
|
33
|
+
return { states, error: 'the coordinator’s status answer has no `tickets` object' };
|
|
34
|
+
}
|
|
35
|
+
for (const id of ids) {
|
|
36
|
+
const t = Object.hasOwn(tickets, id) ? tickets[id] : undefined;
|
|
37
|
+
const state = plain(t?.state);
|
|
38
|
+
if (!state || typeof t.closed !== 'boolean') continue; // not answered: the ticket stays coordinated
|
|
39
|
+
states.set(id, { state, closed: t.closed, reason: plain(t.reason) });
|
|
40
|
+
}
|
|
41
|
+
return { states, error: null };
|
|
42
|
+
}
|
package/src/import.mjs
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Import tracker exports into a Dibber store ([DIB-16](../tickets/DIB-16.md)).
|
|
2
|
+
import { readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { extname, join } from 'node:path';
|
|
4
|
+
import { parse } from 'csv-parse/sync';
|
|
5
|
+
import { checkStore } from './check.mjs';
|
|
6
|
+
import { rel } from './store.mjs';
|
|
7
|
+
import { allocateTicketId, frontmatterYaml, Refusal, today } from './tickets.mjs';
|
|
8
|
+
|
|
9
|
+
const asArray = (value) => Array.isArray(value) ? value : value?.nodes ?? [];
|
|
10
|
+
const present = (values) => values.filter((value) => value !== undefined && value !== null && value !== '');
|
|
11
|
+
const csvValues = (value) => present(Array.isArray(value) ? value : [value]);
|
|
12
|
+
const list = (value) => csvValues(value).flatMap((entry) => entry.split(/[,;]\s*/)).map((entry) => entry.trim()).filter(Boolean);
|
|
13
|
+
const ref = (value) => value && (typeof value === 'object'
|
|
14
|
+
? ref(value.issue ?? value.relatedIssue ?? value.number ?? value.identifier ?? value.key ?? value.id) : String(value));
|
|
15
|
+
const label = (value) => typeof value === 'string' ? value : value?.name ?? value?.title;
|
|
16
|
+
const person = (value) => typeof value === 'string' ? value : value?.login ?? value?.name ?? value?.displayName;
|
|
17
|
+
const quote = (value) => String(value).replace(/\r\n?/g, '\n').split('\n').map((line) => `> ${line}`).join('\n');
|
|
18
|
+
|
|
19
|
+
function statusFor(status, closed = false) {
|
|
20
|
+
const word = String(status ?? '').trim().toLowerCase().replace(/[-_]/g, ' ');
|
|
21
|
+
if (['duplicate', 'superseded'].includes(word)) return 'superseded';
|
|
22
|
+
if (['canceled', 'cancelled', 'withdrawn', 'not planned', "won't do"].includes(word)) return 'withdrawn';
|
|
23
|
+
if (closed || ['done', 'completed', 'closed', 'resolved'].includes(word)) return 'done';
|
|
24
|
+
if (['in progress', 'started', 'doing'].includes(word)) return 'in-progress';
|
|
25
|
+
if (['in review', 'review'].includes(word)) return 'in-review';
|
|
26
|
+
return 'available';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function github(row) {
|
|
30
|
+
return {
|
|
31
|
+
key: ref(row.number), aliases: present([ref(row.id), row.url, row.html_url]),
|
|
32
|
+
title: row.title, body: row.body, url: row.html_url ?? row.url,
|
|
33
|
+
status: statusFor(row.stateReason ?? row.state_reason, row.closed || row.state?.toLowerCase() === 'closed'),
|
|
34
|
+
tags: asArray(row.labels).map(label), project: label(row.milestone ?? asArray(row.projectItems)[0]),
|
|
35
|
+
assignee: person(row.assignee ?? asArray(row.assignees)[0]),
|
|
36
|
+
parent: ref(row.parent), children: asArray(row.subIssues).map(ref),
|
|
37
|
+
waits: asArray(row.blockedBy ?? row.blocked_by).map(ref), comments: asArray(row.comments),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function linear(row) {
|
|
42
|
+
const state = row.state ?? row.Status;
|
|
43
|
+
return {
|
|
44
|
+
key: ref(row.identifier ?? row.ID ?? row.id), aliases: present([ref(row.id)]),
|
|
45
|
+
title: row.title ?? row.Title, body: row.description ?? row.Description, url: row.url ?? row.URL,
|
|
46
|
+
status: statusFor(row.canceledAt || row.Canceled ? 'canceled' : state?.name ?? state,
|
|
47
|
+
Boolean(row.completedAt || row.Completed || state?.type === 'completed')),
|
|
48
|
+
tags: row.Labels ? list(row.Labels) : asArray(row.labels).map(label),
|
|
49
|
+
project: label(row.project ?? row.Project ?? row['Project Milestone']),
|
|
50
|
+
assignee: person(row.assignee ?? row.Assignee),
|
|
51
|
+
parent: ref(row.parent ?? row['Parent issue']),
|
|
52
|
+
children: asArray(row.children).map(ref),
|
|
53
|
+
waits: [...asArray(row.blockedBy).map(ref), ...list(row['Blocked by'])],
|
|
54
|
+
comments: asArray(row.comments),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function jira(row) {
|
|
59
|
+
return {
|
|
60
|
+
key: ref(row['Issue key']), aliases: present([ref(row['Issue id'])]),
|
|
61
|
+
title: row.Summary, body: row.Description, url: row.URL ?? row['Issue URL'],
|
|
62
|
+
status: statusFor(row.Resolution || row.Status, /^done$|^resolved$|^closed$/i.test(row.Status ?? '')),
|
|
63
|
+
tags: list(row.Labels), project: row['Project name'] || row['Project key'],
|
|
64
|
+
assignee: row.Assignee,
|
|
65
|
+
parent: ref(row['Parent key'] || row.Parent || row['Epic Link']),
|
|
66
|
+
waits: Object.entries(row)
|
|
67
|
+
.filter(([name]) => /^(?:inward issue link \(blocks\)|blocked by)$/i.test(name))
|
|
68
|
+
.flatMap(([, value]) => list(value)),
|
|
69
|
+
comments: csvValues(row.Comment).map((comment) => {
|
|
70
|
+
const [createdAt, author, ...body] = comment.split(';');
|
|
71
|
+
return body.length ? { createdAt, author, body: body.join(';') } : { body: comment };
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const adapters = { github, linear, jira };
|
|
77
|
+
|
|
78
|
+
function readExport(source, path) {
|
|
79
|
+
try {
|
|
80
|
+
const data = readFileSync(path, 'utf8');
|
|
81
|
+
if (source === 'jira' || (source === 'linear' && extname(path).toLowerCase() === '.csv')) {
|
|
82
|
+
return parse(data, { bom: true, columns: true, group_columns_by_name: true, skip_empty_lines: true });
|
|
83
|
+
}
|
|
84
|
+
const value = JSON.parse(data);
|
|
85
|
+
const issues = value?.data?.issues ?? value?.issues ?? value;
|
|
86
|
+
const rows = Array.isArray(issues) ? issues : issues?.nodes;
|
|
87
|
+
if (!Array.isArray(rows)) throw new Error('expected an issue list');
|
|
88
|
+
return rows.filter((row) => source !== 'github' || !row?.pull_request);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
throw new Refusal(`cannot read ${source} export: ${error.message}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function originalUrl(source, issue, sourceUrl) {
|
|
95
|
+
const key = encodeURIComponent(issue.key);
|
|
96
|
+
const url = issue.url || (sourceUrl && ({
|
|
97
|
+
github: `${sourceUrl}/issues/${key}`,
|
|
98
|
+
linear: `${sourceUrl}/issue/${key}`,
|
|
99
|
+
jira: `${sourceUrl}/browse/${key}`,
|
|
100
|
+
})[source]);
|
|
101
|
+
if (!url) throw new Refusal(`${issue.key} has no URL in the export; pass --source-url`);
|
|
102
|
+
try {
|
|
103
|
+
const parsed = new URL(url);
|
|
104
|
+
if (!['https:', 'http:'].includes(parsed.protocol) || parsed.username || parsed.password) throw new Error();
|
|
105
|
+
return parsed.href;
|
|
106
|
+
} catch {
|
|
107
|
+
throw new Refusal(`${issue.key} has an invalid source URL`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function render(issue, meta, source, url) {
|
|
112
|
+
const comments = issue.comments.map((comment) => {
|
|
113
|
+
const rawDate = comment.createdAt ?? comment.created_at ?? '';
|
|
114
|
+
const date = /^\d{4}-\d{2}-\d{2}/.exec(rawDate)?.[0] ?? (rawDate || 'date unavailable');
|
|
115
|
+
const author = person(comment.author ?? comment.user);
|
|
116
|
+
return quote(`${date}${author ? ` · ${author}` : ''}\n\n${comment.body ?? ''}`);
|
|
117
|
+
});
|
|
118
|
+
return [
|
|
119
|
+
`---\n${frontmatterYaml(meta)}---`,
|
|
120
|
+
`**Imported from:** ${source} ${issue.key} — <${url}>`,
|
|
121
|
+
`**Depends on:** ${meta.depends_on.length ? meta.depends_on.join(', ') + '.' : 'none.'}`,
|
|
122
|
+
...(issue.body ? [`### Original description\n\n${quote(issue.body)}`] : []),
|
|
123
|
+
'## Status',
|
|
124
|
+
`_Imported ${today()}._`,
|
|
125
|
+
...comments,
|
|
126
|
+
].join('\n\n') + '\n';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function importTickets(root, source, path, sourceUrl) {
|
|
130
|
+
if (!Object.hasOwn(adapters, source)) throw new Refusal('import source must be github, linear, or jira');
|
|
131
|
+
const rows = readExport(source, path);
|
|
132
|
+
if (rows.some((row) => row === null || typeof row !== 'object' || Array.isArray(row))) {
|
|
133
|
+
throw new Refusal(`${source} export contains a malformed issue`);
|
|
134
|
+
}
|
|
135
|
+
const issues = rows.map(adapters[source]);
|
|
136
|
+
const { store, errors } = checkStore(root);
|
|
137
|
+
if (errors.length) throw new Refusal('fix the existing store with dibber check before importing');
|
|
138
|
+
const imported = new Set(store.tickets.flatMap(({ body }) =>
|
|
139
|
+
[...body.matchAll(/^\*\*Imported from:\*\* [^\n]* — <([^>\n]+)>$/gm)].map((match) => match[1])));
|
|
140
|
+
const refs = new Map();
|
|
141
|
+
for (const issue of issues) {
|
|
142
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(issue.key ?? '') || typeof issue.title !== 'string' || !issue.title.trim()) {
|
|
143
|
+
throw new Refusal(`${source} export contains an issue without a key or title`);
|
|
144
|
+
}
|
|
145
|
+
for (const key of new Set([issue.key, ...issue.aliases])) {
|
|
146
|
+
if (refs.has(key)) throw new Refusal(`the export repeats issue key ${key}`);
|
|
147
|
+
refs.set(key, issue);
|
|
148
|
+
}
|
|
149
|
+
issue.originalUrl = originalUrl(source, issue, sourceUrl?.replace(/\/+$/, ''));
|
|
150
|
+
if (imported.has(issue.originalUrl)) throw new Refusal(`${issue.key} was already imported`);
|
|
151
|
+
imported.add(issue.originalUrl);
|
|
152
|
+
}
|
|
153
|
+
const resolveRef = (key, issue) => {
|
|
154
|
+
const target = refs.get(key);
|
|
155
|
+
if (!target) throw new Refusal(`${issue.key} references ${key}, which is missing from the export`);
|
|
156
|
+
return target;
|
|
157
|
+
};
|
|
158
|
+
for (const issue of issues) {
|
|
159
|
+
for (const key of issue.children ?? []) {
|
|
160
|
+
const child = resolveRef(key, issue);
|
|
161
|
+
if (child.parent && resolveRef(child.parent, child) !== issue) {
|
|
162
|
+
throw new Refusal(`${child.key} has conflicting parents`);
|
|
163
|
+
}
|
|
164
|
+
child.parent = issue.key;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const issue of issues) {
|
|
168
|
+
issue.dependencies = present(issue.waits).map((key) => resolveRef(key, issue));
|
|
169
|
+
if (issue.parent) issue.parentIssue = resolveRef(issue.parent, issue);
|
|
170
|
+
}
|
|
171
|
+
const staged = { ...store, tickets: [...store.tickets] };
|
|
172
|
+
for (const issue of issues) {
|
|
173
|
+
issue.id = allocateTicketId(root, staged);
|
|
174
|
+
staged.tickets.push({ meta: { id: issue.id } });
|
|
175
|
+
}
|
|
176
|
+
const written = [];
|
|
177
|
+
try {
|
|
178
|
+
for (const issue of issues) {
|
|
179
|
+
const meta = {
|
|
180
|
+
id: issue.id, title: `${issue.id} — ${issue.title.trim()}`, status: issue.status,
|
|
181
|
+
depends_on: [...new Set(issue.dependencies.map((dep) => dep.id))],
|
|
182
|
+
...(issue.parentIssue && { parent: issue.parentIssue.id }),
|
|
183
|
+
...(issue.tags.some(Boolean) && { tags: [...new Set(issue.tags.filter(Boolean))] }),
|
|
184
|
+
...(issue.project && { project: issue.project }),
|
|
185
|
+
...(issue.assignee && { assignee: issue.assignee }),
|
|
186
|
+
};
|
|
187
|
+
const filename = join(store.storeDir, `${issue.id}.md`);
|
|
188
|
+
writeFileSync(filename, render(issue, meta, source, issue.originalUrl), { flag: 'wx' });
|
|
189
|
+
written.push({ id: issue.id, original: issue.key, file: rel(root, filename), filename });
|
|
190
|
+
}
|
|
191
|
+
const checked = checkStore(root);
|
|
192
|
+
if (checked.errors.length) {
|
|
193
|
+
throw new Refusal(checked.errors.map((error) => `${error.file}: ${error.message}`).join('\n'));
|
|
194
|
+
}
|
|
195
|
+
} catch (error) {
|
|
196
|
+
for (const { filename } of written) unlinkSync(filename);
|
|
197
|
+
throw new Refusal(`import failed: ${error.message}`);
|
|
198
|
+
}
|
|
199
|
+
return written.map(({ filename, ...entry }) => entry);
|
|
200
|
+
}
|
package/src/init.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
6
6
|
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync, appendFileSync, statSync, symlinkSync } from 'node:fs';
|
|
7
7
|
import { basename, dirname, join, relative } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
-
import { today } from './tickets.mjs';
|
|
9
|
+
import { Refusal, nextId, today } from './tickets.mjs';
|
|
10
10
|
import { readStore } from './store.mjs';
|
|
11
11
|
|
|
12
12
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -75,7 +75,7 @@ export function defaultPrefix(root) {
|
|
|
75
75
|
const words = basename(root).toUpperCase().split(/[^A-Z0-9]+/).filter(Boolean);
|
|
76
76
|
let p = words.length > 1 ? words.map((w) => w[0]).join('').slice(0, 4) : (words[0] ?? '').slice(0, 3);
|
|
77
77
|
p = p.replace(/^[0-9]+/, '');
|
|
78
|
-
return /^[A-
|
|
78
|
+
return /^[A-Za-z][A-Za-z0-9]*$/.test(p) ? p : 'T';
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export function skillNames() {
|
|
@@ -136,20 +136,23 @@ function writeOnce(path, content, report, overwrite = false) {
|
|
|
136
136
|
export function init(root, opts = {}) {
|
|
137
137
|
const report = { created: [], updated: [], skipped: [], repaired: [] };
|
|
138
138
|
const prefix = opts.prefix ?? defaultPrefix(root);
|
|
139
|
-
if (!/^[A-
|
|
139
|
+
if (!/^[A-Za-z][A-Za-z0-9]*$/.test(prefix)) throw new Error(`the prefix \`${prefix}\` must be letters and digits, starting with a letter (no dash)`);
|
|
140
140
|
const storeRel = opts.store ?? 'tickets';
|
|
141
|
+
if (opts.ids !== undefined && !['numeric', 'random'].includes(opts.ids)) throw new Refusal('--ids must be numeric or random');
|
|
141
142
|
|
|
142
143
|
const configPath = join(root, '.dibber', 'config.json');
|
|
143
|
-
|
|
144
|
+
const defaults = { store: storeRel, prefix, ...(opts.ids && { ids: opts.ids }) };
|
|
145
|
+
let config = defaults;
|
|
144
146
|
if (existsSync(configPath)) {
|
|
145
147
|
try { config = { ...config, ...JSON.parse(readFileSync(configPath, 'utf8')) }; } catch {}
|
|
146
148
|
}
|
|
147
|
-
writeOnce(configPath, JSON.stringify(
|
|
149
|
+
writeOnce(configPath, JSON.stringify(defaults, null, 2) + '\n', report);
|
|
148
150
|
|
|
149
151
|
const store = join(root, config.store);
|
|
150
152
|
mkdirSync(store, { recursive: true });
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
const current = readStore(root);
|
|
154
|
+
if (current.tickets.length === 0) {
|
|
155
|
+
const id = nextId(root, current);
|
|
153
156
|
const sample = readFileSync(join(TEMPLATES, 'first-ticket.md'), 'utf8')
|
|
154
157
|
.replaceAll('{{ID}}', id)
|
|
155
158
|
.replaceAll('{{DATE}}', today())
|
|
@@ -204,5 +207,5 @@ export function init(root, opts = {}) {
|
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
const relp = (p) => p.slice(root.length + 1).split('\\').join('/');
|
|
207
|
-
return { created: report.created.map(relp), updated: report.updated.map(relp), skipped: report.skipped.map(relp), repaired: report.repaired.map(relp), prefix: config.prefix, store: config.store, repo };
|
|
210
|
+
return { created: report.created.map(relp), updated: report.updated.map(relp), skipped: report.skipped.map(relp), repaired: report.repaired.map(relp), prefix: config.prefix, ids: config.ids, store: config.store, repo };
|
|
208
211
|
}
|
package/src/intake.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// File outside GitHub reports without treating their text as work instructions ([DIB-10](../tickets/DIB-10.md)).
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { readStore } from './store.mjs';
|
|
4
|
+
import { newTicket, Refusal } from './tickets.mjs';
|
|
5
|
+
|
|
6
|
+
export function intakeGitHub(root, path) {
|
|
7
|
+
let issue;
|
|
8
|
+
try {
|
|
9
|
+
issue = JSON.parse(readFileSync(path, 'utf8'));
|
|
10
|
+
} catch (error) {
|
|
11
|
+
throw new Refusal(`cannot read GitHub issue JSON: ${error.message}`);
|
|
12
|
+
}
|
|
13
|
+
const url = issue?.html_url ?? issue?.url ?? '';
|
|
14
|
+
const match = /^https:\/\/github\.com\/[A-Za-z0-9-]+\/[A-Za-z0-9_.-]+\/issues\/(\d+)$/.exec(url);
|
|
15
|
+
const author = issue?.author?.login ?? issue?.user?.login ?? '';
|
|
16
|
+
if (!match || !/^[A-Za-z0-9-]+(?:\[bot\])?$/.test(author) || typeof issue.title !== 'string'
|
|
17
|
+
|| (issue.body != null && typeof issue.body !== 'string')) {
|
|
18
|
+
throw new Refusal('expected one GitHub issue with a canonical URL, reporter login, title and body');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const signature = `**Brief:** GitHub issue [#${match[1]}](${url}), filed by outside reporter @${author}.`;
|
|
22
|
+
const existing = readStore(root).tickets.find((ticket) =>
|
|
23
|
+
ticket.body.trimStart().startsWith(signature + '\n'));
|
|
24
|
+
if (existing) return { id: existing.meta.id, file: existing.file, existing: true };
|
|
25
|
+
|
|
26
|
+
const report = `${issue.title}\n\n${issue.body ?? ''}`
|
|
27
|
+
.replace(/\r\n?/g, '\n').split('\n').map((line) => `> ${line}`).join('\n');
|
|
28
|
+
return newTicket(root, {
|
|
29
|
+
title: `Triage GitHub issue #${match[1]}`,
|
|
30
|
+
body: [
|
|
31
|
+
signature,
|
|
32
|
+
'**Depends on:** none.',
|
|
33
|
+
'### Reported',
|
|
34
|
+
report,
|
|
35
|
+
'### What to build',
|
|
36
|
+
'Confirm the report and decide what follow-up work is needed.',
|
|
37
|
+
'### Exit criteria',
|
|
38
|
+
'- [ ] Record the triage decision and link any follow-up ticket.',
|
|
39
|
+
].join('\n\n'),
|
|
40
|
+
});
|
|
41
|
+
}
|
package/src/migrate.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Upgrade a store in place while preserving ticket paths and bodies ([DIB-27](../tickets/DIB-27.md)).
|
|
2
|
+
import { writeFileSync } from 'node:fs';
|
|
3
|
+
import { checkStore, legacyPageKind, TICKET_SCHEMA } from './check.mjs';
|
|
4
|
+
import { splitFrontmatter, readStore, LIVE, COORDINATED, hasCoordinator } from './store.mjs';
|
|
5
|
+
import { Refusal } from './tickets.mjs';
|
|
6
|
+
|
|
7
|
+
// Only the status line changes, so a large store's migration reads as one line a ticket.
|
|
8
|
+
function toOrchestrator(store) {
|
|
9
|
+
if (!hasCoordinator(store.settings)) throw new Refusal('--to-orchestrator needs a `coordinator` in .dibber/config.json');
|
|
10
|
+
return store.tickets.filter((t) => LIVE.includes(t.meta.status)).map((entry) => {
|
|
11
|
+
const { body, raw, doc } = splitFrontmatter(entry.text);
|
|
12
|
+
const line = raw.replace(/^status:[^\r\n]*/m, `status: ${COORDINATED}`);
|
|
13
|
+
let text = entry.text.replace(raw, () => line);
|
|
14
|
+
const again = splitFrontmatter(text);
|
|
15
|
+
if (again?.meta?.status !== COORDINATED || JSON.stringify({ ...again.meta, status: 0 }) !== JSON.stringify({ ...entry.meta, status: 0 }) || again.body !== body) {
|
|
16
|
+
doc.set('status', COORDINATED);
|
|
17
|
+
text = `---\n${doc.toString({ lineWidth: 0, flowCollectionPadding: false })}---\n${body}`;
|
|
18
|
+
}
|
|
19
|
+
return { entry, text };
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function migrateStore(root, opts = {}) {
|
|
24
|
+
const store = readStore(root);
|
|
25
|
+
if (!store.exists) throw new Refusal(`there is no store at ${store.storeRel}/`);
|
|
26
|
+
const updates = opts.toOrchestrator ? toOrchestrator(store) : [];
|
|
27
|
+
|
|
28
|
+
if (!opts.toOrchestrator) for (const entry of [...store.pages, ...store.tickets]) {
|
|
29
|
+
const { doc, body, meta } = splitFrontmatter(entry.text);
|
|
30
|
+
const kind = legacyPageKind(meta);
|
|
31
|
+
if (kind !== undefined) {
|
|
32
|
+
doc.set('page', kind);
|
|
33
|
+
doc.delete('kind');
|
|
34
|
+
} else if (meta.id !== undefined && meta.status !== undefined && meta.page === undefined) {
|
|
35
|
+
if (!Object.hasOwn(meta, 'type') || TICKET_SCHEMA.properties.type.enum.includes(meta.type)) continue;
|
|
36
|
+
if (Object.hasOwn(meta, 'legacy_type')) {
|
|
37
|
+
throw new Refusal(`${entry.file} already has legacy_type; resolve the two values before migrating`);
|
|
38
|
+
}
|
|
39
|
+
doc.set('legacy_type', doc.get('type', true));
|
|
40
|
+
doc.delete('type');
|
|
41
|
+
} else continue;
|
|
42
|
+
updates.push({ entry, text: `---\n${doc.toString({ lineWidth: 0 })}---\n${body}` });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!updates.length) return [];
|
|
46
|
+
const written = [];
|
|
47
|
+
try {
|
|
48
|
+
for (const { entry, text } of updates) {
|
|
49
|
+
written.push(entry);
|
|
50
|
+
writeFileSync(entry.path, text);
|
|
51
|
+
}
|
|
52
|
+
const { errors } = checkStore(root);
|
|
53
|
+
if (errors.length) {
|
|
54
|
+
throw new Refusal(errors.map(({ file, message }) => `${file}: ${message}`).join('\n'));
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
for (const entry of written) writeFileSync(entry.path, entry.text);
|
|
58
|
+
throw new Refusal(`migration failed: ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
return updates.map(({ entry }) => entry.file);
|
|
61
|
+
}
|
package/src/store.mjs
CHANGED
|
@@ -8,13 +8,15 @@ import { parseDocument } from 'yaml';
|
|
|
8
8
|
|
|
9
9
|
/** The statuses of R-DIB-6, by class. */
|
|
10
10
|
export const LIVE = ['available', 'in-progress', 'in-review', 'deprioritized'];
|
|
11
|
+
/** Live, with its progress in the coordinator's record (R-DIB-6, [DIB-35](../tickets/DIB-35.md)). */
|
|
12
|
+
export const COORDINATED = 'orchestrator';
|
|
11
13
|
export const CLOSED_DONE = ['done'];
|
|
12
14
|
export const CLOSED_WITHDRAWN = ['withdrawn', 'superseded', 'deferred'];
|
|
13
15
|
export const CLOSED = [...CLOSED_DONE, ...CLOSED_WITHDRAWN];
|
|
14
|
-
export const STATUSES = [...LIVE, ...CLOSED];
|
|
16
|
+
export const STATUSES = [...LIVE, COORDINATED, ...CLOSED];
|
|
15
17
|
|
|
16
|
-
export const ID_RE = /^[A-Z][A-Z0-9]*-[0-9]+[a-z0-9]
|
|
17
|
-
export const QUALIFIED_RE = /^([a-z0-9][a-z0-9._-]*):([A-Z][A-Z0-9]*-[0-9]+[a-z0-9]*)$/;
|
|
18
|
+
export const ID_RE = /^(?:[A-Za-z][A-Za-z0-9]*-(?:[0-9]+|[a-z0-9]{4,})|[A-Z][A-Z0-9]*-[0-9]+[a-z0-9]*)$/;
|
|
19
|
+
export const QUALIFIED_RE = /^([a-z0-9][a-z0-9._-]*):((?:[A-Za-z][A-Za-z0-9]*-(?:[0-9]+|[a-z0-9]{4,})|[A-Z][A-Z0-9]*-[0-9]+[a-z0-9]*))$/;
|
|
18
20
|
|
|
19
21
|
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(\r?\n|$)/;
|
|
20
22
|
|
|
@@ -53,6 +55,9 @@ export function readSettings(root) {
|
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
/** The settings name a coordinator (R-DIB-14). */
|
|
59
|
+
export const hasCoordinator = (settings) => typeof settings.raw?.coordinator === 'object' && settings.raw.coordinator !== null && !Array.isArray(settings.raw.coordinator);
|
|
60
|
+
|
|
56
61
|
function walk(dir, out = []) {
|
|
57
62
|
for (const name of readdirSync(dir).sort()) {
|
|
58
63
|
if (name === 'node_modules' || name === '.git') continue;
|
|
@@ -66,7 +71,7 @@ function walk(dir, out = []) {
|
|
|
66
71
|
|
|
67
72
|
/**
|
|
68
73
|
* Read every Markdown file under the store. A file is a ticket when its frontmatter carries an
|
|
69
|
-
* `id` and
|
|
74
|
+
* `id` and `status` without a `page` marker (R-DIB-1); a file whose frontmatter does not parse is
|
|
70
75
|
* reported as `broken`, since it cannot be told apart.
|
|
71
76
|
*/
|
|
72
77
|
export function readStore(root) {
|
|
@@ -84,7 +89,7 @@ export function readStore(root) {
|
|
|
84
89
|
continue;
|
|
85
90
|
}
|
|
86
91
|
const { meta } = parts;
|
|
87
|
-
const isTicket = meta.id !== undefined &&
|
|
92
|
+
const isTicket = meta.id !== undefined && meta.status !== undefined && meta.page === undefined;
|
|
88
93
|
const closed = CLOSED.includes(meta.status); // closure is the status alone (R-DIB-2)
|
|
89
94
|
const entry = { path, file, closed, meta, body: parts.body, text, ext: extname(path), name: basename(path, extname(path)) };
|
|
90
95
|
(isTicket ? result.tickets : result.pages).push(entry);
|
|
@@ -95,7 +100,7 @@ export function readStore(root) {
|
|
|
95
100
|
/** Numeric part of an id, for ordering (`X-10` after `X-9`). */
|
|
96
101
|
export function idNumber(id) {
|
|
97
102
|
const m = /-(\d+)/.exec(String(id));
|
|
98
|
-
return m ? Number(m[1]) :
|
|
103
|
+
return m ? Number(m[1]) : Infinity;
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
export function byOrderThenId(a, b) {
|