@ferronhooi/aihub 0.1.0-next.10 → 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.
- package/dist/commands/explain.js +5 -0
- package/dist/commands/skills.js +20 -3
- package/dist/commands/update.js +17 -0
- package/dist/lib/ado.js +12 -1
- package/dist/lib/doctor.js +7 -0
- package/dist/lib/explain.js +53 -0
- package/dist/lib/git.js +5 -0
- package/dist/lib/gitx.js +3 -0
- package/dist/lib/init.js +39 -27
- package/dist/lib/install.js +18 -12
- package/dist/lib/integrate.js +3 -0
- package/dist/lib/pack.js +8 -0
- package/dist/lib/skillsDiff.js +75 -0
- package/dist/lib/trace.js +77 -0
- package/dist/lib/update.js +110 -0
- package/dist/router.js +31 -1
- package/pack/CHANGELOG.md +14 -0
- package/pack/skills/_shared/references/team.schema.yaml +3 -0
- package/pack/skills/start-here/SKILL.md +1 -1
- package/pack/team-pack/.agents/skills/_shared/assets/commit-template.en.txt +5 -0
- package/pack/team-pack/.agents/skills/_shared/assets/story-template.en.md +12 -0
- package/pack/team-pack/.agents/skills/_shared/references/team.yaml +46 -0
- package/pack/team-pack/.azuredevops/pull_request_template.en.md +16 -0
- package/pack/team-pack/.github/guidelines/aihub.md +9 -0
- package/pack/team-pack/.github/instructions/aihub.instructions.md +6 -0
- package/pack/team-pack/README.md +20 -0
- package/package.json +1 -1
- /package/pack/{skills/_shared/assets/commit-template.nl.txt → team-pack/.agents/skills/_shared/assets/commit-template.txt} +0 -0
- /package/pack/{skills/_shared/assets/story-template.nl.md → team-pack/.agents/skills/_shared/assets/story-template.md} +0 -0
- /package/pack/{skills/_shared/assets/pull_request_template.nl.md → team-pack/.azuredevops/pull_request_template.md} +0 -0
package/dist/commands/skills.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { AihubError } from "../lib/errors.js";
|
|
3
3
|
import { repoRoot } from "../lib/git.js";
|
|
4
|
+
import { diffClient } from "../lib/skillsDiff.js";
|
|
4
5
|
import { installClients, parseClients, uninstallClients, updateClients } from "../lib/install.js";
|
|
5
|
-
const USAGE = "usage: aihub skills install|update|uninstall [--client opencode|github-copilot|codex|all] [--into-repo]\n" +
|
|
6
|
+
const USAGE = "usage: aihub skills install|update|diff|uninstall [--client opencode|github-copilot|codex|all] [--into-repo]\n" +
|
|
6
7
|
" install copy the bundled skills and slash commands into each client's global folder\n" +
|
|
7
8
|
" update rewrite the copies of every client that has them from the bundled pack (files you edited stay)\n" +
|
|
9
|
+
" diff show your edits to the installed skills (and copies behind the bundled pack)\n" +
|
|
8
10
|
" uninstall remove only the files aihub wrote and you did not change\n" +
|
|
9
11
|
" --into-repo use the current repository instead of the global folders (for teams that keep skills in the repo)";
|
|
10
|
-
function report(reports, out) {
|
|
12
|
+
export function report(reports, out) {
|
|
11
13
|
for (const r of reports) {
|
|
12
14
|
const count = (a) => r.results.filter((x) => x.action === a).length;
|
|
13
15
|
out(`${r.client}: ${r.dir}`);
|
|
@@ -18,7 +20,7 @@ function report(reports, out) {
|
|
|
18
20
|
}
|
|
19
21
|
export async function run(argv, ctx) {
|
|
20
22
|
const [sub, ...rest] = argv;
|
|
21
|
-
if (sub !== "install" && sub !== "update" && sub !== "uninstall")
|
|
23
|
+
if (sub !== "install" && sub !== "update" && sub !== "uninstall" && sub !== "diff")
|
|
22
24
|
throw new AihubError(USAGE);
|
|
23
25
|
let v;
|
|
24
26
|
try {
|
|
@@ -43,6 +45,21 @@ export async function run(argv, ctx) {
|
|
|
43
45
|
throw new AihubError("--into-repo needs a git repository: cd into the repository first");
|
|
44
46
|
}
|
|
45
47
|
}
|
|
48
|
+
if (sub === "diff") {
|
|
49
|
+
let any = false;
|
|
50
|
+
for (const c of clients) {
|
|
51
|
+
const d = diffClient(ctx.env, c, opts);
|
|
52
|
+
for (const f of d) {
|
|
53
|
+
any = true;
|
|
54
|
+
ctx.out(`${c}: ${f.rel} (${f.state === "edited" ? "edited by you" : f.state === "behind" ? "older than the bundled pack, aihub skills update refreshes it" : "deleted by you"})`);
|
|
55
|
+
for (const l of f.diff)
|
|
56
|
+
ctx.out(` ${l}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!any)
|
|
60
|
+
ctx.out("no differences: installed skills match the bundled pack");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
46
63
|
if (sub === "install")
|
|
47
64
|
report(installClients(clients, ctx.env, opts), ctx.out);
|
|
48
65
|
else if (sub === "uninstall")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { AihubError } from "../lib/errors.js";
|
|
3
|
+
import { runUpdate } from "../lib/update.js";
|
|
4
|
+
import { report } from "./skills.js";
|
|
5
|
+
export async function run(argv, ctx) {
|
|
6
|
+
let v;
|
|
7
|
+
try {
|
|
8
|
+
v = parseArgs({ args: argv, options: { check: { type: "boolean" }, after: { type: "string" } } }).values;
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
throw new AihubError(e.message);
|
|
12
|
+
}
|
|
13
|
+
const r = runUpdate(ctx, { check: !!v.check, after: v.after });
|
|
14
|
+
for (const l of r.lines)
|
|
15
|
+
ctx.out(l);
|
|
16
|
+
report(r.reports, ctx.out);
|
|
17
|
+
}
|
package/dist/lib/ado.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AihubError } from "./errors.js";
|
|
2
|
+
import { isRestWrite, summarizeBody, trace } from "./trace.js";
|
|
2
3
|
export function parseRemote(url) {
|
|
3
4
|
const u = url.trim();
|
|
4
5
|
const dec = (s) => decodeURIComponent(s);
|
|
@@ -49,7 +50,15 @@ export class AdoClient {
|
|
|
49
50
|
return `${this.remote.orgUrl}/${encodeURIComponent(this.remote.project)}/_apis/${path}?${q.toString()}`;
|
|
50
51
|
}
|
|
51
52
|
async request(method, path, opts = {}) {
|
|
52
|
-
const
|
|
53
|
+
const fullUrl = this.url(path, opts.query);
|
|
54
|
+
const bodyText = opts.rawBody !== undefined ? `${opts.rawBody.length} bytes` : summarizeBody(opts.body);
|
|
55
|
+
if (trace.dryRun && isRestWrite(method, path)) {
|
|
56
|
+
trace.plan(`would ${method} ${fullUrl}${bodyText ? ` body ${bodyText}` : ""}`);
|
|
57
|
+
return { data: {}, headers: new Headers() };
|
|
58
|
+
}
|
|
59
|
+
if (trace.verbose)
|
|
60
|
+
trace.log(`+ ${method} ${fullUrl}${bodyText ? ` body ${bodyText}` : ""}`);
|
|
61
|
+
const res = await this.fetchFn(fullUrl, {
|
|
53
62
|
method,
|
|
54
63
|
headers: {
|
|
55
64
|
Authorization: await this.auth(),
|
|
@@ -62,6 +71,8 @@ export class AdoClient {
|
|
|
62
71
|
body: opts.rawBody !== undefined ? opts.rawBody : opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
63
72
|
});
|
|
64
73
|
const text = await res.text();
|
|
74
|
+
if (trace.verbose)
|
|
75
|
+
trace.log(` -> ${res.status}`);
|
|
65
76
|
const ctype = res.headers.get("content-type") ?? "";
|
|
66
77
|
// Azure DevOps answers a bad/missing credential with 203 + an HTML sign-in page.
|
|
67
78
|
if (res.status === 401 || res.status === 203 || (res.ok && !opts.raw && ctype.includes("text/html"))) {
|
package/dist/lib/doctor.js
CHANGED
|
@@ -97,6 +97,13 @@ export function runChecks(ctx) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
const team = loadTeam(root);
|
|
100
|
+
const guidelines = Array.isArray(team.guidelines) ? team.guidelines.map(String) : [];
|
|
101
|
+
if (guidelines.length) {
|
|
102
|
+
const missing = guidelines.filter((g) => !existsSync(join(root, g)));
|
|
103
|
+
checks.push(missing.length
|
|
104
|
+
? fix("guidelines", `listed in team.yaml but not found: ${missing.join(", ")}`, "add the files or remove them from guidelines: in team.yaml")
|
|
105
|
+
: ok("guidelines", `${guidelines.length} guideline file(s) found`));
|
|
106
|
+
}
|
|
100
107
|
const target = defaultTargetFor(team, repoName) || originDefaultBranch(root) || "main";
|
|
101
108
|
const tpl = resolveTemplate(target, { readRef: (b, p) => showFile(root, b, p), localRoot: root });
|
|
102
109
|
checks.push(tpl
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Short, step-by-step description per command. Keep these in sync when a command changes. */
|
|
2
|
+
export const EXPLAIN = {
|
|
3
|
+
pr: [
|
|
4
|
+
"aihub pr create --body-file pr.md",
|
|
5
|
+
"1. git: current branch, merge-base with the target, commits since then (read only).",
|
|
6
|
+
"2. Target = --target, else team.yaml defaultTarget, else the remote default branch.",
|
|
7
|
+
"3. Reads the PR template from origin/<target> (.azuredevops, .vsts, docs, root), falls back to the working tree.",
|
|
8
|
+
"4. Fills the template: your body file by heading, story link and commit list by code, empty sections get team.yaml emptySection.",
|
|
9
|
+
"5. git push of the branch when origin is behind; REST POST .../pullrequests (or PATCH when an active PR exists).",
|
|
10
|
+
"aihub pr update: edits sections of the existing description (PATCH); other sections stay intact.",
|
|
11
|
+
"Use --dry-run to see the filled description and the calls without writing.",
|
|
12
|
+
],
|
|
13
|
+
comments: ["aihub comments get: REST GET of the PR threads, shows open ones with the code around the line.", "aihub comments reply --replies-file f.yaml: REST POST of the replies and thread status changes you listed."],
|
|
14
|
+
init: [
|
|
15
|
+
"aihub init: reads the git remote (organization/project/repository) and the default branch.",
|
|
16
|
+
"1. Proposes team.yaml, story and commit templates, and a PR template only when none exists where Azure DevOps looks.",
|
|
17
|
+
"2. Never overwrites a file; existing ones are reported as skipped.",
|
|
18
|
+
"3. Creates branch chore/aihub-team-pack, commits, pushes and opens a PR (REST POST). --no-pr only writes the files.",
|
|
19
|
+
"Skills and slash commands are not written to the repository unless --into-repo.",
|
|
20
|
+
],
|
|
21
|
+
skills: [
|
|
22
|
+
"aihub skills install: copies the bundled skills and slash commands into each client's global folder (opencode, Codex, Copilot).",
|
|
23
|
+
"Every file gets an 'aihub <version>' marker; checksums go in .aihub-manifest.json so edited files are never overwritten.",
|
|
24
|
+
"aihub skills update: rewrites unchanged copies from the bundled pack. aihub skills diff: shows your edits. aihub skills uninstall: removes only our unchanged files.",
|
|
25
|
+
],
|
|
26
|
+
doctor: ["aihub doctor: checks Node, git, remote, sign-in method, team.yaml against the schema, PR template, guideline files and the installed skills per client. Nothing is written."],
|
|
27
|
+
update: [
|
|
28
|
+
"aihub update: asks npm for the latest version (registry from your npm config / .npmrc).",
|
|
29
|
+
"1. npm global install: runs npm i -g <package>@latest, then the new CLI shows the changelog and refreshes the skills of every client.",
|
|
30
|
+
"2. Other install: prints the exact command to run.",
|
|
31
|
+
"aihub update --check only reports versions; nothing changes.",
|
|
32
|
+
],
|
|
33
|
+
story: ["aihub story show|create|refine: reads or writes work items through REST; story start|link|finish prepare the branches, link the PR and finish the story.", "Use --dry-run to see the planned git and REST calls."],
|
|
34
|
+
branch: ["aihub branch update: merges (or rebases with --rebase) the target branch into the current branch, then pushes.", "git fetch, git merge/rebase, git push."],
|
|
35
|
+
"cherry-pick": ["aihub cherry-pick: creates a branch per target from the release branch, cherry-picks the commits of the PR, pushes and opens a PR per target."],
|
|
36
|
+
pipeline: ["aihub pipeline follow|status|runs|logs|run: reads builds through REST; run queues one. follow polls until it finishes."],
|
|
37
|
+
batch: ["aihub batch: runs the same flow for several stories or pull requests one after the other and prints one result per item."],
|
|
38
|
+
work: ["aihub work: the combined daily flow (story, branch, PR) in one command; see 'aihub explain story' and 'aihub explain pr'."],
|
|
39
|
+
worktree: ["aihub worktree create|list|remove: git worktrees per story across the repositories of a set, so each story has its own folder."],
|
|
40
|
+
review: ["aihub review show: reads a PR with its changes. aihub review post --comments-file f.yaml: posts your review comments (REST POST)."],
|
|
41
|
+
wiki: ["aihub wiki update --page <path> --body-file f: writes a wiki page (REST PUT); --publish also publishes it."],
|
|
42
|
+
release: ["aihub release plan: lists the pull requests of the given stories for a target branch. aihub release run --plan-file f: executes that plan."],
|
|
43
|
+
workitem: ["aihub workitem state --id n --to state: changes the state of a work item (REST PATCH)."],
|
|
44
|
+
evidence: ["aihub evidence add --pr n --file image: uploads the image as an attachment and adds it to the PR as a comment."],
|
|
45
|
+
fabric: ["aihub fabric plan|run|status: plans and runs Fabric deployments for the workspaces in team.yaml."],
|
|
46
|
+
robot: ["aihub robot needed|run|targets: decides which Robot suites are needed, merges the feature into the integration branch in a temporary worktree, pushes and queues the run."],
|
|
47
|
+
};
|
|
48
|
+
export function explain(name) {
|
|
49
|
+
if (!name)
|
|
50
|
+
return [`Commands with an explanation: ${Object.keys(EXPLAIN).join(", ")}.`, "Run 'aihub explain <command>'."];
|
|
51
|
+
const e = EXPLAIN[name];
|
|
52
|
+
return e ?? [`no explanation for '${name}'. Commands: ${Object.keys(EXPLAIN).join(", ")}.`];
|
|
53
|
+
}
|
package/dist/lib/git.js
CHANGED
|
@@ -3,7 +3,10 @@ import { mkdtempSync, rmSync } from "node:fs";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { AihubError } from "./errors.js";
|
|
6
|
+
import { gitGate } from "./trace.js";
|
|
6
7
|
export function git(cwd, args, opts = {}) {
|
|
8
|
+
if (gitGate(cwd, args))
|
|
9
|
+
return "";
|
|
7
10
|
const r = spawnSync("git", args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
8
11
|
if (r.error)
|
|
9
12
|
throw new AihubError(`git is not available: ${r.error.message}`);
|
|
@@ -82,6 +85,8 @@ export function workItemFromBranch(branch) {
|
|
|
82
85
|
}
|
|
83
86
|
/** Run git and return the exit status instead of throwing. */
|
|
84
87
|
export function gitRaw(cwd, args) {
|
|
88
|
+
if (gitGate(cwd, args))
|
|
89
|
+
return { status: 0, stdout: "", stderr: "" };
|
|
85
90
|
const r = spawnSync("git", args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
86
91
|
if (r.error)
|
|
87
92
|
throw new AihubError(`git is not available: ${r.error.message}`);
|
package/dist/lib/gitx.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { AihubError } from "./errors.js";
|
|
3
|
+
import { gitGate } from "./trace.js";
|
|
3
4
|
/** Runs git and reports success instead of throwing (the exit code matters for merge checks). */
|
|
4
5
|
export function tryGit(cwd, args) {
|
|
6
|
+
if (gitGate(cwd, args))
|
|
7
|
+
return { ok: true, out: "", err: "" };
|
|
5
8
|
const r = spawnSync("git", args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
6
9
|
if (r.error)
|
|
7
10
|
throw new AihubError(`git is not available: ${r.error.message}`);
|
package/dist/lib/init.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { parseDocument } from "yaml";
|
|
5
5
|
import { parseRemote } from "./ado.js";
|
|
6
6
|
import { AihubError } from "./errors.js";
|
|
7
7
|
import { git, hasRef, originDefaultBranch, pushIfNeeded, remoteUrl, repoRoot, showFile } from "./git.js";
|
|
8
8
|
import { listFiles, packRoot, readPackFile } from "./pack.js";
|
|
9
9
|
import { createPr } from "./pr.js";
|
|
10
|
+
import { trace } from "./trace.js";
|
|
10
11
|
import { TEAM_FILE } from "./team.js";
|
|
11
12
|
import { resolveTemplate } from "./templates.js";
|
|
12
13
|
export const PACK_BRANCH = "chore/aihub-team-pack";
|
|
@@ -20,23 +21,26 @@ export function parseLanguage(v) {
|
|
|
20
21
|
return v;
|
|
21
22
|
throw new AihubError(`--language must be nl or en, not '${v}'`);
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
/** The team pack files (the single source: team-pack/ in the repository, pack/team-pack in the npm package). */
|
|
25
|
+
export function teamPackDir() {
|
|
26
|
+
return join(packRoot(), "team-pack");
|
|
27
|
+
}
|
|
28
|
+
/** team-pack/team.yaml with the values of this repository filled in; the comments of the example stay. */
|
|
29
|
+
function teamYaml(src, o) {
|
|
30
|
+
const doc = parseDocument(src);
|
|
31
|
+
doc.setIn(["language"], o.language);
|
|
32
|
+
doc.setIn(["azureDevOps", "organization"], o.org);
|
|
33
|
+
doc.setIn(["azureDevOps", "project"], o.project);
|
|
34
|
+
doc.setIn(["repositories", 0, "name"], o.repo);
|
|
35
|
+
doc.setIn(["repositories", 0, "defaultTarget"], o.target);
|
|
36
|
+
doc.setIn(["repositories", 0, "aliases"], doc.createNode([]));
|
|
37
|
+
doc.setIn(["pullRequest", "template"], o.prTemplate);
|
|
38
|
+
doc.setIn(["pullRequest", "emptySection"], o.language === "nl" ? "n.v.t." : "-");
|
|
39
|
+
doc.setIn(["branches", "protected", 0], o.target);
|
|
40
|
+
doc.deleteIn(["pipelines"]);
|
|
41
|
+
doc.deleteIn(["guidelines"]);
|
|
42
|
+
doc.deleteIn(["cherryPick"]);
|
|
43
|
+
return "# Proposed by 'aihub init': check every value and change it through a pull request.\n" + String(doc);
|
|
40
44
|
}
|
|
41
45
|
/** Where Azure DevOps already finds a PR template for the target branch, or undefined. */
|
|
42
46
|
export function existingPrTemplate(root, target) {
|
|
@@ -45,17 +49,21 @@ export function existingPrTemplate(root, target) {
|
|
|
45
49
|
/** Everything `aihub init` would like to have in the repository (before skipping what exists). */
|
|
46
50
|
export function planFiles(root, o) {
|
|
47
51
|
const pack = packRoot();
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
52
|
+
const dir = teamPackDir();
|
|
53
|
+
const en = o.language === "en";
|
|
54
|
+
// team-pack holds Dutch files and `name.en.ext` English variants; the repository gets the plain name either way
|
|
55
|
+
const read = (rel) => {
|
|
56
|
+
const enRel = rel.replace(/(\.[^./]+)$/, ".en$1");
|
|
57
|
+
return readPackFile(join(dir, en && existsSync(join(dir, enRel)) ? enRel : rel));
|
|
58
|
+
};
|
|
51
59
|
const found = existingPrTemplate(root, o.target);
|
|
52
60
|
const plan = [
|
|
53
|
-
{ path: TEAM_FILE, content: teamYaml({ ...o, prTemplate: found && !found.includes("/branches/") ? found : PR_TEMPLATE }) },
|
|
54
|
-
{ path: STORY_TEMPLATE, content:
|
|
55
|
-
{ path: COMMIT_TEMPLATE, content:
|
|
61
|
+
{ path: TEAM_FILE, content: teamYaml(readPackFile(join(dir, TEAM_FILE)), { ...o, prTemplate: found && !found.includes("/branches/") ? found : PR_TEMPLATE }) },
|
|
62
|
+
{ path: STORY_TEMPLATE, content: read(STORY_TEMPLATE) },
|
|
63
|
+
{ path: COMMIT_TEMPLATE, content: read(COMMIT_TEMPLATE) },
|
|
56
64
|
];
|
|
57
65
|
if (!found)
|
|
58
|
-
plan.push({ path: PR_TEMPLATE, content:
|
|
66
|
+
plan.push({ path: PR_TEMPLATE, content: read(PR_TEMPLATE) });
|
|
59
67
|
if (o.intoRepo) {
|
|
60
68
|
for (const f of listFiles(join(pack, "commands", "opencode"))) {
|
|
61
69
|
plan.push({ path: `.opencode/command/${f}`, content: readPackFile(join(pack, "commands", "opencode", f)) });
|
|
@@ -77,8 +85,12 @@ export function writePlanned(root, plan, skipExtra = {}) {
|
|
|
77
85
|
res.skipped.push({ path: p.path, reason: "exists" });
|
|
78
86
|
continue;
|
|
79
87
|
}
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
if (trace.dryRun)
|
|
89
|
+
trace.plan(`would write ${abs}`);
|
|
90
|
+
else {
|
|
91
|
+
mkdirSync(dirname(abs), { recursive: true });
|
|
92
|
+
writeFileSync(abs, p.content, "utf8");
|
|
93
|
+
}
|
|
82
94
|
res.created.push(p.path);
|
|
83
95
|
}
|
|
84
96
|
return res;
|
package/dist/lib/install.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { trace } from "./trace.js";
|
|
2
3
|
import { dirname, join } from "node:path";
|
|
3
4
|
import { clientDirs, CLIENTS } from "./clients.js";
|
|
4
5
|
import { cliVersion, listFiles, packRoot, readPackFile, sha256, stamp } from "./pack.js";
|
|
6
|
+
// --dry-run: the same code path runs, but nothing is written and every planned write is printed.
|
|
7
|
+
const wf = (p, c) => (trace.dryRun ? trace.plan(`would write ${p}`) : writeFileSync(p, c, "utf8"));
|
|
8
|
+
const wq = (p, c) => (trace.dryRun ? undefined : writeFileSync(p, c, "utf8"));
|
|
9
|
+
const mk = (p) => (trace.dryRun ? undefined : void mkdirSync(p, { recursive: true }));
|
|
10
|
+
const rm = (p) => (trace.dryRun ? trace.plan(`would delete ${p}`) : unlinkSync(p));
|
|
5
11
|
export const MANIFEST = ".aihub-manifest.json";
|
|
6
|
-
function readManifest(dir) {
|
|
12
|
+
export function readManifest(dir) {
|
|
7
13
|
try {
|
|
8
14
|
const m = JSON.parse(readFileSync(join(dir, MANIFEST), "utf8"));
|
|
9
15
|
return { version: m.version, files: m.files ?? {} };
|
|
@@ -12,7 +18,7 @@ function readManifest(dir) {
|
|
|
12
18
|
return { version: "", files: {} };
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
|
-
const readNorm = (p) => readFileSync(p, "utf8").replace(/\r\n/g, "\n");
|
|
21
|
+
export const readNorm = (p) => readFileSync(p, "utf8").replace(/\r\n/g, "\n");
|
|
16
22
|
/**
|
|
17
23
|
* Write entries into dir. Files that are not ours (no manifest record) or that the user changed (checksum differs from
|
|
18
24
|
* what we wrote) are never overwritten. Idempotent. Files we installed earlier that left the pack are removed when unmodified.
|
|
@@ -25,8 +31,8 @@ export function installEntries(dir, entries, version) {
|
|
|
25
31
|
const abs = join(dir, e.rel);
|
|
26
32
|
const want = sha256(e.content);
|
|
27
33
|
if (!existsSync(abs)) {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
mk(dirname(abs));
|
|
35
|
+
wf(abs, e.content);
|
|
30
36
|
next[e.rel] = want;
|
|
31
37
|
results.push({ action: "created", path: abs });
|
|
32
38
|
continue;
|
|
@@ -37,7 +43,7 @@ export function installEntries(dir, entries, version) {
|
|
|
37
43
|
results.push({ action: "unchanged", path: abs });
|
|
38
44
|
}
|
|
39
45
|
else if (man.files[e.rel] === cur) {
|
|
40
|
-
|
|
46
|
+
wf(abs, e.content);
|
|
41
47
|
next[e.rel] = want;
|
|
42
48
|
results.push({ action: "updated", path: abs });
|
|
43
49
|
}
|
|
@@ -54,15 +60,15 @@ export function installEntries(dir, entries, version) {
|
|
|
54
60
|
if (!existsSync(abs))
|
|
55
61
|
continue;
|
|
56
62
|
if (sha256(readNorm(abs)) === sum) {
|
|
57
|
-
|
|
63
|
+
rm(abs);
|
|
58
64
|
results.push({ action: "removed", path: abs, reason: "no longer in the pack" });
|
|
59
65
|
}
|
|
60
66
|
else
|
|
61
67
|
next[rel] = sum;
|
|
62
68
|
}
|
|
63
69
|
if (Object.keys(next).length) {
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
mk(dir);
|
|
71
|
+
wq(join(dir, MANIFEST), JSON.stringify({ version, files: next }, null, 2) + "\n");
|
|
66
72
|
}
|
|
67
73
|
pruneEmpty(dir, dir);
|
|
68
74
|
return results;
|
|
@@ -77,7 +83,7 @@ export function uninstallDir(dir) {
|
|
|
77
83
|
if (!existsSync(abs))
|
|
78
84
|
continue;
|
|
79
85
|
if (sha256(readNorm(abs)) === sum) {
|
|
80
|
-
|
|
86
|
+
rm(abs);
|
|
81
87
|
results.push({ action: "removed", path: abs });
|
|
82
88
|
}
|
|
83
89
|
else {
|
|
@@ -87,8 +93,8 @@ export function uninstallDir(dir) {
|
|
|
87
93
|
}
|
|
88
94
|
const mf = join(dir, MANIFEST);
|
|
89
95
|
if (Object.keys(keep).length)
|
|
90
|
-
|
|
91
|
-
else if (existsSync(mf))
|
|
96
|
+
wq(mf, JSON.stringify({ version: man.version, files: keep }, null, 2) + "\n");
|
|
97
|
+
else if (existsSync(mf) && !trace.dryRun)
|
|
92
98
|
unlinkSync(mf);
|
|
93
99
|
pruneEmpty(dir, dir);
|
|
94
100
|
return results;
|
|
@@ -100,7 +106,7 @@ function pruneEmpty(dir, top) {
|
|
|
100
106
|
for (const n of readdirSync(dir, { withFileTypes: true }))
|
|
101
107
|
if (n.isDirectory())
|
|
102
108
|
pruneEmpty(join(dir, n.name), top);
|
|
103
|
-
if (readdirSync(dir).length === 0)
|
|
109
|
+
if (readdirSync(dir).length === 0 && !trace.dryRun)
|
|
104
110
|
rmdirSync(dir);
|
|
105
111
|
}
|
|
106
112
|
export function skillEntries(version = cliVersion()) {
|
package/dist/lib/integrate.js
CHANGED
|
@@ -4,7 +4,10 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { AihubError } from "./errors.js";
|
|
6
6
|
import { git, pushIfNeeded } from "./git.js";
|
|
7
|
+
import { gitGate } from "./trace.js";
|
|
7
8
|
function tryGit(cwd, args) {
|
|
9
|
+
if (gitGate(cwd, args))
|
|
10
|
+
return { ok: true, out: "", err: "" };
|
|
8
11
|
const r = spawnSync("git", args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
9
12
|
return { ok: r.status === 0, out: (r.stdout ?? "").replace(/\r\n/g, "\n").trim(), err: (r.stderr ?? "").trim() };
|
|
10
13
|
}
|
package/dist/lib/pack.js
CHANGED
|
@@ -20,6 +20,14 @@ export function cliVersion() {
|
|
|
20
20
|
return "0.0.0";
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
export function cliPackageName() {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(readFileSync(join(here, "..", "..", "package.json"), "utf8")).name;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return "@ferronhooi/aihub";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
23
31
|
export const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
|
|
24
32
|
/** Relative POSIX paths of all files below dir, sorted. */
|
|
25
33
|
export function listFiles(dir, base = dir) {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { clientDirs } from "./clients.js";
|
|
4
|
+
import { cliVersion } from "./pack.js";
|
|
5
|
+
import { readManifest, readNorm, skillEntries } from "./install.js";
|
|
6
|
+
import { sha256 } from "./pack.js";
|
|
7
|
+
/** Line diff (longest common subsequence); fine for skill-sized files. */
|
|
8
|
+
export function lineDiff(a, b) {
|
|
9
|
+
const x = a.split("\n");
|
|
10
|
+
const y = b.split("\n");
|
|
11
|
+
const m = x.length;
|
|
12
|
+
const n = y.length;
|
|
13
|
+
const l = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
14
|
+
for (let i = m - 1; i >= 0; i--)
|
|
15
|
+
for (let j = n - 1; j >= 0; j--)
|
|
16
|
+
l[i][j] = x[i] === y[j] ? l[i + 1][j + 1] + 1 : Math.max(l[i + 1][j], l[i][j + 1]);
|
|
17
|
+
const out = [];
|
|
18
|
+
let i = 0;
|
|
19
|
+
let j = 0;
|
|
20
|
+
while (i < m && j < n) {
|
|
21
|
+
if (x[i] === y[j])
|
|
22
|
+
out.push({ t: " ", s: x[i++] }), j++;
|
|
23
|
+
else if (l[i + 1][j] >= l[i][j + 1])
|
|
24
|
+
out.push({ t: "-", s: x[i++] });
|
|
25
|
+
else
|
|
26
|
+
out.push({ t: "+", s: y[j++] });
|
|
27
|
+
}
|
|
28
|
+
while (i < m)
|
|
29
|
+
out.push({ t: "-", s: x[i++] });
|
|
30
|
+
while (j < n)
|
|
31
|
+
out.push({ t: "+", s: y[j++] });
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
/** The `aihub <version>` marker differs per release and is not a user edit. */
|
|
35
|
+
const unmark = (s) => s.replace(/^(<!-- aihub \S+ -->|# aihub \S+)\n/m, "");
|
|
36
|
+
/** Only the changed lines with one line of context. */
|
|
37
|
+
export function formatDiff(a, b) {
|
|
38
|
+
const ops = lineDiff(a, b);
|
|
39
|
+
const keep = ops.map((o, i) => o.t !== " " || (ops[i - 1] !== undefined && ops[i - 1].t !== " ") || (ops[i + 1] !== undefined && ops[i + 1].t !== " "));
|
|
40
|
+
const lines = [];
|
|
41
|
+
let gap = false;
|
|
42
|
+
ops.forEach((o, i) => {
|
|
43
|
+
if (!keep[i]) {
|
|
44
|
+
gap = true;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (gap && lines.length)
|
|
48
|
+
lines.push(" ...");
|
|
49
|
+
gap = false;
|
|
50
|
+
lines.push(`${o.t} ${o.s}`);
|
|
51
|
+
});
|
|
52
|
+
return lines;
|
|
53
|
+
}
|
|
54
|
+
/** Compare the installed copy of one client with the bundled pack. Only files aihub installed (manifest) are looked at. */
|
|
55
|
+
export function diffClient(env, client, opts) {
|
|
56
|
+
const dir = clientDirs(client, env, opts).skills;
|
|
57
|
+
const man = readManifest(dir);
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const e of skillEntries(cliVersion())) {
|
|
60
|
+
const recorded = man.files[e.rel];
|
|
61
|
+
if (!recorded)
|
|
62
|
+
continue;
|
|
63
|
+
const abs = join(dir, e.rel);
|
|
64
|
+
if (!existsSync(abs)) {
|
|
65
|
+
out.push({ rel: e.rel, state: "missing", diff: [] });
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const local = readNorm(abs);
|
|
69
|
+
if (sha256(local) === sha256(e.content))
|
|
70
|
+
continue;
|
|
71
|
+
const edited = sha256(local) !== recorded;
|
|
72
|
+
out.push({ rel: e.rel, state: edited ? "edited" : "behind", diff: edited ? formatDiff(unmark(e.content), unmark(local)) : [] });
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export const trace = { dryRun: false, verbose: false, log: () => { }, plan: () => { } };
|
|
2
|
+
export function setTrace(s) {
|
|
3
|
+
Object.assign(trace, { dryRun: false, verbose: false, log: () => { }, plan: () => { } }, s);
|
|
4
|
+
}
|
|
5
|
+
const READ_ONLY = new Set([
|
|
6
|
+
"rev-parse", "symbolic-ref", "log", "show", "ls-remote", "merge-base", "diff", "diff-tree", "status", "rev-list",
|
|
7
|
+
"for-each-ref", "ls-files", "cat-file", "describe", "blame", "fetch", "version", "--version",
|
|
8
|
+
]);
|
|
9
|
+
/** Subcommand of a git invocation, skipping leading `-c k=v` / `-C dir` options. */
|
|
10
|
+
function subcommand(args) {
|
|
11
|
+
let i = 0;
|
|
12
|
+
while (i < args.length && args[i].startsWith("-"))
|
|
13
|
+
i += args[i] === "-c" || args[i] === "-C" ? 2 : 1;
|
|
14
|
+
return { sub: args[i] ?? "", rest: args.slice(i + 1) };
|
|
15
|
+
}
|
|
16
|
+
/** True when this git invocation can change a repository, a branch, a remote or the configuration. */
|
|
17
|
+
export function isGitWrite(args) {
|
|
18
|
+
const { sub, rest } = subcommand(args);
|
|
19
|
+
if (READ_ONLY.has(sub))
|
|
20
|
+
return false;
|
|
21
|
+
const plain = rest.filter((a) => !a.startsWith("-"));
|
|
22
|
+
const has = (...f) => rest.some((a) => f.includes(a));
|
|
23
|
+
switch (sub) {
|
|
24
|
+
case "config":
|
|
25
|
+
return !(has("--get", "--get-all", "--list", "-l", "--get-regexp") || plain.length < 2);
|
|
26
|
+
case "remote":
|
|
27
|
+
return !(plain.length === 0 || plain[0] === "get-url" || plain[0] === "show");
|
|
28
|
+
case "branch":
|
|
29
|
+
return !(has("--list", "-l", "--show-current", "-a", "-r", "--contains", "--merged", "--no-merged") || plain.length === 0);
|
|
30
|
+
case "worktree":
|
|
31
|
+
return plain[0] !== "list";
|
|
32
|
+
case "tag":
|
|
33
|
+
return !(has("--list", "-l") || plain.length === 0);
|
|
34
|
+
default:
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Called before running git. Returns true when the command must be skipped (dry-run write). */
|
|
39
|
+
export function gitGate(cwd, args) {
|
|
40
|
+
const write = isGitWrite(args);
|
|
41
|
+
if (trace.dryRun && write) {
|
|
42
|
+
trace.plan(`would run: git ${args.join(" ")} (in ${cwd})`);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (trace.verbose)
|
|
46
|
+
trace.log(`+ git ${args.join(" ")} (in ${cwd})`);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
function summarizeValue(v) {
|
|
50
|
+
if (typeof v === "string")
|
|
51
|
+
return `${v.length} chars`;
|
|
52
|
+
if (Array.isArray(v))
|
|
53
|
+
return `${v.length} items`;
|
|
54
|
+
if (v && typeof v === "object")
|
|
55
|
+
return `{${Object.keys(v).join(", ")}}`;
|
|
56
|
+
return JSON.stringify(v);
|
|
57
|
+
}
|
|
58
|
+
/** Short description of a request body: keys with sizes, or the operations of a JSON patch. */
|
|
59
|
+
export function summarizeBody(body) {
|
|
60
|
+
if (body === undefined)
|
|
61
|
+
return "";
|
|
62
|
+
if (Array.isArray(body)) {
|
|
63
|
+
const ops = body.map((o) => (o && typeof o === "object" && "op" in o ? `${o.op} ${o.path ?? ""}` : summarizeValue(o)));
|
|
64
|
+
return `[${ops.join("; ")}]`;
|
|
65
|
+
}
|
|
66
|
+
if (body && typeof body === "object") {
|
|
67
|
+
return `{${Object.entries(body).map(([k, v]) => `${k}: ${summarizeValue(v)}`).join(", ")}}`;
|
|
68
|
+
}
|
|
69
|
+
return summarizeValue(body);
|
|
70
|
+
}
|
|
71
|
+
/** POST endpoints that only read (queries); they run even in a dry-run. */
|
|
72
|
+
const READ_POSTS = /wiql|workitemsbatch|\/search|pullrequestquery|\/queries|\/reporting/i;
|
|
73
|
+
export function isRestWrite(method, path) {
|
|
74
|
+
if (method === "GET" || method === "HEAD")
|
|
75
|
+
return false;
|
|
76
|
+
return !(method === "POST" && READ_POSTS.test(path));
|
|
77
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { dirname, join, sep } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { CLIENTS, clientDirs } from "./clients.js";
|
|
6
|
+
import { AihubError } from "./errors.js";
|
|
7
|
+
import { compareVersions, installedVersion, updateClients } from "./install.js";
|
|
8
|
+
import { cliPackageName, cliVersion, packRoot } from "./pack.js";
|
|
9
|
+
/** npm and aihub are .cmd files on Windows, so they need a shell there. */
|
|
10
|
+
const sysRun = (cmd, args) => {
|
|
11
|
+
const r = spawnSync(cmd, args, { encoding: "utf8", shell: process.platform === "win32", timeout: 300_000 });
|
|
12
|
+
if (r.error || r.status !== 0)
|
|
13
|
+
throw new Error(r.error?.message ?? ((r.stderr || r.stdout || "").trim().split("\n")[0] || `exit ${r.status}`));
|
|
14
|
+
return r.stdout;
|
|
15
|
+
};
|
|
16
|
+
const runner = (ctx) => (cmd, args) => (ctx.exec ? ctx.exec(cmd, args) : sysRun(cmd, args));
|
|
17
|
+
/** `## <version>` sections of CHANGELOG.md newer than `from` and not newer than the running CLI, as one line per bullet. */
|
|
18
|
+
export function changelogSince(from, text, current = cliVersion()) {
|
|
19
|
+
const out = [];
|
|
20
|
+
let version = "";
|
|
21
|
+
for (const line of text.replace(/\r\n/g, "\n").split("\n")) {
|
|
22
|
+
const h = /^##\s+v?(\d+\.\d+\.\d+\S*)/.exec(line);
|
|
23
|
+
if (h) {
|
|
24
|
+
version = h[1];
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (version && /^\s*[-*]\s+/.test(line) && compareVersions(version, from) > 0 && compareVersions(version, current) <= 0) {
|
|
28
|
+
out.push(` ${version}: ${line.replace(/^\s*[-*]\s+/, "")}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
function readChangelog() {
|
|
34
|
+
try {
|
|
35
|
+
const p = join(packRoot(), "CHANGELOG.md");
|
|
36
|
+
return existsSync(p) ? readFileSync(p, "utf8") : "";
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function isGlobalInstall(ctx, run) {
|
|
43
|
+
try {
|
|
44
|
+
const root = realpathSync(run("npm", ["root", "-g"]).trim());
|
|
45
|
+
const raw = ctx.installPath ?? dirname(fileURLToPath(import.meta.url));
|
|
46
|
+
const here = realpathSync(raw);
|
|
47
|
+
return here.toLowerCase().startsWith((root + sep).toLowerCase());
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function skillsLines(ctx, current) {
|
|
54
|
+
const lines = [];
|
|
55
|
+
for (const c of CLIENTS) {
|
|
56
|
+
const v = installedVersion(clientDirs(c, ctx.env, { global: true }).skills);
|
|
57
|
+
if (v)
|
|
58
|
+
lines.push(`skills ${c}: aihub ${v}${compareVersions(v, current) < 0 ? ` (older than the CLI, 'aihub skills update' refreshes it)` : ""}`);
|
|
59
|
+
}
|
|
60
|
+
return lines.length ? lines : ["skills: not installed ('aihub skills install')"];
|
|
61
|
+
}
|
|
62
|
+
export function runUpdate(ctx, o) {
|
|
63
|
+
const run = runner(ctx);
|
|
64
|
+
const name = cliPackageName();
|
|
65
|
+
const current = cliVersion();
|
|
66
|
+
if (o.after !== undefined) {
|
|
67
|
+
const lines = changelogSince(o.after, readChangelog(), current);
|
|
68
|
+
const reports = updateClients([...CLIENTS], ctx.env);
|
|
69
|
+
return { lines: [`aihub ${o.after} -> ${current}`, ...(lines.length ? ["changes:", ...lines] : ["no changelog entries for this range"])], reports };
|
|
70
|
+
}
|
|
71
|
+
let registry = "";
|
|
72
|
+
try {
|
|
73
|
+
registry = run("npm", ["config", "get", "registry"]).trim();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
/* npm missing: the next call reports it */
|
|
77
|
+
}
|
|
78
|
+
let latest;
|
|
79
|
+
try {
|
|
80
|
+
latest = run("npm", ["view", name, "version"]).trim();
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
throw new AihubError(`cannot read the latest version of ${name}${registry ? ` from ${registry}` : ""}: ${e.message}; check your .npmrc (registry and sign-in)`);
|
|
84
|
+
}
|
|
85
|
+
const head = [`${name} ${current}${registry ? ` (registry ${registry})` : ""}`, `latest: ${latest}`];
|
|
86
|
+
const newer = compareVersions(current, latest) < 0;
|
|
87
|
+
const global = isGlobalInstall(ctx, run);
|
|
88
|
+
const cmd = `npm i -g ${name}@latest`;
|
|
89
|
+
if (o.check) {
|
|
90
|
+
return {
|
|
91
|
+
lines: [
|
|
92
|
+
...head,
|
|
93
|
+
newer ? `update available: run 'aihub update'${global ? "" : ` (not a global npm install: run '${cmd}' yourself)`}` : "the CLI is up to date",
|
|
94
|
+
...skillsLines(ctx, current),
|
|
95
|
+
],
|
|
96
|
+
reports: [],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (newer) {
|
|
100
|
+
if (!global) {
|
|
101
|
+
return { lines: [...head, `not detected as a global npm install, so run this yourself: ${cmd}`, "then run 'aihub update' again to refresh the skills"], reports: [] };
|
|
102
|
+
}
|
|
103
|
+
run("npm", ["i", "-g", `${name}@latest`]);
|
|
104
|
+
// the new CLI shows the changelog and refreshes the skills from its own bundled pack
|
|
105
|
+
const after = run("aihub", ["update", "--after", current]);
|
|
106
|
+
return { lines: [...head, `installed ${name}@${latest}`, ...after.trimEnd().split("\n")], reports: [] };
|
|
107
|
+
}
|
|
108
|
+
const reports = updateClients([...CLIENTS], ctx.env);
|
|
109
|
+
return { lines: [...head, "the CLI is up to date", reports.length ? "skills refreshed from the bundled pack:" : "no client has aihub skills yet ('aihub skills install')"], reports };
|
|
110
|
+
}
|
package/dist/router.js
CHANGED
|
@@ -22,6 +22,9 @@ import * as workitem from "./commands/workitem.js";
|
|
|
22
22
|
import * as evidence from "./commands/evidence.js";
|
|
23
23
|
import * as port from "./commands/port.js";
|
|
24
24
|
import * as crossrepo from "./commands/crossrepo.js";
|
|
25
|
+
import * as update from "./commands/update.js";
|
|
26
|
+
import * as explain from "./commands/explain.js";
|
|
27
|
+
import { setTrace } from "./lib/trace.js";
|
|
25
28
|
/**
|
|
26
29
|
* Command registry. To add a command: create src/commands/<name>.ts exporting
|
|
27
30
|
* `run(argv, ctx)` and add one line here. Commands print through ctx.out and
|
|
@@ -49,6 +52,8 @@ export const commands = {
|
|
|
49
52
|
evidence: evidence.run,
|
|
50
53
|
port: port.run,
|
|
51
54
|
crossrepo: crossrepo.run,
|
|
55
|
+
update: update.run,
|
|
56
|
+
explain: explain.run,
|
|
52
57
|
};
|
|
53
58
|
export const VERSION = cliVersion();
|
|
54
59
|
/** Returns the process exit code. */
|
|
@@ -67,15 +72,40 @@ export async function main(argv, ctx, registry = commands) {
|
|
|
67
72
|
ctx.err(`aihub: unknown command '${name}'. Commands: ${Object.keys(registry).join(", ")}.`);
|
|
68
73
|
return 2;
|
|
69
74
|
}
|
|
75
|
+
// global flags: --verbose logs the real git/REST calls; --dry-run prints the writes it would do and skips them
|
|
76
|
+
const ownDryRun = (name === "pr" && rest[0] === "create") || (name === "story" && storyFlow.STORY_FLOW_SUBS.includes(rest[0]));
|
|
77
|
+
const verbose = rest.includes("--verbose");
|
|
78
|
+
const dryRun = rest.includes("--dry-run");
|
|
79
|
+
const args = rest.filter((a) => a !== "--verbose" && (ownDryRun || a !== "--dry-run"));
|
|
80
|
+
let planned = 0;
|
|
81
|
+
setTrace({
|
|
82
|
+
dryRun,
|
|
83
|
+
verbose,
|
|
84
|
+
log: (l) => ctx.err(l),
|
|
85
|
+
plan: (l) => {
|
|
86
|
+
planned++;
|
|
87
|
+
ctx.out(`dry-run: ${l}`);
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const run = dryRun && !ownDryRun ? { ...ctx, out: (l) => ctx.out(` (simulated) ${l}`) } : ctx;
|
|
70
91
|
try {
|
|
71
|
-
await fn(
|
|
92
|
+
await fn(args, run);
|
|
93
|
+
if (dryRun)
|
|
94
|
+
ctx.out(`dry-run: ${planned} planned write(s), nothing was changed`);
|
|
72
95
|
return 0;
|
|
73
96
|
}
|
|
74
97
|
catch (e) {
|
|
98
|
+
if (dryRun && planned > 0) {
|
|
99
|
+
ctx.out(`dry-run: stopped after the planned writes above, because the later steps need the real results (${e.message})`);
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
75
102
|
if (e instanceof AihubError)
|
|
76
103
|
ctx.err(`aihub: ${e.message}`);
|
|
77
104
|
else
|
|
78
105
|
ctx.err(`aihub: unexpected error: ${e.message}`);
|
|
79
106
|
return 1;
|
|
80
107
|
}
|
|
108
|
+
finally {
|
|
109
|
+
setTrace({});
|
|
110
|
+
}
|
|
81
111
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
One `## <version>` heading per release, one bullet per change. `aihub update` shows the bullets between the old and the new version.
|
|
4
|
+
|
|
5
|
+
## 0.1.0
|
|
6
|
+
- `aihub pr create|update`, `comments get|reply`, `story`, `branch`, `cherry-pick`, `pipeline`, `batch`, `work`, `fabric`, `robot` and the other workflow commands.
|
|
7
|
+
- `aihub init` proposes team.yaml and the templates as a pull request; it never overwrites a file.
|
|
8
|
+
- `aihub skills install|update|diff|uninstall` copies the bundled skills and slash commands into opencode, Codex and Copilot.
|
|
9
|
+
- `aihub doctor` checks sign-in, remote, team.yaml, PR template, guideline files and the installed skills.
|
|
10
|
+
- `aihub update [--check]` updates the CLI and the skills; `aihub explain <command>` describes a command step by step.
|
|
11
|
+
- `--dry-run` prints the writes (git and REST) a command would do; `--verbose` logs the real calls.
|
|
12
|
+
- One-line installers (install.ps1, install.sh, Install-aihub.cmd), docs/self-hosting.md and zure-pipelines.yml for teams that run aihub from their own feed.
|
|
13
|
+
- eam-pack/: the copy-ready team files (also the source of ihub init), attached to each GitHub release as ihub-team-pack-<version>.zip.
|
|
14
|
+
- guidelines: in team.yaml: repository files the agent reads first.
|
|
@@ -81,3 +81,6 @@ crossRepo: # cross-repo settings for `aihub port` and `a
|
|
|
81
81
|
fromRepo: <repository> # repository the resources come from (optional)
|
|
82
82
|
paths: ["tests/data/**"] # globs, relative to the source repository root (optional)
|
|
83
83
|
toPath: "" # directory prefix in the target repository, default none (optional)
|
|
84
|
+
|
|
85
|
+
guidelines: # list of repo files the agent reads before writing code or text (optional)
|
|
86
|
+
- docs/guidelines.md
|
|
@@ -38,7 +38,7 @@ Slash commands `/pr /pr-update /cherry-pick /story /refine /review /watch /start
|
|
|
38
38
|
Example: the user sends a pullrequest link, so follow pr-watch with that id.
|
|
39
39
|
|
|
40
40
|
## What the CLI fills
|
|
41
|
-
Templates, target branch, story links and repository come from `team.yaml` (see the [team schema](../_shared/references/team.schema.yaml)). Never ask the user for them.
|
|
41
|
+
Templates, target branch, story links and repository come from `team.yaml` (see the [team schema](../_shared/references/team.schema.yaml)). Never ask the user for them. Read the files listed under `guidelines:` in `team.yaml` (if any) before writing code or text.
|
|
42
42
|
|
|
43
43
|
## If it fails
|
|
44
44
|
Run `aihub doctor` and show its output. If `team.yaml` is missing, tell the user to run `aihub init` in the team repo.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
As a <role>, I want <goal>, so that <benefit>.
|
|
3
|
+
|
|
4
|
+
## Acceptance criteria
|
|
5
|
+
- [ ] <observable result 1>
|
|
6
|
+
- [ ] <observable result 2>
|
|
7
|
+
|
|
8
|
+
## Technical notes
|
|
9
|
+
<constraints, affected components, open questions>
|
|
10
|
+
|
|
11
|
+
## Out of scope
|
|
12
|
+
<what this story deliberately does not do>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Team file for aihub. Every key has one line of explanation. Values below are a synthetic example: replace them.
|
|
2
|
+
# Full schema: skills/_shared/references/team.schema.yaml in the aihub repository; see docs/team-yaml.md there.
|
|
3
|
+
version: 1 # schema version, keep 1
|
|
4
|
+
language: nl # language of stories, PR text and comments (nl or en)
|
|
5
|
+
|
|
6
|
+
azureDevOps:
|
|
7
|
+
organization: ferron-test # Azure DevOps organization name (the part after dev.azure.com/)
|
|
8
|
+
project: test-project # project name
|
|
9
|
+
|
|
10
|
+
repositories: # repositories of the team (at least one)
|
|
11
|
+
- name: test-project # exact repository name in Azure DevOps
|
|
12
|
+
aliases: [tp] # short names you may say in chat, for example "maak een PR in tp"
|
|
13
|
+
defaultTarget: main # branch a new pull request targets
|
|
14
|
+
releaseBranches: ["release/*"] # release branch patterns, used by cherry-pick and release
|
|
15
|
+
|
|
16
|
+
pullRequest:
|
|
17
|
+
template: .azuredevops/pull_request_template.md # path of the PR template in the repository
|
|
18
|
+
title: "{storyId}: {storyTitle}" # title pattern; placeholders {storyId} {storyTitle} {branch}
|
|
19
|
+
emptySection: "n.v.t." # text the CLI writes into a template section that stays empty
|
|
20
|
+
|
|
21
|
+
workItems:
|
|
22
|
+
storyType: User Story # work item type used for stories (Bug, Task, Product Backlog Item, ...)
|
|
23
|
+
storyTemplate: .agents/skills/_shared/assets/story-template.md # story template path
|
|
24
|
+
states:
|
|
25
|
+
active: Active # state set by `aihub story start`
|
|
26
|
+
finished: Done # state set by `aihub story finish`
|
|
27
|
+
|
|
28
|
+
branches:
|
|
29
|
+
feature: "feature/{storyId}-{slug}" # pattern for feature branches
|
|
30
|
+
protected: # branches the CLI never pushes to or force-updates
|
|
31
|
+
- main
|
|
32
|
+
- "release/*"
|
|
33
|
+
|
|
34
|
+
cherryPick:
|
|
35
|
+
groups: # named sets of target branches, used as `aihub cherry-pick --to <group>`
|
|
36
|
+
supported: ["release/1.2", "release/1.3"] # example group: the releases that still get fixes
|
|
37
|
+
|
|
38
|
+
pipelines: # pipelines `aihub pipeline` and `aihub pr watch` follow
|
|
39
|
+
- repository: test-project # repository this pipeline belongs to
|
|
40
|
+
name: test-project-ci # pipeline name or id
|
|
41
|
+
required: true # true: a red run blocks the pull request
|
|
42
|
+
|
|
43
|
+
guidelines: # repository files the agent reads before writing code or text
|
|
44
|
+
- .github/guidelines/aihub.md # example hook: your own rules, see the file itself
|
|
45
|
+
|
|
46
|
+
# Optional sections (see docs/team-yaml.md in the aihub repository): fabric: (workspaces) and robot: (integration tests).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
## Summary
|
|
2
|
+
<what changed and why, in two or three sentences>
|
|
3
|
+
|
|
4
|
+
## Changes
|
|
5
|
+
- <change 1>
|
|
6
|
+
- <change 2>
|
|
7
|
+
|
|
8
|
+
## Tests
|
|
9
|
+
| Test | Result |
|
|
10
|
+
|---|---|
|
|
11
|
+
| <test that was really run> | <pass or fail> |
|
|
12
|
+
|
|
13
|
+
Not run: <what was not tested and why>
|
|
14
|
+
|
|
15
|
+
## Related
|
|
16
|
+
Story: <work item link>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Team guidelines for the agent (example)
|
|
2
|
+
|
|
3
|
+
Replace this text with your own rules. `aihub` and the generic skills tell the agent to read the files listed under
|
|
4
|
+
`guidelines:` in `team.yaml` before it writes code or text.
|
|
5
|
+
|
|
6
|
+
- Write pull requests and stories in Dutch, following the templates.
|
|
7
|
+
- One topic per pull request; no unrelated formatting changes.
|
|
8
|
+
- Name branches `feature/<story id>-<slug>`.
|
|
9
|
+
- Mention what was not tested instead of leaving it out.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**"
|
|
3
|
+
---
|
|
4
|
+
Before writing code, a story or a pull request, read `.github/guidelines/aihub.md` and the files listed under
|
|
5
|
+
`guidelines:` in `.agents/skills/_shared/references/team.yaml`. Use the aihub skills for Azure DevOps work
|
|
6
|
+
(`aihub pr create`, `aihub story create`, ...) instead of improvising the steps.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# aihub team pack
|
|
2
|
+
|
|
3
|
+
The files a team keeps in its own repository: team settings, templates and a hook for your own guidelines. The generic
|
|
4
|
+
skills and the CLI stay outside the repository (`aihub skills install`).
|
|
5
|
+
|
|
6
|
+
Two ways to get them:
|
|
7
|
+
|
|
8
|
+
1. Run `aihub init` in the repository. It copies exactly these files (without overwriting anything), fills in the
|
|
9
|
+
organization, project, repository and default branch from the git remote, and opens a pull request.
|
|
10
|
+
2. Copy these folders into the root of your repository yourself, adjust `team.yaml`, and open a pull request.
|
|
11
|
+
|
|
12
|
+
| File | What it is |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `.agents/skills/_shared/references/team.yaml` | Team settings, every key explained. Replace the example values (`ferron-test`, `test-project`). |
|
|
15
|
+
| `.agents/skills/_shared/assets/story-template.md`, `commit-template.txt` | Story and commit templates in Dutch. |
|
|
16
|
+
| `.agents/skills/_shared/assets/*.en.*`, `.azuredevops/pull_request_template.en.md` | English variants: delete the Dutch file and remove `.en` from the name. `aihub init --language en` does this for you. |
|
|
17
|
+
| `.azuredevops/pull_request_template.md` | Pull request template (Dutch). Skip it if your repository already has one. |
|
|
18
|
+
| `.github/instructions/aihub.instructions.md`, `.github/guidelines/aihub.md` | Example hook for your own guidelines (GitHub Copilot instructions plus a guideline file listed under `guidelines:` in `team.yaml`). Only copied by hand; `aihub init` does not write them. |
|
|
19
|
+
|
|
20
|
+
After copying run `aihub doctor`. Change the files later through a pull request.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ferronhooi/aihub",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.11",
|
|
4
4
|
"description": "One small CLI for Azure DevOps team workflows used by coding agents (stories, pull requests, reviews, cherry-picks).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|