@capybara-hq/plugin-sdk 0.1.0-rc.8 → 0.1.0-rc.80

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 (149) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +11 -3
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +3 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extensions.md +77 -4
  14. package/agent-docs/plugin-format.md +45 -10
  15. package/agent-docs/setup.md +54 -0
  16. package/dist/agent-template.d.ts +15 -6
  17. package/dist/agent-template.js +32 -13
  18. package/dist/avatar-presets.d.ts +8 -0
  19. package/dist/avatar-presets.js +17 -0
  20. package/dist/bootstrap.d.ts +109 -1
  21. package/dist/bootstrap.js +185 -2
  22. package/dist/cards.d.ts +60 -13
  23. package/dist/cards.js +88 -18
  24. package/dist/channel.d.ts +128 -47
  25. package/dist/channel.js +10 -5
  26. package/dist/client-css.d.ts +36 -0
  27. package/dist/client-css.js +326 -0
  28. package/dist/client-section.d.ts +35 -0
  29. package/dist/client-section.js +133 -0
  30. package/dist/config-ui.d.ts +28 -6
  31. package/dist/config-ui.js +88 -25
  32. package/dist/config-url-fetch.d.ts +19 -0
  33. package/dist/config-url-fetch.js +43 -0
  34. package/dist/connector-auth.d.ts +13 -2
  35. package/dist/connector-auth.js +82 -8
  36. package/dist/connector.d.ts +74 -32
  37. package/dist/context.d.ts +40 -0
  38. package/dist/context.js +2 -0
  39. package/dist/ctx.d.ts +224 -30
  40. package/dist/ctx.js +9 -1
  41. package/dist/define-extension.d.ts +23 -13
  42. package/dist/define-extension.js +19 -5
  43. package/dist/device-denied-paths.d.ts +20 -0
  44. package/dist/device-denied-paths.js +118 -0
  45. package/dist/device-operation.d.ts +339 -0
  46. package/dist/device-operation.js +312 -0
  47. package/dist/device-protocol.d.ts +285 -50
  48. package/dist/device-protocol.js +755 -90
  49. package/dist/device-provider.d.ts +780 -0
  50. package/dist/device-provider.js +409 -0
  51. package/dist/device-service.d.ts +126 -0
  52. package/dist/device-service.js +211 -0
  53. package/dist/dial-in.d.ts +286 -0
  54. package/dist/dial-in.js +213 -0
  55. package/dist/directory.d.ts +15 -12
  56. package/dist/extension-point.d.ts +2 -0
  57. package/dist/extension-point.js +7 -3
  58. package/dist/field-meta.d.ts +19 -0
  59. package/dist/field-meta.js +54 -0
  60. package/dist/file-preview.d.ts +43 -10
  61. package/dist/git-hosts.d.ts +53 -0
  62. package/dist/git-hosts.js +98 -0
  63. package/dist/hooks.d.ts +125 -20
  64. package/dist/hooks.js +5 -0
  65. package/dist/http-access.d.ts +71 -0
  66. package/dist/http-access.js +12 -0
  67. package/dist/identity.d.ts +70 -9
  68. package/dist/identity.js +46 -1
  69. package/dist/index.d.ts +28 -4
  70. package/dist/index.js +28 -4
  71. package/dist/model-params.d.ts +41 -22
  72. package/dist/model-params.js +28 -15
  73. package/dist/model.d.ts +210 -75
  74. package/dist/model.js +152 -19
  75. package/dist/native-failure.d.ts +13 -0
  76. package/dist/native-failure.js +31 -0
  77. package/dist/net.d.ts +52 -0
  78. package/dist/net.js +34 -0
  79. package/dist/network-classes.d.ts +98 -0
  80. package/dist/network-classes.js +291 -0
  81. package/dist/permissions.d.ts +65 -22
  82. package/dist/permissions.js +139 -43
  83. package/dist/platform-only.d.ts +27 -0
  84. package/dist/platform-only.js +35 -0
  85. package/dist/plugin-manifest.d.ts +30 -6
  86. package/dist/plugin-manifest.js +147 -55
  87. package/dist/plugin-package.d.ts +82 -39
  88. package/dist/plugin-package.js +68 -41
  89. package/dist/push.d.ts +75 -0
  90. package/dist/push.js +87 -0
  91. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  92. package/dist/sandbox-linux-runtime-source.js +2343 -0
  93. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  94. package/dist/sandbox-native-runtime-source.js +480 -0
  95. package/dist/sandbox-runtime-source.d.ts +47 -0
  96. package/dist/sandbox-runtime-source.js +73 -0
  97. package/dist/sandbox-write-denies.d.ts +139 -0
  98. package/dist/sandbox-write-denies.js +869 -0
  99. package/dist/secret.d.ts +8 -2
  100. package/dist/secret.js +11 -4
  101. package/dist/setup-check.d.ts +128 -0
  102. package/dist/setup-check.js +142 -0
  103. package/dist/setup-guide-parse.d.ts +121 -0
  104. package/dist/setup-guide-parse.js +356 -0
  105. package/dist/setup-guide-render.d.ts +45 -0
  106. package/dist/setup-guide-render.js +351 -0
  107. package/dist/setup-guide.d.ts +86 -72
  108. package/dist/setup-guide.js +340 -108
  109. package/dist/shell-capabilities.d.ts +211 -0
  110. package/dist/shell-capabilities.js +44 -0
  111. package/dist/shell-environment.d.ts +57 -0
  112. package/dist/shell-environment.js +21 -0
  113. package/dist/skill-invocation.d.ts +5 -0
  114. package/dist/skill-invocation.js +4 -3
  115. package/dist/skill.d.ts +27 -17
  116. package/dist/skill.js +40 -26
  117. package/dist/storage.d.ts +52 -25
  118. package/dist/svg-viewbox.d.ts +10 -0
  119. package/dist/svg-viewbox.js +24 -0
  120. package/dist/theme-assets.d.ts +25 -9
  121. package/dist/theme-assets.js +87 -47
  122. package/dist/theme-tokens.generated.d.ts +26 -2
  123. package/dist/theme-tokens.generated.js +17 -0
  124. package/dist/theme.d.ts +48 -10
  125. package/dist/theme.js +100 -21
  126. package/dist/tool.d.ts +156 -30
  127. package/dist/tool.js +91 -9
  128. package/dist/ui-parts.d.ts +23 -0
  129. package/dist/ui-parts.js +385 -0
  130. package/dist/ui-resolve.d.ts +35 -0
  131. package/dist/ui-resolve.js +42 -0
  132. package/dist/ui-slots.d.ts +65 -0
  133. package/dist/ui-slots.js +261 -0
  134. package/dist/ui.d.ts +245 -77
  135. package/dist/ui.js +104 -27
  136. package/dist/url.d.ts +4 -1
  137. package/dist/url.js +4 -1
  138. package/dist/web.d.ts +26 -20
  139. package/package.json +12 -1
  140. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  141. package/schemas/bootstrap.v1.schema.json +20 -0
  142. package/schemas/connector-template.v1.schema.json +62 -4
  143. package/schemas/plugin.v1.schema.json +74 -143
  144. package/schemas/theme.v1.schema.json +77 -0
  145. package/agent-docs/extension-points/sandbox.md +0 -15
  146. package/dist/org-access.d.ts +0 -27
  147. package/dist/org-access.js +0 -35
  148. package/dist/sandbox.d.ts +0 -254
  149. package/dist/sandbox.js +0 -153
package/dist/secret.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  import type { z } from "zod";
2
2
  /**
3
3
  * Marks a schema as a secret field (Zod 4 meta `{ secret: true }`), merging with existing meta
4
- * (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
4
+ * (`ui` hints, `hot`, `platformOnly`), also the meta of the nodes under `.optional()` /
5
+ * `.default()` and the other wrappers, so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
5
6
  */
6
7
  export declare function secret<T extends z.ZodTypeAny>(schema: T): T;
7
- /** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
8
+ /**
9
+ * Whether a schema is sensitive: `secret: true` in its meta or in the meta of any node it wraps
10
+ * through `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()`
11
+ * (fail-safe: an outer meta never hides the mark). The kernel's `meta({secret:true})` is recognized
12
+ * the same way.
13
+ */
8
14
  export declare function isSecret(schema: z.ZodTypeAny): boolean;
package/dist/secret.js CHANGED
@@ -1,11 +1,18 @@
1
+ import { chainMeta, withMeta } from "./field-meta.js";
1
2
  /**
2
3
  * Marks a schema as a secret field (Zod 4 meta `{ secret: true }`), merging with existing meta
3
- * (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
4
+ * (`ui` hints, `hot`, `platformOnly`), also the meta of the nodes under `.optional()` /
5
+ * `.default()` and the other wrappers, so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
4
6
  */
5
7
  export function secret(schema) {
6
- return schema.meta({ ...(schema.meta() ?? {}), secret: true });
8
+ return withMeta(schema, "secret", true);
7
9
  }
8
- /** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
10
+ /**
11
+ * Whether a schema is sensitive: `secret: true` in its meta or in the meta of any node it wraps
12
+ * through `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()`
13
+ * (fail-safe: an outer meta never hides the mark). The kernel's `meta({secret:true})` is recognized
14
+ * the same way.
15
+ */
9
16
  export function isSecret(schema) {
10
- return schema.meta()?.secret === true;
17
+ return chainMeta(schema).secret === true;
11
18
  }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Setup checks (spec `2026-11-09-setup-guides-v2-design.md` §10): a check answers one question
3
+ * about one target ("does this bot token work?") for a `::check` line of a setup guide. An
4
+ * extension registers its checks in `setup` with `ctx.setup.check(id, def)`; each id must be
5
+ * listed in `permissions.setupChecks`. The kernel runs a check only when a person or an agent asks
6
+ * (never in the background), caches, single-flights and rate-limits it, and redacts the result.
7
+ *
8
+ * Contract rules (backed by review and kernel redaction, not by isolation: extensions are fully
9
+ * trusted):
10
+ * - A check never writes, at the third party or in Capybara, and stays cheap (one or two reads).
11
+ * - Pass `signal` to every request; the kernel aborts it at {@link SETUP_CHECK_LIMITS}.timeoutMs.
12
+ * - No retries inside the check: the person retries, retry policy is the kernel's.
13
+ * - Never put a secret, or any part of one, in `reason` or `fix`: the result is shown to people
14
+ * and to models (the `Platform` tool returns it). The kernel replaces known secret values with
15
+ * `[REDACTED]` before caching or returning, but only as exact matches of whole values of 8
16
+ * characters or more: a prefix, suffix, shorter secret or transformed copy is not redacted.
17
+ *
18
+ * What a check receives is what the extension already receives for the same target, nothing more:
19
+ * a channel connection's config (as `channel@1` `verify` and `connect` get it), a connector's
20
+ * ids and OAuth client id, or the extension's own platform deployment config (as its `ctx.config`,
21
+ * for the `extension-deployment` place, run only by a super admin). A check never gets the OAuth client secret or a member's token; those
22
+ * stay with the kernel and the connector extension's `auth()` (decided 2026-11-09).
23
+ */
24
+ import type { SetupGuidePlace } from "./setup-guide.js";
25
+ /**
26
+ * `ok`: verified now. `failing`: verified wrong (needs a reason; should have a fix). `unknown`:
27
+ * could not tell (third party down, rate limited, the check does not apply yet); never a failure
28
+ * the person must act on.
29
+ */
30
+ export type SetupCheckStatus = "ok" | "failing" | "unknown";
31
+ /** Plain text in English (required) and optionally Chinese; rendered as text, never Markdown. */
32
+ export interface SetupCheckText {
33
+ readonly en: string;
34
+ readonly zh?: string;
35
+ }
36
+ /**
37
+ * The answer of a check. There is deliberately no structured details field: a result has nowhere
38
+ * for a token to hide. {@link validateSetupCheckResult} refuses any other key.
39
+ */
40
+ export interface SetupCheckResult {
41
+ readonly status: SetupCheckStatus;
42
+ /** Why, in a sentence. At most `reasonChars` per language. Required when `failing`. */
43
+ readonly reason?: SetupCheckText;
44
+ /** What to do when failing. At most `fixChars` per language. */
45
+ readonly fix?: SetupCheckText;
46
+ }
47
+ /**
48
+ * What a check is about. The kernel builds it field by field; it only ever names targets of the
49
+ * check's own plugin (a channel connection on the plugin, a connector made from one of its
50
+ * templates, the plugin's own deployment).
51
+ */
52
+ export type SetupCheckTarget = {
53
+ readonly kind: "channel-connection";
54
+ readonly connectionId: string;
55
+ /** The connection config as `channel@1` `verify` and `connect` receive it, secrets included. */
56
+ readonly config: unknown;
57
+ } | {
58
+ readonly kind: "connector";
59
+ readonly connectorId: string;
60
+ readonly templateId: string;
61
+ /** The OAuth client id when the template uses a manual client; never the client secret. */
62
+ readonly clientId: string | null;
63
+ /** The viewing member's account, for member-audience checks; never their token. */
64
+ readonly accountId: string | null;
65
+ } | {
66
+ readonly kind: "extension-deployment";
67
+ /** The check's own plugin. */
68
+ readonly plugin: string;
69
+ /** The extension's platform deployment config as its `ctx.config` holds it, secrets included. */
70
+ readonly config: unknown;
71
+ };
72
+ /** What `run` receives. */
73
+ export interface SetupCheckArgs {
74
+ /** The org the check runs for; null for the `extension-deployment` place (the platform). */
75
+ readonly orgId: string | null;
76
+ /**
77
+ * The extension's effective config for the org (platform config plus the org's copy); for the
78
+ * `extension-deployment` place, its platform deployment config.
79
+ */
80
+ readonly config: unknown;
81
+ readonly locale: "en" | "zh";
82
+ /** The guide's mode (`long_connection`, `webhook`), or null when the place has none. */
83
+ readonly mode: string | null;
84
+ readonly target: SetupCheckTarget;
85
+ /** Aborted at the kernel's timeout or when the extension is disposed. Pass it to every request. */
86
+ readonly signal: AbortSignal;
87
+ }
88
+ /** A check registered with `ctx.setup.check`. */
89
+ export interface SetupCheckDefinition {
90
+ /** The place whose guides may use the check; the kernel runs it only for targets of that place. */
91
+ place: SetupGuidePlace;
92
+ /** Never writes, passes `signal` on, does not retry, never puts a secret in the result. */
93
+ run(args: SetupCheckArgs): Promise<SetupCheckResult>;
94
+ }
95
+ /**
96
+ * A check id an extension declares and registers. Ids with `:` belong to the kernel
97
+ * (`capybara:*`), so an extension cannot shadow a kernel check.
98
+ */
99
+ export declare const SETUP_CHECK_ID_RE: RegExp;
100
+ /** Limits of setup checks (spec §10.5). Characters are UTF-16 code units. */
101
+ export declare const SETUP_CHECK_LIMITS: Readonly<{
102
+ /** Per run; the kernel aborts `signal` and records `unknown`. */
103
+ readonly timeoutMs: 10000;
104
+ /** Characters of `reason`, per language. */
105
+ readonly reasonChars: 300;
106
+ /** Characters of `fix`, per language. */
107
+ readonly fixChars: 500;
108
+ /** A cached result stays fresh this long (and for the same input fingerprint). */
109
+ readonly freshMs: 300000;
110
+ /** A forced rerun of one check and target at most this often. */
111
+ readonly cooldownMs: 10000;
112
+ /** Concurrent runs per org across all replicas. */
113
+ readonly orgConcurrency: 8;
114
+ /** Run requests per account per minute. */
115
+ readonly perAccountPerMinute: 30;
116
+ /** Ids in `permissions.setupChecks`. */
117
+ readonly idsPerExtension: 32;
118
+ }>;
119
+ type Problem = {
120
+ problem: string;
121
+ };
122
+ /**
123
+ * The result as a fresh plain object holding only `status`, `reason` and `fix`, or why it is
124
+ * invalid (English). The kernel treats an invalid result as `unknown` and logs the problem. Run
125
+ * kernel redaction on the returned copy, then validate again (redaction can change the length).
126
+ */
127
+ export declare function validateSetupCheckResult(x: unknown): SetupCheckResult | Problem;
128
+ export {};
@@ -0,0 +1,142 @@
1
+ /**
2
+ * A check id an extension declares and registers. Ids with `:` belong to the kernel
3
+ * (`capybara:*`), so an extension cannot shadow a kernel check.
4
+ */
5
+ export const SETUP_CHECK_ID_RE = /^[a-z0-9][a-z0-9-]{0,47}$/;
6
+ /** Limits of setup checks (spec §10.5). Characters are UTF-16 code units. */
7
+ export const SETUP_CHECK_LIMITS = Object.freeze({
8
+ /** Per run; the kernel aborts `signal` and records `unknown`. */
9
+ timeoutMs: 10_000,
10
+ /** Characters of `reason`, per language. */
11
+ reasonChars: 300,
12
+ /** Characters of `fix`, per language. */
13
+ fixChars: 500,
14
+ /** A cached result stays fresh this long (and for the same input fingerprint). */
15
+ freshMs: 300_000,
16
+ /** A forced rerun of one check and target at most this often. */
17
+ cooldownMs: 10_000,
18
+ /** Concurrent runs per org across all replicas. */
19
+ orgConcurrency: 8,
20
+ /** Run requests per account per minute. */
21
+ perAccountPerMinute: 30,
22
+ /** Ids in `permissions.setupChecks`. */
23
+ idsPerExtension: 32,
24
+ });
25
+ const STATUSES = ["ok", "failing", "unknown"];
26
+ const RESULT_KEYS = new Set(["status", "reason", "fix"]);
27
+ const TEXT_KEYS = new Set(["en", "zh"]);
28
+ // C0 controls except tab, LF, CR; DEL; C1 controls.
29
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: matching control characters is the point
30
+ const CONTROL_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/;
31
+ // Bidi embeddings, overrides and isolates reorder what a reader sees (Trojan Source); the marks
32
+ // (LRM, RLM, ALM) stay allowed, real right-to-left names carry them.
33
+ const BIDI_RE = /[\u202a-\u202e\u2066-\u2069]/;
34
+ // Line and paragraph separators: invisible line breaks in plain text.
35
+ const SEPARATOR_RE = /[\u2028\u2029]/;
36
+ // A surrogate without its pair: not valid Unicode, and PostgreSQL jsonb refuses it.
37
+ const LONE_SURROGATE_RE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
38
+ // A key short and plain enough to name in a problem; others are not echoed, because the problem is
39
+ // logged and a truncated echo of a secret-valued key would slip past value redaction.
40
+ const ECHO_KEY_RE = /^[A-Za-z0-9_-]{1,32}$/;
41
+ /**
42
+ * Copies the own data properties of a plain object, or explains why it is not one. Accessors,
43
+ * symbol keys, non-enumerable keys and keys outside `allowed` are refused, so nothing runs while
44
+ * reading and nothing unlisted survives.
45
+ */
46
+ function plainCopy(label, x, allowed) {
47
+ if (typeof x !== "object" || x === null || Array.isArray(x)) {
48
+ return { problem: `${label} must be an object` };
49
+ }
50
+ const proto = Object.getPrototypeOf(x);
51
+ if (proto !== Object.prototype && proto !== null) {
52
+ return { problem: `${label} must be a plain object` };
53
+ }
54
+ const out = {};
55
+ for (const key of Reflect.ownKeys(x)) {
56
+ if (!allowed.has(key)) {
57
+ const shown = typeof key === "string" && ECHO_KEY_RE.test(key) ? `"${key}"` : "(not shown)";
58
+ return { problem: `${label} has an unknown key ${shown}` };
59
+ }
60
+ const d = Object.getOwnPropertyDescriptor(x, key);
61
+ if (!d || !("value" in d) || !d.enumerable) {
62
+ return { problem: `${label}.${String(key)} must be a plain data property` };
63
+ }
64
+ out[key] = d.value;
65
+ }
66
+ return out;
67
+ }
68
+ function text(label, x, max) {
69
+ const o = plainCopy(label, x, TEXT_KEYS);
70
+ if ("problem" in o)
71
+ return o;
72
+ const out = { en: "" };
73
+ for (const lang of ["en", "zh"]) {
74
+ const v = o[lang];
75
+ if (v === undefined && lang === "zh")
76
+ continue;
77
+ if (typeof v !== "string" || v === "") {
78
+ return { problem: `${label}.${lang} must be a non-empty string` };
79
+ }
80
+ if (v.length > max) {
81
+ return { problem: `${label}.${lang} is longer than ${max} characters` };
82
+ }
83
+ if (CONTROL_RE.test(v)) {
84
+ return { problem: `${label}.${lang} contains control characters` };
85
+ }
86
+ if (BIDI_RE.test(v)) {
87
+ return {
88
+ problem: `${label}.${lang} contains bidi embedding, override or isolate characters`,
89
+ };
90
+ }
91
+ if (SEPARATOR_RE.test(v)) {
92
+ return { problem: `${label}.${lang} contains line or paragraph separators` };
93
+ }
94
+ if (LONE_SURROGATE_RE.test(v)) {
95
+ return { problem: `${label}.${lang} is not well-formed UTF-16 (lone surrogate)` };
96
+ }
97
+ out[lang] = v;
98
+ }
99
+ return out;
100
+ }
101
+ /**
102
+ * The result as a fresh plain object holding only `status`, `reason` and `fix`, or why it is
103
+ * invalid (English). The kernel treats an invalid result as `unknown` and logs the problem. Run
104
+ * kernel redaction on the returned copy, then validate again (redaction can change the length).
105
+ */
106
+ export function validateSetupCheckResult(x) {
107
+ // A proxy (revoked, or with throwing traps) can throw while being read: that is an invalid
108
+ // result, never an exception the caller has to expect.
109
+ try {
110
+ return validateResult(x);
111
+ }
112
+ catch {
113
+ return { problem: "result could not be read (a proxy or an object that throws when read)" };
114
+ }
115
+ }
116
+ function validateResult(x) {
117
+ const o = plainCopy("result", x, RESULT_KEYS);
118
+ if ("problem" in o)
119
+ return o;
120
+ if (!STATUSES.includes(o.status)) {
121
+ return { problem: `result.status must be one of ${STATUSES.join(", ")}` };
122
+ }
123
+ const out = {
124
+ status: o.status,
125
+ };
126
+ if (o.reason !== undefined) {
127
+ const r = text("result.reason", o.reason, SETUP_CHECK_LIMITS.reasonChars);
128
+ if ("problem" in r)
129
+ return r;
130
+ out.reason = r;
131
+ }
132
+ if (o.fix !== undefined) {
133
+ const f = text("result.fix", o.fix, SETUP_CHECK_LIMITS.fixChars);
134
+ if ("problem" in f)
135
+ return f;
136
+ out.fix = f;
137
+ }
138
+ if (out.status === "failing" && !out.reason) {
139
+ return { problem: "result.reason is required when status is failing" };
140
+ }
141
+ return out;
142
+ }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * The line scanner and parser of setup guide documents (spec `2026-11-09-setup-guides-v2-design.md`
3
+ * §4.2). A guide is CommonMark + GFM with three line shapes the scanner recognizes in column 0
4
+ * outside fenced code: `::: mode <mode>` / `::: audience <audience>` (open a section), `:::` (close
5
+ * it) and `::check <check-id> <label>`. The scanner keeps line numbers: directive lines become blank
6
+ * lines and each check line becomes a level-6 heading holding a private-use marker, so it is a block
7
+ * of its own and can be found again after parsing.
8
+ */
9
+ import type { Nodes, Root } from "mdast";
10
+ /** `{{name}}`, spaces inside the braces allowed. */
11
+ export declare const SETUP_GUIDE_VARIABLE_RE: RegExp;
12
+ /** The private-use range the renderer reserves for its sentinels; refused in sources. */
13
+ export declare const SETUP_GUIDE_RESERVED_RE: RegExp;
14
+ /** Variable sentinel: `<n>`, n indexing the occurrences. */
15
+ export declare const SENTINEL_RE: RegExp;
16
+ /** The same sentinel percent-encoded, as micromark leaves it in a link destination. */
17
+ export declare const ENCODED_SENTINEL_RE: RegExp;
18
+ /** One issue of a document, with the 1-based source line when it has one. */
19
+ export interface SetupGuideParseIssue {
20
+ level: "error" | "warning";
21
+ line?: number;
22
+ message: string;
23
+ }
24
+ /** A `::: mode` / `::: audience` section of a document. */
25
+ export interface SetupGuideSection {
26
+ type: "mode" | "audience";
27
+ value: string;
28
+ /** Line of the opening directive. */
29
+ line: number;
30
+ /** Index of the enclosing section, or null. */
31
+ parent: number | null;
32
+ }
33
+ /** A `::check` line of a document. */
34
+ export interface SetupGuideCheckLine {
35
+ id: string;
36
+ label: string;
37
+ source: "plugin" | "kernel";
38
+ line: number;
39
+ /** Index of the innermost enclosing section, or null. */
40
+ section: number | null;
41
+ }
42
+ /** A fenced code block of a document. */
43
+ export interface SetupGuideCodeBlock {
44
+ /** The info string's first word; empty when missing. */
45
+ language: string;
46
+ title: string | null;
47
+ text: string;
48
+ line: number;
49
+ /** Index of the innermost enclosing section, or null. */
50
+ section: number | null;
51
+ }
52
+ /** The structure of a document (see {@link parseSetupGuide}). */
53
+ export interface ParsedSetupGuide {
54
+ /** The level-1 heading the document starts with, or null when it does not. */
55
+ title: string | null;
56
+ sections: SetupGuideSection[];
57
+ checks: SetupGuideCheckLine[];
58
+ codeBlocks: SetupGuideCodeBlock[];
59
+ /** Structural problems (place independent: modes, audiences and variables are not judged). */
60
+ issues: SetupGuideParseIssue[];
61
+ }
62
+ type LineKind = "text" | "fence" | "section-open" | "section-close" | "check";
63
+ /** @internal The scanner's result. */
64
+ export interface GuideScan {
65
+ lines: string[];
66
+ kinds: LineKind[];
67
+ /** The enclosing sections of each line, outermost first. */
68
+ stacks: number[][];
69
+ /** Check index of each check line. */
70
+ checkAt: Map<number, number>;
71
+ sections: SetupGuideSection[];
72
+ checks: SetupGuideCheckLine[];
73
+ issues: SetupGuideParseIssue[];
74
+ }
75
+ /** LF line endings. */
76
+ export declare function normalizeGuideSource(source: string): string;
77
+ /** @internal Classifies the lines of a (normalized) document. */
78
+ export declare function scanGuide(source: string): GuideScan;
79
+ /** @internal Whether line `i` is in the sections of `mode` and `audience`. */
80
+ export declare function lineSelected(scan: GuideScan, i: number, mode: string | null, audience: string | null): boolean;
81
+ /**
82
+ * @internal The Markdown the parser sees, line for line: unselected and directive lines blank, check
83
+ * lines as marker headings, other lines through `subst`.
84
+ */
85
+ export declare function preparedGuideText(scan: GuideScan, include: (i: number) => boolean, subst?: (text: string, i: number) => string): string;
86
+ /** @internal Parses Markdown (CommonMark + GFM) to mdast. */
87
+ export declare function parseGuideMarkdown(text: string): Root;
88
+ /** @internal The check index of a marker heading, or undefined. */
89
+ export declare function checkMarkerIndex(node: Nodes): number | undefined;
90
+ /** @internal The plain text of a node (values and image alts, joined). */
91
+ export declare function nodeText(node: Nodes): string;
92
+ /** @internal Visits nodes depth first in document order, with their depth (root's children = 1). */
93
+ export declare function visitGuide(node: Nodes, fn: (node: Nodes, depth: number, parent: Nodes | null) => void, depth?: number, parent?: Nodes | null): void;
94
+ /** @internal The title of a fence info string's meta: `{ title }`, or `{ bad }` for other text. */
95
+ export declare function fenceTitle(meta: string | null | undefined): {
96
+ title: string | null;
97
+ bad?: string;
98
+ };
99
+ /** @internal A variable occurrence the analysis replaced by a sentinel. */
100
+ export interface GuideVariableUse {
101
+ name: string;
102
+ line: number;
103
+ }
104
+ /** @internal Everything validation needs: the scan, the sentinel tree of all sections, the uses. */
105
+ export interface GuideAnalysis {
106
+ parsed: ParsedSetupGuide;
107
+ scan: GuideScan;
108
+ tree: Root;
109
+ uses: GuideVariableUse[];
110
+ }
111
+ /** @internal Replaces the sentinels (plain or percent-encoded) of `s` with `{{name}}`. */
112
+ export declare function revertSentinels(s: string, names: readonly string[]): string;
113
+ /** @internal Scans and parses a document with every section and every variable as a sentinel. */
114
+ export declare function analyzeSetupGuide(source: string): GuideAnalysis;
115
+ /**
116
+ * Parses a setup guide document into its title, sections, check lines and fenced code blocks, with
117
+ * the structural problems found (missing title, nesting, malformed directive lines, indented code,
118
+ * fence info strings, limits). Place-dependent rules are `validateSetupGuide`'s. Pure.
119
+ */
120
+ export declare function parseSetupGuide(source: string): ParsedSetupGuide;
121
+ export {};