@usepipa/pipa 0.3.1 → 0.3.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.
- package/README.md +17 -0
- package/bin/pipa.mjs +5 -1
- package/package.json +1 -1
- package/src/app.mjs +17 -1
- package/src/state.mjs +6 -0
package/README.md
CHANGED
|
@@ -43,6 +43,23 @@ pipa start
|
|
|
43
43
|
|
|
44
44
|
Keep `pipa start` running, invite Pipa to a trusted public or private Slack channel, and mention it there. Pipa starts one OpenCode server bound to `127.0.0.1` on an operating-system-assigned port and reuses it for every Slack turn. Port `0` asks the operating system for an available port; no port configuration is required. Pipa replies in a thread, and follow-up messages in that thread reuse the same OpenCode session without another mention. Messages can include up to Slack's 10-file limit, with a maximum size of 100 MB per file. Attachments require a text prompt and are copied to a temporary directory only for the duration of the turn.
|
|
45
45
|
|
|
46
|
+
### Access control
|
|
47
|
+
|
|
48
|
+
By default Pipa answers anyone who mentions it in a channel it can see. In a shared workspace, restrict who can use it by listing the allowed Slack channel and user IDs. `pipa init` asks for these, and they are stored in the config:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"botName": "Pipa",
|
|
53
|
+
"workingDirectory": "/work",
|
|
54
|
+
"slackAppToken": "xapp-...",
|
|
55
|
+
"slackBotToken": "xoxb-...",
|
|
56
|
+
"allowedSlackChannelIds": ["C0BSE2JTYPR"],
|
|
57
|
+
"allowedSlackUserIds": ["UFWBSCZ54"]
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
A mention is only handled when the channel ID is in `allowedSlackChannelIds` **and** the author's user ID is in `allowedSlackUserIds`. Leave a list empty to allow any channel or any user. You can also set them non-interactively during setup with `PIPA_ALLOWED_CHANNEL_IDS` and `PIPA_ALLOWED_USER_IDS` (comma-separated).
|
|
62
|
+
|
|
46
63
|
To use an existing OpenCode server instead, set its URL before starting Pipa. Pipa health-checks the server but does not start or stop it. If the server uses authentication, also set `OPENCODE_SERVER_USERNAME` and `OPENCODE_SERVER_PASSWORD`:
|
|
47
64
|
|
|
48
65
|
```sh
|
package/bin/pipa.mjs
CHANGED
|
@@ -61,8 +61,12 @@ async function init(io) {
|
|
|
61
61
|
};
|
|
62
62
|
const slackAppToken = process.env.PIPA_SLACK_APP_TOKEN || await askSecret("Slack app token (xapp-, input hidden): ", "App token");
|
|
63
63
|
const slackBotToken = process.env.PIPA_SLACK_BOT_TOKEN || await askSecret("Slack bot token (xoxb-, input hidden): ", "Bot token");
|
|
64
|
+
const allowedSlackChannelIds = process.env.PIPA_ALLOWED_CHANNEL_IDS
|
|
65
|
+
?? (await prompt.question("Allowed Slack channel IDs (comma-separated, e.g. C0BSE2JTYPR; leave empty to allow any channel): ")).trim();
|
|
66
|
+
const allowedSlackUserIds = process.env.PIPA_ALLOWED_USER_IDS
|
|
67
|
+
?? (await prompt.question("Allowed Slack user IDs (comma-separated, e.g. UFWBSCZ54; leave empty to allow any user): ")).trim();
|
|
64
68
|
io.output.write("\nChecking OpenCode and Slack credentials...\n");
|
|
65
|
-
const result = await initializePipa({ botName, workingDirectory, slackAppToken, slackBotToken });
|
|
69
|
+
const result = await initializePipa({ botName, workingDirectory, slackAppToken, slackBotToken, allowedSlackChannelIds, allowedSlackUserIds });
|
|
66
70
|
io.output.write(`✓ Credentials validated.\n\nSaved config to ${result.paths.config}. Run \`pipa start\`.\n`);
|
|
67
71
|
} finally {
|
|
68
72
|
prompt.close();
|
package/package.json
CHANGED
package/src/app.mjs
CHANGED
|
@@ -12,6 +12,8 @@ export async function initializePipa(input, options = {}) {
|
|
|
12
12
|
slackAppToken: requireToken(input.slackAppToken, "Slack app token", "xapp-"),
|
|
13
13
|
slackBotToken: requireToken(input.slackBotToken, "Slack bot token", "xoxb-"),
|
|
14
14
|
workingDirectory: await canonicalWorkingDirectory(input.workingDirectory),
|
|
15
|
+
allowedSlackChannelIds: normalizeIdList(input.allowedSlackChannelIds),
|
|
16
|
+
allowedSlackUserIds: normalizeIdList(input.allowedSlackUserIds),
|
|
15
17
|
};
|
|
16
18
|
const openCodeVersion = await (options.checkOpenCode ?? runOpenCodeVersion)();
|
|
17
19
|
if (!/^v?1(?:\.|$)/u.test(openCodeVersion)) throw new Error(`Pipa requires OpenCode v1; found ${openCodeVersion || "an unknown version"}.`);
|
|
@@ -60,7 +62,7 @@ export async function startPipa(options = {}) {
|
|
|
60
62
|
let accepting = true;
|
|
61
63
|
|
|
62
64
|
const handle = async (thread, message, subscribe) => {
|
|
63
|
-
if (!accepting || shouldIgnore(thread, message)) return;
|
|
65
|
+
if (!accepting || !isAuthorized(thread, message, config) || shouldIgnore(thread, message)) return;
|
|
64
66
|
const prompt = subscribe || message.isMention ? stripMention(message.text) : message.text.trim();
|
|
65
67
|
if (!prompt) return;
|
|
66
68
|
const attachments = message.attachments ?? [];
|
|
@@ -201,6 +203,20 @@ function shouldIgnore(thread, message) {
|
|
|
201
203
|
|| !message.text?.trim();
|
|
202
204
|
}
|
|
203
205
|
|
|
206
|
+
function isAuthorized(thread, message, config) {
|
|
207
|
+
const channelId = thread.id.split(":")[1];
|
|
208
|
+
const userId = message.author?.userId ?? message.author?.id;
|
|
209
|
+
if (config.allowedSlackChannelIds?.length && !config.allowedSlackChannelIds.includes(channelId)) return false;
|
|
210
|
+
if (config.allowedSlackUserIds?.length && !config.allowedSlackUserIds.includes(userId)) return false;
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function normalizeIdList(value) {
|
|
215
|
+
if (value === undefined || value === null) return [];
|
|
216
|
+
const list = Array.isArray(value) ? value : String(value).split(/[\s,]+/u);
|
|
217
|
+
return list.map((item) => String(item).trim()).filter(Boolean);
|
|
218
|
+
}
|
|
219
|
+
|
|
204
220
|
function stripMention(text = "") {
|
|
205
221
|
return text.replace(/(?:<@|@)[UW][A-Z0-9]+>?/u, "").trim();
|
|
206
222
|
}
|
package/src/state.mjs
CHANGED
|
@@ -114,6 +114,12 @@ export async function loadConfig(file = pipaPaths().config) {
|
|
|
114
114
|
if (slackMode === "managed" && (!Number.isInteger(config.openCodePort) || config.openCodePort < 1 || config.openCodePort > 65535)) {
|
|
115
115
|
throw new Error("Invalid Pipa config: openCodePort must be an integer from 1 to 65535.");
|
|
116
116
|
}
|
|
117
|
+
for (const key of ["allowedSlackChannelIds", "allowedSlackUserIds"]) {
|
|
118
|
+
const value = config[key];
|
|
119
|
+
if (value !== undefined && (!Array.isArray(value) || !value.every((item) => typeof item === "string" && item.trim()))) {
|
|
120
|
+
throw new Error(`Invalid Pipa config: ${key} must be a list of non-empty Slack IDs.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
117
123
|
return { ...config, slackMode };
|
|
118
124
|
}
|
|
119
125
|
|