@clicksmith/core 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ClickSmith contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @clicksmith/core
2
+
3
+ Platform-neutral shared contracts for ClickSmith. This package is the single
4
+ source of truth for the data that flows between the browser extension, the
5
+ daemon, the MCP server, and agent adapters.
6
+
7
+ > It has **no Node or browser runtime assumptions** beyond [`zod`](https://zod.dev),
8
+ > so it can be imported from a content script, a Fastify route, or a CLI alike.
9
+
10
+ ## What's inside
11
+
12
+ | Module | Exports |
13
+ | --- | --- |
14
+ | `schemas` | Zod schemas: `LocatorSchema`, `CapturedElementSchema`, `ExecutionOptionsSchema`, `CaptureBundleSchema` (v5), `SessionSchema`, … |
15
+ | `types` | Inferred TS types for everything above (`Locator`, `CaptureBundle`, `Session`, …). |
16
+ | `ids` | `newSessionId`, `newRunId`, `nextElementId`, `parseElementRef`. |
17
+ | `locator` | `LOCATOR_PRIORITY`, `rankLocators`, `pickBestLocator`, `describeLocator`. |
18
+ | `session` | `createSession`, `appendElement`, `removeElement`, `finalizeSession`, `isExpired`, `touchSession`. |
19
+ | `bundle` | `validateBundle`, `parseBundle`, `serializeBundle`, `deserializeBundle`. |
20
+ | `defaults` | `DEFAULT_EXECUTION_OPTIONS`, `requiresConfirmation`, `DEFAULT_SESSION_TTL_MS`, port defaults. |
21
+ | `protocol` | HTTP DTOs (`CaptureRequest`, `SubmitRequest`, …) and the `ServerEvent` WebSocket union. |
22
+
23
+ ## The capture bundle (v5)
24
+
25
+ ```ts
26
+ import { CaptureBundleSchema, type CaptureBundle } from '@clicksmith/core';
27
+
28
+ const bundle: CaptureBundle = CaptureBundleSchema.parse(payload);
29
+ ```
30
+
31
+ ```jsonc
32
+ {
33
+ "v": 5,
34
+ "sessionId": "cs_…",
35
+ "submittedAt": "2026-06-07T10:05:00.000Z",
36
+ "prompt": "make #1 match #2's style",
37
+ "app": { "url": "…", "route": "/pricing", "page": "Pricing" },
38
+ "elements": [ /* CapturedElement[] */ ],
39
+ "execution": { "mode": "plan", "isolation": "worktree", "autoApply": false },
40
+ "enrichment": { /* optional code-review-graph context */ }
41
+ }
42
+ ```
43
+
44
+ ## Locator ranking
45
+
46
+ Locators are a discriminated union ranked **exactly** `source → attr → behavioral → dom`:
47
+
48
+ ```ts
49
+ import { pickBestLocator } from '@clicksmith/core';
50
+
51
+ pickBestLocator([domLocator, attrLocator, sourceLocator]); // → sourceLocator
52
+ ```
53
+
54
+ ## Safety defaults
55
+
56
+ `plan + worktree + no auto-apply` is the immutable safe path. `requiresConfirmation()`
57
+ returns `true` for any deviation (edit mode, in-place isolation, or auto-apply), and
58
+ `confirmationReasons()` explains why — drive your confirmation UI from these.
59
+
60
+ ## Scripts
61
+
62
+ ```bash
63
+ pnpm build # tsup → dist (ESM + d.ts)
64
+ pnpm test # vitest
65
+ pnpm typecheck # tsc --noEmit
66
+ ```