pi-export-notool 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hyein Cho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # pi-export-notool
2
+
3
+ A [Pi](https://pi.dev) extension that exports the current session to HTML while hiding tool-call and tool-output blocks with injected CSS.
4
+
5
+ ## Use
6
+
7
+ Start Pi with this extension, then run:
8
+
9
+ ```text
10
+ /export-notool [output.html]
11
+ ```
12
+
13
+ Pi's built-in `/export` remains unchanged. `/export-notool` creates the no-tool HTML variant.
14
+
15
+ If no path is supplied, it writes `pi-no-tools-<session-id>.html` in the current working directory. The output is created with Pi's built-in HTML exporter, then gets an idempotent stylesheet that hides `.tool-execution` blocks. The sidebar remains unchanged, so Pi's built-in **No-tools** toggle continues to work. Session data remains embedded in the file; this is display-only hiding.
16
+
17
+ ## Development
18
+
19
+ Run the extension from this checkout:
20
+
21
+ ```bash
22
+ pi --no-extensions -e .
23
+ ```
24
+
25
+ Run its regression tests:
26
+
27
+ ```bash
28
+ npm test
29
+ ```
@@ -0,0 +1,29 @@
1
+ const START_MARKER = "/* pi-export-notool: start */";
2
+ const END_MARKER = "/* pi-export-notool: end */";
3
+
4
+ export const HIDE_TOOL_BLOCKS_CSS = `${START_MARKER}
5
+ /* Keep the transcript readable while retaining Pi's original session data. */
6
+ .tool-execution {
7
+ display: none !important;
8
+ }
9
+ ${END_MARKER}`;
10
+
11
+ /**
12
+ * Add the no-tool stylesheet to a Pi HTML export.
13
+ * The marker makes repeated exports or retries idempotent.
14
+ */
15
+ export function injectNoToolCss(html) {
16
+ if (html.includes(START_MARKER)) return html;
17
+
18
+ const stylesheetClose = /<\/style\s*>/i;
19
+ if (stylesheetClose.test(html)) {
20
+ return html.replace(stylesheetClose, `\n${HIDE_TOOL_BLOCKS_CSS}\n</style>`);
21
+ }
22
+
23
+ const headClose = /<\/head\s*>/i;
24
+ if (headClose.test(html)) {
25
+ return html.replace(headClose, `<style>\n${HIDE_TOOL_BLOCKS_CSS}\n</style>\n</head>`);
26
+ }
27
+
28
+ throw new Error("The exported file does not contain a <style> or <head> element.");
29
+ }
@@ -0,0 +1,57 @@
1
+ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
+ import { basename, dirname, extname, resolve } from "node:path";
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
+ import { injectNoToolCss } from "./html-injection.js";
5
+
6
+ const EXPORT_TIMEOUT_MS = 60_000;
7
+
8
+ function outputPathFor(args: string, cwd: string, sessionFile: string): string {
9
+ const requestedPath = args.trim();
10
+ const defaultName = `pi-no-tools-${basename(sessionFile, ".jsonl")}.html`;
11
+ const outputPath = resolve(cwd, requestedPath || defaultName);
12
+
13
+ if (extname(outputPath).toLowerCase() !== ".html") {
14
+ throw new Error("Output path must use the .html extension.");
15
+ }
16
+
17
+ return outputPath;
18
+ }
19
+
20
+ export default function (pi: ExtensionAPI) {
21
+ const exportNoTool = async (args: string, ctx: ExtensionCommandContext) => {
22
+ const sessionFile = ctx.sessionManager.getSessionFile();
23
+ if (!sessionFile) {
24
+ ctx.ui.notify("No saved session is available to export yet.", "error");
25
+ return;
26
+ }
27
+
28
+ try {
29
+ const outputPath = outputPathFor(args, ctx.cwd, sessionFile);
30
+ await mkdir(dirname(outputPath), { recursive: true });
31
+
32
+ // Use Pi's own exporter so the output keeps the active export template and theme.
33
+ const result = await pi.exec(
34
+ "pi",
35
+ ["--no-extensions", "--export", sessionFile, outputPath],
36
+ { cwd: ctx.cwd, timeout: EXPORT_TIMEOUT_MS },
37
+ );
38
+ if (result.killed || result.code !== 0) {
39
+ throw new Error(result.stderr.trim() || result.stdout.trim() || "Pi HTML export failed.");
40
+ }
41
+
42
+ const html = await readFile(outputPath, "utf8");
43
+ await writeFile(outputPath, injectNoToolCss(html), "utf8");
44
+ ctx.ui.notify(`No-tool HTML export written to ${outputPath}`, "info");
45
+ } catch (error) {
46
+ const message = error instanceof Error ? error.message : String(error);
47
+ ctx.ui.notify(`No-tool export failed: ${message}`, "error");
48
+ }
49
+ };
50
+
51
+ // Interactive TUI handles Pi's built-in /export before extension commands,
52
+ // so /export-notool is the explicit no-tool export command.
53
+ pi.registerCommand("export-notool", {
54
+ description: "Export the current session to HTML with tool-call blocks hidden",
55
+ handler: exportNoTool,
56
+ });
57
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "pi-export-notool",
3
+ "version": "0.1.0",
4
+ "description": "Export Pi sessions to HTML without visible tool-call blocks",
5
+ "type": "module",
6
+ "keywords": [
7
+ "pi-package",
8
+ "pi-extension"
9
+ ],
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "test": "node --test test/*.test.mjs"
13
+ },
14
+ "files": [
15
+ "extensions",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "pi": {
20
+ "extensions": [
21
+ "./extensions/pi-export-notool/index.ts"
22
+ ]
23
+ },
24
+ "peerDependencies": {
25
+ "@earendil-works/pi-coding-agent": "*"
26
+ }
27
+ }