@standardagents/code-plugin-sdk 1.0.0-alpha.2 → 1.0.0-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standardagents/code-plugin-sdk",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
4
4
  "type": "module",
5
5
  "description": "Standard Code plugin authoring SDK",
6
6
  "license": "MIT",
package/src/index.d.ts CHANGED
@@ -92,6 +92,14 @@ export interface CanvasSpec {
92
92
  captureInput?: boolean;
93
93
  }
94
94
  export type CanvasContent = { kind: 'canvas'; canvas: CanvasSpec };
95
+ /**
96
+ * What an `onInput` handler for a canvas receives. Keys arrive while the canvas
97
+ * declares `captureInput` and holds focus; focus loss arrives when the host
98
+ * stops showing it.
99
+ */
100
+ export type CanvasInputEvent =
101
+ | { kind: 'key'; key: string; phase: 'press' | 'repeat'; contributionId: string; entity?: EntityRef }
102
+ | { kind: 'focus'; focused: false; contributionId: string; entity?: EntityRef };
95
103
 
96
104
  /** Semantic tones. The host maps each tone to the viewer's theme. */
97
105
  export type Tone = 'ok' | 'info' | 'warn' | 'error' | 'muted' | 'accent' | 'pending' | 'bright';
@@ -207,6 +215,40 @@ export interface PluginEvent {
207
215
  data: Json;
208
216
  deliveryId?: string;
209
217
  }
218
+ /** The native release this machine runs. */
219
+ export type BuildInfo = {
220
+ version: string;
221
+ /** The 40-character lowercase commit SHA. */
222
+ commit: string;
223
+ /** The Git ref of the build's source, such as `refs/heads/main`, or null when it is not known. */
224
+ ref: string | null;
225
+ channel: 'branch' | 'canary' | 'production' | 'team' | null;
226
+ };
227
+ /** The account-wide build policy every machine in the fleet follows. */
228
+ export type FleetPolicy = {
229
+ mode: 'follow' | 'pin' | 'production' | null;
230
+ npmTag: string | null;
231
+ /** The Git ref of the followed channel, or null when it is not known. */
232
+ ref: string | null;
233
+ /** The pinned or target version, or null when it is not known. */
234
+ version: string | null;
235
+ };
236
+ /** The `context.get` result. `build` and `fleet` are null when unknown. */
237
+ export type PluginContextInfo = {
238
+ accountId: string;
239
+ machineId: string;
240
+ build?: BuildInfo | null;
241
+ fleet?: FleetPolicy | null;
242
+ };
243
+ /** The `data` of a `build-context` event. */
244
+ export type BuildContextEventData = {
245
+ build: BuildInfo | null;
246
+ fleet: FleetPolicy | null;
247
+ };
248
+ export interface BuildContextEvent extends PluginEvent {
249
+ name: 'build-context';
250
+ data: BuildContextEventData;
251
+ }
210
252
  export interface Popover {
211
253
  kind: 'chooser' | 'form' | 'confirm';
212
254
  title: string;
@@ -231,7 +273,7 @@ export interface OperationMap {
231
273
  'config.get': { input: Record<string, never>; output: Record<string, Json> };
232
274
  'state.get': { input: { key: string }; output: Json };
233
275
  'state.set': { input: { key: string; value: Json }; output: null };
234
- 'context.get': { input: Record<string, never>; output: Json };
276
+ 'context.get': { input: Record<string, never>; output: PluginContextInfo };
235
277
  'popover.open': { input: Popover; output: { choiceId?: string; values?: Record<string, Json>; confirmationId?: string } | null };
236
278
  'canvas.write': { input: { key: ContributionKey; ansi: string }; output: null };
237
279
  'canvas.focus': { input: { key: ContributionKey; capture: boolean }; output: null };
@@ -287,9 +329,11 @@ export interface PluginContext {
287
329
  key(id: string, handler: ActionHandler): KeyRegistration;
288
330
  link(id: string, options: LinkOptions, handler: LinkHandler): Subscription;
289
331
  link(id: string, handler: LinkHandler): Subscription;
332
+ onEvent(name: 'build-context', handler: (event: BuildContextEvent, context: HandlerContext) => void | Promise<void>, condition?: Condition): Subscription;
290
333
  onEvent(name: string, handler: (event: PluginEvent, context: HandlerContext) => void | Promise<void>, condition?: Condition): Subscription;
291
334
  onHook(name: string, handler: (event: HookEvent, context: HandlerContext) => HookResult | Promise<HookResult>): Subscription;
292
335
  onAction(name: string, handler: (event: Selection, context: HandlerContext) => Json | void | Promise<Json | void>): Subscription;
336
+ /** For a canvas, `name` is its contribution ID and events are `CanvasInputEvent` values. */
293
337
  onInput(name: string, handler: (event: Json, context: HandlerContext) => void | Promise<void>): Subscription;
294
338
  onSelect(name: string, handler: (event: Selection, context: HandlerContext) => void | Promise<void>): Subscription;
295
339
  onResize(name: string, handler: (event: { columns: number; rows: number }, context: HandlerContext) => void | Promise<void>): Subscription;
@@ -313,7 +357,7 @@ export interface PluginContext {
313
357
  config: { get(options?: RequestOptions): Promise<Record<string, Json>> };
314
358
  /** Local state for one machine. It is never shared with other machines. */
315
359
  state: { get(key: string, options?: RequestOptions): Promise<Json>; set(key: string, value: Json, options?: RequestOptions): Promise<null> };
316
- context: { get(options?: RequestOptions): Promise<Json> };
360
+ context: { get(options?: RequestOptions): Promise<PluginContextInfo> };
317
361
  popover: { open(args: Popover, options?: RequestOptions): Promise<OperationMap['popover.open']['output']> };
318
362
  health: { set(args: OperationMap['health.set']['input'], options?: RequestOptions): Promise<null> };
319
363
  webhook: { ack(deliveryId: string, options?: RequestOptions): Promise<null> };
package/src/testing.mjs CHANGED
@@ -41,7 +41,7 @@ export function createHarness({ manifest: input, machineId = 'test-machine', epo
41
41
  ensure(localState.has(args.key) || localState.size < LIMITS.contributions, 'queue_full', 'Harness state is full')
42
42
  localState.set(args.key, structuredClone(args.value)); return null
43
43
  case 'config.get': return {}
44
- case 'context.get': return { machineId }
44
+ case 'context.get': return { accountId: 'test-account', machineId, build: null, fleet: null }
45
45
  case 'health.set': return null
46
46
  default: throw new PluginError('missing_fixture', `Provide a harness handler for ${operation.op}`)
47
47
  }