tencil 0.5.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/react.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as TencilCloudOptions } from "./cloud-Ez2olqK0.mjs";
1
+ import { t as TencilCloudOptions } from "./cloud-CIAGUsk2.mjs";
2
2
  //#region src/integrations/react.d.ts
3
3
  /**
4
4
  * Loads the Tencil overlay in development from the daemon on the machine
@@ -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
  /**
@@ -3045,7 +3141,7 @@ function errorMessage(error) {
3045
3141
  }
3046
3142
  //#endregion
3047
3143
  //#region src/version.ts
3048
- const VERSION = "0.5.0";
3144
+ const VERSION = "0.6.0";
3049
3145
  //#endregion
3050
3146
  //#region src/daemon/thread-store.ts
3051
3147
  const StoreFile = z.object({
package/dist/vite.d.mts CHANGED
@@ -1,17 +1,25 @@
1
- import { t as TencilCloudOptions } from "./cloud-Ez2olqK0.mjs";
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 !== "serve") return void 0;
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.5.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",
@@ -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/protocol": "0.1.0",
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.0",
101
+ "@tencildev/testing": "0.1.1",
95
102
  "@tencildev/tsconfig": "0.0.0"
96
103
  },
97
104
  "scripts": {