@sanity-labs/oclif-plugin-skills-flag 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sanity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # @sanity-labs/oclif-plugin-skills-flag
2
+
3
+ Adds `--llms` and its `--skill` alias to every command in an oclif v4 CLI. The flag prints
4
+ command-specific Markdown for coding agents, then exits without running the command.
5
+
6
+ ## Install
7
+
8
+ Install the plugin in the CLI:
9
+
10
+ ```sh
11
+ npm install @sanity-labs/oclif-plugin-skills-flag
12
+ ```
13
+
14
+ Register it in the CLI's `package.json`:
15
+
16
+ ```json
17
+ {
18
+ "oclif": {
19
+ "plugins": ["@sanity-labs/oclif-plugin-skills-flag"]
20
+ }
21
+ }
22
+ ```
23
+
24
+ Add a `skills` directory at the package root. Name each file after its oclif command ID, replacing
25
+ colons with hyphens:
26
+
27
+ ```text
28
+ skills/
29
+ ├── deploy.md
30
+ └── functions-test.md
31
+ ```
32
+
33
+ These commands then print the matching files:
34
+
35
+ ```sh
36
+ my-cli deploy --llms
37
+ my-cli functions test --skill
38
+ ```
39
+
40
+ The second command uses `skills/functions-test.md`. A single-command CLI uses `skills/index.md`.
41
+ Include `skills` in the CLI's npm `files` list if it has one.
42
+
43
+ ## Show the flag in help
44
+
45
+ An oclif plugin cannot add flags to the host commands' generated help. The hook still recognizes
46
+ both flags before oclif parses the command. To advertise `--llms`, add the exported config to the
47
+ CLI's existing base command:
48
+
49
+ ```ts
50
+ import {Command, Flags} from '@oclif/core'
51
+ import {llmsFlagConfig} from '@sanity-labs/oclif-plugin-skills-flag'
52
+
53
+ export abstract class BaseCommand extends Command {
54
+ static baseFlags = {
55
+ ...super.baseFlags,
56
+ llms: Flags.boolean(llmsFlagConfig),
57
+ }
58
+ }
59
+ ```
60
+
61
+ The plugin handles the flag, so command implementations do not need to read `flags.llms`.
62
+
63
+ ## Limitations
64
+
65
+ - The plugin targets oclif v4.
66
+ - `--llms` and `--skill` take precedence over same-named host flags.
67
+ - The init hook writes the skill and exits immediately. Later oclif lifecycle hooks do not run.
68
+
69
+ ## Development
70
+
71
+ mise selects Node 24, which runs the TypeScript tests directly:
72
+
73
+ ```sh
74
+ npm install
75
+ npm test
76
+ ```
77
+
78
+ Run `npm run build` to create the publishable files in `dist/`. Use `npm run lint:fix` to apply
79
+ Biome formatting and safe lint fixes.
@@ -0,0 +1,18 @@
1
+ import type { Hook } from "@oclif/core";
2
+ export interface SkillsFlagRuntime {
3
+ exit(code: number): never;
4
+ write(output: string): void;
5
+ }
6
+ export interface SkillsFlagOptions {
7
+ argv: string[];
8
+ bin: string;
9
+ commandExists(commandId: string): boolean;
10
+ commandId: string | undefined;
11
+ error(message: string): void;
12
+ isSingleCommandCLI: boolean;
13
+ root: string;
14
+ }
15
+ export declare function handleSkillsFlag(options: SkillsFlagOptions, runtime?: SkillsFlagRuntime): Promise<void>;
16
+ declare const hook: Hook.Init;
17
+ export default hook;
18
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/hooks/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAQvC,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;IACzB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAA;IACzC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,kBAAkB,EAAE,OAAO,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;CACb;AAWD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,iBAAkC,GAC1C,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,IAUhB,CAAA;eAEc,IAAI"}
@@ -0,0 +1,39 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { commandSkillFilename, ensureFinalNewline, hasSkillsFlag, readCommandSkill, } from "../skills.js";
3
+ const processRuntime = {
4
+ exit(code) {
5
+ process.exit(code);
6
+ },
7
+ write(output) {
8
+ writeFileSync(process.stdout.fd, output);
9
+ },
10
+ };
11
+ export async function handleSkillsFlag(options, runtime = processRuntime) {
12
+ if (!hasSkillsFlag(options.argv))
13
+ return;
14
+ if (!options.commandId || !options.commandExists(options.commandId))
15
+ return;
16
+ const skillCommandId = options.isSingleCommandCLI ? "" : options.commandId;
17
+ const filename = commandSkillFilename(skillCommandId);
18
+ const skill = await readCommandSkill(skillCommandId, options.root);
19
+ if (skill === undefined) {
20
+ const commandName = skillCommandId.replaceAll(":", " ") || options.bin;
21
+ options.error(`No agent guidance is available for \`${commandName}\`.\nAdd it at skills/${filename}.`);
22
+ return;
23
+ }
24
+ runtime.write(ensureFinalNewline(skill));
25
+ runtime.exit(0);
26
+ }
27
+ const hook = async ({ argv, config, context, id }) => {
28
+ await handleSkillsFlag({
29
+ argv,
30
+ bin: config.bin,
31
+ commandExists: (commandId) => config.findCommand(commandId) !== undefined,
32
+ commandId: id,
33
+ error: (message) => context.error(message, { code: "E_SKILL_NOT_FOUND" }),
34
+ isSingleCommandCLI: config.isSingleCommandCLI,
35
+ root: config.root,
36
+ });
37
+ };
38
+ export default hook;
39
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/hooks/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAA;AAiBrB,MAAM,cAAc,GAAsB;IACxC,IAAI,CAAC,IAAI;QACP,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC;IACD,KAAK,CAAC,MAAM;QACV,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC;CACF,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAA0B,EAC1B,OAAO,GAAsB,cAAc;IAE3C,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAM;IACxC,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,CAAC,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AAI,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { commandSkillFilename, ensureFinalNewline, hasSkillsFlag, llmsFlagConfig, readCommandSkill, } from "./skills.ts";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,gBAAgB,GACjB,MAAM,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { commandSkillFilename, ensureFinalNewline, hasSkillsFlag, llmsFlagConfig, readCommandSkill, } from "./skills.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,gBAAgB,GACjB,MAAM,aAAa,CAAA"}
@@ -0,0 +1,9 @@
1
+ export declare const llmsFlagConfig: {
2
+ readonly aliases: readonly ["skill"];
3
+ readonly description: "Show agent-oriented guidance for this command";
4
+ };
5
+ export declare function commandSkillFilename(commandId: string): string;
6
+ export declare function ensureFinalNewline(input: string): string;
7
+ export declare function hasSkillsFlag(argv: string[]): boolean;
8
+ export declare function readCommandSkill(commandId: string, root: string): Promise<string | undefined>;
9
+ //# sourceMappingURL=skills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../src/skills.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc;aACzB,OAAO,YAAG,OAAO;aACjB,WAAW,EAAE,+CAA+C;CACpD,CAAA;AAEV,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAc9D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAOrD;AAED,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS7B"}
package/dist/skills.js ADDED
@@ -0,0 +1,43 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ const SKILLS_DIRECTORY = "skills";
4
+ const SKILLS_FLAGS = new Set(["--llms", "--skill"]);
5
+ export const llmsFlagConfig = {
6
+ aliases: ["skill"],
7
+ description: "Show agent-oriented guidance for this command",
8
+ };
9
+ export function commandSkillFilename(commandId) {
10
+ const filename = commandId.replaceAll(":", "-") || "index";
11
+ if (filename === "." ||
12
+ filename === ".." ||
13
+ filename.includes("/") ||
14
+ filename.includes("\\") ||
15
+ filename.includes("\0")) {
16
+ throw new TypeError(`Invalid oclif command ID: ${commandId}`);
17
+ }
18
+ return `${filename}.md`;
19
+ }
20
+ export function ensureFinalNewline(input) {
21
+ return input.endsWith("\n") ? input : `${input}\n`;
22
+ }
23
+ export function hasSkillsFlag(argv) {
24
+ for (const argument of argv) {
25
+ if (argument === "--")
26
+ return false;
27
+ if (SKILLS_FLAGS.has(argument))
28
+ return true;
29
+ }
30
+ return false;
31
+ }
32
+ export async function readCommandSkill(commandId, root) {
33
+ const path = join(root, SKILLS_DIRECTORY, commandSkillFilename(commandId));
34
+ try {
35
+ return await readFile(path, "utf8");
36
+ }
37
+ catch (error) {
38
+ if (error.code === "ENOENT")
39
+ return;
40
+ throw error;
41
+ }
42
+ }
43
+ //# sourceMappingURL=skills.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills.js","sourceRoot":"","sources":["../src/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,gBAAgB,GAAG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CAAC,SAAS,CAAC,CAAC,CAAA;IAE1E,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAM;QAC9D,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@sanity-labs/oclif-plugin-skills-flag",
3
+ "version": "0.1.0",
4
+ "description": "Expose per-command Markdown to coding agents through an oclif flag",
5
+ "author": "Sanity",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "LICENSE",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc --project tsconfig.build.json",
23
+ "lint": "biome ci .",
24
+ "lint:fix": "biome check --write .",
25
+ "prepack": "npm test && npm run build",
26
+ "test": "npm run typecheck && node --test test/*.test.ts && npm run lint",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "engines": {
30
+ "node": ">=22"
31
+ },
32
+ "peerDependencies": {
33
+ "@oclif/core": "^4.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@biomejs/biome": "2.5.5",
37
+ "@oclif/core": "^4.11.14",
38
+ "@types/node": "^22.0.0",
39
+ "typescript": "^7.0.2"
40
+ },
41
+ "oclif": {
42
+ "hooks": {
43
+ "init": "./dist/hooks/init.js"
44
+ }
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/sanity-labs/oclif-plugin-skills-flag.git"
52
+ },
53
+ "bugs": "https://github.com/sanity-labs/oclif-plugin-skills-flag/issues",
54
+ "homepage": "https://github.com/sanity-labs/oclif-plugin-skills-flag#readme",
55
+ "keywords": [
56
+ "agent",
57
+ "llm",
58
+ "oclif",
59
+ "oclif-plugin",
60
+ "skill"
61
+ ]
62
+ }