@serviceme/devtools-core 0.1.8 → 0.2.0

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 (47) hide show
  1. package/dist/auth.d.mts +590 -0
  2. package/dist/auth.d.ts +590 -0
  3. package/dist/auth.js +842 -0
  4. package/dist/auth.js.map +1 -0
  5. package/dist/auth.mjs +804 -0
  6. package/dist/auth.mjs.map +1 -0
  7. package/dist/device.d.mts +456 -0
  8. package/dist/device.d.ts +456 -0
  9. package/dist/device.js +696 -0
  10. package/dist/device.js.map +1 -0
  11. package/dist/device.mjs +647 -0
  12. package/dist/device.mjs.map +1 -0
  13. package/dist/index-CrNC-aao.d.ts +277 -0
  14. package/dist/index-Dmyy4urr.d.mts +277 -0
  15. package/dist/index.d.mts +1372 -27
  16. package/dist/index.d.ts +1372 -27
  17. package/dist/index.js +5125 -888
  18. package/dist/index.js.map +1 -0
  19. package/dist/index.mjs +5022 -906
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/skill-linker.d.mts +188 -0
  22. package/dist/skill-linker.d.ts +188 -0
  23. package/dist/skill-linker.js +374 -0
  24. package/dist/skill-linker.js.map +1 -0
  25. package/dist/skill-linker.mjs +330 -0
  26. package/dist/skill-linker.mjs.map +1 -0
  27. package/dist/skill-store.d.mts +35 -0
  28. package/dist/skill-store.d.ts +35 -0
  29. package/dist/skill-store.js +291 -0
  30. package/dist/skill-store.js.map +1 -0
  31. package/dist/skill-store.mjs +254 -0
  32. package/dist/skill-store.mjs.map +1 -0
  33. package/dist/submit.d.mts +3 -0
  34. package/dist/submit.d.ts +3 -0
  35. package/dist/submit.js +166 -0
  36. package/dist/submit.js.map +1 -0
  37. package/dist/submit.mjs +130 -0
  38. package/dist/submit.mjs.map +1 -0
  39. package/dist/toolbox.d.mts +240 -0
  40. package/dist/toolbox.d.ts +240 -0
  41. package/dist/toolbox.js +530 -0
  42. package/dist/toolbox.js.map +1 -0
  43. package/dist/toolbox.mjs +482 -0
  44. package/dist/toolbox.mjs.map +1 -0
  45. package/dist/types-B9gk3dXH.d.mts +62 -0
  46. package/dist/types-B9gk3dXH.d.ts +62 -0
  47. package/package.json +50 -5
@@ -0,0 +1,240 @@
1
+ import { ExternalTool, ToolboxScope, ToolboxList } from '@serviceme/devtools-protocol';
2
+
3
+ /**
4
+ * toolbox sort + dedup — pure helpers, no I/O.
5
+ *
6
+ * The Extension's `ToolBoxService` keeps a stable `order` index and
7
+ * surfaces "recently used" via the `lastUsedAt` ISO timestamp. These
8
+ * helpers codify that algorithm so the CLI and Extension agree on the
9
+ * "最近使用置顶" UX.
10
+ *
11
+ * Refs:
12
+ * - 4.功能规划.md §2.3 — `sort.ts 排序与去重纯函数`
13
+ */
14
+
15
+ /**
16
+ * Sort by "recently used" — entries with newer `lastUsedAt` float to
17
+ * the top, entries with no `lastUsedAt` sort to the bottom (preserving
18
+ * their relative `order` index when both are absent).
19
+ *
20
+ * Ties (same `lastUsedAt` or both missing) are broken by `order`, then
21
+ * by `id` for determinism.
22
+ */
23
+ declare function sortByRecentFirst(tools: readonly ExternalTool[]): ExternalTool[];
24
+ /**
25
+ * Sort by user-defined `order` field. Entries without `order` are
26
+ * appended in their input order (stable sort via `id` tiebreaker).
27
+ */
28
+ declare function sortByUserOrder(tools: readonly ExternalTool[]): ExternalTool[];
29
+ /**
30
+ * Merge built-in defaults with user-stored tools. Defaults keep
31
+ * `isDefault: true` and their `order`; user tools are appended with
32
+ * their stored metadata. Output is sorted by user order.
33
+ */
34
+ declare function mergeWithDefaults(defaults: readonly ExternalTool[], userTools: readonly ExternalTool[]): ExternalTool[];
35
+ /**
36
+ * Re-number `order` for a list of tool ids. Used by
37
+ * `toolbox.update` when the user drags-and-drops entries in the UI.
38
+ */
39
+ declare function reindexOrder(tools: ExternalTool[], newOrderIds: readonly string[]): ExternalTool[];
40
+ /**
41
+ * Stamp `lastUsedAt` on the targeted tool (clones the array). Returns
42
+ * a new array; the input is left untouched.
43
+ */
44
+ declare function touchLastUsedAt(tools: readonly ExternalTool[], id: string, when?: Date): ExternalTool[];
45
+
46
+ /**
47
+ * toolbox types — internal-only data shapes.
48
+ *
49
+ * The public data model lives in `@serviceme/devtools-protocol/toolbox`
50
+ * (`ExternalTool`, `ToolboxScope`, `ToolboxList`). The types below are
51
+ * the persisted on-disk shape and the patch helpers, scoped to the
52
+ * toolbox domain only.
53
+ *
54
+ * Refs:
55
+ * - 4.功能规划.md §2.3 — `toolbox/types.ts`
56
+ */
57
+
58
+ /** Schema version of the on-disk toolbox JSON files. Bumped on breaking changes. */
59
+ declare const TOOLBOX_JSON_SCHEMA_VERSION = 1;
60
+ interface PersistedToolbox {
61
+ version: number;
62
+ tools: ExternalTool[];
63
+ }
64
+ /** Patch payload accepted by `ToolboxCore.update` (mirrors `ExternalToolPatch`). */
65
+ type ToolboxPatch = Partial<Omit<ExternalTool, "id" | "isDefault">>;
66
+ /**
67
+ * Built-in (default) tool seeds. Mirrors the Extension's
68
+ * `apps/extension/src/config/external-tools.ts`. The Core stores these
69
+ * verbatim and never mutates them — the Extension's `ToolBoxService`
70
+ * runs the same merge on top of the Core's view.
71
+ */
72
+ interface DefaultToolSeed {
73
+ id: string;
74
+ name: string;
75
+ description: string;
76
+ icon: string;
77
+ url: string;
78
+ }
79
+ /** Built-in tools rendered when the JSON file is missing or empty. */
80
+ declare const BUILTIN_DEFAULT_TOOLS: readonly DefaultToolSeed[];
81
+ /** Resolved toolbox shape returned by `ToolboxStore.read()`. */
82
+ interface ResolvedToolbox {
83
+ scope: ToolboxScope;
84
+ tools: ExternalTool[];
85
+ }
86
+
87
+ /**
88
+ * ToolboxStore — JSON persistence for the toolbox entries.
89
+ *
90
+ * Two scopes:
91
+ * - `user` → `~/.serviceme/toolbox.json`
92
+ * - `workspace` → `<cwd>/.github/.serviceme-toolbox.json`
93
+ *
94
+ * Both files share the `PersistedToolbox` shape and the same atomic
95
+ * write pattern (tmp + rename + fsync) as `IdentityStore`. Concurrent
96
+ * writers are serialized via a mkdir-based file lock (Phase 6+ may
97
+ * upgrade to `proper-lockfile`).
98
+ *
99
+ * Refs:
100
+ * - 4.功能规划.md §2.3 — `ToolboxStore.ts JSON 持久化(user + workspace scope)`
101
+ * - `3.功能拆分.md` §3 — toolbox wire shape
102
+ */
103
+
104
+ declare const WORKSPACE_TOOLBOX_RELATIVE_PATH: string;
105
+ interface ToolboxFileBackend {
106
+ read(filePath: string): Promise<PersistedToolbox | null>;
107
+ write(filePath: string, payload: PersistedToolbox): Promise<void>;
108
+ exists(filePath: string): Promise<boolean>;
109
+ }
110
+ interface ToolboxStoreOptions {
111
+ /** Override the user-scope file path (default: `getToolboxJsonPath()`). */
112
+ userFilePath?: string;
113
+ /** Override the workspace-scope file path resolver (default: cwd-relative). */
114
+ resolveWorkspacePath?: () => string | null;
115
+ /** Injectable built-in tool seeds (default: `BUILTIN_DEFAULT_TOOLS`). */
116
+ defaultTools?: readonly DefaultToolSeed[];
117
+ hooks?: ToolboxStoreHooks;
118
+ backend?: ToolboxFileBackend;
119
+ lockTimeoutMs?: number;
120
+ lockRetryMs?: number;
121
+ }
122
+ interface ToolboxStoreHooks {
123
+ beforeWrite?: (scope: ToolboxScope, payload: PersistedToolbox) => void | Promise<void>;
124
+ afterWrite?: (scope: ToolboxScope, payload: PersistedToolbox) => void | Promise<void>;
125
+ }
126
+ declare class FsToolboxFileBackend implements ToolboxFileBackend {
127
+ exists(filePath: string): Promise<boolean>;
128
+ read(filePath: string): Promise<PersistedToolbox | null>;
129
+ private backupCorruptedFile;
130
+ write(filePath: string, payload: PersistedToolbox): Promise<void>;
131
+ }
132
+ declare class ToolboxStore {
133
+ private readonly userFilePath;
134
+ private readonly resolveWorkspacePath;
135
+ private readonly defaults;
136
+ private readonly hooks;
137
+ private readonly backend;
138
+ private readonly lockTimeoutMs;
139
+ private readonly lockRetryMs;
140
+ constructor(opts?: ToolboxStoreOptions);
141
+ /** Read a scope; returns the resolved toolbox (with defaults merged when empty). */
142
+ read(scope: ToolboxScope): Promise<ResolvedToolbox>;
143
+ /**
144
+ * Atomic write under a file lock. Replaces the entire `tools` array
145
+ * with the provided snapshot.
146
+ */
147
+ write(scope: ToolboxScope, tools: readonly ExternalTool[]): Promise<void>;
148
+ /**
149
+ * Read-modify-write under the file lock. The mutator receives the
150
+ * current user-only list (defaults not included) and returns the
151
+ * replacement list. Throwing inside the mutator aborts the write.
152
+ */
153
+ mutate(scope: ToolboxScope, mutator: (current: ExternalTool[]) => Promise<ExternalTool[]>): Promise<ExternalTool[]>;
154
+ /** Wipe a scope entirely (used by `toolbox.remove --all` extensions). */
155
+ clear(scope: ToolboxScope): Promise<void>;
156
+ /** Test seam — resolve the user-scope file path. */
157
+ getUserFilePath(): string;
158
+ /** Test seam — resolve the workspace-scope file path (or null when disabled). */
159
+ getWorkspaceFilePath(): string | null;
160
+ private filePathFor;
161
+ }
162
+
163
+ /**
164
+ * ToolboxCore — Main entry for the toolbox domain.
165
+ *
166
+ * Orchestrates the user + workspace scopes via `ToolboxStore`, applies
167
+ * the "最近使用置顶" sort, and exposes a small surface that mirrors
168
+ * the Phase 5.1 bridge methods:
169
+ *
170
+ * - `list(scope?)` → `toolbox.list`
171
+ * - `add(tool, scope)` → `toolbox.add`
172
+ * - `remove(id, scope?)` → `toolbox.remove`
173
+ * - `update(id, patch, scope?)` → `toolbox.update`
174
+ *
175
+ * Default tools (built-in seeds) are never user-deletable. `remove()`
176
+ * is a no-op for default tools and surfaces a structured error so
177
+ * callers can map it to `TOOLBOX_DEFAULT_IMMUTABLE` (Phase 5.3 error
178
+ * code).
179
+ *
180
+ * Refs:
181
+ * - 4.功能规划.md §2.3 — `ToolboxCore.ts 主入口`
182
+ * - `3.功能拆分.md` §3 — wire shape
183
+ */
184
+
185
+ /** Sentinel — caller tried to remove a built-in (immutable) tool. */
186
+ declare class DefaultToolImmutableError extends Error {
187
+ readonly toolId: string;
188
+ constructor(toolId: string);
189
+ }
190
+ interface ToolboxCoreOptions {
191
+ store?: ToolboxStore;
192
+ defaultTools?: readonly DefaultToolSeed[];
193
+ /** Sort applied to the merged list returned by `list()`. Default: `sortByUserOrder`. */
194
+ listSort?: (tools: readonly ExternalTool[]) => ExternalTool[];
195
+ }
196
+ declare class ToolboxCore {
197
+ private readonly store;
198
+ private readonly defaults;
199
+ private readonly listSort;
200
+ constructor(opts?: ToolboxCoreOptions);
201
+ /** List all tools in a scope. Built-in defaults are merged in. */
202
+ list(scope?: ToolboxScope): Promise<ToolboxList>;
203
+ /**
204
+ * Append a new tool to the requested scope. Default tools are
205
+ * rejected (they are seeds, not user entries).
206
+ */
207
+ add(tool: ExternalTool, scope?: ToolboxScope): Promise<ToolboxList>;
208
+ /**
209
+ * Remove a tool by id. Returns `success: false` when the id is a
210
+ * built-in default (idempotent, never throws on missing entries).
211
+ */
212
+ remove(id: string, scope?: ToolboxScope): Promise<{
213
+ scope: ToolboxScope;
214
+ toolId: string;
215
+ success: boolean;
216
+ }>;
217
+ /**
218
+ * Patch a tool by id. Default tools can only have their `order`
219
+ * updated; other patches are silently ignored for default entries
220
+ * (callers can compare before/after to detect the ignore).
221
+ */
222
+ update(id: string, patch: ToolboxPatch, scope?: ToolboxScope): Promise<ToolboxList>;
223
+ /**
224
+ * Stamp `lastUsedAt` on the targeted tool. This is the "recently
225
+ * used" hook the Extension's webview uses when a user clicks a
226
+ * toolbox entry.
227
+ */
228
+ recordUsage(id: string, scope?: ToolboxScope, when?: Date): Promise<ExternalTool | null>;
229
+ /**
230
+ * Combined view: user + workspace scopes merged, sorted by recent
231
+ * usage. Workspace tools overlay user tools (workspace entries win
232
+ * on `id` collision).
233
+ */
234
+ listMerged(): Promise<ToolboxList>;
235
+ /** Expose the underlying store (CLI / Bridge use it for path-level access). */
236
+ getStore(): ToolboxStore;
237
+ private isDefaultId;
238
+ }
239
+
240
+ export { BUILTIN_DEFAULT_TOOLS, DefaultToolImmutableError, type DefaultToolSeed, FsToolboxFileBackend, type PersistedToolbox, type ResolvedToolbox, TOOLBOX_JSON_SCHEMA_VERSION, ToolboxCore, type ToolboxCoreOptions, type ToolboxFileBackend, type ToolboxPatch, ToolboxStore, type ToolboxStoreHooks, type ToolboxStoreOptions, WORKSPACE_TOOLBOX_RELATIVE_PATH, mergeWithDefaults, reindexOrder, sortByRecentFirst, sortByUserOrder, touchLastUsedAt };