@farming-labs/docs 0.2.120 → 0.2.121

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 (188) hide show
  1. package/README.md +8 -0
  2. package/dist/access.d.mts +13 -0
  3. package/dist/access.mjs +56 -0
  4. package/dist/agent-conformance.d.mts +60 -0
  5. package/dist/agent-conformance.mjs +538 -0
  6. package/dist/agent-contract.d.mts +47 -0
  7. package/dist/agent-contract.mjs +645 -0
  8. package/dist/agent-detection.d.mts +6 -0
  9. package/dist/agent-detection.mjs +83 -0
  10. package/dist/agent-evals.d.mts +224 -0
  11. package/dist/{agent-evals-BLNLvXbG.mjs → agent-evals.mjs} +7 -565
  12. package/dist/agent-feedback-evaluations-node.mjs +38 -0
  13. package/dist/agent-feedback-evaluations.d.mts +91 -0
  14. package/dist/{agent-feedback-evaluations-CcMGlgsO.mjs → agent-feedback-evaluations.mjs} +2 -2
  15. package/dist/agent-feedback-loop.d.mts +45 -0
  16. package/dist/{agent-feedback-loop-CcZL_sb1.mjs → agent-feedback-loop.mjs} +1 -1
  17. package/dist/agent-maintenance.d.mts +71 -0
  18. package/dist/{agent-maintenance-CuZ7iAKq.mjs → agent-maintenance.mjs} +1 -1
  19. package/dist/agent-provenance.d.mts +23 -0
  20. package/dist/agent-provenance.mjs +77 -0
  21. package/dist/agent-scope.mjs +321 -0
  22. package/dist/agent-skills-archive.mjs +86 -0
  23. package/dist/agent-skills-bundle.d.mts +1 -1
  24. package/dist/{agent-skills-progressive-disclosure-PjPtTYL-.mjs → agent-skills-progressive-disclosure.mjs} +2 -2
  25. package/dist/{agent-skills-server-D5IuvwM7.d.mts → agent-skills-server.d.mts} +3 -3
  26. package/dist/{agent-skills-server-BC7md56k.mjs → agent-skills-server.mjs} +2 -2
  27. package/dist/agent-skills-vite.d.mts +3 -3
  28. package/dist/agent-skills-vite.mjs +1 -2
  29. package/dist/agent-surface-drift.mjs +236 -0
  30. package/dist/{golden-evaluations-CLUViycJ.mjs → agent-usefulness.mjs} +5 -290
  31. package/dist/{content-change-hydration-wqXIZHp6.d.mts → agent.d.mts} +10 -411
  32. package/dist/agent.mjs +2729 -0
  33. package/dist/{analytics-w3FDOksr.d.mts → analytics.d.mts} +2 -2
  34. package/dist/{analytics-p8Vhhu2P.mjs → analytics.mjs} +2 -2
  35. package/dist/{sitemap-server-BUdPBcGs.d.mts → api-reference.d.mts} +2 -6
  36. package/dist/api-reference.mjs +1481 -0
  37. package/dist/{audience-exposure-DBrFWULA.d.mts → audience-exposure.d.mts} +1 -1
  38. package/dist/audience-exposure.mjs +8 -0
  39. package/dist/audience.d.mts +44 -0
  40. package/dist/audience.mjs +1654 -0
  41. package/dist/authoring-mcp.d.mts +44 -0
  42. package/dist/{authoring-mcp-CiCUQe3o.mjs → authoring-mcp.mjs} +3 -3
  43. package/dist/browser.d.mts +6 -4
  44. package/dist/browser.mjs +6 -7
  45. package/dist/build.d.mts +8 -0
  46. package/dist/build.mjs +8 -0
  47. package/dist/changelog.d.mts +20 -0
  48. package/dist/changelog.mjs +39 -0
  49. package/dist/{agent-export-CA6IUQ7T.mjs → cli/agent-export.mjs} +19 -45
  50. package/dist/{agent-CYk2DxY7.mjs → cli/agent.mjs} +6 -35
  51. package/dist/{agents-BUiVmj8i.mjs → cli/agents.mjs} +5 -18
  52. package/dist/cli/api-doctor.mjs +206 -0
  53. package/dist/{authoring-C2ymvYWl.mjs → cli/authoring.mjs} +2 -8
  54. package/dist/{cloud-6eKrlmKd.mjs → cli/cloud.mjs} +3 -3
  55. package/dist/{codeblocks-CHpgAwY-.mjs → cli/codeblocks.mjs} +2 -2
  56. package/dist/cli/config.d.mts +11 -0
  57. package/dist/{config-BZnKAj_Y.mjs → cli/config.mjs} +1 -1
  58. package/dist/cli/dev-banner.mjs +58 -0
  59. package/dist/{dev-Bnn-NUNa.mjs → cli/dev.mjs} +3 -57
  60. package/dist/{doctor-Bfkrkzad.mjs → cli/doctor.mjs} +41 -226
  61. package/dist/{downgrade-CHMta85e.mjs → cli/downgrade.mjs} +2 -2
  62. package/dist/cli/errors.d.mts +4 -0
  63. package/dist/{errors-BtnVLhNF.mjs → cli/errors.mjs} +1 -1
  64. package/dist/{feedback-evals-DMilg9pY.mjs → cli/feedback-evals.mjs} +3 -36
  65. package/dist/{feedback-DL4T5oIO.mjs → cli/feedback.mjs} +1 -1
  66. package/dist/cli/git-dates.mjs +35 -0
  67. package/dist/cli/golden-evaluations.mjs +52 -0
  68. package/dist/cli/index.d.mts +2 -3
  69. package/dist/cli/index.mjs +38 -38
  70. package/dist/{init-K0LmXDZ5.mjs → cli/init.mjs} +3 -3
  71. package/dist/{mcp-iLCmnPJI.mjs → cli/mcp.mjs} +7 -19
  72. package/dist/{openapi-diff-HcpUNjA-.mjs → cli/openapi-diff.mjs} +2 -7
  73. package/dist/{openapi-sdk-BQKC6H-_.mjs → cli/openapi-sdk.mjs} +2 -7
  74. package/dist/{openapi-source-DK6ts_Bk.mjs → cli/openapi-source.mjs} +2 -2
  75. package/dist/{package-version-HJhYeq4M.mjs → cli/package-version.mjs} +2 -2
  76. package/dist/{propose-JmUv_BTt.mjs → cli/propose.mjs} +1 -1
  77. package/dist/{review-C6EmbV0l.mjs → cli/review.mjs} +16 -15
  78. package/dist/{robots-DteZB8vl.mjs → cli/robots.mjs} +3 -7
  79. package/dist/{search-Bhuv_YsL.mjs → cli/search.mjs} +7 -20
  80. package/dist/{sitemap-DW5LDKDa.mjs → cli/sitemap.mjs} +7 -42
  81. package/dist/{skills-BAPQLSCm.mjs → cli/skills.mjs} +5 -19
  82. package/dist/{templates-BuQ8YsGv.mjs → cli/templates.mjs} +1 -1
  83. package/dist/{upgrade-DlQMOFV1.mjs → cli/upgrade.mjs} +2 -2
  84. package/dist/{utils-C7KDrPpA.mjs → cli/utils.mjs} +1 -1
  85. package/dist/client/react.d.mts +2 -18
  86. package/dist/client/react.mjs +1 -157
  87. package/dist/{cloud-analytics-D14HplI7.mjs → cloud-analytics.mjs} +1 -1
  88. package/dist/{cloud-ask-ai-BrsTXQf6.d.mts → cloud-ask-ai.d.mts} +2 -2
  89. package/dist/{cloud-ask-ai-BqKhjpS5.mjs → cloud-ask-ai.mjs} +3 -3
  90. package/dist/code-blocks.d.mts +51 -0
  91. package/dist/{code-blocks-GYdvS3BH.mjs → code-blocks.mjs} +2 -2
  92. package/dist/code-group-mdx.d.mts +11 -0
  93. package/dist/code-group-mdx.mjs +57 -0
  94. package/dist/content-change-hydration.d.mts +87 -0
  95. package/dist/{openapi-mcp-BIOTLiA7.mjs → content-change-hydration.mjs} +5 -210
  96. package/dist/content-changes.d.mts +47 -0
  97. package/dist/content-changes.mjs +216 -0
  98. package/dist/create-theme.d.mts +48 -0
  99. package/dist/create-theme.mjs +57 -0
  100. package/dist/date.d.mts +5 -0
  101. package/dist/date.mjs +17 -0
  102. package/dist/define-docs.d.mts +9 -0
  103. package/dist/define-docs.mjs +46 -0
  104. package/dist/docs-cloud-client.d.mts +18 -0
  105. package/dist/docs-cloud-client.mjs +161 -0
  106. package/dist/docs-cloud-server.d.mts +2 -2
  107. package/dist/docs-cloud-server.mjs +2 -3
  108. package/dist/heading-toc.d.mts +10 -0
  109. package/dist/heading-toc.mjs +23 -0
  110. package/dist/http-body.d.mts +14 -0
  111. package/dist/{http-body-DkAPk6D5.mjs → http-body.mjs} +1 -1
  112. package/dist/http-cache.d.mts +25 -0
  113. package/dist/http-cache.mjs +140 -0
  114. package/dist/http-link.mjs +81 -0
  115. package/dist/i18n.d.mts +18 -0
  116. package/dist/{i18n-B1gJ9EW0.mjs → i18n.mjs} +1 -1
  117. package/dist/index.d.mts +42 -674
  118. package/dist/index.mjs +40 -14
  119. package/dist/markdown-rendering.mjs +1 -1
  120. package/dist/markdown-section-cache.mjs +49 -0
  121. package/dist/markdown-sections.d.mts +47 -0
  122. package/dist/{markdown-sections-9Oxr33b-.mjs → markdown-sections.mjs} +29 -703
  123. package/dist/mcp-auth.d.mts +14 -0
  124. package/dist/mcp-auth.mjs +99 -0
  125. package/dist/mcp.d.mts +5 -3
  126. package/dist/mcp.mjs +21 -9
  127. package/dist/mdx.d.mts +6 -0
  128. package/dist/mdx.mjs +7 -0
  129. package/dist/metadata.d.mts +60 -0
  130. package/dist/{metadata-BOHn0Y5K.mjs → metadata.mjs} +2 -2
  131. package/dist/native-api-reference.mjs +968 -0
  132. package/dist/okf.d.mts +42 -0
  133. package/dist/okf.mjs +145 -0
  134. package/dist/openapi-contract.mjs +154 -0
  135. package/dist/{openapi-mcp-node-C4jUpZG6.mjs → openapi-mcp-node.mjs} +1 -1
  136. package/dist/openapi-mcp.d.mts +26 -0
  137. package/dist/openapi-mcp.mjs +132 -0
  138. package/dist/openapi-operations.d.mts +71 -0
  139. package/dist/{openapi-operations-DFpaqOqA.mjs → openapi-operations.mjs} +1 -1
  140. package/dist/openapi-overlays.mjs +221 -0
  141. package/dist/openapi-references.mjs +233 -0
  142. package/dist/pagination.d.mts +7 -0
  143. package/dist/pagination.mjs +100 -0
  144. package/dist/prompt-references.d.mts +12 -0
  145. package/dist/prompt-references.mjs +132 -0
  146. package/dist/prompt-utils.d.mts +36 -0
  147. package/dist/{prompt-utils-B5g-bv7o.mjs → prompt-utils.mjs} +1 -57
  148. package/dist/reading-time.d.mts +23 -0
  149. package/dist/reading-time.mjs +58 -0
  150. package/dist/related.d.mts +7 -0
  151. package/dist/related.mjs +50 -0
  152. package/dist/retrieval-digest.d.mts +16 -0
  153. package/dist/{retrieval-digest-CT-eIEcp.mjs → retrieval-digest.mjs} +1 -1
  154. package/dist/review.d.mts +69 -0
  155. package/dist/review.mjs +562 -0
  156. package/dist/robots.d.mts +54 -0
  157. package/dist/{robots-BYJAVeI6.mjs → robots.mjs} +5 -3
  158. package/dist/runtime.d.mts +3 -3
  159. package/dist/runtime.mjs +3 -9
  160. package/dist/search.d.mts +210 -0
  161. package/dist/search.mjs +3401 -0
  162. package/dist/server.d.mts +22 -198
  163. package/dist/server.mjs +21 -19
  164. package/dist/sidebar.d.mts +15 -0
  165. package/dist/sidebar.mjs +73 -0
  166. package/dist/sitemap-server.d.mts +7 -0
  167. package/dist/{sitemap-server-Lg3YhUx4.mjs → sitemap-server.mjs} +2 -2
  168. package/dist/{sitemap-Cl8vrixd.d.mts → sitemap.d.mts} +3 -3
  169. package/dist/sitemap.mjs +254 -0
  170. package/dist/{standards-discovery-BHPc7YIX.d.mts → standards-discovery.d.mts} +2 -2
  171. package/dist/{standards-discovery-sSEojU80.mjs → standards-discovery.mjs} +3 -139
  172. package/dist/telemetry-runtime.d.mts +42 -0
  173. package/dist/telemetry-runtime.mjs +238 -0
  174. package/dist/telemetry.d.mts +15 -0
  175. package/dist/telemetry.mjs +117 -0
  176. package/dist/{types-BJFeMXWZ.d.mts → types.d.mts} +3 -2
  177. package/dist/urls.d.mts +7 -0
  178. package/dist/urls.mjs +21 -0
  179. package/dist/utils.d.mts +8 -0
  180. package/dist/utils.mjs +22 -0
  181. package/package.json +21 -3
  182. package/dist/agent-DkAidqtV.mjs +0 -9026
  183. package/dist/api-reference-BYee4zMo.mjs +0 -3046
  184. package/dist/prompt-references-DMgbu_dz.mjs +0 -1082
  185. package/dist/retrieval-digest-AOx2-LbC.d.mts +0 -367
  186. package/dist/sidebar-CFHBj29f.mjs +0 -421
  187. package/dist/sidebar-CMPbVfGP.d.mts +0 -63
  188. /package/dist/{openapi-CfCzX_a1.mjs → cli/openapi.mjs} +0 -0
@@ -0,0 +1,47 @@
1
+ import { PageAgentFrontmatter } from "./types.mjs";
2
+
3
+ //#region src/agent-contract.d.ts
4
+ interface PageAgentFrontmatterIssue {
5
+ path: string;
6
+ message: string;
7
+ }
8
+ declare const PAGE_AGENT_STRUCTURED_CONTRACT_FIELDS: readonly ["task", "outcome", "appliesTo", "prerequisites", "files", "commands", "sideEffects", "verification", "rollback", "failureModes"];
9
+ declare const PAGE_AGENT_CONTRACT_FIELDS: readonly ["tokenBudget", "access", "task", "outcome", "appliesTo", "prerequisites", "files", "commands", "sideEffects", "verification", "rollback", "failureModes"];
10
+ declare const PAGE_AGENT_CONTRACT_FIELD_SCHEMA: {
11
+ readonly tokenBudget: "number";
12
+ readonly access: "{visibility?,scopes?,claims?}";
13
+ readonly task: "string";
14
+ readonly outcome: "string";
15
+ readonly appliesTo: {
16
+ readonly framework: "string|string[]";
17
+ readonly version: "string|string[]";
18
+ readonly package: "string|string[]";
19
+ };
20
+ readonly prerequisites: "string[]";
21
+ readonly files: "string[]";
22
+ readonly commands: "Array<string|{run,cwd?,description?}>";
23
+ readonly sideEffects: "string[]";
24
+ readonly verification: "Array<string|{description?,run?,expect?}>";
25
+ readonly rollback: "string[]";
26
+ readonly failureModes: "Array<string|{symptom,resolution?}>";
27
+ };
28
+ declare const PAGE_AGENT_CONTRACT_START_MARKER = "<!-- farming-labs:agent-contract:start -->";
29
+ declare const PAGE_AGENT_CONTRACT_END_MARKER = "<!-- farming-labs:agent-contract:end -->";
30
+ /**
31
+ * Normalize untrusted page frontmatter into the stable agent contract shape.
32
+ * Invalid fields are omitted so malformed author input cannot break page delivery.
33
+ */
34
+ declare function normalizePageAgentFrontmatter(value: unknown): PageAgentFrontmatter | undefined;
35
+ declare function hasStructuredPageAgentContract(value: unknown): boolean;
36
+ /** Return author-facing validation issues without throwing. */
37
+ declare function getPageAgentFrontmatterIssues(value: unknown): PageAgentFrontmatterIssue[];
38
+ /** Render normalized `agent` YAML in a stable field order. */
39
+ declare function renderPageAgentFrontmatterYamlLines(value: unknown, indentation?: number): string[];
40
+ /** Render the structured contract as deterministic, compact machine-readable Markdown. */
41
+ declare function renderPageAgentContractMarkdown(value: unknown): string;
42
+ /** Remove generated contract blocks while preserving handwritten guidance. */
43
+ declare function stripGeneratedPageAgentContractMarkdown(markdown: string): string;
44
+ /** Insert one generated contract unless the document already has handwritten contract guidance. */
45
+ declare function upsertPageAgentContractMarkdown(markdown: string, value: unknown): string;
46
+ //#endregion
47
+ export { PAGE_AGENT_CONTRACT_END_MARKER, PAGE_AGENT_CONTRACT_FIELDS, PAGE_AGENT_CONTRACT_FIELD_SCHEMA, PAGE_AGENT_CONTRACT_START_MARKER, PAGE_AGENT_STRUCTURED_CONTRACT_FIELDS, PageAgentFrontmatterIssue, getPageAgentFrontmatterIssues, hasStructuredPageAgentContract, normalizePageAgentFrontmatter, renderPageAgentContractMarkdown, renderPageAgentFrontmatterYamlLines, stripGeneratedPageAgentContractMarkdown, upsertPageAgentContractMarkdown };
@@ -0,0 +1,645 @@
1
+ import { normalizeDocsPageAccessPolicy } from "./access.mjs";
2
+
3
+ //#region src/agent-contract.ts
4
+ const PAGE_AGENT_STRUCTURED_CONTRACT_FIELDS = [
5
+ "task",
6
+ "outcome",
7
+ "appliesTo",
8
+ "prerequisites",
9
+ "files",
10
+ "commands",
11
+ "sideEffects",
12
+ "verification",
13
+ "rollback",
14
+ "failureModes"
15
+ ];
16
+ const PAGE_AGENT_CONTRACT_FIELDS = [
17
+ "tokenBudget",
18
+ "access",
19
+ ...PAGE_AGENT_STRUCTURED_CONTRACT_FIELDS
20
+ ];
21
+ const PAGE_AGENT_CONTRACT_FIELD_SCHEMA = {
22
+ tokenBudget: "number",
23
+ access: "{visibility?,scopes?,claims?}",
24
+ task: "string",
25
+ outcome: "string",
26
+ appliesTo: {
27
+ framework: "string|string[]",
28
+ version: "string|string[]",
29
+ package: "string|string[]"
30
+ },
31
+ prerequisites: "string[]",
32
+ files: "string[]",
33
+ commands: "Array<string|{run,cwd?,description?}>",
34
+ sideEffects: "string[]",
35
+ verification: "Array<string|{description?,run?,expect?}>",
36
+ rollback: "string[]",
37
+ failureModes: "Array<string|{symptom,resolution?}>"
38
+ };
39
+ const APPLIES_TO_FIELDS = [
40
+ "framework",
41
+ "version",
42
+ "package"
43
+ ];
44
+ const COMMAND_FIELDS = [
45
+ "run",
46
+ "cwd",
47
+ "description"
48
+ ];
49
+ const VERIFICATION_FIELDS = [
50
+ "description",
51
+ "run",
52
+ "expect"
53
+ ];
54
+ const FAILURE_MODE_FIELDS = ["symptom", "resolution"];
55
+ const ACCESS_FIELDS = [
56
+ "visibility",
57
+ "scopes",
58
+ "claims"
59
+ ];
60
+ const PAGE_AGENT_CONTRACT_START_MARKER = "<!-- farming-labs:agent-contract:start -->";
61
+ const PAGE_AGENT_CONTRACT_END_MARKER = "<!-- farming-labs:agent-contract:end -->";
62
+ function isRecord(value) {
63
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
64
+ }
65
+ function normalizeString(value) {
66
+ if (typeof value !== "string") return void 0;
67
+ return value.trim() || void 0;
68
+ }
69
+ function normalizeStringList(value) {
70
+ if (!Array.isArray(value)) return void 0;
71
+ const seen = /* @__PURE__ */ new Set();
72
+ const normalized = [];
73
+ for (const item of value) {
74
+ const text = normalizeString(item);
75
+ if (!text || seen.has(text)) continue;
76
+ seen.add(text);
77
+ normalized.push(text);
78
+ }
79
+ return normalized.length > 0 ? normalized : void 0;
80
+ }
81
+ function normalizeStringOrList(value) {
82
+ const single = normalizeString(value);
83
+ if (single) return [single];
84
+ return normalizeStringList(value);
85
+ }
86
+ function normalizeAppliesTo(value) {
87
+ if (!isRecord(value)) return void 0;
88
+ const framework = normalizeStringOrList(value.framework);
89
+ const version = normalizeStringOrList(value.version);
90
+ const packageNames = normalizeStringOrList(value.package);
91
+ if (!framework && !version && !packageNames) return void 0;
92
+ return {
93
+ ...framework ? { framework } : {},
94
+ ...version ? { version } : {},
95
+ ...packageNames ? { package: packageNames } : {}
96
+ };
97
+ }
98
+ function normalizeCommands(value) {
99
+ if (!Array.isArray(value)) return void 0;
100
+ const commands = [];
101
+ for (const item of value) {
102
+ const shorthand = normalizeString(item);
103
+ if (shorthand) {
104
+ commands.push(shorthand);
105
+ continue;
106
+ }
107
+ if (!isRecord(item)) continue;
108
+ const run = normalizeString(item.run);
109
+ if (!run) continue;
110
+ const cwd = normalizeString(item.cwd);
111
+ const description = normalizeString(item.description);
112
+ commands.push({
113
+ run,
114
+ ...cwd ? { cwd } : {},
115
+ ...description ? { description } : {}
116
+ });
117
+ }
118
+ return commands.length > 0 ? commands : void 0;
119
+ }
120
+ function normalizeVerification(value) {
121
+ if (!Array.isArray(value)) return void 0;
122
+ const verification = [];
123
+ for (const item of value) {
124
+ const shorthand = normalizeString(item);
125
+ if (shorthand) {
126
+ verification.push(shorthand);
127
+ continue;
128
+ }
129
+ if (!isRecord(item)) continue;
130
+ const description = normalizeString(item.description);
131
+ const run = normalizeString(item.run);
132
+ const expect = normalizeString(item.expect);
133
+ if (!description && !run && !expect) continue;
134
+ verification.push({
135
+ ...description ? { description } : {},
136
+ ...run ? { run } : {},
137
+ ...expect ? { expect } : {}
138
+ });
139
+ }
140
+ return verification.length > 0 ? verification : void 0;
141
+ }
142
+ function normalizeFailureModes(value) {
143
+ if (!Array.isArray(value)) return void 0;
144
+ const failureModes = [];
145
+ for (const item of value) {
146
+ const shorthand = normalizeString(item);
147
+ if (shorthand) {
148
+ failureModes.push(shorthand);
149
+ continue;
150
+ }
151
+ if (!isRecord(item)) continue;
152
+ const symptom = normalizeString(item.symptom);
153
+ if (!symptom) continue;
154
+ const resolution = normalizeString(item.resolution);
155
+ failureModes.push({
156
+ symptom,
157
+ ...resolution ? { resolution } : {}
158
+ });
159
+ }
160
+ return failureModes.length > 0 ? failureModes : void 0;
161
+ }
162
+ function normalizeTokenBudget(value) {
163
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return void 0;
164
+ return Math.ceil(value);
165
+ }
166
+ /**
167
+ * Normalize untrusted page frontmatter into the stable agent contract shape.
168
+ * Invalid fields are omitted so malformed author input cannot break page delivery.
169
+ */
170
+ function normalizePageAgentFrontmatter(value) {
171
+ if (!isRecord(value)) return void 0;
172
+ const tokenBudget = normalizeTokenBudget(value.tokenBudget);
173
+ const access = "access" in value ? normalizeDocsPageAccessPolicy(value.access) ?? { visibility: "authenticated" } : void 0;
174
+ const task = normalizeString(value.task);
175
+ const outcome = normalizeString(value.outcome);
176
+ const appliesTo = normalizeAppliesTo(value.appliesTo);
177
+ const prerequisites = normalizeStringList(value.prerequisites);
178
+ const files = normalizeStringList(value.files);
179
+ const commands = normalizeCommands(value.commands);
180
+ const sideEffects = normalizeStringList(value.sideEffects);
181
+ const verification = normalizeVerification(value.verification);
182
+ const rollback = normalizeStringList(value.rollback);
183
+ const failureModes = normalizeFailureModes(value.failureModes);
184
+ const normalized = {
185
+ ...tokenBudget !== void 0 ? { tokenBudget } : {},
186
+ ...access ? { access } : {},
187
+ ...task ? { task } : {},
188
+ ...outcome ? { outcome } : {},
189
+ ...appliesTo ? { appliesTo } : {},
190
+ ...prerequisites ? { prerequisites } : {},
191
+ ...files ? { files } : {},
192
+ ...commands ? { commands } : {},
193
+ ...sideEffects ? { sideEffects } : {},
194
+ ...verification ? { verification } : {},
195
+ ...rollback ? { rollback } : {},
196
+ ...failureModes ? { failureModes } : {}
197
+ };
198
+ return Object.keys(normalized).length > 0 ? normalized : void 0;
199
+ }
200
+ function hasStructuredPageAgentContract(value) {
201
+ const normalized = normalizePageAgentFrontmatter(value);
202
+ if (!normalized) return false;
203
+ return PAGE_AGENT_STRUCTURED_CONTRACT_FIELDS.some((field) => normalized[field] !== void 0);
204
+ }
205
+ function addStringIssue(issues, object, field) {
206
+ if (!(field in object)) return;
207
+ if (!normalizeString(object[field])) issues.push({
208
+ path: `agent.${field}`,
209
+ message: "must be a non-empty string"
210
+ });
211
+ }
212
+ function addStringListIssues(issues, object, field) {
213
+ if (!(field in object)) return;
214
+ const value = object[field];
215
+ if (!Array.isArray(value) || value.length === 0) {
216
+ issues.push({
217
+ path: `agent.${field}`,
218
+ message: "must be a non-empty string array"
219
+ });
220
+ return;
221
+ }
222
+ value.forEach((item, index) => {
223
+ if (!normalizeString(item)) issues.push({
224
+ path: `agent.${field}[${index}]`,
225
+ message: "must be a non-empty string"
226
+ });
227
+ });
228
+ }
229
+ function editDistance(left, right) {
230
+ const previous = Array.from({ length: right.length + 1 }, (_, index) => index);
231
+ for (let leftIndex = 1; leftIndex <= left.length; leftIndex += 1) {
232
+ const current = [leftIndex];
233
+ for (let rightIndex = 1; rightIndex <= right.length; rightIndex += 1) current[rightIndex] = Math.min((current[rightIndex - 1] ?? 0) + 1, (previous[rightIndex] ?? 0) + 1, (previous[rightIndex - 1] ?? 0) + (left[leftIndex - 1] === right[rightIndex - 1] ? 0 : 1));
234
+ previous.splice(0, previous.length, ...current);
235
+ }
236
+ return previous[right.length] ?? 0;
237
+ }
238
+ function closestKnownField(field, allowed) {
239
+ const closest = allowed.map((candidate) => ({
240
+ candidate,
241
+ distance: editDistance(field, candidate)
242
+ })).sort((left, right) => left.distance - right.distance || left.candidate.localeCompare(right.candidate))[0];
243
+ if (!closest) return void 0;
244
+ const threshold = Math.max(1, Math.min(3, Math.floor(closest.candidate.length / 3)));
245
+ return closest.distance <= threshold ? closest.candidate : void 0;
246
+ }
247
+ function addUnknownKeyIssues(issues, object, allowed, path) {
248
+ for (const field of Object.keys(object)) {
249
+ if (allowed.includes(field)) continue;
250
+ const suggestion = closestKnownField(field, allowed);
251
+ issues.push({
252
+ path: `${path}.${field}`,
253
+ message: suggestion ? `is not recognized; did you mean "${path}.${suggestion}"?` : "is not recognized"
254
+ });
255
+ }
256
+ }
257
+ /** Return author-facing validation issues without throwing. */
258
+ function getPageAgentFrontmatterIssues(value) {
259
+ if (value === void 0) return [];
260
+ if (!isRecord(value)) return [{
261
+ path: "agent",
262
+ message: "must be an object"
263
+ }];
264
+ const issues = [];
265
+ addUnknownKeyIssues(issues, value, PAGE_AGENT_CONTRACT_FIELDS, "agent");
266
+ if ("tokenBudget" in value && (typeof value.tokenBudget !== "number" || !Number.isFinite(value.tokenBudget) || value.tokenBudget <= 0)) issues.push({
267
+ path: "agent.tokenBudget",
268
+ message: "must be a positive finite number"
269
+ });
270
+ if ("access" in value) if (!isRecord(value.access)) issues.push({
271
+ path: "agent.access",
272
+ message: "must be an object"
273
+ });
274
+ else {
275
+ addUnknownKeyIssues(issues, value.access, ACCESS_FIELDS, "agent.access");
276
+ if ("visibility" in value.access && value.access.visibility !== "public" && value.access.visibility !== "authenticated") issues.push({
277
+ path: "agent.access.visibility",
278
+ message: "must be \"public\" or \"authenticated\""
279
+ });
280
+ if ("scopes" in value.access && !normalizeStringList(value.access.scopes)) issues.push({
281
+ path: "agent.access.scopes",
282
+ message: "must be a non-empty string array"
283
+ });
284
+ if ("claims" in value.access) {
285
+ if (!isRecord(value.access.claims) || Object.keys(value.access.claims).length === 0) issues.push({
286
+ path: "agent.access.claims",
287
+ message: "must be a non-empty object"
288
+ });
289
+ else for (const [name, claim] of Object.entries(value.access.claims)) if (!name.trim() || normalizeDocsPageAccessPolicy({ claims: { [name]: claim } }) === void 0) issues.push({
290
+ path: `agent.access.claims.${name || "<empty>"}`,
291
+ message: "must be a string, number, boolean, or non-empty string array"
292
+ });
293
+ }
294
+ if (!normalizeDocsPageAccessPolicy(value.access)) issues.push({
295
+ path: "agent.access",
296
+ message: "must include a valid visibility, scope, or claim"
297
+ });
298
+ }
299
+ addStringIssue(issues, value, "task");
300
+ addStringIssue(issues, value, "outcome");
301
+ if ("appliesTo" in value) if (!isRecord(value.appliesTo)) issues.push({
302
+ path: "agent.appliesTo",
303
+ message: "must be an object"
304
+ });
305
+ else {
306
+ addUnknownKeyIssues(issues, value.appliesTo, APPLIES_TO_FIELDS, "agent.appliesTo");
307
+ for (const field of [
308
+ "framework",
309
+ "version",
310
+ "package"
311
+ ]) {
312
+ if (!(field in value.appliesTo)) continue;
313
+ const fieldValue = value.appliesTo[field];
314
+ if (!normalizeStringOrList(fieldValue)) {
315
+ issues.push({
316
+ path: `agent.appliesTo.${field}`,
317
+ message: "must be a non-empty string or string array"
318
+ });
319
+ continue;
320
+ }
321
+ if (Array.isArray(fieldValue)) fieldValue.forEach((item, index) => {
322
+ if (!normalizeString(item)) issues.push({
323
+ path: `agent.appliesTo.${field}[${index}]`,
324
+ message: "must be a non-empty string"
325
+ });
326
+ });
327
+ }
328
+ if (!normalizeAppliesTo(value.appliesTo)) issues.push({
329
+ path: "agent.appliesTo",
330
+ message: "must include framework, version, or package"
331
+ });
332
+ }
333
+ for (const field of [
334
+ "prerequisites",
335
+ "files",
336
+ "sideEffects",
337
+ "rollback"
338
+ ]) addStringListIssues(issues, value, field);
339
+ if ("commands" in value) if (!Array.isArray(value.commands) || value.commands.length === 0) issues.push({
340
+ path: "agent.commands",
341
+ message: "must be a non-empty array"
342
+ });
343
+ else value.commands.forEach((command, index) => {
344
+ if (normalizeString(command)) return;
345
+ if (!isRecord(command)) {
346
+ issues.push({
347
+ path: `agent.commands[${index}]`,
348
+ message: "must be a command string or an object with a non-empty run field"
349
+ });
350
+ return;
351
+ }
352
+ addUnknownKeyIssues(issues, command, COMMAND_FIELDS, `agent.commands[${index}]`);
353
+ if (!normalizeString(command.run)) {
354
+ issues.push({
355
+ path: `agent.commands[${index}]`,
356
+ message: "must be a command string or an object with a non-empty run field"
357
+ });
358
+ return;
359
+ }
360
+ for (const field of ["cwd", "description"]) if (field in command && !normalizeString(command[field])) issues.push({
361
+ path: `agent.commands[${index}].${field}`,
362
+ message: "must be a non-empty string"
363
+ });
364
+ });
365
+ if ("verification" in value) if (!Array.isArray(value.verification) || value.verification.length === 0) issues.push({
366
+ path: "agent.verification",
367
+ message: "must be a non-empty array"
368
+ });
369
+ else value.verification.forEach((step, index) => {
370
+ if (normalizeString(step)) return;
371
+ if (!isRecord(step)) {
372
+ issues.push({
373
+ path: `agent.verification[${index}]`,
374
+ message: "must be a string or an object with description, run, or expect"
375
+ });
376
+ return;
377
+ }
378
+ addUnknownKeyIssues(issues, step, VERIFICATION_FIELDS, `agent.verification[${index}]`);
379
+ if (!normalizeVerification([step])) {
380
+ issues.push({
381
+ path: `agent.verification[${index}]`,
382
+ message: "must be a string or an object with description, run, or expect"
383
+ });
384
+ return;
385
+ }
386
+ for (const field of [
387
+ "description",
388
+ "run",
389
+ "expect"
390
+ ]) if (field in step && !normalizeString(step[field])) issues.push({
391
+ path: `agent.verification[${index}].${field}`,
392
+ message: "must be a non-empty string"
393
+ });
394
+ });
395
+ if ("failureModes" in value) if (!Array.isArray(value.failureModes) || value.failureModes.length === 0) issues.push({
396
+ path: "agent.failureModes",
397
+ message: "must be a non-empty array"
398
+ });
399
+ else value.failureModes.forEach((mode, index) => {
400
+ if (normalizeString(mode)) return;
401
+ if (!isRecord(mode)) {
402
+ issues.push({
403
+ path: `agent.failureModes[${index}]`,
404
+ message: "must be a string or an object with a non-empty symptom field"
405
+ });
406
+ return;
407
+ }
408
+ addUnknownKeyIssues(issues, mode, FAILURE_MODE_FIELDS, `agent.failureModes[${index}]`);
409
+ if (!normalizeString(mode.symptom)) {
410
+ issues.push({
411
+ path: `agent.failureModes[${index}]`,
412
+ message: "must be a string or an object with a non-empty symptom field"
413
+ });
414
+ return;
415
+ }
416
+ if ("resolution" in mode && !normalizeString(mode.resolution)) issues.push({
417
+ path: `agent.failureModes[${index}].resolution`,
418
+ message: "must be a non-empty string"
419
+ });
420
+ });
421
+ return issues;
422
+ }
423
+ function yamlString(value) {
424
+ return JSON.stringify(value);
425
+ }
426
+ function renderYamlStringList(lines, indent, key, values) {
427
+ lines.push(`${indent}${key}:`);
428
+ for (const value of values) lines.push(`${indent} - ${yamlString(value)}`);
429
+ }
430
+ function renderYamlObjectList(lines, indent, key, values, fields) {
431
+ lines.push(`${indent}${key}:`);
432
+ for (const value of values) {
433
+ if (typeof value === "string") {
434
+ lines.push(`${indent} - ${yamlString(value)}`);
435
+ continue;
436
+ }
437
+ const record = value;
438
+ const firstField = fields.find((field) => normalizeString(record[field]));
439
+ if (!firstField) continue;
440
+ lines.push(`${indent} - ${firstField}: ${yamlString(normalizeString(record[firstField]))}`);
441
+ for (const field of fields) {
442
+ const fieldValue = normalizeString(record[field]);
443
+ if (field === firstField || !fieldValue) continue;
444
+ lines.push(`${indent} ${field}: ${yamlString(fieldValue)}`);
445
+ }
446
+ }
447
+ }
448
+ /** Render normalized `agent` YAML in a stable field order. */
449
+ function renderPageAgentFrontmatterYamlLines(value, indentation = 0) {
450
+ const agent = normalizePageAgentFrontmatter(value);
451
+ if (!agent) return [];
452
+ const indent = " ".repeat(Math.max(0, indentation));
453
+ const child = `${indent} `;
454
+ const lines = [`${indent}agent:`];
455
+ if (agent.tokenBudget !== void 0) lines.push(`${child}tokenBudget: ${agent.tokenBudget}`);
456
+ if (agent.access) {
457
+ lines.push(`${child}access:`);
458
+ const accessIndent = `${child} `;
459
+ if (agent.access.visibility) lines.push(`${accessIndent}visibility: ${agent.access.visibility}`);
460
+ if (agent.access.scopes) renderYamlStringList(lines, accessIndent, "scopes", [...agent.access.scopes]);
461
+ if (agent.access.claims) {
462
+ lines.push(`${accessIndent}claims:`);
463
+ const claimsIndent = `${accessIndent} `;
464
+ for (const [name, claim] of Object.entries(agent.access.claims).sort(([left], [right]) => left.localeCompare(right))) if (Array.isArray(claim)) renderYamlStringList(lines, claimsIndent, yamlString(name), [...claim]);
465
+ else lines.push(`${claimsIndent}${yamlString(name)}: ${typeof claim === "string" ? yamlString(claim) : claim}`);
466
+ }
467
+ }
468
+ if (agent.task) lines.push(`${child}task: ${yamlString(agent.task)}`);
469
+ if (agent.outcome) lines.push(`${child}outcome: ${yamlString(agent.outcome)}`);
470
+ if (agent.appliesTo) {
471
+ lines.push(`${child}appliesTo:`);
472
+ const appliesIndent = `${child} `;
473
+ for (const field of [
474
+ "framework",
475
+ "version",
476
+ "package"
477
+ ]) {
478
+ const values = normalizeStringOrList(agent.appliesTo[field]);
479
+ if (values) renderYamlStringList(lines, appliesIndent, field, values);
480
+ }
481
+ }
482
+ if (agent.prerequisites) renderYamlStringList(lines, child, "prerequisites", agent.prerequisites);
483
+ if (agent.files) renderYamlStringList(lines, child, "files", agent.files);
484
+ if (agent.commands) renderYamlObjectList(lines, child, "commands", agent.commands, [
485
+ "run",
486
+ "cwd",
487
+ "description"
488
+ ]);
489
+ if (agent.sideEffects) renderYamlStringList(lines, child, "sideEffects", agent.sideEffects);
490
+ if (agent.verification) renderYamlObjectList(lines, child, "verification", agent.verification, [
491
+ "description",
492
+ "run",
493
+ "expect"
494
+ ]);
495
+ if (agent.rollback) renderYamlStringList(lines, child, "rollback", agent.rollback);
496
+ if (agent.failureModes) renderYamlObjectList(lines, child, "failureModes", agent.failureModes, ["symptom", "resolution"]);
497
+ return lines;
498
+ }
499
+ function inlineCode(value) {
500
+ const longestRun = Math.max(0, ...[...value.matchAll(/`+/g)].map((match) => match[0].length));
501
+ const fence = "`".repeat(longestRun + 1);
502
+ const padding = value.startsWith("`") || value.endsWith("`") ? " " : "";
503
+ return `${fence}${padding}${value}${padding}${fence}`;
504
+ }
505
+ function renderTextList(lines, title, values, code = false) {
506
+ lines.push("", `### ${title}`, "");
507
+ for (const value of values) lines.push(`- ${code ? inlineCode(value) : value}`);
508
+ }
509
+ /** Render the structured contract as deterministic, compact machine-readable Markdown. */
510
+ function renderPageAgentContractMarkdown(value) {
511
+ const agent = normalizePageAgentFrontmatter(value);
512
+ if (!agent || !hasStructuredPageAgentContract(agent)) return "";
513
+ const lines = [PAGE_AGENT_CONTRACT_START_MARKER, "## Agent Contract"];
514
+ if (agent.task) lines.push("", `Task: ${agent.task}`);
515
+ if (agent.outcome) lines.push(`Outcome: ${agent.outcome}`);
516
+ if (agent.appliesTo) {
517
+ lines.push("", "### Applies To", "");
518
+ for (const [label, field] of [
519
+ ["Framework", "framework"],
520
+ ["Version", "version"],
521
+ ["Package", "package"]
522
+ ]) {
523
+ const values = normalizeStringOrList(agent.appliesTo[field]);
524
+ if (values) lines.push(`- ${label}: ${values.map(inlineCode).join(", ")}`);
525
+ }
526
+ }
527
+ if (agent.prerequisites) renderTextList(lines, "Prerequisites", agent.prerequisites);
528
+ if (agent.files) renderTextList(lines, "Files", agent.files, true);
529
+ if (agent.commands) {
530
+ lines.push("", "### Commands", "");
531
+ for (const command of agent.commands) {
532
+ if (typeof command === "string") {
533
+ lines.push(`- ${inlineCode(command)}`);
534
+ continue;
535
+ }
536
+ const details = [command.cwd ? `cwd ${inlineCode(command.cwd)}` : void 0, command.description].filter(Boolean);
537
+ lines.push(`- ${inlineCode(command.run)}${details.length ? ` — ${details.join("; ")}` : ""}`);
538
+ }
539
+ }
540
+ if (agent.sideEffects) renderTextList(lines, "Side Effects", agent.sideEffects);
541
+ if (agent.verification) {
542
+ lines.push("", "### Verification", "");
543
+ for (const step of agent.verification) {
544
+ if (typeof step === "string") {
545
+ lines.push(`- ${step}`);
546
+ continue;
547
+ }
548
+ const summary = step.description ?? (step.run ? `Run ${inlineCode(step.run)}` : step.expect ?? "Verification step");
549
+ lines.push(`- ${summary}`);
550
+ if (step.run && step.description) lines.push(` - Run: ${inlineCode(step.run)}`);
551
+ if (step.expect && step.expect !== summary) lines.push(` - Expected: ${step.expect}`);
552
+ }
553
+ }
554
+ if (agent.rollback) renderTextList(lines, "Rollback", agent.rollback);
555
+ if (agent.failureModes) {
556
+ lines.push("", "### Failure Modes", "");
557
+ for (const mode of agent.failureModes) {
558
+ if (typeof mode === "string") {
559
+ lines.push(`- ${mode}`);
560
+ continue;
561
+ }
562
+ lines.push(`- ${mode.symptom}${mode.resolution ? ` — Recovery: ${mode.resolution}` : ""}`);
563
+ }
564
+ }
565
+ lines.push(PAGE_AGENT_CONTRACT_END_MARKER);
566
+ return lines.join("\n");
567
+ }
568
+ /** Remove generated contract blocks while preserving handwritten guidance. */
569
+ function stripGeneratedPageAgentContractMarkdown(markdown) {
570
+ const newline = markdown.includes("\r\n") ? "\r\n" : "\n";
571
+ const output = [];
572
+ let fence;
573
+ let pendingBlock;
574
+ let skipEmptySeparator = false;
575
+ for (const line of markdown.split(/\r?\n/)) {
576
+ if (pendingBlock) {
577
+ pendingBlock.push(line);
578
+ if (isGeneratedAgentContractMarker(line, PAGE_AGENT_CONTRACT_END_MARKER)) {
579
+ pendingBlock = void 0;
580
+ skipEmptySeparator = true;
581
+ }
582
+ continue;
583
+ }
584
+ if (!fence && isGeneratedAgentContractMarker(line, PAGE_AGENT_CONTRACT_START_MARKER)) {
585
+ pendingBlock = [line];
586
+ continue;
587
+ }
588
+ if (skipEmptySeparator && line.length === 0) continue;
589
+ skipEmptySeparator = false;
590
+ output.push(line);
591
+ fence = advanceMarkdownFence(line, fence);
592
+ }
593
+ if (pendingBlock) output.push(...pendingBlock);
594
+ while (output[0] === "") output.shift();
595
+ return output.join(newline);
596
+ }
597
+ function isGeneratedAgentContractMarker(line, marker) {
598
+ if (line.trim() !== marker) return false;
599
+ const markerIndex = line.indexOf(marker);
600
+ return markerIndex <= 3 && /^ *$/.test(line.slice(0, markerIndex));
601
+ }
602
+ function advanceMarkdownFence(line, fence) {
603
+ if (fence) {
604
+ const closing = /^ {0,3}(`+|~+)[\t ]*$/.exec(line)?.[1];
605
+ if (closing?.[0] === fence.character && closing.length >= fence.length) return;
606
+ return fence;
607
+ }
608
+ const opening = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
609
+ if (!opening?.[1]) return void 0;
610
+ if (opening[1][0] === "`" && opening[2]?.includes("`")) return void 0;
611
+ return {
612
+ character: opening[1][0],
613
+ length: opening[1].length
614
+ };
615
+ }
616
+ function isAgentContractHeadingText(value) {
617
+ return value.trim().toLowerCase() === "agent contract";
618
+ }
619
+ function hasPageAgentContractHeading(markdown) {
620
+ let fence;
621
+ let previousLine;
622
+ for (const line of markdown.split(/\r?\n/)) {
623
+ const nextFence = advanceMarkdownFence(line, fence);
624
+ if (fence || nextFence) {
625
+ fence = nextFence;
626
+ previousLine = void 0;
627
+ continue;
628
+ }
629
+ const atxText = /^ {0,3}#{1,6}(?:[\t ]+|$)(.*)$/.exec(line)?.[1]?.replace(/[\t ]+#+[\t ]*$/, "").trim();
630
+ if (atxText && isAgentContractHeadingText(atxText)) return true;
631
+ if (previousLine && /^ {0,3}(?:=+|-+)[\t ]*$/.test(line) && isAgentContractHeadingText(previousLine)) return true;
632
+ previousLine = line.trim().length > 0 && !/^ {4}/.test(line) && !/^ {0,3}\t/.test(line) ? line : void 0;
633
+ }
634
+ return false;
635
+ }
636
+ /** Insert one generated contract unless the document already has handwritten contract guidance. */
637
+ function upsertPageAgentContractMarkdown(markdown, value) {
638
+ const cleaned = stripGeneratedPageAgentContractMarkdown(markdown);
639
+ const contract = renderPageAgentContractMarkdown(value);
640
+ if (!contract || hasPageAgentContractHeading(cleaned)) return cleaned;
641
+ return cleaned ? `${contract}\n\n${cleaned.replace(/^\r?\n+/, "")}` : contract;
642
+ }
643
+
644
+ //#endregion
645
+ export { PAGE_AGENT_CONTRACT_END_MARKER, PAGE_AGENT_CONTRACT_FIELDS, PAGE_AGENT_CONTRACT_FIELD_SCHEMA, PAGE_AGENT_CONTRACT_START_MARKER, PAGE_AGENT_STRUCTURED_CONTRACT_FIELDS, getPageAgentFrontmatterIssues, hasStructuredPageAgentContract, normalizePageAgentFrontmatter, renderPageAgentContractMarkdown, renderPageAgentFrontmatterYamlLines, stripGeneratedPageAgentContractMarkdown, upsertPageAgentContractMarkdown };
@@ -0,0 +1,6 @@
1
+ //#region src/agent-detection.d.ts
2
+ declare const DOCS_AI_AGENT_USER_AGENT_HEADER_PATTERN: string;
3
+ declare const DOCS_TRADITIONAL_BOT_USER_AGENT_HEADER_PATTERN: string;
4
+ declare const DOCS_BOT_LIKE_USER_AGENT_HEADER_PATTERN: string;
5
+ //#endregion
6
+ export { DOCS_AI_AGENT_USER_AGENT_HEADER_PATTERN, DOCS_BOT_LIKE_USER_AGENT_HEADER_PATTERN, DOCS_TRADITIONAL_BOT_USER_AGENT_HEADER_PATTERN };