@maxiaochao/pi-toolkit 0.1.7 → 0.1.8

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2026-08-31 - v0.1.8
2
+
3
+ - fix cache export branch attribution and update HTML artifact guidance
4
+
1
5
  ## 2026-08-21 - v0.1.7
2
6
 
3
7
  - add the html-artifact skill for interactive HTML explanations and codebase visualizations
@@ -63,7 +63,10 @@ export default function (pi) {
63
63
  pi.registerCommand("cache_export", {
64
64
  description: "Export a tau-style interactive cache dashboard (hit-rate charts, per-request table, events)",
65
65
  handler: async (args, ctx) => {
66
- const entries = ctx.sessionManager.getEntries();
66
+ const sessionManager = ctx.sessionManager;
67
+ const entries = typeof sessionManager.getBranch === "function"
68
+ ? sessionManager.getBranch()
69
+ : sessionManager.getEntries();
67
70
  if (!entries || entries.length === 0) {
68
71
  ctx.ui.notify("No session entries to analyze.", "error");
69
72
  return;
@@ -1,5 +1,9 @@
1
1
  // Deterministic test cases for analyzeStreaks / analyzeMisses / parseEntries.
2
2
  // Run: node --experimental-strip-types tests/run-tests.mjs
3
+ import { mkdtempSync, readFileSync, rmSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { tmpdir } from "node:os";
6
+ import registerCacheExport from "../index.ts";
3
7
  import { parseEntries, analyzeStreaks, analyzeMisses, lineChartForTest } from "../render.ts";
4
8
 
5
9
  let pass = 0, fail = 0;
@@ -314,6 +318,53 @@ const hitOf = (r) => r.cached / (r.fresh + r.cached + r.cacheWrite);
314
318
  s.length === 2 && s.every((x) => x.hits.length === 3), JSON.stringify(s.map((x) => [x.from, x.to])));
315
319
  }
316
320
 
321
+ // Q. subagent results remain visible as main-session tool input -----------
322
+ {
323
+ const entries = [
324
+ req({ cached: 0, fresh: 10000, min: 1, content: [
325
+ { type: "toolCall", tool: "subagent", name: "subagent" },
326
+ { type: "toolCall", tool: "bash", name: "bash" },
327
+ ] }),
328
+ toolResult("delegated result", "subagent"),
329
+ toolResult("ordinary result", "bash"),
330
+ req({ cached: 9000, fresh: 10000, min: 2 }),
331
+ ];
332
+ const d = parseEntries(entries);
333
+ check("Q subagent invocation remains in main-session tool counts",
334
+ d.toolCalls.some(([name]) => name === "subagent") && d.toolCalls.some(([name]) => name === "bash"),
335
+ JSON.stringify(d.toolCalls));
336
+ check("Q subagent result remains available for main fresh-input attribution",
337
+ d.requests[1].gapTools.length === 2 && d.requests[1].gapTools.some(({ tool }) => tool === "subagent"),
338
+ JSON.stringify(d.requests[1].gapTools));
339
+ }
340
+
341
+ // R. command exports only the current main-session branch ----------------
342
+ {
343
+ const root = mkdtempSync(join(tmpdir(), "cache-export-test-"));
344
+ const reportFile = join(root, "report.html");
345
+ const entry = (value, id, parentId) => ({ ...value, id, parentId });
346
+ const first = entry(req({ cached: 9000, fresh: 1000, min: 1, model: "main-first" }), "p1", null);
347
+ const abandoned = entry(req({ cached: 0, fresh: 9000, min: 2, model: "abandoned-model" }), "p2", "p1");
348
+ const active = entry(req({ cached: 8000, fresh: 2000, min: 3, model: "active-model" }), "p3", "p1");
349
+
350
+ let command;
351
+ registerCacheExport({ registerCommand: (name, definition) => { if (name === "cache_export") command = definition; } });
352
+ await command.handler(reportFile, {
353
+ sessionManager: {
354
+ getBranch: () => [first, active],
355
+ getEntries: () => [first, abandoned, active],
356
+ getSessionFile: () => join(root, "main.jsonl"),
357
+ getSessionId: () => "main",
358
+ },
359
+ ui: { notify: () => {} },
360
+ });
361
+ const html = readFileSync(reportFile, "utf8");
362
+ check("R current branch excludes abandoned requests",
363
+ html.includes("2 requests") && html.includes("active-model") && !html.includes("abandoned-model"));
364
+ check("R main-only report has no subagent dashboard", !html.includes("Subagent cache"));
365
+ rmSync(root, { recursive: true, force: true });
366
+ }
367
+
317
368
  // K. degenerate inputs ---------------------------------------------------
318
369
  {
319
370
  check("K empty session -> no crash, no streaks", analyzeStreaks(parseEntries([]).requests).length === 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maxiaochao/pi-toolkit",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Personal pi coding agent toolkit: /todos extension + /cache_export interactive cache dashboard.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -1,12 +1,10 @@
1
1
  ---
2
2
  name: html-artifact
3
- description: Create self-contained, responsive HTML artifacts for complex explanations that benefit from visual structure or interaction, including workflows, code/module relationships, state machines, event/data flows, architecture maps, timelines, comparisons, dashboards, and interactive demonstrations. Use Markdown for ordinary prose, short answers, diffs, and focused code reviews.
3
+ description: Create self-contained, responsive HTML artifacts for complex explanations that benefit from visual structure or interaction, including workflows, code/module relationships, state machines, event/data flows, architecture maps, timelines, comparisons, dashboards, and interactive demonstrations.
4
4
  ---
5
5
 
6
6
  # HTML Artifact
7
7
 
8
- Use this skill when the user needs to understand or explore a complex process, codebase relationship, system design, state transition, comparison, or other content where static Markdown would be hard to scan or interact with.
9
-
10
8
  ## Decide the format
11
9
 
12
10
  Use Markdown when the response is short, linear, text-first, or primarily a focused code review. Use an HTML artifact when visual layout, filtering, expanding details, tabs, highlighting, diagrams, timelines, or interactive state changes materially improve understanding.