pi-pocket 0.26.0 → 0.27.0-beta.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.
@@ -22,6 +22,7 @@ import {
22
22
  import { join } from "node:path";
23
23
  import { Type } from "@earendil-works/pi-ai";
24
24
  import { defineTool, type ToolRegistration } from "@earendil-works/pi-durable";
25
+ import { checkTokensBlock, scanReport, scanRoot, scanTokens } from "./scan.ts";
25
26
 
26
27
  /** The file's path, in the session's working directory. */
27
28
  export const SYSTEM_FILE = join(".pi", "design-system.md");
@@ -181,11 +182,21 @@ export function writeDesignSystemText(cwd: string, content: string): number {
181
182
  export function designSystemTool(): ToolRegistration {
182
183
  return defineTool({
183
184
  name: "design_system",
184
- description: `The project's design system: ${SYSTEM_FILE} in the session's folder, with the design tokens as a fenced JSON block, then the components and rules for new designs. Use read before you make or change a design; use write (content replaces the file) after you read the codebase or the brand files the person points at.`,
185
+ description: `The project's design system: ${SYSTEM_FILE} in the session's folder, with the design tokens as a fenced JSON block, then the components and rules for new designs. Use read before you make or change a design. Use scan to draft one from the project's style files (colors, fonts, radii, CSS variables; it saves nothing). Use write (content replaces the file) after you check the draft or read the brand files the person points at; a tokens block that is not valid JSON is refused.`,
185
186
  parameters: Type.Object({
186
- action: Type.Union([Type.Literal("read"), Type.Literal("write")], {
187
- description: "read the file, or write over it",
188
- }),
187
+ action: Type.Union(
188
+ [Type.Literal("read"), Type.Literal("write"), Type.Literal("scan")],
189
+ {
190
+ description:
191
+ "read the file, write over it, or scan the project's styles for a draft",
192
+ },
193
+ ),
194
+ path: Type.Optional(
195
+ Type.String({
196
+ description:
197
+ "scan: a folder inside the session's folder to scan (default: the whole folder)",
198
+ }),
199
+ ),
189
200
  content: Type.Optional(
190
201
  Type.String({
191
202
  description: `write: the new file, up to ${MAX_BYTES} bytes`,
@@ -203,18 +214,26 @@ export function designSystemTool(): ToolRegistration {
203
214
  );
204
215
  }
205
216
 
217
+ if (args.action === "scan") {
218
+ const draft = scanReport(scanTokens(scanRoot(cwd, args.path)));
219
+
220
+ return { output: [{ type: "text" as const, text: draft }] };
221
+ }
222
+
206
223
  if (args.action === "write") {
207
224
  if (args.content === undefined) {
208
225
  throw new Error("write needs the new design system in content.");
209
226
  }
210
227
 
228
+ // A broken tokens block is refused before anything is written.
229
+ const hasTokens = checkTokensBlock(args.content);
211
230
  const size = writeDesignSystemText(cwd, args.content);
212
231
 
213
232
  return {
214
233
  output: [
215
234
  {
216
235
  type: "text" as const,
217
- text: `Wrote ${SYSTEM_FILE} (${size} bytes). The next design request reads it.`,
236
+ text: `Wrote ${SYSTEM_FILE} (${size} bytes). The next design request reads it.${hasTokens ? "" : " It has no fenced JSON tokens block; add one so designs can read the tokens."}`,
218
237
  },
219
238
  ],
220
239
  };
@@ -227,7 +246,7 @@ export function designSystemTool(): ToolRegistration {
227
246
  output: [
228
247
  {
229
248
  type: "text" as const,
230
- text: `There is no ${SYSTEM_FILE} in this session yet. Read the codebase or the brand files the person points at, then write the design system: the design tokens as a fenced JSON block, then the components and rules for new designs.`,
249
+ text: `There is no ${SYSTEM_FILE} in this session yet. Run design_system scan for a draft from the project's styles, or read the brand files the person points at, then write the design system: the design tokens as a fenced JSON block, then the components and rules for new designs.`,
231
250
  },
232
251
  ],
233
252
  };
@@ -55,6 +55,13 @@ function ago(at) {
55
55
  return `${Math.round(hours / 24)} days ago`;
56
56
  }
57
57
 
58
+ /** A version of the beta channel: `0.27.0-beta.1`. */
59
+ const isBeta = (version) => typeof version === "string" && version.includes("-");
60
+
61
+ /** "0.27.0-beta.1 (beta)": a beta is marked wherever its version shows. */
62
+ const named = (release) =>
63
+ release.beta || isBeta(release.version) ? `${release.version} (beta)` : release.version;
64
+
58
65
  export default function setup(pocket) {
59
66
  const { html, useEffect, useState } = pocket;
60
67
 
@@ -125,13 +132,13 @@ export default function setup(pocket) {
125
132
 
126
133
  const hint =
127
134
  next.step ??
128
- (next.available && next.latest ? `${next.latest.version} is out` : undefined);
135
+ (next.available && next.latest ? `${named(next.latest)} is out` : undefined);
129
136
 
130
137
  menu.update({ hint });
131
138
  launcher.update(
132
139
  next.available && next.latest
133
140
  ? {
134
- label: `Update Pi Pocket to ${next.latest.version}`,
141
+ label: `Update Pi Pocket to ${named(next.latest)}`,
135
142
  detail: "See what is new, and update",
136
143
  }
137
144
  : { label: "Update Pi Pocket", detail: "Check for a new version of Pi Pocket" },
@@ -141,7 +148,7 @@ export default function setup(pocket) {
141
148
  remember(TOLD, next.latest.version);
142
149
  pocket.notify(
143
150
  "info",
144
- `Pi Pocket ${next.latest.version} is out: Menu → Update Pi Pocket.`,
151
+ `Pi Pocket ${named(next.latest)} is out: Menu → Update Pi Pocket.`,
145
152
  );
146
153
  }
147
154
 
@@ -276,8 +283,17 @@ export default function setup(pocket) {
276
283
  <div class="updates-card">
277
284
  <div class="updates-row">
278
285
  <div>
279
- <div class="updates-title">Pi Pocket ${current.version}</div>
286
+ <div class="updates-title">
287
+ Pi Pocket ${current.version}
288
+ ${
289
+ isBeta(current.version) &&
290
+ html` <span class="updates-badge">Beta</span>`
291
+ }
292
+ </div>
280
293
  ${where && html`<div class="muted small mono">${where}</div>`}
294
+ <div class="muted small">
295
+ ${current.beta ? "Beta updates are on." : "Stable releases only."}
296
+ </div>
281
297
  </div>
282
298
  <button
283
299
  class="button"
@@ -298,7 +314,7 @@ export default function setup(pocket) {
298
314
  current.error
299
315
  ? "Could not check."
300
316
  : current.available
301
- ? `${latest.version} is out.`
317
+ ? `${named(latest)} is out.`
302
318
  : latest
303
319
  ? "This is the newest version."
304
320
  : current.checkedAt
@@ -334,7 +350,13 @@ export default function setup(pocket) {
334
350
  current.available &&
335
351
  html`<div class="updates-card updates-new">
336
352
  <div class="updates-row">
337
- <div class="updates-title">${latest.name}</div>
353
+ <div class="updates-title">
354
+ ${latest.name}
355
+ ${
356
+ (latest.beta || isBeta(latest.version)) &&
357
+ html` <span class="updates-badge">Beta</span>`
358
+ }
359
+ </div>
338
360
  ${
339
361
  latest.url &&
340
362
  html`<a
@@ -411,15 +433,15 @@ export default function setup(pocket) {
411
433
  disabled=${current.blockers.length > 0 || (careful && !confirmed)}
412
434
  onClick=${update}
413
435
  >
414
- Update to ${latest.version} and restart
436
+ Update to ${named(latest)} and restart
415
437
  </button>`
416
438
  }
417
439
  </div>`
418
440
  }
419
441
  ${!current.available && error && html`<div class="error-box">${error}</div>`}
420
442
  <p class="muted small">
421
- To look for new versions, or install them by themselves, open Menu → Extensions →
422
- Installed → Pi Pocket updates.
443
+ To look for new versions, install them by themselves, or turn Beta updates on or
444
+ off, open Menu → Extensions → Installed → Pi Pocket updates.
423
445
  </p>
424
446
  </div>`;
425
447
  }
@@ -118,3 +118,14 @@
118
118
  min-height: 40px;
119
119
  flex: none;
120
120
  }
121
+
122
+ .updates-badge {
123
+ display: inline-block;
124
+ padding: 0 6px;
125
+ border: 1px solid var(--warn);
126
+ border-radius: 999px;
127
+ color: var(--warn);
128
+ font-size: 0.75em;
129
+ font-weight: 600;
130
+ vertical-align: middle;
131
+ }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Updates of Pi Pocket itself: it looks for a new release every 6 hours, tells the owner, shows its notes, and updates
3
3
  * the git checkout or the global npm install to it with one tap, then restarts; it can also install new releases by itself while no session is
4
- * working. Its routes and screens are the owner's alone (`updates.ts` does the work).
4
+ * working. The owner can opt in to beta releases (pre-releases such as `0.27.0-beta.1`). Its routes and screens are
5
+ * the owner's alone (`updates.ts` does the work).
5
6
  */
6
7
  import { defineExtension } from "@earendil-works/pi-durable";
7
8
  import type { ExtensionWeb, PocketHost, WebHandler, WebRequest } from "../host.ts";
@@ -63,6 +64,14 @@ export default function createUpdates(host: PocketHost, web: ExtensionWeb) {
63
64
  type: "boolean",
64
65
  default: false,
65
66
  },
67
+ {
68
+ name: "beta",
69
+ label: "Beta updates",
70
+ description:
71
+ "Also offer beta versions (such as 0.27.0-beta.1) before the stable release. A beta can be less tested. Off keeps stable releases only; a beta then still gets the next stable release.",
72
+ type: "boolean",
73
+ default: false,
74
+ },
66
75
  ]);
67
76
 
68
77
  /** Errors as they are, to the owner: they say what stands in the way, and name nothing secret. */
@@ -153,6 +162,25 @@ export default function createUpdates(host: PocketHost, web: ExtensionWeb) {
153
162
  void updates.check().then(autoInstall, () => {});
154
163
  };
155
164
 
165
+ // The channel is core's: a server from before the beta channel has no `setBeta`, and the next restart has it.
166
+ const channel = () => {
167
+ if (
168
+ typeof updates.setBeta !== "function" ||
169
+ updates.beta === (web.setting("beta") === true)
170
+ ) {
171
+ return;
172
+ }
173
+
174
+ updates.setBeta(web.setting("beta") === true);
175
+ look();
176
+ };
177
+
178
+ if (typeof updates.setBeta === "function") {
179
+ updates.setBeta(web.setting("beta") === true);
180
+ }
181
+
182
+ web.onDispose(web.onSettings(channel));
183
+
156
184
  // Waiting for quiet sessions needs no new look at GitHub: the last one is enough.
157
185
  const wait = () => {
158
186
  if (web.setting("auto") === true) {
@@ -503,7 +503,10 @@ export interface PocketHost {
503
503
  | "shareTheme"
504
504
  >;
505
505
  /** Updates of Pi Pocket itself (`updates.ts`): its extension's routes are the owner's way to them. */
506
- readonly updates: Pick<Updates, "status" | "check" | "apply" | "subscribe">;
506
+ readonly updates: Pick<
507
+ Updates,
508
+ "status" | "check" | "apply" | "subscribe" | "setBeta" | "beta"
509
+ >;
507
510
  }
508
511
 
509
512
  /**