@yousif_nazhat/penpal-pi 0.2.0-rc.2

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/index.ts +151 -0
  4. package/package.json +21 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yousif Nazhat
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,12 @@
1
+ # PenPal PI adapter
2
+
3
+ This PI package adds PenPal's seven read-only, masked workspace tools to PI.
4
+
5
+ Install the PenPal Python core first, then install this release candidate in PI:
6
+
7
+ ```bash
8
+ python3 -m pip install --pre penpal-enum
9
+ pi install npm:@yousif_nazhat/penpal-pi@0.2.0-rc.2
10
+ ```
11
+
12
+ Set `PENPAL_WORKSPACE` when the workspace is not `penpal-workspace`; set `PENPAL_PYTHON` when Python is not available as `python3`.
package/index.ts ADDED
@@ -0,0 +1,151 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { execFile } from "node:child_process";
3
+ import { promisify } from "node:util";
4
+ import { Type } from "typebox";
5
+
6
+ const execFileAsync = promisify(execFile);
7
+ const cwd = process.env.PENPAL_CWD ?? process.cwd();
8
+ const python = process.env.PENPAL_PYTHON ?? (process.platform === "win32" ? "python" : "python3");
9
+ const workspace = process.env.PENPAL_WORKSPACE;
10
+ const readOnlyTools = [
11
+ "penpal_context",
12
+ "penpal_suggest",
13
+ "penpal_evidence",
14
+ "penpal_playbooks_validate",
15
+ "penpal_playbook_show",
16
+ "penpal_modules_list",
17
+ "penpal_module_plan",
18
+ ];
19
+
20
+ export default function (pi: ExtensionAPI) {
21
+ pi.registerTool({
22
+ name: "penpal_context",
23
+ label: "PenPal context",
24
+ description: "Read PenPal's masked deterministic context snapshot for a target.",
25
+ parameters: Type.Object({ target: Type.String({ description: "PenPal target name" }) }),
26
+ async execute(_toolCallId, params, signal) {
27
+ return readOnly(["context", params.target, "--json"], signal);
28
+ },
29
+ });
30
+
31
+ pi.registerTool({
32
+ name: "penpal_suggest",
33
+ label: "PenPal suggestions",
34
+ description: "Read PenPal's deterministic suggestions for a target.",
35
+ parameters: Type.Object({ target: Type.String({ description: "PenPal target name" }) }),
36
+ async execute(_toolCallId, params, signal) {
37
+ return readOnly(["suggest", params.target, "--json"], signal);
38
+ },
39
+ });
40
+
41
+ pi.registerTool({
42
+ name: "penpal_evidence",
43
+ label: "PenPal evidence",
44
+ description: "Read PenPal's masked extracted evidence for a target.",
45
+ parameters: Type.Object({ target: Type.String({ description: "PenPal target name" }) }),
46
+ async execute(_toolCallId, params, signal) {
47
+ return readOnly(["evidence", params.target, "--json"], signal);
48
+ },
49
+ });
50
+
51
+ pi.registerTool({
52
+ name: "penpal_playbooks_validate",
53
+ label: "Validate PenPal playbooks",
54
+ description: "Validate PenPal's bundled playbooks.",
55
+ parameters: Type.Object({}),
56
+ async execute(_toolCallId, _params, signal) {
57
+ return readOnly(["playbooks", "playbooks", "--json"], signal);
58
+ },
59
+ });
60
+
61
+ pi.registerTool({
62
+ name: "penpal_playbook_show",
63
+ label: "Show PenPal playbook",
64
+ description: "Read one validated PenPal playbook by id.",
65
+ parameters: Type.Object({ id: Type.String({ description: "Playbook id" }) }),
66
+ async execute(_toolCallId, params, signal) {
67
+ return readOnly(["playbooks", "playbooks", "--show", params.id], signal);
68
+ },
69
+ });
70
+
71
+ pi.registerTool({
72
+ name: "penpal_modules_list",
73
+ label: "List PenPal service modules",
74
+ description: "Read PenPal's source-backed service module registry.",
75
+ parameters: Type.Object({}),
76
+ async execute(_toolCallId, _params, signal) {
77
+ return readOnly(["modules", "list", "--json"], signal);
78
+ },
79
+ });
80
+
81
+ pi.registerTool({
82
+ name: "penpal_module_plan",
83
+ label: "Plan PenPal service module",
84
+ description: "Read a source-backed module plan without executing commands.",
85
+ parameters: Type.Object({
86
+ target: Type.String({ description: "PenPal target name" }),
87
+ module: Type.String({ description: "Module name, such as snmp, web, smb, or dns" }),
88
+ }),
89
+ async execute(_toolCallId, params, signal) {
90
+ return readOnly(["modules", "plan", params.target, params.module, "--json"], signal);
91
+ },
92
+ });
93
+
94
+ pi.registerCommand("penpal-status", {
95
+ description: "Verify PenPal's read-only PI tools and deterministic core.",
96
+ handler: async (_args, ctx) => {
97
+ const registered = new Set(pi.getAllTools().map((tool) => tool.name));
98
+ const missing = readOnlyTools.filter((tool) => !registered.has(tool));
99
+ if (missing.length > 0) {
100
+ ctx.ui.notify(`PenPal extension incomplete; missing tools: ${missing.join(", ")}`, "error");
101
+ return;
102
+ }
103
+ try {
104
+ const report = JSON.parse(await penpal(["playbooks", "playbooks", "--json"]));
105
+ if (report.invalid_playbooks !== 0) {
106
+ ctx.ui.notify(`PenPal core reported ${report.invalid_playbooks} invalid playbooks`, "error");
107
+ return;
108
+ }
109
+ ctx.ui.notify(
110
+ `PenPal ready: ${readOnlyTools.length} read-only tools registered; ${report.valid_playbooks} playbooks valid.`,
111
+ "info",
112
+ );
113
+ } catch (error) {
114
+ ctx.ui.notify(errorMessage(error), "error");
115
+ }
116
+ },
117
+ });
118
+ }
119
+
120
+ async function readOnly(args: string[], signal?: AbortSignal) {
121
+ try {
122
+ return textResult(await penpal(args, signal));
123
+ } catch (error) {
124
+ return textResult(`error: ${errorMessage(error)}`);
125
+ }
126
+ }
127
+
128
+ async function penpal(args: string[], signal?: AbortSignal): Promise<string> {
129
+ const fullArgs = ["-m", "penpal"];
130
+ if (workspace) fullArgs.push("--workspace", workspace);
131
+ fullArgs.push(...args);
132
+ const { stdout } = await execFileAsync(python, fullArgs, {
133
+ cwd,
134
+ signal,
135
+ timeout: 30_000,
136
+ maxBuffer: 2_000_000,
137
+ });
138
+ return stdout.trim();
139
+ }
140
+
141
+ function errorMessage(error: unknown): string {
142
+ if (error instanceof Error) {
143
+ const stderr = (error as Error & { stderr?: string }).stderr?.trim();
144
+ return stderr || error.message;
145
+ }
146
+ return String(error);
147
+ }
148
+
149
+ function textResult(text: string) {
150
+ return { content: [{ type: "text" as const, text }], details: {} };
151
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@yousif_nazhat/penpal-pi",
3
+ "version": "0.2.0-rc.2",
4
+ "description": "PI cockpit for the PenPal Python core.",
5
+ "license": "MIT",
6
+ "keywords": ["pi-package", "penpal"],
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "engines": {
11
+ "node": ">=22.19.0"
12
+ },
13
+ "files": ["index.ts", "LICENSE", "README.md"],
14
+ "peerDependencies": {
15
+ "@earendil-works/pi-coding-agent": "*",
16
+ "typebox": "*"
17
+ },
18
+ "pi": {
19
+ "extensions": ["./index.ts"]
20
+ }
21
+ }