requirementbot 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +197 -2
- package/bin/requirementbot.js +21 -0
- package/package.json +53 -4
- package/prompts/README.md +18 -0
- package/prompts/check.md +15 -0
- package/prompts/fix.md +4 -0
- package/prompts/from-code.md +12 -0
- package/prompts/from-docs.md +11 -0
- package/prompts/from-issues.md +14 -0
- package/prompts/mdq.md +8 -0
- package/prompts/partials/non-interactive.md +1 -0
- package/prompts/partials/subagents.md +1 -0
- package/prompts/report.md +8 -0
- package/prompts/system.md +9 -0
- package/skills/SOURCE.md +14 -0
- package/skills/catalog-features/SKILL.md +168 -0
- package/skills/catalog-features/references/layout.md +87 -0
- package/skills/detect-product-mismatches/SKILL.md +147 -0
- package/skills/detect-product-mismatches/references/features.md +84 -0
- package/skills/detect-product-mismatches/references/layout.md +99 -0
- package/skills/pull-request-diff-analyzer/SKILL.md +141 -0
- package/skills/qa-explain-behavior/SKILL.md +112 -0
- package/skills/qa-explain-behavior/references/answer-shapes.md +116 -0
- package/skills/qa-explain-behavior/references/examples.md +157 -0
- package/skills/qa-pr-requirements-analyzer/SKILL.md +149 -0
- package/skills/qa-pr-requirements-analyzer/references/summary-example.md +54 -0
- package/skills/qa-requirement-reviewer/SKILL.md +126 -0
- package/skills/qa-requirement-reviewer/references/requirements_reviewer_examples.md +128 -0
- package/skills/qa-thinking/SKILL.md +46 -0
- package/skills/requirements-from-code/SKILL.md +114 -0
- package/skills/requirements-from-code/references/behaviors.md +42 -0
- package/skills/requirements-from-code/references/layout.md +100 -0
- package/skills/requirements-from-expected/SKILL.md +116 -0
- package/skills/requirements-from-expected/references/behaviors.md +49 -0
- package/skills/requirements-from-expected/references/layout.md +74 -0
- package/skills/requirements-from-expected/references/merge.md +34 -0
- package/skills/write-user-story/SKILL.md +42 -0
- package/src/agent/agent.js +278 -0
- package/src/agent/auth.js +209 -0
- package/src/agent/prompt.js +36 -0
- package/src/branding.js +27 -0
- package/src/cli.js +26 -0
- package/src/commands/agent-command.js +61 -0
- package/src/commands/check.js +26 -0
- package/src/commands/command.js +40 -0
- package/src/commands/connect.js +33 -0
- package/src/commands/disconnect.js +18 -0
- package/src/commands/generate-from-code.js +20 -0
- package/src/commands/generate-from-docs.js +38 -0
- package/src/commands/generate-from-issues.js +41 -0
- package/src/commands/index.js +40 -0
- package/src/commands/login.js +44 -0
- package/src/commands/logout.js +17 -0
- package/src/commands/models.js +11 -0
- package/src/commands/pull.js +15 -0
- package/src/commands/push.js +29 -0
- package/src/commands/query.js +31 -0
- package/src/commands/report.js +23 -0
- package/src/commands/skills.js +20 -0
- package/src/commands/sources.js +16 -0
- package/src/commands/update-from-code.js +7 -0
- package/src/commands/update-from-docs.js +7 -0
- package/src/commands/update-from-issues.js +7 -0
- package/src/config.js +90 -0
- package/src/files.js +25 -0
- package/src/github.js +50 -0
- package/src/http.js +19 -0
- package/src/requirements.js +139 -0
- package/src/sources/adf.js +48 -0
- package/src/sources/github.js +81 -0
- package/src/sources/index.js +41 -0
- package/src/sources/jira.js +135 -0
- package/src/sources/pages.js +67 -0
- package/src/sources/source.js +60 -0
- package/src/transports/confluence.js +114 -0
- package/src/transports/git.js +90 -0
- package/src/transports/github.js +42 -0
- package/src/transports/index.js +36 -0
- package/src/transports/notion.js +108 -0
- package/src/transports/page-tree.js +119 -0
- package/src/transports/transport.js +41 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Client } from '@notionhq/client';
|
|
2
|
+
import { markdownToBlocks } from '@tryfabric/martian';
|
|
3
|
+
import { NotionToMarkdown } from 'notion-to-md';
|
|
4
|
+
import { log, muted } from '../branding.js';
|
|
5
|
+
import { requireEnv } from '../config.js';
|
|
6
|
+
import { PageIds, PageTree } from './page-tree.js';
|
|
7
|
+
import { Transport } from './transport.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `notion:<page id or URL>` — mirrors the folder as nested pages under the parent page. Needs NOTION_TOKEN.
|
|
11
|
+
*/
|
|
12
|
+
export class NotionTransport extends Transport {
|
|
13
|
+
static kind = 'notion';
|
|
14
|
+
static usage = 'notion:<page id or URL>';
|
|
15
|
+
|
|
16
|
+
constructor(target) {
|
|
17
|
+
super(target);
|
|
18
|
+
const hex = String(target).replace(/-/g, '').match(/([0-9a-f]{32})(?:\?.*)?$/i);
|
|
19
|
+
if (!hex) throw new Error(`Use ${NotionTransport.usage}`);
|
|
20
|
+
this.pageId = hex[1].toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get client() {
|
|
24
|
+
this._client ||= new Client({ auth: requireEnv('NOTION_TOKEN')[0] });
|
|
25
|
+
return this._client;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async push(dir, { dryRun }) {
|
|
29
|
+
const tree = PageTree.read(dir);
|
|
30
|
+
const pages = tree.pages();
|
|
31
|
+
const ids = new PageIds('notion', this.pageId);
|
|
32
|
+
if (dryRun) {
|
|
33
|
+
for (const p of pages) process.stderr.write(` ${ids.get(p.path) ? 'update' : 'create'} ${muted(p.title)} ← ${p.path}\n`);
|
|
34
|
+
return log(`Dry run: ${pages.length} page(s) under ${this.pageId}`);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await this.upsert(tree, this.pageId, ids);
|
|
38
|
+
} finally {
|
|
39
|
+
ids.save();
|
|
40
|
+
}
|
|
41
|
+
const rootId = ids.get(tree.path).replace(/-/g, '');
|
|
42
|
+
log(`Pushed ${pages.length} page(s) to https://www.notion.so/${rootId}`);
|
|
43
|
+
log(`Requirements page id: ${rootId}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async upsert(node, parentId, ids) {
|
|
47
|
+
const blocks = markdownToBlocks(node.body);
|
|
48
|
+
let id = ids.get(node.path);
|
|
49
|
+
const existing = id ? await this.client.pages.retrieve({ page_id: id }).catch(() => undefined) : undefined;
|
|
50
|
+
if (existing && !existing.archived && !existing.in_trash) {
|
|
51
|
+
await this.client.pages.update({ page_id: id, properties: this.titleProperty(node.title) });
|
|
52
|
+
for (const block of await this.children(id)) {
|
|
53
|
+
if (block.type !== 'child_page' && block.type !== 'child_database') await this.client.blocks.delete({ block_id: block.id });
|
|
54
|
+
}
|
|
55
|
+
await this.append(id, blocks);
|
|
56
|
+
process.stderr.write(` updated ${muted(node.title)}\n`);
|
|
57
|
+
} else {
|
|
58
|
+
id = (await this.client.pages.create({ parent: { page_id: parentId }, properties: this.titleProperty(node.title), children: blocks.slice(0, 100) })).id;
|
|
59
|
+
ids.set(node.path, id);
|
|
60
|
+
await this.append(id, blocks.slice(100));
|
|
61
|
+
process.stderr.write(` created ${muted(node.title)}\n`);
|
|
62
|
+
}
|
|
63
|
+
for (const child of node.children) await this.upsert(child, id, ids);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async pull(dir, { dryRun }) {
|
|
67
|
+
const converter = new NotionToMarkdown({ notionClient: this.client });
|
|
68
|
+
converter.setCustomTransformer('child_page', () => '');
|
|
69
|
+
converter.setCustomTransformer('child_database', () => '');
|
|
70
|
+
const page = await this.client.pages.retrieve({ page_id: this.pageId });
|
|
71
|
+
const title = Object.values(page.properties || {}).find((p) => p.type === 'title')?.title?.map((t) => t.plain_text).join('');
|
|
72
|
+
const tree = await this.download(converter, this.pageId, title || 'Requirements');
|
|
73
|
+
const count = tree.pages().length;
|
|
74
|
+
if (dryRun) return log(`Dry run: would write ${count} page(s) into ${dir}`);
|
|
75
|
+
tree.write(dir);
|
|
76
|
+
log(`Pulled ${count} page(s) into ${dir}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async download(converter, id, title) {
|
|
80
|
+
const body = converter.toMarkdownString(await converter.pageToMarkdown(id)).parent || '';
|
|
81
|
+
const node = new PageTree({ path: '', title, body });
|
|
82
|
+
for (const block of await this.children(id)) {
|
|
83
|
+
if (block.type === 'child_page') node.children.push(await this.download(converter, block.id, block.child_page.title));
|
|
84
|
+
}
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async children(blockId) {
|
|
89
|
+
const blocks = [];
|
|
90
|
+
let cursor;
|
|
91
|
+
do {
|
|
92
|
+
const page = await this.client.blocks.children.list({ block_id: blockId, start_cursor: cursor, page_size: 100 });
|
|
93
|
+
blocks.push(...page.results);
|
|
94
|
+
cursor = page.has_more ? page.next_cursor : undefined;
|
|
95
|
+
} while (cursor);
|
|
96
|
+
return blocks;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async append(blockId, blocks) {
|
|
100
|
+
for (let i = 0; i < blocks.length; i += 100) {
|
|
101
|
+
await this.client.blocks.children.append({ block_id: blockId, children: blocks.slice(i, i + 100) });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
titleProperty(title) {
|
|
106
|
+
return { title: { title: [{ type: 'text', text: { content: title.slice(0, 2000) } }] } };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join, posix } from 'node:path';
|
|
3
|
+
import matter from 'gray-matter';
|
|
4
|
+
import { Config } from '../config.js';
|
|
5
|
+
import { slugify } from '../files.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A markdown folder seen as a tree of pages, for wiki destinations (Confluence, Notion).
|
|
9
|
+
* Folders are pages whose body is their README.md; other `.md` files are child pages.
|
|
10
|
+
* `path` is relative to the root folder with `/`, e.g. `features/checkout/README.md`.
|
|
11
|
+
*/
|
|
12
|
+
export class PageTree {
|
|
13
|
+
/** @param {{ path: string, title: string, body: string, children?: PageTree[] }} page */
|
|
14
|
+
constructor({ path, title, body, children = [] }) {
|
|
15
|
+
this.path = path;
|
|
16
|
+
this.title = title;
|
|
17
|
+
this.body = body;
|
|
18
|
+
this.children = children;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static read(dir, rel = '') {
|
|
22
|
+
const readme = join(dir, 'README.md');
|
|
23
|
+
const { title, body } = existsSync(readme) ? PageTree.splitTitle(readFileSync(readme, 'utf8')) : { body: '' };
|
|
24
|
+
const node = new PageTree({ path: posix.join(rel, 'README.md'), title: title || PageTree.humanize(basename(dir)), body });
|
|
25
|
+
const entries = readdirSync(dir, { withFileTypes: true })
|
|
26
|
+
.filter((e) => !e.name.startsWith('.'))
|
|
27
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const path = join(dir, entry.name);
|
|
30
|
+
if (entry.isDirectory()) {
|
|
31
|
+
node.children.push(PageTree.read(path, posix.join(rel, entry.name)));
|
|
32
|
+
} else if (entry.name.endsWith('.md') && entry.name !== 'README.md') {
|
|
33
|
+
const page = PageTree.splitTitle(readFileSync(path, 'utf8'));
|
|
34
|
+
node.children.push(new PageTree({ path: posix.join(rel, entry.name), title: page.title || PageTree.humanize(entry.name.replace(/\.md$/, '')), body: page.body }));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Write the tree as markdown: pages with children become folders with a README.md. */
|
|
41
|
+
write(dir) {
|
|
42
|
+
mkdirSync(dir, { recursive: true });
|
|
43
|
+
writeFileSync(join(dir, 'README.md'), this.markdown());
|
|
44
|
+
const used = new Set(['readme']);
|
|
45
|
+
for (const child of this.children) {
|
|
46
|
+
let name = slugify(child.title);
|
|
47
|
+
while (used.has(name)) name = `${name}-1`;
|
|
48
|
+
used.add(name);
|
|
49
|
+
if (child.children.length) child.write(join(dir, name));
|
|
50
|
+
else writeFileSync(join(dir, `${name}.md`), child.markdown());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
markdown() {
|
|
55
|
+
return `# ${this.title}\n\n${this.body.trim()}\n`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @returns {PageTree[]} this page and all descendants */
|
|
59
|
+
pages() {
|
|
60
|
+
return [this, ...this.children.flatMap((child) => child.pages())];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Make titles unique across the tree (Confluence requires unique titles per space). */
|
|
64
|
+
uniqueTitles(prefix = '') {
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
const walk = (node, parent) => {
|
|
67
|
+
let title = `${prefix}${node.title}`;
|
|
68
|
+
if (seen.has(title)) title = `${title} (${parent?.title || node.path})`;
|
|
69
|
+
seen.add(title);
|
|
70
|
+
node.title = title;
|
|
71
|
+
node.children.forEach((child) => walk(child, node));
|
|
72
|
+
};
|
|
73
|
+
walk(this);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Resolve a relative markdown link from the page at `fromPath` to a page path in the tree. */
|
|
78
|
+
static resolveLink(fromPath, href) {
|
|
79
|
+
const [file] = href.split('#');
|
|
80
|
+
const target = posix.normalize(posix.join(posix.dirname(fromPath), file));
|
|
81
|
+
return target.endsWith('/') || !target.endsWith('.md') ? posix.join(target, 'README.md') : target;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Split the first `# Title` from the body and drop front matter. */
|
|
85
|
+
static splitTitle(source) {
|
|
86
|
+
const { content } = matter(source);
|
|
87
|
+
const match = content.match(/^\s*#\s+(.+?)\s*#*\s*$/m);
|
|
88
|
+
if (!match || content.slice(0, match.index).trim()) return { title: undefined, body: content.trim() };
|
|
89
|
+
return { title: match[1].trim(), body: content.slice(match.index + match[0].length).trim() };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static humanize(name) {
|
|
93
|
+
const text = name.replace(/[-_]+/g, ' ').trim();
|
|
94
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Remote page ids per destination, kept in `.requirementbot/<kind>-pages.json` so pushes update the same pages. */
|
|
99
|
+
export class PageIds {
|
|
100
|
+
constructor(kind, key, cwd = process.cwd()) {
|
|
101
|
+
this.path = join(cwd, Config.DIR_NAME, `${kind}-pages.json`);
|
|
102
|
+
this.key = key;
|
|
103
|
+
this.all = existsSync(this.path) ? JSON.parse(readFileSync(this.path, 'utf8')) : {};
|
|
104
|
+
this.ids = { ...this.all[key] };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get(path) {
|
|
108
|
+
return this.ids[path];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
set(path, id) {
|
|
112
|
+
this.ids[path] = id;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
save() {
|
|
116
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
117
|
+
writeFileSync(this.path, `${JSON.stringify({ ...this.all, [this.key]: this.ids }, null, 2)}\n`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A place requirements are pushed to and pulled from. Subclasses set `kind`, parse their target
|
|
3
|
+
* in the constructor, and implement `push` and `pull` over a local requirements folder.
|
|
4
|
+
*/
|
|
5
|
+
export class Transport {
|
|
6
|
+
/** @type {string} */
|
|
7
|
+
static kind;
|
|
8
|
+
/** Target syntax shown in help and errors. */
|
|
9
|
+
static usage = '';
|
|
10
|
+
|
|
11
|
+
/** @param {string} target everything after `<kind>:` */
|
|
12
|
+
constructor(target) {
|
|
13
|
+
this.target = target;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get kind() {
|
|
17
|
+
return this.constructor.kind;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toString() {
|
|
21
|
+
return `${this.kind}:${this.target}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Send the local folder to the destination.
|
|
26
|
+
* @param {string} dir
|
|
27
|
+
* @param {{ dryRun?: boolean, [key: string]: any }} options
|
|
28
|
+
*/
|
|
29
|
+
async push(dir, options) {
|
|
30
|
+
throw new Error(`${this.kind} does not support push`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Replace the local folder with the destination's content.
|
|
35
|
+
* @param {string} dir
|
|
36
|
+
* @param {{ dryRun?: boolean, [key: string]: any }} options
|
|
37
|
+
*/
|
|
38
|
+
async pull(dir, options) {
|
|
39
|
+
throw new Error(`${this.kind} does not support pull`);
|
|
40
|
+
}
|
|
41
|
+
}
|