pi-copy-all 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 RespectMathias
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,77 @@
1
+ # pi-copy-all
2
+
3
+ A Pi extension that copies current thread transcript to clipboard.
4
+
5
+ ## Features
6
+
7
+ - `/copy-all` slash command
8
+ - `ctrl+alt+a` shortcut
9
+ - Copies current session branch only
10
+ - Includes previous `user` and `assistant` messages
11
+ - Skips tool results, custom messages, thinking blocks, and tool calls
12
+ - Replaces images with `[image: mime/type]`
13
+ - Notifies when copy succeeds, transcript is empty, or clipboard write fails
14
+
15
+ ## Install
16
+
17
+ From npm:
18
+
19
+ ```bash
20
+ pi install npm:pi-copy-all
21
+ ```
22
+
23
+ From GitHub:
24
+
25
+ ```bash
26
+ pi install git:github.com/RespectMathias/pi-copy-all
27
+ ```
28
+
29
+ Local development:
30
+
31
+ ```bash
32
+ pi -e ./src/index.ts
33
+ ```
34
+
35
+ ## Commands
36
+
37
+ ```text
38
+ /copy-all
39
+ ```
40
+
41
+ Default shortcut:
42
+
43
+ ```text
44
+ ctrl+alt+a
45
+ ```
46
+
47
+ No built-in keybindings are changed by this extension.
48
+
49
+ ## Development
50
+
51
+ ```bash
52
+ npm install
53
+ npm run check
54
+ npm run pack:dry
55
+ ```
56
+
57
+ ## Publishing
58
+
59
+ ```bash
60
+ npm login
61
+ npm publish
62
+ ```
63
+
64
+ GitHub setup:
65
+
66
+ ```bash
67
+ git init
68
+ git add .
69
+ git commit -m "Initial release"
70
+ git branch -M main
71
+ git remote add origin https://github.com/RespectMathias/pi-copy-all.git
72
+ git push -u origin main
73
+ ```
74
+
75
+ ## License
76
+
77
+ MIT © RespectMathias
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "pi-copy-all",
3
+ "version": "0.1.0",
4
+ "description": "Pi extension: copy current thread user and assistant messages to clipboard.",
5
+ "type": "module",
6
+ "keywords": [
7
+ "pi-package",
8
+ "pi-extension",
9
+ "clipboard",
10
+ "pi-coding-agent",
11
+ "pi",
12
+ "copy-all",
13
+ "transcript"
14
+ ],
15
+ "pi": {
16
+ "extensions": [
17
+ "./src/index.ts"
18
+ ]
19
+ },
20
+ "scripts": {
21
+ "test": "vitest run",
22
+ "typecheck": "tsc --noEmit",
23
+ "check": "npm run typecheck && npm test",
24
+ "prepublishOnly": "npm run check",
25
+ "pack:dry": "npm pack --dry-run"
26
+ },
27
+ "peerDependencies": {
28
+ "@earendil-works/pi-coding-agent": "*"
29
+ },
30
+ "devDependencies": {
31
+ "@earendil-works/pi-coding-agent": "*",
32
+ "@types/node": "^24.0.0",
33
+ "typescript": "^5.9.0",
34
+ "vitest": "^4.0.0"
35
+ },
36
+ "author": "RespectMathias",
37
+ "license": "MIT",
38
+ "homepage": "https://github.com/RespectMathias/pi-copy-all#readme",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/RespectMathias/pi-copy-all.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/RespectMathias/pi-copy-all/issues"
45
+ },
46
+ "files": [
47
+ "src/",
48
+ "README.md",
49
+ "LICENSE"
50
+ ],
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "engines": {
55
+ "node": ">=20"
56
+ }
57
+ }
package/src/copyAll.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { copyToClipboard } from "@earendil-works/pi-coding-agent";
2
+ import { formatTranscript } from "./format.js";
3
+
4
+ export type NotifyLevel = "info" | "warning" | "error";
5
+
6
+ export interface CopyAllContext {
7
+ sessionManager: {
8
+ getBranch(): readonly unknown[];
9
+ };
10
+ ui: {
11
+ notify(message: string, level?: NotifyLevel): void;
12
+ };
13
+ }
14
+
15
+ export interface CopyAllResult {
16
+ copied: boolean;
17
+ messageCount: number;
18
+ text: string;
19
+ error?: string;
20
+ }
21
+
22
+ export type ClipboardWriter = (text: string) => Promise<void>;
23
+
24
+ export async function copyAllTranscript(
25
+ ctx: CopyAllContext,
26
+ writeClipboard: ClipboardWriter = copyToClipboard,
27
+ ): Promise<CopyAllResult> {
28
+ const result = formatTranscript(ctx.sessionManager.getBranch());
29
+
30
+ if (result.messageCount === 0) {
31
+ ctx.ui.notify("No user or assistant messages to copy.", "warning");
32
+ return { copied: false, messageCount: 0, text: "" };
33
+ }
34
+
35
+ try {
36
+ await writeClipboard(result.text);
37
+ ctx.ui.notify(
38
+ `Copied ${result.messageCount} messages to clipboard.`,
39
+ "info",
40
+ );
41
+ return {
42
+ copied: true,
43
+ messageCount: result.messageCount,
44
+ text: result.text,
45
+ };
46
+ } catch (error) {
47
+ const message = error instanceof Error ? error.message : String(error);
48
+ ctx.ui.notify(message, "error");
49
+ return {
50
+ copied: false,
51
+ messageCount: result.messageCount,
52
+ text: result.text,
53
+ error: message,
54
+ };
55
+ }
56
+ }
package/src/format.ts ADDED
@@ -0,0 +1,100 @@
1
+ export interface TranscriptResult {
2
+ text: string;
3
+ messageCount: number;
4
+ }
5
+
6
+ type TranscriptRole = "user" | "assistant";
7
+
8
+ interface MessageEntryLike {
9
+ type?: unknown;
10
+ message?: {
11
+ role?: unknown;
12
+ content?: unknown;
13
+ };
14
+ }
15
+
16
+ export function formatTranscript(
17
+ entries: readonly unknown[],
18
+ ): TranscriptResult {
19
+ const sections: string[] = [];
20
+ let messageCount = 0;
21
+
22
+ for (const entry of entries) {
23
+ const message = getCopyableMessage(entry);
24
+ if (!message) continue;
25
+
26
+ const body = formatContent(message.content);
27
+ if (!body.trim()) continue;
28
+
29
+ sections.push(`${roleLabel(message.role)}:\n${body}`);
30
+ messageCount += 1;
31
+ }
32
+
33
+ return {
34
+ text: sections.join("\n\n"),
35
+ messageCount,
36
+ };
37
+ }
38
+
39
+ function getCopyableMessage(
40
+ entry: unknown,
41
+ ): { role: TranscriptRole; content: unknown } | undefined {
42
+ const maybeEntry = entry as MessageEntryLike;
43
+ if (maybeEntry?.type !== "message") return undefined;
44
+
45
+ const role = maybeEntry.message?.role;
46
+ if (role !== "user" && role !== "assistant") return undefined;
47
+
48
+ return {
49
+ role,
50
+ content: maybeEntry.message?.content,
51
+ };
52
+ }
53
+
54
+ function roleLabel(role: TranscriptRole): string {
55
+ return role === "user" ? "User" : "Assistant";
56
+ }
57
+
58
+ function formatContent(content: unknown): string {
59
+ if (typeof content === "string") return content;
60
+ if (!Array.isArray(content)) return "";
61
+
62
+ return content
63
+ .map(formatContentBlock)
64
+ .filter((line): line is string => line !== undefined && line.length > 0)
65
+ .join("\n");
66
+ }
67
+
68
+ function formatContentBlock(block: unknown): string | undefined {
69
+ if (!block || typeof block !== "object") return undefined;
70
+
71
+ const typedBlock = block as {
72
+ type?: unknown;
73
+ text?: unknown;
74
+ mimeType?: unknown;
75
+ mediaType?: unknown;
76
+ source?: { mediaType?: unknown };
77
+ };
78
+
79
+ if (typedBlock.type === "text" && typeof typedBlock.text === "string") {
80
+ return typedBlock.text;
81
+ }
82
+
83
+ if (typedBlock.type === "image") {
84
+ return `[image: ${getImageMimeType(typedBlock)}]`;
85
+ }
86
+
87
+ // Skip thinking, tool calls, and unknown blocks.
88
+ return undefined;
89
+ }
90
+
91
+ function getImageMimeType(block: {
92
+ mimeType?: unknown;
93
+ mediaType?: unknown;
94
+ source?: { mediaType?: unknown };
95
+ }): string {
96
+ const mimeType = block.mimeType ?? block.mediaType ?? block.source?.mediaType;
97
+ return typeof mimeType === "string" && mimeType.length > 0
98
+ ? mimeType
99
+ : "unknown";
100
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { copyAllTranscript } from "./copyAll.js";
3
+
4
+ export default function copyAllExtension(pi: ExtensionAPI) {
5
+ const description =
6
+ "Copy current thread user and assistant messages to clipboard";
7
+
8
+ pi.registerCommand("copy-all", {
9
+ description,
10
+ handler: async (_args, ctx) => {
11
+ await copyAllTranscript(ctx);
12
+ },
13
+ });
14
+
15
+ pi.registerShortcut("ctrl+alt+a", {
16
+ description,
17
+ handler: async (ctx) => {
18
+ await copyAllTranscript(ctx);
19
+ },
20
+ });
21
+ }