tencil 0.5.0 → 0.6.1
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 +50 -3
- package/dist/{cloud-Ez2olqK0.d.mts → cloud-CIAGUsk2.d.mts} +1 -1
- package/dist/{index-DzR4m_IL.d.mts → index-B0phpEz9.d.mts} +114 -1
- package/dist/index.d.mts +3 -1
- 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 +155 -30
- package/dist/react.d.mts +1 -1
- package/dist/{server-DZUEgjla.mjs → server-CbF3t-Cx.mjs} +134 -13
- package/dist/vite.d.mts +10 -2
- package/dist/vite.mjs +156 -1
- package/package.json +11 -4
package/dist/react.d.mts
CHANGED
|
@@ -81,7 +81,9 @@ const ClientMessage = z.discriminatedUnion("type", [
|
|
|
81
81
|
type: z.literal("hello"),
|
|
82
82
|
protocol: z.literal(1),
|
|
83
83
|
pageUrl: z.string(),
|
|
84
|
-
build: BuildInfo.optional()
|
|
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()
|
|
85
87
|
}),
|
|
86
88
|
z.object({
|
|
87
89
|
type: z.literal("thread.create"),
|
|
@@ -219,6 +221,66 @@ const ThreadMessage = z.object({
|
|
|
219
221
|
createdAt: z.string()
|
|
220
222
|
});
|
|
221
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
|
+
/**
|
|
222
284
|
* A conversation Tencil tracks, backed by one provider thread. Owned and
|
|
223
285
|
* persisted by the bridge. Pinned threads sit on an element of a page;
|
|
224
286
|
* threads opened from the provider's list have no anchor and live in the dock.
|
|
@@ -240,6 +302,10 @@ const Thread = z.object({
|
|
|
240
302
|
/** Deep link into the provider UI, when it has one. */
|
|
241
303
|
url: z.string().optional()
|
|
242
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(),
|
|
243
309
|
createdAt: z.string(),
|
|
244
310
|
updatedAt: z.string()
|
|
245
311
|
});
|
|
@@ -311,15 +377,15 @@ function renderBatchPrompt(comments) {
|
|
|
311
377
|
return `${comments.map((comment) => `#${comment.number} ${comment.prompt.trim()}`).join("\n\n")}\n\n${CONTEXT_OPEN}\n${lines.join("\n")}\n${CONTEXT_CLOSE}`;
|
|
312
378
|
}
|
|
313
379
|
function contextLines(pageUrl, context) {
|
|
314
|
-
const lines = [`- Page: ${pageUrl}`, `- Element: \`${oneLine(context.html)}\``];
|
|
380
|
+
const lines = [`- Page: ${page(pageUrl)}`, `- Element: \`${page(truncate(oneLine(context.html), 2e3))}\``];
|
|
315
381
|
const [component, ...owners] = context.components;
|
|
316
382
|
if (component) {
|
|
317
383
|
const chain = [component, ...owners.slice(0, 4)].map(formatFrame).join(" ← ");
|
|
318
|
-
lines.push(`- Component: ${chain}`);
|
|
384
|
+
lines.push(`- Component: ${page(chain)}`);
|
|
319
385
|
}
|
|
320
|
-
lines.push(`- Selector: \`${context.selector}\``);
|
|
321
|
-
if (context.text) lines.push(`- Visible text: "${truncate(oneLine(context.text), 200)}"`);
|
|
322
|
-
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))}"`);
|
|
323
389
|
const { rect, viewport } = context;
|
|
324
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`);
|
|
325
391
|
return lines;
|
|
@@ -341,6 +407,14 @@ function formatFrame(frame) {
|
|
|
341
407
|
const position = [frame.source.line, frame.source.column].filter((n) => n != null).join(":");
|
|
342
408
|
return `${frame.name} (${frame.source.file}${position ? `:${position}` : ""})`;
|
|
343
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
|
+
}
|
|
344
418
|
function oneLine(text) {
|
|
345
419
|
return text.replace(/\s+/g, " ").trim();
|
|
346
420
|
}
|
|
@@ -411,7 +485,8 @@ var Bridge = class {
|
|
|
411
485
|
project: this.#options.project,
|
|
412
486
|
provider: this.#provider().info(),
|
|
413
487
|
settings: this.#settings(),
|
|
414
|
-
threads: this.#options.store.list()
|
|
488
|
+
threads: this.#options.store.list(),
|
|
489
|
+
...client.viewer && { viewer: client.viewer }
|
|
415
490
|
});
|
|
416
491
|
return;
|
|
417
492
|
case "thread.create":
|
|
@@ -743,6 +818,7 @@ var Bridge = class {
|
|
|
743
818
|
resolved: false,
|
|
744
819
|
status: "working",
|
|
745
820
|
statusDetail: void 0,
|
|
821
|
+
steps: void 0,
|
|
746
822
|
messages: [...current.messages, localMessage(message.text, (/* @__PURE__ */ new Date()).toISOString())]
|
|
747
823
|
}));
|
|
748
824
|
await this.#providerOf(thread).sendMessage({
|
|
@@ -771,6 +847,11 @@ var Bridge = class {
|
|
|
771
847
|
status,
|
|
772
848
|
statusDetail
|
|
773
849
|
})),
|
|
850
|
+
delivery: (delivery) => each((thread) => ({
|
|
851
|
+
...thread,
|
|
852
|
+
delivery
|
|
853
|
+
})),
|
|
854
|
+
step: (step) => each((thread) => mergeStep(thread, step)),
|
|
774
855
|
gone: () => each((thread) => ({
|
|
775
856
|
...thread,
|
|
776
857
|
status: "error",
|
|
@@ -882,6 +963,21 @@ function mergeMessage(thread, incoming) {
|
|
|
882
963
|
messages
|
|
883
964
|
};
|
|
884
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
|
+
}
|
|
885
981
|
//#endregion
|
|
886
982
|
//#region ../bridge/src/project-providers.ts
|
|
887
983
|
/**
|
|
@@ -2303,6 +2399,15 @@ async function persist(socket, threadId, messageId, attachments) {
|
|
|
2303
2399
|
}))
|
|
2304
2400
|
})).attachments;
|
|
2305
2401
|
}
|
|
2402
|
+
/** Requests the user answers; T3 Code resolves `auth_refresh` and `dynamic_tool_call` itself. */
|
|
2403
|
+
const USER_REQUEST_KINDS = /* @__PURE__ */ new Set([
|
|
2404
|
+
"command",
|
|
2405
|
+
"file-read",
|
|
2406
|
+
"file-change",
|
|
2407
|
+
"mcp-elicitation",
|
|
2408
|
+
"permission",
|
|
2409
|
+
"user_input"
|
|
2410
|
+
]);
|
|
2306
2411
|
const ACTIVE_RUN_STATUSES = /* @__PURE__ */ new Set([
|
|
2307
2412
|
"preparing",
|
|
2308
2413
|
"starting",
|
|
@@ -2311,6 +2416,7 @@ const ACTIVE_RUN_STATUSES = /* @__PURE__ */ new Set([
|
|
|
2311
2416
|
]);
|
|
2312
2417
|
var V2ThreadTracker = class {
|
|
2313
2418
|
#runs = /* @__PURE__ */ new Map();
|
|
2419
|
+
#requests = /* @__PURE__ */ new Map();
|
|
2314
2420
|
#messages = /* @__PURE__ */ new Map();
|
|
2315
2421
|
#lastStatusKey = "";
|
|
2316
2422
|
apply(raw) {
|
|
@@ -2319,6 +2425,7 @@ var V2ThreadTracker = class {
|
|
|
2319
2425
|
let gone = false;
|
|
2320
2426
|
if (item.kind === "snapshot") {
|
|
2321
2427
|
for (const run of item.projection.runs ?? []) this.#runs.set(run.id, run);
|
|
2428
|
+
for (const request of item.projection.runtimeRequests ?? []) this.#requests.set(request.id, request);
|
|
2322
2429
|
for (const message of item.projection.messages ?? []) this.#upsertMessage(message, changed);
|
|
2323
2430
|
for (const turnItem of item.projection.turnItems ?? []) this.#upsertTurnItem(turnItem, changed);
|
|
2324
2431
|
} else if (item.kind === "event") {
|
|
@@ -2326,6 +2433,9 @@ var V2ThreadTracker = class {
|
|
|
2326
2433
|
if (type === "run.created" || type === "run.updated") {
|
|
2327
2434
|
const run = payload;
|
|
2328
2435
|
this.#runs.set(run.id, run);
|
|
2436
|
+
} else if (type === "runtime-request.updated") {
|
|
2437
|
+
const request = payload;
|
|
2438
|
+
this.#requests.set(request.id, request);
|
|
2329
2439
|
} else if (type === "message.updated") this.#upsertMessage(payload, changed);
|
|
2330
2440
|
else if (type === "turn-item.updated") this.#upsertTurnItem(payload, changed);
|
|
2331
2441
|
else if (type === "thread.deleted") gone = true;
|
|
@@ -2347,11 +2457,8 @@ var V2ThreadTracker = class {
|
|
|
2347
2457
|
case "preparing":
|
|
2348
2458
|
case "queued":
|
|
2349
2459
|
case "starting":
|
|
2350
|
-
case "running":
|
|
2351
|
-
case "waiting": return {
|
|
2352
|
-
status: "waiting",
|
|
2353
|
-
detail: "Waiting for approval in T3 Code"
|
|
2354
|
-
};
|
|
2460
|
+
case "running":
|
|
2461
|
+
case "waiting": return this.#pendingRequest(latest) ?? { status: "working" };
|
|
2355
2462
|
case "failed": return {
|
|
2356
2463
|
status: "error",
|
|
2357
2464
|
detail: "Run failed"
|
|
@@ -2372,6 +2479,20 @@ var V2ThreadTracker = class {
|
|
|
2372
2479
|
}
|
|
2373
2480
|
return active?.id;
|
|
2374
2481
|
}
|
|
2482
|
+
/**
|
|
2483
|
+
* Approvals and questions don't change the run's status; they're runtime requests.
|
|
2484
|
+
* A stopped run can leave one pending, so only count those made during `run`.
|
|
2485
|
+
*/
|
|
2486
|
+
#pendingRequest(run) {
|
|
2487
|
+
for (const request of this.#requests.values()) {
|
|
2488
|
+
if (request.status !== "pending" || !USER_REQUEST_KINDS.has(request.kind)) continue;
|
|
2489
|
+
if (run.requestedAt && request.createdAt && request.createdAt < run.requestedAt) continue;
|
|
2490
|
+
return {
|
|
2491
|
+
status: "waiting",
|
|
2492
|
+
detail: request.kind === "user_input" ? "Waiting for your answer in T3 Code" : "Waiting for approval in T3 Code"
|
|
2493
|
+
};
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2375
2496
|
#latestRun() {
|
|
2376
2497
|
let latest;
|
|
2377
2498
|
for (const run of this.#runs.values()) if (!latest || run.ordinal > latest.ordinal) latest = run;
|
|
@@ -3045,7 +3166,7 @@ function errorMessage(error) {
|
|
|
3045
3166
|
}
|
|
3046
3167
|
//#endregion
|
|
3047
3168
|
//#region src/version.ts
|
|
3048
|
-
const VERSION = "0.
|
|
3169
|
+
const VERSION = "0.6.1";
|
|
3049
3170
|
//#endregion
|
|
3050
3171
|
//#region src/daemon/thread-store.ts
|
|
3051
3172
|
const StoreFile = z.object({
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { t as TencilCloudOptions } from "./cloud-
|
|
1
|
+
import { t as TencilCloudOptions } from "./cloud-CIAGUsk2.mjs";
|
|
2
2
|
//#region src/integrations/vite.d.ts
|
|
3
3
|
/** Structural subset of Vite's Plugin type, so `vite` stays an optional peer. */
|
|
4
4
|
interface VitePlugin {
|
|
5
5
|
name: string;
|
|
6
|
+
/** Before the React plugin compiles JSX, so source attributes can be added. */
|
|
7
|
+
enforce: 'pre';
|
|
6
8
|
apply(config: unknown, env: {
|
|
7
9
|
command: 'build' | 'serve';
|
|
8
10
|
}): boolean;
|
|
11
|
+
configResolved(config: {
|
|
12
|
+
root: string;
|
|
13
|
+
}): void;
|
|
9
14
|
transformIndexHtml(): Array<{
|
|
10
15
|
tag: string;
|
|
11
16
|
children: string;
|
|
12
17
|
injectTo: 'body';
|
|
13
18
|
}>;
|
|
14
|
-
transform(code: string, id: string): string | undefined
|
|
19
|
+
transform(code: string, id: string): string | undefined | Promise<{
|
|
20
|
+
code: string;
|
|
21
|
+
map: unknown;
|
|
22
|
+
} | undefined>;
|
|
15
23
|
}
|
|
16
24
|
export interface TencilViteOptions {
|
|
17
25
|
/** Port of the Tencil daemon. Defaults to TENCIL_PORT or 4747. */
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,155 @@
|
|
|
1
1
|
import { n as cloudLoader, r as resolveCloudBuild } from "./cloud-CiwIrP1h.mjs";
|
|
2
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
|
|
3
153
|
//#region src/integrations/vite.ts
|
|
4
154
|
/** Vite's dev client, which every dev page loads, whether or not it has an index.html. */
|
|
5
155
|
const VITE_CLIENT = /vite\/dist\/client\/(?:client|bundledDevClient)\.mjs$/;
|
|
@@ -14,8 +164,10 @@ function tencil(options = {}) {
|
|
|
14
164
|
const port = options.port ?? Number(process.env.TENCIL_PORT ?? 4747);
|
|
15
165
|
let loader = overlayLoader(port);
|
|
16
166
|
let command = "serve";
|
|
167
|
+
let root = process.cwd();
|
|
17
168
|
return {
|
|
18
169
|
name: "tencil",
|
|
170
|
+
enforce: "pre",
|
|
19
171
|
apply(_config, env) {
|
|
20
172
|
command = env.command;
|
|
21
173
|
if (command === "serve") return true;
|
|
@@ -25,8 +177,11 @@ function tencil(options = {}) {
|
|
|
25
177
|
loader = cloudLoader(cloud);
|
|
26
178
|
return true;
|
|
27
179
|
},
|
|
180
|
+
configResolved(config) {
|
|
181
|
+
root = repositoryRoot(config.root);
|
|
182
|
+
},
|
|
28
183
|
transform(code, id) {
|
|
29
|
-
if (command
|
|
184
|
+
if (command === "build") return addSourceAttributes(code, id, root);
|
|
30
185
|
return VITE_CLIENT.test(id) ? `${code}\n${loader}\n` : void 0;
|
|
31
186
|
},
|
|
32
187
|
transformIndexHtml() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tencil",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
|
@@ -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.
|
|
96
|
+
"@tencildev/bridge": "0.2.0",
|
|
97
|
+
"@tencildev/protocol": "0.2.0",
|
|
90
98
|
"@tencildev/overlay": "0.0.0",
|
|
91
|
-
"@tencildev/protocol": "0.1.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": {
|