promptopskit 0.3.4 → 0.3.6
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/README.md +8 -9
- package/SKILL.md +4 -1
- package/dist/{chunk-2LK6IILW.js → chunk-6FLNJVE7.js} +5 -2
- package/dist/chunk-6FLNJVE7.js.map +1 -0
- package/dist/{chunk-UJA7XBQZ.js → chunk-J32I6DSG.js} +2 -2
- package/dist/{chunk-VU3WKLFI.js → chunk-MN3RQ7DZ.js} +2 -2
- package/dist/{chunk-R5PKK6Y7.js → chunk-MYXDJMWV.js} +2 -2
- package/dist/{chunk-S5YHGHK5.js → chunk-SHYKSLVR.js} +172 -16
- package/dist/chunk-SHYKSLVR.js.map +1 -0
- package/dist/{chunk-U7IDX2P7.js → chunk-SOY2CEJM.js} +3 -3
- package/dist/cli/index.js +145 -56
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +203 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +48 -56
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.cjs +144 -15
- package/dist/providers/anthropic.cjs.map +1 -1
- package/dist/providers/anthropic.d.cts +2 -2
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +3 -3
- package/dist/providers/gemini.cjs +144 -15
- package/dist/providers/gemini.cjs.map +1 -1
- package/dist/providers/gemini.d.cts +2 -2
- package/dist/providers/gemini.d.ts +2 -2
- package/dist/providers/gemini.js +3 -3
- package/dist/providers/openai.cjs +144 -15
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.d.cts +2 -2
- package/dist/providers/openai.d.ts +2 -2
- package/dist/providers/openai.js +3 -3
- package/dist/providers/openrouter.cjs +144 -15
- package/dist/providers/openrouter.cjs.map +1 -1
- package/dist/providers/openrouter.d.cts +2 -2
- package/dist/providers/openrouter.d.ts +2 -2
- package/dist/providers/openrouter.js +4 -4
- package/dist/{schema-Dq0jKest.d.cts → schema-D145q3Dw.d.cts} +63 -42
- package/dist/{schema-Dq0jKest.d.ts → schema-D145q3Dw.d.ts} +63 -42
- package/dist/testing.cjs +4 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/{types-CgA7_wNI.d.cts → types-B3sWHzIo.d.cts} +9 -2
- package/dist/{types-D_-336jx.d.ts → types-CXlVWckk.d.ts} +9 -2
- package/dist/usagetap/index.d.cts +2 -2
- package/dist/usagetap/index.d.ts +2 -2
- package/package.json +4 -1
- package/dist/chunk-2LK6IILW.js.map +0 -1
- package/dist/chunk-S5YHGHK5.js.map +0 -1
- /package/dist/{chunk-UJA7XBQZ.js.map → chunk-J32I6DSG.js.map} +0 -0
- /package/dist/{chunk-VU3WKLFI.js.map → chunk-MN3RQ7DZ.js.map} +0 -0
- /package/dist/{chunk-R5PKK6Y7.js.map → chunk-MYXDJMWV.js.map} +0 -0
- /package/dist/{chunk-U7IDX2P7.js.map → chunk-SOY2CEJM.js.map} +0 -0
package/dist/cli/index.js
CHANGED
|
@@ -43,7 +43,10 @@ var HistorySchema = z.object({
|
|
|
43
43
|
});
|
|
44
44
|
var ContextInputDefinitionObjectSchema = z.object({
|
|
45
45
|
name: z.string(),
|
|
46
|
-
max_size: z.number().int().positive().optional()
|
|
46
|
+
max_size: z.number().int().positive().optional(),
|
|
47
|
+
trim: z.union([z.boolean(), z.enum(["start", "end", "both"])]).optional(),
|
|
48
|
+
allow_regex: z.string().optional(),
|
|
49
|
+
deny_regex: z.string().optional()
|
|
47
50
|
});
|
|
48
51
|
var ContextInputDefinitionSchema = z.union([
|
|
49
52
|
z.string(),
|
|
@@ -341,7 +344,10 @@ function normalizeContextInput(input) {
|
|
|
341
344
|
}
|
|
342
345
|
return {
|
|
343
346
|
name: input.name,
|
|
344
|
-
max_size: input.max_size
|
|
347
|
+
max_size: input.max_size,
|
|
348
|
+
trim: input.trim,
|
|
349
|
+
allow_regex: input.allow_regex,
|
|
350
|
+
deny_regex: input.deny_regex
|
|
345
351
|
};
|
|
346
352
|
}
|
|
347
353
|
|
|
@@ -456,6 +462,30 @@ function validateAsset(asset, frontMatterKeys, filePath) {
|
|
|
456
462
|
});
|
|
457
463
|
}
|
|
458
464
|
}
|
|
465
|
+
for (const input of getContextInputs(asset)) {
|
|
466
|
+
if (input.trim !== void 0 && input.trim !== false && input.max_size === void 0) {
|
|
467
|
+
warnings.push({
|
|
468
|
+
code: "POK014",
|
|
469
|
+
message: `Context input "${input.name}" sets trim but has no max_size; trim-to-budget will be skipped.`,
|
|
470
|
+
filePath
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
const checks = [];
|
|
474
|
+
if (input.allow_regex) checks.push({ pattern: input.allow_regex, kind: "allow_regex" });
|
|
475
|
+
if (input.deny_regex) checks.push({ pattern: input.deny_regex, kind: "deny_regex" });
|
|
476
|
+
for (const check of checks) {
|
|
477
|
+
try {
|
|
478
|
+
new RegExp(check.pattern);
|
|
479
|
+
} catch (error) {
|
|
480
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
481
|
+
errors.push({
|
|
482
|
+
code: "POK013",
|
|
483
|
+
message: `Invalid context ${check.kind} for "${input.name}": ${reason}`,
|
|
484
|
+
filePath
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
459
489
|
return {
|
|
460
490
|
valid: errors.length === 0,
|
|
461
491
|
errors,
|
|
@@ -568,6 +598,99 @@ async function collectPromptFiles(dir) {
|
|
|
568
598
|
// src/cli/commands/compile.ts
|
|
569
599
|
import { readdir as readdir2, writeFile, mkdir, rm } from "fs/promises";
|
|
570
600
|
import { join as join3, extname as extname2, relative, dirname as dirname3 } from "path";
|
|
601
|
+
|
|
602
|
+
// src/prompt-resolution.ts
|
|
603
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
604
|
+
import { existsSync, statSync as statSync2 } from "fs";
|
|
605
|
+
import { resolve as resolve3 } from "path";
|
|
606
|
+
|
|
607
|
+
// src/cache.ts
|
|
608
|
+
import { statSync } from "fs";
|
|
609
|
+
var PromptCache = class {
|
|
610
|
+
cache = /* @__PURE__ */ new Map();
|
|
611
|
+
maxSize;
|
|
612
|
+
constructor(maxSize = 100) {
|
|
613
|
+
this.maxSize = maxSize;
|
|
614
|
+
}
|
|
615
|
+
get(filePath) {
|
|
616
|
+
const entry = this.cache.get(filePath);
|
|
617
|
+
if (!entry) return void 0;
|
|
618
|
+
try {
|
|
619
|
+
const stat = statSync(filePath);
|
|
620
|
+
if (stat.mtimeMs !== entry.mtime) {
|
|
621
|
+
this.cache.delete(filePath);
|
|
622
|
+
return void 0;
|
|
623
|
+
}
|
|
624
|
+
} catch {
|
|
625
|
+
this.cache.delete(filePath);
|
|
626
|
+
return void 0;
|
|
627
|
+
}
|
|
628
|
+
this.cache.delete(filePath);
|
|
629
|
+
this.cache.set(filePath, entry);
|
|
630
|
+
return entry.value;
|
|
631
|
+
}
|
|
632
|
+
set(filePath, value) {
|
|
633
|
+
try {
|
|
634
|
+
const stat = statSync(filePath);
|
|
635
|
+
if (this.cache.has(filePath)) {
|
|
636
|
+
this.cache.delete(filePath);
|
|
637
|
+
} else if (this.cache.size >= this.maxSize) {
|
|
638
|
+
const oldest = this.cache.keys().next().value;
|
|
639
|
+
if (oldest) this.cache.delete(oldest);
|
|
640
|
+
}
|
|
641
|
+
this.cache.set(filePath, { value, mtime: stat.mtimeMs });
|
|
642
|
+
} catch {
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
clear() {
|
|
646
|
+
this.cache.clear();
|
|
647
|
+
}
|
|
648
|
+
get size() {
|
|
649
|
+
return this.cache.size;
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// src/overrides/apply-overrides.ts
|
|
654
|
+
function applyOverrides(asset, options = {}) {
|
|
655
|
+
let result = { ...asset };
|
|
656
|
+
if (options.environment && result.environments?.[options.environment]) {
|
|
657
|
+
result = mergeOverride(result, result.environments[options.environment]);
|
|
658
|
+
}
|
|
659
|
+
if (options.tier && result.tiers?.[options.tier]) {
|
|
660
|
+
result = mergeOverride(result, result.tiers[options.tier]);
|
|
661
|
+
}
|
|
662
|
+
if (options.runtime) {
|
|
663
|
+
result = mergeOverride(result, options.runtime);
|
|
664
|
+
}
|
|
665
|
+
return result;
|
|
666
|
+
}
|
|
667
|
+
function mergeOverride(base, override) {
|
|
668
|
+
const result = { ...base };
|
|
669
|
+
if (override.model !== void 0) result.model = override.model;
|
|
670
|
+
if (override.fallback_models !== void 0) result.fallback_models = override.fallback_models;
|
|
671
|
+
if (override.tools !== void 0) result.tools = override.tools;
|
|
672
|
+
if (override.reasoning !== void 0) {
|
|
673
|
+
result.reasoning = { ...result.reasoning, ...override.reasoning };
|
|
674
|
+
}
|
|
675
|
+
if (override.sampling !== void 0) {
|
|
676
|
+
result.sampling = { ...result.sampling, ...override.sampling };
|
|
677
|
+
}
|
|
678
|
+
if (override.response !== void 0) {
|
|
679
|
+
result.response = { ...result.response, ...override.response };
|
|
680
|
+
}
|
|
681
|
+
return result;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// src/prompt-resolution.ts
|
|
685
|
+
var DEFAULT_PROMPTS_DIR = "./prompts";
|
|
686
|
+
var DEFAULT_COMPILED_JSON_DIR = "./.generated-prompts/json";
|
|
687
|
+
var DEFAULT_COMPILED_ESM_DIR = "./.generated-prompts/esm";
|
|
688
|
+
function defaultCompiledDirForFormat(format) {
|
|
689
|
+
return format === "esm" ? DEFAULT_COMPILED_ESM_DIR : DEFAULT_COMPILED_JSON_DIR;
|
|
690
|
+
}
|
|
691
|
+
var sharedPromptCache = new PromptCache();
|
|
692
|
+
|
|
693
|
+
// src/cli/commands/compile.ts
|
|
571
694
|
var HELP2 = `
|
|
572
695
|
promptopskit compile [sourceDir] [outputDir] [options]
|
|
573
696
|
|
|
@@ -594,8 +717,8 @@ async function compile(args) {
|
|
|
594
717
|
console.error(`Error: Unknown format "${format}". Use "json" or "esm".`);
|
|
595
718
|
process.exit(1);
|
|
596
719
|
}
|
|
597
|
-
const sourceDir = getFlag(args, "--source", "-s") ?? positional[0] ??
|
|
598
|
-
const outputDir = getFlag(args, "--output", "-o") ?? positional[1] ??
|
|
720
|
+
const sourceDir = getFlag(args, "--source", "-s") ?? positional[0] ?? DEFAULT_PROMPTS_DIR;
|
|
721
|
+
const outputDir = getFlag(args, "--output", "-o") ?? positional[1] ?? defaultCompiledDirForFormat(format);
|
|
599
722
|
const files = await collectPromptFiles2(sourceDir);
|
|
600
723
|
if (files.length === 0) {
|
|
601
724
|
console.log(`No .md prompt files found in ${sourceDir}`);
|
|
@@ -644,9 +767,6 @@ async function compile(args) {
|
|
|
644
767
|
process.exit(1);
|
|
645
768
|
}
|
|
646
769
|
}
|
|
647
|
-
function defaultOutputDirForFormat(format) {
|
|
648
|
-
return format === "esm" ? "./.generated-prompts/esm" : "./.generated-prompts/json";
|
|
649
|
-
}
|
|
650
770
|
function getPositionalArgs(args, flagsWithValues) {
|
|
651
771
|
const positional = [];
|
|
652
772
|
for (let index = 0; index < args.length; index++) {
|
|
@@ -683,49 +803,18 @@ async function collectPromptFiles2(dir) {
|
|
|
683
803
|
}
|
|
684
804
|
|
|
685
805
|
// src/cli/commands/render.ts
|
|
686
|
-
import { readFile as
|
|
687
|
-
import { existsSync as
|
|
688
|
-
|
|
689
|
-
// src/overrides/apply-overrides.ts
|
|
690
|
-
function applyOverrides(asset, options = {}) {
|
|
691
|
-
let result = { ...asset };
|
|
692
|
-
if (options.environment && result.environments?.[options.environment]) {
|
|
693
|
-
result = mergeOverride(result, result.environments[options.environment]);
|
|
694
|
-
}
|
|
695
|
-
if (options.tier && result.tiers?.[options.tier]) {
|
|
696
|
-
result = mergeOverride(result, result.tiers[options.tier]);
|
|
697
|
-
}
|
|
698
|
-
if (options.runtime) {
|
|
699
|
-
result = mergeOverride(result, options.runtime);
|
|
700
|
-
}
|
|
701
|
-
return result;
|
|
702
|
-
}
|
|
703
|
-
function mergeOverride(base, override) {
|
|
704
|
-
const result = { ...base };
|
|
705
|
-
if (override.model !== void 0) result.model = override.model;
|
|
706
|
-
if (override.fallback_models !== void 0) result.fallback_models = override.fallback_models;
|
|
707
|
-
if (override.tools !== void 0) result.tools = override.tools;
|
|
708
|
-
if (override.reasoning !== void 0) {
|
|
709
|
-
result.reasoning = { ...result.reasoning, ...override.reasoning };
|
|
710
|
-
}
|
|
711
|
-
if (override.sampling !== void 0) {
|
|
712
|
-
result.sampling = { ...result.sampling, ...override.sampling };
|
|
713
|
-
}
|
|
714
|
-
if (override.response !== void 0) {
|
|
715
|
-
result.response = { ...result.response, ...override.response };
|
|
716
|
-
}
|
|
717
|
-
return result;
|
|
718
|
-
}
|
|
806
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
807
|
+
import { existsSync as existsSync3 } from "fs";
|
|
719
808
|
|
|
720
809
|
// src/cli/commands/defaults-root.ts
|
|
721
|
-
import { existsSync } from "fs";
|
|
722
|
-
import { dirname as dirname4, join as join4, resolve as
|
|
810
|
+
import { existsSync as existsSync2 } from "fs";
|
|
811
|
+
import { dirname as dirname4, join as join4, resolve as resolve4 } from "path";
|
|
723
812
|
function findDefaultsRoot(filePath) {
|
|
724
|
-
let current =
|
|
813
|
+
let current = resolve4(dirname4(filePath));
|
|
725
814
|
let root = current;
|
|
726
815
|
let foundDefaults = false;
|
|
727
816
|
while (true) {
|
|
728
|
-
if (
|
|
817
|
+
if (existsSync2(join4(current, "defaults.md"))) {
|
|
729
818
|
root = current;
|
|
730
819
|
foundDefaults = true;
|
|
731
820
|
} else if (foundDefaults) {
|
|
@@ -768,13 +857,13 @@ async function render(args) {
|
|
|
768
857
|
const jsonOutput = args.includes("--json");
|
|
769
858
|
let variables = {};
|
|
770
859
|
if (varsFile) {
|
|
771
|
-
const varsContent = await
|
|
860
|
+
const varsContent = await readFile4(varsFile, "utf-8");
|
|
772
861
|
variables = JSON.parse(varsContent);
|
|
773
862
|
} else {
|
|
774
863
|
const sidecarPath = file.replace(/\.md$/, ".test.yaml");
|
|
775
|
-
if (
|
|
864
|
+
if (existsSync3(sidecarPath)) {
|
|
776
865
|
const { default: yaml } = await import("gray-matter");
|
|
777
|
-
const sidecarContent = await
|
|
866
|
+
const sidecarContent = await readFile4(sidecarPath, "utf-8");
|
|
778
867
|
const parsed2 = yaml(`---
|
|
779
868
|
${sidecarContent}---
|
|
780
869
|
`);
|
|
@@ -859,7 +948,7 @@ async function inspect(args) {
|
|
|
859
948
|
// src/cli/commands/init.ts
|
|
860
949
|
import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
861
950
|
import { join as join5, dirname as dirname5 } from "path";
|
|
862
|
-
import { existsSync as
|
|
951
|
+
import { existsSync as existsSync4, readFileSync } from "fs";
|
|
863
952
|
var HELP5 = `
|
|
864
953
|
promptopskit init [dir]
|
|
865
954
|
|
|
@@ -1010,7 +1099,7 @@ async function init(args) {
|
|
|
1010
1099
|
let created = 0;
|
|
1011
1100
|
let skipped = 0;
|
|
1012
1101
|
for (const file of files) {
|
|
1013
|
-
if (
|
|
1102
|
+
if (existsSync4(file.path)) {
|
|
1014
1103
|
console.log(` skip ${file.path} (already exists)`);
|
|
1015
1104
|
skipped++;
|
|
1016
1105
|
continue;
|
|
@@ -1022,7 +1111,7 @@ async function init(args) {
|
|
|
1022
1111
|
}
|
|
1023
1112
|
console.log();
|
|
1024
1113
|
console.log(`Created ${created} file(s), skipped ${skipped} existing.`);
|
|
1025
|
-
if (
|
|
1114
|
+
if (existsSync4("package.json")) {
|
|
1026
1115
|
try {
|
|
1027
1116
|
const pkg = JSON.parse(readFileSync("package.json", "utf-8"));
|
|
1028
1117
|
if (!pkg.scripts?.["build:prompts"]) {
|
|
@@ -1036,9 +1125,9 @@ async function init(args) {
|
|
|
1036
1125
|
}
|
|
1037
1126
|
|
|
1038
1127
|
// src/cli/commands/skill.ts
|
|
1039
|
-
import { writeFile as writeFile3, readFile as
|
|
1128
|
+
import { writeFile as writeFile3, readFile as readFile5, mkdir as mkdir3 } from "fs/promises";
|
|
1040
1129
|
import { dirname as dirname6 } from "path";
|
|
1041
|
-
import { existsSync as
|
|
1130
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1042
1131
|
var MARKER_START = "<!-- promptopskit:start -->";
|
|
1043
1132
|
var MARKER_END = "<!-- promptopskit:end -->";
|
|
1044
1133
|
var HELP6 = `
|
|
@@ -1124,8 +1213,8 @@ async function skill(args) {
|
|
|
1124
1213
|
continue;
|
|
1125
1214
|
}
|
|
1126
1215
|
const markedContent = config.wrap(wrapMarkers(STUB_CONTENT));
|
|
1127
|
-
if (
|
|
1128
|
-
const existing = await
|
|
1216
|
+
if (existsSync5(filePath) && !force) {
|
|
1217
|
+
const existing = await readFile5(filePath, "utf-8");
|
|
1129
1218
|
const merged = mergeContent(existing, markedContent);
|
|
1130
1219
|
if (merged === existing) {
|
|
1131
1220
|
console.log(` skip ${filePath} (already up to date)`);
|
|
@@ -1148,13 +1237,13 @@ async function skill(args) {
|
|
|
1148
1237
|
}
|
|
1149
1238
|
async function deployClaude(filePath, force) {
|
|
1150
1239
|
const content = CLAUDE_LINE + "\n";
|
|
1151
|
-
if (!
|
|
1240
|
+
if (!existsSync5(filePath) || force) {
|
|
1152
1241
|
await mkdir3(dirname6(filePath), { recursive: true });
|
|
1153
1242
|
await writeFile3(filePath, content, "utf-8");
|
|
1154
1243
|
console.log(` \u2713 ${filePath}`);
|
|
1155
1244
|
return 1;
|
|
1156
1245
|
}
|
|
1157
|
-
const existing = await
|
|
1246
|
+
const existing = await readFile5(filePath, "utf-8");
|
|
1158
1247
|
if (existing.split("\n").some((line) => line.trim() === CLAUDE_LINE)) {
|
|
1159
1248
|
console.log(` skip ${filePath} (already up to date)`);
|
|
1160
1249
|
return 0;
|