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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Chat turns in flight on a hosted server, in memory. A turn is one
|
|
2
|
+
// question on its way through a connected agent: the board posts it, the
|
|
3
|
+
// agent's machine picks it up over its link (src/hosted/agent-link.js),
|
|
4
|
+
// streams events back, and finishes it with the answer. This hub keeps what
|
|
5
|
+
// only matters while that happens:
|
|
6
|
+
//
|
|
7
|
+
// - the events so far (bounded), so a second viewer or a reloaded tab can
|
|
8
|
+
// replay them and follow on (subscribe with `after`)
|
|
9
|
+
// - who listens (the sender's response and any other viewer's)
|
|
10
|
+
// - the cancel flag (Stop), and when the machine was last heard from
|
|
11
|
+
//
|
|
12
|
+
// Stored state (the messages, the turn's row) lives in the database
|
|
13
|
+
// (src/hosted/chat-store.js). Nothing here survives a restart: turns that
|
|
14
|
+
// were running then are marked interrupted when their thread is next read.
|
|
15
|
+
//
|
|
16
|
+
// Keys carry the workspace, so one tenant's ids never meet another's.
|
|
17
|
+
|
|
18
|
+
export const TURN_LIMITS = {
|
|
19
|
+
// Live events kept per turn for replay. Past this the oldest text goes
|
|
20
|
+
// first; a late viewer then starts from what is left.
|
|
21
|
+
bufferBytes: 1024 * 1024,
|
|
22
|
+
// A running turn nobody has heard from in this long is interrupted when
|
|
23
|
+
// its agent has no link either.
|
|
24
|
+
lostMs: 45_000,
|
|
25
|
+
// However long the agent's machine allows, the server lets go after this.
|
|
26
|
+
maxMs: 30 * 60_000,
|
|
27
|
+
subscribers: 20,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const sizeOf = (data) => Buffer.byteLength(JSON.stringify(data))
|
|
31
|
+
|
|
32
|
+
export function createTurnHub({ now = () => Date.now(), limits = {} } = {}) {
|
|
33
|
+
const limit = { ...TURN_LIMITS, ...limits }
|
|
34
|
+
// turn id -> turn
|
|
35
|
+
const turns = new Map()
|
|
36
|
+
// `${workspace}:${project}:${board}:${thread}` -> turn id
|
|
37
|
+
const byThread = new Map()
|
|
38
|
+
|
|
39
|
+
const threadKey = (turn) => `${turn.workspaceId}:${turn.projectId}:${turn.boardId}:${turn.threadId}`
|
|
40
|
+
|
|
41
|
+
// A new turn. `seed`: events every subscriber sees first (the stored
|
|
42
|
+
// person's message). Returns the live turn.
|
|
43
|
+
function open({ id, workspaceId, projectId, boardId, threadId, agentId, kind = 'chat', startedBy = null, seed = [] }) {
|
|
44
|
+
const turn = {
|
|
45
|
+
id,
|
|
46
|
+
workspaceId,
|
|
47
|
+
projectId,
|
|
48
|
+
boardId,
|
|
49
|
+
threadId,
|
|
50
|
+
agentId,
|
|
51
|
+
kind,
|
|
52
|
+
startedBy,
|
|
53
|
+
state: 'queued',
|
|
54
|
+
cancel: false,
|
|
55
|
+
events: [],
|
|
56
|
+
bytes: 0,
|
|
57
|
+
// The next sequence number given to a browser event (1-based).
|
|
58
|
+
next: 1,
|
|
59
|
+
// The last batch the agent's machine sent, by its own numbering.
|
|
60
|
+
acked: 0,
|
|
61
|
+
subscribers: new Set(),
|
|
62
|
+
openedAt: now(),
|
|
63
|
+
heardAt: now(),
|
|
64
|
+
// What the answer's cards looked like last, by id: the stored answer
|
|
65
|
+
// is the machine's, but a turn that is cut short keeps these.
|
|
66
|
+
trimmed: false,
|
|
67
|
+
}
|
|
68
|
+
turns.set(id, turn)
|
|
69
|
+
byThread.set(threadKey(turn), id)
|
|
70
|
+
for (const event of seed) push(turn, event.name, event.data)
|
|
71
|
+
return turn
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function push(turn, name, data) {
|
|
75
|
+
const event = { seq: turn.next, name, data }
|
|
76
|
+
turn.next += 1
|
|
77
|
+
const bytes = sizeOf(data) + name.length + 16
|
|
78
|
+
turn.events.push({ ...event, bytes })
|
|
79
|
+
turn.bytes += bytes
|
|
80
|
+
// Over the cap: streamed text and thinking go first (the stored answer
|
|
81
|
+
// will have them); cards and statuses stay as long as they fit.
|
|
82
|
+
while (turn.bytes > limit.bufferBytes && turn.events.length > 1) {
|
|
83
|
+
const index = turn.events.findIndex((item) => item.name === 'text' || item.name === 'reasoning')
|
|
84
|
+
const [gone] = turn.events.splice(index >= 0 ? index : 0, 1)
|
|
85
|
+
turn.bytes -= gone.bytes
|
|
86
|
+
turn.trimmed = true
|
|
87
|
+
}
|
|
88
|
+
for (const subscriber of [...turn.subscribers]) {
|
|
89
|
+
try {
|
|
90
|
+
subscriber(event)
|
|
91
|
+
} catch {
|
|
92
|
+
turn.subscribers.delete(subscriber)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return event
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const get = (id) => turns.get(id) || null
|
|
99
|
+
const ofThread = (workspaceId, projectId, boardId, threadId) => get(byThread.get(`${workspaceId}:${projectId}:${boardId}:${threadId}`))
|
|
100
|
+
const ofAgent = (workspaceId, agentId) =>
|
|
101
|
+
[...turns.values()].filter((turn) => turn.workspaceId === workspaceId && turn.agentId === agentId)
|
|
102
|
+
|
|
103
|
+
// Events from `after` on, then every new one, until the turn ends (the
|
|
104
|
+
// listener then hears { name: 'end' } once). Returns the unsubscribe, or
|
|
105
|
+
// null when the turn has too many listeners.
|
|
106
|
+
function subscribe(turn, after, listener) {
|
|
107
|
+
if (turn.subscribers.size >= limit.subscribers) return null
|
|
108
|
+
for (const event of turn.events) if (event.seq > after) listener({ seq: event.seq, name: event.name, data: event.data })
|
|
109
|
+
turn.subscribers.add(listener)
|
|
110
|
+
return () => turn.subscribers.delete(listener)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The turn is over: every listener hears the last event and `end`.
|
|
114
|
+
function close(turn, name = null, data = null) {
|
|
115
|
+
if (!turns.has(turn.id)) return
|
|
116
|
+
if (name) push(turn, name, data)
|
|
117
|
+
turns.delete(turn.id)
|
|
118
|
+
if (byThread.get(threadKey(turn)) === turn.id) byThread.delete(threadKey(turn))
|
|
119
|
+
const listeners = [...turn.subscribers]
|
|
120
|
+
turn.subscribers.clear()
|
|
121
|
+
for (const listener of listeners) {
|
|
122
|
+
try {
|
|
123
|
+
listener({ seq: turn.next, name: 'end', data: null })
|
|
124
|
+
} catch {
|
|
125
|
+
/* a listener that went away */
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Turns whose machine went quiet (`linked(turn)`: its agent still holds a
|
|
131
|
+
// link) or that ran past the limit: the caller interrupts them.
|
|
132
|
+
function stale(linked) {
|
|
133
|
+
const time = now()
|
|
134
|
+
return [...turns.values()].filter((turn) => time - turn.openedAt > limit.maxMs || (time - turn.heardAt > limit.lostMs && !linked(turn)))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
open,
|
|
139
|
+
push,
|
|
140
|
+
get,
|
|
141
|
+
ofThread,
|
|
142
|
+
ofAgent,
|
|
143
|
+
subscribe,
|
|
144
|
+
close,
|
|
145
|
+
stale,
|
|
146
|
+
heard: (turn) => {
|
|
147
|
+
turn.heardAt = now()
|
|
148
|
+
},
|
|
149
|
+
all: () => [...turns.values()],
|
|
150
|
+
size: () => turns.size,
|
|
151
|
+
}
|
|
152
|
+
}
|