promptopskit 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +8 -10
  2. package/SKILL.md +8 -8
  3. package/dist/{chunk-VU3WKLFI.js → chunk-2X5HFPSD.js} +2 -2
  4. package/dist/{chunk-R5PKK6Y7.js → chunk-4QW4BSGE.js} +2 -2
  5. package/dist/{chunk-UJA7XBQZ.js → chunk-7RWTFGMS.js} +2 -2
  6. package/dist/{chunk-S5YHGHK5.js → chunk-M5VKRDIY.js} +27 -14
  7. package/dist/chunk-M5VKRDIY.js.map +1 -0
  8. package/dist/{chunk-U7IDX2P7.js → chunk-ROBYCHAW.js} +3 -3
  9. package/dist/cli/index.js +144 -65
  10. package/dist/cli/index.js.map +1 -1
  11. package/dist/index.cjs +30 -18
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +5 -5
  14. package/dist/index.d.ts +5 -5
  15. package/dist/index.js +14 -11
  16. package/dist/index.js.map +1 -1
  17. package/dist/providers/anthropic.cjs +24 -13
  18. package/dist/providers/anthropic.cjs.map +1 -1
  19. package/dist/providers/anthropic.d.cts +1 -1
  20. package/dist/providers/anthropic.d.ts +1 -1
  21. package/dist/providers/anthropic.js +2 -2
  22. package/dist/providers/gemini.cjs +24 -13
  23. package/dist/providers/gemini.cjs.map +1 -1
  24. package/dist/providers/gemini.d.cts +1 -1
  25. package/dist/providers/gemini.d.ts +1 -1
  26. package/dist/providers/gemini.js +2 -2
  27. package/dist/providers/openai.cjs +24 -13
  28. package/dist/providers/openai.cjs.map +1 -1
  29. package/dist/providers/openai.d.cts +1 -1
  30. package/dist/providers/openai.d.ts +1 -1
  31. package/dist/providers/openai.js +2 -2
  32. package/dist/providers/openrouter.cjs +24 -13
  33. package/dist/providers/openrouter.cjs.map +1 -1
  34. package/dist/providers/openrouter.d.cts +1 -1
  35. package/dist/providers/openrouter.d.ts +1 -1
  36. package/dist/providers/openrouter.js +3 -3
  37. package/dist/{types-CgA7_wNI.d.cts → types-ClXTFaX-.d.cts} +1 -1
  38. package/dist/{types-D_-336jx.d.ts → types-lLD7m02V.d.ts} +1 -1
  39. package/dist/usagetap/index.d.cts +1 -1
  40. package/dist/usagetap/index.d.ts +1 -1
  41. package/package.json +4 -1
  42. package/dist/chunk-S5YHGHK5.js.map +0 -1
  43. /package/dist/{chunk-VU3WKLFI.js.map → chunk-2X5HFPSD.js.map} +0 -0
  44. /package/dist/{chunk-R5PKK6Y7.js.map → chunk-4QW4BSGE.js.map} +0 -0
  45. /package/dist/{chunk-UJA7XBQZ.js.map → chunk-7RWTFGMS.js.map} +0 -0
  46. /package/dist/{chunk-U7IDX2P7.js.map → chunk-ROBYCHAW.js.map} +0 -0
package/dist/cli/index.js CHANGED
@@ -568,12 +568,107 @@ async function collectPromptFiles(dir) {
568
568
  // src/cli/commands/compile.ts
569
569
  import { readdir as readdir2, writeFile, mkdir, rm } from "fs/promises";
570
570
  import { join as join3, extname as extname2, relative, dirname as dirname3 } from "path";
571
+
572
+ // src/prompt-resolution.ts
573
+ import { readFile as readFile3 } from "fs/promises";
574
+ import { existsSync, statSync as statSync2 } from "fs";
575
+ import { resolve as resolve3 } from "path";
576
+
577
+ // src/cache.ts
578
+ import { statSync } from "fs";
579
+ var PromptCache = class {
580
+ cache = /* @__PURE__ */ new Map();
581
+ maxSize;
582
+ constructor(maxSize = 100) {
583
+ this.maxSize = maxSize;
584
+ }
585
+ get(filePath) {
586
+ const entry = this.cache.get(filePath);
587
+ if (!entry) return void 0;
588
+ try {
589
+ const stat = statSync(filePath);
590
+ if (stat.mtimeMs !== entry.mtime) {
591
+ this.cache.delete(filePath);
592
+ return void 0;
593
+ }
594
+ } catch {
595
+ this.cache.delete(filePath);
596
+ return void 0;
597
+ }
598
+ this.cache.delete(filePath);
599
+ this.cache.set(filePath, entry);
600
+ return entry.value;
601
+ }
602
+ set(filePath, value) {
603
+ try {
604
+ const stat = statSync(filePath);
605
+ if (this.cache.has(filePath)) {
606
+ this.cache.delete(filePath);
607
+ } else if (this.cache.size >= this.maxSize) {
608
+ const oldest = this.cache.keys().next().value;
609
+ if (oldest) this.cache.delete(oldest);
610
+ }
611
+ this.cache.set(filePath, { value, mtime: stat.mtimeMs });
612
+ } catch {
613
+ }
614
+ }
615
+ clear() {
616
+ this.cache.clear();
617
+ }
618
+ get size() {
619
+ return this.cache.size;
620
+ }
621
+ };
622
+
623
+ // src/overrides/apply-overrides.ts
624
+ function applyOverrides(asset, options = {}) {
625
+ let result = { ...asset };
626
+ if (options.environment && result.environments?.[options.environment]) {
627
+ result = mergeOverride(result, result.environments[options.environment]);
628
+ }
629
+ if (options.tier && result.tiers?.[options.tier]) {
630
+ result = mergeOverride(result, result.tiers[options.tier]);
631
+ }
632
+ if (options.runtime) {
633
+ result = mergeOverride(result, options.runtime);
634
+ }
635
+ return result;
636
+ }
637
+ function mergeOverride(base, override) {
638
+ const result = { ...base };
639
+ if (override.model !== void 0) result.model = override.model;
640
+ if (override.fallback_models !== void 0) result.fallback_models = override.fallback_models;
641
+ if (override.tools !== void 0) result.tools = override.tools;
642
+ if (override.reasoning !== void 0) {
643
+ result.reasoning = { ...result.reasoning, ...override.reasoning };
644
+ }
645
+ if (override.sampling !== void 0) {
646
+ result.sampling = { ...result.sampling, ...override.sampling };
647
+ }
648
+ if (override.response !== void 0) {
649
+ result.response = { ...result.response, ...override.response };
650
+ }
651
+ return result;
652
+ }
653
+
654
+ // src/prompt-resolution.ts
655
+ var DEFAULT_PROMPTS_DIR = "./prompts";
656
+ var DEFAULT_COMPILED_JSON_DIR = "./.generated-prompts/json";
657
+ var DEFAULT_COMPILED_ESM_DIR = "./.generated-prompts/esm";
658
+ function defaultCompiledDirForFormat(format) {
659
+ return format === "esm" ? DEFAULT_COMPILED_ESM_DIR : DEFAULT_COMPILED_JSON_DIR;
660
+ }
661
+ var sharedPromptCache = new PromptCache();
662
+
663
+ // src/cli/commands/compile.ts
571
664
  var HELP2 = `
572
- promptopskit compile <sourceDir> <outputDir> [options]
665
+ promptopskit compile [sourceDir] [outputDir] [options]
573
666
 
574
- Compile .md prompt files to JSON artifacts.
667
+ Compile .md prompt files to JSON or ESM artifacts.
575
668
 
576
669
  Options:
670
+ --source, -s Source directory (default: ./prompts)
671
+ --output, -o Output directory (default: ./.generated-prompts/<format>)
577
672
  --no-clean Don't clear the output directory before compiling
578
673
  --dry-run Show what would be compiled without writing files
579
674
  --format Output format: json (default) or esm
@@ -584,14 +679,7 @@ async function compile(args) {
584
679
  console.log(HELP2);
585
680
  return;
586
681
  }
587
- const positional = args.filter((a) => !a.startsWith("--"));
588
- const sourceDir = positional[0];
589
- const outputDir = positional[1];
590
- if (!sourceDir || !outputDir) {
591
- console.error("Error: Please provide source and output directories.");
592
- console.error("Usage: promptopskit compile <sourceDir> <outputDir>");
593
- process.exit(1);
594
- }
682
+ const positional = getPositionalArgs(args, /* @__PURE__ */ new Set(["--format", "--source", "--output", "-s", "-o"]));
595
683
  const dryRun = args.includes("--dry-run");
596
684
  const noClean = args.includes("--no-clean");
597
685
  const format = getFlag(args, "--format") ?? "json";
@@ -599,6 +687,8 @@ async function compile(args) {
599
687
  console.error(`Error: Unknown format "${format}". Use "json" or "esm".`);
600
688
  process.exit(1);
601
689
  }
690
+ const sourceDir = getFlag(args, "--source", "-s") ?? positional[0] ?? DEFAULT_PROMPTS_DIR;
691
+ const outputDir = getFlag(args, "--output", "-o") ?? positional[1] ?? defaultCompiledDirForFormat(format);
602
692
  const files = await collectPromptFiles2(sourceDir);
603
693
  if (files.length === 0) {
604
694
  console.log(`No .md prompt files found in ${sourceDir}`);
@@ -647,10 +737,27 @@ async function compile(args) {
647
737
  process.exit(1);
648
738
  }
649
739
  }
650
- function getFlag(args, flag) {
651
- const idx = args.indexOf(flag);
652
- if (idx >= 0 && idx + 1 < args.length) {
653
- return args[idx + 1];
740
+ function getPositionalArgs(args, flagsWithValues) {
741
+ const positional = [];
742
+ for (let index = 0; index < args.length; index++) {
743
+ const arg = args[index];
744
+ if (flagsWithValues.has(arg)) {
745
+ index++;
746
+ continue;
747
+ }
748
+ if (arg.startsWith("-")) {
749
+ continue;
750
+ }
751
+ positional.push(arg);
752
+ }
753
+ return positional;
754
+ }
755
+ function getFlag(args, ...flags) {
756
+ for (const flag of flags) {
757
+ const idx = args.indexOf(flag);
758
+ if (idx >= 0 && idx + 1 < args.length) {
759
+ return args[idx + 1];
760
+ }
654
761
  }
655
762
  return void 0;
656
763
  }
@@ -666,49 +773,18 @@ async function collectPromptFiles2(dir) {
666
773
  }
667
774
 
668
775
  // src/cli/commands/render.ts
669
- import { readFile as readFile3 } from "fs/promises";
670
- import { existsSync as existsSync2 } from "fs";
671
-
672
- // src/overrides/apply-overrides.ts
673
- function applyOverrides(asset, options = {}) {
674
- let result = { ...asset };
675
- if (options.environment && result.environments?.[options.environment]) {
676
- result = mergeOverride(result, result.environments[options.environment]);
677
- }
678
- if (options.tier && result.tiers?.[options.tier]) {
679
- result = mergeOverride(result, result.tiers[options.tier]);
680
- }
681
- if (options.runtime) {
682
- result = mergeOverride(result, options.runtime);
683
- }
684
- return result;
685
- }
686
- function mergeOverride(base, override) {
687
- const result = { ...base };
688
- if (override.model !== void 0) result.model = override.model;
689
- if (override.fallback_models !== void 0) result.fallback_models = override.fallback_models;
690
- if (override.tools !== void 0) result.tools = override.tools;
691
- if (override.reasoning !== void 0) {
692
- result.reasoning = { ...result.reasoning, ...override.reasoning };
693
- }
694
- if (override.sampling !== void 0) {
695
- result.sampling = { ...result.sampling, ...override.sampling };
696
- }
697
- if (override.response !== void 0) {
698
- result.response = { ...result.response, ...override.response };
699
- }
700
- return result;
701
- }
776
+ import { readFile as readFile4 } from "fs/promises";
777
+ import { existsSync as existsSync3 } from "fs";
702
778
 
703
779
  // src/cli/commands/defaults-root.ts
704
- import { existsSync } from "fs";
705
- import { dirname as dirname4, join as join4, resolve as resolve3 } from "path";
780
+ import { existsSync as existsSync2 } from "fs";
781
+ import { dirname as dirname4, join as join4, resolve as resolve4 } from "path";
706
782
  function findDefaultsRoot(filePath) {
707
- let current = resolve3(dirname4(filePath));
783
+ let current = resolve4(dirname4(filePath));
708
784
  let root = current;
709
785
  let foundDefaults = false;
710
786
  while (true) {
711
- if (existsSync(join4(current, "defaults.md"))) {
787
+ if (existsSync2(join4(current, "defaults.md"))) {
712
788
  root = current;
713
789
  foundDefaults = true;
714
790
  } else if (foundDefaults) {
@@ -751,13 +827,13 @@ async function render(args) {
751
827
  const jsonOutput = args.includes("--json");
752
828
  let variables = {};
753
829
  if (varsFile) {
754
- const varsContent = await readFile3(varsFile, "utf-8");
830
+ const varsContent = await readFile4(varsFile, "utf-8");
755
831
  variables = JSON.parse(varsContent);
756
832
  } else {
757
833
  const sidecarPath = file.replace(/\.md$/, ".test.yaml");
758
- if (existsSync2(sidecarPath)) {
834
+ if (existsSync3(sidecarPath)) {
759
835
  const { default: yaml } = await import("gray-matter");
760
- const sidecarContent = await readFile3(sidecarPath, "utf-8");
836
+ const sidecarContent = await readFile4(sidecarPath, "utf-8");
761
837
  const parsed2 = yaml(`---
762
838
  ${sidecarContent}---
763
839
  `);
@@ -842,12 +918,15 @@ async function inspect(args) {
842
918
  // src/cli/commands/init.ts
843
919
  import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
844
920
  import { join as join5, dirname as dirname5 } from "path";
845
- import { existsSync as existsSync3, readFileSync } from "fs";
921
+ import { existsSync as existsSync4, readFileSync } from "fs";
846
922
  var HELP5 = `
847
923
  promptopskit init [dir]
848
924
 
849
925
  Scaffold a prompts directory with starter files.
850
926
 
927
+ Arguments:
928
+ dir Target directory (default: ./prompts)
929
+
851
930
  Options:
852
931
  --help, -h Show this help
853
932
  `.trim();
@@ -990,7 +1069,7 @@ async function init(args) {
990
1069
  let created = 0;
991
1070
  let skipped = 0;
992
1071
  for (const file of files) {
993
- if (existsSync3(file.path)) {
1072
+ if (existsSync4(file.path)) {
994
1073
  console.log(` skip ${file.path} (already exists)`);
995
1074
  skipped++;
996
1075
  continue;
@@ -1002,13 +1081,13 @@ async function init(args) {
1002
1081
  }
1003
1082
  console.log();
1004
1083
  console.log(`Created ${created} file(s), skipped ${skipped} existing.`);
1005
- if (existsSync3("package.json")) {
1084
+ if (existsSync4("package.json")) {
1006
1085
  try {
1007
1086
  const pkg = JSON.parse(readFileSync("package.json", "utf-8"));
1008
1087
  if (!pkg.scripts?.["build:prompts"]) {
1009
1088
  console.log();
1010
1089
  console.log(`Tip: Add to your package.json scripts:`);
1011
- console.log(` "build:prompts": "promptopskit compile ${dir} ./dist/prompts"`);
1090
+ console.log(` "build:prompts": "promptopskit compile ${dir}"`);
1012
1091
  }
1013
1092
  } catch {
1014
1093
  }
@@ -1016,9 +1095,9 @@ async function init(args) {
1016
1095
  }
1017
1096
 
1018
1097
  // src/cli/commands/skill.ts
1019
- import { writeFile as writeFile3, readFile as readFile4, mkdir as mkdir3 } from "fs/promises";
1098
+ import { writeFile as writeFile3, readFile as readFile5, mkdir as mkdir3 } from "fs/promises";
1020
1099
  import { dirname as dirname6 } from "path";
1021
- import { existsSync as existsSync4 } from "fs";
1100
+ import { existsSync as existsSync5 } from "fs";
1022
1101
  var MARKER_START = "<!-- promptopskit:start -->";
1023
1102
  var MARKER_END = "<!-- promptopskit:end -->";
1024
1103
  var HELP6 = `
@@ -1104,8 +1183,8 @@ async function skill(args) {
1104
1183
  continue;
1105
1184
  }
1106
1185
  const markedContent = config.wrap(wrapMarkers(STUB_CONTENT));
1107
- if (existsSync4(filePath) && !force) {
1108
- const existing = await readFile4(filePath, "utf-8");
1186
+ if (existsSync5(filePath) && !force) {
1187
+ const existing = await readFile5(filePath, "utf-8");
1109
1188
  const merged = mergeContent(existing, markedContent);
1110
1189
  if (merged === existing) {
1111
1190
  console.log(` skip ${filePath} (already up to date)`);
@@ -1128,13 +1207,13 @@ async function skill(args) {
1128
1207
  }
1129
1208
  async function deployClaude(filePath, force) {
1130
1209
  const content = CLAUDE_LINE + "\n";
1131
- if (!existsSync4(filePath) || force) {
1210
+ if (!existsSync5(filePath) || force) {
1132
1211
  await mkdir3(dirname6(filePath), { recursive: true });
1133
1212
  await writeFile3(filePath, content, "utf-8");
1134
1213
  console.log(` \u2713 ${filePath}`);
1135
1214
  return 1;
1136
1215
  }
1137
- const existing = await readFile4(filePath, "utf-8");
1216
+ const existing = await readFile5(filePath, "utf-8");
1138
1217
  if (existing.split("\n").some((line) => line.trim() === CLAUDE_LINE)) {
1139
1218
  console.log(` skip ${filePath} (already up to date)`);
1140
1219
  return 0;
@@ -1169,7 +1248,7 @@ Usage:
1169
1248
  Commands:
1170
1249
  init [dir] Scaffold a prompts directory with starter files
1171
1250
  validate <dir> Validate prompt files
1172
- compile <src> <out> [options] Compile .md prompts to JSON/ESM artifacts
1251
+ compile [src] [out] [options] Compile .md prompts to JSON/ESM artifacts
1173
1252
  render <file> [options] Render a prompt preview
1174
1253
  inspect <file> Print normalized prompt asset
1175
1254
  skill [options] Deploy AI agent instructions into your project