agentpen-cli 0.1.2 → 0.1.4
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 +19 -5
- package/cli/agentpen.js +67 -13
- package/cli/claude-share.js +46 -13
- package/cli/codex-app.js +20 -6
- package/cli/handoff.js +44 -28
- package/cli/install.js +128 -8
- package/cli/redact.js +32 -16
- package/package.json +2 -4
- package/server/agents.js +0 -250
- package/server/db.js +0 -161
- package/server/hub.js +0 -637
- package/server/index.js +0 -746
- package/server/notify.js +0 -91
- package/server/search.js +0 -34
- package/web/app.js +0 -518
- package/web/favicon.svg +0 -1
- package/web/index.html +0 -16
- package/web/session.js +0 -460
- package/web/styles.css +0 -263
- package/web/team-page.png +0 -0
package/server/db.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// SQLite persistence. One file, zero external services: the same binary runs
|
|
2
|
-
// the hosted product and a customer's self-hosted install.
|
|
3
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
4
|
-
import { createHash, randomBytes } from 'node:crypto';
|
|
5
|
-
import fs from 'node:fs';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
|
|
8
|
-
export const DATA_DIR = path.resolve(process.env.AGENTPEN_DATA || 'data');
|
|
9
|
-
export const RECORDINGS_DIR = path.join(DATA_DIR, 'recordings');
|
|
10
|
-
fs.mkdirSync(RECORDINGS_DIR, { recursive: true });
|
|
11
|
-
// Checkpoints: the agent's conversation and the host's unpushed code, so a
|
|
12
|
-
// teammate can carry on when the host's laptop is shut.
|
|
13
|
-
export const HANDOFF_DIR = path.join(DATA_DIR, 'handoffs');
|
|
14
|
-
fs.mkdirSync(HANDOFF_DIR, { recursive: true });
|
|
15
|
-
|
|
16
|
-
export const db = new DatabaseSync(path.join(DATA_DIR, 'agentpen.db'));
|
|
17
|
-
db.exec(`
|
|
18
|
-
PRAGMA journal_mode = WAL;
|
|
19
|
-
PRAGMA foreign_keys = ON;
|
|
20
|
-
|
|
21
|
-
CREATE TABLE IF NOT EXISTS users (
|
|
22
|
-
id TEXT PRIMARY KEY,
|
|
23
|
-
email TEXT NOT NULL UNIQUE,
|
|
24
|
-
name TEXT NOT NULL,
|
|
25
|
-
created_at INTEGER NOT NULL
|
|
26
|
-
);
|
|
27
|
-
CREATE TABLE IF NOT EXISTS workspaces (
|
|
28
|
-
id TEXT PRIMARY KEY,
|
|
29
|
-
slug TEXT NOT NULL UNIQUE,
|
|
30
|
-
name TEXT NOT NULL,
|
|
31
|
-
domain TEXT, -- verified email domain of the creator
|
|
32
|
-
domain_join INTEGER NOT NULL DEFAULT 0,
|
|
33
|
-
default_access TEXT NOT NULL DEFAULT 'control',
|
|
34
|
-
invite_code TEXT NOT NULL UNIQUE,
|
|
35
|
-
slack_webhook TEXT,
|
|
36
|
-
plan TEXT NOT NULL DEFAULT 'free',
|
|
37
|
-
created_at INTEGER NOT NULL
|
|
38
|
-
);
|
|
39
|
-
CREATE TABLE IF NOT EXISTS memberships (
|
|
40
|
-
workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
|
|
41
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
42
|
-
role TEXT NOT NULL, -- owner | admin | member
|
|
43
|
-
created_at INTEGER NOT NULL,
|
|
44
|
-
PRIMARY KEY (workspace_id, user_id)
|
|
45
|
-
);
|
|
46
|
-
CREATE TABLE IF NOT EXISTS invites (
|
|
47
|
-
token_hash TEXT PRIMARY KEY,
|
|
48
|
-
workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
|
|
49
|
-
email TEXT NOT NULL,
|
|
50
|
-
role TEXT NOT NULL,
|
|
51
|
-
invited_by TEXT NOT NULL,
|
|
52
|
-
expires_at INTEGER NOT NULL,
|
|
53
|
-
created_at INTEGER NOT NULL
|
|
54
|
-
);
|
|
55
|
-
-- kind: login (magic link) | web (browser cookie) | cli (bearer token)
|
|
56
|
-
CREATE TABLE IF NOT EXISTS tokens (
|
|
57
|
-
hash TEXT PRIMARY KEY,
|
|
58
|
-
kind TEXT NOT NULL,
|
|
59
|
-
user_id TEXT,
|
|
60
|
-
email TEXT,
|
|
61
|
-
label TEXT,
|
|
62
|
-
expires_at INTEGER NOT NULL,
|
|
63
|
-
created_at INTEGER NOT NULL
|
|
64
|
-
);
|
|
65
|
-
CREATE TABLE IF NOT EXISTS device_codes (
|
|
66
|
-
device_hash TEXT PRIMARY KEY,
|
|
67
|
-
user_code TEXT NOT NULL UNIQUE,
|
|
68
|
-
label TEXT,
|
|
69
|
-
user_id TEXT,
|
|
70
|
-
expires_at INTEGER NOT NULL
|
|
71
|
-
);
|
|
72
|
-
CREATE TABLE IF NOT EXISTS sessions (
|
|
73
|
-
id TEXT PRIMARY KEY,
|
|
74
|
-
workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
|
|
75
|
-
host_id TEXT NOT NULL REFERENCES users(id),
|
|
76
|
-
title TEXT NOT NULL,
|
|
77
|
-
agent TEXT NOT NULL,
|
|
78
|
-
project TEXT,
|
|
79
|
-
branch TEXT,
|
|
80
|
-
access TEXT NOT NULL, -- control | view
|
|
81
|
-
status TEXT NOT NULL, -- live | ended
|
|
82
|
-
guest_hash TEXT,
|
|
83
|
-
started_at INTEGER NOT NULL,
|
|
84
|
-
ended_at INTEGER,
|
|
85
|
-
has_recording INTEGER NOT NULL DEFAULT 0
|
|
86
|
-
);
|
|
87
|
-
CREATE INDEX IF NOT EXISTS sessions_ws ON sessions(workspace_id, started_at DESC);
|
|
88
|
-
CREATE TABLE IF NOT EXISTS events (
|
|
89
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
90
|
-
workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
|
|
91
|
-
session_id TEXT,
|
|
92
|
-
actor TEXT, -- display name at the time
|
|
93
|
-
actor_id TEXT,
|
|
94
|
-
type TEXT NOT NULL,
|
|
95
|
-
detail TEXT,
|
|
96
|
-
at INTEGER NOT NULL
|
|
97
|
-
);
|
|
98
|
-
CREATE INDEX IF NOT EXISTS events_ws ON events(workspace_id, id DESC);
|
|
99
|
-
`);
|
|
100
|
-
|
|
101
|
-
// kind: terminal (a PTY stream) | thread (a Codex app conversation)
|
|
102
|
-
if (!db.prepare(`PRAGMA table_info(sessions)`).all().some((c) => c.name === 'kind')) {
|
|
103
|
-
db.exec(`ALTER TABLE sessions ADD COLUMN kind TEXT NOT NULL DEFAULT 'terminal'`);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!db.prepare(`PRAGMA table_info(users)`).all().some((c) => c.name === 'prefs')) {
|
|
107
|
-
db.exec(`ALTER TABLE users ADD COLUMN prefs TEXT`);
|
|
108
|
-
}
|
|
109
|
-
db.exec(`
|
|
110
|
-
CREATE TABLE IF NOT EXISTS notifications (
|
|
111
|
-
id TEXT PRIMARY KEY,
|
|
112
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
113
|
-
kind TEXT NOT NULL,
|
|
114
|
-
title TEXT NOT NULL,
|
|
115
|
-
body TEXT,
|
|
116
|
-
session_id TEXT,
|
|
117
|
-
reply TEXT,
|
|
118
|
-
urgent INTEGER NOT NULL DEFAULT 0,
|
|
119
|
-
at INTEGER NOT NULL
|
|
120
|
-
);
|
|
121
|
-
CREATE INDEX IF NOT EXISTS notifications_user ON notifications(user_id, at DESC);
|
|
122
|
-
`);
|
|
123
|
-
|
|
124
|
-
for (const [table, col, ddl] of [
|
|
125
|
-
['sessions', 'handoff_at', 'INTEGER'], ['sessions', 'handoff_meta', 'TEXT'], ['sessions', 'end_reason', 'TEXT'],
|
|
126
|
-
['workspaces', 'handoff', 'INTEGER NOT NULL DEFAULT 1'], ['workspaces', 'anthropic_key', 'TEXT'], ['workspaces', 'agent_config', 'TEXT'],
|
|
127
|
-
['sessions', 'summary', 'TEXT'], ['sessions', 'summary_at', 'INTEGER'],
|
|
128
|
-
]) {
|
|
129
|
-
if (!db.prepare(`PRAGMA table_info(${table})`).all().some((c) => c.name === col)) db.exec(`ALTER TABLE ${table} ADD COLUMN ${col} ${ddl}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// A crash leaves rows marked live with no host behind them.
|
|
133
|
-
db.prepare(`UPDATE sessions SET status='ended', ended_at=COALESCE(ended_at, ?) WHERE status='live'`).run(Date.now());
|
|
134
|
-
|
|
135
|
-
export const now = () => Date.now();
|
|
136
|
-
export const id = (n = 12) => randomBytes(n).toString('base64url').replace(/[-_]/g, 'x').slice(0, n);
|
|
137
|
-
export const secret = () => randomBytes(32).toString('base64url');
|
|
138
|
-
export const sha = (s) => createHash('sha256').update(s).digest('hex');
|
|
139
|
-
|
|
140
|
-
export const q = {
|
|
141
|
-
get: (sql, ...a) => db.prepare(sql).get(...a),
|
|
142
|
-
all: (sql, ...a) => db.prepare(sql).all(...a),
|
|
143
|
-
run: (sql, ...a) => db.prepare(sql).run(...a),
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export function audit(workspaceId, type, { session = null, actor = null, detail = null } = {}) {
|
|
147
|
-
q.run(
|
|
148
|
-
`INSERT INTO events (workspace_id, session_id, actor, actor_id, type, detail, at) VALUES (?,?,?,?,?,?,?)`,
|
|
149
|
-
workspaceId, session, actor?.name ?? null, actor?.id ?? null, type, detail, now(),
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Seats per plan. Billing itself is external (AGENTPEN_UPGRADE_URL); the
|
|
154
|
-
// server only enforces what the plan column says.
|
|
155
|
-
export const PLANS = {
|
|
156
|
-
free: { seats: 5, label: 'Free' },
|
|
157
|
-
team: { seats: 200, label: 'Team' },
|
|
158
|
-
enterprise: { seats: Infinity, label: 'Enterprise' },
|
|
159
|
-
};
|
|
160
|
-
export const seatsUsed = (wsId) => q.get(`SELECT COUNT(*) n FROM memberships WHERE workspace_id=?`, wsId).n;
|
|
161
|
-
export const hasSeat = (ws) => seatsUsed(ws.id) < (PLANS[ws.plan] || PLANS.free).seats;
|