@apifuse/provider-sdk 2.2.0-beta.4 → 2.2.0-beta.7

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 (51) hide show
  1. package/AUTHORING.md +92 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +5 -1
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +26 -1
  6. package/bin/apifuse-pack-check.ts +14 -0
  7. package/bin/apifuse-submit-check.ts +433 -15
  8. package/bin/apifuse-sync-assets.ts +117 -0
  9. package/dist/cli/commands.d.ts +1 -1
  10. package/dist/cli/commands.js +8 -0
  11. package/dist/cli/create.d.ts +3 -0
  12. package/dist/cli/create.js +34 -35
  13. package/dist/cli/prompt-assets.d.ts +80 -0
  14. package/dist/cli/prompt-assets.js +743 -0
  15. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/runtime/executor.js +7 -0
  19. package/dist/runtime/secrets.d.ts +27 -0
  20. package/dist/runtime/secrets.js +51 -0
  21. package/dist/server/index.d.ts +1 -1
  22. package/dist/server/index.js +1 -1
  23. package/dist/server/self-test.d.ts +101 -0
  24. package/dist/server/self-test.js +670 -112
  25. package/dist/server/serve.d.ts +5 -0
  26. package/dist/server/serve.js +41 -1
  27. package/package.json +1 -1
  28. package/src/cli/commands.ts +10 -0
  29. package/src/cli/create.ts +42 -35
  30. package/src/cli/prompt-assets.ts +865 -0
  31. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  32. package/src/index.ts +5 -0
  33. package/src/runtime/executor.ts +8 -0
  34. package/src/runtime/secrets.ts +64 -0
  35. package/src/server/index.ts +5 -0
  36. package/src/server/self-test.ts +852 -127
  37. package/src/server/serve.ts +60 -1
  38. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  39. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  40. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  41. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  42. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  43. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  44. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  45. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  46. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  47. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  48. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  49. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  50. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  51. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
@@ -23,6 +23,13 @@ export const COMMAND_MANIFEST = {
23
23
  examples: ["apifuse check .", "apifuse check providers/korea-air-quality"],
24
24
  modulePath: "./apifuse-check",
25
25
  },
26
+ "sync-assets": {
27
+ name: "sync-assets",
28
+ summary: "Regenerate SDK-managed agent prompt assets (AGENTS.md, .agents/skills, symlinks, manifest) for the installed SDK version.",
29
+ usage: "apifuse sync-assets [path] [--check]",
30
+ examples: ["apifuse sync-assets .", "apifuse sync-assets . --check"],
31
+ modulePath: "./apifuse-sync-assets",
32
+ },
26
33
  "submit-check": {
27
34
  name: "submit-check",
28
35
  summary: "Score provider bounty submission readiness and emit checklist evidence.",
@@ -73,6 +80,7 @@ export const COMMAND_ORDER = [
73
80
  "create",
74
81
  "dev",
75
82
  "check",
83
+ "sync-assets",
76
84
  "submit-check",
77
85
  "record",
78
86
  "test",
@@ -26,7 +26,10 @@ export type CreateResolvedOptions = {
26
26
  };
27
27
  export type ProviderPlanFile = {
28
28
  path: string;
29
+ /** File content, or the symlink target (relative path) for kind "symlink". */
29
30
  content: string;
31
+ /** Absent kind means "file" (backward compatible with older consumers). */
32
+ kind?: "file" | "symlink";
30
33
  };
31
34
  export type ProviderCreatePlan = {
32
35
  displayName: string;
@@ -1,11 +1,12 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
- import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { mkdir, readFile, rm, symlink, writeFile } from "node:fs/promises";
4
4
  import { dirname, relative, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { cancel, intro, isCancel, note, outro, select, text } from "@clack/prompts";
7
7
  import { z } from "zod";
8
8
  import packageJson from "../../package.json";
9
+ import { buildPromptAssetManifest, buildPromptAssetPlanEntries, PROMPT_ASSET_MANIFEST_PATH, } from "./prompt-assets.js";
9
10
  export const PROVIDER_NAME_REGEX = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
10
11
  export const CATEGORY_OPTIONS = [
11
12
  "developer-tools",
@@ -283,10 +284,15 @@ export async function buildProviderCreatePlan(options, cwd) {
283
284
  if (options.sdkSpecifier?.startsWith("workspace:") && !resolvedWorkspaceRoot) {
284
285
  throw new Error("workspace:* is only valid inside the APIFuse monorepo because public Provider SDK scaffolds must install from npm or an explicit tarball/file specifier.");
285
286
  }
287
+ // Exact pin, not a caret range: the prompt-asset freshness gate requires
288
+ // manifest.sdkVersion === installed SDK version, and the manifest records
289
+ // this CLI's own version. A caret range would let `bun install` resolve a
290
+ // newer SDK than the create binary, making a fresh scaffold fail its own
291
+ // gate. `sync-assets` after an explicit SDK upgrade re-records the version.
286
292
  const sdkSpecifier = options.sdkSpecifier ??
287
293
  (options.preset === "monorepo" && resolvedWorkspaceRoot
288
294
  ? "workspace:*"
289
- : `^${packageJson.version}`);
295
+ : packageJson.version);
290
296
  const relativeProviderRoot = relative(cwd, providerRoot) || options.name;
291
297
  const nextDevCommand = `cd ${relativeProviderRoot} && bun run dev`;
292
298
  const packageName = options.preset === "monorepo"
@@ -405,39 +411,21 @@ export async function buildProviderCreatePlan(options, cwd) {
405
411
  PROVIDER_ID: options.name,
406
412
  }),
407
413
  },
408
- {
409
- path: resolve(providerRoot, "AGENTS.md"),
410
- content: await renderTemplate("AGENTS.md.tpl", {}),
411
- },
412
- {
413
- path: resolve(providerRoot, "CLAUDE.md"),
414
- content: await renderTemplate("CLAUDE.md.tpl", {}),
415
- },
416
- {
417
- path: resolve(providerRoot, "skills", "normalization-standards", "SKILL.md"),
418
- content: await renderTemplate("skills/normalization-standards/SKILL.md.tpl", {}),
419
- },
420
- {
421
- path: resolve(providerRoot, "skills", "upstream-contract-verification", "SKILL.md"),
422
- content: await renderTemplate("skills/upstream-contract-verification/SKILL.md.tpl", {}),
423
- },
424
- {
425
- path: resolve(providerRoot, "skills", "fixtures-and-recording", "SKILL.md"),
426
- content: await renderTemplate("skills/fixtures-and-recording/SKILL.md.tpl", {}),
427
- },
428
- {
429
- path: resolve(providerRoot, "skills", "pagination-and-counts", "SKILL.md"),
430
- content: await renderTemplate("skills/pagination-and-counts/SKILL.md.tpl", {}),
431
- },
432
- {
433
- path: resolve(providerRoot, "skills", "health-checks-and-fail-closed", "SKILL.md"),
434
- content: await renderTemplate("skills/health-checks-and-fail-closed/SKILL.md.tpl", {}),
435
- },
436
- {
437
- path: resolve(providerRoot, "skills", "upstream-notes", "README.md"),
438
- content: await renderTemplate("skills/upstream-notes/README.md.tpl", {}),
439
- },
440
414
  ];
415
+ const promptAssetEntries = await buildPromptAssetPlanEntries(renderTemplate);
416
+ for (const entry of promptAssetEntries) {
417
+ files.push({
418
+ path: resolve(providerRoot, entry.path),
419
+ content: entry.content,
420
+ ...(entry.kind === "symlink" ? { kind: "symlink" } : {}),
421
+ });
422
+ }
423
+ // Manifest last: writePlan writes in order, so a crash mid-scaffold never
424
+ // leaves a manifest that claims assets which were not written.
425
+ files.push({
426
+ path: resolve(providerRoot, PROMPT_ASSET_MANIFEST_PATH),
427
+ content: buildPromptAssetManifest(promptAssetEntries, packageJson.version),
428
+ });
441
429
  return {
442
430
  displayName: options.displayName,
443
431
  files,
@@ -477,6 +465,7 @@ function renderPackageJson(input) {
477
465
  check: "apifuse check . && bun run type-check",
478
466
  "type-check": "tsc --noEmit",
479
467
  "submit-check": "apifuse submit-check . --markdown submission-report.md",
468
+ "sync-assets": "apifuse sync-assets .",
480
469
  test: "apifuse test .",
481
470
  record: "apifuse record .",
482
471
  start: "bun start.ts",
@@ -696,6 +685,13 @@ function isApifuseInternalWorkspaceRoot(workspaceRoot) {
696
685
  async function writePlan(plan) {
697
686
  for (const file of plan.files) {
698
687
  await mkdir(dirname(file.path), { recursive: true });
688
+ if (file.kind === "symlink") {
689
+ // rm operates on the link itself (lstat semantics) and tolerates
690
+ // directories, so whatever occupies the path is replaced by the link.
691
+ await rm(file.path, { recursive: true, force: true });
692
+ await symlink(file.content, file.path);
693
+ continue;
694
+ }
699
695
  await writeFile(file.path, file.content);
700
696
  }
701
697
  }
@@ -754,7 +750,10 @@ function printResult(plan, jsonMode, dryRun) {
754
750
  },
755
751
  validationCommands: plan.validationCommands,
756
752
  nextDevCommand: plan.nextDevCommand,
757
- files: plan.files.map((file) => relative(plan.providerRoot, file.path) || file.path),
753
+ files: plan.files.map((file) => {
754
+ const relativePath = relative(plan.providerRoot, file.path) || file.path;
755
+ return file.kind === "symlink" ? `${relativePath} -> ${file.content} (symlink)` : relativePath;
756
+ }),
758
757
  };
759
758
  if (jsonMode) {
760
759
  console.log(JSON.stringify(payload, null, 2));
@@ -0,0 +1,80 @@
1
+ /**
2
+ * SDK-managed agent prompt assets.
3
+ *
4
+ * `apifuse create` scaffolds these files, `apifuse sync-assets` regenerates
5
+ * them in an existing provider root, and `apifuse check` / `submit-check`
6
+ * enforce that they byte-match the installed SDK version (fail closed).
7
+ *
8
+ * Layout contract:
9
+ * - AGENTS.md — real file (agent guide)
10
+ * - CLAUDE.md — symlink -> AGENTS.md
11
+ * - .agents/skills/<skill>/SKILL.md — real files
12
+ * - .agents/skills/upstream-notes/README.md — real file
13
+ * - .claude / .codex — symlinks -> .agents
14
+ * - .apifuse/prompt-assets.json — manifest (schema v2), written last
15
+ */
16
+ export declare const PROMPT_ASSET_MANIFEST_PATH = ".apifuse/prompt-assets.json";
17
+ export declare const PROMPT_ASSET_MANIFEST_SCHEMA_VERSION = 2;
18
+ export declare const PROMPT_ASSET_SYNC_REMEDIATION = "Run `bun run sync-assets` (or `bunx apifuse sync-assets .`) to regenerate the SDK-managed agent prompt assets.";
19
+ export declare const PROMPT_ASSET_SYMLINKS: Readonly<Record<string, string>>;
20
+ /** Relative asset paths whose content is rendered from `<path>.tpl`. */
21
+ export declare const PROMPT_ASSET_FILE_PATHS: readonly string[];
22
+ export type PromptAssetKind = "file" | "symlink";
23
+ export type PromptAssetEntry = {
24
+ /** Provider-root-relative path (POSIX separators). */
25
+ path: string;
26
+ /** File content, or the symlink target for kind "symlink". */
27
+ content: string;
28
+ kind: PromptAssetKind;
29
+ };
30
+ export type PromptAssetTemplateRenderer = (fileName: string, values: Record<string, string>) => string | Promise<string>;
31
+ export type PromptAssetVerification = {
32
+ ok: boolean;
33
+ /** Expected paths (or the manifest) absent on disk. */
34
+ missing: string[];
35
+ /** Manifest recorded for a different SDK version than the installed one. */
36
+ stale: string[];
37
+ /** Files/symlinks/manifest whose bytes or target differ from the regenerated set. */
38
+ modified: string[];
39
+ /** Legacy layout remnants (top-level skills/). */
40
+ legacy: string[];
41
+ /** Entries inside `.agents/` that are not part of the managed asset set. */
42
+ unexpected: string[];
43
+ };
44
+ export type PromptAssetSyncResult = {
45
+ changed: boolean;
46
+ removed: string[];
47
+ wroteFiles: string[];
48
+ createdSymlinks: string[];
49
+ manifestPath: string;
50
+ };
51
+ /**
52
+ * Build the full managed asset entry list (files first, symlinks after,
53
+ * manifest excluded). The renderer is injected so `apifuse create` can reuse
54
+ * its own template renderer; sync/verify use the SDK-internal renderer.
55
+ */
56
+ export declare function buildPromptAssetPlanEntries(renderTemplate: PromptAssetTemplateRenderer): Promise<PromptAssetEntry[]>;
57
+ export declare function buildPromptAssetPlanEntriesSync(): PromptAssetEntry[];
58
+ /**
59
+ * Deterministic manifest serialization: schema v2, 2-space JSON, trailing
60
+ * newline, sorted paths (including symlink paths, excluding the manifest
61
+ * itself). `sdkVersion` + `paths` keep their v1 semantics so older parsers
62
+ * keep working; `schemaVersion` and `symlinks` are additive.
63
+ */
64
+ export declare function buildPromptAssetManifest(entries: readonly PromptAssetEntry[], sdkVersion: string): string;
65
+ export declare function installedSdkVersion(): string;
66
+ /**
67
+ * Verify the on-disk prompt assets against the set regenerated from the
68
+ * installed SDK. Uses lstat/readlink for symlinks (never follows), byte
69
+ * comparison for files, and exact-version comparison for the manifest.
70
+ */
71
+ export declare function verifyPromptAssets(providerRoot: string): PromptAssetVerification;
72
+ export declare function formatPromptAssetIssues(verification: PromptAssetVerification): string[];
73
+ /**
74
+ * Regenerate the full managed asset set for the installed SDK version in an
75
+ * existing provider root. Deletes legacy managed paths first (top-level
76
+ * skills/**, plus manifest-listed paths that left the set — restricted to
77
+ * managed namespaces with no symlinked ancestors), writes files, replaces
78
+ * symlinks, and writes the manifest last. Idempotent.
79
+ */
80
+ export declare function syncPromptAssets(providerRoot: string): PromptAssetSyncResult;