tencil 0.13.0 → 0.14.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-kfsssyEM.mjs";
1
+ import { t as TencilCloudOptions } from "./cloud-CRDNwbe9.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
@@ -149,6 +149,8 @@ const Preferences = z.object({
149
149
  ]).optional(),
150
150
  shortcuts: Shortcuts.optional()
151
151
  });
152
+ /** The longest instructions a user can save to go with every pin. */
153
+ const CONTEXT_MAX = 1e4;
152
154
  const ClientMessage = z.discriminatedUnion("type", [
153
155
  z.object({
154
156
  type: z.literal("hello"),
@@ -229,7 +231,11 @@ const ClientMessage = z.discriminatedUnion("type", [
229
231
  type: z.literal("settings.update"),
230
232
  provider: z.string().min(1).optional(),
231
233
  batch: z.boolean().optional(),
232
- ruler: z.boolean().optional()
234
+ ruler: z.boolean().optional(),
235
+ /** Instructions for every pin of this project; empty clears them. */
236
+ context: z.string().max(CONTEXT_MAX).optional(),
237
+ /** Instructions for every pin of every project (where the host keeps them). */
238
+ globalContext: z.string().max(CONTEXT_MAX).optional()
233
239
  }),
234
240
  z.object({
235
241
  type: z.literal("model.select"),
@@ -270,7 +276,14 @@ z.object({
270
276
  /** New comments are queued and sent together. */
271
277
  batch: z.boolean(),
272
278
  /** The toolbar offers the ruler: spacing while picking, distances with Alt. */
273
- ruler: z.boolean()
279
+ ruler: z.boolean(),
280
+ /** Instructions that go with every pin of this project; empty when there are none. */
281
+ context: z.string(),
282
+ /**
283
+ * Instructions that go with every pin of every project. Left out where the
284
+ * host has nowhere to keep them; the overlay then doesn't offer them.
285
+ */
286
+ globalContext: z.string().optional()
274
287
  });
275
288
  /**
276
289
  * How the daemon matched the page to its project: an Ensemble thread's dev
@@ -469,6 +482,7 @@ function renderPrompt(input) {
469
482
  ...contextLines(input.pageUrl, input.context)
470
483
  ];
471
484
  if (input.hasScreenshot) lines.push("- A screenshot of the element is attached.");
485
+ lines.push(...instructionLines(input.instructions));
472
486
  return `${input.prompt.trim()}\n\n${CONTEXT_OPEN}\n${lines.join("\n")}\n${CONTEXT_CLOSE}`;
473
487
  }
474
488
  /**
@@ -476,12 +490,13 @@ function renderPrompt(input) {
476
490
  * their pins, then one context block with a section per comment. Stripping
477
491
  * the block leaves the numbered comments.
478
492
  */
479
- function renderBatchPrompt(comments) {
493
+ function renderBatchPrompt(comments, instructions) {
480
494
  const lines = [`The user pinned ${comments.length} comments on elements of their running app (via Tencil). Work through all of them in this workspace, using the context below to locate the code. They're numbered like the pins on the page: refer to them by number (#2) when you report back.`, ...deployedNote(comments.map((comment) => comment.pageUrl))];
481
495
  for (const comment of comments) {
482
496
  lines.push("", `#${comment.number}`, ...contextLines(comment.pageUrl, comment.context));
483
497
  if (comment.screenshots.length > 0) lines.push(`- Screenshot: attached image ${comment.screenshots.join(", ")}`);
484
498
  }
499
+ lines.push(...instructionLines(instructions));
485
500
  return `${comments.map((comment) => `#${comment.number} ${comment.prompt.trim()}`).join("\n\n")}\n\n${CONTEXT_OPEN}\n${lines.join("\n")}\n${CONTEXT_CLOSE}`;
486
501
  }
487
502
  function contextLines(pageUrl, context) {
@@ -502,6 +517,20 @@ function contextLines(pageUrl, context) {
502
517
  return lines;
503
518
  }
504
519
  /**
520
+ * The user's standing instructions, global first, then the project's. They're
521
+ * the user's own words but go inside the block, so the agent reads them as
522
+ * context for the change and the overlay doesn't show them on every pin.
523
+ */
524
+ function instructionLines(instructions = {}) {
525
+ const lines = [];
526
+ const sections = [["The user asks this for every project:", instructions.global], ["The user asks this for this project:", instructions.project]];
527
+ for (const [heading, text] of sections) {
528
+ const trimmed = text?.trim();
529
+ if (trimmed) lines.push("", heading, page$1(trimmed));
530
+ }
531
+ return lines;
532
+ }
533
+ /**
505
534
  * When a pin was made on a deployed site (through the extension) rather than the
506
535
  * local dev server, the agent should know its edit won't show there until it ships,
507
536
  * and that a production build may have no component names or source paths.
@@ -608,6 +637,7 @@ var Bridge = class {
608
637
  #offInfo = () => {};
609
638
  #offDefault;
610
639
  #offSettings;
640
+ #offGlobalContext;
611
641
  constructor(options) {
612
642
  this.#options = options;
613
643
  this.#followDefault();
@@ -626,6 +656,10 @@ var Bridge = class {
626
656
  type: "settings",
627
657
  settings: this.#settings()
628
658
  }));
659
+ this.#offGlobalContext = options.globalContext?.onChange(() => this.#broadcast({
660
+ type: "settings",
661
+ settings: this.#settings()
662
+ })) ?? (() => {});
629
663
  for (const thread of options.store.list()) if (thread.provider.threadId && options.providers.has(thread.provider.id) && !this.#archived(thread.provider)) this.#watch(thread.provider.id, thread.provider.threadId);
630
664
  }
631
665
  connect(client) {
@@ -696,6 +730,12 @@ var Bridge = class {
696
730
  if (message.provider) await providers.setDefault(message.provider);
697
731
  if (message.batch !== void 0) await providers.setBatch(message.batch);
698
732
  if (message.ruler !== void 0) await providers.setRuler(message.ruler);
733
+ if (message.context !== void 0) await providers.setContext(message.context);
734
+ if (message.globalContext !== void 0) {
735
+ const { globalContext } = this.#options;
736
+ if (!globalContext) throw new Error("Instructions for every project aren't saved here");
737
+ await globalContext.set(message.globalContext);
738
+ }
699
739
  return;
700
740
  }
701
741
  case "provider.models": {
@@ -758,6 +798,7 @@ var Bridge = class {
758
798
  this.#offInfo();
759
799
  this.#offDefault();
760
800
  this.#offSettings();
801
+ this.#offGlobalContext();
761
802
  for (const unwatch of this.#watches.values()) unwatch();
762
803
  for (const timer of this.#pendingBroadcast.values()) clearTimeout(timer);
763
804
  await this.#options.store.flush();
@@ -789,7 +830,8 @@ var Bridge = class {
789
830
  prompt: message.prompt,
790
831
  pageUrl: message.pageUrl,
791
832
  context: message.context,
792
- hasScreenshot: message.attachments.length > 0
833
+ hasScreenshot: message.attachments.length > 0,
834
+ instructions: this.#instructions()
793
835
  }),
794
836
  attachments: message.attachments,
795
837
  model: this.#options.providers.modelFor(provider.id)
@@ -863,8 +905,9 @@ var Bridge = class {
863
905
  });
864
906
  const text = drafts.length === 1 ? renderPrompt({
865
907
  ...comments[0],
866
- hasScreenshot: attachments.length > 0
867
- }) : renderBatchPrompt(comments);
908
+ hasScreenshot: attachments.length > 0,
909
+ instructions: this.#instructions()
910
+ }) : renderBatchPrompt(comments, this.#instructions());
868
911
  const now = (/* @__PURE__ */ new Date()).toISOString();
869
912
  const echo = localMessage(stripContext(text), now);
870
913
  for (const { thread } of drafts) this.#update(thread.id, (current) => ({
@@ -941,7 +984,8 @@ var Bridge = class {
941
984
  prompt: message.prompt,
942
985
  pageUrl: message.pageUrl,
943
986
  context: message.context,
944
- hasScreenshot: message.attachments.length > 0
987
+ hasScreenshot: message.attachments.length > 0,
988
+ instructions: this.#instructions()
945
989
  }),
946
990
  attachments: message.attachments
947
991
  });
@@ -1108,7 +1152,16 @@ var Bridge = class {
1108
1152
  providers: providers.choices,
1109
1153
  ...model ? { model } : {},
1110
1154
  batch: providers.batch,
1111
- ruler: providers.ruler
1155
+ ruler: providers.ruler,
1156
+ context: providers.context,
1157
+ ...this.#options.globalContext && { globalContext: this.#options.globalContext.get() }
1158
+ };
1159
+ }
1160
+ /** What the user's settings say goes with every new pin. */
1161
+ #instructions() {
1162
+ return {
1163
+ global: this.#options.globalContext?.get(),
1164
+ project: this.#options.providers.context
1112
1165
  };
1113
1166
  }
1114
1167
  #require(threadId) {
@@ -1212,6 +1265,7 @@ var ProjectProviders = class ProjectProviders {
1212
1265
  #batch = true;
1213
1266
  /** On unless the project turns it off. */
1214
1267
  #ruler = true;
1268
+ #context = "";
1215
1269
  constructor(options) {
1216
1270
  this.#options = options;
1217
1271
  this.choices = options.choices;
@@ -1243,6 +1297,7 @@ var ProjectProviders = class ProjectProviders {
1243
1297
  this.#models = saved.models ?? {};
1244
1298
  this.#batch = saved.batch ?? true;
1245
1299
  this.#ruler = saved.ruler ?? true;
1300
+ this.#context = saved.context ?? "";
1246
1301
  }
1247
1302
  }
1248
1303
  get defaultId() {
@@ -1305,7 +1360,17 @@ var ProjectProviders = class ProjectProviders {
1305
1360
  await this.#save();
1306
1361
  for (const listener of this.#settingsListeners) listener();
1307
1362
  }
1308
- /** Fires when a picked model, batching or the ruler changes. */
1363
+ /** The project's instructions for every pin, empty when there are none. */
1364
+ get context() {
1365
+ return this.#context;
1366
+ }
1367
+ async setContext(context) {
1368
+ if (context === this.#context) return;
1369
+ this.#context = context;
1370
+ await this.#save();
1371
+ for (const listener of this.#settingsListeners) listener();
1372
+ }
1373
+ /** Fires when a picked model, batching, the ruler or the context changes. */
1309
1374
  onSettingsChange(listener) {
1310
1375
  this.#settingsListeners.add(listener);
1311
1376
  return () => this.#settingsListeners.delete(listener);
@@ -1323,7 +1388,8 @@ var ProjectProviders = class ProjectProviders {
1323
1388
  provider: this.#chosen,
1324
1389
  models: this.#models,
1325
1390
  batch: this.#batch,
1326
- ruler: this.#ruler
1391
+ ruler: this.#ruler,
1392
+ ...this.#context ? { context: this.#context } : {}
1327
1393
  });
1328
1394
  }
1329
1395
  };
@@ -5359,7 +5425,7 @@ function errorMessage(error) {
5359
5425
  }
5360
5426
  //#endregion
5361
5427
  //#region src/version.ts
5362
- const VERSION = "0.13.0";
5428
+ const VERSION = "0.14.0";
5363
5429
  //#endregion
5364
5430
  //#region src/daemon/thread-store.ts
5365
5431
  const StoreFile = z.object({
@@ -5481,29 +5547,43 @@ const providerLabel = (id) => PROVIDER_OPTIONS.find((option) => option.id === id
5481
5547
  const SettingsFile$1 = z.object({
5482
5548
  version: z.literal(1),
5483
5549
  /** The agent of projects that haven't picked one in the overlay. */
5484
- provider: z.enum(PROVIDERS).optional()
5550
+ provider: z.enum(PROVIDERS).optional(),
5551
+ /** Instructions that go with every pin of every project. */
5552
+ context: z.string().optional()
5485
5553
  });
5486
5554
  const settingsPath = (dataDir) => join(dataDir, "settings.json");
5487
- /** The agent chosen for this machine (by setup or `--provider`), if any. */
5488
- async function savedProvider(dataDir = defaultDataDir()) {
5555
+ /** This machine's settings; empty when there are none or the file is broken. */
5556
+ async function readSettings(dataDir = defaultDataDir()) {
5489
5557
  const raw = await readFile(settingsPath(dataDir), "utf8").catch(() => void 0);
5490
- if (raw === void 0) return void 0;
5558
+ if (raw === void 0) return {};
5491
5559
  try {
5492
5560
  const parsed = SettingsFile$1.safeParse(JSON.parse(raw));
5493
- return parsed.success ? parsed.data.provider : void 0;
5561
+ if (!parsed.success) return {};
5562
+ const { version: _, ...settings } = parsed.data;
5563
+ return settings;
5494
5564
  } catch {
5495
- return;
5565
+ return {};
5496
5566
  }
5497
5567
  }
5498
- async function saveProvider(provider, dataDir = defaultDataDir()) {
5568
+ /** Merges `changes` into the saved settings; an undefined value removes that setting. */
5569
+ async function writeSettings(changes, dataDir = defaultDataDir()) {
5499
5570
  const path = settingsPath(dataDir);
5500
- await mkdir(dirname(path), { recursive: true });
5501
- await writeFile(`${path}.tmp`, `${JSON.stringify({
5571
+ const next = {
5502
5572
  version: 1,
5503
- provider
5504
- }, null, 2)}\n`);
5573
+ ...await readSettings(dataDir),
5574
+ ...changes
5575
+ };
5576
+ await mkdir(dirname(path), { recursive: true });
5577
+ await writeFile(`${path}.tmp`, `${JSON.stringify(next, null, 2)}\n`);
5505
5578
  await rename(`${path}.tmp`, path);
5506
5579
  }
5580
+ /** The agent chosen for this machine (by setup or `--provider`), if any. */
5581
+ async function savedProvider(dataDir = defaultDataDir()) {
5582
+ return (await readSettings(dataDir)).provider;
5583
+ }
5584
+ async function saveProvider(provider, dataDir = defaultDataDir()) {
5585
+ await writeSettings({ provider }, dataDir);
5586
+ }
5507
5587
  /**
5508
5588
  * Which agents this machine has: a paired or running T3 Code, an installed
5509
5589
  * Claude Code, Codex's CLI or desktop app, a running Ensemble app.
@@ -5733,6 +5813,40 @@ function escapeHtml(text) {
5733
5813
  })[char] ?? char);
5734
5814
  }
5735
5815
  //#endregion
5816
+ //#region src/daemon/global-context.ts
5817
+ /**
5818
+ * The instructions that go with every pin of every project on this machine,
5819
+ * kept as `context` in `settings.json` next to the machine's agent. One per
5820
+ * daemon, shared by every project's bridge.
5821
+ */
5822
+ var FileGlobalContext = class {
5823
+ dataDir;
5824
+ #context = "";
5825
+ #listeners = /* @__PURE__ */ new Set();
5826
+ /** Saves run one after another, so a quick second change can't land first. */
5827
+ #writing = Promise.resolve();
5828
+ constructor(dataDir = defaultDataDir()) {
5829
+ this.dataDir = dataDir;
5830
+ }
5831
+ async load() {
5832
+ this.#context = (await readSettings(this.dataDir)).context ?? "";
5833
+ }
5834
+ get() {
5835
+ return this.#context;
5836
+ }
5837
+ async set(context) {
5838
+ if (context === this.#context) return;
5839
+ this.#context = context;
5840
+ for (const listener of this.#listeners) listener();
5841
+ this.#writing = this.#writing.then(() => writeSettings({ context: context || void 0 }, this.dataDir)).catch(() => {});
5842
+ await this.#writing;
5843
+ }
5844
+ onChange(listener) {
5845
+ this.#listeners.add(listener);
5846
+ return () => this.#listeners.delete(listener);
5847
+ }
5848
+ };
5849
+ //#endregion
5736
5850
  //#region src/daemon/preferences.ts
5737
5851
  const PreferencesFile = Preferences.extend({ version: z.literal(1) });
5738
5852
  function preferencesPath(dataDir = defaultDataDir()) {
@@ -5793,13 +5907,15 @@ const SettingsFile = z.object({
5793
5907
  /** Queue new comments and send them together. */
5794
5908
  batch: z.boolean().optional(),
5795
5909
  /** Offer the ruler in the overlay's toolbar. */
5796
- ruler: z.boolean().optional()
5910
+ ruler: z.boolean().optional(),
5911
+ /** Instructions that go with every pin of this project. */
5912
+ context: z.string().optional()
5797
5913
  });
5798
5914
  /** A project's settings live next to its pins: `<slug>-<hash>.settings.json`. */
5799
5915
  function projectSettingsPath(projectRoot, dataDir = defaultDataDir()) {
5800
5916
  return projectStorePath(projectRoot, dataDir).replace(/\.json$/, ".settings.json");
5801
5917
  }
5802
- /** A project's overlay settings (provider, models, batching, ruler) in a JSON file. */
5918
+ /** A project's overlay settings (provider, models, batching, ruler, context) in a JSON file. */
5803
5919
  var FileProjectSettings = class {
5804
5920
  path;
5805
5921
  constructor(path) {
@@ -5818,7 +5934,8 @@ var FileProjectSettings = class {
5818
5934
  provider: settings.provider,
5819
5935
  models: settings.models,
5820
5936
  batch: settings.batch,
5821
- ruler: settings.ruler
5937
+ ruler: settings.ruler,
5938
+ context: settings.context
5822
5939
  }, null, 2)}\n`);
5823
5940
  await rename(temp, this.path);
5824
5941
  }
@@ -6714,6 +6831,8 @@ async function startDaemon(options = {}) {
6714
6831
  const overlayPath = resolveOverlayPath();
6715
6832
  let updater;
6716
6833
  const preferences = new FilePreferences(preferencesPath(dataDir));
6834
+ const globalContext = new FileGlobalContext(dataDir);
6835
+ const globalContextLoaded = globalContext.load();
6717
6836
  const claudeCodeDir = join(dataDir, "claude-code");
6718
6837
  const t3Url = options.t3?.url ?? process.env.TENCIL_T3_URL;
6719
6838
  const createProvider = options.createProvider ?? ((root, id) => {
@@ -6760,7 +6879,11 @@ async function startDaemon(options = {}) {
6760
6879
  settings: new FileProjectSettings(projectSettingsPath(key, dataDir))
6761
6880
  });
6762
6881
  const store = new FileThreadStore(key, dataDir);
6763
- await Promise.all([store.load(), providers.load()]);
6882
+ await Promise.all([
6883
+ store.load(),
6884
+ providers.load(),
6885
+ globalContextLoaded
6886
+ ]);
6764
6887
  const bridge = new Bridge({
6765
6888
  providers,
6766
6889
  store,
@@ -6770,6 +6893,7 @@ async function startDaemon(options = {}) {
6770
6893
  },
6771
6894
  version: VERSION,
6772
6895
  update: () => updater?.status() ?? { state: "idle" },
6896
+ globalContext,
6773
6897
  log: (message) => log(`[${basename(key)}] ${message}`)
6774
6898
  });
6775
6899
  log(`Serving ${key} with ${providers.default().label}`);
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as TencilCloudOptions } from "./cloud-kfsssyEM.mjs";
1
+ import { t as TencilCloudOptions } from "./cloud-CRDNwbe9.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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tencil",
3
- "version": "0.13.0",
3
+ "version": "0.14.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",
@@ -94,14 +94,14 @@
94
94
  "@types/ws": "^8.18.2",
95
95
  "react": "^19.3.0",
96
96
  "tsdown": "^0.23.0",
97
+ "@tencildev/bridge": "0.6.0",
97
98
  "@tencildev/overlay": "0.0.0",
98
- "@tencildev/protocol": "0.7.0",
99
+ "@tencildev/protocol": "0.8.0",
99
100
  "@tencildev/provider-claude-code": "0.0.0",
100
- "@tencildev/bridge": "0.5.2",
101
101
  "@tencildev/provider-codex": "0.0.0",
102
102
  "@tencildev/provider-ensemble": "0.0.0",
103
103
  "@tencildev/provider-t3code": "0.0.0",
104
- "@tencildev/testing": "0.4.1",
104
+ "@tencildev/testing": "0.4.2",
105
105
  "@tencildev/tsconfig": "0.0.0"
106
106
  },
107
107
  "scripts": {