pisha-server 0.0.0-stage → 0.0.11
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 +40 -2
- package/accounts/accounts.js +754 -0
- package/accounts/index.js +1 -0
- package/accounts/passwords.js +41 -0
- package/accounts/totp.js +54 -0
- package/boards/boards.js +1079 -0
- package/boards/github.js +212 -0
- package/boards/index.js +1 -0
- package/boards/sync.js +980 -0
- package/companies.js +294 -0
- package/company-export.js +101 -0
- package/company.js +79 -0
- package/dashboard/dashboard.js +407 -0
- package/dashboard/index.js +1 -0
- package/data-upgrade.js +69 -0
- package/install/linux.sh +181 -0
- package/install/macos.sh +121 -0
- package/install/windows.bat +54 -0
- package/machines/index.js +3 -0
- package/machines/machines.js +910 -0
- package/messaging/inbox.js +252 -0
- package/messaging/index.js +3 -0
- package/messaging/messaging.js +551 -0
- package/messaging/plans.js +67 -0
- package/observation/index.js +1 -0
- package/observation/observation.js +224 -0
- package/organization/index.js +1 -0
- package/organization/organization.js +218 -0
- package/package.json +54 -4
- package/permissions/index.js +1 -0
- package/permissions/permissions.js +211 -0
- package/pisha-host.mjs +3297 -0
- package/pisha-host.mjs.sig +1 -0
- package/platform/acme.js +207 -0
- package/platform/basics.js +14 -0
- package/platform/config.js +154 -0
- package/platform/control.js +93 -0
- package/platform/credentials.js +151 -0
- package/platform/database.js +251 -0
- package/platform/errors.js +13 -0
- package/platform/files.js +50 -0
- package/platform/http.js +207 -0
- package/platform/index.js +58 -0
- package/platform/limits.js +122 -0
- package/platform/listen.js +183 -0
- package/platform/roles.js +6 -0
- package/platform/stream.js +19 -0
- package/platform/text.js +83 -0
- package/platform/ws.js +186 -0
- package/routes.js +405 -0
- package/server.js +65 -0
- package/sessions/index.js +1 -0
- package/sessions/sessions.js +533 -0
- package/ui/LICENSE-affectui.txt +26 -0
- package/ui/addmachine.js +151 -0
- package/ui/api.js +20 -0
- package/ui/app.js +143 -0
- package/ui/attention.js +78 -0
- package/ui/back.js +166 -0
- package/ui/boards.js +958 -0
- package/ui/chat.js +388 -0
- package/ui/content.js +157 -0
- package/ui/dialogs.js +135 -0
- package/ui/doing.js +112 -0
- package/ui/dom.js +6 -0
- package/ui/ds-base.css +146 -0
- package/ui/ds-components.css +229 -0
- package/ui/fonts/LICENSE-space-grotesk.txt +93 -0
- package/ui/fonts/space-grotesk-latin-700-normal.woff2 +0 -0
- package/ui/fonts/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/ui/format.js +25 -0
- package/ui/i18n.js +2093 -0
- package/ui/icons/apple-touch-icon.png +0 -0
- package/ui/icons/icon-192.png +0 -0
- package/ui/icons/icon-512.png +0 -0
- package/ui/icons/maskable-512.png +0 -0
- package/ui/icons.js +40 -0
- package/ui/inbox.js +535 -0
- package/ui/index.html +103 -0
- package/ui/machines.js +261 -0
- package/ui/manifest.webmanifest +16 -0
- package/ui/mosaic.js +189 -0
- package/ui/nav.js +141 -0
- package/ui/newteam.js +223 -0
- package/ui/org.js +653 -0
- package/ui/overlays.css +126 -0
- package/ui/palette.js +179 -0
- package/ui/people.js +370 -0
- package/ui/permissions.js +202 -0
- package/ui/qr.js +158 -0
- package/ui/router.js +171 -0
- package/ui/routes.js +46 -0
- package/ui/screen-boards.css +241 -0
- package/ui/screen-inbox.css +201 -0
- package/ui/screen-machines.css +76 -0
- package/ui/screen-mosaic.css +26 -0
- package/ui/screen-newteam.css +90 -0
- package/ui/screen-org.css +113 -0
- package/ui/screen-session.css +99 -0
- package/ui/screen-signin.css +28 -0
- package/ui/screen-team.css +80 -0
- package/ui/screen-teams.css +41 -0
- package/ui/session.js +42 -0
- package/ui/shell.css +122 -0
- package/ui/signin.js +120 -0
- package/ui/squads.js +370 -0
- package/ui/state.js +59 -0
- package/ui/stream.js +268 -0
- package/ui/styles.css +343 -0
- package/ui/team.js +115 -0
- package/ui/teams.js +58 -0
- package/ui/terminal.js +261 -0
- package/ui/theme.js +32 -0
- package/ui/timeline.js +163 -0
- package/ui/topbar.js +205 -0
- package/ui/voice-parse.js +98 -0
- package/ui/voice.js +320 -0
- package/vendor/InterVariable.woff2 +0 -0
- package/vendor/LICENSE-inter +92 -0
- package/vendor/LICENSE-xterm +21 -0
- package/vendor/README.md +8 -0
- package/vendor/addon-fit.js +2 -0
- package/vendor/xterm.css +218 -0
- package/vendor/xterm.js +2 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto'
|
|
2
|
+
import { bad, now, oneLine, cleanText } from '../platform/index.js'
|
|
3
|
+
|
|
4
|
+
// Permission profiles: what the agents of a team may do without asking,
|
|
5
|
+
// written in the dashboard and turned into Claude Code's own permission rules
|
|
6
|
+
// (allow, ask, deny), which its machine passes to each session it opens from
|
|
7
|
+
// the dashboard (claude --settings). Claude Code enforces them, not the model;
|
|
8
|
+
// what the user wrote in their own words goes to the session's system prompt
|
|
9
|
+
// too, as the reason. Each machine decides how far the dashboard may go
|
|
10
|
+
// ("permissions_from_dashboard" in its settings.json): pisha-host checks
|
|
11
|
+
// every rule again and refuses what it doesn't take.
|
|
12
|
+
//
|
|
13
|
+
// A profile is a few capabilities, each allowed, always asked or forbidden
|
|
14
|
+
// (left out: Claude Code decides, as without a profile), and rules of its own.
|
|
15
|
+
|
|
16
|
+
// What each capability is, as rules. deny: what forbidding it denies (when
|
|
17
|
+
// it isn't the same list).
|
|
18
|
+
export const CAPABILITIES = {
|
|
19
|
+
edit: { rules: ['Edit(./**)'], deny: ['Edit(**)'] },
|
|
20
|
+
tests: {
|
|
21
|
+
rules: [
|
|
22
|
+
'Bash(npm test *)', 'Bash(npm run test *)', 'Bash(npm run build *)', 'Bash(npm run lint *)', 'Bash(pnpm test *)', 'Bash(pnpm run test *)',
|
|
23
|
+
'Bash(yarn test *)', 'Bash(npx vitest *)', 'Bash(npx jest *)', 'Bash(npx playwright test *)', 'Bash(node --test *)', 'Bash(pytest *)',
|
|
24
|
+
'Bash(python -m pytest *)', 'Bash(python3 -m pytest *)', 'Bash(go test *)', 'Bash(go build *)', 'Bash(cargo test *)', 'Bash(cargo build *)',
|
|
25
|
+
'Bash(make test *)', 'Bash(php artisan test *)', 'Bash(vendor/bin/phpunit *)', 'Bash(composer test *)', 'Bash(dotnet test *)', 'Bash(mvn test *)',
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
install: {
|
|
29
|
+
rules: [
|
|
30
|
+
'Bash(npm install *)', 'Bash(npm ci *)', 'Bash(pnpm install *)', 'Bash(pnpm add *)', 'Bash(yarn install *)', 'Bash(yarn add *)',
|
|
31
|
+
'Bash(pip install *)', 'Bash(pip3 install *)', 'Bash(composer install *)', 'Bash(composer require *)', 'Bash(bundle install *)',
|
|
32
|
+
'Bash(go mod download *)', 'Bash(cargo fetch *)',
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
commit: {
|
|
36
|
+
rules: [
|
|
37
|
+
'Bash(git status *)', 'Bash(git diff *)', 'Bash(git log *)', 'Bash(git show *)', 'Bash(git add *)', 'Bash(git commit *)',
|
|
38
|
+
'Bash(git restore *)', 'Bash(git stash *)', 'Bash(git switch *)', 'Bash(git branch *)',
|
|
39
|
+
],
|
|
40
|
+
deny: ['Bash(git commit *)'],
|
|
41
|
+
},
|
|
42
|
+
push: { rules: ['Bash(git push *)'] },
|
|
43
|
+
history: { rules: ['Bash(git push --force *)', 'Bash(git push -f *)', 'Bash(git push --force-with-lease *)', 'Bash(git reset --hard *)', 'Bash(git clean *)', 'Bash(git rebase *)'] },
|
|
44
|
+
remove: { rules: ['Bash(rm *)', 'Bash(rmdir *)', 'Bash(git rm *)'] },
|
|
45
|
+
web: { rules: ['WebFetch', 'WebSearch'] },
|
|
46
|
+
docker: { rules: ['Bash(docker *)', 'Bash(docker-compose *)'] },
|
|
47
|
+
sudo: { rules: ['Bash(sudo *)'] },
|
|
48
|
+
}
|
|
49
|
+
export const CAPABILITY_IDS = Object.keys(CAPABILITIES)
|
|
50
|
+
const STATES = ['allow', 'ask', 'deny']
|
|
51
|
+
|
|
52
|
+
// Two to start from, as they are (a copy can be changed).
|
|
53
|
+
export const BUILTIN_PROFILES = [
|
|
54
|
+
{
|
|
55
|
+
id: 'readonly', builtin: true, name: 'Read only', notes: '',
|
|
56
|
+
caps: { edit: 'deny', install: 'deny', commit: 'deny', push: 'deny', history: 'deny', remove: 'deny', docker: 'deny', sudo: 'deny' },
|
|
57
|
+
extra: { allow: [], ask: [], deny: [] },
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'dev', builtin: true, name: 'Development', notes: '',
|
|
61
|
+
caps: { edit: 'allow', tests: 'allow', install: 'allow', commit: 'allow', push: 'ask', history: 'deny', remove: 'ask', sudo: 'deny' },
|
|
62
|
+
extra: { allow: [], ask: [], deny: [] },
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
// A rule as Claude Code writes them: a tool, and what it applies to. (Its
|
|
67
|
+
// machine checks each one again, with what it takes from the dashboard.)
|
|
68
|
+
export const RULE_RE = /^(?:(?:Bash|PowerShell|Read|Edit|Write|NotebookEdit|WebFetch|WebSearch|Glob|Grep|Agent|Skill)(?:\((?:[^()\x00-\x1f\x7f]|\([^()\x00-\x1f\x7f]*\)){1,300}\))?|mcp__[A-Za-z0-9_-]+(?:__(?:[A-Za-z0-9_-]+|\*))?)$/
|
|
69
|
+
const RULES_MAX = 100
|
|
70
|
+
const NOTES_MAX = 2000
|
|
71
|
+
const PROFILES_MAX = 50
|
|
72
|
+
const ID_RE = /^(?:readonly|dev|p_[A-Za-z0-9_-]{8,24})$/
|
|
73
|
+
export const NONE = 'none' // a session that follows no profile, whatever its team's
|
|
74
|
+
|
|
75
|
+
export function createPermissions(platform, { sessions }) {
|
|
76
|
+
const { db, broadcast } = platform
|
|
77
|
+
const { NAME_RE } = sessions
|
|
78
|
+
|
|
79
|
+
db.exec(`CREATE TABLE IF NOT EXISTS permission_profiles (
|
|
80
|
+
id TEXT PRIMARY KEY, name TEXT NOT NULL, notes TEXT, caps TEXT NOT NULL, extra TEXT NOT NULL, updated_at INTEGER NOT NULL)`)
|
|
81
|
+
for (const [table, column] of [['squads', 'profile'], ['identities', 'permission_profile']]) {
|
|
82
|
+
if (!db.prepare(`PRAGMA table_info(${table})`).all().some(c => c.name === column)) db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} TEXT`)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const parse = (s, dflt) => { try { const v = JSON.parse(s); return v && typeof v === 'object' ? v : dflt } catch { return dflt } }
|
|
86
|
+
function listProfiles() {
|
|
87
|
+
const own = db.prepare('SELECT * FROM permission_profiles ORDER BY name COLLATE NOCASE').all()
|
|
88
|
+
.map(r => ({ id: r.id, builtin: false, name: r.name, notes: r.notes || '', caps: parse(r.caps, {}), extra: { allow: [], ask: [], deny: [], ...parse(r.extra, {}) }, updated_at: r.updated_at }))
|
|
89
|
+
return [...BUILTIN_PROFILES, ...own]
|
|
90
|
+
}
|
|
91
|
+
const profileById = id => listProfiles().find(p => p.id === id) ?? null
|
|
92
|
+
|
|
93
|
+
// What the dashboard sends, checked: anything unexpected is refused.
|
|
94
|
+
function cleanRules(list, what) {
|
|
95
|
+
if (list == null) return []
|
|
96
|
+
if (!Array.isArray(list)) throw bad(`${what} must be a list of rules`)
|
|
97
|
+
const out = []
|
|
98
|
+
for (const raw of list) {
|
|
99
|
+
const r = typeof raw === 'string' ? raw.trim() : ''
|
|
100
|
+
if (!r) continue
|
|
101
|
+
if (!RULE_RE.test(r)) throw bad(`"${cleanText(r.slice(0, 80))}" is not a Claude Code permission rule (e.g. Bash(make deploy *), Edit(./docs/**), WebFetch(domain:example.com))`)
|
|
102
|
+
if (!out.includes(r)) out.push(r)
|
|
103
|
+
}
|
|
104
|
+
return out
|
|
105
|
+
}
|
|
106
|
+
function cleanProfile(p) {
|
|
107
|
+
const name = oneLine(p.name, 40)
|
|
108
|
+
if (!name) throw bad('the profile needs a name')
|
|
109
|
+
const notes = typeof p.notes === 'string' ? cleanText(p.notes.slice(0, NOTES_MAX * 2)).trim().slice(0, NOTES_MAX) : ''
|
|
110
|
+
const caps = {}
|
|
111
|
+
for (const [k, v] of Object.entries(p.caps && typeof p.caps === 'object' ? p.caps : {})) {
|
|
112
|
+
if (!CAPABILITY_IDS.includes(k)) throw bad(`unknown capability "${cleanText(String(k).slice(0, 40))}"`)
|
|
113
|
+
if (v == null || v === '' || v === 'default') continue
|
|
114
|
+
if (!STATES.includes(v)) throw bad(`${k}: must be allow, ask or deny`)
|
|
115
|
+
caps[k] = v
|
|
116
|
+
}
|
|
117
|
+
const e = p.extra && typeof p.extra === 'object' ? p.extra : {}
|
|
118
|
+
const extra = { allow: cleanRules(e.allow, 'allow'), ask: cleanRules(e.ask, 'ask'), deny: cleanRules(e.deny, 'deny') }
|
|
119
|
+
if (extra.allow.length + extra.ask.length + extra.deny.length > RULES_MAX) throw bad(`at most ${RULES_MAX} rules of its own`)
|
|
120
|
+
return { name, notes, caps, extra }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function saveProfile(p) {
|
|
124
|
+
const id = p.id == null || p.id === '' ? null : String(p.id)
|
|
125
|
+
if (id && !ID_RE.test(id)) throw bad('invalid profile id')
|
|
126
|
+
if (id && BUILTIN_PROFILES.some(b => b.id === id)) throw bad('the built-in profiles are kept as they are: make a copy to change it')
|
|
127
|
+
const v = cleanProfile(p)
|
|
128
|
+
const others = listProfiles().filter(x => x.id !== id)
|
|
129
|
+
if (others.some(x => x.name.toLowerCase() === v.name.toLowerCase())) throw bad(`there is already a profile called "${v.name}"`)
|
|
130
|
+
if (id && !db.prepare('SELECT 1 FROM permission_profiles WHERE id = ?').get(id)) throw bad('profile not found')
|
|
131
|
+
if (!id && db.prepare('SELECT COUNT(*) AS n FROM permission_profiles').get().n >= PROFILES_MAX) throw bad(`at most ${PROFILES_MAX} profiles`)
|
|
132
|
+
const newId = id ?? `p_${randomBytes(9).toString('base64url')}`
|
|
133
|
+
db.prepare(`INSERT INTO permission_profiles (id, name, notes, caps, extra, updated_at) VALUES (?, ?, ?, ?, ?, ?)
|
|
134
|
+
ON CONFLICT(id) DO UPDATE SET name = excluded.name, notes = excluded.notes, caps = excluded.caps, extra = excluded.extra, updated_at = excluded.updated_at`)
|
|
135
|
+
.run(newId, v.name, v.notes || null, JSON.stringify(v.caps), JSON.stringify(v.extra), now())
|
|
136
|
+
broadcastAll()
|
|
137
|
+
return profileById(newId)
|
|
138
|
+
}
|
|
139
|
+
function deleteProfile(p) {
|
|
140
|
+
const id = String(p.id ?? '')
|
|
141
|
+
if (BUILTIN_PROFILES.some(b => b.id === id)) throw bad('the built-in profiles cannot be deleted')
|
|
142
|
+
if (!db.prepare('DELETE FROM permission_profiles WHERE id = ?').run(id).changes) throw bad('profile not found')
|
|
143
|
+
// (Teams and sessions that had it follow none now, as before it existed.)
|
|
144
|
+
db.prepare('UPDATE squads SET profile = NULL WHERE profile = ?').run(id)
|
|
145
|
+
db.prepare('UPDATE identities SET permission_profile = NULL WHERE permission_profile = ?').run(id)
|
|
146
|
+
broadcastAll()
|
|
147
|
+
return { id, deleted: true }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Which profile a team follows (its coordinator's name), or a session on
|
|
151
|
+
// its own (NONE: none, whatever its team's; null: its team's).
|
|
152
|
+
function assignProfile(p) {
|
|
153
|
+
const profile = p.profile == null || p.profile === '' ? null : String(p.profile)
|
|
154
|
+
if (profile && profile !== NONE && !profileById(profile)) throw bad('profile not found')
|
|
155
|
+
if (p.coordinator != null) {
|
|
156
|
+
const coordinator = String(p.coordinator)
|
|
157
|
+
if (!NAME_RE.test(coordinator)) throw bad('invalid coordinator')
|
|
158
|
+
if (profile === NONE) throw bad('a team follows a profile or none (leave it empty)')
|
|
159
|
+
db.prepare(`INSERT INTO squads (coordinator, profile, updated_at) VALUES (?, ?, ?)
|
|
160
|
+
ON CONFLICT(coordinator) DO UPDATE SET profile = excluded.profile, updated_at = excluded.updated_at`).run(coordinator, profile, now())
|
|
161
|
+
broadcast('profiles', state())
|
|
162
|
+
return { coordinator, profile }
|
|
163
|
+
}
|
|
164
|
+
const name = String(p.session ?? '')
|
|
165
|
+
if (!NAME_RE.test(name) || !db.prepare('SELECT 1 FROM identities WHERE name = ?').get(name)) throw bad('session not found')
|
|
166
|
+
db.prepare('UPDATE identities SET permission_profile = ? WHERE name = ?').run(profile, name)
|
|
167
|
+
broadcast('profiles', state())
|
|
168
|
+
return { session: name, profile }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// What the dashboard shows: the profiles, and who follows which.
|
|
172
|
+
function state() {
|
|
173
|
+
return {
|
|
174
|
+
profiles: listProfiles(),
|
|
175
|
+
teams: Object.fromEntries(db.prepare('SELECT coordinator, profile FROM squads WHERE profile IS NOT NULL').all().map(r => [r.coordinator, r.profile])),
|
|
176
|
+
sessions: Object.fromEntries(db.prepare('SELECT name, permission_profile FROM identities WHERE permission_profile IS NOT NULL').all().map(r => [r.name, r.permission_profile])),
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const broadcastAll = () => broadcast('profiles', state())
|
|
180
|
+
|
|
181
|
+
// The profile a session opened from the dashboard follows: its own, else its
|
|
182
|
+
// team's (a coordinator's own squad; a worker's coordinator's). null: none.
|
|
183
|
+
function effectiveProfile(name, role, coordinator) {
|
|
184
|
+
const own = db.prepare('SELECT permission_profile FROM identities WHERE name = ?').get(name)?.permission_profile ?? null
|
|
185
|
+
if (own === NONE) return null
|
|
186
|
+
const team = role === 'coordinator' ? name : role === 'worker' ? coordinator : null
|
|
187
|
+
const id = own ?? (team ? db.prepare('SELECT profile FROM squads WHERE coordinator = ?').get(team)?.profile ?? null : null)
|
|
188
|
+
return id ? profileById(id) : null
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// A profile as Claude Code's rules (and its words, for the system prompt).
|
|
192
|
+
// A capability forbidden wins over one allowed that shares a rule.
|
|
193
|
+
function compile(profile) {
|
|
194
|
+
if (!profile) return null
|
|
195
|
+
const allow = [], ask = [], deny = []
|
|
196
|
+
const add = (list, rules) => { for (const r of rules) if (!list.includes(r)) list.push(r) }
|
|
197
|
+
for (const id of CAPABILITY_IDS) {
|
|
198
|
+
const state = profile.caps?.[id]
|
|
199
|
+
const cap = CAPABILITIES[id]
|
|
200
|
+
if (state === 'allow') add(allow, cap.rules)
|
|
201
|
+
else if (state === 'ask') add(ask, cap.rules)
|
|
202
|
+
else if (state === 'deny') add(deny, cap.deny ?? cap.rules)
|
|
203
|
+
}
|
|
204
|
+
add(allow, profile.extra?.allow ?? [])
|
|
205
|
+
add(ask, profile.extra?.ask ?? [])
|
|
206
|
+
add(deny, profile.extra?.deny ?? [])
|
|
207
|
+
return { id: profile.id, name: profile.name, allow, ask, deny, notes: profile.notes || '' }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { listProfiles, saveProfile, deleteProfile, assignProfile, permissionsState: state, effectiveProfile, compile, NONE }
|
|
211
|
+
}
|