@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.31

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 (127) hide show
  1. package/agent-docs/agent-templates.md +15 -3
  2. package/agent-docs/concepts.md +5 -0
  3. package/agent-docs/connector-templates.md +2 -1
  4. package/agent-docs/extension-points/channel.md +1 -1
  5. package/agent-docs/extension-points/config-source.md +1 -1
  6. package/agent-docs/extension-points/connector.md +1 -1
  7. package/agent-docs/extension-points/context.md +15 -0
  8. package/agent-docs/extension-points/counter.md +1 -1
  9. package/agent-docs/extension-points/directory.md +1 -1
  10. package/agent-docs/extension-points/file-preview.md +1 -1
  11. package/agent-docs/extension-points/identity-source.md +1 -1
  12. package/agent-docs/extension-points/model-provider.md +4 -2
  13. package/agent-docs/extension-points/object-store.md +3 -1
  14. package/agent-docs/extension-points/sandbox.md +3 -3
  15. package/agent-docs/extension-points/secret-store.md +1 -1
  16. package/agent-docs/extension-points/web-fetch.md +1 -1
  17. package/agent-docs/extension-points/web-search.md +1 -1
  18. package/agent-docs/extensions.md +29 -4
  19. package/agent-docs/plugin-format.md +43 -3
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +1 -1
  22. package/agent-docs/tool-naming.md +1 -1
  23. package/dist/agent-template.d.ts +15 -6
  24. package/dist/agent-template.js +32 -13
  25. package/dist/bootstrap.d.ts +15 -1
  26. package/dist/bootstrap.js +17 -1
  27. package/dist/cards.d.ts +56 -13
  28. package/dist/cards.js +90 -20
  29. package/dist/channel.d.ts +111 -48
  30. package/dist/channel.js +10 -5
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +22 -0
  36. package/dist/config-ui.js +64 -4
  37. package/dist/connector-auth.d.ts +7 -2
  38. package/dist/connector-auth.js +29 -8
  39. package/dist/connector.d.ts +74 -32
  40. package/dist/context.d.ts +40 -0
  41. package/dist/context.js +2 -0
  42. package/dist/ctx.d.ts +135 -26
  43. package/dist/define-extension.d.ts +26 -12
  44. package/dist/define-extension.js +11 -4
  45. package/dist/device-protocol-v3.d.ts +117 -0
  46. package/dist/device-protocol-v3.js +409 -0
  47. package/dist/device-protocol.d.ts +330 -0
  48. package/dist/device-protocol.js +567 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +5 -2
  51. package/dist/file-preview.d.ts +1 -1
  52. package/dist/git-hosts.d.ts +44 -0
  53. package/dist/git-hosts.js +81 -0
  54. package/dist/hooks.d.ts +111 -21
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +52 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +22 -9
  59. package/dist/index.d.ts +23 -1
  60. package/dist/index.js +24 -1
  61. package/dist/marketplace.d.ts +26 -0
  62. package/dist/marketplace.js +43 -1
  63. package/dist/model-params.d.ts +41 -22
  64. package/dist/model-params.js +28 -15
  65. package/dist/model.d.ts +180 -71
  66. package/dist/model.js +71 -19
  67. package/dist/net.d.ts +52 -0
  68. package/dist/net.js +34 -0
  69. package/dist/permissions.d.ts +42 -20
  70. package/dist/permissions.js +97 -40
  71. package/dist/plugin-manifest.d.ts +45 -5
  72. package/dist/plugin-manifest.js +169 -6
  73. package/dist/plugin-package.d.ts +82 -38
  74. package/dist/plugin-package.js +61 -29
  75. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  76. package/dist/sandbox-linux-runtime-source.js +1886 -0
  77. package/dist/sandbox-native-runtime-source.d.ts +8 -0
  78. package/dist/sandbox-native-runtime-source.js +325 -0
  79. package/dist/sandbox-operation.d.ts +248 -0
  80. package/dist/sandbox-operation.js +245 -0
  81. package/dist/sandbox-runtime-source.d.ts +19 -0
  82. package/dist/sandbox-runtime-source.js +28 -0
  83. package/dist/sandbox-write-denies.d.ts +60 -0
  84. package/dist/sandbox-write-denies.js +630 -0
  85. package/dist/sandbox.d.ts +201 -16
  86. package/dist/sandbox.js +89 -14
  87. package/dist/secret.d.ts +4 -1
  88. package/dist/secret.js +4 -1
  89. package/dist/setup-check.d.ts +115 -0
  90. package/dist/setup-check.js +142 -0
  91. package/dist/setup-guide-parse.d.ts +121 -0
  92. package/dist/setup-guide-parse.js +350 -0
  93. package/dist/setup-guide-render.d.ts +45 -0
  94. package/dist/setup-guide-render.js +351 -0
  95. package/dist/setup-guide.d.ts +94 -0
  96. package/dist/setup-guide.js +336 -0
  97. package/dist/skill-invocation.d.ts +4 -3
  98. package/dist/skill-invocation.js +5 -4
  99. package/dist/skill.d.ts +34 -21
  100. package/dist/skill.js +48 -31
  101. package/dist/storage.d.ts +52 -25
  102. package/dist/theme-assets.d.ts +39 -0
  103. package/dist/theme-assets.js +449 -0
  104. package/dist/theme-readability.d.ts +37 -0
  105. package/dist/theme-readability.js +145 -0
  106. package/dist/theme-tokens.generated.d.ts +279 -0
  107. package/dist/theme-tokens.generated.js +174 -0
  108. package/dist/theme.d.ts +152 -0
  109. package/dist/theme.js +392 -0
  110. package/dist/tool.d.ts +69 -26
  111. package/dist/tool.js +29 -9
  112. package/dist/ui-parts.d.ts +23 -0
  113. package/dist/ui-parts.js +337 -0
  114. package/dist/ui-resolve.d.ts +35 -0
  115. package/dist/ui-resolve.js +42 -0
  116. package/dist/ui-slots.d.ts +53 -0
  117. package/dist/ui-slots.js +238 -0
  118. package/dist/ui.d.ts +191 -79
  119. package/dist/ui.js +101 -27
  120. package/dist/url.d.ts +4 -1
  121. package/dist/url.js +4 -1
  122. package/package.json +7 -1
  123. package/schemas/bootstrap.v1.schema.json +6 -0
  124. package/schemas/connector-template.v1.schema.json +35 -0
  125. package/schemas/marketplace.v1.schema.json +14 -0
  126. package/schemas/plugin.v1.schema.json +115 -3
  127. package/schemas/theme.v1.schema.json +225 -0
package/dist/ctx.d.ts CHANGED
@@ -1,24 +1,31 @@
1
1
  import type { Kysely } from "kysely";
2
2
  import type { ExtensionPointRef } from "./extension-point.js";
3
3
  import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
4
+ import type { RouteCaller } from "./http-access.js";
5
+ import type { ModelEmbeddingInfo, ModelKind } from "./model.js";
6
+ import type { ExtensionNet } from "./net.js";
7
+ import type { SetupCheckDefinition } from "./setup-check.js";
4
8
  import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
5
9
  import type { ToolHandler, ToolSpec } from "./tool.js";
6
10
  import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
7
- /** 日志接口。 */
11
+ /** Logger interface. */
8
12
  export interface Logger {
9
13
  info(msg: string, fields?: Record<string, unknown>): void;
10
14
  warn(msg: string, fields?: Record<string, unknown>): void;
11
15
  error(msg: string, fields?: Record<string, unknown>): void;
12
16
  }
13
- /** 分布式锁租约。 */
17
+ /** Distributed lock lease. */
14
18
  export interface Lease {
15
19
  renew(): Promise<boolean>;
16
20
  release(): Promise<void>;
17
21
  }
18
22
  /**
19
- * 插件的对象存储(`ctx.storage`,需 `permissions.storage`):与 `ObjectStore` 同形,但每个方法的第一个参数是
20
- * `orgId`,键与前缀由内核自动加上 `plugins/<插件名>/<orgId>/`——插件只能看到自己在该组织下的对象。
21
- * 底层是部署配置的 `object-store@1` 提供方;没有提供方时各方法抛错。
23
+ * The plugin's object storage (`ctx.storage`, needs `permissions.storage`): the same shape as
24
+ * `ObjectStore`, but the first parameter of every method is
25
+ * `orgId`, and the kernel adds `plugins/<plugin name>/<orgId>/` to keys and prefixes automatically:
26
+ * a plugin sees only its own objects under that org.
27
+ * The backing store is the deployment-configured `object-store@1` provider; every method throws
28
+ * when there is no provider.
22
29
  */
23
30
  export interface ExtensionStorage {
24
31
  put(orgId: string, key: string, body: Uint8Array | ReadableStream<Uint8Array>, opts: {
@@ -27,8 +34,10 @@ export interface ExtensionStorage {
27
34
  signal?: AbortSignal;
28
35
  }): Promise<ObjectHead>;
29
36
  /**
30
- * 不存在返回 null。`range` 为闭区间字节范围,缺省 `end` 表示读到末尾。
31
- * 带 `range` 时 `head.size` 仍是整个对象的大小;存储忽略 Range 时 body 可能是整个对象。
37
+ * Returns null when missing. `range` is a closed byte range; an omitted `end` means read to the
38
+ * end.
39
+ * With `range`, `head.size` is still the size of the whole object; when the store ignores Range,
40
+ * body may be the whole object.
32
41
  */
33
42
  get(orgId: string, key: string, opts?: {
34
43
  signal?: AbortSignal;
@@ -41,7 +50,7 @@ export interface ExtensionStorage {
41
50
  body: ReadableStream<Uint8Array>;
42
51
  } | null>;
43
52
  head(orgId: string, key: string): Promise<ObjectHead | null>;
44
- /** 不存在也算成功。 */
53
+ /** A missing key also counts as success. */
45
54
  delete(orgId: string, key: string): Promise<void>;
46
55
  deletePrefix(orgId: string, prefix: string): Promise<number>;
47
56
  list(orgId: string, prefix: string, opts?: {
@@ -58,7 +67,69 @@ export interface ExtensionStorage {
58
67
  ttlSeconds: number;
59
68
  }): Promise<PresignedUpload>;
60
69
  }
61
- /** 传给插件 `setup` 的上下文。不提供定时器与进程内共享状态;kv 写入必须带 TTL。 */
70
+ /** A `ctx.models.embed` request: texts embedded for one org with the model mapped to a purpose. */
71
+ export interface ExtensionEmbedRequest {
72
+ orgId: string;
73
+ /** A purpose this extension declared in `permissions.models` with `kind: "embedding"`. */
74
+ purpose: string;
75
+ /** The texts, one vector each; split into batches by the model's `maxBatch` by the kernel. */
76
+ input: string[];
77
+ /** One of the model's `embedding.dimensions`; the model's default when absent. */
78
+ dimensions?: number;
79
+ inputType?: "query" | "document";
80
+ /**
81
+ * Aborts this call (e.g. the tool call's `signal`); combined with `ctx.signal`. Batches not yet
82
+ * sent are not sent; batches already answered are still recorded as usage.
83
+ */
84
+ signal?: AbortSignal;
85
+ }
86
+ /** A `ctx.models.embed` result. */
87
+ export interface ExtensionEmbedResult {
88
+ /** One vector per input, in input order. */
89
+ vectors: number[][];
90
+ /** The model that made them (a changed model invalidates stored vectors). */
91
+ model: {
92
+ provider: string;
93
+ id: string;
94
+ };
95
+ dimensions: number;
96
+ }
97
+ /** The model a purpose maps to in an org (`ctx.models.describe`). */
98
+ export interface ExtensionModelTarget {
99
+ provider: string;
100
+ id: string;
101
+ kind: ModelKind;
102
+ /** Present for an embedding model. */
103
+ embedding?: ModelEmbeddingInfo;
104
+ }
105
+ /**
106
+ * Models by purpose (`permissions.models`): the purpose → model mapping is chosen by org admins
107
+ * (and the deployment default by the super admin), never by the extension. Only purposes this
108
+ * extension declared with `kind: "embedding"` are accepted (`model.purpose_unknown` otherwise), and
109
+ * only for an org that enabled the extension (`extension.not_enabled`). Usage is recorded by the
110
+ * kernel and reported through `usage.report` (purpose `embedding`).
111
+ */
112
+ export interface ExtensionModels {
113
+ /**
114
+ * Embeds `input` with the org's effective model for `purpose`. Rejects with `model.unconfigured`
115
+ * when the purpose maps to no model the org can use, `validation_failed` for dimensions the model
116
+ * lacks, and a `ModelError` when the provider fails (a result of the wrong count or dimension is a
117
+ * `ModelError` of kind `server`). Not retried by the kernel. Each call fires the `model.request`
118
+ * hook first (`purpose: "embedding"`, every text of the call): when a policy hook denies it, the
119
+ * call rejects with an error whose `code` is `model.hook_denied` (HTTP 403 if it escapes an
120
+ * extension route), and nothing is sent or billed.
121
+ */
122
+ embed(req: ExtensionEmbedRequest): Promise<ExtensionEmbedResult>;
123
+ /** The org's effective model for `purpose`, or null when it maps to no model the org can use. */
124
+ describe(req: {
125
+ orgId: string;
126
+ purpose: string;
127
+ }): Promise<ExtensionModelTarget | null>;
128
+ }
129
+ /**
130
+ * The context passed to a plugin's `setup`. It provides no timers or in-process shared state; kv
131
+ * writes must carry a TTL.
132
+ */
62
133
  export interface ExtensionContext {
63
134
  kv: {
64
135
  get(key: string): Promise<string | null>;
@@ -92,16 +163,27 @@ export interface ExtensionContext {
92
163
  get(orgId: string, key: string): Promise<string | null>;
93
164
  set(orgId: string, key: string, value: string): Promise<void>;
94
165
  };
95
- /** 对象存储(需 `permissions.storage`,见 {@link ExtensionStorage})。 */
166
+ /** Object storage (needs `permissions.storage`, see {@link ExtensionStorage}). */
96
167
  storage: ExtensionStorage;
97
- /** 已切到本插件 schema(withSchema)的 Kysely 实例。 */
168
+ /** Models by purpose (requires `permissions.models`, see {@link ExtensionModels}). */
169
+ models: ExtensionModels;
170
+ /**
171
+ * Guarded HTTP for URLs a person supplied (see {@link ExtensionNet}): a connector endpoint or an
172
+ * org-overridable base URL goes through `ctx.net.fetch`, never the global `fetch`.
173
+ */
174
+ net: ExtensionNet;
175
+ /** A Kysely instance already switched to this plugin's schema (withSchema). */
98
176
  db: Kysely<any>;
99
177
  http: {
100
- /** 实际挂载到 `/plugins/<name><path>`。 */
101
- route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request) => Promise<Response>): void;
178
+ /**
179
+ * Mounted at `/plugins/<name><path>` (`public`, `embed`) or `/plugins/<name>/orgs/:orgId<path>`
180
+ * (`member`, `admin`), as `permissions.http` declares. The kernel enforces the access before
181
+ * the handler runs and passes the resolved caller; trust only `caller`.
182
+ */
183
+ route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request, caller: RouteCaller) => Promise<Response>): void;
102
184
  };
103
185
  tools: {
104
- /** 注册一个工具;只能在 `setup` 期间调用,名称不可重复。 */
186
+ /** Registers a tool; callable only during `setup`, names must not repeat. */
105
187
  register(spec: ToolSpec, handler: ToolHandler): void;
106
188
  };
107
189
  /**
@@ -133,23 +215,45 @@ export interface ExtensionContext {
133
215
  }[]>;
134
216
  };
135
217
  /**
136
- * 界面贡献的运行时(清单 `ui` + `permissions.ui`):
137
- * - `view` / `action`:只能在 `setup` 期间注册,id 是清单里 kind view 的贡献 id;
138
- * `action` 收到视图里按钮或表单提交(`args.actionId` 区分是哪一个);
139
- * - `invalidate`:告诉内核「这个贡献变了」,打开着它的网页会重新取视图(经 bus,跨副本);
140
- * - `verifyEmbedToken`:校验 embed 页面拿到的嵌入令牌,只认签给本插件、未过期的,且此刻插件仍在该组织启用、
141
- * 调用者仍是 active 成员(组织页面还要求 member 以上),否则返回 null;返回的 `role` 是此刻的角色。
218
+ * Runtime of UI contributions (manifest `ui` + `permissions.ui`):
219
+ * - `view` / `action`: can be registered only during `setup`; the id is the contribution id of
220
+ * the kind-view entry in the manifest;
221
+ * `action` receives a button click or form submission from the view (`args.actionId` tells
222
+ * which one);
223
+ * - `invalidate`: tells the kernel "this contribution changed", and the web pages that have it
224
+ * open fetch the view again (via the bus, across replicas); a
225
+ * `platform.page` contribution takes no `orgId` (it refreshes the admin console), every other
226
+ * contribution requires one;
227
+ * - `verifyEmbedToken`: validates the embed token an embed page received; it accepts only
228
+ * tokens signed for this plugin and not expired, while the plugin is still enabled in that org,
229
+ * the caller is still an active member and the role still satisfies the slot's minRole,
230
+ * otherwise it returns null; the returned `role` is the role at this moment. A
231
+ * platform-scope token (`scope: "platform"`, no `orgId`) verifies only for a `platform.page`
232
+ * contribution while the account is still an active super admin.
142
233
  */
143
234
  ui: {
144
235
  view(id: string, render: (args: UiRenderArgs) => Promise<UiView>): void;
145
236
  action(id: string, handler: (args: UiActionArgs) => Promise<UiActionResult>): void;
146
237
  invalidate(target: {
147
- orgId: string;
238
+ /** Required, except for a `platform.page` contribution, where it must be omitted. */
239
+ orgId?: string;
148
240
  conversationId?: string;
149
241
  contribution: string;
150
242
  }): Promise<void>;
151
243
  verifyEmbedToken(token: string): Promise<EmbedClaims | null>;
152
244
  };
245
+ /**
246
+ * Setup checks (`permissions.setupChecks`): the live rows of the plugin's setup guides.
247
+ * `check` is only allowed during `setup`; `id` must be listed in `permissions.setupChecks`
248
+ * (else `ExtensionPermissionError`); registering an id twice throws. The kernel runs a check only
249
+ * when a person or an agent asks, only for targets of this plugin and of `def.place`, aborts
250
+ * `signal` after `SETUP_CHECK_LIMITS.timeoutMs`, and redacts and bounds the result. A check never
251
+ * writes, passes `signal` to every request, does not retry and never puts a secret in `reason`
252
+ * or `fix`. It never receives an OAuth client secret or a member's token.
253
+ */
254
+ setup: {
255
+ check(id: string, def: SetupCheckDefinition): void;
256
+ };
153
257
  /**
154
258
  * Hooks (`permissions.hooks`): observe model and tool calls, or deny them with a policy hook.
155
259
  * `on` is only allowed during `setup`; the mount point must be declared in `permissions.hooks` and be
@@ -164,14 +268,19 @@ export interface ExtensionContext {
164
268
  };
165
269
  provide(extensionPoint: ExtensionPointRef, impl: unknown): void;
166
270
  /**
167
- * 本插件实例的生命周期信号:实例被撤销(停用、卸载、升级)时、在途调用排空之后中止。
168
- * 插件自己起的长任务(轮询循环、长连接等)据此收尾。
271
+ * The lifecycle signal of this plugin instance: aborted when the instance is revoked (disabled,
272
+ * uninstalled, upgraded), after in-flight calls have drained.
273
+ * Long-running tasks the plugin started itself (polling loops, long connections, etc.) wind down
274
+ * on it.
169
275
  */
170
276
  signal: AbortSignal;
171
277
  /**
172
- * 部署级配置,已按插件 schema 校验(启动配置与企业管理员在后台保存的值合并后)。这是一个 getter:
173
- * 标了 `hot`(`.meta({ hot: true })`)的字段改动时内核就地替换,插件**在用时读** `ctx.config` 才能拿到新值,
174
- * 不要在 setup 里把 hot 字段拷进闭包;改了非 hot 字段时内核重新加载插件实例(新的 setup)。
278
+ * Deployment-level config, validated against the plugin schema (the startup config merged with
279
+ * values the super admin saved in the console). This is a getter:
280
+ * when a field marked `hot` (`.meta({ hot: true })`) changes, the kernel replaces it in place, so
281
+ * the plugin must read `ctx.config` **at the time of use** to get the new value;
282
+ * do not copy hot fields into a closure in setup; when a non-hot field changes the kernel reloads
283
+ * the plugin instance (a new setup).
175
284
  */
176
285
  readonly config: unknown;
177
286
  log: Logger;
@@ -3,18 +3,25 @@ import type { ExtensionContext } from "./ctx.js";
3
3
  import { type ExtensionPointRef } from "./extension-point.js";
4
4
  import { type ExtensionPermissions } from "./permissions.js";
5
5
  import type { UiContribution } from "./ui.js";
6
- /** 插件清单。 */
6
+ /** The plugin manifest. */
7
7
  export interface ExtensionManifest {
8
8
  name: string;
9
9
  version: string;
10
10
  sdk: string;
11
11
  provides: ExtensionPointRef[];
12
12
  requires?: ExtensionPointRef[];
13
- /** 可选依赖:缺失时插件照常加载,运行时经 ctx.extensionPoints 判断。 */
13
+ /**
14
+ * Optional dependencies: when missing the plugin still loads, and decides at runtime through
15
+ * ctx.extensionPoints.
16
+ */
14
17
  optional?: ExtensionPointRef[];
15
- /** 权限清单(治理而非沙箱)。 */
18
+ /** Permission manifest (governance, not a sandbox). */
16
19
  permissions?: ExtensionPermissions;
17
- /** 界面贡献:对话页标签与组织页面;id 须同时列在 `permissions.ui` 里。 */
20
+ /**
21
+ * UI contributions, each in a slot of `UI_SLOTS`; every id is also listed in `permissions.ui`.
22
+ * Kept exactly as written: structural problems fail the extension, while a contribution to an
23
+ * unknown slot or version is only dropped when the host resolves the slots (`resolveUiSlots`).
24
+ */
18
25
  ui?: UiContribution[];
19
26
  config?: {
20
27
  deployment?: z.ZodTypeAny;
@@ -23,19 +30,26 @@ export interface ExtensionManifest {
23
30
  migrations?: string;
24
31
  setup(ctx: ExtensionContext): void | Promise<void>;
25
32
  /**
26
- * 可选:插件实例被撤销(停用、卸载、升级换新实例、依赖方随提供方重新加载)时调用。
27
- * 调用时内核已经:停止接新的调用、等在途调用结束(最多 `extensionHost.drainSeconds`)、中止 `ctx.signal`、
28
- * 撤销本实例经 ctx 做过的全部登记(工具、路由、队列 worker、bus 订阅、锁租约、界面、provide)。
29
- * 这里只收拾插件自己在 ctx 之外开的东西(如自建的连接);不要再经 ctx 登记任何东西。
30
- * setup 抛错时不调用(已登记的由内核撤销)。
33
+ * Optional: called when the plugin instance is revoked (disabled, uninstalled, replaced by a new
34
+ * instance on upgrade, a dependent reloaded together with its provider).
35
+ * By then the kernel has already: stopped accepting new calls, waited for in-flight calls to
36
+ * finish (at most `extensionHost.drainSeconds`), aborted `ctx.signal`,
37
+ * and revoked every registration this instance made through ctx (tools, routes, queue workers,
38
+ * bus subscriptions, lock leases, UI, provide).
39
+ * Clean up here only what the plugin opened outside ctx (e.g. its own connections); do not
40
+ * register anything through ctx again.
41
+ * Not called when setup throws (the kernel revokes what was already registered).
31
42
  */
32
43
  dispose?(ctx: ExtensionContext): void | Promise<void>;
33
44
  }
34
- /** 插件清单不合法。 */
45
+ /** The plugin manifest is invalid. */
35
46
  export declare class ExtensionManifestError extends Error {
36
47
  constructor(plugin: string, message: string);
37
48
  }
38
- /** 插件名规则(清单 `name`;连接器模板的 `plugin` 也按它校验)。 */
49
+ /** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
39
50
  export declare const EXTENSION_NAME_RE: RegExp;
40
- /** 校验并原样返回插件清单;不合法抛 ExtensionManifestError。 */
51
+ /**
52
+ * Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
53
+ * invalid.
54
+ */
41
55
  export declare function defineExtension(m: ExtensionManifest): ExtensionManifest;
@@ -1,17 +1,20 @@
1
1
  import semver from "semver";
2
2
  import { EXTENSION_POINTS, parseExtensionPoint, } from "./extension-point.js";
3
3
  import { validatePermissions, validateUiContributions, } from "./permissions.js";
4
- /** 插件清单不合法。 */
4
+ /** The plugin manifest is invalid. */
5
5
  export class ExtensionManifestError extends Error {
6
6
  constructor(plugin, message) {
7
7
  super(`extension ${plugin}: ${message}`);
8
8
  this.name = "ExtensionManifestError";
9
9
  }
10
10
  }
11
- /** 插件名规则(清单 `name`;连接器模板的 `plugin` 也按它校验)。 */
11
+ /** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
12
12
  export const EXTENSION_NAME_RE = /^[a-z][a-z0-9-]{1,40}$/;
13
13
  const NAME_RE = EXTENSION_NAME_RE;
14
- /** 保留的插件名:内核用 `kernel` 作为自己的 secrets 命名空间,插件不能与之相同。 */
14
+ /**
15
+ * Reserved plugin name: the kernel uses `kernel` as its own secrets namespace, so a plugin cannot
16
+ * take it.
17
+ */
15
18
  const RESERVED_NAMES = new Set(["kernel"]);
16
19
  function checkRefs(label, refs, fail, forbidBrokered = false) {
17
20
  for (const ref of refs) {
@@ -30,7 +33,10 @@ function checkRefs(label, refs, fail, forbidBrokered = false) {
30
33
  }
31
34
  }
32
35
  }
33
- /** 校验并原样返回插件清单;不合法抛 ExtensionManifestError。 */
36
+ /**
37
+ * Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
38
+ * invalid.
39
+ */
34
40
  export function defineExtension(m) {
35
41
  const plugin = typeof m?.name === "string" && m.name !== "" ? m.name : "<unnamed>";
36
42
  const fail = (msg) => {
@@ -78,6 +84,7 @@ export function defineExtension(m) {
78
84
  if (errs.length > 0)
79
85
  fail(`invalid permissions: ${errs.join("; ")}`);
80
86
  }
87
+ // structural ui problems only; slot resolution never fails the extension (UI slots spec §3.2)
81
88
  const uiErrs = validateUiContributions(m.ui, m.permissions);
82
89
  if (uiErrs.length > 0)
83
90
  fail(`invalid ui: ${uiErrs.join("; ")}`);
@@ -0,0 +1,117 @@
1
+ /** Development staging only. Task 8 replaces v2 and removes this module and its staged names together. */
2
+ import { type DeviceHello, type DeviceLocalPolicySummary, type DeviceOp, type DevicePolicyArgs, type DevicePolicyStatus, type DeviceRes, type KernelCancel } from "./device-protocol.js";
3
+ import { type SandboxPermissionSupport } from "./sandbox-operation.js";
4
+ export declare const STAGED_DEVICE_PROTOCOL_VERSION = 3;
5
+ export type DeviceOperationV3 = Exclude<DeviceOp, "killTagged" | "killAll"> | "prepareReadFile" | "prepareWriteFile" | "prepareStat" | "browseStat" | "browseList" | "browseScan" | "backgroundStart" | "backgroundStatus" | "backgroundTail" | "backgroundReadOutput" | "backgroundStop" | "revokeOperation" | "bindInstance";
6
+ export interface DeviceOwnerCeilingV3 {
7
+ readonly version: 2;
8
+ readonly sequence: number;
9
+ readonly restrictedProjectReach: "workspace" | "os-user";
10
+ readonly revision: string;
11
+ readonly fullAccess: boolean;
12
+ readonly restrictedAllowedDomains: readonly string[];
13
+ }
14
+ /**
15
+ * The only owner-ceiling change the kernel may ask of a machine (B2): narrowing. Widening is decided
16
+ * on the machine by its owner (`capybara-device ceiling set`), never over the wire.
17
+ */
18
+ export interface DeviceOwnerCeilingNarrowingV3 {
19
+ readonly fullAccess?: false;
20
+ readonly restrictedProjectReach?: "workspace";
21
+ }
22
+ /** A staged `policy` op: the protocol 2 change plus an optional owner-ceiling narrowing. */
23
+ export interface DevicePolicyArgsV3 extends DevicePolicyArgs {
24
+ ownerCeiling?: DeviceOwnerCeilingNarrowingV3;
25
+ }
26
+ /** A staged `policy` answer: the policy as written and the owner report issued for it. */
27
+ export interface DevicePolicyResultV3 {
28
+ policy: DeviceLocalPolicySummary;
29
+ ownerCeiling: DeviceOwnerCeilingV3;
30
+ }
31
+ /** A staged `policyStatus` answer: an `applied` outcome carries the current owner report. */
32
+ export interface DevicePolicyStatusV3 extends DevicePolicyStatus {
33
+ ownerCeiling?: DeviceOwnerCeilingV3;
34
+ }
35
+ /** The device pushed a policy change: the owner report for the newly observed revision. */
36
+ export interface DevicePolicyChangedV3 {
37
+ type: "policy";
38
+ policy?: DeviceLocalPolicySummary;
39
+ ownerCeiling: DeviceOwnerCeilingV3;
40
+ }
41
+ export interface DeviceHelloV3 extends DeviceHello {
42
+ protocol: 3;
43
+ permissionSupport: SandboxPermissionSupport;
44
+ ownerCeiling: DeviceOwnerCeilingV3;
45
+ instanceGeneration: string | null;
46
+ transport: {
47
+ maxFrameBytes: number;
48
+ };
49
+ /** Absent until the program can attest actual installed runtime/helper/environment bytes. */
50
+ runtimeIdentity?: DeviceRuntimeIdentityV3;
51
+ }
52
+ /** A verified installed runtime/helper/environment identity bound to one instance generation. */
53
+ export interface DeviceRuntimeIdentityV3 {
54
+ runtimeHash: string;
55
+ helperHash: string;
56
+ imageFingerprint: string;
57
+ instanceGeneration: string;
58
+ }
59
+ /**
60
+ * Private lifecycle request (permission runtime cutover B4): binds the kernel's committed instance
61
+ * generation to the device after commit. It carries no path, policy or manifest.
62
+ */
63
+ export interface BindInstanceRequestV3 {
64
+ instanceId: string;
65
+ instanceGeneration: string;
66
+ bindingId: string;
67
+ expectedPreviousGeneration: string | null;
68
+ }
69
+ export interface BindInstanceResultV3 {
70
+ instanceId: string;
71
+ instanceGeneration: string;
72
+ bindingId: string;
73
+ runtimeIdentity: DeviceRuntimeIdentityV3;
74
+ permissionSupport: SandboxPermissionSupport;
75
+ ownerCeiling: DeviceOwnerCeilingV3;
76
+ }
77
+ export interface KernelReadyV3 {
78
+ type: "ready";
79
+ connectionId: string;
80
+ maxFrameBytes: number;
81
+ }
82
+ export interface BackgroundReadOutputRequestV3 {
83
+ offset: number;
84
+ maxBytes: number;
85
+ }
86
+ export type BackgroundReadOutputResultV3 = {
87
+ dataB64: string;
88
+ offset: number;
89
+ nextOffset: number;
90
+ totalBytes: number;
91
+ } | {
92
+ unavailable: "lost" | "expired";
93
+ };
94
+ export interface KernelRequestV3 {
95
+ type: "req";
96
+ id: string;
97
+ op: DeviceOperationV3;
98
+ args: Readonly<Record<string, unknown>>;
99
+ deadlineMs: number;
100
+ }
101
+ export type DeviceResponseV3 = Exclude<DeviceRes, {
102
+ ok: false;
103
+ }> | {
104
+ type: "res";
105
+ id: string;
106
+ ok: false;
107
+ error: {
108
+ kind: "gone" | "fs_gone" | "policy" | "error" | "denied" | "unsupported" | "unknown";
109
+ message: string;
110
+ };
111
+ };
112
+ export type DeviceFrameV3 = DeviceHelloV3 | KernelReadyV3 | KernelRequestV3 | KernelCancel | DeviceResponseV3 | DevicePolicyChangedV3;
113
+ /** Strictly parses one authenticated owner-ceiling report (B2); throws {@link DeviceProtocolError}. */
114
+ export declare function parseOwnerCeilingReportV3(value: unknown): DeviceOwnerCeilingV3;
115
+ /** Strict scope-bearing frames; active parseDeviceFrame still speaks v2. */
116
+ export declare function parseDeviceFrameV3(raw: string, from: "device" | "kernel", maxFrameBytes?: number): DeviceFrameV3;
117
+ export declare function parseOperationResultV3(op: DeviceOperationV3, result: unknown, request?: BackgroundReadOutputRequestV3 | BindInstanceRequestV3): unknown;