pi-anycopy 0.1.2 → 0.1.3
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 +5 -0
- package/extensions/anycopy/config.json +1 -0
- package/extensions/anycopy/index.ts +42 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,8 +66,13 @@ Notes:
|
|
|
66
66
|
|
|
67
67
|
Edit `~/.pi/agent/extensions/anycopy/config.json`:
|
|
68
68
|
|
|
69
|
+
- `treeFilterMode`: initial tree filter mode when opening `/anycopy` (idea sourced from [lajarre](https://github.com/lajarre)'s [pi-mono/issues/1845](https://github.com/badlogic/pi-mono/issues/1845))
|
|
70
|
+
- one of: `default` | `no-tools` | `user-only` | `labeled-only` | `all`
|
|
71
|
+
- `keys`: keybindings (see above)
|
|
72
|
+
|
|
69
73
|
```json
|
|
70
74
|
{
|
|
75
|
+
"treeFilterMode": "default",
|
|
71
76
|
"keys": {
|
|
72
77
|
"toggleSelect": "space",
|
|
73
78
|
"copy": "shift+c",
|
|
@@ -45,8 +45,16 @@ type anycopyKeyConfig = {
|
|
|
45
45
|
pageUp: string;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
type TreeFilterMode = "default" | "no-tools" | "user-only" | "labeled-only" | "all";
|
|
49
|
+
|
|
48
50
|
type anycopyConfig = {
|
|
49
51
|
keys?: Partial<anycopyKeyConfig>;
|
|
52
|
+
treeFilterMode?: TreeFilterMode;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type anycopyRuntimeConfig = {
|
|
56
|
+
keys: anycopyKeyConfig;
|
|
57
|
+
treeFilterMode: TreeFilterMode;
|
|
50
58
|
};
|
|
51
59
|
|
|
52
60
|
const DEFAULT_KEYS: anycopyKeyConfig = {
|
|
@@ -59,31 +67,45 @@ const DEFAULT_KEYS: anycopyKeyConfig = {
|
|
|
59
67
|
pageUp: "shift+left",
|
|
60
68
|
};
|
|
61
69
|
|
|
70
|
+
const DEFAULT_TREE_FILTER_MODE: TreeFilterMode = "default";
|
|
71
|
+
|
|
62
72
|
const getExtensionDir = (): string => {
|
|
63
73
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
64
74
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
65
75
|
return dirname(fileURLToPath(import.meta.url));
|
|
66
76
|
};
|
|
67
77
|
|
|
68
|
-
const loadConfig = ():
|
|
78
|
+
const loadConfig = (): anycopyRuntimeConfig => {
|
|
69
79
|
const configPath = join(getExtensionDir(), "config.json");
|
|
70
|
-
if (!existsSync(configPath))
|
|
80
|
+
if (!existsSync(configPath)) {
|
|
81
|
+
return { keys: { ...DEFAULT_KEYS }, treeFilterMode: DEFAULT_TREE_FILTER_MODE };
|
|
82
|
+
}
|
|
71
83
|
|
|
72
84
|
try {
|
|
73
85
|
const raw = readFileSync(configPath, "utf8");
|
|
74
86
|
const parsed = JSON.parse(raw) as anycopyConfig;
|
|
75
87
|
const keys = parsed.keys ?? {};
|
|
88
|
+
const treeFilterModeRaw = parsed.treeFilterMode;
|
|
89
|
+
const validTreeFilterModes: TreeFilterMode[] = ["default", "no-tools", "user-only", "labeled-only", "all"];
|
|
90
|
+
const treeFilterMode =
|
|
91
|
+
typeof treeFilterModeRaw === "string" && validTreeFilterModes.includes(treeFilterModeRaw as TreeFilterMode)
|
|
92
|
+
? (treeFilterModeRaw as TreeFilterMode)
|
|
93
|
+
: DEFAULT_TREE_FILTER_MODE;
|
|
94
|
+
|
|
76
95
|
return {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
keys: {
|
|
97
|
+
toggleSelect: typeof keys.toggleSelect === "string" ? keys.toggleSelect : DEFAULT_KEYS.toggleSelect,
|
|
98
|
+
copy: typeof keys.copy === "string" ? keys.copy : DEFAULT_KEYS.copy,
|
|
99
|
+
clear: typeof keys.clear === "string" ? keys.clear : DEFAULT_KEYS.clear,
|
|
100
|
+
scrollDown: typeof keys.scrollDown === "string" ? keys.scrollDown : DEFAULT_KEYS.scrollDown,
|
|
101
|
+
scrollUp: typeof keys.scrollUp === "string" ? keys.scrollUp : DEFAULT_KEYS.scrollUp,
|
|
102
|
+
pageDown: typeof keys.pageDown === "string" ? keys.pageDown : DEFAULT_KEYS.pageDown,
|
|
103
|
+
pageUp: typeof keys.pageUp === "string" ? keys.pageUp : DEFAULT_KEYS.pageUp,
|
|
104
|
+
},
|
|
105
|
+
treeFilterMode,
|
|
84
106
|
};
|
|
85
107
|
} catch {
|
|
86
|
-
return { ...DEFAULT_KEYS };
|
|
108
|
+
return { keys: { ...DEFAULT_KEYS }, treeFilterMode: DEFAULT_TREE_FILTER_MODE };
|
|
87
109
|
}
|
|
88
110
|
};
|
|
89
111
|
|
|
@@ -626,7 +648,9 @@ class anycopyOverlay implements Focusable {
|
|
|
626
648
|
}
|
|
627
649
|
|
|
628
650
|
export default function anycopyExtension(pi: ExtensionAPI) {
|
|
629
|
-
const
|
|
651
|
+
const config = loadConfig();
|
|
652
|
+
const keys = config.keys;
|
|
653
|
+
const treeFilterMode = config.treeFilterMode;
|
|
630
654
|
|
|
631
655
|
pi.registerCommand("anycopy", {
|
|
632
656
|
description: "Browse session tree with preview and copy any node(s) to clipboard",
|
|
@@ -676,6 +700,13 @@ export default function anycopyExtension(pi: ExtensionAPI) {
|
|
|
676
700
|
|
|
677
701
|
const treeList = selector.getTreeList();
|
|
678
702
|
|
|
703
|
+
// Set initial tree filter mode (same semantics as `/tree`)
|
|
704
|
+
const rawTreeList = treeList as any;
|
|
705
|
+
if (rawTreeList && typeof rawTreeList === "object") {
|
|
706
|
+
rawTreeList.filterMode = treeFilterMode;
|
|
707
|
+
if (typeof rawTreeList.applyFilter === "function") rawTreeList.applyFilter();
|
|
708
|
+
}
|
|
709
|
+
|
|
679
710
|
// Monkey-patch render to inject checkbox markers (✓/○) into tree rows
|
|
680
711
|
const originalRender = treeList.render.bind(treeList);
|
|
681
712
|
treeList.render = (width: number) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-anycopy",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Copy any single message, or multiple selected messages, from the session tree, with scrollable message preview",
|
|
5
5
|
"keywords": ["pi-package", "pi", "pi-coding-agent"],
|
|
6
6
|
"license": "MIT",
|