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.
Files changed (157) hide show
  1. package/CHANGELOG.md +501 -0
  2. package/README.md +87 -4
  3. package/THIRD_PARTY.md +15 -0
  4. package/dist/agent/package-lock.json +594 -2
  5. package/dist/client/assets/BoardChat-WS8mAIW6.js +27 -0
  6. package/dist/client/assets/{BuzzDialog-Ix9qJvim.js → BuzzDialog-B-Mlr6wF.js} +1 -1
  7. package/dist/client/assets/ChecksPanel-Dx1ZLBR6.js +1 -0
  8. package/dist/client/assets/History-sXhmpcvs.js +1 -0
  9. package/dist/client/assets/LocalSettings-CtGzz9F3.js +1 -0
  10. package/dist/client/assets/{Management-NVFDtSZB.js → Management-CGHe8Wt9.js} +1 -1
  11. package/dist/client/assets/QuickConnect-DEk84E4A.js +1 -0
  12. package/dist/client/assets/{ShareDialog-By0ETg6n.js → ShareDialog-CGGx-AYK.js} +2 -2
  13. package/dist/client/assets/{app-update-dialog-RGIw24iZ.js → app-update-dialog-_bVp8hnC.js} +1 -1
  14. package/dist/client/assets/{circle-x-B6KfScOE.js → circle-x-BWoHA1QY.js} +1 -1
  15. package/dist/client/assets/index-Bm-Xd3YN.js +37 -0
  16. package/dist/client/assets/index-C7Ostk3K.css +2 -0
  17. package/dist/client/assets/play-BzQ3tRTv.js +1 -0
  18. package/dist/client/assets/{refresh-cw-vkgvCCfR.js → refresh-cw-BYBMyDKT.js} +1 -1
  19. package/dist/client/assets/{runtime-Bft6x_6E.js → runtime-Bvq10IhH.js} +1 -1
  20. package/dist/client/assets/ui-CAY6myRA.js +41 -0
  21. package/dist/client/build-info.json +1 -1
  22. package/dist/client/index.html +3 -3
  23. package/dist/client/sw.js +2 -2
  24. package/dist/console/assets/LocalAccountsApp-CWRguRRL.js +1 -0
  25. package/dist/console/assets/LocalConsole--I2SaIpr.js +2 -0
  26. package/dist/console/assets/LocalUsage-BmpCZ36k.js +1 -0
  27. package/dist/console/assets/app-update-dialog-B8M9plaT.js +1 -0
  28. package/dist/console/assets/app-version-muKrQqbL.js +1 -0
  29. package/dist/console/assets/console-CrhTsPbz.css +2 -0
  30. package/dist/console/assets/console-DxapQ9oS.js +11 -0
  31. package/dist/console/assets/local-agents-CoqD4dSN.js +6 -0
  32. package/dist/console/assets/minus-DDQ0ydcM.js +1 -0
  33. package/dist/console/assets/tailnet-C5Flwl_d.js +2 -0
  34. package/dist/console/assets/theme-DCd0qh4l.js +1 -0
  35. package/dist/console/assets/ui-Bry1mnCY.js +41 -0
  36. package/dist/console/assets/usage-CIPWnHaS.css +1 -0
  37. package/dist/console/assets/usage-CqVjMb7m.js +5 -0
  38. package/dist/console/assets/usage-D1G0GgE3.js +56 -0
  39. package/dist/console/build-info.json +1 -1
  40. package/dist/console/console.html +8 -2
  41. package/docs/agent-hardening.md +206 -0
  42. package/docs/agent-recipes.md +23 -0
  43. package/docs/agent-workflow.md +5 -0
  44. package/docs/agents.md +49 -6
  45. package/docs/architecture.md +10 -4
  46. package/docs/deployment.md +39 -17
  47. package/docs/design-system.md +56 -7
  48. package/docs/hosted.md +1800 -46
  49. package/docs/images/board-overview.png +0 -0
  50. package/docs/images/journeys.png +0 -0
  51. package/docs/images/live-comment.png +0 -0
  52. package/docs/images/phone-comment.png +0 -0
  53. package/docs/images/phone-overview.png +0 -0
  54. package/docs/images/variant.png +0 -0
  55. package/docs/where-to-run.md +119 -3
  56. package/package.json +6 -1
  57. package/src/agent/backends/acp.js +745 -44
  58. package/src/agent/branch-mode.js +17 -3
  59. package/src/agent/card-hash.js +65 -0
  60. package/src/agent/context.js +41 -0
  61. package/src/agent/exec-paths.js +105 -0
  62. package/src/agent/routes.js +23 -2
  63. package/src/agent/run.js +11 -1
  64. package/src/agent/starter/cli.js +6 -1
  65. package/src/agent/turn-changes.js +70 -8
  66. package/src/agent/usage-log.js +251 -0
  67. package/src/cli/args.js +37 -0
  68. package/src/cli/commands.js +20 -5
  69. package/src/cli/help.js +73 -3
  70. package/src/cli/init.js +2 -1
  71. package/src/cli/serve.js +20 -5
  72. package/src/cli.js +8 -0
  73. package/src/hosted/access-cli.js +99 -1
  74. package/src/hosted/activity-core.js +232 -0
  75. package/src/hosted/activity.js +375 -0
  76. package/src/hosted/admin.js +87 -13
  77. package/src/hosted/agent-approvals.js +29 -4
  78. package/src/hosted/agent-link.js +1032 -0
  79. package/src/hosted/agent-policy.js +10 -3
  80. package/src/hosted/agent-presence.js +63 -22
  81. package/src/hosted/agent-routes.js +135 -0
  82. package/src/hosted/agents.js +1206 -0
  83. package/src/hosted/app.js +178 -12
  84. package/src/hosted/auth-routes.js +156 -15
  85. package/src/hosted/auth.js +123 -20
  86. package/src/hosted/board-routes.js +129 -5
  87. package/src/hosted/chat-frames.js +246 -0
  88. package/src/hosted/chat-job.js +204 -0
  89. package/src/hosted/chat-permissions.js +203 -0
  90. package/src/hosted/chat-routes.js +1009 -0
  91. package/src/hosted/chat-store.js +477 -0
  92. package/src/hosted/comment-files.js +11 -1
  93. package/src/hosted/comments.js +1 -1
  94. package/src/hosted/console-routes.js +122 -34
  95. package/src/hosted/db.js +295 -0
  96. package/src/hosted/device-routes.js +88 -10
  97. package/src/hosted/device.js +54 -4
  98. package/src/hosted/events.js +3 -3
  99. package/src/hosted/guards.js +337 -27
  100. package/src/hosted/http.js +6 -3
  101. package/src/hosted/membership.js +22 -3
  102. package/src/hosted/operator-access.js +418 -0
  103. package/src/hosted/operator.js +106 -2
  104. package/src/hosted/ops-cli.js +238 -3
  105. package/src/hosted/pages.js +4 -0
  106. package/src/hosted/passkey-policy.js +75 -0
  107. package/src/hosted/permissions.js +52 -6
  108. package/src/hosted/presence.js +31 -2
  109. package/src/hosted/projects.js +30 -2
  110. package/src/hosted/public.js +4 -4
  111. package/src/hosted/ratelimit.js +14 -0
  112. package/src/hosted/retention.js +18 -2
  113. package/src/hosted/server.js +123 -11
  114. package/src/hosted/shares.js +2 -2
  115. package/src/hosted/step-up-settings.js +68 -0
  116. package/src/hosted/step-up.js +135 -0
  117. package/src/hosted/tailnet-identity.js +24 -0
  118. package/src/hosted/tailnet-routes.js +342 -0
  119. package/src/hosted/tailnet.js +220 -0
  120. package/src/hosted/tailscale.js +75 -9
  121. package/src/hosted/tenancy.js +66 -1
  122. package/src/hosted/token-api.js +119 -20
  123. package/src/hosted/token-events.js +5 -3
  124. package/src/hosted/tokens.js +29 -6
  125. package/src/hosted/turn-hub.js +152 -0
  126. package/src/hosted/usage-core.js +624 -0
  127. package/src/hosted/usage-layout.js +724 -0
  128. package/src/hosted/usage-routes.js +375 -0
  129. package/src/hosted/usage-shape.js +256 -0
  130. package/src/hosted/usage.js +641 -0
  131. package/src/remote/agent-connect.js +469 -0
  132. package/src/remote/agent-fix.js +611 -0
  133. package/src/remote/agent-job.js +216 -0
  134. package/src/remote/agent-link.js +906 -0
  135. package/src/remote/agent-policy-file.js +242 -0
  136. package/src/remote/credentials.js +35 -1
  137. package/src/remote/login.js +44 -9
  138. package/src/remote/share.js +1 -1
  139. package/src/remote/tailnet-cli.js +547 -0
  140. package/src/server/app.js +15 -0
  141. package/src/server/pairing-routes.js +34 -5
  142. package/src/server/tailscale.js +97 -4
  143. package/src/tailnet-proof.js +766 -0
  144. package/dist/client/assets/BoardChat-DxehB761.js +0 -27
  145. package/dist/client/assets/ChecksPanel-pA_ueIaJ.js +0 -1
  146. package/dist/client/assets/History-C9N32kCv.js +0 -1
  147. package/dist/client/assets/LocalSettings-DawtKnvi.js +0 -1
  148. package/dist/client/assets/QuickConnect-DO1TjS1t.js +0 -1
  149. package/dist/client/assets/index-CsqLdqGx.css +0 -2
  150. package/dist/client/assets/index-DnZarJ3U.js +0 -37
  151. package/dist/client/assets/shield-check-QzwGhz0t.js +0 -1
  152. package/dist/client/assets/ui-DI-FGWWK.js +0 -41
  153. package/dist/console/assets/LocalAccountsApp-VOCZg8dg.js +0 -1
  154. package/dist/console/assets/LocalConsole-CMwAW-mF.js +0 -1
  155. package/dist/console/assets/app-update-dialog-Cw6UDqNP.js +0 -1
  156. package/dist/console/assets/console-DgfWmUEx.js +0 -55
  157. 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
+ }