shapewall 0.3.3 → 0.7.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/CHANGELOG.md +501 -0
- package/README.md +87 -4
- package/THIRD_PARTY.md +15 -0
- package/dist/agent/package-lock.json +594 -2
- package/dist/client/assets/BoardChat-WS8mAIW6.js +27 -0
- package/dist/client/assets/{BuzzDialog-Ix9qJvim.js → BuzzDialog-B-Mlr6wF.js} +1 -1
- package/dist/client/assets/ChecksPanel-Dx1ZLBR6.js +1 -0
- package/dist/client/assets/History-sXhmpcvs.js +1 -0
- package/dist/client/assets/LocalSettings-CtGzz9F3.js +1 -0
- package/dist/client/assets/{Management-NVFDtSZB.js → Management-CGHe8Wt9.js} +1 -1
- package/dist/client/assets/QuickConnect-DEk84E4A.js +1 -0
- package/dist/client/assets/{ShareDialog-By0ETg6n.js → ShareDialog-CGGx-AYK.js} +2 -2
- package/dist/client/assets/{app-update-dialog-RGIw24iZ.js → app-update-dialog-_bVp8hnC.js} +1 -1
- package/dist/client/assets/{circle-x-B6KfScOE.js → circle-x-BWoHA1QY.js} +1 -1
- package/dist/client/assets/index-Bm-Xd3YN.js +37 -0
- package/dist/client/assets/index-C7Ostk3K.css +2 -0
- package/dist/client/assets/play-BzQ3tRTv.js +1 -0
- package/dist/client/assets/{refresh-cw-vkgvCCfR.js → refresh-cw-BYBMyDKT.js} +1 -1
- package/dist/client/assets/{runtime-Bft6x_6E.js → runtime-Bvq10IhH.js} +1 -1
- package/dist/client/assets/ui-CAY6myRA.js +41 -0
- package/dist/client/build-info.json +1 -1
- package/dist/client/index.html +3 -3
- package/dist/client/sw.js +2 -2
- package/dist/console/assets/LocalAccountsApp-CWRguRRL.js +1 -0
- package/dist/console/assets/LocalConsole--I2SaIpr.js +2 -0
- package/dist/console/assets/LocalUsage-BmpCZ36k.js +1 -0
- package/dist/console/assets/app-update-dialog-B8M9plaT.js +1 -0
- package/dist/console/assets/app-version-muKrQqbL.js +1 -0
- package/dist/console/assets/console-CrhTsPbz.css +2 -0
- package/dist/console/assets/console-DxapQ9oS.js +11 -0
- package/dist/console/assets/local-agents-CoqD4dSN.js +6 -0
- package/dist/console/assets/minus-DDQ0ydcM.js +1 -0
- package/dist/console/assets/tailnet-C5Flwl_d.js +2 -0
- package/dist/console/assets/theme-DCd0qh4l.js +1 -0
- package/dist/console/assets/ui-Bry1mnCY.js +41 -0
- package/dist/console/assets/usage-CIPWnHaS.css +1 -0
- package/dist/console/assets/usage-CqVjMb7m.js +5 -0
- package/dist/console/assets/usage-D1G0GgE3.js +56 -0
- package/dist/console/build-info.json +1 -1
- package/dist/console/console.html +8 -2
- package/docs/agent-hardening.md +206 -0
- package/docs/agent-recipes.md +23 -0
- package/docs/agent-workflow.md +5 -0
- package/docs/agents.md +49 -6
- package/docs/architecture.md +10 -4
- package/docs/deployment.md +39 -17
- package/docs/design-system.md +56 -7
- package/docs/hosted.md +1800 -46
- package/docs/images/board-overview.png +0 -0
- package/docs/images/journeys.png +0 -0
- package/docs/images/live-comment.png +0 -0
- package/docs/images/phone-comment.png +0 -0
- package/docs/images/phone-overview.png +0 -0
- package/docs/images/variant.png +0 -0
- package/docs/where-to-run.md +119 -3
- package/package.json +6 -1
- package/src/agent/backends/acp.js +745 -44
- package/src/agent/branch-mode.js +17 -3
- package/src/agent/card-hash.js +65 -0
- package/src/agent/context.js +41 -0
- package/src/agent/exec-paths.js +105 -0
- package/src/agent/routes.js +23 -2
- package/src/agent/run.js +11 -1
- package/src/agent/starter/cli.js +6 -1
- package/src/agent/turn-changes.js +70 -8
- package/src/agent/usage-log.js +251 -0
- package/src/cli/args.js +37 -0
- package/src/cli/commands.js +20 -5
- package/src/cli/help.js +73 -3
- package/src/cli/init.js +2 -1
- package/src/cli/serve.js +20 -5
- package/src/cli.js +8 -0
- package/src/hosted/access-cli.js +99 -1
- package/src/hosted/activity-core.js +232 -0
- package/src/hosted/activity.js +375 -0
- package/src/hosted/admin.js +87 -13
- package/src/hosted/agent-approvals.js +29 -4
- package/src/hosted/agent-link.js +1032 -0
- package/src/hosted/agent-policy.js +10 -3
- package/src/hosted/agent-presence.js +63 -22
- package/src/hosted/agent-routes.js +135 -0
- package/src/hosted/agents.js +1206 -0
- package/src/hosted/app.js +178 -12
- package/src/hosted/auth-routes.js +156 -15
- package/src/hosted/auth.js +123 -20
- package/src/hosted/board-routes.js +129 -5
- package/src/hosted/chat-frames.js +246 -0
- package/src/hosted/chat-job.js +204 -0
- package/src/hosted/chat-permissions.js +203 -0
- package/src/hosted/chat-routes.js +1009 -0
- package/src/hosted/chat-store.js +477 -0
- package/src/hosted/comment-files.js +11 -1
- package/src/hosted/comments.js +1 -1
- package/src/hosted/console-routes.js +122 -34
- package/src/hosted/db.js +295 -0
- package/src/hosted/device-routes.js +88 -10
- package/src/hosted/device.js +54 -4
- package/src/hosted/events.js +3 -3
- package/src/hosted/guards.js +337 -27
- package/src/hosted/http.js +6 -3
- package/src/hosted/membership.js +22 -3
- package/src/hosted/operator-access.js +418 -0
- package/src/hosted/operator.js +106 -2
- package/src/hosted/ops-cli.js +238 -3
- package/src/hosted/pages.js +4 -0
- package/src/hosted/passkey-policy.js +75 -0
- package/src/hosted/permissions.js +52 -6
- package/src/hosted/presence.js +31 -2
- package/src/hosted/projects.js +30 -2
- package/src/hosted/public.js +4 -4
- package/src/hosted/ratelimit.js +14 -0
- package/src/hosted/retention.js +18 -2
- package/src/hosted/server.js +123 -11
- package/src/hosted/shares.js +2 -2
- package/src/hosted/step-up-settings.js +68 -0
- package/src/hosted/step-up.js +135 -0
- package/src/hosted/tailnet-identity.js +24 -0
- package/src/hosted/tailnet-routes.js +342 -0
- package/src/hosted/tailnet.js +220 -0
- package/src/hosted/tailscale.js +75 -9
- package/src/hosted/tenancy.js +66 -1
- package/src/hosted/token-api.js +119 -20
- package/src/hosted/token-events.js +5 -3
- package/src/hosted/tokens.js +29 -6
- package/src/hosted/turn-hub.js +152 -0
- package/src/hosted/usage-core.js +624 -0
- package/src/hosted/usage-layout.js +724 -0
- package/src/hosted/usage-routes.js +375 -0
- package/src/hosted/usage-shape.js +256 -0
- package/src/hosted/usage.js +641 -0
- package/src/remote/agent-connect.js +469 -0
- package/src/remote/agent-fix.js +611 -0
- package/src/remote/agent-job.js +216 -0
- package/src/remote/agent-link.js +906 -0
- package/src/remote/agent-policy-file.js +242 -0
- package/src/remote/credentials.js +35 -1
- package/src/remote/login.js +44 -9
- package/src/remote/share.js +1 -1
- package/src/remote/tailnet-cli.js +547 -0
- package/src/server/app.js +15 -0
- package/src/server/pairing-routes.js +34 -5
- package/src/server/tailscale.js +97 -4
- package/src/tailnet-proof.js +766 -0
- package/dist/client/assets/BoardChat-DxehB761.js +0 -27
- package/dist/client/assets/ChecksPanel-pA_ueIaJ.js +0 -1
- package/dist/client/assets/History-C9N32kCv.js +0 -1
- package/dist/client/assets/LocalSettings-DawtKnvi.js +0 -1
- package/dist/client/assets/QuickConnect-DO1TjS1t.js +0 -1
- package/dist/client/assets/index-CsqLdqGx.css +0 -2
- package/dist/client/assets/index-DnZarJ3U.js +0 -37
- package/dist/client/assets/shield-check-QzwGhz0t.js +0 -1
- package/dist/client/assets/ui-DI-FGWWK.js +0 -41
- package/dist/console/assets/LocalAccountsApp-VOCZg8dg.js +0 -1
- package/dist/console/assets/LocalConsole-CMwAW-mF.js +0 -1
- package/dist/console/assets/app-update-dialog-Cw6UDqNP.js +0 -1
- package/dist/console/assets/console-DgfWmUEx.js +0 -55
- package/dist/console/assets/console-Lis0vvdL.css +0 -2
|
@@ -8,13 +8,28 @@ import { ID_PATTERNS } from './crypto.js'
|
|
|
8
8
|
import { transaction } from './db.js'
|
|
9
9
|
import { HttpError, fail } from './http.js'
|
|
10
10
|
import { workspaceSuspended } from './operator.js'
|
|
11
|
-
import {
|
|
11
|
+
import { cleanAgentName, isAgentTint, isBuiltInIcon } from '../agent/identity.js'
|
|
12
|
+
import { AGENT_AUDIENCES, NEEDS } from './permissions.js'
|
|
12
13
|
import { createProjectStore } from './projects.js'
|
|
13
14
|
import { roleAtLeast, roleIn, tenant, workspacesForUser } from './tenancy.js'
|
|
14
15
|
import { TOKEN_SCOPES } from './tokens.js'
|
|
15
16
|
|
|
16
17
|
export function mountDeviceApprovals(consoleApi, deps) {
|
|
17
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
db,
|
|
20
|
+
dataDir,
|
|
21
|
+
now,
|
|
22
|
+
quotas,
|
|
23
|
+
deviceLogins,
|
|
24
|
+
clientIp,
|
|
25
|
+
limit,
|
|
26
|
+
handle,
|
|
27
|
+
stepUpOrThrow,
|
|
28
|
+
machineTokensOrThrow,
|
|
29
|
+
auditOf,
|
|
30
|
+
createApiToken,
|
|
31
|
+
agentsFor,
|
|
32
|
+
} = deps
|
|
18
33
|
|
|
19
34
|
// ---- `shapewall login`: approving a login in the console ----
|
|
20
35
|
// The CLI side (start, poll) is on /api/v1/device, without a session.
|
|
@@ -27,6 +42,8 @@ export function mountDeviceApprovals(consoleApi, deps) {
|
|
|
27
42
|
return {
|
|
28
43
|
code: formatUserCode(found.code),
|
|
29
44
|
purpose: found.entry.purpose,
|
|
45
|
+
// An agent connection: what the machine says it runs, and the name it suggests.
|
|
46
|
+
...(found.entry.purpose === 'agent' ? { agent: found.entry.agent } : {}),
|
|
30
47
|
name: found.entry.name,
|
|
31
48
|
ip: found.entry.ip,
|
|
32
49
|
approverIp,
|
|
@@ -54,19 +71,23 @@ export function mountDeviceApprovals(consoleApi, deps) {
|
|
|
54
71
|
name: item.name,
|
|
55
72
|
projects: createProjectStore(tenant(db, item.id), { db, dataDir })
|
|
56
73
|
.list()
|
|
57
|
-
.map((project) => ({ id: project.id, name: project.name })),
|
|
74
|
+
.map((project) => ({ id: project.id, name: project.name, slug: project.slug })),
|
|
58
75
|
}))
|
|
59
76
|
res.json({
|
|
60
77
|
login: devicePublic(found, req),
|
|
61
78
|
workspaces,
|
|
62
|
-
|
|
79
|
+
// An agent connection gets a fixed set (AGENT_LOGIN_SCOPES): nothing to tick.
|
|
80
|
+
scopes:
|
|
81
|
+
found.entry.purpose === 'agent'
|
|
82
|
+
? AGENT_LOGIN_SCOPES
|
|
83
|
+
: TOKEN_SCOPES.filter((scope) => scope !== 'agent' && (scope !== 'import' || found.entry.purpose === 'import')),
|
|
84
|
+
...(found.entry.purpose === 'agent' ? { audiences: AGENT_AUDIENCES } : {}),
|
|
63
85
|
})
|
|
64
86
|
}),
|
|
65
87
|
)
|
|
66
88
|
consoleApi.post(
|
|
67
89
|
'/device/approve',
|
|
68
90
|
limit('deviceLookup', (req) => req.user.id),
|
|
69
|
-
needFresh,
|
|
70
91
|
handle(async (req, res) => {
|
|
71
92
|
const found = deviceFound(req)
|
|
72
93
|
const ws = String(req.body?.workspaceId || '')
|
|
@@ -74,6 +95,13 @@ export function mountDeviceApprovals(consoleApi, deps) {
|
|
|
74
95
|
if (!role) throw new HttpError(404, 'unknown_workspace', 'No such workspace.')
|
|
75
96
|
if (!roleAtLeast(role, NEEDS.tokens)) throw new HttpError(403, 'forbidden', `This needs the ${NEEDS.tokens} role or higher.`)
|
|
76
97
|
req.t = tenant(db, ws)
|
|
98
|
+
// Approving a machine or an agent: the passkey again only when this workspace asks ("Agents and machines").
|
|
99
|
+
stepUpOrThrow(req, 'agents')
|
|
100
|
+
// A session that only a tailnet identity stands behind may approve by
|
|
101
|
+
// default (src/remote/tailnet-cli.js does, with no code); a workspace
|
|
102
|
+
// that switched on "Approve command line logins in the browser" wants
|
|
103
|
+
// the code and a passkey check (src/hosted/guards.js machineTokensOrThrow).
|
|
104
|
+
const identityOnly = machineTokensOrThrow(req)
|
|
77
105
|
if (workspaceSuspended(req.t))
|
|
78
106
|
throw new HttpError(403, 'workspace_suspended', 'This workspace is suspended by the server operator; it takes no new tokens.')
|
|
79
107
|
req.role = role
|
|
@@ -91,15 +119,44 @@ export function mountDeviceApprovals(consoleApi, deps) {
|
|
|
91
119
|
req.project = projectStore.create({ name: req.body.newProjectName, userId: req.user.id, now: now() })
|
|
92
120
|
auditOf(req, 'project_created', req.project.id)
|
|
93
121
|
}
|
|
122
|
+
const agentLogin = found.entry.purpose === 'agent'
|
|
123
|
+
// Connecting an agent: the approver names it, picks its icon and who
|
|
124
|
+
// may use it. The scopes are fixed, whatever the request says: what
|
|
125
|
+
// an agent works with, plus the link.
|
|
126
|
+
const look = agentLogin ? agentLook(req.body?.agent, found.entry) : null
|
|
127
|
+
if (!agentLogin && Array.isArray(req.body?.scopes) && req.body.scopes.includes('agent'))
|
|
128
|
+
throw new HttpError(403, 'agent_login_required', 'The agent scope comes from "shapewall agent connect".')
|
|
94
129
|
const token = createApiToken(
|
|
95
130
|
req,
|
|
96
131
|
{
|
|
97
|
-
name: `${found.entry.name} (shapewall login)`,
|
|
98
|
-
scopes: req.body?.scopes,
|
|
132
|
+
name: agentLogin ? look.name : `${found.entry.name} (shapewall login)`,
|
|
133
|
+
scopes: agentLogin ? AGENT_LOGIN_SCOPES : req.body?.scopes,
|
|
99
134
|
expiresInDays: req.body?.expiresInDays ?? null,
|
|
100
135
|
},
|
|
101
|
-
{
|
|
136
|
+
{
|
|
137
|
+
via: agentLogin ? 'agent' : found.entry.purpose === 'import' ? 'import' : 'login',
|
|
138
|
+
machine: found.entry.name,
|
|
139
|
+
...(identityOnly ? { approvedBy: 'tailnet identity' } : {}),
|
|
140
|
+
...(agentLogin ? { agent: { kind: found.entry.agent?.kind || 'custom', icon: look.icon, tint: look.tint } } : {}),
|
|
141
|
+
},
|
|
102
142
|
)
|
|
143
|
+
let agent = null
|
|
144
|
+
if (agentLogin) {
|
|
145
|
+
const actor = { userId: req.user.id, role: req.role, audit: (action, target, detail) => auditOf(req, action, target, detail) }
|
|
146
|
+
// A new agent is its connector's own; widening it is said here, on
|
|
147
|
+
// the approval, and written to the audit log like any other change.
|
|
148
|
+
if (look.audience !== 'owner')
|
|
149
|
+
agentsFor(req.t).setAudience(actor, req.project.id, token.agentId, { audience: look.audience, users: look.users })
|
|
150
|
+
auditOf(req, 'agent_connected', token.agentId, {
|
|
151
|
+
project: req.project.id,
|
|
152
|
+
name: look.name,
|
|
153
|
+
kind: found.entry.agent?.kind || 'custom',
|
|
154
|
+
machine: found.entry.name,
|
|
155
|
+
audience: look.audience,
|
|
156
|
+
...(identityOnly ? { approvedBy: 'tailnet identity' } : {}),
|
|
157
|
+
})
|
|
158
|
+
agent = { id: token.agentId, name: look.name, audience: look.audience }
|
|
159
|
+
}
|
|
103
160
|
const approved = deviceLogins.approve(found.code, {
|
|
104
161
|
token: token.token,
|
|
105
162
|
tokenName: token.info.name,
|
|
@@ -107,15 +164,17 @@ export function mountDeviceApprovals(consoleApi, deps) {
|
|
|
107
164
|
expiresAt: token.info.expiresAt,
|
|
108
165
|
workspace: { id: ws, name: workspace.name },
|
|
109
166
|
project: { id: req.project.id, name: req.project.name },
|
|
167
|
+
...(agent ? { agent } : {}),
|
|
110
168
|
})
|
|
111
169
|
if (!approved) throw new HttpError(404, 'unknown_code', 'That code was already used, or it expired. Run shapewall login again.')
|
|
112
|
-
return token
|
|
170
|
+
return { ...token, agent }
|
|
113
171
|
})
|
|
114
172
|
res.json({
|
|
115
173
|
ok: true,
|
|
116
174
|
info: made.info,
|
|
117
175
|
workspace: { id: ws, name: workspace.name },
|
|
118
176
|
project: { id: req.project.id, name: req.project.name },
|
|
177
|
+
...(made.agent ? { agent: made.agent } : {}),
|
|
119
178
|
})
|
|
120
179
|
}),
|
|
121
180
|
)
|
|
@@ -130,6 +189,25 @@ export function mountDeviceApprovals(consoleApi, deps) {
|
|
|
130
189
|
)
|
|
131
190
|
}
|
|
132
191
|
|
|
192
|
+
// What a connected agent's token may do: read dispatched comments, answer
|
|
193
|
+
// them as itself, set statuses, take work, and hold the link. Never resolve
|
|
194
|
+
// or push: those stay separate tokens.
|
|
195
|
+
export const AGENT_LOGIN_SCOPES = ['read', 'reply', 'status', 'claim', 'agent']
|
|
196
|
+
|
|
197
|
+
// The name, icon, tint and audience the approver chose for a new agent.
|
|
198
|
+
function agentLook(input, entry) {
|
|
199
|
+
const wanted = typeof input?.name === 'string' && input.name.trim() ? input.name : entry.agent?.name || entry.name
|
|
200
|
+
const { name, problem } = cleanAgentName(wanted)
|
|
201
|
+
if (problem || !name) throw new HttpError(400, 'invalid_name', problem ? `Agent ${problem}.` : 'Agent name: 1 to 40 characters.')
|
|
202
|
+
const icon = input?.icon ?? null
|
|
203
|
+
if (icon !== null && !isBuiltInIcon(icon)) throw new HttpError(400, 'invalid_icon', 'Choose one of the built-in icons.')
|
|
204
|
+
const tint = input?.tint ?? null
|
|
205
|
+
if (tint !== null && !isAgentTint(tint)) throw new HttpError(400, 'invalid_tint', 'Choose one of the tints.')
|
|
206
|
+
const audience = input?.audience ?? 'owner'
|
|
207
|
+
if (!AGENT_AUDIENCES.includes(audience)) throw new HttpError(400, 'invalid_audience', `Audience: ${AGENT_AUDIENCES.join(', ')}.`)
|
|
208
|
+
return { name, icon, tint, audience, users: Array.isArray(input?.users) ? input.users : [] }
|
|
209
|
+
}
|
|
210
|
+
|
|
133
211
|
export function mountDeviceApi(app, deps) {
|
|
134
212
|
const { deviceLogins, publicOrigin, clientIp, limit, handle } = deps
|
|
135
213
|
|
|
@@ -146,7 +224,7 @@ export function mountDeviceApi(app, deps) {
|
|
|
146
224
|
'/start',
|
|
147
225
|
limit('deviceStart'),
|
|
148
226
|
handle(async (req, res) => {
|
|
149
|
-
const started = deviceLogins.start({ name: req.body?.name, ip: clientIp(req), purpose: req.body?.purpose })
|
|
227
|
+
const started = deviceLogins.start({ name: req.body?.name, ip: clientIp(req), purpose: req.body?.purpose, agent: req.body?.agent })
|
|
150
228
|
if (started.refused)
|
|
151
229
|
throw new HttpError(429, 'too_many_logins', 'Too many logins in progress from this address. Finish or wait out one (10 minutes).')
|
|
152
230
|
res.status(201).json({
|
package/src/hosted/device.js
CHANGED
|
@@ -70,6 +70,53 @@ export function cleanMachineName(value) {
|
|
|
70
70
|
return name || 'a computer'
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// What a device login is for: a plain token (null), moving a local project
|
|
74
|
+
// ("import"), or connecting an agent ("agent", `shapewall agent connect`).
|
|
75
|
+
export const DEVICE_PURPOSES = ['import', 'agent']
|
|
76
|
+
const AGENT_META_KINDS = ['claude', 'codex', 'goose', 'gemini', 'custom']
|
|
77
|
+
// What `shapewall agent connect` says its machine takes from the board (its
|
|
78
|
+
// own rules: --approvals, --auto, --base): { approvals, auto, base }, or null
|
|
79
|
+
// when the terminal did not say (an older shapewall). Shown to the approver
|
|
80
|
+
// as the terminal's report; the machine enforces its rules itself, and the
|
|
81
|
+
// server decides nothing by this.
|
|
82
|
+
const ASKS_APPROVALS = ['none', 'owner', 'admins']
|
|
83
|
+
const ASKS_BASE_RE = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,99}$/
|
|
84
|
+
export function cleanAgentAsks(value) {
|
|
85
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null
|
|
86
|
+
const approvals = ASKS_APPROVALS.includes(value.approvals) ? value.approvals : 'none'
|
|
87
|
+
return {
|
|
88
|
+
approvals,
|
|
89
|
+
// Edits allowed without asking, once switched on in the console. Never without edits.
|
|
90
|
+
auto: approvals !== 'none' && value.auto === true,
|
|
91
|
+
base: approvals !== 'none' && typeof value.base === 'string' && ASKS_BASE_RE.test(value.base) ? value.base : null,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// What `shapewall agent connect` says about the agent it will run: its kind,
|
|
95
|
+
// the name it suggests and what its machine takes from the board. The
|
|
96
|
+
// machine's own claim, shown on the approval page and never trusted for
|
|
97
|
+
// anything else.
|
|
98
|
+
export function cleanAgentMeta(value) {
|
|
99
|
+
const asks = cleanAgentAsks(value?.asks)
|
|
100
|
+
const kind = AGENT_META_KINDS.includes(value?.kind) ? value.kind : 'custom'
|
|
101
|
+
const name =
|
|
102
|
+
typeof value?.name === 'string'
|
|
103
|
+
? value.name
|
|
104
|
+
// eslint-disable-next-line no-control-regex
|
|
105
|
+
.replace(/[\u0000-\u001f\u007f<>]/g, '')
|
|
106
|
+
.replace(/\s+/g, ' ')
|
|
107
|
+
.trim()
|
|
108
|
+
.slice(0, 40)
|
|
109
|
+
: ''
|
|
110
|
+
return { kind, name: name || null, ...(asks ? { asks } : {}) }
|
|
111
|
+
}
|
|
112
|
+
const parseMeta = (text) => {
|
|
113
|
+
try {
|
|
114
|
+
return cleanAgentMeta(JSON.parse(text || '{}'))
|
|
115
|
+
} catch {
|
|
116
|
+
return cleanAgentMeta(null)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
73
120
|
// ---- Sealing the token to the device code ----
|
|
74
121
|
|
|
75
122
|
// PKCS#8 header of a raw 32-byte X25519 private key.
|
|
@@ -125,11 +172,13 @@ export function createDeviceLogins({ db, now = () => new Date(), maxPending = MA
|
|
|
125
172
|
expiresAt: row.expires_at,
|
|
126
173
|
status: row.status,
|
|
127
174
|
purpose: row.purpose || null,
|
|
175
|
+
// What an agent login said it runs: { kind, name } (cleaned at start).
|
|
176
|
+
agent: row.purpose === 'agent' ? parseMeta(row.meta) : null,
|
|
128
177
|
}
|
|
129
178
|
|
|
130
179
|
// A new login, or { refused: 'per_ip' } when this address has too many
|
|
131
180
|
// pending already.
|
|
132
|
-
function start({ name, ip, purpose }) {
|
|
181
|
+
function start({ name, ip, purpose, agent = null }) {
|
|
133
182
|
return transaction(db, () => {
|
|
134
183
|
sweep()
|
|
135
184
|
const from = ip || null
|
|
@@ -154,11 +203,12 @@ export function createDeviceLogins({ db, now = () => new Date(), maxPending = MA
|
|
|
154
203
|
const deviceCode = randomToken(32)
|
|
155
204
|
const created = time()
|
|
156
205
|
q.run(
|
|
157
|
-
`INSERT INTO device_logins (device_hash, user_code, name, ip, seal_key, created_at, expires_at, status, purpose)
|
|
158
|
-
VALUES (:hash, :code, :name, :ip, :seal, :created, :expires, 'pending', :purpose)`,
|
|
206
|
+
`INSERT INTO device_logins (device_hash, user_code, name, ip, seal_key, created_at, expires_at, status, purpose, meta)
|
|
207
|
+
VALUES (:hash, :code, :name, :ip, :seal, :created, :expires, 'pending', :purpose, :meta)`,
|
|
159
208
|
{
|
|
160
209
|
hash: sha256(deviceCode),
|
|
161
|
-
purpose: purpose
|
|
210
|
+
purpose: DEVICE_PURPOSES.includes(purpose) ? purpose : null,
|
|
211
|
+
meta: purpose === 'agent' ? JSON.stringify(cleanAgentMeta(agent)) : null,
|
|
162
212
|
code: userCode,
|
|
163
213
|
name: cleanMachineName(name),
|
|
164
214
|
ip: from,
|
package/src/hosted/events.js
CHANGED
|
@@ -21,7 +21,7 @@ export function createEventBus() {
|
|
|
21
21
|
|
|
22
22
|
// The change event a successful write publishes (the SSE stream and board
|
|
23
23
|
// presence refetch on it), or null. Only comment, approval, import, agent
|
|
24
|
-
// policy and push-commit writes change what watchers see, and a board
|
|
24
|
+
// policy, agent setting and push-commit writes change what watchers see, and a board
|
|
25
25
|
// removed in the console (`method` DELETE on the board itself); a push's
|
|
26
26
|
// file uploads, token and device approvals publish nothing.
|
|
27
27
|
export function changeEventType(pathname, method = 'POST') {
|
|
@@ -31,10 +31,10 @@ export function changeEventType(pathname, method = 'POST') {
|
|
|
31
31
|
if (/\/comments\/[1-9][0-9]*\/resolve$/.test(pathname)) return 'comment.resolved'
|
|
32
32
|
if (/\/boards\/[^/]+\/comments$/.test(pathname)) return 'comment.created'
|
|
33
33
|
if (
|
|
34
|
-
/\/boards\/[^/]+\/(?:comments\/[1-9][0-9]*(?:\/(?:replies|reactions|reopen|agent-status|approvals))?|approvals\/[^/]+|import)$/.test(
|
|
34
|
+
/\/boards\/[^/]+\/(?:comments\/[1-9][0-9]*(?:\/(?:replies|reactions|reopen|agent-status|approvals|release-agent))?|approvals\/[^/]+|import)$/.test(
|
|
35
35
|
pathname,
|
|
36
36
|
) ||
|
|
37
|
-
/\/projects\/[^/]+\/agent$/.test(pathname)
|
|
37
|
+
/\/projects\/[^/]+\/(?:agent|default-agent|agents\/[^/]+(?:\/(?:audience|approval))?)$/.test(pathname)
|
|
38
38
|
)
|
|
39
39
|
return 'comment.updated'
|
|
40
40
|
return null
|