@linkdesk/contracts 0.1.57 → 0.1.58

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/ai-bridge.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * AI bridge(CLI/MCP)命令结果契约——S6/T11 的单一来源。
3
+ *
4
+ * A 的 `electron/services/aiBridge/{whitelist,opRegistry}.ts` 与 C 的客户端类型都从这里取;
5
+ * ⛔ 在 CLI/MCP/SDK 另存一份形状(第二份真相)。
6
+ *
7
+ * 形状按 A 的 T11 规格(交接.md):
8
+ * - 异步命令 exec 回执 = `AiBridgeExecPending`(⛔ 同步命令不带 pending);
9
+ * - `opStatus` 回执 = `AiBridgeOpStatus`(state 封闭枚举;过期抛 EOPEXPIRED)。
10
+ */
11
+ export interface AiBridgeExecPending {
12
+ commandId: string;
13
+ pending: true;
14
+ opId: string;
15
+ startedAt: string;
16
+ }
17
+
18
+ /** 同步命令回执的可选相位字段(异步命令整体走 AiBridgeExecPending) */
19
+ export interface AiBridgeCommandResult {
20
+ pending?: boolean;
21
+ opId?: string;
22
+ [key: string]: unknown;
23
+ }
24
+
25
+ export type AiBridgeOpState = "running" | "done" | "failed" | "expired";
26
+
27
+ export interface AiBridgeOpError {
28
+ code: string;
29
+ message: string;
30
+ hint?: string;
31
+ }
32
+
33
+ export interface AiBridgeOpStatus {
34
+ state: AiBridgeOpState;
35
+ /** state=done 时的命令结果 */
36
+ result?: unknown;
37
+ /** state=failed 时的统一错误信封 */
38
+ error?: AiBridgeOpError;
39
+ startedAt: string;
40
+ elapsedMs: number;
41
+ }
package/index.cjs ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * 壳保留错误码——**唯一来源**(C 的 `check-error-envelope` 经 `createRequire` 同步读)。
4
+ *
5
+ * 9 个码由 A 确认(壳侧产生/透传,插件不得自造变体);值改动只在这里改,
6
+ * ⛔ 在 SDK / CLI / 插件收一份字面量表(那是第二份真相)。
7
+ *
8
+ * CJS(`.cjs`):SDK 的 `runPluginLint` 是同步 API,用 `createRequire` 读本文件;
9
+ * 包 `type:module` + `main:"./index.cjs"` 让 `require("@linkdesk/contracts")` 命中这里。
10
+ */
11
+ const SHELL_ERROR_CODES = Object.freeze([
12
+ "EVIEWREQUIRED",
13
+ "ENOTACTIVE",
14
+ "EUNKNOWNCOMMAND",
15
+ "EOPEXPIRED",
16
+ "EPOLICYDENIED",
17
+ "EPROTECTED",
18
+ "EUSERDENIED",
19
+ "ESHELLTIMEOUT",
20
+ "EUNKNOWN",
21
+ ]);
22
+
23
+ module.exports = { SHELL_ERROR_CODES };
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 壳保留错误码(运行时入口 `index.cjs` 的类型面)。
3
+ * 唯一来源;⛔ 在 SDK / CLI / 插件另存字面量表。
4
+ */
5
+ export declare const SHELL_ERROR_CODES: readonly [
6
+ "EVIEWREQUIRED",
7
+ "ENOTACTIVE",
8
+ "EUNKNOWNCOMMAND",
9
+ "EOPEXPIRED",
10
+ "EPOLICYDENIED",
11
+ "EPROTECTED",
12
+ "EUSERDENIED",
13
+ "ESHELLTIMEOUT",
14
+ "EUNKNOWN",
15
+ ];
package/linkdesk.d.ts CHANGED
@@ -98,6 +98,21 @@ export interface LinkDeskCommandParam {
98
98
  /** One-sentence description of what this parameter is (omitted = the name is self-explanatory) */
99
99
  description?: string;
100
100
  }
101
+ /**
102
+ * S3b/T12: return-shape field table entry — **first-level keys** (optionally one nested level via description),
103
+ * ⛔ not a full JSON Schema. Lets the AI compose assertions without trial and error; `doctor` samples real
104
+ * receipts to catch drift. Mirrors manifest `contributes.commands[].returns[]`.
105
+ */
106
+ export interface LinkDeskCommandReturnField {
107
+ /** Field name in the receipt */
108
+ name: string;
109
+ /** Field type — e.g. string / number / boolean / object / array */
110
+ type: string;
111
+ /** Whether the field may be absent (defaults to false) */
112
+ optional?: boolean;
113
+ /** One sentence on what this field means */
114
+ description?: string;
115
+ }
101
116
  export interface LinkDeskCommand {
102
117
  id: string;
103
118
  title: string;
@@ -117,9 +132,23 @@ export interface LinkDeskCommand {
117
132
  userOnly?: boolean;
118
133
  /**
119
134
  * Declared risk level (2026-11-24 · AI permission tiers) — mirrors `contributes.commands[].risk`.
120
- * Merge order: host built-in table > this declaration > fallback R1. Purely additive.
135
+ * S7 merge: host built-in table covers **shell commands only**; a plugin command's risk is its
136
+ * declaration; undeclared ⇒ conservative R2 fallback (never silently allowed). Purely additive.
121
137
  */
122
138
  risk?: "R0" | "R1" | "R2" | "R3";
139
+ /**
140
+ * S4 reachability — runtime truth from the registration context (pool registration), or the manifest
141
+ * declaration while the command is not yet registered. "entry" = plugin-level (callable with no view open,
142
+ * lazily activated on command miss); "view" = registered by a mounted view instance (needs that view).
143
+ * Additive — describe() surfaces it so the AI can plan without trial and error.
144
+ */
145
+ activation?: "entry" | "view";
146
+ /** S6: async command — exec answers `{pending:true, opId}` and the result is read via `opStatus`. Additive. */
147
+ async?: boolean;
148
+ /** S3b/T12: return-shape field table (manifest `contributes.commands[].returns`) — first-level keys. Additive. */
149
+ returns?: LinkDeskCommandReturnField[];
150
+ /** S3b/T12: request-body example (manifest `contributes.commands[].example`) — request side only. Additive. */
151
+ example?: Record<string, unknown>;
123
152
  }
124
153
  /** Recipe contribution domains—shared by theme metadata domains (mix-and-match source filtering) and the theme:changed payload (domain-level fine-grained refresh) (06 §2/§6.2).
125
154
  * Five domains: colors (colorways always contribute) + the four appearance style domains (radius/glass/font/background).
@@ -254,6 +283,9 @@ export interface CommandsAPI {
254
283
  pluginId?: string;
255
284
  description?: string;
256
285
  params?: LinkDeskCommandParam[];
286
+ /** S6/T11: declare this command as async — exec answers `{pending:true, opId}` and the result is read via `opStatus`.
287
+ * Same semantics as `LinkDeskCommand.async`; describe surfaces it. Additive. */
288
+ async?: boolean;
257
289
  }): void;
258
290
  /** Unregister a plugin's pool-resident commands (convention: command ID format "pluginId.commandName") — called on view unmount */
259
291
  unregisterCommands(pluginId: string): void;
@@ -264,6 +296,11 @@ export interface CommandsAPI {
264
296
  /** pool-preload-only internal hook — the pool renderer registers the on-command activation callback (command miss → import the owning plugin entry).
265
297
  * Underscore internal surface (modeled after _executeShellLocal), not a plugin-author API — the wiring point for on-demand activation of pure command plugins. */
266
298
  _setCommandMissHandler?(handler: (pluginId: string) => Promise<boolean>): void;
299
+ /** S4: pool-preload-only internal hooks — PluginComponent mount/unmount pushes/pops the activation context stack,
300
+ * so registerCommand records activation:"view" + scope:"view:<id>" for view-mounted commands (entry-level registrations stay activation:"entry").
301
+ * Underscore internal surface, not a plugin-author API — ⛔ plugins must not call these. */
302
+ _enterViewContext?(viewInstanceId: string): void;
303
+ _leaveViewContext?(viewInstanceId: string): void;
267
304
  };
268
305
  /** Configuration — the new name — modeled after VS Code vscode.workspace.getConfiguration */
269
306
  configuration: {
@@ -1957,24 +1994,29 @@ export interface SerialStatus {
1957
1994
  portName: string;
1958
1995
  baudRate: number;
1959
1996
  }
1960
- /** Open serial port config—plugin API input + consumed by the main-process serial-service */
1997
+ /** Open serial port config—plugin API input + consumed by the main-process serial-service.
1998
+ * No `encoding`: the shell only moves bytes; receive-decoding is the plugin's job (D2). */
1961
1999
  export interface OpenPortConfig {
1962
2000
  portName: string;
1963
2001
  baudRate: number;
1964
2002
  dataBits?: number;
1965
2003
  stopBits?: number;
1966
2004
  parity?: string;
1967
- encoding?: string;
1968
2005
  /** D8—resource ownership declaration: declared by the plugin itself at openPort (pool WCV means multiple plugins share one JS context,
1969
2006
  * so the main process cannot identify the plugin from the sender); on unload, closePortsByOwner reclaims the hardware resources by it. */
1970
2007
  ownerPluginId?: string;
1971
2008
  }
1972
- /** Serial data payload—the serial.data push ( evolved from the original port-name-less string—D6 payload objectification). */
2009
+ /** Serial data payload—the serial.data push ( evolved from the original port-name-less string—D6 payload objectification).
2010
+ * D1: the shell marks direction at its read/write boundary and passes raw bytes through; decoding belongs to the plugin (D2). */
1973
2011
  export interface SerialDataPayload {
1974
2012
  /** Data-source port = routing key—consumers receive their own port's data by portName (multiple ports coexist, each receiving its own) */
1975
2013
  portName: string;
1976
- /** Decoded line text */
1977
- text: string;
2014
+ /** Direction marked by the shell boundary: rx = received from the device, tx = written by us */
2015
+ dir: "rx" | "tx";
2016
+ /** Raw bytes—never pre-decoded (no second decoder in the shell) */
2017
+ data: Uint8Array;
2018
+ /** Timestamp (ms since epoch) of this chunk's arrival/write */
2019
+ at: number;
1978
2020
  }
1979
2021
  /** Serial stats payload—the serial.stats push ( evolved from the original port-name-less SerialStats—the data source for the S10 per-port counters).
1980
2022
  * tx/rx are push deltas (not cumulative values)—consumers accumulate on their own. */
@@ -2199,6 +2241,16 @@ export interface FileDecorationProvider {
2199
2241
  provideDecoration(uri: string): FileDecoration | null | undefined;
2200
2242
  onDidChangeFileDecorations?(cb: (uris: string[]) => void): () => void;
2201
2243
  }
2244
+ /** 文件关联候选(`listHandlersFor` 元素)——`title` = 插件显示名,`displayName` = 文件类型显示名 */
2245
+ export interface FileHandlerCandidate {
2246
+ pluginId: string;
2247
+ title: string;
2248
+ displayName: string;
2249
+ /** 宿主按「覆盖表 → 声明序 → 角色兜底」算出的当前默认 */
2250
+ isCurrent: boolean;
2251
+ }
2252
+ /** 覆盖表快照——`ext(无点小写) → pluginId`;无覆盖 = 空表 */
2253
+ export type FileAssociationOverrides = Record<string, string>;
2202
2254
  /** File decoration / association / language definition / LSP / protocol / view container namespace surfaces — editor companion services (answered directly by the main process / in-pool) */
2203
2255
  export interface EditorAPI {
2204
2256
  /** file decorations — a local in-pool registry (zero IPC). Shape modeled after contract §3.24 */
@@ -2232,12 +2284,14 @@ export interface EditorAPI {
2232
2284
  * `title` = the **plugin** display name (manifest.name ?? pluginId); `displayName` = the **file type** display name
2233
2285
  * (the displayName in the declaration, e.g. .rs → "Rust") — the two differ semantically; naming surfaces use `title`.
2234
2286
  */
2235
- listHandlersFor(ext: string): Promise<Array<{
2236
- pluginId: string;
2237
- title: string;
2238
- displayName: string;
2239
- isCurrent: boolean;
2240
- }>>;
2287
+ listHandlersFor(ext: string): Promise<FileHandlerCandidate[]>;
2288
+ /** 覆盖表**只读快照**(2026-11-24 A6):`ext → pluginId`,无覆盖 = 空表。
2289
+ * UI 插件不再需要知道宿主配置键名/表形状(旧路 `configuration.get("workbench.fileAssociations")` 退役);
2290
+ * 写入仍走 `setDefault` / `setDefaultBulk`(唯一单写者)。 */
2291
+ getOverrides(): Promise<FileAssociationOverrides>;
2292
+ /** 覆盖表变更订阅(2026-11-24 A6)——宿主写入后推送**归一化快照**;返回退订函数。
2293
+ * 旧壳无本方法 ⇒ 调用方 feature-detect 后降级(本档 K2/K10 豁免账本登记到期条件)。 */
2294
+ onDidChangeOverrides(cb: (overrides: FileAssociationOverrides) => void): () => void;
2241
2295
  /** The override table's only write port — `pluginId: null` = restore automatic (deletes the override key); config:changed is broadcast immediately after writing () */
2242
2296
  setDefault(ext: string, pluginId: string | null): Promise<void>;
2243
2297
  /** Same as above, **writes N types at once** (2/aggregation: `pluginId: null` = delete per type) — invalid/duplicate extensions are skipped within the write surface */
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@linkdesk/contracts",
3
- "version": "0.1.57",
3
+ "version": "0.1.58",
4
4
  "description": "LinkDesk 插件契约类型——window.linkdesk.* 全量类型定义(E5.8 契约生成产物)。第三方插件作者唯一合法类型消费路径。",
5
5
  "type": "module",
6
+ "main": "./index.cjs",
6
7
  "types": "./linkdesk.d.ts",
7
8
  "files": [
8
- "linkdesk.d.ts"
9
+ "linkdesk.d.ts",
10
+ "index.cjs",
11
+ "index.d.ts",
12
+ "ai-bridge.d.ts"
9
13
  ],
10
14
  "sideEffects": false,
11
15
  "publishConfig": {