pi-durable-bot 0.0.0-stage → 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 +274 -2
- package/dist/agent/agent.js +235 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/judge.js +78 -0
- package/dist/agent/judge.js.map +1 -0
- package/dist/agent/models.js +41 -0
- package/dist/agent/models.js.map +1 -0
- package/dist/bot/bot.js +325 -0
- package/dist/bot/bot.js.map +1 -0
- package/dist/bot/control.js +67 -0
- package/dist/bot/control.js.map +1 -0
- package/dist/bot/definition.js +81 -0
- package/dist/bot/definition.js.map +1 -0
- package/dist/bot/machine.js +26 -0
- package/dist/bot/machine.js.map +1 -0
- package/dist/bot/prompt.js +168 -0
- package/dist/bot/prompt.js.map +1 -0
- package/dist/bot/timers.js +113 -0
- package/dist/bot/timers.js.map +1 -0
- package/dist/channels/load.js +21 -0
- package/dist/channels/load.js.map +1 -0
- package/dist/channels/slack/index.js +518 -0
- package/dist/channels/slack/index.js.map +1 -0
- package/dist/channels/slack/sdk.js +55 -0
- package/dist/channels/slack/sdk.js.map +1 -0
- package/dist/channels/terminal/index.js +19 -0
- package/dist/channels/terminal/index.js.map +1 -0
- package/dist/channels/test/index.js +197 -0
- package/dist/channels/test/index.js.map +1 -0
- package/dist/cli/agent.js +78 -0
- package/dist/cli/agent.js.map +1 -0
- package/dist/cli/ai.js +126 -0
- package/dist/cli/ai.js.map +1 -0
- package/dist/cli/bots.js +57 -0
- package/dist/cli/bots.js.map +1 -0
- package/dist/cli/chat.js +157 -0
- package/dist/cli/chat.js.map +1 -0
- package/dist/cli/control.js +52 -0
- package/dist/cli/control.js.map +1 -0
- package/dist/cli/init.js +103 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/pots.js +74 -0
- package/dist/cli/pots.js.map +1 -0
- package/dist/cli/service.js +228 -0
- package/dist/cli/service.js.map +1 -0
- package/dist/core/channel.js +4 -0
- package/dist/core/channel.js.map +1 -0
- package/dist/core/env-file.js +22 -0
- package/dist/core/env-file.js.map +1 -0
- package/dist/core/home.js +16 -0
- package/dist/core/home.js.map +1 -0
- package/dist/core/judge.js +3 -0
- package/dist/core/judge.js.map +1 -0
- package/dist/core/sql.js +2 -0
- package/dist/core/sql.js.map +1 -0
- package/dist/core/wake.js +2 -0
- package/dist/core/wake.js.map +1 -0
- package/dist/gateway/gateway.js +175 -0
- package/dist/gateway/gateway.js.map +1 -0
- package/dist/gateway/log.js +264 -0
- package/dist/gateway/log.js.map +1 -0
- package/dist/gateway/outbox.js +63 -0
- package/dist/gateway/outbox.js.map +1 -0
- package/dist/gateway/waker.js +168 -0
- package/dist/gateway/waker.js.map +1 -0
- package/dist/main.js +148 -0
- package/dist/main.js.map +1 -0
- package/docs/channels/slack-app-manifest.yaml +54 -0
- package/docs/channels/slack.md +22 -0
- package/package.json +55 -4
package/dist/main.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { openModels } from "./agent/models.js";
|
|
6
|
+
import { Bot } from "./bot/bot.js";
|
|
7
|
+
import { BOT_ID, botPaths, readDefinition } from "./bot/definition.js";
|
|
8
|
+
import { BIN_DIR, BOTS_DIR, PID_FILE, POTS_HOME } from "./core/home.js";
|
|
9
|
+
// The gateway: runs every bot folder in ~/.pots/bots. A folder with a bot.json is a bot. Checks the folders every few
|
|
10
|
+
// seconds, so a new folder starts a bot, a removed one stops it, and a changed bot.json applies while running.
|
|
11
|
+
const SCAN_MS = 5_000;
|
|
12
|
+
/** A bot that failed to start or to apply bot.json is tried again after this long (for example while the network is not up yet). */
|
|
13
|
+
const RETRY_MS = 60_000;
|
|
14
|
+
/** The `pots` command line next to this file: src/cli/pots.ts, or dist/cli/pots.js in the built package. */
|
|
15
|
+
const potsEntry = fileURLToPath(new URL(`./cli/pots${import.meta.url.slice(import.meta.url.lastIndexOf("."))}`, import.meta.url));
|
|
16
|
+
function print(bot) {
|
|
17
|
+
return (message, data) => {
|
|
18
|
+
console.log(JSON.stringify({ time: new Date().toISOString(), ...(bot ? { bot } : {}), message, ...data }));
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** The process ID in the pid file, when that process is still running. */
|
|
22
|
+
export function runningGateway() {
|
|
23
|
+
if (!existsSync(PID_FILE))
|
|
24
|
+
return undefined;
|
|
25
|
+
const pid = Number(readFileSync(PID_FILE, "utf8").trim());
|
|
26
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
try {
|
|
29
|
+
process.kill(pid, 0);
|
|
30
|
+
return pid;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return error.code === "EPERM" ? pid : undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Write the `pots` command that the bots' shells and scheduled jobs use: this node and this package, so it works where
|
|
38
|
+
* PATH has neither (cron, Git Bash on Windows).
|
|
39
|
+
*/
|
|
40
|
+
function writePotsCommand() {
|
|
41
|
+
mkdirSync(BIN_DIR, { recursive: true });
|
|
42
|
+
const path = (file) => (process.platform === "win32" ? file.replaceAll("\\", "/") : file);
|
|
43
|
+
const command = join(BIN_DIR, "pots");
|
|
44
|
+
writeFileSync(command, `#!/bin/sh\nexec "${path(process.execPath)}" "${path(potsEntry)}" "$@"\n`, { mode: 0o755 });
|
|
45
|
+
return command;
|
|
46
|
+
}
|
|
47
|
+
/** Run the gateway until SIGTERM or SIGINT. Only one gateway runs per POTS_HOME. */
|
|
48
|
+
export async function runGateway() {
|
|
49
|
+
mkdirSync(BOTS_DIR, { recursive: true, mode: 0o700 });
|
|
50
|
+
const other = runningGateway();
|
|
51
|
+
if (other !== undefined && other !== process.pid)
|
|
52
|
+
throw new Error(`a gateway is already running for ${POTS_HOME} (process ${other})`);
|
|
53
|
+
writeFileSync(PID_FILE, `${process.pid}\n`);
|
|
54
|
+
const potsCommand = writePotsCommand();
|
|
55
|
+
const log = print(undefined);
|
|
56
|
+
const models = await openModels();
|
|
57
|
+
const running = new Map();
|
|
58
|
+
/** Bots whose bot.json could not be read (the error) or used (the bot.json text and when it failed). */
|
|
59
|
+
const invalid = new Map();
|
|
60
|
+
const failed = new Map();
|
|
61
|
+
let scanning = Promise.resolve();
|
|
62
|
+
let stopping = false;
|
|
63
|
+
async function scan() {
|
|
64
|
+
const ids = existsSync(BOTS_DIR)
|
|
65
|
+
? readdirSync(BOTS_DIR, { withFileTypes: true })
|
|
66
|
+
.filter((entry) => entry.isDirectory() && BOT_ID.test(entry.name) && existsSync(join(BOTS_DIR, entry.name, "bot.json")))
|
|
67
|
+
.map((entry) => entry.name)
|
|
68
|
+
: [];
|
|
69
|
+
for (const [id, entry] of running) {
|
|
70
|
+
if (ids.includes(id))
|
|
71
|
+
continue;
|
|
72
|
+
running.delete(id);
|
|
73
|
+
await entry.bot.stop().catch((error) => log("bot stop failed", { bot: id, error: String(error) }));
|
|
74
|
+
}
|
|
75
|
+
for (const id of ids) {
|
|
76
|
+
const paths = botPaths(join(BOTS_DIR, id));
|
|
77
|
+
let read;
|
|
78
|
+
try {
|
|
79
|
+
read = readDefinition(paths.definition);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
83
|
+
if (invalid.get(id) !== message) {
|
|
84
|
+
invalid.set(id, message);
|
|
85
|
+
print(id)("bot.json is not valid; keeping the running definition", { error: message });
|
|
86
|
+
await writeFile(paths.definitionError, `${message}\n`).catch(() => { });
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
invalid.delete(id);
|
|
91
|
+
const current = running.get(id);
|
|
92
|
+
if (current && current.text === read.text) {
|
|
93
|
+
// Back to the definition that runs: nothing to apply, and no error left.
|
|
94
|
+
failed.delete(id);
|
|
95
|
+
if (existsSync(paths.definitionError))
|
|
96
|
+
await unlink(paths.definitionError).catch(() => { });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const failure = failed.get(id);
|
|
100
|
+
if (failure && failure.text === read.text && Date.now() - failure.at < RETRY_MS)
|
|
101
|
+
continue;
|
|
102
|
+
try {
|
|
103
|
+
if (current) {
|
|
104
|
+
await current.bot.applyDefinition(read.definition);
|
|
105
|
+
current.text = read.text;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const bot = await Bot.start(id, paths.dir, read.definition, { botsDir: BOTS_DIR, potsCommand, models }, print(id));
|
|
109
|
+
running.set(id, { bot, text: read.text });
|
|
110
|
+
}
|
|
111
|
+
failed.delete(id);
|
|
112
|
+
if (existsSync(paths.definitionError))
|
|
113
|
+
await unlink(paths.definitionError).catch(() => { });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
117
|
+
failed.set(id, { text: read.text, at: Date.now() });
|
|
118
|
+
print(id)(current ? "applying bot.json failed" : "bot start failed", { error: message });
|
|
119
|
+
await writeFile(paths.definitionError, `${message}\n`).catch(() => { });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function rescan() {
|
|
124
|
+
scanning = scanning.then(() => (stopping ? undefined : scan())).catch((error) => log("scan failed", { error: String(error) }));
|
|
125
|
+
return scanning;
|
|
126
|
+
}
|
|
127
|
+
await rescan();
|
|
128
|
+
log("started", { home: POTS_HOME, bots: [...running.keys()] });
|
|
129
|
+
const timer = setInterval(() => void rescan(), SCAN_MS);
|
|
130
|
+
async function shutdown(signal) {
|
|
131
|
+
if (stopping)
|
|
132
|
+
return;
|
|
133
|
+
stopping = true;
|
|
134
|
+
log("shutdown", { signal });
|
|
135
|
+
clearInterval(timer);
|
|
136
|
+
const deadline = setTimeout(() => process.exit(1), 25_000);
|
|
137
|
+
await scanning;
|
|
138
|
+
await Promise.allSettled([...running.values()].map((entry) => entry.bot.stop()));
|
|
139
|
+
clearTimeout(deadline);
|
|
140
|
+
if (runningGateway() === process.pid)
|
|
141
|
+
await unlink(PID_FILE).catch(() => { });
|
|
142
|
+
process.exit(0);
|
|
143
|
+
}
|
|
144
|
+
process.on("SIGTERM", () => void shutdown("SIGTERM"));
|
|
145
|
+
process.on("SIGINT", () => void shutdown("SIGINT"));
|
|
146
|
+
process.on("unhandledRejection", (error) => log("unhandled rejection", { error: String(error) }));
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAExE,sHAAsH;AACtH,+GAA+G;AAE/G,MAAM,OAAO,GAAG,KAAK,CAAC;AACtB,oIAAoI;AACpI,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,4GAA4G;AAC5G,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC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AM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# pi-durable-bot · Slack app manifest
|
|
2
|
+
# Use: api.slack.com/apps, Create New App, From an app manifest, pick the workspace, paste this file.
|
|
3
|
+
# Based on the manifest recommended in the Vercel Chat SDK Slack adapter README, changed to socket mode, with DM and file scopes added.
|
|
4
|
+
# Change the name to your coworker's name before you paste it.
|
|
5
|
+
# This file holds no tokens. Never put tokens in this repository.
|
|
6
|
+
display_information:
|
|
7
|
+
name: Pots
|
|
8
|
+
description: A coworker on your team
|
|
9
|
+
features:
|
|
10
|
+
app_home:
|
|
11
|
+
home_tab_enabled: false
|
|
12
|
+
messages_tab_enabled: true
|
|
13
|
+
messages_tab_read_only_enabled: false
|
|
14
|
+
bot_user:
|
|
15
|
+
display_name: pots
|
|
16
|
+
always_online: true
|
|
17
|
+
oauth_config:
|
|
18
|
+
scopes:
|
|
19
|
+
bot:
|
|
20
|
+
- app_mentions:read
|
|
21
|
+
- channels:history
|
|
22
|
+
- channels:read
|
|
23
|
+
- chat:write
|
|
24
|
+
- files:read
|
|
25
|
+
- files:write
|
|
26
|
+
- groups:history
|
|
27
|
+
- groups:read
|
|
28
|
+
- im:history
|
|
29
|
+
- im:read
|
|
30
|
+
- im:write
|
|
31
|
+
- mpim:history
|
|
32
|
+
- mpim:read
|
|
33
|
+
- reactions:read
|
|
34
|
+
- reactions:write
|
|
35
|
+
- users:read
|
|
36
|
+
user:
|
|
37
|
+
- chat:write
|
|
38
|
+
- im:write
|
|
39
|
+
settings:
|
|
40
|
+
event_subscriptions:
|
|
41
|
+
bot_events:
|
|
42
|
+
- app_mention
|
|
43
|
+
- message.channels
|
|
44
|
+
- message.groups
|
|
45
|
+
- message.im
|
|
46
|
+
- message.mpim
|
|
47
|
+
- member_joined_channel
|
|
48
|
+
- reaction_added
|
|
49
|
+
- reaction_removed
|
|
50
|
+
interactivity:
|
|
51
|
+
is_enabled: true
|
|
52
|
+
org_deploy_enabled: false
|
|
53
|
+
socket_mode_enabled: true
|
|
54
|
+
token_rotation_enabled: false
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Connect Slack
|
|
2
|
+
|
|
3
|
+
Written for a bot that connects itself; a person can follow it too. The app uses socket mode, so the computer needs no public address.
|
|
4
|
+
|
|
5
|
+
1. Open https://api.slack.com/apps?new_app=1 in a browser window on this computer that the person can see (not headless), driven by any browser automation you can run, for example Playwright. If Slack asks to sign in, ask the person to sign in in that window.
|
|
6
|
+
2. Choose **From a manifest**, pick the workspace, and paste [slack-app-manifest.yaml](slack-app-manifest.yaml). Change `name` and `display_name` to your own name first. Create the app.
|
|
7
|
+
3. **Basic Information → App-Level Tokens → Generate Token and Scopes**: add the scope `connections:write` and generate. This is the app token (`xapp-…`).
|
|
8
|
+
4. **Install App → Install to workspace → Allow**. Some workspaces need an admin to approve; then ask the person. Copy the **Bot User OAuth Token** (`xoxb-…`).
|
|
9
|
+
5. Write both tokens to `slack.env` in the secrets folder (`~/.pots/secrets/`), readable only by this user:
|
|
10
|
+
```sh
|
|
11
|
+
SLACK_APP_TOKEN=xapp-...
|
|
12
|
+
SLACK_BOT_TOKEN=xoxb-...
|
|
13
|
+
```
|
|
14
|
+
Do not put tokens in a chat message, a log or any other file.
|
|
15
|
+
6. Add the channel to `channels` in your `bot.json`:
|
|
16
|
+
```json
|
|
17
|
+
{ "id": "slack", "type": "slack", "secrets": "~/.pots/secrets/slack.env" }
|
|
18
|
+
```
|
|
19
|
+
It connects within a few seconds. `pots status` lists it; if it fails, the reason is in `bot.json.error`.
|
|
20
|
+
7. You join only the places you are invited to. Ask the person to invite you to the right channels (`/invite @yourname`) or to send you a DM in Slack.
|
|
21
|
+
|
|
22
|
+
A second Slack workspace is a second channel entry with its own `id` (for example `slack-acme`) and its own env file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-bot",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Open-source AI coworkers that read every channel, decide what matters, and act on their own computer. Self-hosted, any model.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "https://github.com/Crokily/pi-durable-bot#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Crokily/pi-durable-bot.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Crokily/pi-durable-bot/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ai-agent",
|
|
17
|
+
"ai-coworker",
|
|
18
|
+
"slack-bot",
|
|
19
|
+
"self-hosted",
|
|
20
|
+
"pi-durable",
|
|
21
|
+
"chat-sdk"
|
|
22
|
+
],
|
|
23
|
+
"bin": {
|
|
24
|
+
"pots": "dist/cli/pots.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"docs/channels",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=24"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"start": "node src/cli/pots.ts start",
|
|
37
|
+
"pots": "node src/cli/pots.ts",
|
|
38
|
+
"check": "tsc --noEmit",
|
|
39
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
40
|
+
"prepare": "npm run build"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@chat-adapter/slack": "4.43.0",
|
|
44
|
+
"@chat-adapter/state-memory": "4.43.0",
|
|
45
|
+
"@earendil-works/chord": "1.4.0",
|
|
46
|
+
"@earendil-works/pi-ai": "1.4.0",
|
|
47
|
+
"@earendil-works/pi-coding-agent": "1.4.0",
|
|
48
|
+
"@earendil-works/pi-durable": "1.4.0",
|
|
49
|
+
"@effect/platform-node": "4.0.7",
|
|
50
|
+
"chat": "4.43.0",
|
|
51
|
+
"effect": "4.0.7"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "26.6.5",
|
|
55
|
+
"typescript": "7.0.2"
|
|
56
|
+
}
|
|
57
|
+
}
|