@ycodium-ai/plugin-api 0.2.4343 → 0.2.4351

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,11 +9,12 @@ own state across restarts.
9
9
  ## Install
10
10
 
11
11
  ```
12
- npm install --save-dev @ycodium-ai/plugin-api
12
+ npm install --save-dev @ycodium-ai/plugin-api esbuild
13
13
  ```
14
14
 
15
15
  Types are erased at build time. Runtime exports such as `definePlugin` come from the
16
- Ycodium host's shared copy; keep this package external when bundling your plugin.
16
+ Ycodium host's shared copy; keep this package external when bundling your plugin, except
17
+ `@ycodium-ai/plugin-api/version`, which must be inlined.
17
18
 
18
19
  The CSS subpath `@ycodium-ai/plugin-api/ui.css` is the public Tailwind preset for
19
20
  plugin pages: control-axis utilities, semantic colors, status animations, and
@@ -58,10 +59,11 @@ And export the definition:
58
59
 
59
60
  ```ts
60
61
  import { definePlugin } from "@ycodium-ai/plugin-api";
62
+ import { PLUGIN_API_VERSION } from "@ycodium-ai/plugin-api/version";
61
63
 
62
64
  export default definePlugin({
63
65
  id: "my-plugin",
64
- apiVersion: 109,
66
+ apiVersion: PLUGIN_API_VERSION,
65
67
  activate: (ctx) => {
66
68
  ctx.log.info("hello");
67
69
 
@@ -90,15 +92,38 @@ ycodium plugin add my-ycodium-plugin
90
92
  ## Bundle your entry file
91
93
 
92
94
  Bundle your own code and private dependencies into an ESM entry. Keep
93
- `@ycodium-ai/plugin-api` and its subpaths external. For esbuild:
95
+ `@ycodium-ai/plugin-api` and its subpaths external, except `@ycodium-ai/plugin-api/version`.
96
+ That one subpath must be bundled so the published file carries the API version of the package
97
+ you built against. Esbuild's `--external:<package>` also matches subpaths, so the CLI cannot exempt
98
+ `/version`; use `onResolve` in `build.mjs` instead:
94
99
 
95
100
  ```js
96
- external: ["@ycodium-ai/plugin-api", "@ycodium-ai/plugin-api/*"];
101
+ import { build } from "esbuild";
102
+
103
+ const versionModule = "@ycodium-ai/plugin-api/version";
104
+ await build({
105
+ entryPoints: ["src/index.ts"],
106
+ outfile: "dist/index.js",
107
+ bundle: true,
108
+ format: "esm",
109
+ platform: "node",
110
+ plugins: [
111
+ {
112
+ name: "ycodium-host-api",
113
+ setup(build) {
114
+ build.onResolve({ filter: /^@ycodium-ai\/plugin-api(?:\/.*)?$/ }, (args) =>
115
+ args.path === versionModule ? undefined : { path: args.path, external: true },
116
+ );
117
+ },
118
+ },
119
+ ],
120
+ });
97
121
  ```
98
122
 
99
- The host resolves these imports to its shared API module, including for bundled official
123
+ The host resolves the other imports to its shared API module, including for bundled official
100
124
  plugins, npm installations, local directories, and temporary plugins. Plugins do not need
101
125
  to copy the API into their package or depend on a particular installation directory.
126
+ The host refuses to resolve `@ycodium-ai/plugin-api/version` at runtime.
102
127
 
103
128
  Browser bundles use the same rule. Map runtime API imports to the host's module table,
104
129
  `window.__ycodiumPluginHost.modules`, as you map React to the host's React instance.
@@ -248,13 +273,14 @@ is refused with `reason: "undeclared"`.
248
273
  | `communication.read` | Read the messages exchanged in projects, including their text |
249
274
  | `memory.read` | Read and search project memory, including earlier versions |
250
275
 
251
- The wording the user sees for each is in `packages/shared/src/pluginPermissionLabel.ts`; the schema is
252
- `packages/contracts/src/pluginPermissions.ts`.
276
+ The installation review explains each permission before the user accepts it. Declare only the
277
+ capabilities your plugin uses; the public TypeScript declarations define each request's shape.
253
278
 
254
279
  ## Shaping the model's turn
255
280
 
256
- Four permissions let a plugin act on the agent's turn rather than beside it. Types are in
257
- `@ycodium-ai/plugin-api` (`capabilityPorts.ts`); `plugins/pentest` uses all four.
281
+ Four permissions let a plugin act on the agent's turn rather than beside it. Their types are
282
+ exported from `@ycodium-ai/plugin-api`; the user documentation's prompt and guard guide walks
283
+ through all four.
258
284
 
259
285
  - **`ctx.systemPrompt.section({ id, text, whenPresetId? })`** and **`ctx.systemPrompt.context(fn)`**
260
286
  (`systemPrompt`). The host composes every plugin's sections and per-turn contexts into one block
@@ -391,24 +417,84 @@ try {
391
417
  }
392
418
  ```
393
419
 
420
+ ## Reporting a failure
421
+
422
+ Report each failure once. A turn that fails ends with a failed `turn.completed`; its `errorMessage`
423
+ is what the user reads. Emit `runtime.error` for a failure that is not part of a turn. Its payload is
424
+ `ExecutorRuntimeErrorPayload`, typed on `ExecutorEventOf<"runtime.error">`:
425
+
426
+ ```ts
427
+ import type { ExecutorEventOf } from "@ycodium-ai/plugin-api/executor";
428
+ import { lastStderrLines, redactStderrExcerpt } from "@ycodium-ai/plugin-api/process-stdin";
429
+
430
+ const event: ExecutorEventOf<"runtime.error"> = {
431
+ eventId,
432
+ provider: "myAgent",
433
+ threadId,
434
+ createdAt: new Date().toISOString(),
435
+ type: "runtime.error",
436
+ payload: {
437
+ // Required: one English sentence for the user, the reason first.
438
+ message: `My agent could not load its config.\n${lastStderrLines(redactStderrExcerpt(stderrTail), 800)}`,
439
+ // Optional: only when you know which kind of failure it is.
440
+ failureCategory: "auth",
441
+ // Optional: kept for logs and diagnostics, never shown.
442
+ detail: { configPath },
443
+ },
444
+ };
445
+ ```
446
+
447
+ - `message` is the session's failure text, the timeline's error row, and the `detail` of
448
+ `thread.failed`. The timeline row keeps the first 180 characters, so put the reason first. Pass any
449
+ child-process output through `redactStderrExcerpt` first; `lastStderrLines` keeps its last lines
450
+ within a length: whole lines when they fit, and a single over-long line is cut without splitting a
451
+ surrogate pair or a redaction marker.
452
+ - `failureCategory` chooses the explanation and next step the user sees. Leave it off when you are
453
+ not sure; never derive it from message text. `process-exit` means your agent process exited after
454
+ the session was established; `transport` means the network path to the provider broke. Only
455
+ `transport` tells the user to check network and proxy settings.
456
+ - `thread.failed` fires once per failure: after it fires, the host fires it again only once the
457
+ session has left the failed state, a new turn was requested, or a queued message started being
458
+ sent. If you emit `runtime.error` and
459
+ also fail the turn, the session keeps the later message while `thread.failed` carries the first.
460
+
461
+ Plugins built on `ycodium-acp-executor` get this for agent exits: pass the spawn handle's `exited`
462
+ and `stderrTail` to `createAcpExecutor`, and a mid-turn exit fails the turn with `process-exit`, the
463
+ exit code and the end of the agent's stderr. Do not add your own `runtime.error` for it.
464
+
394
465
  ## THERE WILL BE COMPATIBILITY-BREAKING CHANGES
395
466
 
396
467
  The definition's `apiVersion` is checked against a closed window: the host loads every version from
397
- its minimum through its current one, and refuses every other value. Declare the version your plugin
398
- targets as a literal; do not read the host's `PLUGIN_API_VERSION` to make the declaration
399
- automatically match. Declare the oldest version that has everything your plugin uses: a newer
400
- declaration narrows which Ycodium can load it. The examples here declare the window minimum. Ycodium's own plugins have the literal written by their build instead: they
401
- import `PLUGIN_API_VERSION` from `@ycodium-ai/plugin-api/version` and bundle that one subpath, so the
402
- published file still carries the version it was built for. If you do the same, that subpath must be
403
- bundled, never left external. Plugins targeting an API older than the window are refused before
404
- activation; the message names the version the plugin declared and the versions this Ycodium loads,
405
- and the plugin card offers an update. A plugin that declares a version newer than the window is
406
- refused until Ycodium itself is updated, with no update button. There is no compatibility layer:
407
- update against the new types and republish.
468
+ its minimum through its current one, and refuses every other value. A published plugin declares the
469
+ version it was built against as a literal in its bundle; it must not read the host's constant at
470
+ runtime and automatically match every host. Import `PLUGIN_API_VERSION` from
471
+ `@ycodium-ai/plugin-api/version` and bundle that one subpath. This declares the current version of
472
+ the interface package you installed, not an inferred minimum. To support an older host, install its
473
+ interface package, check the APIs you use, and rebuild. A newer declaration narrows which Ycodium
474
+ can load the plugin.
475
+
476
+ Unbundled local directories and selfdev single-file definitions instead declare the oldest API
477
+ version they need as a literal. Do not read the host's constant: after a breaking upgrade, that could
478
+ let old code pass as if it were new. The examples declare the window minimum, maintained by the
479
+ version generator. In a selfdev session, `ycodium_inspect` section `api`, topic `shape`, names the
480
+ window this host accepts. Install and load errors also name the declared version and the accepted
481
+ range.
482
+
483
+ Plugins targeting an API older than the window are refused before activation; the message names the
484
+ version the plugin declared and the versions this Ycodium loads, and the plugin card offers an
485
+ update. A plugin that declares a version newer than the window is refused until Ycodium itself is
486
+ updated, with no update button. There is no compatibility layer: update against the new types and
487
+ republish.
408
488
 
409
489
  <!-- plugin-api-versions:start (generated by scripts/gen-plugin-api-version.ts from packages/plugin-api/version-history.json; edit that file) -->
410
490
 
411
- The current API is **109**. This Ycodium loads only plugins declaring 109.
491
+ The current API is **110**. This Ycodium loads only plugins declaring 110.
492
+
493
+ API 110 adds the `process-exit` failure category (the agent process exited after the session was established; `transport` now means only the network channel to the provider) and types the `runtime.error` payload as `ExecutorRuntimeErrorPayload`: one user-facing sentence in `message`, optional `failureCategory`, `detail` and `class`. Adds `lastStderrLines(redacted, maxChars)` to `@ycodium-ai/plugin-api/process-stdin` for putting the end of a redacted stderr excerpt into such a message: it starts at a whole line when one fits, and a single over-long line is cut without splitting a surrogate pair or a redaction marker.
494
+
495
+ API 110 fires `thread.failed` once per failure: when an executor both emits `runtime.error` and fails the turn, the session is set to error twice but plugins get one `thread.failed`, carrying the first report's words. It fires again once a new attempt starts: the session left the error state, a new turn was requested, or a queued message started sending.
496
+
497
+ API 110 adds the optional accepted plugin API version range to machineSettings.config.get.
412
498
 
413
499
  API 109 gives general system notifications an optional `sourceThreadId`. Parsed notifications form a discriminated union: child kinds guarantee `childThreadId`, while general kinds can omit it. Plugins can narrow by kind before opening a child thread.
414
500
 
@@ -570,6 +570,10 @@ type Objects_83 = {
570
570
  readonly "otlpLogsUrl": string;
571
571
  readonly "fullTraceUntil"?: number;
572
572
  };
573
+ type PluginApiVersionRange = {
574
+ readonly "min": number;
575
+ readonly "max": number;
576
+ };
573
577
  type Arrays_15 = ReadonlyArray<"desktop-bootstrap" | "one-time-token">;
574
578
  type Arrays_16 = ReadonlyArray<"browser-session-cookie" | "bearer-access-token" | "dpop-access-token">;
575
579
  type Arrays_17 = ReadonlyArray<{
@@ -1278,7 +1282,7 @@ type Objects_30 = {
1278
1282
  readonly "nativeModeId"?: string | undefined;
1279
1283
  readonly "activeTurnId": string | null;
1280
1284
  readonly "lastError": string | null;
1281
- readonly "failureCategory"?: "quota" | "rate-limit" | "context-limit" | "auth" | "model-unavailable" | "transport" | "unknown" | undefined;
1285
+ readonly "failureCategory"?: "quota" | "rate-limit" | "context-limit" | "auth" | "model-unavailable" | "transport" | "unknown" | "process-exit" | undefined;
1282
1286
  readonly "retry"?: Union_14;
1283
1287
  readonly "endReason"?: "server-restart" | undefined;
1284
1288
  readonly "updatedAt": string;
@@ -2283,7 +2287,7 @@ type Objects_16 = {
2283
2287
  readonly "interactionMode": "default" | "plan";
2284
2288
  readonly "modelSelection": Objects_18;
2285
2289
  readonly "sessionStatus": "idle" | "starting" | "running" | "ready" | "interrupted" | "stopped" | "error" | null;
2286
- readonly "sessionFailureCategory"?: "quota" | "rate-limit" | "context-limit" | "auth" | "model-unavailable" | "transport" | "unknown";
2290
+ readonly "sessionFailureCategory"?: "quota" | "rate-limit" | "context-limit" | "auth" | "model-unavailable" | "transport" | "unknown" | "process-exit";
2287
2291
  readonly "latestTurnState": "running" | "interrupted" | "completed" | "error" | null;
2288
2292
  readonly "status": "needs-approval" | "needs-input" | "plan-ready" | "running" | "failed" | "background" | "stopped" | "idle";
2289
2293
  readonly "worktreePath"?: string | null;
@@ -3715,7 +3719,7 @@ export type ThreadsExecutionGetOutput = {
3715
3719
  readonly "lastError": string | null;
3716
3720
  readonly "updatedAt": string;
3717
3721
  readonly "endReason"?: "server-restart";
3718
- readonly "failureCategory"?: "quota" | "rate-limit" | "context-limit" | "auth" | "model-unavailable" | "transport" | "unknown";
3722
+ readonly "failureCategory"?: "quota" | "rate-limit" | "context-limit" | "auth" | "model-unavailable" | "transport" | "unknown" | "process-exit";
3719
3723
  readonly "status": string;
3720
3724
  readonly "providerInstanceId": string | null;
3721
3725
  } | null;
@@ -4556,6 +4560,7 @@ export type MachineSettingsGetInput = {};
4556
4560
  export type MachineSettingsGetOutput = Objects_73;
4557
4561
  export type MachineSettingsConfigGetInput = {};
4558
4562
  export type MachineSettingsConfigGetOutput = {
4563
+ readonly "pluginApiVersionRange"?: PluginApiVersionRange;
4559
4564
  readonly "environment": {
4560
4565
  readonly "environmentId": string;
4561
4566
  readonly "label": string;
@@ -8266,6 +8271,7 @@ export type MachineSettingsGetEncodedOutput = {
8266
8271
  readonly "observability": Objects_83;
8267
8272
  };
8268
8273
  export type MachineSettingsConfigGetEncodedOutput = {
8274
+ readonly "pluginApiVersionRange"?: PluginApiVersionRange;
8269
8275
  readonly "environment": {
8270
8276
  readonly "environmentId": string;
8271
8277
  readonly "label": string;