@mp-lb/forum-cli 0.1.46 → 0.1.48

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/index.js CHANGED
@@ -17251,7 +17251,6 @@ var fileTypeIdSchema = external_exports.union([
17251
17251
  external_exports.literal("experiment"),
17252
17252
  external_exports.literal("invoice"),
17253
17253
  external_exports.literal("list"),
17254
- external_exports.literal("skills"),
17255
17254
  external_exports.literal("lottie"),
17256
17255
  external_exports.literal("meta_ad_campaign"),
17257
17256
  external_exports.literal("resume"),
@@ -17268,12 +17267,6 @@ var fileTypeIdSchema = external_exports.union([
17268
17267
  external_exports.literal("unknown")
17269
17268
  ]);
17270
17269
  var fileTypeDefinitions = [
17271
- {
17272
- id: "skills",
17273
- label: "Skills index",
17274
- extensions: [".skills.json"],
17275
- storageClass: textStorageClass
17276
- },
17277
17270
  {
17278
17271
  id: "asset-library",
17279
17272
  label: "Asset Library",
@@ -22669,41 +22662,6 @@ var redeemPromoCodeResultSchema = external_exports.object({
22669
22662
  grantAmount: external_exports.number().int().nonnegative()
22670
22663
  });
22671
22664
 
22672
- // ../../packages/core/src/skills/skillIndexSchema.ts
22673
- var skillSlugSchema = external_exports.string().min(1).max(64).regex(
22674
- /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
22675
- "Use lowercase letters, numbers, and single hyphens."
22676
- );
22677
- var skillStorePathSchema = external_exports.string().min(1).max(1024).regex(
22678
- // eslint-disable-next-line no-control-regex -- Store paths must reject control characters.
22679
- /^(?!\.{1,2}(?:\/|$))(?!.*\/\.{1,2}(?:\/|$))[^/\\:\u0000-\u001f\u007f]+(?:\/[^/\\:\u0000-\u001f\u007f]+)*$/,
22680
- "Use a path from the store root, without a leading slash, URL, or dot segments."
22681
- );
22682
- var skillIndexPathSchema = skillStorePathSchema.regex(/\.skills\.json$/i);
22683
- var skillDocumentPathSchema = skillStorePathSchema.regex(/\.(md|markdown)$/i);
22684
- var skillIndexItemSchema = external_exports.strictObject({
22685
- slug: skillSlugSchema,
22686
- description: external_exports.string().trim().min(1).max(1024),
22687
- path: skillDocumentPathSchema
22688
- });
22689
- var skillIndexSchema = external_exports.strictObject({
22690
- $schema: external_exports.string().optional(),
22691
- version: external_exports.literal(1),
22692
- items: external_exports.array(skillIndexItemSchema)
22693
- }).superRefine((index, ctx) => {
22694
- const slugs = /* @__PURE__ */ new Set();
22695
- index.items.forEach((item, position) => {
22696
- if (slugs.has(item.slug)) {
22697
- ctx.addIssue({
22698
- code: "custom",
22699
- path: ["items", position, "slug"],
22700
- message: `Duplicate skill: ${item.slug}`
22701
- });
22702
- }
22703
- slugs.add(item.slug);
22704
- });
22705
- });
22706
-
22707
22665
  // ../../packages/core/src/structuredFileSchemas.ts
22708
22666
  var structuredSchemaReferenceShape = {
22709
22667
  $schema: external_exports.string().url().optional()
@@ -23524,7 +23482,6 @@ var creatableFileTypeSections = [
23524
23482
  t("board", "Board", ".board.json"),
23525
23483
  t("calendar", "Calendar", ".calendar.json"),
23526
23484
  t("list", "List", ".list.json"),
23527
- t("skills", "Skills index", ".skills.json"),
23528
23485
  t("data-table", "Data table", ".table.json"),
23529
23486
  t("spreadsheet", "Spreadsheet", ".sheet.json"),
23530
23487
  t("experiment", "Experimental tracker", ".experiment.json"),
@@ -23687,6 +23644,42 @@ var storeMemberSchema = external_exports.object({
23687
23644
  createdAt: external_exports.string().datetime().default(() => (/* @__PURE__ */ new Date()).toISOString())
23688
23645
  });
23689
23646
 
23647
+ // ../../packages/core/src/skills/skillSchemas.ts
23648
+ var skillSlugSchema = external_exports.string().min(1).max(64).regex(
23649
+ /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
23650
+ "Use lowercase letters, numbers, and single hyphens."
23651
+ );
23652
+ var skillStorePathSchema = external_exports.string().min(1).max(1024).regex(
23653
+ // eslint-disable-next-line no-control-regex -- Reject control characters in store paths.
23654
+ /^(?!\.{1,2}(?:\/|$))(?!.*\/\.{1,2}(?:\/|$))[^/\\:\u0000-\u001f\u007f]+(?:\/[^/\\:\u0000-\u001f\u007f]+)*$/,
23655
+ "Use a store path without URLs, backslashes, or dot segments."
23656
+ );
23657
+ var skillDocumentPathSchema = skillStorePathSchema.regex(/\.(md|markdown)$/i);
23658
+ var skillFolderSchema = external_exports.string().transform((value) => value === "." ? "" : value.replace(/^\/+|\/+$/g, "")).pipe(external_exports.union([external_exports.literal(""), skillStorePathSchema])).transform((value) => value ? `/${value}` : "/");
23659
+ var skillMetadataSchema = external_exports.object({
23660
+ name: skillSlugSchema,
23661
+ description: external_exports.string().trim().min(1).max(1024)
23662
+ });
23663
+ var discoveredSkillSchema = external_exports.object({
23664
+ slug: skillSlugSchema,
23665
+ description: external_exports.string().min(1).max(1024),
23666
+ path: skillDocumentPathSchema
23667
+ });
23668
+ var skillScanSchema = external_exports.object({
23669
+ storeId: external_exports.string(),
23670
+ workspaceId: external_exports.string(),
23671
+ folder: skillFolderSchema,
23672
+ markdownCount: external_exports.number().int().nonnegative(),
23673
+ skills: external_exports.array(discoveredSkillSchema),
23674
+ problems: external_exports.array(
23675
+ external_exports.object({
23676
+ path: external_exports.string(),
23677
+ kind: external_exports.enum(["invalid", "unconfigured"]),
23678
+ message: external_exports.string()
23679
+ })
23680
+ )
23681
+ });
23682
+
23690
23683
  // ../../packages/store-tree/src/patterns.ts
23691
23684
  var escapeRegex2 = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
23692
23685
  var basename2 = (path25) => {
@@ -31411,7 +31404,8 @@ var retrySafeOperations = /* @__PURE__ */ new Set([
31411
31404
  "files.search",
31412
31405
  "files.readFile",
31413
31406
  "files.readFileByRef",
31414
- "skills.readIndex",
31407
+ "skills.scan",
31408
+ "skills.folders",
31415
31409
  "skills.read",
31416
31410
  "files.listFileVersions",
31417
31411
  "files.listFileVersionsByRef",
@@ -31519,7 +31513,8 @@ var createStoreClient = ({
31519
31513
  "files.deleteFileByRef",
31520
31514
  () => trpc.files.deleteFileByRef.mutate(input)
31521
31515
  ),
31522
- readSkillIndex: (input) => call("skills.readIndex", () => trpc.skills.readIndex.query(input)),
31516
+ scanSkills: (input) => call("skills.scan", () => trpc.skills.scan.query(input)),
31517
+ listSkillFolders: (input) => call("skills.folders", () => trpc.skills.folders.query(input)),
31523
31518
  readSkill: (input) => call("skills.read", () => trpc.skills.read.query(input)),
31524
31519
  readUserPreferences: () => call("userPreferences.read", () => trpc.userPreferences.read.query({})),
31525
31520
  upsertUserPreferences: (input) => call(
@@ -31727,27 +31722,128 @@ var parseSkillAgents = (value) => {
31727
31722
  return [...new Set(agents)];
31728
31723
  };
31729
31724
 
31730
- // src/skills/parseSkillIndexPath.ts
31731
- import { InvalidArgumentError as InvalidArgumentError2 } from "commander";
31732
- var parseSkillIndexPath = (value) => {
31733
- const result = skillIndexPathSchema.safeParse(value.replace(/^\//, ""));
31734
- if (!result.success)
31735
- throw new InvalidArgumentError2(
31736
- "Expected a store-relative .skills.json path without dot segments."
31737
- );
31738
- return result.data;
31739
- };
31740
-
31741
31725
  // src/skills/loadSkillsCommand.ts
31742
31726
  import os2 from "os";
31743
31727
 
31728
+ // src/skills/createSkillClient.ts
31729
+ import path18 from "path";
31730
+ var createSkillClient = async (options2) => {
31731
+ const stateDir = options2.stateDir ? path18.resolve(options2.stateDir) : defaultStateDir();
31732
+ const saved = await readConfig(stateDir);
31733
+ const apiBaseUrl = (process.env.DOCTRINE_API_URL || DEFAULT_API_BASE_URL).replace(/\/+$/, "");
31734
+ const token = options2.token || process.env.DOCTRINE_TOKEN || saved.token;
31735
+ return { client: createClient({ apiBaseUrl, token }), apiBaseUrl };
31736
+ };
31737
+
31738
+ // src/skills/skillConnectionOptions.ts
31739
+ var skillConnectionOptions = external_exports.object({
31740
+ store: external_exports.string().min(1).optional(),
31741
+ folder: skillFolderSchema.optional(),
31742
+ agents: external_exports.array(external_exports.enum(["codex", "claude"])).min(1).optional(),
31743
+ global: external_exports.boolean().optional(),
31744
+ interactive: external_exports.boolean().default(false),
31745
+ dryRun: external_exports.boolean().default(false),
31746
+ json: external_exports.boolean().default(false),
31747
+ token: external_exports.string().optional(),
31748
+ stateDir: external_exports.string().optional()
31749
+ });
31750
+
31751
+ // src/skills/parseSkillStore.ts
31752
+ var parseSkillStore = (store) => {
31753
+ const segments2 = store.split("/");
31754
+ return storeRefSchema.parse(
31755
+ segments2.length === 2 ? { workspaceSlug: segments2[0], storeSlug: segments2[1] } : segments2.length === 1 ? { storeId: store } : {}
31756
+ );
31757
+ };
31758
+
31759
+ // src/skills/promptSkillConnection.ts
31760
+ import enquirer2 from "enquirer";
31761
+
31762
+ // src/skills/promptSkillStore.ts
31763
+ import enquirer from "enquirer";
31764
+ var promptSkillStore = async (client) => {
31765
+ let workspaceSlug;
31766
+ while (true) {
31767
+ const stores = await client.listStores({ workspaceSlug });
31768
+ const { store } = await enquirer.prompt({
31769
+ type: "select",
31770
+ name: "store",
31771
+ message: "Which store contains your skills?",
31772
+ stdout: process.stderr,
31773
+ choices: [
31774
+ ...stores.filter((store2) => !store2.archivedAt && !store2.deletedAt).map((store2) => ({
31775
+ name: store2.id,
31776
+ message: [store2.workspaceSlug, store2.slug].filter(Boolean).join("/")
31777
+ })),
31778
+ { name: "another-workspace", message: "Choose another workspace\u2026" }
31779
+ ]
31780
+ });
31781
+ if (store !== "another-workspace") return store;
31782
+ const answer = await enquirer.prompt({
31783
+ type: "input",
31784
+ name: "workspace",
31785
+ message: "Workspace slug",
31786
+ stdout: process.stderr,
31787
+ required: true
31788
+ });
31789
+ workspaceSlug = answer.workspace.trim();
31790
+ }
31791
+ };
31792
+
31793
+ // src/skills/promptSkillConnection.ts
31794
+ var promptSkillConnection = async (client, input) => {
31795
+ const store = input.store ?? await promptSkillStore(client);
31796
+ let folder = input.folder;
31797
+ if (folder === void 0) {
31798
+ const folders = await client.listSkillFolders(parseSkillStore(store));
31799
+ if (!folders.length)
31800
+ throw new Error(
31801
+ "This store has no Markdown files. Create a Markdown document in Forum, then run fm skills -i again."
31802
+ );
31803
+ folder = (await enquirer2.prompt({
31804
+ type: "select",
31805
+ name: "folder",
31806
+ message: "Which folder?",
31807
+ stdout: process.stderr,
31808
+ choices: folders.map((item) => ({
31809
+ name: item.folder,
31810
+ message: `${item.folder} (${item.markdownCount} Markdown files)`
31811
+ }))
31812
+ })).folder;
31813
+ }
31814
+ const agents = input.agents ?? parseSkillAgents(
31815
+ (await enquirer2.prompt({
31816
+ type: "select",
31817
+ name: "agents",
31818
+ message: "Connect to which agents on this computer?",
31819
+ stdout: process.stderr,
31820
+ choices: [
31821
+ { name: "all", message: "Codex and Claude Code" },
31822
+ { name: "codex", message: "Codex" },
31823
+ { name: "claude", message: "Claude Code" }
31824
+ ]
31825
+ })).agents
31826
+ );
31827
+ const global = input.global ?? (await enquirer2.prompt({
31828
+ type: "select",
31829
+ name: "scope",
31830
+ message: "Where should these skills be available?",
31831
+ stdout: process.stderr,
31832
+ choices: [
31833
+ { name: "project", message: `This project (${process.cwd()})` },
31834
+ { name: "global", message: "All projects on this computer" }
31835
+ ]
31836
+ })).scope === "global";
31837
+ return { ...input, store, folder, agents, global };
31838
+ };
31839
+
31744
31840
  // src/skills/loadSkillStubs.ts
31745
31841
  import { lstat as lstat4, mkdir as mkdir6, open, unlink } from "fs/promises";
31746
- import path21 from "path";
31842
+ import path22 from "path";
31747
31843
 
31748
31844
  // src/skills/planSkillStubs.ts
31749
31845
  import { lstat as lstat3, readdir as readdir5, readFile as readFile8 } from "fs/promises";
31750
- import path19 from "path";
31846
+ import path20 from "path";
31751
31847
  import { isDeepStrictEqual } from "util";
31752
31848
 
31753
31849
  // src/skills/createSkillStub.ts
@@ -31762,20 +31858,20 @@ var createSkillStub = (item, source) => [
31762
31858
  "This skill's instructions live in Forum. Before using the skill, fetch them:",
31763
31859
  "",
31764
31860
  "```sh",
31765
- `DOCTRINE_API_URL=${quote(source.apiBaseUrl)} fm skills read ${quote(item.slug)} --store ${quote(source.storeId)} --index ${quote(source.indexPath)}`,
31861
+ `DOCTRINE_API_URL=${quote(source.apiBaseUrl)} fm skills read ${quote(item.slug)} --store ${quote(source.storeId)} --folder ${quote(source.folder)}`,
31766
31862
  "```",
31767
31863
  "",
31768
31864
  "Read and follow the returned instructions. If the fetch fails, report the error and do not substitute the description or previously fetched instructions.",
31769
31865
  "The response identifies the source store, document path, and revision. Resolve supporting document paths in that Forum store, relative to the source document, and fetch them with fm read. They are not files next to this local stub.",
31770
31866
  "Fetch current instructions when starting a new use of this skill. Instructions already loaded into a task do not update automatically.",
31771
31867
  "",
31772
- "Generated by fm skills load. Edit the index and instructions in Forum, then reload the index to refresh discovery metadata.",
31868
+ "Generated by fm skills. Edit the Markdown metadata and instructions in Forum, then reconnect the folder to refresh discovery metadata.",
31773
31869
  ""
31774
31870
  ].join("\n");
31775
31871
 
31776
31872
  // src/skills/readSkillStubMarker.ts
31777
31873
  import { lstat as lstat2, readFile as readFile7, readdir as readdir4 } from "fs/promises";
31778
- import path18 from "path";
31874
+ import path19 from "path";
31779
31875
  import { createHash as createHash3 } from "crypto";
31780
31876
  var readSkillStubMarker = async (directory) => {
31781
31877
  const stat4 = await lstat2(directory).catch((error51) => {
@@ -31787,7 +31883,7 @@ var readSkillStubMarker = async (directory) => {
31787
31883
  throw new Error(
31788
31884
  `Skill destination is not a regular directory: ${directory}`
31789
31885
  );
31790
- const markerPath = path18.join(directory, ".forum-skill.json");
31886
+ const markerPath = path19.join(directory, ".forum-skill.json");
31791
31887
  const names = await readdir4(directory);
31792
31888
  if (!names.includes(".forum-skill.json")) return null;
31793
31889
  const markerStat = await lstat2(markerPath);
@@ -31796,14 +31892,14 @@ var readSkillStubMarker = async (directory) => {
31796
31892
  const marker = JSON.parse(
31797
31893
  await readFile7(markerPath, "utf8")
31798
31894
  );
31799
- if (marker.version !== 1 || typeof marker.source?.storeId !== "string" || typeof marker.source?.indexPath !== "string" || typeof marker.source?.apiBaseUrl !== "string" || typeof marker.hash !== "string") {
31895
+ if (marker.version !== 1 || typeof marker.source?.storeId !== "string" || typeof marker.source?.folder !== "string" || typeof marker.source?.apiBaseUrl !== "string" || typeof marker.hash !== "string") {
31800
31896
  throw new Error(`Invalid Forum skill marker: ${markerPath}`);
31801
31897
  }
31802
31898
  if (names.some((name) => name !== "SKILL.md" && name !== ".forum-skill.json"))
31803
31899
  throw new Error(
31804
31900
  `Skill contains local files; refusing to replace it: ${directory}`
31805
31901
  );
31806
- const stubPath = path18.join(directory, "SKILL.md");
31902
+ const stubPath = path19.join(directory, "SKILL.md");
31807
31903
  const stubStat = await lstat2(stubPath);
31808
31904
  if (!stubStat.isFile() || stubStat.isSymbolicLink())
31809
31905
  throw new Error(`Invalid generated skill: ${stubPath}`);
@@ -31825,8 +31921,8 @@ var planSkillStubs = async (input, roots) => {
31825
31921
  throw error51;
31826
31922
  }
31827
31923
  );
31828
- for (const item of input.index.items) {
31829
- const destination = path19.join(root, item.slug);
31924
+ for (const item of input.skills) {
31925
+ const destination = path20.join(root, item.slug);
31830
31926
  const exists2 = directories.some((entry) => entry.name === item.slug);
31831
31927
  const marker = exists2 ? await readSkillStubMarker(destination) : null;
31832
31928
  if (exists2 && (!marker || !isDeepStrictEqual(marker.source, input.source)))
@@ -31834,7 +31930,7 @@ var planSkillStubs = async (input, roots) => {
31834
31930
  `Skill name collision: ${destination}. Choose a different slug; existing skills are never overwritten.`
31835
31931
  );
31836
31932
  const content = createSkillStub(item, input.source);
31837
- const unchanged = marker && await readFile8(path19.join(destination, "SKILL.md"), "utf8") === content;
31933
+ const unchanged = marker && await readFile8(path20.join(destination, "SKILL.md"), "utf8") === content;
31838
31934
  changes.push({
31839
31935
  agent,
31840
31936
  slug: item.slug,
@@ -31843,12 +31939,12 @@ var planSkillStubs = async (input, roots) => {
31843
31939
  content
31844
31940
  });
31845
31941
  }
31846
- const slugs = new Set(input.index.items.map((item) => item.slug));
31942
+ const slugs = new Set(input.skills.map((item) => item.slug));
31847
31943
  for (const entry of directories) {
31848
31944
  if (!entry.isDirectory() || entry.isSymbolicLink() || slugs.has(entry.name) || entry.name.startsWith("."))
31849
31945
  continue;
31850
- const destination = path19.join(root, entry.name);
31851
- const markerPath = path19.join(destination, ".forum-skill.json");
31946
+ const destination = path20.join(root, entry.name);
31947
+ const markerPath = path20.join(destination, ".forum-skill.json");
31852
31948
  const markerStat = await lstat3(markerPath).catch(
31853
31949
  (error51) => {
31854
31950
  if (error51.code === "ENOENT") return null;
@@ -31873,14 +31969,14 @@ var planSkillStubs = async (input, roots) => {
31873
31969
  // src/skills/applySkillStubChanges.ts
31874
31970
  import { createHash as createHash4 } from "crypto";
31875
31971
  import { mkdtemp, rename as rename4, rm as rm4, writeFile as writeFile5 } from "fs/promises";
31876
- import path20 from "path";
31972
+ import path21 from "path";
31877
31973
  var applySkillStubChanges = async (changes, source) => {
31878
31974
  const applied = [];
31879
31975
  try {
31880
31976
  for (const change of changes) {
31881
31977
  if (change.action === "unchanged") continue;
31882
31978
  const temporary = await mkdtemp(
31883
- path20.join(path20.dirname(change.path), ".forum-skills-")
31979
+ path21.join(path21.dirname(change.path), ".forum-skills-")
31884
31980
  );
31885
31981
  const entry = {
31886
31982
  change,
@@ -31896,9 +31992,9 @@ var applySkillStubChanges = async (changes, source) => {
31896
31992
  source,
31897
31993
  hash: createHash4("sha256").update(content).digest("hex")
31898
31994
  };
31899
- await writeFile5(path20.join(temporary, "SKILL.md"), content, "utf8");
31995
+ await writeFile5(path21.join(temporary, "SKILL.md"), content, "utf8");
31900
31996
  await writeFile5(
31901
- path20.join(temporary, ".forum-skill.json"),
31997
+ path21.join(temporary, ".forum-skill.json"),
31902
31998
  `${JSON.stringify(marker, null, 2)}
31903
31999
  `,
31904
32000
  "utf8"
@@ -31930,17 +32026,20 @@ var applySkillStubChanges = async (changes, source) => {
31930
32026
 
31931
32027
  // src/skills/loadSkillStubs.ts
31932
32028
  var loadSkillStubs = async (input) => {
31933
- skillIndexSchema.parse(input.index);
31934
- skillIndexPathSchema.parse(input.source.indexPath);
31935
- const base = path21.resolve(input.global ? input.home : input.directory);
32029
+ discoveredSkillSchema.array().parse(input.skills);
32030
+ if (skillFolderSchema.parse(input.source.folder) !== input.source.folder)
32031
+ throw new Error("Use a canonical store folder path.");
32032
+ if (new Set(input.skills.map((skill) => skill.slug)).size !== input.skills.length)
32033
+ throw new Error("Duplicate skill names in collection.");
32034
+ const base = path22.resolve(input.global ? input.home : input.directory);
31936
32035
  const roots = [...new Set(input.agents)].map((agent) => ({
31937
32036
  agent,
31938
- root: path21.join(base, agent === "codex" ? ".agents" : ".claude", "skills")
32037
+ root: path22.join(base, agent === "codex" ? ".agents" : ".claude", "skills")
31939
32038
  }));
31940
32039
  const locks = [];
31941
32040
  try {
31942
32041
  for (const { root } of roots) {
31943
- for (const directory of [path21.dirname(root), root]) {
32042
+ for (const directory of [path22.dirname(root), root]) {
31944
32043
  const stat4 = await lstat4(directory).catch(
31945
32044
  (error51) => {
31946
32045
  if (error51.code === "ENOENT") return null;
@@ -31954,7 +32053,7 @@ var loadSkillStubs = async (input) => {
31954
32053
  }
31955
32054
  if (!input.dryRun) {
31956
32055
  await mkdir6(root, { recursive: true });
31957
- const lockPath = path21.join(root, ".forum-skills.lock");
32056
+ const lockPath = path22.join(root, ".forum-skills.lock");
31958
32057
  const file2 = await open(lockPath, "wx").catch(
31959
32058
  (error51) => {
31960
32059
  if (error51.code === "EEXIST")
@@ -31987,57 +32086,125 @@ var loadSkillStubs = async (input) => {
31987
32086
  }
31988
32087
  };
31989
32088
 
31990
- // src/skills/resolveSkillCommandContext.ts
31991
- import path22 from "path";
31992
- var resolveSkillCommandContext = async (options2) => {
31993
- const segments2 = options2.store.split("/");
31994
- const storeRef = storeRefSchema.parse(
31995
- segments2.length === 2 ? { workspaceSlug: segments2[0], storeSlug: segments2[1] } : segments2.length === 1 ? { storeId: options2.store } : {}
31996
- );
31997
- const saved = await readConfig(
31998
- options2.stateDir ? path22.resolve(options2.stateDir) : defaultStateDir()
32089
+ // src/skills/connectSkillCollection.ts
32090
+ var connectSkillCollection = async (scan, input) => {
32091
+ const collection = skillScanSchema.parse(scan);
32092
+ if (collection.problems.some((problem) => problem.kind === "invalid"))
32093
+ return { status: "invalid", collection, changes: [] };
32094
+ if (!collection.skills.length)
32095
+ return { status: "empty", collection, changes: [] };
32096
+ const result = await loadSkillStubs({
32097
+ ...input,
32098
+ skills: collection.skills,
32099
+ source: {
32100
+ apiBaseUrl: input.apiBaseUrl,
32101
+ storeId: collection.storeId,
32102
+ folder: collection.folder
32103
+ }
32104
+ });
32105
+ return {
32106
+ status: input.dryRun ? "preview" : "installed",
32107
+ collection,
32108
+ changes: result.changes
32109
+ };
32110
+ };
32111
+
32112
+ // src/skills/renderSkillConnection.ts
32113
+ var renderSkillConnection = (result, json2) => {
32114
+ if (json2) {
32115
+ renderOutput(result);
32116
+ return;
32117
+ }
32118
+ const { collection } = result;
32119
+ renderOutput(
32120
+ `Found ${collection.skills.length} skills in ${collection.markdownCount} Markdown files (${collection.folder}).`
31999
32121
  );
32000
- const apiBaseUrl = (process.env.DOCTRINE_API_URL || DEFAULT_API_BASE_URL).replace(/\/+$/, "");
32001
- const token = options2.token || process.env.DOCTRINE_TOKEN || saved.token;
32002
- return { client: createClient({ apiBaseUrl, token }), apiBaseUrl, storeRef };
32122
+ for (const skill of collection.skills)
32123
+ renderOutput(` ${skill.slug}: ${skill.path}`);
32124
+ for (const problem of collection.problems)
32125
+ renderOutput(
32126
+ ` ${problem.kind === "invalid" ? "Invalid" : "Not a skill"}: ${problem.path} \u2014 ${problem.message}`
32127
+ );
32128
+ if (!collection.markdownCount)
32129
+ renderOutput(
32130
+ "No Markdown files were found directly in this folder. Choose a folder containing .md or .markdown files; nested folders are separate collections."
32131
+ );
32132
+ if (collection.problems.length || !collection.skills.length) {
32133
+ renderOutput(
32134
+ "Each skill needs YAML frontmatter at the beginning of its Markdown file:"
32135
+ );
32136
+ renderOutput(
32137
+ "---\nname: example-skill\ndescription: Your description\n---\n\nDocument content"
32138
+ );
32139
+ renderOutput(
32140
+ "name: 1\u201364 lowercase letters, numbers, and single hyphens; unique in this folder. description: a non-empty string, up to 1,024 characters. Edit the Metadata section in Forum, or add this header in Raw view."
32141
+ );
32142
+ }
32143
+ for (const change of result.changes)
32144
+ renderOutput(
32145
+ `${result.status === "preview" ? "Would " : ""}${change.action} ${change.agent}: ${change.path}`
32146
+ );
32147
+ if (result.status === "invalid")
32148
+ renderOutput(
32149
+ "No local skills changed. Correct the invalid metadata and try again."
32150
+ );
32151
+ else if (result.status === "empty")
32152
+ renderOutput(
32153
+ "No local skills changed. Add the required metadata and try again."
32154
+ );
32155
+ else
32156
+ renderOutput(
32157
+ result.status === "preview" ? "Preview complete. No local skills changed." : "Skills connected. Instructions are fetched from Forum when used. Reconnect this folder after adding skills or changing names/descriptions. Start a new agent session if the skills are not yet visible."
32158
+ );
32003
32159
  };
32004
32160
 
32005
32161
  // src/skills/loadSkillsCommand.ts
32006
- var loadSkillsCommand = async (indexPath, _options, command) => {
32007
- const options2 = command.optsWithGlobals();
32008
- configureRenderer({ json: Boolean(options2.json) });
32009
- const { client, apiBaseUrl, storeRef } = await resolveSkillCommandContext(
32010
- options2
32011
- );
32012
- const result = await client.readSkillIndex({
32013
- ...storeRef,
32014
- indexPath,
32015
- validateTargets: true
32162
+ var loadSkillsCommand = async (folder, _options, command) => {
32163
+ let options2 = skillConnectionOptions.parse({
32164
+ ...command.optsWithGlobals(),
32165
+ folder
32166
+ });
32167
+ configureRenderer({ json: options2.json });
32168
+ if (!options2.interactive && folder === void 0 && !options2.store) {
32169
+ command.outputHelp();
32170
+ return;
32171
+ }
32172
+ if (options2.interactive && (!process.stdin.isTTY || !process.stderr.isTTY))
32173
+ throw new Error(
32174
+ "Interactive setup needs a terminal. Supply a folder and --store for non-interactive use."
32175
+ );
32176
+ const { client, apiBaseUrl } = await createSkillClient(options2);
32177
+ if (options2.interactive)
32178
+ options2 = await promptSkillConnection(client, options2);
32179
+ if (!options2.store || options2.folder === void 0)
32180
+ throw new Error(
32181
+ "Supply a folder and --store, or run fm skills -i for guided setup."
32182
+ );
32183
+ const collection = await client.scanSkills({
32184
+ ...parseSkillStore(options2.store),
32185
+ folder: options2.folder
32016
32186
  });
32017
- const report = await loadSkillStubs({
32018
- agents: options2.agents,
32187
+ const result = await connectSkillCollection(collection, {
32188
+ apiBaseUrl,
32189
+ agents: options2.agents ?? ["codex", "claude"],
32019
32190
  directory: process.cwd(),
32020
- global: Boolean(options2.global),
32021
32191
  home: os2.homedir(),
32022
- index: result.index,
32023
- source: {
32024
- apiBaseUrl,
32025
- storeId: result.storeId,
32026
- indexPath: result.indexPath
32027
- },
32028
- dryRun: Boolean(options2.dryRun)
32192
+ global: options2.global ?? false,
32193
+ dryRun: options2.dryRun
32029
32194
  });
32030
- if (options2.json) renderOutput(JSON.stringify(report));
32031
- else {
32032
- report.changes.forEach(
32033
- (change) => renderOutput(
32034
- `${report.dryRun ? "Would " : ""}${change.action} ${change.agent}: ${change.path}`
32035
- )
32036
- );
32037
- renderOutput(
32038
- `Skills ${report.dryRun ? "validated" : "loaded"}. Instructions are fetched live; reload this index after changing descriptions or membership.`
32039
- );
32040
- }
32195
+ renderSkillConnection(result, options2.json);
32196
+ if (result.status === "invalid" || result.status === "empty")
32197
+ process.exitCode = 1;
32198
+ };
32199
+
32200
+ // src/skills/resolveSkillCommandContext.ts
32201
+ var resolveSkillCommandContext = async (options2) => {
32202
+ if (!options2.store)
32203
+ throw new Error("Supply --store with a store ID or workspace/store.");
32204
+ return {
32205
+ ...await createSkillClient(options2),
32206
+ storeRef: parseSkillStore(options2.store)
32207
+ };
32041
32208
  };
32042
32209
 
32043
32210
  // src/skills/readSkillCommand.ts
@@ -32049,11 +32216,11 @@ var readSkillCommand = async (slug, _options, command) => {
32049
32216
  );
32050
32217
  const result = await client.readSkill({
32051
32218
  ...storeRef,
32052
- indexPath: options2.index,
32219
+ folder: options2.folder,
32053
32220
  slug
32054
32221
  });
32055
32222
  renderOutput(
32056
- options2.json ? JSON.stringify(result) : [
32223
+ options2.json ? result : [
32057
32224
  `Skill: ${result.slug}`,
32058
32225
  `Store: ${result.storeId}`,
32059
32226
  `Document: ${result.path}`,
@@ -32068,32 +32235,32 @@ var readSkillCommand = async (slug, _options, command) => {
32068
32235
  // src/skills/createSkillsCommand.ts
32069
32236
  var createSkillsCommand = () => {
32070
32237
  const program = new Command().name("fm").description("Forum skills CLI").option("--token <token>", "Use a Forum access token").option("--state-dir <path>", "Read CLI configuration from this directory").option("--json", "Print structured JSON").exitOverride();
32071
- const skills = program.command("skills").description(
32072
- "Discover local skills and read their live Forum instructions"
32073
- );
32074
- skills.command("load").description("Create or refresh local skill stubs from a Forum index").argument("<index>", "Skills index path in the store", parseSkillIndexPath).requiredOption(
32075
- "--store <store>",
32076
- "Source store (workspace/store or store ID)"
32077
- ).option(
32238
+ const skills = program.command("skills").description("Find and install skills from a Forum folder").argument(
32239
+ "[folder]",
32240
+ "Folder in the source store; / selects the store root",
32241
+ (value) => skillFolderSchema.parse(value)
32242
+ ).option("--store <store>", "Source store (workspace/store or store ID)").option(
32078
32243
  "--agents <agents>",
32079
- "Agent destinations: codex, claude, or all",
32080
- parseSkillAgents,
32081
- ["codex", "claude"]
32244
+ "Agent destinations: codex, claude, or all (default: both)",
32245
+ parseSkillAgents
32082
32246
  ).option(
32083
32247
  "--global",
32084
- "Load into user skill directories instead of this project"
32085
- ).option("--dry-run, -d", "Validate and show changes without writing files").action(loadSkillsCommand);
32086
- skills.command("read").description("Fetch current instructions for a skill in a Forum index").argument(
32248
+ "Make skills available in all projects on this computer"
32249
+ ).option(
32250
+ "-i, --interactive",
32251
+ "Choose the store, folder, agents, and scope interactively"
32252
+ ).option(
32253
+ "-d, --dry-run",
32254
+ "Scan and report planned changes without writing local files"
32255
+ ).action(loadSkillsCommand);
32256
+ skills.command("read").description("Fetch current instructions for a skill in a Forum folder").argument(
32087
32257
  "<slug>",
32088
- "Skill slug",
32258
+ "Skill name from Markdown frontmatter",
32089
32259
  (value) => skillSlugSchema.parse(value)
32090
32260
  ).requiredOption(
32091
- "--store <store>",
32092
- "Source store (workspace/store or store ID)"
32093
- ).requiredOption(
32094
- "--index <path>",
32095
- "Skills index path in the store",
32096
- parseSkillIndexPath
32261
+ "--folder <path>",
32262
+ "Source folder in the store",
32263
+ (value) => skillFolderSchema.parse(value)
32097
32264
  ).action(readSkillCommand);
32098
32265
  return program;
32099
32266
  };