shapewall 0.6.0 → 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 +252 -0
- package/README.md +39 -2
- package/THIRD_PARTY.md +15 -0
- package/dist/agent/package-lock.json +594 -2
- package/dist/client/assets/{BoardChat-DdwBcb2N.js → BoardChat-WS8mAIW6.js} +1 -1
- package/dist/client/assets/{BuzzDialog-DpUcnU6S.js → BuzzDialog-B-Mlr6wF.js} +1 -1
- package/dist/client/assets/{ChecksPanel-CngYV4yz.js → ChecksPanel-Dx1ZLBR6.js} +1 -1
- package/dist/client/assets/{History-CD0saQA5.js → History-sXhmpcvs.js} +1 -1
- package/dist/client/assets/{LocalSettings-MZy2baig.js → LocalSettings-CtGzz9F3.js} +1 -1
- package/dist/client/assets/{Management-CSvZ-SHO.js → Management-CGHe8Wt9.js} +1 -1
- package/dist/client/assets/{QuickConnect-foLh2QUm.js → QuickConnect-DEk84E4A.js} +1 -1
- package/dist/client/assets/{ShareDialog-DPWDftoL.js → ShareDialog-CGGx-AYK.js} +1 -1
- package/dist/client/assets/{app-update-dialog-CtiXpTRD.js → app-update-dialog-_bVp8hnC.js} +1 -1
- package/dist/client/assets/{circle-x-CteRBtXC.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-BjRNIGSf.js → play-BzQ3tRTv.js} +1 -1
- package/dist/client/assets/{refresh-cw-r_tZiFfB.js → refresh-cw-BYBMyDKT.js} +1 -1
- package/dist/client/assets/{ui-zQpn-PdL.js → ui-CAY6myRA.js} +1 -1
- 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 +31 -17
- package/docs/agents.md +35 -0
- package/docs/architecture.md +10 -4
- package/docs/deployment.md +39 -17
- package/docs/design-system.md +56 -7
- package/docs/hosted.md +1004 -43
- 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 +82 -1
- package/package.json +6 -1
- package/src/agent/backends/acp.js +224 -26
- package/src/agent/routes.js +21 -0
- package/src/agent/usage-log.js +251 -0
- package/src/cli/args.js +24 -0
- package/src/cli/help.js +37 -2
- 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 +80 -13
- package/src/hosted/agent-approvals.js +2 -2
- package/src/hosted/agent-routes.js +3 -3
- package/src/hosted/agents.js +11 -4
- package/src/hosted/app.js +89 -7
- package/src/hosted/auth-routes.js +156 -15
- package/src/hosted/auth.js +123 -20
- package/src/hosted/board-routes.js +3 -3
- package/src/hosted/chat-frames.js +5 -15
- package/src/hosted/chat-permissions.js +12 -0
- package/src/hosted/chat-routes.js +8 -8
- package/src/hosted/chat-store.js +20 -3
- package/src/hosted/comment-files.js +5 -2
- package/src/hosted/console-routes.js +111 -34
- package/src/hosted/db.js +130 -0
- package/src/hosted/device-routes.js +25 -3
- package/src/hosted/device.js +23 -4
- package/src/hosted/guards.js +337 -27
- package/src/hosted/http.js +6 -3
- package/src/hosted/membership.js +13 -2
- 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 +2 -0
- package/src/hosted/passkey-policy.js +75 -0
- package/src/hosted/permissions.js +14 -6
- package/src/hosted/presence.js +14 -2
- package/src/hosted/projects.js +2 -1
- package/src/hosted/public.js +4 -4
- package/src/hosted/ratelimit.js +6 -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 +48 -1
- package/src/hosted/token-api.js +2 -2
- package/src/hosted/tokens.js +9 -2
- 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 +37 -1
- package/src/remote/agent-link.js +2 -0
- package/src/remote/login.js +33 -8
- 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/index-Cxz1UVcV.css +0 -2
- package/dist/client/assets/index-uUZVBYUS.js +0 -37
- package/dist/console/assets/LocalAccountsApp-DIdy1KnN.js +0 -1
- package/dist/console/assets/LocalConsole-DfcQztF-.js +0 -1
- package/dist/console/assets/app-update-dialog-ttl9lF5A.js +0 -1
- package/dist/console/assets/console-OqAjD0kV.js +0 -55
- package/dist/console/assets/console-kvjrAArQ.css +0 -2
package/src/hosted/ops-cli.js
CHANGED
|
@@ -30,10 +30,30 @@ export async function hostedCommand(positional, flags, out, err = out) {
|
|
|
30
30
|
await operatorCommand(sub, { dataDir: dataDirOf(flags), flags, env: process.env, out })
|
|
31
31
|
return 0
|
|
32
32
|
}
|
|
33
|
+
if (sub === 'claim') return claim(flags, out)
|
|
33
34
|
if (sub === 'admin') return admin(rest, flags, out)
|
|
34
35
|
if (sub === 'backup') return backupCommand(flags, out)
|
|
35
36
|
if (sub === 'restore') return restoreCommand(flags, out, err)
|
|
36
|
-
throw new Error(`unknown hosted command "${show(sub).slice(0, 40)}" (admin, backup, restore; or no command to run the server)`)
|
|
37
|
+
throw new Error(`unknown hosted command "${show(sub).slice(0, 40)}" (claim, admin, backup, restore; or no command to run the server)`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ---- The first account, without the browser (tailnet sign-in) ----
|
|
41
|
+
|
|
42
|
+
// `shapewall hosted claim --data DIR --login LOGIN` on the server's own
|
|
43
|
+
// machine: whoever can read the data folder controls the server, and says
|
|
44
|
+
// whose it is (src/hosted/access-cli.js claimCommand; the server never
|
|
45
|
+
// takes a tailnet identity from its own machine). `shapewall hosted claim
|
|
46
|
+
// --setup-link URL` from another tailnet device: the server sees who asks,
|
|
47
|
+
// and --login can only refuse another answer (src/remote/tailnet-cli.js).
|
|
48
|
+
async function claim(flags, out) {
|
|
49
|
+
// From another tailnet device, with the setup link itself: the server sees who asks.
|
|
50
|
+
if (typeof flags['setup-link'] === 'string') {
|
|
51
|
+
const { claimServer } = await import('../remote/tailnet-cli.js')
|
|
52
|
+
return claimServer({ setupUrl: flags['setup-link'], flags, out })
|
|
53
|
+
}
|
|
54
|
+
// On the server's own machine: the data folder is the proof, --login says whose it is.
|
|
55
|
+
const { operatorCommand } = await import('./access-cli.js')
|
|
56
|
+
return operatorCommand('claim', { dataDir: dataDirOf(flags), flags, env: process.env, out })
|
|
37
57
|
}
|
|
38
58
|
|
|
39
59
|
// ---- Run the server ----
|
|
@@ -63,9 +83,12 @@ async function serve(flags, out) {
|
|
|
63
83
|
usercontentOrigin: flags['usercontent-origin'] || env.SHAPEWALL_USERCONTENT_ORIGIN || env.SHAPEWALL_HOSTED_USERCONTENT_ORIGIN || null,
|
|
64
84
|
previousOrigin: flags['previous-origin'] || env.SHAPEWALL_HOSTED_PREVIOUS_ORIGIN || null,
|
|
65
85
|
reportEmail: flags['report-email'] || env.SHAPEWALL_HOSTED_REPORT_EMAIL || null,
|
|
86
|
+
ownersSeeSignIns: Boolean(flags['owners-see-sign-ins']) || env.SHAPEWALL_HOSTED_OWNERS_SEE_SIGN_INS === '1',
|
|
66
87
|
signup: flags.signup || env.SHAPEWALL_HOSTED_SIGNUP || 'invite',
|
|
67
88
|
trustProxy,
|
|
68
89
|
tailscale,
|
|
90
|
+
tailnetSignIn: Boolean(flags['tailnet-sign-in']) || env.SHAPEWALL_HOSTED_TAILNET_SIGN_IN === '1',
|
|
91
|
+
tailnetPasskeys: Boolean(flags['tailnet-passkeys']) || env.SHAPEWALL_HOSTED_TAILNET_PASSKEYS === '1',
|
|
69
92
|
quotasFile: flags.quotas || env.SHAPEWALL_HOSTED_QUOTAS || null,
|
|
70
93
|
retentionHours: intFlag(flags, 'retention-hours', { min: 0, max: 24 * 30, fallback: undefined }),
|
|
71
94
|
retentionKeep: intFlag(flags, 'retention-keep', { min: 0, max: 100, fallback: undefined }),
|
|
@@ -73,7 +96,8 @@ async function serve(flags, out) {
|
|
|
73
96
|
})
|
|
74
97
|
} catch (error) {
|
|
75
98
|
const { TailscaleError } = await import('./tailscale.js')
|
|
76
|
-
|
|
99
|
+
const { TailnetSignInError } = await import('./server.js')
|
|
100
|
+
if (error instanceof TailscaleError || error instanceof TailnetSignInError) {
|
|
77
101
|
out(error.message)
|
|
78
102
|
return 1
|
|
79
103
|
}
|
|
@@ -154,7 +178,23 @@ const ADMIN_HELP = `shapewall hosted admin <command> --data DIR (on the server
|
|
|
154
178
|
reports [--all] abuse reports (open ones; --all with closed)
|
|
155
179
|
reports close ID [--note TEXT]
|
|
156
180
|
retention WS --keep N|default older versions kept per page and viewport
|
|
181
|
+
retention WS --usage-days N|default how long usage records are kept (400 days by default)
|
|
157
182
|
retention --run [--dry-run] prune now (the server also does it every 6 hours)
|
|
183
|
+
members list who is in the workspace, with roles
|
|
184
|
+
members add --login TAILNET_LOGIN | --handle HANDLE [--role ROLE] put someone in, or change their role
|
|
185
|
+
(a tailnet login with no account yet gets an invite only it can take)
|
|
186
|
+
members remove --login TAILNET_LOGIN | --handle HANDLE take someone out; what they made to let others in is revoked
|
|
187
|
+
members relink --handle HANDLE [--login TAILNET_LOGIN] their tailnet login again: the next arrival as it is taken as
|
|
188
|
+
them (for "This tailnet login belongs to someone else here"); --login links another login.
|
|
189
|
+
Or: members relink --login TAILNET_LOGIN (the account linked to it now)
|
|
190
|
+
members unlink --handle HANDLE take the tailnet login off an account
|
|
191
|
+
invites list | invites revoke ID
|
|
192
|
+
invites create --login TAILNET_LOGIN [--role ROLE] [--days N] or a link: --link --origin https://the.server
|
|
193
|
+
projects list
|
|
194
|
+
passkeys status|on|off on a server with tailnet sign-in: whether anyone may add a passkey (off by default)
|
|
195
|
+
passkeys list --handle HANDLE | --login TAILNET_LOGIN an account's passkeys (ids, where added, on hold)
|
|
196
|
+
passkeys remove ID --handle HANDLE | --login TAILNET_LOGIN remove one, also the last; ends the account's passkey sessions
|
|
197
|
+
--workspace ID which workspace, when the server has several (members, invites, projects)
|
|
158
198
|
log [--limit N] the operator log
|
|
159
199
|
--operator NAME who you are in the operator log (default user@host)
|
|
160
200
|
--json machine-readable output`
|
|
@@ -258,10 +298,22 @@ async function admin(positional, flags, out) {
|
|
|
258
298
|
out(
|
|
259
299
|
`${dryRun ? 'Would remove' : 'Removed'} ${result.files} old version files (${mb(result.bytes)}) from ${result.boards} boards in ${result.workspaces} workspaces.`,
|
|
260
300
|
)
|
|
301
|
+
if (result.usageRows) out(`${dryRun ? 'Would remove' : 'Removed'} ${result.usageRows} old usage records.`)
|
|
302
|
+
return 0
|
|
303
|
+
}
|
|
304
|
+
if (target && flags['usage-days'] !== undefined) {
|
|
305
|
+
const days = flags['usage-days'] === 'default' ? null : intFlag(flags, 'usage-days', { min: 1, max: 3650 })
|
|
306
|
+
const result = ops.setUsageRetentionFor(db, { workspaceId: target, days, operator })
|
|
307
|
+
if (flags.json) return json(result)
|
|
308
|
+
out(
|
|
309
|
+
`${result.id} (${show(result.name)}) keeps usage records for ${result.usageDays} days${result.own ? '' : ' (the server default)'}.`,
|
|
310
|
+
)
|
|
261
311
|
return 0
|
|
262
312
|
}
|
|
263
313
|
if (!target || flags.keep === undefined)
|
|
264
|
-
throw new ops.OperatorError(
|
|
314
|
+
throw new ops.OperatorError(
|
|
315
|
+
'usage: hosted admin retention WS --keep N|default, hosted admin retention WS --usage-days N|default, or hosted admin retention --run [--dry-run]',
|
|
316
|
+
)
|
|
265
317
|
const keep = flags.keep === 'default' ? null : intFlag(flags, 'keep', { min: 0, max: 100 })
|
|
266
318
|
const result = ops.setRetention(db, { workspaceId: target, keep, operator })
|
|
267
319
|
if (flags.json) return json(result)
|
|
@@ -270,6 +322,189 @@ async function admin(positional, flags, out) {
|
|
|
270
322
|
)
|
|
271
323
|
return 0
|
|
272
324
|
}
|
|
325
|
+
case 'members': {
|
|
326
|
+
const access = await import('./operator-access.js')
|
|
327
|
+
const where = { workspaceId: flags.workspace, operator }
|
|
328
|
+
if (!target || target === 'list') {
|
|
329
|
+
const result = access.listMembers(db, where)
|
|
330
|
+
if (flags.json) return json(result)
|
|
331
|
+
out(`${show(result.workspace.name)} (${result.workspace.id}):`)
|
|
332
|
+
for (const member of result.members)
|
|
333
|
+
out(
|
|
334
|
+
` @${show(member.handle)} ${member.role} ${show(member.name)}` +
|
|
335
|
+
`${member.tailnetLogin ? ` tailnet ${show(member.tailnetLogin)}` : ''}${member.passkeys ? ` ${member.passkeys} passkey${member.passkeys === 1 ? '' : 's'}` : ''}`,
|
|
336
|
+
)
|
|
337
|
+
return 0
|
|
338
|
+
}
|
|
339
|
+
if (target === 'add') {
|
|
340
|
+
const result = access.addMember(db, { ...where, handle: flags.handle, login: flags.login, role: flags.role })
|
|
341
|
+
if (flags.json) return json(result)
|
|
342
|
+
if (result.invited)
|
|
343
|
+
return say(
|
|
344
|
+
`${show(result.invite.tailnetLogin)} has no account here yet: invited to ${show(result.workspace.name)} as ${result.invite.role}. ` +
|
|
345
|
+
'Only that tailnet login can take it: they open the server from one of their tailnet devices.',
|
|
346
|
+
)
|
|
347
|
+
return say(
|
|
348
|
+
result.changedFrom
|
|
349
|
+
? `@${show(result.member.handle)} is now ${result.member.role} in ${show(result.workspace.name)} (was ${result.changedFrom}).`
|
|
350
|
+
: `@${show(result.member.handle)} is in ${show(result.workspace.name)} as ${result.member.role}.`,
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
if (target === 'remove') {
|
|
354
|
+
const result = access.removeMember(db, { ...where, handle: flags.handle, login: flags.login })
|
|
355
|
+
if (flags.json) return json(result)
|
|
356
|
+
const { invites, shares, tokens } = result.revoked
|
|
357
|
+
return say(
|
|
358
|
+
`Removed @${show(result.removed.handle)} (${result.removed.role}) from ${show(result.workspace.name)}. ` +
|
|
359
|
+
`Revoked: ${invites} invites, ${shares} share links, ${tokens} API tokens they made.`,
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
if (target === 'relink') {
|
|
363
|
+
const result = access.relinkMember(db, { handle: flags.handle, login: flags.login, operator })
|
|
364
|
+
if (flags.json) return json(result)
|
|
365
|
+
out(
|
|
366
|
+
`@${show(result.user.handle)} is linked to ${show(result.login)}${result.was && result.was !== result.login ? ` (was ${show(result.was)})` : ''}. ` +
|
|
367
|
+
'Whoever next arrives through the tailnet as that login, from a device of theirs, is taken as this account from then on.',
|
|
368
|
+
)
|
|
369
|
+
return say(
|
|
370
|
+
`${result.sessionsEnded} tailnet session${result.sessionsEnded === 1 ? '' : 's'} of the account ended. Make sure it is the right person who opens the server next.`,
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
if (target === 'unlink') {
|
|
374
|
+
const result = access.unlinkMember(db, { handle: flags.handle, login: flags.login, operator })
|
|
375
|
+
if (flags.json) return json(result)
|
|
376
|
+
out(
|
|
377
|
+
`@${show(result.user.handle)} is no longer linked to ${show(result.was)}; ${result.sessionsEnded} tailnet session${result.sessionsEnded === 1 ? '' : 's'} ended.`,
|
|
378
|
+
)
|
|
379
|
+
return say(
|
|
380
|
+
result.passkeys
|
|
381
|
+
? 'The account signs in with its passkey, where this server allows passkeys.'
|
|
382
|
+
: 'The account has no passkey: nothing signs it in until it is linked again (hosted admin members relink --handle ... --login ...).',
|
|
383
|
+
)
|
|
384
|
+
}
|
|
385
|
+
throw new ops.OperatorError(
|
|
386
|
+
'usage: hosted admin members list|add|remove|relink|unlink --login TAILNET_LOGIN | --handle HANDLE [--role ROLE]',
|
|
387
|
+
)
|
|
388
|
+
}
|
|
389
|
+
case 'invites': {
|
|
390
|
+
const access = await import('./operator-access.js')
|
|
391
|
+
const where = { workspaceId: flags.workspace, operator }
|
|
392
|
+
if (!target || target === 'list') {
|
|
393
|
+
const result = access.listInvites(db, where)
|
|
394
|
+
if (flags.json) return json(result)
|
|
395
|
+
if (!result.invites.length) return say(`No open invites to ${show(result.workspace.name)}.`)
|
|
396
|
+
out(`Open invites to ${show(result.workspace.name)}:`)
|
|
397
|
+
for (const invite of result.invites)
|
|
398
|
+
out(
|
|
399
|
+
` ${invite.id} ${invite.role} ${invite.tailnetLogin ? `for ${show(invite.tailnetLogin)}` : 'a link'} until ${invite.expiresAt.slice(0, 16).replace('T', ' ')}`,
|
|
400
|
+
)
|
|
401
|
+
return 0
|
|
402
|
+
}
|
|
403
|
+
if (target === 'create') {
|
|
404
|
+
const result = access.createInvite(db, {
|
|
405
|
+
...where,
|
|
406
|
+
login: typeof flags.login === 'string' ? flags.login : null,
|
|
407
|
+
origin: flags.link && typeof flags.origin === 'string' ? flags.origin : null,
|
|
408
|
+
role: flags.role,
|
|
409
|
+
days: flags.days === undefined ? 7 : Number(flags.days),
|
|
410
|
+
})
|
|
411
|
+
if (flags.json) return json(result)
|
|
412
|
+
if (result.url) {
|
|
413
|
+
out(`An invite to ${show(result.workspace.name)} as ${result.invite.role}. Whoever has this link can use it once:`)
|
|
414
|
+
return say(` ${result.url}`)
|
|
415
|
+
}
|
|
416
|
+
return say(
|
|
417
|
+
`Invited ${show(result.invite.tailnetLogin)} to ${show(result.workspace.name)} as ${result.invite.role}. Only that tailnet login can take it.`,
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
if (target === 'revoke') {
|
|
421
|
+
const result = access.revokeInvite(db, { ...where, id: extra })
|
|
422
|
+
if (flags.json) return json(result)
|
|
423
|
+
return say(`Revoked the invite ${result.revoked}.`)
|
|
424
|
+
}
|
|
425
|
+
throw new ops.OperatorError('usage: hosted admin invites list | create --login TAILNET_LOGIN [--role ROLE] | revoke ID')
|
|
426
|
+
}
|
|
427
|
+
case 'projects': {
|
|
428
|
+
const access = await import('./operator-access.js')
|
|
429
|
+
if (target && target !== 'list') throw new ops.OperatorError('usage: hosted admin projects list')
|
|
430
|
+
const result = access.listProjects(db, { workspaceId: flags.workspace, operator })
|
|
431
|
+
if (flags.json) return json(result)
|
|
432
|
+
if (!result.projects.length) return say(`${show(result.workspace.name)} has no project yet.`)
|
|
433
|
+
out(`Projects in ${show(result.workspace.name)}:`)
|
|
434
|
+
for (const project of result.projects) out(` ${show(project.slug)} ${show(project.name)} (${project.id})`)
|
|
435
|
+
return 0
|
|
436
|
+
}
|
|
437
|
+
case 'passkeys': {
|
|
438
|
+
if (['on', 'off', 'status'].includes(target)) {
|
|
439
|
+
const access = await import('./operator-access.js')
|
|
440
|
+
const result = target === 'status' ? access.passkeysStatus(db) : access.setPasskeys(db, { on: target === 'on', operator })
|
|
441
|
+
if (flags.json) return json(result)
|
|
442
|
+
out(
|
|
443
|
+
result.setting === null
|
|
444
|
+
? 'Passkeys on a tailnet sign-in server: not set here. They are off unless the server runs with --tailnet-passkeys.'
|
|
445
|
+
: result.setting
|
|
446
|
+
? 'Passkeys are ON for a server with tailnet sign-in: an account may add a passkey, and one that has a passkey confirms with it.'
|
|
447
|
+
: 'Passkeys are OFF for a server with tailnet sign-in: the Tailscale account is the only sign-in, and nobody is asked for a passkey.',
|
|
448
|
+
)
|
|
449
|
+
out('A running server follows this at once. A server without --tailnet-sign-in always uses passkeys, whatever this says.')
|
|
450
|
+
if (result.sessionsEnded)
|
|
451
|
+
out(
|
|
452
|
+
`${result.sessionsEnded} session${result.sessionsEnded === 1 ? '' : 's'} that a passkey or a recovery code started ${result.sessionsEnded === 1 ? 'was' : 'were'} ended.`,
|
|
453
|
+
)
|
|
454
|
+
if (result.holdsRestarted)
|
|
455
|
+
out(
|
|
456
|
+
`${result.holdsRestarted} passkey${result.holdsRestarted === 1 ? '' : 's'} that ${result.holdsRestarted === 1 ? 'was' : 'were'} on hold start${result.holdsRestarted === 1 ? 's its' : ' their'} 24 hours again.`,
|
|
457
|
+
)
|
|
458
|
+
for (const workspace of result.workspaces || [])
|
|
459
|
+
out(
|
|
460
|
+
`${show(workspace.name)} (${workspace.id}) asks for a passkey in its settings (${workspace.settings.join(', ')}): ` +
|
|
461
|
+
(result.setting ? 'asked again from now.' : 'not asked while passkeys are off. Its audit log says so.'),
|
|
462
|
+
)
|
|
463
|
+
if (result.setting === false && result.passkeyOnly)
|
|
464
|
+
out(
|
|
465
|
+
`${result.passkeyOnly} account${result.passkeyOnly === 1 ? ' is' : 's are'} not linked to a tailnet login: with passkeys off ${result.passkeyOnly === 1 ? 'it' : 'they'} cannot sign in.`,
|
|
466
|
+
)
|
|
467
|
+
if (result.setting === false && result.withPasskey)
|
|
468
|
+
out(
|
|
469
|
+
`${result.withPasskey} account${result.withPasskey === 1 ? ' has' : 's have'} a passkey; it is kept and not used while passkeys are off.`,
|
|
470
|
+
)
|
|
471
|
+
return 0
|
|
472
|
+
}
|
|
473
|
+
const who = { handle: flags.handle, login: flags.login, operator }
|
|
474
|
+
if (target === 'list') {
|
|
475
|
+
const result = ops.listPasskeysOf(db, who)
|
|
476
|
+
if (flags.json) return json(result)
|
|
477
|
+
const name = `@${show(result.user.handle)}${result.user.tailnetLogin ? ` (tailnet login ${show(result.user.tailnetLogin)})` : ''}`
|
|
478
|
+
if (!result.passkeys.length) return say(`${name} has no passkey.`)
|
|
479
|
+
out(`${name}:`)
|
|
480
|
+
for (const key of result.passkeys)
|
|
481
|
+
out(
|
|
482
|
+
` ${key.id}\n ${show(key.nickname) || '(no name)'}; added ${key.createdAt.slice(0, 16).replace('T', ' ')}` +
|
|
483
|
+
`${key.addedFrom ? ` from ${show(key.addedFrom)} in a tailnet session` : ''}; last used ${key.lastUsedAt ? key.lastUsedAt.slice(0, 16).replace('T', ' ') : 'never'}` +
|
|
484
|
+
`${key.onHoldUntil ? `; on hold until ${key.onHoldUntil.slice(0, 16).replace('T', ' ')}` : ''}`,
|
|
485
|
+
)
|
|
486
|
+
return 0
|
|
487
|
+
}
|
|
488
|
+
if (target === 'remove') {
|
|
489
|
+
if (!extra) throw new ops.OperatorError('usage: hosted admin passkeys remove ID --handle HANDLE | --login TAILNET_LOGIN')
|
|
490
|
+
const result = ops.removePasskeyOf(db, { ...who, id: extra })
|
|
491
|
+
if (flags.json) return json(result)
|
|
492
|
+
out(
|
|
493
|
+
`Removed the passkey ${show(result.removed.nickname) || result.removed.id.slice(0, 12)} of @${show(result.user.handle)}. ` +
|
|
494
|
+
`${result.sessionsEnded} passkey session${result.sessionsEnded === 1 ? '' : 's'} ended; ${result.left} passkey${result.left === 1 ? '' : 's'} left.`,
|
|
495
|
+
)
|
|
496
|
+
if (!result.left)
|
|
497
|
+
out(
|
|
498
|
+
result.user.tailnetLogin
|
|
499
|
+
? `The account has no passkey now: ${show(result.user.tailnetLogin)} signs in through the tailnet and can add one.`
|
|
500
|
+
: 'The account has no passkey now: it signs in with a recovery code, if it has one left.',
|
|
501
|
+
)
|
|
502
|
+
return 0
|
|
503
|
+
}
|
|
504
|
+
throw new ops.OperatorError(
|
|
505
|
+
'usage: hosted admin passkeys status|on|off, or passkeys list|remove ID --handle HANDLE | --login TAILNET_LOGIN',
|
|
506
|
+
)
|
|
507
|
+
}
|
|
273
508
|
case 'log': {
|
|
274
509
|
ops.recordOperatorRead(db, { action: 'log', operator })
|
|
275
510
|
const rows = ops.operatorLog(db, { limit: intFlag(flags, 'limit', { min: 1, max: 10_000, fallback: 50 }) })
|
package/src/hosted/pages.js
CHANGED
|
@@ -65,6 +65,8 @@ export function mountPages(app, { db, dataDir, consoleDir, clientDir, turnstile,
|
|
|
65
65
|
'/w/:ws/projects/:pid',
|
|
66
66
|
// A project's Agents page.
|
|
67
67
|
'/w/:ws/agents/:pid',
|
|
68
|
+
// A person's page and an agent's page, under Activity.
|
|
69
|
+
'/w/:ws/activity/:subject',
|
|
68
70
|
])
|
|
69
71
|
app.get(route, (req, res) => sendConsole(req, res))
|
|
70
72
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Whether passkeys exist on this server.
|
|
2
|
+
//
|
|
3
|
+
// On a server without tailnet sign-in (its own domain, or a tailnet with
|
|
4
|
+
// passkeys) they are the sign-in, always.
|
|
5
|
+
//
|
|
6
|
+
// On a server started with --tailnet-sign-in, Tailscale is the sign-in and
|
|
7
|
+
// passkeys are OFF unless the operator turns them on: one identity (your
|
|
8
|
+
// Tailscale account), your different machines, and no second credential. The
|
|
9
|
+
// tailnet is the trust boundary there: anything running as you on one of
|
|
10
|
+
// your tailnet devices can act as you, so the few things that always ask
|
|
11
|
+
// (src/hosted/step-up.js, the fixed core) ask for a typed confirmation
|
|
12
|
+
// instead of a passkey (src/hosted/guards.js). An operator who wants more
|
|
13
|
+
// turns passkeys on:
|
|
14
|
+
// - `shapewall hosted --tailnet-passkeys` (or $SHAPEWALL_HOSTED_TAILNET_PASSKEYS=1), or
|
|
15
|
+
// - `shapewall hosted admin passkeys on|off --data DIR` (kept in the
|
|
16
|
+
// database, read on every request, and it wins over the flag).
|
|
17
|
+
// With them on, an account may add a passkey, and then the fixed core needs
|
|
18
|
+
// it, with the protections for a first passkey (hold, notice, removal).
|
|
19
|
+
|
|
20
|
+
import { accounts } from './tenancy.js'
|
|
21
|
+
|
|
22
|
+
const KEY = 'tailnet_passkeys'
|
|
23
|
+
// When the operator last switched them off: holds of passkeys stand still from then (see holdsAt).
|
|
24
|
+
const OFF_AT = 'tailnet_passkeys_off_at'
|
|
25
|
+
|
|
26
|
+
export function serverSetting(db, key) {
|
|
27
|
+
return accounts(db).get('SELECT value FROM server_settings WHERE key = :key', { key })?.value ?? null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function setServerSetting(db, key, value, at) {
|
|
31
|
+
accounts(db).run(
|
|
32
|
+
`INSERT INTO server_settings (key, value, updated_at) VALUES (:key, :value, :at)
|
|
33
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at`,
|
|
34
|
+
{ key, value: String(value), at },
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The operator's switch: true, false, or null (not set: the flag decides).
|
|
39
|
+
export const tailnetPasskeysSetting = (db) => {
|
|
40
|
+
const value = serverSetting(db, KEY)
|
|
41
|
+
return value === null ? null : value === '1'
|
|
42
|
+
}
|
|
43
|
+
export const setTailnetPasskeys = (db, on, at) => {
|
|
44
|
+
setServerSetting(db, KEY, on ? '1' : '0', at)
|
|
45
|
+
if (on) accounts(db).run('DELETE FROM server_settings WHERE key = :key', { key: OFF_AT })
|
|
46
|
+
else if (!serverSetting(db, OFF_AT)) setServerSetting(db, OFF_AT, at, at)
|
|
47
|
+
}
|
|
48
|
+
export const tailnetPasskeysOffAt = (db) => serverSetting(db, OFF_AT)
|
|
49
|
+
|
|
50
|
+
// tailnet: the tailnet gate of this server, or null (no tailnet sign-in).
|
|
51
|
+
export function createPasskeyPolicy({ db, tailnet = null, flag = false }) {
|
|
52
|
+
const on = () => {
|
|
53
|
+
if (!tailnet) return true
|
|
54
|
+
const set = tailnetPasskeysSetting(db)
|
|
55
|
+
return set === null ? Boolean(flag) : set
|
|
56
|
+
}
|
|
57
|
+
// The moment a passkey's 24 hour hold is judged at. While passkeys are off nobody can use one, so a hold
|
|
58
|
+
// does not run out behind the account's back: it stands as it was when they were switched off (and starts
|
|
59
|
+
// again when they are switched on, src/hosted/operator-access.js). null: now.
|
|
60
|
+
const holdsAt = () => {
|
|
61
|
+
if (on()) return null
|
|
62
|
+
const at = tailnetPasskeysOffAt(db)
|
|
63
|
+
return at && Number.isFinite(Date.parse(at)) ? new Date(at) : null
|
|
64
|
+
}
|
|
65
|
+
return { on, holdsAt, tailnetSignIn: Boolean(tailnet) }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Every route that makes, uses or manages a passkey or a recovery code, or
|
|
69
|
+
// links a passkey account to a tailnet login. Off with passkeys.
|
|
70
|
+
const PASSKEY_ROUTES = /^\/auth\/(?:register|login|recovery|reauth|passkeys|recovery-codes|rebind|tailnet\/link)(?:\/|$)/i
|
|
71
|
+
|
|
72
|
+
export const PASSKEYS_OFF_MESSAGE =
|
|
73
|
+
'Passkeys are off on this server: your Tailscale account is the sign-in. Whoever runs the server can turn them on (shapewall hosted admin passkeys on).'
|
|
74
|
+
|
|
75
|
+
export const isPasskeyRoute = (path) => PASSKEY_ROUTES.test(String(path || ''))
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
//
|
|
7
7
|
// viewer sees projects, boards and comments
|
|
8
8
|
// member + comments, replies, reactions, resolve and reopen; edits and deletes their own
|
|
9
|
+
// member + their own agent usage (and that of agents they connected)
|
|
9
10
|
// admin + projects, tokens, invites (up to admin), share links, members
|
|
10
|
-
// and viewers, any comment, the access overview, audit log, settings
|
|
11
|
+
// and viewers, any comment, the access overview, audit log, settings,
|
|
12
|
+
// the workspace's usage, everyone's activity, the access review
|
|
11
13
|
// owner + admins and owners, owner invites, deleting the workspace
|
|
12
14
|
// guest a share link visitor: one project; comments and replies on a
|
|
13
15
|
// comment link, nothing else
|
|
@@ -38,6 +40,14 @@ export const NEEDS = {
|
|
|
38
40
|
access: 'admin',
|
|
39
41
|
audit: 'admin',
|
|
40
42
|
export: 'admin',
|
|
43
|
+
// Usage: a member reads their own turns and the agents they connected;
|
|
44
|
+
// admins and owners the workspace (src/hosted/usage.js usageScope).
|
|
45
|
+
usage: 'member',
|
|
46
|
+
// Activity: anyone in the workspace reads their own; admins and owners all of it.
|
|
47
|
+
activity: 'viewer',
|
|
48
|
+
accessReview: 'admin',
|
|
49
|
+
// The layout of the Usage dashboard that everyone in the workspace starts from.
|
|
50
|
+
usageDefaultLayout: 'owner',
|
|
41
51
|
deleteWorkspace: 'owner',
|
|
42
52
|
}
|
|
43
53
|
export const can = (role, need) => roleAtLeast(role, NEEDS[need])
|
|
@@ -120,11 +130,9 @@ export const canInvite = (actorRole, role) =>
|
|
|
120
130
|
can(actorRole, 'invites') && ROLES.includes(role) && (role !== 'owner' || actorRole === 'owner')
|
|
121
131
|
export const invitableRoles = (actorRole) => ROLES.filter((role) => canInvite(actorRole, role))
|
|
122
132
|
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
newRole === 'owner' || newRole === 'admin' || (['owner', 'admin'].includes(targetRole) && targetRole !== newRole)
|
|
127
|
-
export const removalNeedsFresh = (targetRole, { self = false } = {}) => !self && ['owner', 'admin'].includes(targetRole)
|
|
133
|
+
// Which of these ask for the passkey again is in src/hosted/step-up.js:
|
|
134
|
+
// anything that makes, changes or removes an owner always does; the same
|
|
135
|
+
// for an admin only when the workspace's owner switched that on.
|
|
128
136
|
|
|
129
137
|
// A workspace always keeps an owner.
|
|
130
138
|
export const leavesNoOwner = ({ targetRole, newRole = null, owners }) => targetRole === 'owner' && newRole !== 'owner' && owners <= 1
|
package/src/hosted/presence.js
CHANGED
|
@@ -10,6 +10,7 @@ import { PUBLIC_ID_RE, readPublic } from './public.js'
|
|
|
10
10
|
import { createProjectStore } from './projects.js'
|
|
11
11
|
import { roleIn, tenant } from './tenancy.js'
|
|
12
12
|
import { guestCookieName, sessionCookieName } from './cookies.js'
|
|
13
|
+
import { sessionReader } from './tailnet.js'
|
|
13
14
|
import { ID_PATTERNS, SHARE_ID_RE } from './crypto.js'
|
|
14
15
|
import { ID_RE } from '../config.js'
|
|
15
16
|
|
|
@@ -75,10 +76,21 @@ function cookie(req, name) {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
// Re-run for every message and heartbeat. No cached membership or share grant.
|
|
78
|
-
export function presenceAuthorizer({
|
|
79
|
+
export function presenceAuthorizer({
|
|
80
|
+
db,
|
|
81
|
+
dataDir,
|
|
82
|
+
origin,
|
|
83
|
+
auth,
|
|
84
|
+
now = () => new Date(),
|
|
85
|
+
guestOnly = false,
|
|
86
|
+
tailnet = null,
|
|
87
|
+
passkeys = null,
|
|
88
|
+
}) {
|
|
79
89
|
const url = new URL(origin)
|
|
80
90
|
const secure = url.protocol === 'https:'
|
|
81
91
|
const iso = () => now().toISOString()
|
|
92
|
+
// A tailnet session counts only with its identity, here as on every request.
|
|
93
|
+
const readSession = sessionReader({ auth, tailnet, passkeys })
|
|
82
94
|
return (req) => {
|
|
83
95
|
if (
|
|
84
96
|
req.headers.origin !== url.origin ||
|
|
@@ -100,7 +112,7 @@ export function presenceAuthorizer({ db, dataDir, origin, auth, now = () => new
|
|
|
100
112
|
let access
|
|
101
113
|
if (member && !guestOnly) {
|
|
102
114
|
const token = cookie(req, sessionCookieName(secure))
|
|
103
|
-
const session = token &&
|
|
115
|
+
const session = token && readSession(req, token)
|
|
104
116
|
if (!session || !roleIn(db, session.user.id, member[1])) return null
|
|
105
117
|
access = {
|
|
106
118
|
workspace: member[1],
|
package/src/hosted/projects.js
CHANGED
|
@@ -10,6 +10,7 @@ import path from 'node:path'
|
|
|
10
10
|
import { ID_RE } from '../config.js'
|
|
11
11
|
import { ID_PATTERNS, newId } from './crypto.js'
|
|
12
12
|
import { transaction } from './db.js'
|
|
13
|
+
import { RUN_DURATION } from './usage-shape.js'
|
|
13
14
|
|
|
14
15
|
export const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,39}$/
|
|
15
16
|
export const PROJECTS_MAX = 50
|
|
@@ -165,7 +166,7 @@ export function createProjectStore(t, { db, dataDir, maxProjects = PROJECTS_MAX
|
|
|
165
166
|
const images = t.get(`SELECT COALESCE(SUM(bytes), 0) AS n FROM comment_files ${where}`, key).n
|
|
166
167
|
const open = t.all(`SELECT id FROM pushes ${where} AND status = 'open'`, key).map((push) => push.id)
|
|
167
168
|
// The usage record of a run on this board stays (it is history), closed.
|
|
168
|
-
t.run(`UPDATE agent_runs SET ended_at = :at, outcome = 'removed' ${where} AND ended_at IS NULL`, {
|
|
169
|
+
t.run(`UPDATE agent_runs SET ended_at = :at, outcome = 'removed', ${RUN_DURATION} ${where} AND ended_at IS NULL`, {
|
|
169
170
|
...key,
|
|
170
171
|
at: new Date().toISOString(),
|
|
171
172
|
})
|
package/src/hosted/public.js
CHANGED
|
@@ -26,7 +26,7 @@ export const publicUrl = (publicId) => `/p/${publicId}/`
|
|
|
26
26
|
|
|
27
27
|
// The workspace switch and the per-project switch, for the console.
|
|
28
28
|
export function mountPublicAdmin(router, deps) {
|
|
29
|
-
const { db, handle, inWorkspace, inProject,
|
|
29
|
+
const { db, handle, inWorkspace, inProject, stepUpOrThrow, auditOf, HttpError, iso } = deps
|
|
30
30
|
|
|
31
31
|
router.patch(
|
|
32
32
|
'/workspaces/:ws/public-projects',
|
|
@@ -36,9 +36,9 @@ export function mountPublicAdmin(router, deps) {
|
|
|
36
36
|
if (typeof enabled !== 'boolean') throw new HttpError(400, 'invalid_settings', 'enabled: true or false.')
|
|
37
37
|
const current = Boolean(req.t.get('SELECT public_projects FROM workspaces WHERE workspace_id = :ws').public_projects)
|
|
38
38
|
if (enabled && !current) {
|
|
39
|
-
// Putting boards on the open web: the owner
|
|
39
|
+
// Putting boards on the open web: the owner (and the passkey again when the workspace asks).
|
|
40
40
|
if (req.role !== 'owner') throw new HttpError(403, 'forbidden', 'Only an owner turns public projects on.')
|
|
41
|
-
|
|
41
|
+
stepUpOrThrow(req, 'tokens')
|
|
42
42
|
}
|
|
43
43
|
if (enabled !== current) {
|
|
44
44
|
transaction(db, () => {
|
|
@@ -69,7 +69,7 @@ export function mountPublicAdmin(router, deps) {
|
|
|
69
69
|
if (req.role !== 'owner') throw new HttpError(403, 'forbidden', 'Only an owner makes a project public.')
|
|
70
70
|
const on = req.t.get('SELECT public_projects FROM workspaces WHERE workspace_id = :ws').public_projects
|
|
71
71
|
if (!on) throw new HttpError(409, 'public_off', 'Public projects are off in this workspace. An owner turns them on in Settings.')
|
|
72
|
-
|
|
72
|
+
stepUpOrThrow(req, 'tokens')
|
|
73
73
|
const id = newPublicId()
|
|
74
74
|
req.t.run('UPDATE projects SET public_id = :pub, public_at = :at, public_by = :user WHERE workspace_id = :ws AND id = :id', {
|
|
75
75
|
pub: id,
|
package/src/hosted/ratelimit.js
CHANGED
|
@@ -55,6 +55,8 @@ export function createRateLimiter({ now = () => Date.now() } = {}) {
|
|
|
55
55
|
// and expensive to abuse; recovery codes get the tightest limit.
|
|
56
56
|
export const LIMITS = {
|
|
57
57
|
ceremony: { limit: 30, windowMs: 60_000 },
|
|
58
|
+
// POST /auth/tailnet/sign-in, per tailnet login.
|
|
59
|
+
tailnetSignIn: { limit: 30, windowMs: 60_000 },
|
|
58
60
|
// Failed recovery codes only: per handle and IP, and per IP. A stranger
|
|
59
61
|
// cannot use up someone else's attempts from another address.
|
|
60
62
|
recoveryFail: { limit: 5, windowMs: 15 * 60_000 },
|
|
@@ -101,4 +103,8 @@ export const LIMITS = {
|
|
|
101
103
|
deviceLookup: { limit: 10, windowMs: 60_000 },
|
|
102
104
|
// Workspace exports per person (each is a zip of everything).
|
|
103
105
|
export: { limit: 5, windowMs: 60 * 60_000 },
|
|
106
|
+
// Usage, activity and access review downloads, per person.
|
|
107
|
+
usageExport: { limit: 30, windowMs: 60 * 60_000 },
|
|
108
|
+
// Activity searches and filters by agent or project (they read the log entry by entry), per person.
|
|
109
|
+
activitySearch: { limit: 60, windowMs: 60_000 },
|
|
104
110
|
}
|
package/src/hosted/retention.js
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
// swaps board folders inside its own transaction, so the two never interleave,
|
|
17
17
|
// also when the CLI runs it from another process.
|
|
18
18
|
//
|
|
19
|
+
// Usage records (agent_runs: one small row per agent turn) are pruned by age:
|
|
20
|
+
// 400 days by default, or the workspace's own setting (`shapewall hosted admin
|
|
21
|
+
// retention <ws> --usage-days N`). A turn still running is never removed.
|
|
22
|
+
//
|
|
19
23
|
// A later push brings back the versions the pushing machine still keeps; the
|
|
20
24
|
// next run trims them again.
|
|
21
25
|
|
|
@@ -26,6 +30,7 @@ import { listVersions } from '../store.js'
|
|
|
26
30
|
import { transaction } from './db.js'
|
|
27
31
|
import { boardConfig } from './projects.js'
|
|
28
32
|
import { allWorkspaces, tenant } from './tenancy.js'
|
|
33
|
+
import { USAGE_RETENTION_DAYS, createUsage } from './usage.js'
|
|
29
34
|
|
|
30
35
|
export const RETENTION_DEFAULT = 2
|
|
31
36
|
export const RETENTION_EVERY_HOURS = 6
|
|
@@ -47,13 +52,23 @@ export function planBoardRetention(versions, referenced, keep) {
|
|
|
47
52
|
return remove
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
export function runRetention({
|
|
51
|
-
|
|
55
|
+
export function runRetention({
|
|
56
|
+
db,
|
|
57
|
+
dataDir,
|
|
58
|
+
keepDefault = RETENTION_DEFAULT,
|
|
59
|
+
usageDaysDefault = USAGE_RETENTION_DAYS,
|
|
60
|
+
dryRun = false,
|
|
61
|
+
workspaceId = null,
|
|
62
|
+
now = () => new Date(),
|
|
63
|
+
}) {
|
|
64
|
+
const result = { workspaces: 0, boards: 0, files: 0, bytes: 0, usageRows: 0, dryRun }
|
|
52
65
|
for (const workspace of allWorkspaces(db)) {
|
|
53
66
|
if (workspaceId && workspace.id !== workspaceId) continue
|
|
54
67
|
result.workspaces += 1
|
|
55
68
|
const keep = workspace.retention_versions ?? keepDefault
|
|
56
69
|
const t = tenant(db, workspace.id)
|
|
70
|
+
// Usage records (one row per agent turn) older than the workspace keeps them.
|
|
71
|
+
result.usageRows += transaction(db, () => createUsage(t, { now }).prune(workspace.retention_usage_days ?? usageDaysDefault, { dryRun }))
|
|
57
72
|
for (const row of t.all('SELECT project_id, board_id FROM boards WHERE workspace_id = :ws ORDER BY project_id, board_id')) {
|
|
58
73
|
if (!ID_RE.test(row.board_id)) continue
|
|
59
74
|
const removed = pruneBoard(db, t, dataDir, row.project_id, row.board_id, keep, dryRun)
|
|
@@ -133,6 +148,7 @@ export function startRetention({ db, dataDir, hours = RETENTION_EVERY_HOURS, kee
|
|
|
133
148
|
const run = () => {
|
|
134
149
|
try {
|
|
135
150
|
const result = runRetention({ db, dataDir, keepDefault })
|
|
151
|
+
if (result.usageRows) log(`retention: removed ${result.usageRows} old usage records`)
|
|
136
152
|
if (result.files)
|
|
137
153
|
log(`retention: removed ${result.files} old version files (${(result.bytes / 1048576).toFixed(1)} MB) from ${result.boards} boards`)
|
|
138
154
|
} catch (error) {
|