@henryqw/pi-open-in 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 +21 -0
- package/README.md +33 -0
- package/extensions/open.ts +50 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Henry Wang
|
|
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,33 @@
|
|
|
1
|
+
# `@henryqw/pi-open-in`
|
|
2
|
+
|
|
3
|
+
Pi extension that adds `/open` and `/set-open-in <command>` for opening current working directory. Default command is `code` (VS Code CLI). You may set it to any command you want.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pi install npm:@henryqw/pi-open-in
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Run `/set-open-in XYZ` to configure `/open`. Then `/open` runs `XYZ <current-working-directory>`.
|
|
12
|
+
|
|
13
|
+
Command saves to `~/.pi/agent/config/pi-open-in.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"command": "code"
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Remove with:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pi remove npm:@henryqw/pi-open-in
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm test
|
|
31
|
+
npm run typecheck
|
|
32
|
+
npm run pack:check
|
|
33
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
getAgentDir,
|
|
6
|
+
type ExtensionAPI,
|
|
7
|
+
} from "@earendil-works/pi-coding-agent";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_COMMAND = "code";
|
|
10
|
+
const configPath = () => join(getAgentDir(), "config", "pi-open-in.json");
|
|
11
|
+
|
|
12
|
+
function configuredCommand(): string {
|
|
13
|
+
try {
|
|
14
|
+
const config: unknown = JSON.parse(readFileSync(configPath(), "utf8"));
|
|
15
|
+
if (config && typeof config === "object" && !Array.isArray(config)) {
|
|
16
|
+
const command = (config as { command?: unknown }).command;
|
|
17
|
+
if (typeof command === "string" && command.trim()) return command.trim();
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
// Missing or malformed config uses default command.
|
|
21
|
+
}
|
|
22
|
+
return DEFAULT_COMMAND;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function saveCommand(command: string): Promise<void> {
|
|
26
|
+
const path = configPath();
|
|
27
|
+
await mkdir(dirname(path), { recursive: true });
|
|
28
|
+
await writeFile(path, `${JSON.stringify({ command }, null, 2)}\n`, "utf8");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default function openInExtension(pi: ExtensionAPI): void {
|
|
32
|
+
const command = configuredCommand();
|
|
33
|
+
|
|
34
|
+
pi.registerCommand("open", {
|
|
35
|
+
description: `Open the current path with \`${command} <current-path>\``,
|
|
36
|
+
handler: async (_args, ctx) => {
|
|
37
|
+
await pi.exec(configuredCommand(), [ctx.cwd]);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
pi.registerCommand("set-open-in", {
|
|
42
|
+
description: "Set command used by /open",
|
|
43
|
+
handler: async (args, ctx) => {
|
|
44
|
+
const command = args.trim();
|
|
45
|
+
if (!command) throw new Error("Usage: /set-open-in <command>");
|
|
46
|
+
await saveCommand(command);
|
|
47
|
+
ctx.ui.notify(`Saved open-in command: ${command}`, "info");
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@henryqw/pi-open-in",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Open the current Pi working directory with a configurable command.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi",
|
|
8
|
+
"vscode",
|
|
9
|
+
"visual-studio-code",
|
|
10
|
+
"command"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.19.0"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"extensions",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node --test test/*.test.ts",
|
|
24
|
+
"typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2022 --module NodeNext --moduleResolution NodeNext --skipLibCheck extensions/open.ts test/*.test.ts",
|
|
25
|
+
"pack:check": "npm pack --dry-run"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/HenryQW/pi-packages.git",
|
|
33
|
+
"directory": "packages/pi-open-in"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/HenryQW/pi-packages/issues"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"pi": {
|
|
42
|
+
"extensions": [
|
|
43
|
+
"./extensions"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|