@ferronhooi/aihub 0.1.0-next.2 → 0.1.0-next.4

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.
Files changed (54) hide show
  1. package/dist/commands/doctor.js +21 -0
  2. package/dist/commands/fabric.js +71 -0
  3. package/dist/commands/init.js +18 -0
  4. package/dist/commands/robot.js +53 -0
  5. package/dist/commands/skills.js +44 -0
  6. package/dist/lib/changes.js +14 -0
  7. package/dist/lib/clients.js +26 -0
  8. package/dist/lib/doctor.js +118 -0
  9. package/dist/lib/fabric.js +232 -0
  10. package/dist/lib/glob.js +28 -0
  11. package/dist/lib/init.js +157 -0
  12. package/dist/lib/install.js +141 -0
  13. package/dist/lib/pack.js +48 -0
  14. package/dist/lib/robot.js +88 -0
  15. package/dist/lib/schema.js +56 -0
  16. package/dist/router.js +12 -1
  17. package/dist/tools/lintSkills.js +1 -0
  18. package/pack/commands/copilot/cherry-pick.prompt.md +6 -0
  19. package/pack/commands/copilot/pr-update.prompt.md +6 -0
  20. package/pack/commands/copilot/pr.prompt.md +6 -0
  21. package/pack/commands/copilot/refine.prompt.md +6 -0
  22. package/pack/commands/copilot/review.prompt.md +6 -0
  23. package/pack/commands/copilot/story.prompt.md +6 -0
  24. package/pack/commands/copilot/test.prompt.md +6 -0
  25. package/pack/commands/copilot/watch.prompt.md +6 -0
  26. package/pack/commands/opencode/cherry-pick.md +5 -0
  27. package/pack/commands/opencode/pr-update.md +5 -0
  28. package/pack/commands/opencode/pr.md +5 -0
  29. package/pack/commands/opencode/refine.md +5 -0
  30. package/pack/commands/opencode/review.md +5 -0
  31. package/pack/commands/opencode/story.md +5 -0
  32. package/pack/commands/opencode/test.md +5 -0
  33. package/pack/commands/opencode/watch.md +5 -0
  34. package/pack/skills/_shared/assets/commit-template.nl.txt +5 -0
  35. package/pack/skills/_shared/assets/commit-template.txt +5 -0
  36. package/pack/skills/_shared/assets/pull_request_template.md +16 -0
  37. package/pack/skills/_shared/assets/pull_request_template.nl.md +16 -0
  38. package/pack/skills/_shared/assets/story-template.md +12 -0
  39. package/pack/skills/_shared/assets/story-template.nl.md +12 -0
  40. package/pack/skills/_shared/references/team.schema.yaml +56 -0
  41. package/pack/skills/branch-sync/SKILL.md +31 -0
  42. package/pack/skills/implement/SKILL.md +25 -0
  43. package/pack/skills/pipeline-fix/SKILL.md +29 -0
  44. package/pack/skills/pr-create/SKILL.md +29 -0
  45. package/pack/skills/pr-update/SKILL.md +28 -0
  46. package/pack/skills/pr-watch/SKILL.md +30 -0
  47. package/pack/skills/release/SKILL.md +35 -0
  48. package/pack/skills/review-process/SKILL.md +35 -0
  49. package/pack/skills/start-here/SKILL.md +36 -0
  50. package/pack/skills/story-create/SKILL.md +28 -0
  51. package/pack/skills/story-refine/SKILL.md +28 -0
  52. package/pack/skills/test-run/SKILL.md +35 -0
  53. package/pack/skills/test-run/references/fabric-robot.md +23 -0
  54. package/package.json +4 -3
@@ -0,0 +1,157 @@
1
+ import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { stringify } from "yaml";
5
+ import { parseRemote } from "./ado.js";
6
+ import { AihubError } from "./errors.js";
7
+ import { git, hasRef, originDefaultBranch, pushIfNeeded, remoteUrl, repoRoot, showFile } from "./git.js";
8
+ import { listFiles, packRoot, readPackFile } from "./pack.js";
9
+ import { createPr } from "./pr.js";
10
+ import { TEAM_FILE } from "./team.js";
11
+ import { resolveTemplate } from "./templates.js";
12
+ export const PACK_BRANCH = "chore/aihub-team-pack";
13
+ export const STORY_TEMPLATE = ".agents/skills/_shared/assets/story-template.md";
14
+ export const COMMIT_TEMPLATE = ".agents/skills/_shared/assets/commit-template.txt";
15
+ export const PR_TEMPLATE = ".azuredevops/pull_request_template.md";
16
+ export function parseLanguage(v) {
17
+ if (!v)
18
+ return "en";
19
+ if (v === "nl" || v === "en")
20
+ return v;
21
+ throw new AihubError(`--language must be nl or en, not '${v}'`);
22
+ }
23
+ function teamYaml(o) {
24
+ const data = {
25
+ version: 1,
26
+ language: o.language,
27
+ azureDevOps: { organization: o.org, project: o.project },
28
+ repositories: [{ name: o.repo, defaultTarget: o.target, releaseBranches: ["release/*"] }],
29
+ pullRequest: {
30
+ template: o.prTemplate,
31
+ title: "{storyId}: {storyTitle}",
32
+ emptySection: o.language === "nl" ? "n.v.t." : "-",
33
+ },
34
+ workItems: { storyType: "User Story", storyTemplate: STORY_TEMPLATE },
35
+ branches: { feature: "feature/{storyId}-{slug}", protected: [o.target, "release/*"] },
36
+ };
37
+ const head = "# Team file proposed by 'aihub init': check every value and change it through a pull request.\n" +
38
+ "# Schema: skills/_shared/references/team.schema.yaml in the aihub pack; see docs/team-yaml.md.\n";
39
+ return head + stringify(data, { lineWidth: 0 });
40
+ }
41
+ /** Where Azure DevOps already finds a PR template for the target branch, or undefined. */
42
+ export function existingPrTemplate(root, target) {
43
+ return resolveTemplate(target, { readRef: (b, p) => showFile(root, b, p), localRoot: root })?.path;
44
+ }
45
+ /** Everything `aihub init` would like to have in the repository (before skipping what exists). */
46
+ export function planFiles(root, o) {
47
+ const pack = packRoot();
48
+ const assets = join(pack, "skills", "_shared", "assets");
49
+ const nl = o.language === "nl";
50
+ const asset = (name, nlName) => readPackFile(join(assets, nl ? nlName : name));
51
+ const found = existingPrTemplate(root, o.target);
52
+ const plan = [
53
+ { path: TEAM_FILE, content: teamYaml({ ...o, prTemplate: found && !found.includes("/branches/") ? found : PR_TEMPLATE }) },
54
+ { path: STORY_TEMPLATE, content: asset("story-template.md", "story-template.nl.md") },
55
+ { path: COMMIT_TEMPLATE, content: asset("commit-template.txt", "commit-template.nl.txt") },
56
+ ];
57
+ if (!found)
58
+ plan.push({ path: PR_TEMPLATE, content: asset("pull_request_template.md", "pull_request_template.nl.md") });
59
+ for (const f of listFiles(join(pack, "commands", "opencode"))) {
60
+ plan.push({ path: `.opencode/command/${f}`, content: readPackFile(join(pack, "commands", "opencode", f)) });
61
+ }
62
+ for (const f of listFiles(join(pack, "commands", "copilot"))) {
63
+ plan.push({ path: `.github/prompts/${f}`, content: readPackFile(join(pack, "commands", "copilot", f)) });
64
+ }
65
+ return { plan, skips: found ? { [PR_TEMPLATE]: `a pull request template already exists (${found})` } : {} };
66
+ }
67
+ /** Write planned files that do not exist yet; never touches an existing file. */
68
+ export function writePlanned(root, plan, skipExtra = {}) {
69
+ const res = { created: [], skipped: [] };
70
+ for (const [path, reason] of Object.entries(skipExtra))
71
+ res.skipped.push({ path, reason });
72
+ for (const p of plan) {
73
+ const abs = join(root, p.path);
74
+ if (existsSync(abs)) {
75
+ res.skipped.push({ path: p.path, reason: "exists" });
76
+ continue;
77
+ }
78
+ mkdirSync(dirname(abs), { recursive: true });
79
+ writeFileSync(abs, p.content, "utf8");
80
+ res.created.push(p.path);
81
+ }
82
+ return res;
83
+ }
84
+ function prBody(language, r) {
85
+ const nl = language === "nl";
86
+ const list = (xs) => (xs.length ? xs.map((x) => `- \`${x}\``).join("\n") : nl ? "- geen" : "- none");
87
+ return [
88
+ `## ${nl ? "Beschrijving" : "Description"}`,
89
+ "",
90
+ nl
91
+ ? "Voorstel van `aihub init` voor het teampakket: teambestand, sjablonen en slash-commando's. Bestaande bestanden zijn niet aangepast. Controleer de waarden in `team.yaml` voor het mergen."
92
+ : "Proposal from `aihub init` for the team pack: team file, templates and slash commands. Existing files were not changed. Check the values in `team.yaml` before merging.",
93
+ "",
94
+ nl ? "Aangemaakt:" : "Created:",
95
+ list(r.created),
96
+ "",
97
+ nl ? "Overgeslagen (bestond al):" : "Skipped (already existed):",
98
+ list(r.skipped.map((s) => s.path)),
99
+ "",
100
+ ].join("\n");
101
+ }
102
+ export async function runInit(ctx, o) {
103
+ const language = parseLanguage(o.language);
104
+ const root = repoRoot(resolve(ctx.cwd, o.repo ?? "."));
105
+ const remote = parseRemote(remoteUrl(root));
106
+ const target = originDefaultBranch(root) || "main";
107
+ const info = { org: remote.org, project: remote.project, repo: remote.repo, target, language };
108
+ if (o.noPr) {
109
+ const p = planFiles(root, info);
110
+ return writePlanned(root, p.plan, p.skips);
111
+ }
112
+ const original = git(root, ["rev-parse", "--abbrev-ref", "HEAD"]).trim();
113
+ if (hasRef(root, `refs/heads/${PACK_BRANCH}`) || git(root, ["ls-remote", "--heads", "origin", PACK_BRANCH], { allowFail: true }).trim()) {
114
+ throw new AihubError(`branch '${PACK_BRANCH}' already exists; merge or delete it first, or run 'aihub init --no-pr'`);
115
+ }
116
+ git(root, ["switch", "-c", PACK_BRANCH, hasRef(root, `origin/${target}`) ? `origin/${target}` : "HEAD"]);
117
+ const back = () => {
118
+ if (original !== "HEAD")
119
+ git(root, ["switch", original], { allowFail: true });
120
+ };
121
+ try {
122
+ const p = planFiles(root, info);
123
+ const result = writePlanned(root, p.plan, p.skips);
124
+ result.branch = PACK_BRANCH;
125
+ if (!result.created.length) {
126
+ back();
127
+ git(root, ["branch", "-D", PACK_BRANCH], { allowFail: true });
128
+ result.branch = undefined;
129
+ return result;
130
+ }
131
+ git(root, ["add", "--", ...result.created]);
132
+ git(root, ["commit", "-m", "chore: aihub team pack", "--", ...result.created]);
133
+ pushIfNeeded(root, PACK_BRANCH);
134
+ const bodyFile = join(mkdtempSync(join(tmpdir(), "aihub-init-")), "body.md");
135
+ writeFileSync(bodyFile, prBody(language, result), "utf8");
136
+ result.pr = await createPr({ ...ctx, cwd: root }, { title: "chore: aihub team pack", bodyFile, target });
137
+ back();
138
+ return result;
139
+ }
140
+ catch (e) {
141
+ back();
142
+ throw e;
143
+ }
144
+ }
145
+ export function reportInit(r) {
146
+ const lines = [
147
+ ...r.created.map((p) => `created ${p}`),
148
+ ...r.skipped.map((s) => `skipped ${s.path} (${s.reason})`),
149
+ ];
150
+ if (!r.created.length)
151
+ lines.push("nothing to create: the team pack is already in place");
152
+ if (r.pr)
153
+ lines.push(r.pr);
154
+ else if (r.created.length && !r.branch)
155
+ lines.push("files written, no pull request (--no-pr): review, commit and push them yourself");
156
+ return lines;
157
+ }
@@ -0,0 +1,141 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { clientDirs, CLIENTS } from "./clients.js";
4
+ import { cliVersion, listFiles, packRoot, readPackFile, sha256, stamp } from "./pack.js";
5
+ export const MANIFEST = ".aihub-manifest.json";
6
+ function readManifest(dir) {
7
+ try {
8
+ const m = JSON.parse(readFileSync(join(dir, MANIFEST), "utf8"));
9
+ return { version: m.version, files: m.files ?? {} };
10
+ }
11
+ catch {
12
+ return { version: "", files: {} };
13
+ }
14
+ }
15
+ const readNorm = (p) => readFileSync(p, "utf8").replace(/\r\n/g, "\n");
16
+ /**
17
+ * Write entries into dir. Files that are not ours (no manifest record) or that the user changed (checksum differs from
18
+ * what we wrote) are never overwritten. Idempotent. Files we installed earlier that left the pack are removed when unmodified.
19
+ */
20
+ export function installEntries(dir, entries, version) {
21
+ const man = readManifest(dir);
22
+ const results = [];
23
+ const next = {};
24
+ for (const e of entries) {
25
+ const abs = join(dir, e.rel);
26
+ const want = sha256(e.content);
27
+ if (!existsSync(abs)) {
28
+ mkdirSync(dirname(abs), { recursive: true });
29
+ writeFileSync(abs, e.content, "utf8");
30
+ next[e.rel] = want;
31
+ results.push({ action: "created", path: abs });
32
+ continue;
33
+ }
34
+ const cur = sha256(readNorm(abs));
35
+ if (cur === want) {
36
+ next[e.rel] = want;
37
+ results.push({ action: "unchanged", path: abs });
38
+ }
39
+ else if (man.files[e.rel] === cur) {
40
+ writeFileSync(abs, e.content, "utf8");
41
+ next[e.rel] = want;
42
+ results.push({ action: "updated", path: abs });
43
+ }
44
+ else {
45
+ if (man.files[e.rel])
46
+ next[e.rel] = man.files[e.rel];
47
+ results.push({ action: "skipped", path: abs, reason: man.files[e.rel] ? "changed by the user" : "exists and is not an aihub file" });
48
+ }
49
+ }
50
+ for (const [rel, sum] of Object.entries(man.files)) {
51
+ if (entries.some((e) => e.rel === rel))
52
+ continue;
53
+ const abs = join(dir, rel);
54
+ if (!existsSync(abs))
55
+ continue;
56
+ if (sha256(readNorm(abs)) === sum) {
57
+ unlinkSync(abs);
58
+ results.push({ action: "removed", path: abs, reason: "no longer in the pack" });
59
+ }
60
+ else
61
+ next[rel] = sum;
62
+ }
63
+ if (Object.keys(next).length) {
64
+ mkdirSync(dir, { recursive: true });
65
+ writeFileSync(join(dir, MANIFEST), JSON.stringify({ version, files: next }, null, 2) + "\n", "utf8");
66
+ }
67
+ pruneEmpty(dir, dir);
68
+ return results;
69
+ }
70
+ /** Remove only the files aihub wrote and the user did not change. */
71
+ export function uninstallDir(dir) {
72
+ const man = readManifest(dir);
73
+ const results = [];
74
+ const keep = {};
75
+ for (const [rel, sum] of Object.entries(man.files)) {
76
+ const abs = join(dir, rel);
77
+ if (!existsSync(abs))
78
+ continue;
79
+ if (sha256(readNorm(abs)) === sum) {
80
+ unlinkSync(abs);
81
+ results.push({ action: "removed", path: abs });
82
+ }
83
+ else {
84
+ keep[rel] = sum;
85
+ results.push({ action: "skipped", path: abs, reason: "changed by the user" });
86
+ }
87
+ }
88
+ const mf = join(dir, MANIFEST);
89
+ if (Object.keys(keep).length)
90
+ writeFileSync(mf, JSON.stringify({ version: man.version, files: keep }, null, 2) + "\n", "utf8");
91
+ else if (existsSync(mf))
92
+ unlinkSync(mf);
93
+ pruneEmpty(dir, dir);
94
+ return results;
95
+ }
96
+ /** Delete empty directories below dir and dir itself when it ends up empty. */
97
+ function pruneEmpty(dir, top) {
98
+ if (!existsSync(dir))
99
+ return;
100
+ for (const n of readdirSync(dir, { withFileTypes: true }))
101
+ if (n.isDirectory())
102
+ pruneEmpty(join(dir, n.name), top);
103
+ if (readdirSync(dir).length === 0)
104
+ rmdirSync(dir);
105
+ }
106
+ export function skillEntries(version = cliVersion()) {
107
+ const src = join(packRoot(), "skills");
108
+ return listFiles(src).map((rel) => ({ rel, content: stamp(rel, readPackFile(join(src, rel)), version) }));
109
+ }
110
+ export function commandEntries(source, version = cliVersion()) {
111
+ const src = join(packRoot(), "commands", source);
112
+ return listFiles(src).map((rel) => ({ rel, content: stamp(rel, readPackFile(join(src, rel)), version) }));
113
+ }
114
+ export function parseClients(value) {
115
+ if (!value || value === "all")
116
+ return [...CLIENTS];
117
+ if (CLIENTS.includes(value))
118
+ return [value];
119
+ throw new Error(`unknown client '${value}'; use opencode, github-copilot, codex or all`);
120
+ }
121
+ export function installClients(clients, env, opts) {
122
+ const version = cliVersion();
123
+ const out = [];
124
+ for (const c of clients) {
125
+ const d = clientDirs(c, env, opts);
126
+ out.push({ client: c, dir: d.skills, results: installEntries(d.skills, skillEntries(version), version) });
127
+ if (d.commands)
128
+ out.push({ client: c, dir: d.commands.dir, results: installEntries(d.commands.dir, commandEntries(d.commands.source, version), version) });
129
+ }
130
+ return out;
131
+ }
132
+ export function uninstallClients(clients, env, opts) {
133
+ const out = [];
134
+ for (const c of clients) {
135
+ const d = clientDirs(c, env, opts);
136
+ out.push({ client: c, dir: d.skills, results: uninstallDir(d.skills) });
137
+ if (d.commands)
138
+ out.push({ client: c, dir: d.commands.dir, results: uninstallDir(d.commands.dir) });
139
+ }
140
+ return out;
141
+ }
@@ -0,0 +1,48 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { AihubError } from "./errors.js";
6
+ const here = dirname(fileURLToPath(import.meta.url));
7
+ /** Directory that holds the bundled `skills/` and `commands/` (the repo root in a checkout, cli/pack in the npm package). */
8
+ export function packRoot() {
9
+ for (const c of [join(here, "..", "..", ".."), join(here, "..", "..", "pack")]) {
10
+ if (existsSync(join(c, "skills")) && existsSync(join(c, "commands")))
11
+ return c;
12
+ }
13
+ throw new AihubError("the bundled skills are missing from this installation; reinstall with 'npm i -g @ferronhooi/aihub'");
14
+ }
15
+ export function cliVersion() {
16
+ try {
17
+ return JSON.parse(readFileSync(join(here, "..", "..", "package.json"), "utf8")).version;
18
+ }
19
+ catch {
20
+ return "0.0.0";
21
+ }
22
+ }
23
+ export const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
24
+ /** Relative POSIX paths of all files below dir, sorted. */
25
+ export function listFiles(dir, base = dir) {
26
+ const out = [];
27
+ for (const name of readdirSync(dir).sort()) {
28
+ const p = join(dir, name);
29
+ if (statSync(p).isDirectory())
30
+ out.push(...listFiles(p, base));
31
+ else
32
+ out.push(p.slice(base.length + 1).replace(/\\/g, "/"));
33
+ }
34
+ return out;
35
+ }
36
+ export const readPackFile = (path) => readFileSync(path, "utf8").replace(/^/, "").replace(/\r\n/g, "\n");
37
+ /**
38
+ * Mark a file as installed by aihub: `<!-- aihub <version> -->` in markdown (after the front matter, which must stay
39
+ * first), `# aihub <version>` in other text files.
40
+ */
41
+ export function stamp(rel, content, version) {
42
+ const isMd = rel.endsWith(".md");
43
+ const mark = isMd ? `<!-- aihub ${version} -->` : `# aihub ${version}`;
44
+ const fm = /^---\n[\s\S]*?\n---\n/.exec(content);
45
+ if (isMd && fm)
46
+ return `${fm[0]}${mark}\n${content.slice(fm[0].length)}`;
47
+ return `${mark}\n${content}`;
48
+ }
@@ -0,0 +1,88 @@
1
+ import { AihubError } from "./errors.js";
2
+ import { anyGlob } from "./glob.js";
3
+ export function robotConfig(team) {
4
+ const r = team.robot ?? {};
5
+ const suites = (r.suites ?? []).filter((s) => !!s?.name && Array.isArray(s.paths));
6
+ return { pipeline: r.pipeline, integrationBranch: r.integrationBranch, suites };
7
+ }
8
+ export function robotNeeded(files, cfg) {
9
+ const out = [];
10
+ for (const s of cfg.suites) {
11
+ const flowFiles = files.filter((f) => anyGlob(s.paths, f) && !(s.tests && anyGlob(s.tests, f)));
12
+ const testFiles = s.tests ? files.filter((f) => anyGlob(s.tests, f)) : [];
13
+ if (flowFiles.length || testFiles.length)
14
+ out.push({ suite: s.name, flowFiles, testFiles });
15
+ }
16
+ return out;
17
+ }
18
+ export function formatNeeded(needs, cfg, branch) {
19
+ if (!cfg.suites.length)
20
+ return "robot: no suites in team.yaml robot.suites; nothing to decide";
21
+ if (!needs.length)
22
+ return `robot: not needed for ${branch}: no changed file belongs to a flow with Robot tests`;
23
+ const lines = [`robot: needed for ${branch}: ${needs.length} suite${needs.length === 1 ? "" : "s"}`];
24
+ for (const n of needs) {
25
+ const t = n.testFiles.length
26
+ ? `tests changed (${n.testFiles.length})`
27
+ : "no Robot test changed: a new or changed flow needs a new or adjusted test";
28
+ lines.push(`- ${n.suite}: ${n.flowFiles.length} flow file${n.flowFiles.length === 1 ? "" : "s"}; ${t}`);
29
+ }
30
+ lines.push(`run: aihub robot run --suite ${needs[0].suite}`);
31
+ return lines.join("\n");
32
+ }
33
+ export async function queueRobot(c, opts) {
34
+ const defs = await c.get("build/definitions", { name: opts.pipeline });
35
+ const def = (defs.value ?? []).find((d) => d.name.toLowerCase() === opts.pipeline.toLowerCase());
36
+ if (!def)
37
+ throw new AihubError(`pipeline '${opts.pipeline}' not found in Azure DevOps; check robot.pipeline in team.yaml or pass --pipeline`);
38
+ const templateParameters = {};
39
+ if (opts.suite)
40
+ templateParameters.suite = opts.suite;
41
+ if (opts.include)
42
+ templateParameters.include = opts.include;
43
+ return c.post("build/builds", {
44
+ definition: { id: def.id },
45
+ sourceBranch: opts.branch.startsWith("refs/") ? opts.branch : `refs/heads/${opts.branch}`,
46
+ ...(Object.keys(templateParameters).length ? { templateParameters } : {}),
47
+ });
48
+ }
49
+ export async function followBuild(c, id, pollMs, timeoutMs = 4 * 3600_000) {
50
+ const deadline = Date.now() + timeoutMs;
51
+ for (;;) {
52
+ const b = await c.get(`build/builds/${id}`);
53
+ if (b.status === "completed")
54
+ return b;
55
+ if (Date.now() > deadline)
56
+ throw new AihubError(`build ${id} still ${b.status} after the timeout; check it in Azure DevOps`);
57
+ await new Promise((r) => setTimeout(r, pollMs));
58
+ }
59
+ }
60
+ /** Results summary: build result, test counts (when published) and failed steps with their first error lines. */
61
+ export async function summarize(c, b) {
62
+ const lines = [`build ${b.buildNumber ?? b.id}: ${b.result ?? b.status}${b._links?.web?.href ? ` ${b._links.web.href}` : ""}`];
63
+ try {
64
+ const runs = await c.get("test/runs", {
65
+ buildUri: `vstfs:///Build/Build/${b.id}`,
66
+ });
67
+ for (const r of runs.value ?? []) {
68
+ const total = r.totalTests ?? 0;
69
+ const passed = r.passedTests ?? 0;
70
+ lines.push(`tests ${r.name ?? "run"}: ${passed}/${total} passed, ${total - passed} failed`);
71
+ }
72
+ }
73
+ catch {
74
+ /* test results are optional */
75
+ }
76
+ try {
77
+ const t = await c.get(`build/builds/${b.id}/timeline`);
78
+ const failed = (t.records ?? []).filter((r) => r.result === "failed" && r.type !== "Stage" && r.type !== "Phase" && r.type !== "Job");
79
+ for (const r of failed.slice(0, 5)) {
80
+ const msg = (r.issues ?? []).find((i) => i.type === "error")?.message ?? "no error message";
81
+ lines.push(`failed: ${r.name}: ${msg.replace(/\s+/g, " ").trim().slice(0, 300)}`);
82
+ }
83
+ }
84
+ catch {
85
+ /* timeline is optional */
86
+ }
87
+ return lines.join("\n");
88
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The team schema file is a documented YAML example: every key carries a comment ending in "(required)" or "(optional)".
3
+ * This reads those comments to find the required key paths (lists are written `repositories[].name`).
4
+ */
5
+ export function requiredPaths(schemaText) {
6
+ const stack = [];
7
+ const out = [];
8
+ for (const line of schemaText.replace(/\r\n/g, "\n").split("\n")) {
9
+ const m = /^(\s*)(-\s+)?([A-Za-z][A-Za-z0-9]*):(.*)$/.exec(line);
10
+ if (!m || line.trimStart().startsWith("#"))
11
+ continue;
12
+ const keyIndent = m[1].length + (m[2]?.length ?? 0);
13
+ while (stack.length && stack[stack.length - 1].indent >= keyIndent)
14
+ stack.pop();
15
+ if (m[2] && stack.length)
16
+ stack[stack.length - 1].isList = true;
17
+ stack.push({ indent: keyIndent, key: m[3], isList: false });
18
+ const comment = m[4].includes("#") ? m[4].slice(m[4].indexOf("#")) : "";
19
+ if (/\(required\b/.test(comment))
20
+ out.push(stack.map((s) => s.key + (s.isList ? "[]" : "")).join("."));
21
+ }
22
+ return out;
23
+ }
24
+ const get = (value, seg) => {
25
+ const isList = seg.endsWith("[]");
26
+ const key = isList ? seg.slice(0, -2) : seg;
27
+ if (value === null || typeof value !== "object" || Array.isArray(value))
28
+ return [];
29
+ const v = value[key];
30
+ if (v === undefined || v === null || v === "" || (Array.isArray(v) && v.length === 0))
31
+ return [];
32
+ return isList ? (Array.isArray(v) ? v : []) : [v];
33
+ };
34
+ /** Human-readable problems of a parsed team file against the required paths; empty when valid. */
35
+ export function validateTeam(data, required) {
36
+ const problems = [];
37
+ for (const path of required) {
38
+ const segs = path.split(".");
39
+ let level = [data];
40
+ let missing = false;
41
+ for (const s of segs) {
42
+ const next = level.flatMap((v) => get(v, s));
43
+ if (s.endsWith("[]") ? !next.length : next.length < level.length || !next.length)
44
+ missing = true;
45
+ level = next;
46
+ if (missing)
47
+ break;
48
+ }
49
+ if (missing)
50
+ problems.push(`missing ${path}`);
51
+ }
52
+ const v = data?.version;
53
+ if (v !== undefined && !Number.isInteger(v))
54
+ problems.push("version must be an integer");
55
+ return problems;
56
+ }
package/dist/router.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import { AihubError } from "./lib/errors.js";
2
+ import { cliVersion } from "./lib/pack.js";
2
3
  import * as comments from "./commands/comments.js";
4
+ import * as doctor from "./commands/doctor.js";
5
+ import * as init from "./commands/init.js";
3
6
  import * as pr from "./commands/pr.js";
7
+ import * as skills from "./commands/skills.js";
8
+ import * as fabric from "./commands/fabric.js";
9
+ import * as robot from "./commands/robot.js";
4
10
  /**
5
11
  * Command registry. To add a command: create src/commands/<name>.ts exporting
6
12
  * `run(argv, ctx)` and add one line here. Commands print through ctx.out and
@@ -9,8 +15,13 @@ import * as pr from "./commands/pr.js";
9
15
  export const commands = {
10
16
  pr: pr.run,
11
17
  comments: comments.run,
18
+ init: init.run,
19
+ skills: skills.run,
20
+ doctor: doctor.run,
21
+ fabric: fabric.run,
22
+ robot: robot.run,
12
23
  };
13
- export const VERSION = "0.0.0";
24
+ export const VERSION = cliVersion();
14
25
  /** Returns the process exit code. */
15
26
  export async function main(argv, ctx, registry = commands) {
16
27
  const [name, ...rest] = argv;
@@ -14,6 +14,7 @@ export const COMMANDS = [
14
14
  { name: "refine", skill: "story-refine", description: "Refine a story", hint: "story id" },
15
15
  { name: "review", skill: "review-process", description: "Process review comments", hint: "optional PR id" },
16
16
  { name: "watch", skill: "pr-watch", description: "Follow a PR and its pipeline", hint: "optional PR id or link" },
17
+ { name: "test", skill: "test-run", description: "Run the Fabric or Robot tests for this branch", hint: "fabric or robot, optional item or suite" },
17
18
  ];
18
19
  export function expectedCommand(kind, c) {
19
20
  const load = `Load the \`${c.skill}\` skill and follow it exactly.`;
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Cherry-pick a PR to other branches
4
+ ---
5
+ Load the `branch-sync` skill and follow it exactly.
6
+ Input: ${input:args:PR id and target branches}
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Update the open pull request
4
+ ---
5
+ Load the `pr-update` skill and follow it exactly.
6
+ Input: ${input:args:optional remarks}
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Create a pull request
4
+ ---
5
+ Load the `pr-create` skill and follow it exactly.
6
+ Input: ${input:args:optional story id or remarks}
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Refine a story
4
+ ---
5
+ Load the `story-refine` skill and follow it exactly.
6
+ Input: ${input:args:story id}
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Process review comments
4
+ ---
5
+ Load the `review-process` skill and follow it exactly.
6
+ Input: ${input:args:optional PR id}
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Create a story
4
+ ---
5
+ Load the `story-create` skill and follow it exactly.
6
+ Input: ${input:args:what the story is about}
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Run the Fabric or Robot tests for this branch
4
+ ---
5
+ Load the `test-run` skill and follow it exactly.
6
+ Input: ${input:args:fabric or robot, optional item or suite}
@@ -0,0 +1,6 @@
1
+ ---
2
+ mode: agent
3
+ description: Follow a PR and its pipeline
4
+ ---
5
+ Load the `pr-watch` skill and follow it exactly.
6
+ Input: ${input:args:optional PR id or link}
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Cherry-pick a PR to other branches
3
+ ---
4
+ Load the `branch-sync` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Update the open pull request
3
+ ---
4
+ Load the `pr-update` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Create a pull request
3
+ ---
4
+ Load the `pr-create` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Refine a story
3
+ ---
4
+ Load the `story-refine` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Process review comments
3
+ ---
4
+ Load the `review-process` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Create a story
3
+ ---
4
+ Load the `story-create` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Run the Fabric or Robot tests for this branch
3
+ ---
4
+ Load the `test-run` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Follow a PR and its pipeline
3
+ ---
4
+ Load the `pr-watch` skill and follow it exactly.
5
+ Arguments: $ARGUMENTS
@@ -0,0 +1,5 @@
1
+ <type>: <korte samenvatting in de gebiedende wijs, maximaal 72 tekens> (#<story-id>)
2
+
3
+ <optionele toelichting: waarom de wijziging nodig was, een alinea>
4
+
5
+ # type: feat | fix | refactor | test | docs | chore
@@ -0,0 +1,5 @@
1
+ <type>: <short summary in the imperative, max 72 characters> (#<story id>)
2
+
3
+ <optional body: why the change was needed, one paragraph>
4
+
5
+ # type: feat | fix | refactor | test | docs | chore