@ferronhooi/aihub 0.0.1 → 0.1.0-next.11

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 (145) hide show
  1. package/dist/cli.js +10 -9
  2. package/dist/commands/batch.js +19 -0
  3. package/dist/commands/branch.js +10 -0
  4. package/dist/commands/cherry-pick.js +25 -0
  5. package/dist/commands/comments.js +32 -0
  6. package/dist/commands/crossrepo.js +70 -0
  7. package/dist/commands/doctor.js +21 -0
  8. package/dist/commands/evidence.js +13 -0
  9. package/dist/commands/explain.js +5 -0
  10. package/dist/commands/fabric.js +121 -0
  11. package/dist/commands/init.js +18 -0
  12. package/dist/commands/pipeline.js +35 -0
  13. package/dist/commands/port.js +38 -0
  14. package/dist/commands/pr-changes.js +36 -0
  15. package/dist/commands/pr.js +78 -0
  16. package/dist/commands/release.js +41 -0
  17. package/dist/commands/review.js +54 -0
  18. package/dist/commands/robot.js +69 -0
  19. package/dist/commands/skills.js +75 -0
  20. package/dist/commands/story-flow.js +48 -0
  21. package/dist/commands/story.js +23 -0
  22. package/dist/commands/update.js +17 -0
  23. package/dist/commands/wiki.js +19 -0
  24. package/dist/commands/work.js +6 -0
  25. package/dist/commands/workitem.js +23 -0
  26. package/dist/commands/worktree.js +27 -0
  27. package/dist/lib/ado.js +183 -0
  28. package/dist/lib/args.js +18 -0
  29. package/dist/lib/auth.js +68 -0
  30. package/dist/lib/batch.js +146 -0
  31. package/dist/lib/branch.js +72 -0
  32. package/dist/lib/branches.js +46 -0
  33. package/dist/lib/changes.js +14 -0
  34. package/dist/lib/cherryPick.js +182 -0
  35. package/dist/lib/cliargs.js +26 -0
  36. package/dist/lib/clients.js +26 -0
  37. package/dist/lib/comments.js +119 -0
  38. package/dist/lib/context.js +9 -0
  39. package/dist/lib/crossRepo.js +134 -0
  40. package/dist/lib/crossRepoOps.js +199 -0
  41. package/dist/lib/diff.js +68 -0
  42. package/dist/lib/doctor.js +133 -0
  43. package/dist/lib/errors.js +7 -0
  44. package/dist/lib/evidence.js +41 -0
  45. package/dist/lib/explain.js +53 -0
  46. package/dist/lib/fabric.js +272 -0
  47. package/dist/lib/git.js +116 -0
  48. package/dist/lib/gitx.js +48 -0
  49. package/dist/lib/glob.js +28 -0
  50. package/dist/lib/init.js +171 -0
  51. package/dist/lib/install.js +184 -0
  52. package/dist/lib/integrate.js +83 -0
  53. package/dist/lib/pack.js +56 -0
  54. package/dist/lib/pipeline.js +249 -0
  55. package/dist/lib/port.js +213 -0
  56. package/dist/lib/pr.js +131 -0
  57. package/dist/lib/prChanges.js +85 -0
  58. package/dist/lib/release.js +202 -0
  59. package/dist/lib/repos.js +50 -0
  60. package/dist/lib/review.js +223 -0
  61. package/dist/lib/robot.js +132 -0
  62. package/dist/lib/schema.js +56 -0
  63. package/dist/lib/skillsDiff.js +75 -0
  64. package/dist/lib/story-flow.js +202 -0
  65. package/dist/lib/story.js +248 -0
  66. package/dist/lib/team.js +37 -0
  67. package/dist/lib/templates.js +184 -0
  68. package/dist/lib/trace.js +77 -0
  69. package/dist/lib/update.js +110 -0
  70. package/dist/lib/wiki.js +46 -0
  71. package/dist/lib/work.js +67 -0
  72. package/dist/lib/workitems.js +56 -0
  73. package/dist/lib/worktree.js +152 -0
  74. package/dist/router.js +111 -0
  75. package/dist/tools/lintSkills.js +173 -0
  76. package/dist/tools/lintSkills.test.js +70 -0
  77. package/pack/CHANGELOG.md +14 -0
  78. package/pack/commands/copilot/cherry-pick.prompt.md +6 -0
  79. package/pack/commands/copilot/explain.prompt.md +6 -0
  80. package/pack/commands/copilot/finish.prompt.md +6 -0
  81. package/pack/commands/copilot/pr-update.prompt.md +6 -0
  82. package/pack/commands/copilot/pr.prompt.md +6 -0
  83. package/pack/commands/copilot/refine.prompt.md +6 -0
  84. package/pack/commands/copilot/release.prompt.md +6 -0
  85. package/pack/commands/copilot/review-pr.prompt.md +6 -0
  86. package/pack/commands/copilot/review.prompt.md +6 -0
  87. package/pack/commands/copilot/start.prompt.md +6 -0
  88. package/pack/commands/copilot/story.prompt.md +6 -0
  89. package/pack/commands/copilot/test.prompt.md +6 -0
  90. package/pack/commands/copilot/watch.prompt.md +6 -0
  91. package/pack/commands/copilot/wiki.prompt.md +6 -0
  92. package/pack/commands/opencode/cherry-pick.md +5 -0
  93. package/pack/commands/opencode/explain.md +5 -0
  94. package/pack/commands/opencode/finish.md +5 -0
  95. package/pack/commands/opencode/pr-update.md +5 -0
  96. package/pack/commands/opencode/pr.md +5 -0
  97. package/pack/commands/opencode/refine.md +5 -0
  98. package/pack/commands/opencode/release.md +5 -0
  99. package/pack/commands/opencode/review-pr.md +5 -0
  100. package/pack/commands/opencode/review.md +5 -0
  101. package/pack/commands/opencode/start.md +5 -0
  102. package/pack/commands/opencode/story.md +5 -0
  103. package/pack/commands/opencode/test.md +5 -0
  104. package/pack/commands/opencode/watch.md +5 -0
  105. package/pack/commands/opencode/wiki.md +5 -0
  106. package/pack/skills/_shared/assets/commit-template.txt +5 -0
  107. package/pack/skills/_shared/assets/pull_request_template.md +16 -0
  108. package/pack/skills/_shared/assets/story-template.md +12 -0
  109. package/pack/skills/_shared/references/team.schema.yaml +86 -0
  110. package/pack/skills/branch-sync/SKILL.md +31 -0
  111. package/pack/skills/cross-repo/SKILL.md +35 -0
  112. package/pack/skills/cross-repo/references/cross-repo.md +22 -0
  113. package/pack/skills/evidence/SKILL.md +28 -0
  114. package/pack/skills/implement/SKILL.md +25 -0
  115. package/pack/skills/pipeline-fix/SKILL.md +30 -0
  116. package/pack/skills/pr-create/SKILL.md +29 -0
  117. package/pack/skills/pr-explain/SKILL.md +28 -0
  118. package/pack/skills/pr-review/SKILL.md +35 -0
  119. package/pack/skills/pr-update/SKILL.md +28 -0
  120. package/pack/skills/pr-watch/SKILL.md +30 -0
  121. package/pack/skills/release/SKILL.md +32 -0
  122. package/pack/skills/review-process/SKILL.md +35 -0
  123. package/pack/skills/start-here/SKILL.md +46 -0
  124. package/pack/skills/story-create/SKILL.md +28 -0
  125. package/pack/skills/story-finish/SKILL.md +29 -0
  126. package/pack/skills/story-refine/SKILL.md +28 -0
  127. package/pack/skills/story-run/SKILL.md +27 -0
  128. package/pack/skills/story-start/SKILL.md +31 -0
  129. package/pack/skills/team-settings/SKILL.md +28 -0
  130. package/pack/skills/test-run/SKILL.md +37 -0
  131. package/pack/skills/test-run/references/fabric-robot.md +24 -0
  132. package/pack/skills/voice-notes/SKILL.md +30 -0
  133. package/pack/skills/wiki/SKILL.md +29 -0
  134. package/pack/skills/worktrees/SKILL.md +29 -0
  135. package/pack/team-pack/.agents/skills/_shared/assets/commit-template.en.txt +5 -0
  136. package/pack/team-pack/.agents/skills/_shared/assets/commit-template.txt +5 -0
  137. package/pack/team-pack/.agents/skills/_shared/assets/story-template.en.md +12 -0
  138. package/pack/team-pack/.agents/skills/_shared/assets/story-template.md +12 -0
  139. package/pack/team-pack/.agents/skills/_shared/references/team.yaml +46 -0
  140. package/pack/team-pack/.azuredevops/pull_request_template.en.md +16 -0
  141. package/pack/team-pack/.azuredevops/pull_request_template.md +16 -0
  142. package/pack/team-pack/.github/guidelines/aihub.md +9 -0
  143. package/pack/team-pack/.github/instructions/aihub.instructions.md +6 -0
  144. package/pack/team-pack/README.md +20 -0
  145. package/package.json +13 -3
package/dist/cli.js CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
- // Entry point. Commands are added per workflow in src/commands/.
3
- const [, , ...args] = process.argv;
4
- if (args[0] === "--version") {
5
- console.log("0.0.0");
6
- }
7
- else {
8
- console.log("aihub: under construction. Commands: pr, comments, cherry-pick, branch, story, pipeline, batch, work, init, skills, doctor.");
9
- }
10
- export {};
2
+ // Entry point. Commands are registered in src/router.ts.
3
+ import { main } from "./router.js";
4
+ const code = await main(process.argv.slice(2), {
5
+ cwd: process.cwd(),
6
+ env: process.env,
7
+ fetch,
8
+ out: (l) => process.stdout.write(l + "\n"),
9
+ err: (l) => process.stderr.write(l + "\n"),
10
+ });
11
+ process.exitCode = code;
@@ -0,0 +1,19 @@
1
+ import { num, parse } from "../lib/args.js";
2
+ import { batch } from "../lib/batch.js";
3
+ export async function run(argv, ctx) {
4
+ const v = parse(argv, {
5
+ select: { type: "string" },
6
+ run: { type: "string" },
7
+ parallel: { type: "string" },
8
+ "retry-failed": { type: "string" },
9
+ json: { type: "boolean" },
10
+ }).values;
11
+ // In-process runner: every target runs one aihub command with its own captured output.
12
+ const runner = async (args) => {
13
+ const { main } = await import("../router.js");
14
+ const lines = [];
15
+ const code = await main(args, { ...ctx, out: (l) => lines.push(l), err: (l) => lines.push(l) });
16
+ return { code, output: lines.join("\n") };
17
+ };
18
+ await batch(ctx, { select: v.select, run: v.run, parallel: num(v.parallel, "--parallel"), retryFailed: v["retry-failed"], json: v.json }, runner);
19
+ }
@@ -0,0 +1,10 @@
1
+ import { parse } from "../lib/args.js";
2
+ import { branchUpdate } from "../lib/branch.js";
3
+ import { AihubError } from "../lib/errors.js";
4
+ export async function run(argv, ctx) {
5
+ const [sub, ...rest] = argv;
6
+ if (sub !== "update")
7
+ throw new AihubError("usage: aihub branch update [--branch B] [--target T] [--rebase]");
8
+ const v = parse(rest, { branch: { type: "string" }, target: { type: "string" }, rebase: { type: "boolean" }, json: { type: "boolean" } }).values;
9
+ ctx.out(await branchUpdate(ctx, { branch: v.branch, target: v.target, rebase: v.rebase, json: v.json }));
10
+ }
@@ -0,0 +1,25 @@
1
+ import { parse } from "../lib/args.js";
2
+ import { cherryPick } from "../lib/cherryPick.js";
3
+ import { AihubError } from "../lib/errors.js";
4
+ export async function run(argv, ctx) {
5
+ const v = parse(argv, {
6
+ from: { type: "string" },
7
+ to: { type: "string", multiple: true },
8
+ "to-group": { type: "string" },
9
+ pr: { type: "boolean" },
10
+ direct: { type: "boolean" },
11
+ "body-file": { type: "string" },
12
+ json: { type: "boolean" },
13
+ }).values;
14
+ if (!v.from)
15
+ throw new AihubError("aihub cherry-pick needs --from <pr N|url|commit sha,...|story id>");
16
+ await cherryPick(ctx, {
17
+ from: v.from,
18
+ to: v.to ?? [],
19
+ toGroup: v["to-group"],
20
+ pr: v.pr,
21
+ direct: v.direct,
22
+ bodyFile: v["body-file"],
23
+ json: v.json,
24
+ });
25
+ }
@@ -0,0 +1,32 @@
1
+ import { parseArgs } from "node:util";
2
+ import { commentsGet, commentsReply } from "../lib/comments.js";
3
+ import { AihubError } from "../lib/errors.js";
4
+ export async function run(argv, ctx) {
5
+ const [sub, ...rest] = argv;
6
+ let v;
7
+ try {
8
+ v = parseArgs({
9
+ args: rest,
10
+ options: {
11
+ pr: { type: "string" },
12
+ "include-resolved": { type: "boolean" },
13
+ "replies-file": { type: "string" },
14
+ json: { type: "boolean" },
15
+ },
16
+ }).values;
17
+ }
18
+ catch (e) {
19
+ throw new AihubError(e.message);
20
+ }
21
+ if (sub === "get") {
22
+ ctx.out(await commentsGet(ctx, { pr: v.pr, includeResolved: !!v["include-resolved"], json: !!v.json }));
23
+ return;
24
+ }
25
+ if (sub === "reply") {
26
+ if (!v["replies-file"])
27
+ throw new AihubError("aihub comments reply needs --replies-file <file.yaml>");
28
+ ctx.out(await commentsReply(ctx, { pr: v.pr, repliesFile: v["replies-file"], json: !!v.json }));
29
+ return;
30
+ }
31
+ throw new AihubError("usage: aihub comments get|reply [flags]");
32
+ }
@@ -0,0 +1,70 @@
1
+ import { num, parse } from "../lib/args.js";
2
+ import { AihubError } from "../lib/errors.js";
3
+ import { crossStatus, formatStatus, linkPrs, testResources } from "../lib/crossRepoOps.js";
4
+ const USAGE = "aihub crossrepo status --story N | link-prs --story N [--pr repo!42] | test-resources --from-repo A --to-repo B --target BRANCH --paths GLOB [--message-file F] [--run-pipeline NAME]";
5
+ export async function run(argv, ctx) {
6
+ const [sub, ...rest] = argv;
7
+ if (sub === "status") {
8
+ const v = parse(rest, { story: { type: "string" }, json: { type: "boolean" } }).values;
9
+ const story = num(v.story, "--story");
10
+ if (!story)
11
+ throw new AihubError("aihub crossrepo status needs --story N");
12
+ const rows = await crossStatus(ctx, { story });
13
+ ctx.out(v.json ? JSON.stringify({ story, repos: rows }) : formatStatus(story, rows));
14
+ return;
15
+ }
16
+ if (sub === "link-prs") {
17
+ const v = parse(rest, { story: { type: "string" }, pr: { type: "string", multiple: true }, json: { type: "boolean" } }).values;
18
+ const story = num(v.story, "--story");
19
+ if (!story)
20
+ throw new AihubError("aihub crossrepo link-prs needs --story N");
21
+ const r = await linkPrs(ctx, { story, extra: v.pr });
22
+ if (v.json)
23
+ ctx.out(JSON.stringify(r));
24
+ else {
25
+ for (const x of r.results)
26
+ ctx.out(`${x.repo} !${x.pr}: ${x.updated ? "related PRs section updated" : "already up to date"}`);
27
+ if (r.linkedToStory.length)
28
+ ctx.out(`linked to story ${story}: ${r.linkedToStory.map((i) => `!${i}`).join(", ")}`);
29
+ }
30
+ return;
31
+ }
32
+ if (sub === "test-resources") {
33
+ const v = parse(rest, {
34
+ "from-repo": { type: "string" },
35
+ "to-repo": { type: "string" },
36
+ target: { type: "string" },
37
+ paths: { type: "string" },
38
+ "to-path": { type: "string" },
39
+ "message-file": { type: "string" },
40
+ "run-pipeline": { type: "string" },
41
+ "no-follow": { type: "boolean" },
42
+ json: { type: "boolean" },
43
+ }).values;
44
+ const r = await testResources(ctx, {
45
+ fromRepo: v["from-repo"],
46
+ toRepo: v["to-repo"],
47
+ target: v.target,
48
+ paths: v.paths,
49
+ toPath: v["to-path"],
50
+ messageFile: v["message-file"],
51
+ runPipeline: v["run-pipeline"],
52
+ noFollow: v["no-follow"],
53
+ });
54
+ if (v.json)
55
+ ctx.out(JSON.stringify(r));
56
+ else {
57
+ ctx.out(`test-resources -> ${r.repo}/${r.branch}: ${r.result} ${r.detail}`);
58
+ for (const f of r.files.slice(0, 50))
59
+ ctx.out(` ${f}`);
60
+ if (r.build?.summary)
61
+ ctx.out(r.build.summary);
62
+ else if (r.build)
63
+ ctx.out(`pipeline build ${r.build.id} queued`);
64
+ }
65
+ if (r.result === "failed" || r.result === "refused")
66
+ throw new AihubError(`test-resources stopped: ${r.detail}`);
67
+ return;
68
+ }
69
+ throw new AihubError(`usage: ${USAGE}`);
70
+ }
@@ -0,0 +1,21 @@
1
+ import { parseArgs } from "node:util";
2
+ import { AihubError } from "../lib/errors.js";
3
+ import { formatChecks, runChecks } from "../lib/doctor.js";
4
+ export async function run(argv, ctx) {
5
+ let json = false;
6
+ try {
7
+ json = !!parseArgs({ args: argv, options: { json: { type: "boolean" } } }).values.json;
8
+ }
9
+ catch (e) {
10
+ throw new AihubError(e.message);
11
+ }
12
+ const checks = runChecks(ctx);
13
+ if (json) {
14
+ ctx.out(JSON.stringify({ ok: checks.every((c) => c.status === "OK"), checks }));
15
+ return;
16
+ }
17
+ for (const l of formatChecks(checks))
18
+ ctx.out(l);
19
+ const bad = checks.filter((c) => c.status === "FIX").length;
20
+ ctx.out(bad ? `${bad} check(s) need a fix` : "all checks passed");
21
+ }
@@ -0,0 +1,13 @@
1
+ import { AihubError } from "../lib/errors.js";
2
+ import { parseFlags } from "../lib/cliargs.js";
3
+ import { addEvidence } from "../lib/evidence.js";
4
+ /** aihub evidence add --pr N --file img.png [--caption text] */
5
+ export async function run(argv, ctx) {
6
+ const [sub, ...rest] = argv;
7
+ const v = parseFlags(rest, { pr: { type: "string" }, file: { type: "string" }, caption: { type: "string" }, section: { type: "string" }, json: { type: "boolean" } });
8
+ if (sub !== "add")
9
+ throw new AihubError("usage: aihub evidence add --pr <n> --file <image> [--caption <text>]");
10
+ if (!v.pr || !v.file)
11
+ throw new AihubError("aihub evidence add needs --pr <n> and --file <image>");
12
+ ctx.out(await addEvidence(ctx, { pr: v.pr, file: v.file, caption: v.caption, section: v.section, json: !!v.json }));
13
+ }
@@ -0,0 +1,5 @@
1
+ import { explain } from "../lib/explain.js";
2
+ export async function run(argv, ctx) {
3
+ for (const l of explain(argv[0]))
4
+ ctx.out(l);
5
+ }
@@ -0,0 +1,121 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { parseArgs } from "node:util";
3
+ import { changedFiles } from "../lib/changes.js";
4
+ import { AihubError } from "../lib/errors.js";
5
+ import { buildPlan, executionDataFromParams, fabricWorkspaces, FabricClient, formatJob, formatPlan, guardEnv, makeFabricAuth, selectWorkspaces, workspaceGroups, waitForJob, } from "../lib/fabric.js";
6
+ import { git, repoRoot } from "../lib/git.js";
7
+ import { loadTeam } from "../lib/team.js";
8
+ const USAGE = "usage: aihub fabric plan|run|status [flags]";
9
+ export async function run(argv, ctx) {
10
+ const [sub, ...rest] = argv;
11
+ let v;
12
+ try {
13
+ v = parseArgs({
14
+ args: rest,
15
+ options: {
16
+ branch: { type: "string" },
17
+ target: { type: "string" },
18
+ workspace: { type: "string", multiple: true },
19
+ workspaces: { type: "string" },
20
+ item: { type: "string" },
21
+ job: { type: "string" },
22
+ "params-file": { type: "string" },
23
+ "allow-env": { type: "string" },
24
+ wait: { type: "boolean" },
25
+ },
26
+ }).values;
27
+ }
28
+ catch (e) {
29
+ throw new AihubError(e.message);
30
+ }
31
+ if (sub !== "plan" && sub !== "run" && sub !== "status")
32
+ throw new AihubError(USAGE);
33
+ const root = repoRoot(ctx.cwd);
34
+ const team = loadTeam(root);
35
+ const list = fabricWorkspaces(team);
36
+ const given = v.branch;
37
+ if (sub === "plan") {
38
+ const c = changedFiles(root, team, { branch: given, target: v.target });
39
+ ctx.out(formatPlan(buildPlan(c.files, list, { branch: c.branch, workspace: v.workspace?.[0] }), c.branch, c.target));
40
+ return;
41
+ }
42
+ const branch = given ?? git(root, ["rev-parse", "--abbrev-ref", "HEAD"], { allowFail: true }).trim();
43
+ const chosen = selectWorkspaces(list, workspaceGroups(team), { workspaces: v.workspace, group: v.workspaces, branch });
44
+ if (!chosen.length)
45
+ throw new AihubError("no dev/feature workspace in team.yaml fabric.workspaces; pass --workspace <name|id>");
46
+ // refuse before any Fabric call when one of them is not allowed
47
+ for (const w of chosen)
48
+ guardEnv(w, v["allow-env"]);
49
+ const ws = chosen[0];
50
+ if (!v.item)
51
+ throw new AihubError(`aihub fabric ${sub} needs --item <name|id>`);
52
+ if (sub === "status" && !v.job)
53
+ throw new AihubError("aihub fabric status needs --job <id> and --item <name|id>");
54
+ const client = new FabricClient(makeFabricAuth({ env: ctx.env, exec: ctx.exec, cacheFile: ctx.tokenCache && `${ctx.tokenCache}.fabric` }), ctx.fetch);
55
+ if (chosen.length > 1) {
56
+ if (sub === "status")
57
+ throw new AihubError("aihub fabric status takes one --workspace");
58
+ await runMany(ctx, client, chosen, v);
59
+ return;
60
+ }
61
+ const wsId = await client.workspaceId(ws);
62
+ const item = await client.resolveItem(wsId, v.item);
63
+ if (sub === "status") {
64
+ ctx.out(formatJob(await client.jobStatus(wsId, item.id, v.job), item.displayName));
65
+ return;
66
+ }
67
+ const exec = v["params-file"] ? executionDataFromParams(readFileSync(v["params-file"], "utf8"), item) : undefined;
68
+ const jobId = await client.startJob(wsId, item, exec);
69
+ ctx.out(`started ${item.type} ${item.displayName} in ${ws.name} (${ws.environment}): job ${jobId}`);
70
+ if (!v.wait) {
71
+ ctx.out(`follow with: aihub fabric status --item ${item.displayName} --job ${jobId}`);
72
+ return;
73
+ }
74
+ const j = await waitForJob(client, wsId, item.id, jobId, { pollMs: Number(ctx.env.AIHUB_POLL_MS ?? 5000) });
75
+ ctx.out(formatJob(j, item.displayName));
76
+ if (j.status !== "Completed")
77
+ throw new AihubError(`${item.displayName} ended as ${j.status}`);
78
+ }
79
+ /** Same item in several workspaces: start in each, wait for all, one table, keep going on errors. */
80
+ async function runMany(ctx, client, chosen, v) {
81
+ const rows = chosen.map((ws) => ({ ws }));
82
+ for (const r of rows) {
83
+ try {
84
+ r.wsId = await client.workspaceId(r.ws);
85
+ const item = await client.resolveItem(r.wsId, v.item);
86
+ r.itemId = item.id;
87
+ const exec = v["params-file"] ? executionDataFromParams(readFileSync(v["params-file"], "utf8"), item) : undefined;
88
+ r.jobId = await client.startJob(r.wsId, item, exec);
89
+ ctx.out(`started ${item.displayName} in ${r.ws.name} (${r.ws.environment}): job ${r.jobId}`);
90
+ }
91
+ catch (e) {
92
+ r.error = e.message;
93
+ }
94
+ }
95
+ if (v.wait) {
96
+ const pollMs = Number(ctx.env.AIHUB_POLL_MS ?? 5000);
97
+ for (const r of rows) {
98
+ if (!r.jobId)
99
+ continue;
100
+ try {
101
+ r.result = await waitForJob(client, r.wsId, r.itemId, r.jobId, { pollMs });
102
+ }
103
+ catch (e) {
104
+ r.error = e.message;
105
+ }
106
+ }
107
+ }
108
+ const lines = ["workspace | environment | job | result"];
109
+ for (const r of rows) {
110
+ const res = r.error
111
+ ? `error: ${r.error}`
112
+ : r.result
113
+ ? `${r.result.status}${r.result.status === "Failed" ? `: ${(r.result.failureReason?.message ?? "no details").replace(/\s+/g, " ").trim()}` : ""}`
114
+ : "started";
115
+ lines.push(`${r.ws.name} | ${r.ws.environment} | ${r.jobId ?? "-"} | ${res}`);
116
+ }
117
+ ctx.out(lines.join(String.fromCharCode(10)));
118
+ const bad = rows.filter((r) => r.error || (v.wait && r.result?.status !== "Completed"));
119
+ if (bad.length)
120
+ throw new AihubError(`${bad.length} of ${rows.length} workspaces did not complete: ${bad.map((r) => r.ws.name).join(", ")}`);
121
+ }
@@ -0,0 +1,18 @@
1
+ import { parseArgs } from "node:util";
2
+ import { AihubError } from "../lib/errors.js";
3
+ import { reportInit, runInit } from "../lib/init.js";
4
+ export async function run(argv, ctx) {
5
+ let v;
6
+ try {
7
+ v = parseArgs({
8
+ args: argv,
9
+ options: { repo: { type: "string" }, "no-pr": { type: "boolean" }, language: { type: "string" }, "into-repo": { type: "boolean" } },
10
+ }).values;
11
+ }
12
+ catch (e) {
13
+ throw new AihubError(e.message);
14
+ }
15
+ const r = await runInit(ctx, { repo: v.repo, noPr: !!v["no-pr"], language: v.language, intoRepo: !!v["into-repo"] });
16
+ for (const l of reportInit(r))
17
+ ctx.out(l);
18
+ }
@@ -0,0 +1,35 @@
1
+ import { num, parse } from "../lib/args.js";
2
+ import { AihubError } from "../lib/errors.js";
3
+ import { pipelineFollow, pipelineLogs, pipelineRun, pipelineRuns, pipelineStatus } from "../lib/pipeline.js";
4
+ export async function run(argv, ctx) {
5
+ const [sub, ...rest] = argv;
6
+ const v = parse(rest, {
7
+ pr: { type: "string" },
8
+ branch: { type: "string" },
9
+ run: { type: "string" },
10
+ definition: { type: "string" },
11
+ name: { type: "string" },
12
+ top: { type: "string" },
13
+ timeout: { type: "string" },
14
+ step: { type: "string" },
15
+ search: { type: "string" },
16
+ tail: { type: "string" },
17
+ "params-file": { type: "string" },
18
+ json: { type: "boolean" },
19
+ }).values;
20
+ const sel = { pr: v.pr, branch: v.branch, run: num(v.run, "--run"), definition: v.definition, top: num(v.top, "--top") };
21
+ if (sub === "follow")
22
+ return pipelineFollow(ctx, { ...sel, timeout: v.timeout });
23
+ if (sub === "status")
24
+ return void ctx.out(await pipelineStatus(ctx, { ...sel, json: v.json }));
25
+ if (sub === "runs")
26
+ return void ctx.out(await pipelineRuns(ctx, { ...sel, json: v.json }));
27
+ if (sub === "logs") {
28
+ if (!sel.run)
29
+ throw new AihubError("aihub pipeline logs needs --run <id> (see 'aihub pipeline runs')");
30
+ return void ctx.out(await pipelineLogs(ctx, { run: sel.run, step: v.step, search: v.search, tail: num(v.tail, "--tail"), json: v.json }));
31
+ }
32
+ if (sub === "run")
33
+ return void ctx.out(await pipelineRun(ctx, { name: v.name, branch: v.branch, paramsFile: v["params-file"], json: v.json }));
34
+ throw new AihubError("usage: aihub pipeline follow|status|runs|logs|run [flags]");
35
+ }
@@ -0,0 +1,38 @@
1
+ import { parse } from "../lib/args.js";
2
+ import { AihubError } from "../lib/errors.js";
3
+ import { formatPort, port } from "../lib/port.js";
4
+ export async function run(argv, ctx) {
5
+ const v = parse(argv, {
6
+ "from-repo": { type: "string" },
7
+ from: { type: "string" },
8
+ "to-repo": { type: "string" },
9
+ "to-branch": { type: "string" },
10
+ "path-map": { type: "string", multiple: true },
11
+ map: { type: "string" },
12
+ strict: { type: "boolean" },
13
+ pr: { type: "boolean" },
14
+ "body-file": { type: "string" },
15
+ json: { type: "boolean" },
16
+ }).values;
17
+ if (!v["from-repo"] || !v.from || !v["to-repo"]) {
18
+ throw new AihubError("aihub port needs --from-repo <A> --from <pr N|commit sha,...|story id> --to-repo <B> [--to-branch T] [--path-map 'src=>dst' | --map <name>] [--pr --body-file F]");
19
+ }
20
+ const r = await port(ctx, {
21
+ fromRepo: v["from-repo"],
22
+ from: v.from,
23
+ toRepo: v["to-repo"],
24
+ toBranch: v["to-branch"],
25
+ pathMaps: v["path-map"],
26
+ map: v.map,
27
+ strict: v.strict,
28
+ pr: v.pr,
29
+ bodyFile: v["body-file"],
30
+ });
31
+ if (v.json)
32
+ ctx.out(JSON.stringify(r));
33
+ else
34
+ for (const l of formatPort(r, v["from-repo"], v["to-repo"]))
35
+ ctx.out(l);
36
+ if (r.result === "conflict" || r.result === "failed" || r.result === "refused")
37
+ throw new AihubError(`port stopped: ${r.detail}`);
38
+ }
@@ -0,0 +1,36 @@
1
+ import { parseArgs } from "node:util";
2
+ import { AihubError } from "../lib/errors.js";
3
+ import { prChanges } from "../lib/prChanges.js";
4
+ function int(v, flag) {
5
+ if (v === undefined)
6
+ return undefined;
7
+ const n = Number(v);
8
+ if (!Number.isInteger(n) || n < 0)
9
+ throw new AihubError(`${flag} must be a number`);
10
+ return n;
11
+ }
12
+ export async function run(argv, ctx) {
13
+ let v;
14
+ try {
15
+ v = parseArgs({
16
+ args: argv,
17
+ options: {
18
+ pr: { type: "string" },
19
+ "since-iteration": { type: "string" },
20
+ paths: { type: "string", multiple: true },
21
+ page: { type: "string" },
22
+ json: { type: "boolean" },
23
+ },
24
+ }).values;
25
+ }
26
+ catch (e) {
27
+ throw new AihubError(e.message);
28
+ }
29
+ ctx.out(await prChanges(ctx, {
30
+ pr: v.pr,
31
+ sinceIteration: int(v["since-iteration"], "--since-iteration"),
32
+ paths: (v.paths ?? []).flatMap((p) => p.split(",")),
33
+ page: int(v.page, "--page"),
34
+ json: v.json,
35
+ }));
36
+ }
@@ -0,0 +1,78 @@
1
+ import { parseArgs } from "node:util";
2
+ import { AihubError } from "../lib/errors.js";
3
+ import { createPr, updatePr } from "../lib/pr.js";
4
+ import { run as runChanges } from "./pr-changes.js";
5
+ function parse(argv, options) {
6
+ try {
7
+ return parseArgs({ args: argv, options, allowPositionals: true }).values;
8
+ }
9
+ catch (e) {
10
+ throw new AihubError(`${e.message}`);
11
+ }
12
+ }
13
+ function num(v, flag) {
14
+ if (v === undefined)
15
+ return undefined;
16
+ const n = Number(String(v).replace(/^AB#/i, ""));
17
+ if (!Number.isInteger(n) || n <= 0)
18
+ throw new AihubError(`${flag} must be a number`);
19
+ return n;
20
+ }
21
+ export async function run(argv, ctx) {
22
+ const [sub, ...rest] = argv;
23
+ if (sub === "changes")
24
+ return runChanges(rest, ctx);
25
+ if (sub === "create") {
26
+ const v = parse(rest, {
27
+ title: { type: "string" },
28
+ "body-file": { type: "string" },
29
+ target: { type: "string" },
30
+ draft: { type: "boolean" },
31
+ "work-item": { type: "string" },
32
+ "dry-run": { type: "boolean" },
33
+ json: { type: "boolean" },
34
+ });
35
+ ctx.out(await createPr(ctx, {
36
+ title: v.title,
37
+ bodyFile: v["body-file"],
38
+ target: v.target,
39
+ draft: v.draft,
40
+ workItem: num(v["work-item"], "--work-item"),
41
+ dryRun: v["dry-run"],
42
+ json: v.json,
43
+ }));
44
+ return;
45
+ }
46
+ if (sub === "update") {
47
+ const v = parse(rest, {
48
+ pr: { type: "string" },
49
+ "body-file": { type: "string" },
50
+ section: { type: "string" },
51
+ "append-file": { type: "string" },
52
+ "replace-file": { type: "string" },
53
+ title: { type: "string" },
54
+ draft: { type: "string" },
55
+ target: { type: "string" },
56
+ json: { type: "boolean" },
57
+ });
58
+ let draft;
59
+ if (v.draft !== undefined) {
60
+ if (v.draft !== "true" && v.draft !== "false")
61
+ throw new AihubError("--draft must be true or false");
62
+ draft = v.draft === "true";
63
+ }
64
+ ctx.out(await updatePr(ctx, {
65
+ pr: v.pr,
66
+ bodyFile: v["body-file"],
67
+ section: v.section,
68
+ appendFile: v["append-file"],
69
+ replaceFile: v["replace-file"],
70
+ title: v.title,
71
+ draft,
72
+ target: v.target,
73
+ json: v.json,
74
+ }));
75
+ return;
76
+ }
77
+ throw new AihubError("usage: aihub pr create|update [flags] (see README)");
78
+ }
@@ -0,0 +1,41 @@
1
+ import { AihubError } from "../lib/errors.js";
2
+ import { intList, list, parseFlags } from "../lib/cliargs.js";
3
+ import { releasePlan, releaseRun } from "../lib/release.js";
4
+ /** aihub release plan|run */
5
+ export async function run(argv, ctx) {
6
+ const [sub, ...rest] = argv;
7
+ const v = parseFlags(rest, {
8
+ stories: { type: "string" },
9
+ prs: { type: "string" },
10
+ target: { type: "string" },
11
+ "also-cherry-pick-to": { type: "string" },
12
+ name: { type: "string" },
13
+ version: { type: "string" },
14
+ commits: { type: "string" },
15
+ tags: { type: "string" },
16
+ out: { type: "string" },
17
+ "plan-file": { type: "string" },
18
+ json: { type: "boolean" },
19
+ });
20
+ if (sub === "plan") {
21
+ ctx.out(await releasePlan(ctx, {
22
+ stories: intList(v.stories, "--stories"),
23
+ prs: intList(v.prs, "--prs"),
24
+ target: v.target,
25
+ also: list(v["also-cherry-pick-to"]),
26
+ name: v.name,
27
+ version: v.version,
28
+ commits: list(v.commits),
29
+ tags: list(v.tags),
30
+ out: v.out,
31
+ json: !!v.json,
32
+ }));
33
+ }
34
+ else if (sub === "run") {
35
+ if (!v["plan-file"])
36
+ throw new AihubError("aihub release run needs --plan-file <file.yaml>");
37
+ ctx.out(await releaseRun(ctx, { planFile: v["plan-file"], json: !!v.json }));
38
+ }
39
+ else
40
+ throw new AihubError("usage: aihub release plan --stories a,b|--prs a,b --target <branch> | release run --plan-file <file>");
41
+ }
@@ -0,0 +1,54 @@
1
+ import { AihubError } from "../lib/errors.js";
2
+ import { optInt, parseFlags } from "../lib/cliargs.js";
3
+ import { prComplete, prExplain, reviewPost, reviewShow } from "../lib/review.js";
4
+ export const PR_EXTRA_SUBS = ["explain", "complete"];
5
+ function need(v, flag) {
6
+ if (typeof v !== "string" || !v)
7
+ throw new AihubError(`${flag} is required`);
8
+ return v;
9
+ }
10
+ /** aihub review show|post */
11
+ export async function run(argv, ctx) {
12
+ const [sub, ...rest] = argv;
13
+ const v = parseFlags(rest, {
14
+ pr: { type: "string" },
15
+ "comments-file": { type: "string" },
16
+ "max-files": { type: "string" },
17
+ "max-diff-lines": { type: "string" },
18
+ "no-diff": { type: "boolean" },
19
+ json: { type: "boolean" },
20
+ });
21
+ if (sub === "show") {
22
+ ctx.out(await reviewShow(ctx, {
23
+ pr: need(v.pr, "--pr"),
24
+ maxFiles: optInt(v["max-files"], "--max-files"),
25
+ maxDiffLines: optInt(v["max-diff-lines"], "--max-diff-lines"),
26
+ noDiff: !!v["no-diff"],
27
+ json: !!v.json,
28
+ }));
29
+ }
30
+ else if (sub === "post") {
31
+ ctx.out(await reviewPost(ctx, { pr: need(v.pr, "--pr"), commentsFile: need(v["comments-file"], "--comments-file"), json: !!v.json }));
32
+ }
33
+ else
34
+ throw new AihubError("usage: aihub review show --pr <n|url> | review post --pr <n> --comments-file <file.yaml>");
35
+ }
36
+ /** aihub pr explain|complete (the other pr subcommands live in commands/pr.ts). */
37
+ export async function runPrExtra(argv, ctx) {
38
+ const [sub, ...rest] = argv;
39
+ const v = parseFlags(rest, {
40
+ pr: { type: "string" },
41
+ auto: { type: "boolean" },
42
+ "delete-source": { type: "boolean" },
43
+ squash: { type: "boolean" },
44
+ json: { type: "boolean" },
45
+ });
46
+ const pr = need(v.pr, "--pr");
47
+ if (sub === "explain")
48
+ ctx.out(await prExplain(ctx, { pr, json: !!v.json }));
49
+ else if (sub === "complete") {
50
+ ctx.out(await prComplete(ctx, { pr, auto: !!v.auto, deleteSource: !!v["delete-source"], squash: !!v.squash, json: !!v.json }));
51
+ }
52
+ else
53
+ throw new AihubError("usage: aihub pr explain|complete --pr <n>");
54
+ }