@ferronhooi/aihub 0.1.0-next.8 → 0.1.0-next.9

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.
@@ -6,13 +6,13 @@ export async function run(argv, ctx) {
6
6
  try {
7
7
  v = parseArgs({
8
8
  args: argv,
9
- options: { repo: { type: "string" }, "no-pr": { type: "boolean" }, language: { type: "string" } },
9
+ options: { repo: { type: "string" }, "no-pr": { type: "boolean" }, language: { type: "string" }, "into-repo": { type: "boolean" } },
10
10
  }).values;
11
11
  }
12
12
  catch (e) {
13
13
  throw new AihubError(e.message);
14
14
  }
15
- const r = await runInit(ctx, { repo: v.repo, noPr: !!v["no-pr"], language: v.language });
15
+ const r = await runInit(ctx, { repo: v.repo, noPr: !!v["no-pr"], language: v.language, intoRepo: !!v["into-repo"] });
16
16
  for (const l of reportInit(r))
17
17
  ctx.out(l);
18
18
  }
@@ -1,7 +1,12 @@
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 { installClients, parseClients, uninstallClients } from "../lib/install.js";
4
+ 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
+ " install copy the bundled skills and slash commands into each client's global folder\n" +
7
+ " update rewrite the copies of every client that has them from the bundled pack (files you edited stay)\n" +
8
+ " uninstall remove only the files aihub wrote and you did not change\n" +
9
+ " --into-repo use the current repository instead of the global folders (for teams that keep skills in the repo)";
5
10
  function report(reports, out) {
6
11
  for (const r of reports) {
7
12
  const count = (a) => r.results.filter((x) => x.action === a).length;
@@ -13,11 +18,11 @@ function report(reports, out) {
13
18
  }
14
19
  export async function run(argv, ctx) {
15
20
  const [sub, ...rest] = argv;
16
- if (sub !== "install" && sub !== "uninstall")
17
- throw new AihubError("usage: aihub skills install|uninstall [--global] [--client opencode|github-copilot|codex|all]");
21
+ if (sub !== "install" && sub !== "update" && sub !== "uninstall")
22
+ throw new AihubError(USAGE);
18
23
  let v;
19
24
  try {
20
- v = parseArgs({ args: rest, options: { global: { type: "boolean" }, client: { type: "string" } } }).values;
25
+ v = parseArgs({ args: rest, options: { global: { type: "boolean" }, "into-repo": { type: "boolean" }, client: { type: "string" } } }).values;
21
26
  }
22
27
  catch (e) {
23
28
  throw new AihubError(e.message);
@@ -29,16 +34,25 @@ export async function run(argv, ctx) {
29
34
  catch (e) {
30
35
  throw new AihubError(e.message);
31
36
  }
32
- const global = !!v.global;
33
- let root;
34
- if (!global) {
37
+ let opts = { global: true };
38
+ if (v["into-repo"]) {
35
39
  try {
36
- root = repoRoot(ctx.cwd);
40
+ opts = { global: false, root: repoRoot(ctx.cwd) };
37
41
  }
38
42
  catch {
39
- throw new AihubError("not inside a git repository: run in a repository for a project install, or add --global");
43
+ throw new AihubError("--into-repo needs a git repository: cd into the repository first");
40
44
  }
41
45
  }
42
- const opts = { global, root };
43
- report(sub === "install" ? installClients(clients, ctx.env, opts) : uninstallClients(clients, ctx.env, opts), ctx.out);
46
+ if (sub === "install")
47
+ report(installClients(clients, ctx.env, opts), ctx.out);
48
+ else if (sub === "uninstall")
49
+ report(uninstallClients(clients, ctx.env, opts), ctx.out);
50
+ else {
51
+ if (!opts.global)
52
+ throw new AihubError("'aihub skills update' refreshes the global copies; for the repository run 'aihub skills install --into-repo' again");
53
+ const r = updateClients(clients, ctx.env);
54
+ if (!r.length)
55
+ throw new AihubError("no client has aihub skills yet; run 'aihub skills install'");
56
+ report(r, ctx.out);
57
+ }
44
58
  }
@@ -6,7 +6,8 @@ import { parseRemote } from "./ado.js";
6
6
  import { defaultExec, ADO_RESOURCE } from "./auth.js";
7
7
  import { CLIENTS, clientDirs } from "./clients.js";
8
8
  import { originDefaultBranch, remoteUrl, repoRoot, showFile } from "./git.js";
9
- import { packRoot } from "./pack.js";
9
+ import { compareVersions, installedVersion } from "./install.js";
10
+ import { cliVersion, packRoot } from "./pack.js";
10
11
  import { requiredPaths, validateTeam } from "./schema.js";
11
12
  import { defaultTargetFor, loadTeam, readUtf8, TEAM_FILE } from "./team.js";
12
13
  import { resolveTemplate } from "./templates.js";
@@ -102,14 +103,21 @@ export function runChecks(ctx) {
102
103
  ? ok("pr-template", `${tpl.path} (${tpl.from === "ref" ? `on origin/${target}` : "in the working tree only"})`)
103
104
  : fix("pr-template", "no pull request template found", "run 'aihub init' or add .azuredevops/pull_request_template.md"));
104
105
  }
106
+ const current = cliVersion();
105
107
  for (const c of CLIENTS) {
106
- const places = [
108
+ const found = [
107
109
  { label: "global", dir: clientDirs(c, ctx.env, { global: true }).skills },
108
110
  ...(root ? [{ label: "project", dir: clientDirs(c, ctx.env, { global: false, root }).skills }] : []),
109
- ].filter((p) => existsSync(join(p.dir, "start-here", "SKILL.md")));
110
- checks.push(places.length
111
- ? ok(`skills:${c}`, places.map((p) => `${p.label} (${p.dir})`).join(", "))
112
- : fix(`skills:${c}`, "aihub skills not installed", `aihub skills install --client ${c} --global`));
111
+ ]
112
+ .map((p) => ({ ...p, version: installedVersion(p.dir) }))
113
+ .filter((p) => p.version !== undefined);
114
+ const stale = found.filter((p) => compareVersions(p.version, current) < 0);
115
+ const where = found.map((p) => `${p.label} ${p.dir} (aihub ${p.version})`).join(", ");
116
+ checks.push(!found.length
117
+ ? fix(`skills:${c}`, "aihub skills not installed", `aihub skills install --client ${c}`)
118
+ : stale.length
119
+ ? fix(`skills:${c}`, `stale copy, older than the CLI ${current}: ${where}`, "run 'aihub skills update'")
120
+ : ok(`skills:${c}`, where));
113
121
  }
114
122
  return checks;
115
123
  }
package/dist/lib/init.js CHANGED
@@ -56,11 +56,13 @@ export function planFiles(root, o) {
56
56
  ];
57
57
  if (!found)
58
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)) });
59
+ if (o.intoRepo) {
60
+ for (const f of listFiles(join(pack, "commands", "opencode"))) {
61
+ plan.push({ path: `.opencode/command/${f}`, content: readPackFile(join(pack, "commands", "opencode", f)) });
62
+ }
63
+ for (const f of listFiles(join(pack, "commands", "copilot"))) {
64
+ plan.push({ path: `.github/prompts/${f}`, content: readPackFile(join(pack, "commands", "copilot", f)) });
65
+ }
64
66
  }
65
67
  return { plan, skips: found ? { [PR_TEMPLATE]: `a pull request template already exists (${found})` } : {} };
66
68
  }
@@ -88,8 +90,8 @@ function prBody(language, r) {
88
90
  `## ${nl ? "Beschrijving" : "Description"}`,
89
91
  "",
90
92
  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
+ ? "Voorstel van `aihub init` voor het teampakket: teambestand en sjablonen. Bestaande bestanden zijn niet aangepast. Controleer de waarden in `team.yaml` voor het mergen."
94
+ : "Proposal from `aihub init` for the team pack: team file and templates. Existing files were not changed. Check the values in `team.yaml` before merging.",
93
95
  "",
94
96
  nl ? "Aangemaakt:" : "Created:",
95
97
  list(r.created),
@@ -104,7 +106,7 @@ export async function runInit(ctx, o) {
104
106
  const root = repoRoot(resolve(ctx.cwd, o.repo ?? "."));
105
107
  const remote = parseRemote(remoteUrl(root));
106
108
  const target = originDefaultBranch(root) || "main";
107
- const info = { org: remote.org, project: remote.project, repo: remote.repo, target, language };
109
+ const info = { org: remote.org, project: remote.project, repo: remote.repo, target, language, intoRepo: !!o.intoRepo };
108
110
  if (o.noPr) {
109
111
  const p = planFiles(root, info);
110
112
  return writePlanned(root, p.plan, p.skips);
@@ -139,3 +139,40 @@ export function uninstallClients(clients, env, opts) {
139
139
  }
140
140
  return out;
141
141
  }
142
+ /** The aihub version in the marker of an installed skills folder, or undefined when none is installed. */
143
+ export function installedVersion(skillsDir) {
144
+ try {
145
+ return /aihub (\S+?) (?:-->|$)/m.exec(readFileSync(join(skillsDir, "start-here", "SKILL.md"), "utf8"))?.[1];
146
+ }
147
+ catch {
148
+ return undefined;
149
+ }
150
+ }
151
+ /** Negative when a is older than b (semver-like; a prerelease is older than its release). */
152
+ export function compareVersions(a, b) {
153
+ const parse = (v) => {
154
+ const m = /^(\d+)\.(\d+)\.(\d+)(?:-(.+))?/.exec(v);
155
+ return m ? { n: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] } : { n: [0, 0, 0], pre: v };
156
+ };
157
+ const x = parse(a);
158
+ const y = parse(b);
159
+ for (let i = 0; i < 3; i++)
160
+ if (x.n[i] !== y.n[i])
161
+ return x.n[i] - y.n[i];
162
+ if (x.pre === y.pre)
163
+ return 0;
164
+ if (!x.pre)
165
+ return 1;
166
+ if (!y.pre)
167
+ return -1;
168
+ return x.pre.localeCompare(y.pre, undefined, { numeric: true });
169
+ }
170
+ /** Does this client already have aihub skills in its global folder? */
171
+ export function clientHasInstall(env, client) {
172
+ const d = clientDirs(client, env, { global: true });
173
+ return installedVersion(d.skills) !== undefined || Object.keys(readManifest(d.skills).files).length > 0;
174
+ }
175
+ /** Rewrite the copies of every selected client that has them from the bundled pack. */
176
+ export function updateClients(clients, env) {
177
+ return installClients(clients.filter((c) => clientHasInstall(env, c)), env, { global: true });
178
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ferronhooi/aihub",
3
- "version": "0.1.0-next.8",
3
+ "version": "0.1.0-next.9",
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",