laminark 2.21.6

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 (40) hide show
  1. package/.claude-plugin/marketplace.json +15 -0
  2. package/README.md +182 -0
  3. package/package.json +63 -0
  4. package/plugin/.claude-plugin/plugin.json +13 -0
  5. package/plugin/.mcp.json +12 -0
  6. package/plugin/dist/analysis/worker.d.ts +1 -0
  7. package/plugin/dist/analysis/worker.js +233 -0
  8. package/plugin/dist/analysis/worker.js.map +1 -0
  9. package/plugin/dist/config-t8LZeB-u.mjs +90 -0
  10. package/plugin/dist/config-t8LZeB-u.mjs.map +1 -0
  11. package/plugin/dist/hooks/handler.d.ts +284 -0
  12. package/plugin/dist/hooks/handler.d.ts.map +1 -0
  13. package/plugin/dist/hooks/handler.js +2125 -0
  14. package/plugin/dist/hooks/handler.js.map +1 -0
  15. package/plugin/dist/index.d.ts +445 -0
  16. package/plugin/dist/index.d.ts.map +1 -0
  17. package/plugin/dist/index.js +5831 -0
  18. package/plugin/dist/index.js.map +1 -0
  19. package/plugin/dist/observations-Ch0nc47i.d.mts +170 -0
  20. package/plugin/dist/observations-Ch0nc47i.d.mts.map +1 -0
  21. package/plugin/dist/tool-registry-CZ3mJ4iR.mjs +2655 -0
  22. package/plugin/dist/tool-registry-CZ3mJ4iR.mjs.map +1 -0
  23. package/plugin/hooks/hooks.json +78 -0
  24. package/plugin/scripts/README.md +47 -0
  25. package/plugin/scripts/bump-version.sh +44 -0
  26. package/plugin/scripts/ensure-deps.sh +12 -0
  27. package/plugin/scripts/install.sh +63 -0
  28. package/plugin/scripts/local-install.sh +103 -0
  29. package/plugin/scripts/setup-tmpdir.sh +65 -0
  30. package/plugin/scripts/uninstall.sh +95 -0
  31. package/plugin/scripts/update.sh +88 -0
  32. package/plugin/scripts/verify-install.sh +43 -0
  33. package/plugin/ui/activity.js +185 -0
  34. package/plugin/ui/app.js +1642 -0
  35. package/plugin/ui/graph.js +2333 -0
  36. package/plugin/ui/help.js +228 -0
  37. package/plugin/ui/index.html +492 -0
  38. package/plugin/ui/settings.js +650 -0
  39. package/plugin/ui/styles.css +2910 -0
  40. package/plugin/ui/timeline.js +652 -0
@@ -0,0 +1,284 @@
1
+ import { t as ObservationRepository } from "../observations-Ch0nc47i.mjs";
2
+ import * as better_sqlite30 from "better-sqlite3";
3
+ import Database from "better-sqlite3";
4
+
5
+ //#region src/storage/research-buffer.d.ts
6
+ /**
7
+ * Lightweight buffer for exploration tool events (Read, Glob, Grep).
8
+ *
9
+ * Instead of creating full observations for these low-signal tools,
10
+ * they are stored in a temporary buffer. When a Write/Edit observation
11
+ * is created, the recent buffer entries are attached as research context,
12
+ * creating provenance links between exploration and changes.
13
+ *
14
+ * Buffer entries are flushed after 30 minutes.
15
+ */
16
+ declare class ResearchBufferRepository {
17
+ private readonly db;
18
+ private readonly projectHash;
19
+ private readonly stmtInsert;
20
+ private readonly stmtGetRecent;
21
+ private readonly stmtFlush;
22
+ constructor(db: Database.Database, projectHash: string);
23
+ /**
24
+ * Records a research tool event in the buffer.
25
+ */
26
+ add(entry: {
27
+ sessionId: string | null;
28
+ toolName: string;
29
+ target: string;
30
+ }): void;
31
+ /**
32
+ * Returns recent buffer entries for a session within a time window.
33
+ */
34
+ getRecent(sessionId: string, windowMinutes?: number): Array<{
35
+ toolName: string;
36
+ target: string;
37
+ createdAt: string;
38
+ }>;
39
+ /**
40
+ * Deletes buffer entries older than the specified number of minutes.
41
+ */
42
+ flush(olderThanMinutes?: number): number;
43
+ }
44
+ //#endregion
45
+ //#region src/shared/tool-types.d.ts
46
+ /**
47
+ * Tool type classification based on how the tool is provided.
48
+ */
49
+ type ToolType = 'mcp_server' | 'mcp_tool' | 'slash_command' | 'skill' | 'plugin' | 'builtin' | 'unknown';
50
+ /**
51
+ * Scope origin of a tool -- where it was discovered from.
52
+ */
53
+ type ToolScope = 'global' | 'project' | 'plugin';
54
+ /**
55
+ * A tool discovered during config scanning (SessionStart).
56
+ * Used as input to ToolRegistryRepository.upsert().
57
+ */
58
+ interface DiscoveredTool {
59
+ name: string;
60
+ toolType: ToolType;
61
+ scope: ToolScope;
62
+ source: string;
63
+ projectHash: string | null;
64
+ description: string | null;
65
+ serverName: string | null;
66
+ }
67
+ /**
68
+ * Raw database row from the tool_registry table (snake_case).
69
+ */
70
+ interface ToolRegistryRow {
71
+ id: number;
72
+ name: string;
73
+ tool_type: string;
74
+ scope: string;
75
+ source: string;
76
+ project_hash: string | null;
77
+ description: string | null;
78
+ server_name: string | null;
79
+ usage_count: number;
80
+ last_used_at: string | null;
81
+ discovered_at: string;
82
+ updated_at: string;
83
+ status: string;
84
+ }
85
+ /**
86
+ * Aggregated usage stats for temporal queries.
87
+ */
88
+ interface ToolUsageStats {
89
+ tool_name: string;
90
+ usage_count: number;
91
+ last_used: string;
92
+ }
93
+ /**
94
+ * A search result from hybrid tool search (FTS5 + vector via RRF).
95
+ */
96
+ interface ToolSearchResult {
97
+ tool: ToolRegistryRow;
98
+ score: number;
99
+ matchType: 'fts' | 'vector' | 'hybrid';
100
+ }
101
+ //#endregion
102
+ //#region src/storage/tool-registry.d.ts
103
+ /**
104
+ * Repository for tool registry CRUD operations.
105
+ *
106
+ * Unlike ObservationRepository, this is NOT scoped to a single project --
107
+ * the tool registry spans all scopes (global, project, plugin) and is
108
+ * queried cross-project for tool discovery and routing.
109
+ *
110
+ * All SQL statements are prepared once in the constructor and reused for
111
+ * every call (better-sqlite3 performance best practice).
112
+ */
113
+ declare class ToolRegistryRepository {
114
+ private readonly db;
115
+ private readonly stmtUpsert;
116
+ private readonly stmtRecordUsage;
117
+ private readonly stmtGetByScope;
118
+ private readonly stmtGetByName;
119
+ private readonly stmtGetAll;
120
+ private readonly stmtCount;
121
+ private readonly stmtGetAvailableForSession;
122
+ private readonly stmtInsertEvent;
123
+ private readonly stmtGetUsageForTool;
124
+ private readonly stmtGetUsageForSession;
125
+ private readonly stmtGetUsageSince;
126
+ private readonly stmtGetRecentUsage;
127
+ private readonly stmtMarkStale;
128
+ private readonly stmtMarkDemoted;
129
+ private readonly stmtMarkActive;
130
+ private readonly stmtGetConfigSourced;
131
+ private readonly stmtGetRecentEventsForTool;
132
+ constructor(db: Database.Database);
133
+ /**
134
+ * Inserts or updates a discovered tool in the registry.
135
+ * On conflict (same name + project_hash), updates description and source.
136
+ */
137
+ upsert(tool: DiscoveredTool): void;
138
+ /**
139
+ * Increments usage_count and updates last_used_at for a tool.
140
+ * Called from organic PostToolUse discovery to track usage.
141
+ */
142
+ recordUsage(name: string, projectHash: string | null): void;
143
+ /**
144
+ * Records usage for an existing tool, or creates it if not yet in the registry.
145
+ * This is the entry point for organic discovery -- an upsert-and-increment-if-exists pattern.
146
+ *
147
+ * First tries recordUsage. If the tool is not in the registry (changes === 0),
148
+ * calls upsert with the full tool info, which initializes it with usage_count = 0.
149
+ */
150
+ recordOrCreate(name: string, defaults: Omit<DiscoveredTool, 'name'>, sessionId?: string | null, success?: boolean): void;
151
+ /**
152
+ * Returns global tools plus project-specific tools for the given project.
153
+ */
154
+ getForProject(projectHash: string): ToolRegistryRow[];
155
+ /**
156
+ * Returns tools available in the resolved scope for a given project.
157
+ * Implements SCOP-01/SCOP-02/SCOP-03 scope resolution rules.
158
+ */
159
+ getAvailableForSession(projectHash: string): ToolRegistryRow[];
160
+ /**
161
+ * Returns the top-usage entry for a given tool name.
162
+ */
163
+ getByName(name: string): ToolRegistryRow | null;
164
+ /**
165
+ * Returns all tools in the registry (for debugging/admin).
166
+ */
167
+ getAll(): ToolRegistryRow[];
168
+ /**
169
+ * Returns total number of tools in the registry.
170
+ */
171
+ count(): number;
172
+ /**
173
+ * Returns usage stats for a specific tool within a time window.
174
+ * @param timeModifier - SQLite datetime modifier, e.g., '-7 days', '-30 days'
175
+ */
176
+ getUsageForTool(toolName: string, projectHash: string, timeModifier?: string): ToolUsageStats | null;
177
+ /**
178
+ * Returns per-tool usage stats for a specific session.
179
+ */
180
+ getUsageForSession(sessionId: string): ToolUsageStats[];
181
+ /**
182
+ * Returns per-tool usage stats since a time offset for a project.
183
+ * @param timeModifier - SQLite datetime modifier, e.g., '-7 days', '-30 days'
184
+ */
185
+ getUsageSince(projectHash: string, timeModifier?: string): ToolUsageStats[];
186
+ /**
187
+ * Returns per-tool usage stats from the last N events for a project.
188
+ * Event-count-based window instead of time-based — immune to usage gaps.
189
+ * @param limit - Number of recent events to consider (default 200)
190
+ */
191
+ getRecentUsage(projectHash: string, limit?: number): ToolUsageStats[];
192
+ /**
193
+ * Marks a tool as stale (no longer in config but still in registry).
194
+ * Idempotent -- no-op if already stale.
195
+ */
196
+ markStale(name: string, projectHash: string | null): void;
197
+ /**
198
+ * Marks a tool as demoted (high failure rate detected).
199
+ */
200
+ markDemoted(name: string, projectHash: string | null): void;
201
+ /**
202
+ * Marks a tool as active (restored from stale/demoted).
203
+ * Idempotent -- no-op if already active.
204
+ */
205
+ markActive(name: string, projectHash: string | null): void;
206
+ /**
207
+ * Returns all config-sourced active tools for a given project (or global).
208
+ * Used by staleness detection to compare against current config state.
209
+ */
210
+ getConfigSourcedTools(projectHash: string): ToolRegistryRow[];
211
+ /**
212
+ * Returns recent success/failure events for a specific tool.
213
+ * Used by failure-driven demotion to check failure rate.
214
+ * @param limit - Number of recent events to check (default 5)
215
+ */
216
+ getRecentEventsForTool(toolName: string, projectHash: string, limit?: number): Array<{
217
+ success: number;
218
+ }>;
219
+ /**
220
+ * Sanitizes a user query for safe FTS5 MATCH usage.
221
+ * Removes FTS5 operators and special characters to prevent syntax errors.
222
+ * Returns null if the query is empty after sanitization.
223
+ */
224
+ private sanitizeQuery;
225
+ /**
226
+ * FTS5 keyword search on tool_registry_fts (name + description).
227
+ * Returns ranked results using BM25 with name weighted 2x over description.
228
+ */
229
+ searchByKeyword(query: string, options?: {
230
+ scope?: string;
231
+ limit?: number;
232
+ }): ToolSearchResult[];
233
+ /**
234
+ * Vector similarity search on tool_registry_embeddings using vec0 KNN.
235
+ * Returns tool IDs and distances sorted by cosine similarity.
236
+ */
237
+ searchByVector(queryEmbedding: Float32Array, options?: {
238
+ scope?: string;
239
+ limit?: number;
240
+ }): Array<{
241
+ tool_id: number;
242
+ distance: number;
243
+ }>;
244
+ /**
245
+ * Hybrid search combining FTS5 keyword and vec0 vector results via
246
+ * reciprocal rank fusion (RRF). Falls back to FTS5-only when vector
247
+ * search is unavailable (no worker, no sqlite-vec, no embeddings).
248
+ */
249
+ searchTools(query: string, options?: {
250
+ scope?: string;
251
+ limit?: number;
252
+ worker?: {
253
+ isReady(): boolean;
254
+ embed(text: string): Promise<Float32Array | null>;
255
+ } | null;
256
+ hasVectorSupport?: boolean;
257
+ }): Promise<ToolSearchResult[]>;
258
+ /**
259
+ * Stores an embedding vector for a tool in tool_registry_embeddings.
260
+ * Used by the background embedding loop to index tool descriptions.
261
+ */
262
+ storeEmbedding(toolId: number, embedding: Float32Array): void;
263
+ /**
264
+ * Returns tools that have descriptions but no embedding yet.
265
+ * Used by the background embedding loop to find work.
266
+ */
267
+ findUnembeddedTools(limit?: number): Array<{
268
+ id: number;
269
+ name: string;
270
+ description: string;
271
+ }>;
272
+ }
273
+ //#endregion
274
+ //#region src/hooks/handler.d.ts
275
+ /**
276
+ * Processes a PostToolUse or PostToolUseFailure event through the full
277
+ * filter pipeline: route research tools -> extract -> privacy -> admission -> store.
278
+ *
279
+ * Exported for unit testing of the pipeline logic.
280
+ */
281
+ declare function processPostToolUseFiltered(input: Record<string, unknown>, obsRepo: ObservationRepository, researchBuffer?: ResearchBufferRepository, toolRegistry?: ToolRegistryRepository, projectHash?: string, db?: better_sqlite30.Database): void;
282
+ //#endregion
283
+ export { processPostToolUseFiltered };
284
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","names":[],"sources":["../../../src/storage/research-buffer.ts","../../../src/shared/tool-types.ts","../../../src/storage/tool-registry.ts","../../../src/hooks/handler.ts"],"mappings":";;;;;;;;;AAcA;;;;;;cAAa,wBAAA;EAAA,iBACM,E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