tencil 0.4.0 → 0.6.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/dist/cli.mjs +69 -103
- package/dist/cloud-CIAGUsk2.d.mts +14 -0
- package/dist/cloud-CiwIrP1h.mjs +104 -0
- package/dist/index-B0phpEz9.d.mts +454 -0
- package/dist/index.d.mts +3 -340
- package/dist/index.mjs +1 -1
- package/dist/next-loader.cjs +163 -0
- package/dist/next.d.mts +14 -0
- package/dist/next.mjs +45 -0
- package/dist/overlay.global.js +53 -26
- package/dist/react.d.mts +10 -3
- package/dist/react.mjs +20 -5
- package/dist/{server-9m0nvaLs.mjs → server-COf9gtqR.mjs} +117 -8
- package/dist/vite.d.mts +23 -4
- package/dist/vite.mjs +178 -4
- package/package.json +13 -6
package/dist/react.d.mts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import { t as TencilCloudOptions } from "./cloud-CIAGUsk2.mjs";
|
|
1
2
|
//#region src/integrations/react.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Loads the Tencil overlay in development from the daemon on the machine
|
|
4
|
-
* serving the page (`npx tencil start`)
|
|
5
|
-
*
|
|
5
|
+
* serving the page (`npx tencil start`); without a running daemon the script
|
|
6
|
+
* simply doesn't load.
|
|
7
|
+
*
|
|
8
|
+
* Outside development it renders nothing, unless TENCIL_CLOUD is set for a
|
|
9
|
+
* preview deployment: then it loads the overlay from Tencil Cloud. That needs
|
|
10
|
+
* the env at render time, so keep `<Tencil />` in a server component (the root
|
|
11
|
+
* layout or `_document`).
|
|
6
12
|
*
|
|
7
13
|
* <body>{children}<Tencil /></body>
|
|
8
14
|
*/
|
|
9
|
-
export declare function Tencil({ port }: {
|
|
15
|
+
export declare function Tencil({ port, cloud }: {
|
|
10
16
|
port?: number;
|
|
17
|
+
cloud?: TencilCloudOptions;
|
|
11
18
|
}): import("react").DetailedReactHTMLElement<{
|
|
12
19
|
id: string;
|
|
13
20
|
dangerouslySetInnerHTML: {
|
package/dist/react.mjs
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
+
import { n as cloudLoader, r as resolveCloudBuild } from "./cloud-CiwIrP1h.mjs";
|
|
1
2
|
import { n as overlayLoader, t as DEFAULT_DAEMON_PORT } from "./loader-BevujQ44.mjs";
|
|
2
3
|
import { createElement } from "react";
|
|
3
4
|
//#region src/integrations/react.ts
|
|
5
|
+
let warned = false;
|
|
4
6
|
/**
|
|
5
7
|
* Loads the Tencil overlay in development from the daemon on the machine
|
|
6
|
-
* serving the page (`npx tencil start`)
|
|
7
|
-
*
|
|
8
|
+
* serving the page (`npx tencil start`); without a running daemon the script
|
|
9
|
+
* simply doesn't load.
|
|
10
|
+
*
|
|
11
|
+
* Outside development it renders nothing, unless TENCIL_CLOUD is set for a
|
|
12
|
+
* preview deployment: then it loads the overlay from Tencil Cloud. That needs
|
|
13
|
+
* the env at render time, so keep `<Tencil />` in a server component (the root
|
|
14
|
+
* layout or `_document`).
|
|
8
15
|
*
|
|
9
16
|
* <body>{children}<Tencil /></body>
|
|
10
17
|
*/
|
|
11
|
-
function Tencil({ port = DEFAULT_DAEMON_PORT }) {
|
|
12
|
-
if (process.env.NODE_ENV
|
|
18
|
+
function Tencil({ port = DEFAULT_DAEMON_PORT, cloud }) {
|
|
19
|
+
if (process.env.NODE_ENV === "development") return script(overlayLoader(port));
|
|
20
|
+
const resolved = resolveCloudBuild(typeof process === "undefined" ? {} : process.env, cloud);
|
|
21
|
+
if (resolved.kind === "refused" && !warned) {
|
|
22
|
+
warned = true;
|
|
23
|
+
console.warn(`[tencil] Not loading Tencil Cloud. ${resolved.reason}`);
|
|
24
|
+
}
|
|
25
|
+
return resolved.kind === "on" ? script(cloudLoader(resolved)) : null;
|
|
26
|
+
}
|
|
27
|
+
function script(code) {
|
|
13
28
|
return createElement("script", {
|
|
14
29
|
id: "tencil-loader",
|
|
15
|
-
dangerouslySetInnerHTML: { __html:
|
|
30
|
+
dangerouslySetInnerHTML: { __html: code }
|
|
16
31
|
});
|
|
17
32
|
}
|
|
18
33
|
//#endregion
|
|
@@ -64,11 +64,26 @@ const ImageAttachment = z.object({
|
|
|
64
64
|
]),
|
|
65
65
|
dataUrl: z.string().startsWith("data:image/").max(14e6)
|
|
66
66
|
});
|
|
67
|
+
/**
|
|
68
|
+
* The code a page was built from, set by Tencil Cloud builds (`TENCIL_CLOUD`).
|
|
69
|
+
* Local pages have none: the daemon finds their project from the dev server.
|
|
70
|
+
*/
|
|
71
|
+
const BuildInfo = z.object({
|
|
72
|
+
/** Project key from the Tencil Cloud dashboard. */
|
|
73
|
+
projectKey: z.string().min(1).max(64),
|
|
74
|
+
/** `owner/name` on GitHub. */
|
|
75
|
+
repo: z.string().min(3).max(200),
|
|
76
|
+
branch: z.string().min(1).max(255),
|
|
77
|
+
sha: z.string().min(7).max(64)
|
|
78
|
+
});
|
|
67
79
|
const ClientMessage = z.discriminatedUnion("type", [
|
|
68
80
|
z.object({
|
|
69
81
|
type: z.literal("hello"),
|
|
70
82
|
protocol: z.literal(1),
|
|
71
|
-
pageUrl: z.string()
|
|
83
|
+
pageUrl: z.string(),
|
|
84
|
+
build: BuildInfo.optional(),
|
|
85
|
+
/** Tencil Cloud access token; the local daemon has no sign-in. */
|
|
86
|
+
token: z.string().min(1).max(4096).optional()
|
|
72
87
|
}),
|
|
73
88
|
z.object({
|
|
74
89
|
type: z.literal("thread.create"),
|
|
@@ -206,6 +221,66 @@ const ThreadMessage = z.object({
|
|
|
206
221
|
createdAt: z.string()
|
|
207
222
|
});
|
|
208
223
|
/**
|
|
224
|
+
* Where a Tencil Cloud run's change is once the agent is done: Tencil Cloud
|
|
225
|
+
* commits and pushes it, the host redeploys the preview. The local daemon
|
|
226
|
+
* never sets it; there the dev server reloads.
|
|
227
|
+
* - `queued`: waiting for earlier runs on the same branch
|
|
228
|
+
* - `pushed`: committed and pushed (to the branch's pull request, or a new one)
|
|
229
|
+
* - `deploying` / `live` / `deploy-failed`: the preview of that commit
|
|
230
|
+
* - `no-changes`: the agent changed nothing, so nothing was pushed
|
|
231
|
+
* - `failed`: couldn't commit or push (e.g. a conflict); see `detail`
|
|
232
|
+
*/
|
|
233
|
+
const DeliveryStatus = z.enum([
|
|
234
|
+
"queued",
|
|
235
|
+
"pushed",
|
|
236
|
+
"deploying",
|
|
237
|
+
"live",
|
|
238
|
+
"deploy-failed",
|
|
239
|
+
"no-changes",
|
|
240
|
+
"failed"
|
|
241
|
+
]);
|
|
242
|
+
const Delivery = z.object({
|
|
243
|
+
status: DeliveryStatus,
|
|
244
|
+
detail: z.string().optional(),
|
|
245
|
+
/** Runs ahead of this one on the branch, while queued. */
|
|
246
|
+
queuePosition: z.number().int().nonnegative().optional(),
|
|
247
|
+
commit: z.object({
|
|
248
|
+
sha: z.string(),
|
|
249
|
+
url: z.string()
|
|
250
|
+
}).optional(),
|
|
251
|
+
/** `opened`: Tencil Cloud opened it for this run (the branch had none). */
|
|
252
|
+
pullRequest: z.object({
|
|
253
|
+
number: z.number().int(),
|
|
254
|
+
url: z.string(),
|
|
255
|
+
opened: z.boolean().default(false)
|
|
256
|
+
}).optional(),
|
|
257
|
+
/** The redeployed preview, once live. */
|
|
258
|
+
previewUrl: z.string().optional(),
|
|
259
|
+
/** Deploy logs, when the deploy failed. */
|
|
260
|
+
logsUrl: z.string().optional()
|
|
261
|
+
});
|
|
262
|
+
const StepStatus = z.enum([
|
|
263
|
+
"running",
|
|
264
|
+
"done",
|
|
265
|
+
"failed",
|
|
266
|
+
"skipped"
|
|
267
|
+
]);
|
|
268
|
+
/**
|
|
269
|
+
* One thing a provider did during the current turn, for the overlay to show
|
|
270
|
+
* under "Working…": Tencil Cloud starting a sandbox, cloning, installing, then
|
|
271
|
+
* the agent's tool calls (nested under the agent step through `parentId`).
|
|
272
|
+
*/
|
|
273
|
+
const ThreadStep = z.object({
|
|
274
|
+
id: z.string(),
|
|
275
|
+
label: z.string(),
|
|
276
|
+
status: StepStatus,
|
|
277
|
+
/** A second line: the command, a file, why it failed. */
|
|
278
|
+
detail: z.string().optional(),
|
|
279
|
+
parentId: z.string().optional(),
|
|
280
|
+
startedAt: z.string(),
|
|
281
|
+
endedAt: z.string().optional()
|
|
282
|
+
});
|
|
283
|
+
/**
|
|
209
284
|
* A conversation Tencil tracks, backed by one provider thread. Owned and
|
|
210
285
|
* persisted by the bridge. Pinned threads sit on an element of a page;
|
|
211
286
|
* threads opened from the provider's list have no anchor and live in the dock.
|
|
@@ -227,6 +302,10 @@ const Thread = z.object({
|
|
|
227
302
|
/** Deep link into the provider UI, when it has one. */
|
|
228
303
|
url: z.string().optional()
|
|
229
304
|
}),
|
|
305
|
+
/** Tencil Cloud only: the run's commit, pull request and preview. */
|
|
306
|
+
delivery: Delivery.optional(),
|
|
307
|
+
/** What the provider did during the latest turn, when it reports steps. */
|
|
308
|
+
steps: z.array(ThreadStep).optional(),
|
|
230
309
|
createdAt: z.string(),
|
|
231
310
|
updatedAt: z.string()
|
|
232
311
|
});
|
|
@@ -298,15 +377,15 @@ function renderBatchPrompt(comments) {
|
|
|
298
377
|
return `${comments.map((comment) => `#${comment.number} ${comment.prompt.trim()}`).join("\n\n")}\n\n${CONTEXT_OPEN}\n${lines.join("\n")}\n${CONTEXT_CLOSE}`;
|
|
299
378
|
}
|
|
300
379
|
function contextLines(pageUrl, context) {
|
|
301
|
-
const lines = [`- Page: ${pageUrl}`, `- Element: \`${oneLine(context.html)}\``];
|
|
380
|
+
const lines = [`- Page: ${page(pageUrl)}`, `- Element: \`${page(truncate(oneLine(context.html), 2e3))}\``];
|
|
302
381
|
const [component, ...owners] = context.components;
|
|
303
382
|
if (component) {
|
|
304
383
|
const chain = [component, ...owners.slice(0, 4)].map(formatFrame).join(" ← ");
|
|
305
|
-
lines.push(`- Component: ${chain}`);
|
|
384
|
+
lines.push(`- Component: ${page(chain)}`);
|
|
306
385
|
}
|
|
307
|
-
lines.push(`- Selector: \`${context.selector}\``);
|
|
308
|
-
if (context.text) lines.push(`- Visible text: "${truncate(oneLine(context.text), 200)}"`);
|
|
309
|
-
if (context.selection) lines.push(`- Selected text: "${truncate(oneLine(context.selection), 300)}"`);
|
|
386
|
+
lines.push(`- Selector: \`${page(truncate(context.selector, 500))}\``);
|
|
387
|
+
if (context.text) lines.push(`- Visible text: "${page(truncate(oneLine(context.text), 200))}"`);
|
|
388
|
+
if (context.selection) lines.push(`- Selected text: "${page(truncate(oneLine(context.selection), 300))}"`);
|
|
310
389
|
const { rect, viewport } = context;
|
|
311
390
|
lines.push(`- Layout: ${Math.round(rect.width)}×${Math.round(rect.height)} at (${Math.round(rect.x)}, ${Math.round(rect.y)}) in a ${viewport.width}×${viewport.height} viewport @${viewport.dpr}x`);
|
|
312
391
|
return lines;
|
|
@@ -328,6 +407,14 @@ function formatFrame(frame) {
|
|
|
328
407
|
const position = [frame.source.line, frame.source.column].filter((n) => n != null).join(":");
|
|
329
408
|
return `${frame.name} (${frame.source.file}${position ? `:${position}` : ""})`;
|
|
330
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Text from the page goes inside the context block as data. It must not be able
|
|
412
|
+
* to close that block early and pass the rest off as the user's words, so the
|
|
413
|
+
* block's tags are defused wherever they appear in it.
|
|
414
|
+
*/
|
|
415
|
+
function page(text) {
|
|
416
|
+
return text.replace(/<(\/?\s*tencil-context)/gi, "‹$1");
|
|
417
|
+
}
|
|
331
418
|
function oneLine(text) {
|
|
332
419
|
return text.replace(/\s+/g, " ").trim();
|
|
333
420
|
}
|
|
@@ -398,7 +485,8 @@ var Bridge = class {
|
|
|
398
485
|
project: this.#options.project,
|
|
399
486
|
provider: this.#provider().info(),
|
|
400
487
|
settings: this.#settings(),
|
|
401
|
-
threads: this.#options.store.list()
|
|
488
|
+
threads: this.#options.store.list(),
|
|
489
|
+
...client.viewer && { viewer: client.viewer }
|
|
402
490
|
});
|
|
403
491
|
return;
|
|
404
492
|
case "thread.create":
|
|
@@ -730,6 +818,7 @@ var Bridge = class {
|
|
|
730
818
|
resolved: false,
|
|
731
819
|
status: "working",
|
|
732
820
|
statusDetail: void 0,
|
|
821
|
+
steps: void 0,
|
|
733
822
|
messages: [...current.messages, localMessage(message.text, (/* @__PURE__ */ new Date()).toISOString())]
|
|
734
823
|
}));
|
|
735
824
|
await this.#providerOf(thread).sendMessage({
|
|
@@ -758,6 +847,11 @@ var Bridge = class {
|
|
|
758
847
|
status,
|
|
759
848
|
statusDetail
|
|
760
849
|
})),
|
|
850
|
+
delivery: (delivery) => each((thread) => ({
|
|
851
|
+
...thread,
|
|
852
|
+
delivery
|
|
853
|
+
})),
|
|
854
|
+
step: (step) => each((thread) => mergeStep(thread, step)),
|
|
761
855
|
gone: () => each((thread) => ({
|
|
762
856
|
...thread,
|
|
763
857
|
status: "error",
|
|
@@ -869,6 +963,21 @@ function mergeMessage(thread, incoming) {
|
|
|
869
963
|
messages
|
|
870
964
|
};
|
|
871
965
|
}
|
|
966
|
+
/** Most steps a pin keeps; a long agent turn drops its oldest tool calls first. */
|
|
967
|
+
const MAX_STEPS = 200;
|
|
968
|
+
function mergeStep(thread, step) {
|
|
969
|
+
const current = thread.steps ?? [];
|
|
970
|
+
const index = current.findIndex((s) => s.id === step.id);
|
|
971
|
+
let steps = index === -1 ? [...current, step] : current.map((s, i) => i === index ? step : s);
|
|
972
|
+
if (steps.length > MAX_STEPS) {
|
|
973
|
+
const drop = steps.findIndex((s) => s.parentId !== void 0 && s.status !== "running");
|
|
974
|
+
steps = steps.filter((_, i) => i !== (drop === -1 ? 0 : drop));
|
|
975
|
+
}
|
|
976
|
+
return {
|
|
977
|
+
...thread,
|
|
978
|
+
steps
|
|
979
|
+
};
|
|
980
|
+
}
|
|
872
981
|
//#endregion
|
|
873
982
|
//#region ../bridge/src/project-providers.ts
|
|
874
983
|
/**
|
|
@@ -3032,7 +3141,7 @@ function errorMessage(error) {
|
|
|
3032
3141
|
}
|
|
3033
3142
|
//#endregion
|
|
3034
3143
|
//#region src/version.ts
|
|
3035
|
-
const VERSION = "0.
|
|
3144
|
+
const VERSION = "0.6.0";
|
|
3036
3145
|
//#endregion
|
|
3037
3146
|
//#region src/daemon/thread-store.ts
|
|
3038
3147
|
const StoreFile = z.object({
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,22 +1,41 @@
|
|
|
1
|
+
import { t as TencilCloudOptions } from "./cloud-CIAGUsk2.mjs";
|
|
1
2
|
//#region src/integrations/vite.d.ts
|
|
2
3
|
/** Structural subset of Vite's Plugin type, so `vite` stays an optional peer. */
|
|
3
4
|
interface VitePlugin {
|
|
4
5
|
name: string;
|
|
5
|
-
|
|
6
|
+
/** Before the React plugin compiles JSX, so source attributes can be added. */
|
|
7
|
+
enforce: 'pre';
|
|
8
|
+
apply(config: unknown, env: {
|
|
9
|
+
command: 'build' | 'serve';
|
|
10
|
+
}): boolean;
|
|
11
|
+
configResolved(config: {
|
|
12
|
+
root: string;
|
|
13
|
+
}): void;
|
|
6
14
|
transformIndexHtml(): Array<{
|
|
7
15
|
tag: string;
|
|
8
16
|
children: string;
|
|
9
17
|
injectTo: 'body';
|
|
10
18
|
}>;
|
|
11
|
-
transform(code: string, id: string): string | undefined
|
|
19
|
+
transform(code: string, id: string): string | undefined | Promise<{
|
|
20
|
+
code: string;
|
|
21
|
+
map: unknown;
|
|
22
|
+
} | undefined>;
|
|
12
23
|
}
|
|
13
24
|
export interface TencilViteOptions {
|
|
14
25
|
/** Port of the Tencil daemon. Defaults to TENCIL_PORT or 4747. */
|
|
15
26
|
port?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Tencil Cloud for preview builds. On when TENCIL_CLOUD holds a project key;
|
|
29
|
+
* repo, branch and commit come from the host. Production builds never load it.
|
|
30
|
+
*/
|
|
31
|
+
cloud?: TencilCloudOptions;
|
|
16
32
|
}
|
|
17
33
|
/**
|
|
18
|
-
*
|
|
19
|
-
* page (`npx tencil start`). Without a running daemon nothing appears.
|
|
34
|
+
* In development: loads the overlay from the Tencil daemon on the machine serving
|
|
35
|
+
* the page (`npx tencil start`). Without a running daemon nothing appears.
|
|
36
|
+
*
|
|
37
|
+
* In a build: nothing, unless TENCIL_CLOUD is set for a preview deployment; then
|
|
38
|
+
* the page loads the overlay from Tencil Cloud.
|
|
20
39
|
*/
|
|
21
40
|
export default function tencil(options?: TencilViteOptions): VitePlugin;
|
|
22
41
|
//#endregion
|
package/dist/vite.mjs
CHANGED
|
@@ -1,17 +1,187 @@
|
|
|
1
|
+
import { n as cloudLoader, r as resolveCloudBuild } from "./cloud-CiwIrP1h.mjs";
|
|
1
2
|
import { n as overlayLoader } from "./loader-BevujQ44.mjs";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
5
|
+
//#region src/integrations/source-attributes.ts
|
|
6
|
+
/** Files whose JSX gets source attributes. */
|
|
7
|
+
const JSX_FILE = /\.[jt]sx$/;
|
|
8
|
+
/** Host elements that never get picked, or must stay untouched. */
|
|
9
|
+
const SKIP = /* @__PURE__ */ new Set([
|
|
10
|
+
"html",
|
|
11
|
+
"head",
|
|
12
|
+
"meta",
|
|
13
|
+
"link",
|
|
14
|
+
"script",
|
|
15
|
+
"style",
|
|
16
|
+
"title",
|
|
17
|
+
"base",
|
|
18
|
+
"noscript",
|
|
19
|
+
"template",
|
|
20
|
+
"slot"
|
|
21
|
+
]);
|
|
22
|
+
/**
|
|
23
|
+
* Tags every host element (`<button>`, not `<Button>`) with where it's written,
|
|
24
|
+
* `data-tencil-src="src/card.tsx:42:7"`, and the component it's in,
|
|
25
|
+
* `data-tencil-component="Card"`. Production builds drop React's dev source
|
|
26
|
+
* info, so this is how a pin on a preview still knows its file and line.
|
|
27
|
+
*
|
|
28
|
+
* Paths are relative to `root`, the repository root, because that's what the
|
|
29
|
+
* cloud agent checks out. Returns undefined when there's nothing to tag or the
|
|
30
|
+
* file doesn't parse (the bundler will report that itself).
|
|
31
|
+
*/
|
|
32
|
+
async function addSourceAttributes(code, id, root) {
|
|
33
|
+
const file = id.replace(/[?#].*$/, "");
|
|
34
|
+
if (!JSX_FILE.test(file) || file.includes(`${sep}node_modules${sep}`) || file.includes("\0")) return;
|
|
35
|
+
const path = relative(root, file).split(sep).join("/");
|
|
36
|
+
if (path.startsWith("..")) return void 0;
|
|
37
|
+
const { parseSync } = await import("oxc-parser");
|
|
38
|
+
const parsed = parseSync(file, code, {
|
|
39
|
+
lang: file.endsWith(".tsx") ? "tsx" : "jsx",
|
|
40
|
+
sourceType: "module"
|
|
41
|
+
});
|
|
42
|
+
if (parsed.errors.length > 0) return void 0;
|
|
43
|
+
const lines = lineStarts(code);
|
|
44
|
+
const inserts = [];
|
|
45
|
+
visit(parsed.program, void 0, (node) => {
|
|
46
|
+
const opening = node;
|
|
47
|
+
const tag = opening.name.type === "JSXIdentifier" ? opening.name.name : void 0;
|
|
48
|
+
if (!tag || !/^[a-z]/.test(tag) || SKIP.has(tag)) return;
|
|
49
|
+
if (opening.attributes.some(isTencilAttribute)) return;
|
|
50
|
+
const { line, column } = position(lines, opening.start);
|
|
51
|
+
return `${path}:${line}:${column}`;
|
|
52
|
+
}, inserts);
|
|
53
|
+
if (inserts.length === 0) return void 0;
|
|
54
|
+
const { default: MagicString } = await import("magic-string");
|
|
55
|
+
const output = new MagicString(code);
|
|
56
|
+
for (const insert of inserts) output.appendLeft(insert.at, insert.text);
|
|
57
|
+
return {
|
|
58
|
+
code: output.toString(),
|
|
59
|
+
map: output.generateMap({
|
|
60
|
+
source: file,
|
|
61
|
+
includeContent: true,
|
|
62
|
+
hires: "boundary"
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Walks the AST, tracking the component each JSX element is written in. */
|
|
67
|
+
function visit(node, component, sourceOf, inserts) {
|
|
68
|
+
let current = component;
|
|
69
|
+
const named = componentName(node);
|
|
70
|
+
if (named) current = named;
|
|
71
|
+
if (node.type === "JSXOpeningElement") {
|
|
72
|
+
const source = sourceOf(node);
|
|
73
|
+
if (source) {
|
|
74
|
+
const name = node.name.end;
|
|
75
|
+
const attributes = [`data-tencil-src={${JSON.stringify(source)}}`];
|
|
76
|
+
if (current) attributes.push(`data-tencil-component={${JSON.stringify(current)}}`);
|
|
77
|
+
inserts.push({
|
|
78
|
+
at: name,
|
|
79
|
+
text: ` ${attributes.join(" ")}`
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const key in node) {
|
|
84
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
85
|
+
const value = node[key];
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
for (const child of value) if (isNode(child)) visit(child, current, sourceOf, inserts);
|
|
88
|
+
} else if (isNode(value)) visit(value, current, sourceOf, inserts);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** `function Card()`, `const Card = () =>`, `const Card = memo(…)`, `class Card`. */
|
|
92
|
+
function componentName(node) {
|
|
93
|
+
let name;
|
|
94
|
+
if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") name = node.id?.name;
|
|
95
|
+
else if (node.type === "VariableDeclarator") {
|
|
96
|
+
const init = node.init;
|
|
97
|
+
if (init && (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression" || init.type === "CallExpression")) name = node.id.name;
|
|
98
|
+
}
|
|
99
|
+
return name && /^[A-Z]/.test(name) ? name : void 0;
|
|
100
|
+
}
|
|
101
|
+
function isTencilAttribute(attribute) {
|
|
102
|
+
const name = attribute.name;
|
|
103
|
+
return attribute.type === "JSXAttribute" && name?.name === "data-tencil-src";
|
|
104
|
+
}
|
|
105
|
+
function isNode(value) {
|
|
106
|
+
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
107
|
+
}
|
|
108
|
+
function lineStarts(code) {
|
|
109
|
+
const starts = [0];
|
|
110
|
+
for (let i = 0; i < code.length; i++) if (code[i] === "\n") starts.push(i + 1);
|
|
111
|
+
return starts;
|
|
112
|
+
}
|
|
113
|
+
/** 1-based line and column of an offset. */
|
|
114
|
+
function position(starts, offset) {
|
|
115
|
+
let low = 0;
|
|
116
|
+
let high = starts.length - 1;
|
|
117
|
+
while (low < high) {
|
|
118
|
+
const middle = low + high + 1 >> 1;
|
|
119
|
+
if (starts[middle] <= offset) low = middle;
|
|
120
|
+
else high = middle - 1;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
line: low + 1,
|
|
124
|
+
column: offset - starts[low] + 1
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const WORKSPACE_FILES = [
|
|
128
|
+
"pnpm-workspace.yaml",
|
|
129
|
+
"turbo.json",
|
|
130
|
+
"nx.json",
|
|
131
|
+
"lerna.json"
|
|
132
|
+
];
|
|
133
|
+
/**
|
|
134
|
+
* The repository a build runs in: the nearest folder with `.git`, else the
|
|
135
|
+
* outermost workspace root (some hosts build without `.git`), else `start`.
|
|
136
|
+
*/
|
|
137
|
+
function repositoryRoot(start) {
|
|
138
|
+
let workspace;
|
|
139
|
+
for (let dir = start;; dir = dirname(dir)) {
|
|
140
|
+
if (existsSync(join(dir, ".git"))) return dir;
|
|
141
|
+
if (WORKSPACE_FILES.some((name) => existsSync(join(dir, name))) || hasWorkspaces(dir)) workspace = dir;
|
|
142
|
+
if (dirname(dir) === dir) return workspace ?? start;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function hasWorkspaces(dir) {
|
|
146
|
+
try {
|
|
147
|
+
return "workspaces" in JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
2
153
|
//#region src/integrations/vite.ts
|
|
3
154
|
/** Vite's dev client, which every dev page loads, whether or not it has an index.html. */
|
|
4
155
|
const VITE_CLIENT = /vite\/dist\/client\/(?:client|bundledDevClient)\.mjs$/;
|
|
5
156
|
/**
|
|
6
|
-
*
|
|
7
|
-
* page (`npx tencil start`). Without a running daemon nothing appears.
|
|
157
|
+
* In development: loads the overlay from the Tencil daemon on the machine serving
|
|
158
|
+
* the page (`npx tencil start`). Without a running daemon nothing appears.
|
|
159
|
+
*
|
|
160
|
+
* In a build: nothing, unless TENCIL_CLOUD is set for a preview deployment; then
|
|
161
|
+
* the page loads the overlay from Tencil Cloud.
|
|
8
162
|
*/
|
|
9
163
|
function tencil(options = {}) {
|
|
10
|
-
const
|
|
164
|
+
const port = options.port ?? Number(process.env.TENCIL_PORT ?? 4747);
|
|
165
|
+
let loader = overlayLoader(port);
|
|
166
|
+
let command = "serve";
|
|
167
|
+
let root = process.cwd();
|
|
11
168
|
return {
|
|
12
169
|
name: "tencil",
|
|
13
|
-
|
|
170
|
+
enforce: "pre",
|
|
171
|
+
apply(_config, env) {
|
|
172
|
+
command = env.command;
|
|
173
|
+
if (command === "serve") return true;
|
|
174
|
+
const cloud = resolveCloudBuild(process.env, options.cloud);
|
|
175
|
+
report(cloud);
|
|
176
|
+
if (cloud.kind !== "on") return false;
|
|
177
|
+
loader = cloudLoader(cloud);
|
|
178
|
+
return true;
|
|
179
|
+
},
|
|
180
|
+
configResolved(config) {
|
|
181
|
+
root = repositoryRoot(config.root);
|
|
182
|
+
},
|
|
14
183
|
transform(code, id) {
|
|
184
|
+
if (command === "build") return addSourceAttributes(code, id, root);
|
|
15
185
|
return VITE_CLIENT.test(id) ? `${code}\n${loader}\n` : void 0;
|
|
16
186
|
},
|
|
17
187
|
transformIndexHtml() {
|
|
@@ -23,5 +193,9 @@ function tencil(options = {}) {
|
|
|
23
193
|
}
|
|
24
194
|
};
|
|
25
195
|
}
|
|
196
|
+
function report(cloud) {
|
|
197
|
+
if (cloud.kind === "refused") console.warn(`[tencil] Not loading Tencil Cloud in this build. ${cloud.reason}`);
|
|
198
|
+
else if (cloud.kind === "on") console.log(`[tencil] Tencil Cloud on for ${cloud.build.repo}@${cloud.build.branch} (${cloud.build.sha.slice(0, 7)}).`);
|
|
199
|
+
}
|
|
26
200
|
//#endregion
|
|
27
201
|
export { tencil as default };
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tencil",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Point at any element of your running app and tell your coding agent what to fix.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Pixel Perfect Agency",
|
|
7
7
|
"homepage": "https://tencil.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/
|
|
10
|
+
"url": "git+https://github.com/tencildev/tencil.git",
|
|
11
11
|
"directory": "packages/tencil"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/
|
|
14
|
+
"url": "https://github.com/tencildev/tencil/issues"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"agent",
|
|
@@ -45,6 +45,11 @@
|
|
|
45
45
|
"types": "./dist/react.d.mts",
|
|
46
46
|
"default": "./dist/react.mjs"
|
|
47
47
|
},
|
|
48
|
+
"./next": {
|
|
49
|
+
"types": "./dist/next.d.mts",
|
|
50
|
+
"default": "./dist/next.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./next-loader": "./dist/next-loader.cjs",
|
|
48
53
|
"./overlay.js": "./dist/overlay.global.js",
|
|
49
54
|
"./package.json": "./package.json"
|
|
50
55
|
},
|
|
@@ -60,6 +65,8 @@
|
|
|
60
65
|
"node": ">=22"
|
|
61
66
|
},
|
|
62
67
|
"dependencies": {
|
|
68
|
+
"magic-string": "^1.4.3",
|
|
69
|
+
"oxc-parser": "^0.153.0",
|
|
63
70
|
"picocolors": "^1.1.1",
|
|
64
71
|
"ws": "^8.22.0",
|
|
65
72
|
"zod": "^4.6.5"
|
|
@@ -86,12 +93,12 @@
|
|
|
86
93
|
"@types/ws": "^8.18.2",
|
|
87
94
|
"react": "^19.3.0",
|
|
88
95
|
"tsdown": "^0.23.0",
|
|
89
|
-
"@tencildev/bridge": "0.1.0",
|
|
90
96
|
"@tencildev/overlay": "0.0.0",
|
|
91
|
-
"@tencildev/
|
|
97
|
+
"@tencildev/bridge": "0.2.0",
|
|
98
|
+
"@tencildev/protocol": "0.2.0",
|
|
92
99
|
"@tencildev/provider-claude-code": "0.0.0",
|
|
93
100
|
"@tencildev/provider-t3code": "0.0.0",
|
|
94
|
-
"@tencildev/testing": "0.1.
|
|
101
|
+
"@tencildev/testing": "0.1.1",
|
|
95
102
|
"@tencildev/tsconfig": "0.0.0"
|
|
96
103
|
},
|
|
97
104
|
"scripts": {
|