@ian-pascoe/pi-codemode 0.3.0 → 0.3.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/README.md CHANGED
@@ -171,7 +171,8 @@ Status always uses a symbol and text together:
171
171
 
172
172
  Awaited Cells publish a presentation update immediately and once per second.
173
173
  Collapsed calls show one highlighted line inline or the first eight highlighted
174
- lines of a multi-line Cell. Expanded calls show the complete TypeScript source.
174
+ lines of a multi-line Cell, truncating long lines to the viewport width. Expanded
175
+ calls wrap long lines and show the complete TypeScript source.
175
176
  Returned-data display uses Pi's 2,000-line/50-KB limit; complete oversized data
176
177
  is written to a private Result Spill while the model-facing result remains
177
178
  unchanged. Result Spill files last for the live Pi session. Replayed history
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ian-pascoe/pi-codemode",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "description": "Process-isolated persistent TypeScript tool composition for Pi",
6
6
  "keywords": [
@@ -200,6 +200,47 @@ function highlightedCodeModeSource(source: string): string {
200
200
  .join("\n");
201
201
  }
202
202
 
203
+ function truncateHighlightedCodeModeSourceLine(line: string, width: number): string {
204
+ if (visibleWidth(line) <= width) return line;
205
+ const prefix = sliceByColumn(line, 0, Math.max(0, width - 1), true);
206
+ return `${prefix}\u001b[22;23;24;25;27;28;29;39m…`;
207
+ }
208
+
209
+ class CodeModeCollapsedSourceComponent implements Component {
210
+ private readonly lines: readonly string[];
211
+
212
+ constructor(source: string) {
213
+ this.lines = highlightedCodeModeSource(source).split("\n");
214
+ }
215
+
216
+ render(width: number): string[] {
217
+ if (width <= 0) return [];
218
+ return this.lines.map((line) => truncateHighlightedCodeModeSourceLine(line, width));
219
+ }
220
+
221
+ invalidate(): void {}
222
+ }
223
+
224
+ class CodeModeCollapsedInlineSourceComponent implements Component {
225
+ constructor(
226
+ private readonly prefix: string,
227
+ private readonly source: string,
228
+ private readonly suffix: string,
229
+ ) {}
230
+
231
+ render(width: number): string[] {
232
+ if (width <= 0) return [];
233
+ const sourceWidth = width - visibleWidth(this.prefix) - visibleWidth(this.suffix);
234
+ if (visibleWidth(this.source) === 0 || sourceWidth <= 0)
235
+ return new Text(`${this.prefix.trimEnd()}${this.suffix}`, 0, 0).render(width);
236
+ return [
237
+ `${this.prefix}${truncateHighlightedCodeModeSourceLine(this.source, sourceWidth)}${this.suffix}`,
238
+ ];
239
+ }
240
+
241
+ invalidate(): void {}
242
+ }
243
+
203
244
  function appendHighlightedCodeModeSource(container: Container, source: string): void {
204
245
  container.addChild(new Text(highlightedCodeModeSource(source), 0, 0));
205
246
  }
@@ -319,30 +360,27 @@ export function renderCodeModeToolCall(
319
360
  const oneLineSource = source !== undefined && !source.includes("\n") ? source : undefined;
320
361
  const expansionHint = `${keyText("app.tools.expand")} to expand`;
321
362
  const container = new Container();
322
- container.addChild(
323
- new Text(
324
- [
325
- theme.fg("toolTitle", theme.bold("CodeMode")),
326
- theme.fg("accent", operation),
327
- theme.fg("muted", sessionId === undefined ? "new" : formatSessionPrefix(sessionId)),
328
- !expanded && oneLineSource !== undefined
329
- ? highlightCode(oneLineSource, "typescript")[0]
330
- : undefined,
331
- !expanded && oneLineSource !== undefined
332
- ? theme.fg("dim", `· ${expansionHint}`)
333
- : undefined,
334
- ]
335
- .filter((part): part is string => part !== undefined)
336
- .join(" "),
337
- 0,
338
- 0,
339
- ),
340
- );
363
+ const header = [
364
+ theme.fg("toolTitle", theme.bold("CodeMode")),
365
+ theme.fg("accent", operation),
366
+ theme.fg("muted", sessionId === undefined ? "new" : formatSessionPrefix(sessionId)),
367
+ ].join(" ");
368
+ if (!expanded && oneLineSource !== undefined) {
369
+ container.addChild(
370
+ new CodeModeCollapsedInlineSourceComponent(
371
+ `${header} `,
372
+ highlightCode(oneLineSource, "typescript")[0] ?? "",
373
+ ` ${theme.fg("dim", `· ${expansionHint}`)}`,
374
+ ),
375
+ );
376
+ } else {
377
+ container.addChild(new Text(header, 0, 0));
378
+ }
341
379
  if (!expanded) {
342
380
  if (source === undefined || oneLineSource !== undefined) return container;
343
381
  const sourceLines = source.split("\n");
344
382
  const visibleSource = sourceLines.slice(0, CODEMODE_COLLAPSED_SCRIPT_LINES).join("\n");
345
- appendHighlightedCodeModeSource(container, visibleSource);
383
+ container.addChild(new CodeModeCollapsedSourceComponent(visibleSource));
346
384
  const omittedLines = Math.max(0, sourceLines.length - CODEMODE_COLLAPSED_SCRIPT_LINES);
347
385
  const omitted =
348
386
  omittedLines === 0 ? "" : `… ${pluralizedCodeModeCount(omittedLines, "line")} omitted · `;
@@ -39,7 +39,7 @@ import {
39
39
  } from "./pi-tool-bridge.js";
40
40
 
41
41
  const CODEMODE_EXECUTE_DESCRIPTION =
42
- "Execute a TypeScript Cell in a persistent isolated Deno CodeMode Session. Reuse a Session ID to retain Notebook Bindings; a new Session reclaims the least-recently-used idle Session at capacity. Use the read-only tools object for registered Pi tools. Cells may call console.log, console.info, console.warn, console.error, and console.debug; captured output arrives only with terminal results.";
42
+ "Execute a TypeScript Cell in a persistent isolated Deno CodeMode Session. Reuse a Session ID to retain Notebook Bindings; a new Session reclaims the least-recently-used idle Session at capacity. Use the read-only tools object for registered Pi tools. Return final result data with a top-level return statement. Reserve console.log, console.info, console.warn, console.error, and console.debug for diagnostics; captured output arrives only with terminal results.";
43
43
 
44
44
  type PiCodeModeGeneration = {
45
45
  readonly captured: CapturedPiAgentSession;