shapewall 0.0.0-stage → 0.2.2
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 +139 -0
- package/Dockerfile.agent +45 -0
- package/LICENSE +202 -0
- package/NOTICE +12 -0
- package/README.md +651 -2
- package/THIRD_PARTY.md +165 -0
- package/bin/shapewall.js +29 -0
- package/dist/agent/package-lock.json +8384 -0
- package/dist/client/assets/BoardChat-D5SFd8HE.js +28 -0
- package/dist/client/assets/BuzzDialog-HWXBy52W.js +1 -0
- package/dist/client/assets/ChecksPanel-DTdImWoD.js +1 -0
- package/dist/client/assets/History-CEv6b-av.js +1 -0
- package/dist/client/assets/LocalSettings-C4vriEVQ.js +1 -0
- package/dist/client/assets/Management-DCfhcEUY.js +1 -0
- package/dist/client/assets/QuickConnect-DQGgUsl1.js +1 -0
- package/dist/client/assets/ShareDialog-C_plIto0.js +2 -0
- package/dist/client/assets/app-update-dialog-2hPz_N9G.js +1 -0
- package/dist/client/assets/circle-x-BZMPi8Zf.js +1 -0
- package/dist/client/assets/index-ByQRKVit.css +2 -0
- package/dist/client/assets/index-DweQ8Qtu.js +29 -0
- package/dist/client/assets/refresh-cw-CRow0Nbq.js +1 -0
- package/dist/client/assets/runtime-Bft6x_6E.js +4 -0
- package/dist/client/assets/square-A8EnIYLR.js +1 -0
- package/dist/client/assets/tts-dist-DYlBQmwG.js +18 -0
- package/dist/client/assets/tts-en-g2p-BPUtBFGG.js +1 -0
- package/dist/client/assets/tts-ort-wasm-simd-threaded-qh98TCA_.wasm +0 -0
- package/dist/client/assets/tts-ort.wasm.bundle.min-rEkcs_ow.js +12 -0
- package/dist/client/assets/tts-rolldown-runtime-D8NudN84.js +1 -0
- package/dist/client/assets/tts-spacy-en-tokenizer-6SNMl--A.json +1 -0
- package/dist/client/assets/tts-tts.worker-Bzm6aWbv.js +1 -0
- package/dist/client/assets/tts-us_gold-DcjeNMH1.json +92589 -0
- package/dist/client/assets/tts-us_silver-C964mEB5.json +93363 -0
- package/dist/client/assets/ui-CLbws0rx.js +41 -0
- package/dist/client/build-info.json +1 -0
- package/dist/client/favicon.svg +7 -0
- package/dist/client/icons/apple-touch-icon.png +0 -0
- package/dist/client/icons/icon-192.png +0 -0
- package/dist/client/icons/icon-512.png +0 -0
- package/dist/client/icons/maskable-512.png +0 -0
- package/dist/client/index.html +25 -0
- package/dist/client/manifest.webmanifest +15 -0
- package/dist/client/sw.js +53 -0
- package/dist/client/theme-boot.js +27 -0
- package/dist/console/assets/LocalAccountsApp-BQCcmj3x.js +1 -0
- package/dist/console/assets/LocalConsole-Bb2FUDs7.js +1 -0
- package/dist/console/assets/app-update-dialog-DIeYepLZ.js +1 -0
- package/dist/console/assets/console-C7uJLLOn.js +51 -0
- package/dist/console/assets/console-R8IBY3Am.css +2 -0
- package/dist/console/build-info.json +1 -0
- package/dist/console/console.html +21 -0
- package/dist/console/favicon.svg +7 -0
- package/dist/console/icons/apple-touch-icon.png +0 -0
- package/dist/console/icons/icon-192.png +0 -0
- package/dist/console/icons/icon-512.png +0 -0
- package/dist/console/icons/maskable-512.png +0 -0
- package/dist/console/manifest.webmanifest +15 -0
- package/dist/console/theme-boot.js +27 -0
- package/docs/agent-hardening.md +342 -0
- package/docs/agent-recipes.md +187 -0
- package/docs/agent-workflow.md +320 -0
- package/docs/agents.md +894 -0
- package/docs/architecture.md +242 -0
- package/docs/buzz.md +140 -0
- package/docs/capture-warnings.md +57 -0
- package/docs/config.md +489 -0
- package/docs/deployment.md +289 -0
- package/docs/design-system.md +162 -0
- package/docs/github.md +107 -0
- package/docs/hosted.md +764 -0
- 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/interaction-audits.md +40 -0
- package/docs/journeys.md +137 -0
- package/docs/local-accounts.md +80 -0
- package/docs/notifications.md +237 -0
- package/docs/page-checks.md +69 -0
- package/docs/performance.md +174 -0
- package/docs/starter-agent.md +325 -0
- package/docs/updates.md +87 -0
- package/examples/audits/interaction.audit.json +17 -0
- package/package.json +132 -4
- package/src/accounts/avatar.js +121 -0
- package/src/accounts/local.js +464 -0
- package/src/agent/acp/command.js +204 -0
- package/src/agent/acp/detect.js +75 -0
- package/src/agent/acp/sandbox.js +160 -0
- package/src/agent/agent-health.js +75 -0
- package/src/agent/backends/acp.js +1297 -0
- package/src/agent/backends/index.js +61 -0
- package/src/agent/backends/openai.js +308 -0
- package/src/agent/composer.js +221 -0
- package/src/agent/config.js +338 -0
- package/src/agent/context.js +191 -0
- package/src/agent/control.js +122 -0
- package/src/agent/errors.js +17 -0
- package/src/agent/feedback-loop.js +137 -0
- package/src/agent/manage.js +94 -0
- package/src/agent/next-steps.js +51 -0
- package/src/agent/owner-mcp.js +38 -0
- package/src/agent/plain-text.js +52 -0
- package/src/agent/ratings-core.js +213 -0
- package/src/agent/ratings.js +100 -0
- package/src/agent/reply-text.js +67 -0
- package/src/agent/routes.js +1065 -0
- package/src/agent/run.js +326 -0
- package/src/agent/settings-routes.js +704 -0
- package/src/agent/showable.js +23 -0
- package/src/agent/starter/approvals.js +181 -0
- package/src/agent/starter/build-image.js +90 -0
- package/src/agent/starter/cli.js +163 -0
- package/src/agent/starter/disk.js +53 -0
- package/src/agent/starter/doctor.js +180 -0
- package/src/agent/starter/egress-proxy.js +351 -0
- package/src/agent/starter/gate.js +90 -0
- package/src/agent/starter/loop.js +114 -0
- package/src/agent/starter/model-relay.js +289 -0
- package/src/agent/starter/pause.js +14 -0
- package/src/agent/starter/probe.js +272 -0
- package/src/agent/starter/prompt.js +41 -0
- package/src/agent/starter/push-guard.js +146 -0
- package/src/agent/starter/rpc.js +164 -0
- package/src/agent/starter/runtime.js +287 -0
- package/src/agent/starter/sandbox-main.js +121 -0
- package/src/agent/starter/settings.js +290 -0
- package/src/agent/starter/source.js +69 -0
- package/src/agent/starter/supervisor.js +755 -0
- package/src/agent/starter/sweep.js +46 -0
- package/src/agent/starter/tools.js +524 -0
- package/src/agent/starter/watch.js +84 -0
- package/src/agent/starter/worktree.js +409 -0
- package/src/agent/text-diff.js +210 -0
- package/src/agent/thread-history.js +223 -0
- package/src/agent/threads.js +399 -0
- package/src/agent/tools.js +200 -0
- package/src/agent/turn-changes.js +424 -0
- package/src/agent/undo-state.js +26 -0
- package/src/agent/user-settings.js +308 -0
- package/src/auth/record.js +375 -0
- package/src/broken-links.js +164 -0
- package/src/buzz/client.js +75 -0
- package/src/buzz/config.js +151 -0
- package/src/buzz/environment.js +13 -0
- package/src/buzz/gateway.js +192 -0
- package/src/buzz/routes.js +61 -0
- package/src/buzz/signer-child.js +205 -0
- package/src/buzz/store.js +89 -0
- package/src/buzz/transport.js +60 -0
- package/src/buzz/verify.js +140 -0
- package/src/capture/actions.js +159 -0
- package/src/capture/capture.js +776 -0
- package/src/capture/dom-names.js +189 -0
- package/src/capture/element-map.js +509 -0
- package/src/capture/live.js +827 -0
- package/src/capture/media-scheme.js +317 -0
- package/src/capture/network-summary.js +86 -0
- package/src/capture/pacing.js +34 -0
- package/src/capture/requests.js +167 -0
- package/src/capture/sanitize.js +752 -0
- package/src/checks/accessibility.js +134 -0
- package/src/checks/budgets.js +58 -0
- package/src/checks/cli.js +55 -0
- package/src/checks/comparison.js +113 -0
- package/src/checks/environments.js +32 -0
- package/src/checks/flow-config.js +82 -0
- package/src/checks/flow-origin.js +53 -0
- package/src/checks/flows.js +398 -0
- package/src/checks/lighthouse-auth.js +145 -0
- package/src/checks/lighthouse-findings.js +130 -0
- package/src/checks/lighthouse.js +395 -0
- package/src/checks/robots.js +85 -0
- package/src/checks/routes.js +52 -0
- package/src/checks/run-control.js +259 -0
- package/src/checks/runner.js +724 -0
- package/src/checks/schema.js +133 -0
- package/src/checks/seo-analysis.js +443 -0
- package/src/checks/seo-probe.js +190 -0
- package/src/checks/seo-snapshot.js +99 -0
- package/src/checks/store.js +214 -0
- package/src/checks/transport.js +47 -0
- package/src/cli/args.js +319 -0
- package/src/cli/capture.js +79 -0
- package/src/cli/commands.js +92 -0
- package/src/cli/comments.js +84 -0
- package/src/cli/help.js +243 -0
- package/src/cli/init.js +214 -0
- package/src/cli/misc.js +64 -0
- package/src/cli/notify.js +87 -0
- package/src/cli/open.js +22 -0
- package/src/cli/serve.js +274 -0
- package/src/cli/variant.js +82 -0
- package/src/cli/watch.js +70 -0
- package/src/cli.js +130 -0
- package/src/comment-fields.js +76 -0
- package/src/comments-cli.js +208 -0
- package/src/config-reload.js +100 -0
- package/src/config.js +1061 -0
- package/src/devices-cli.js +21 -0
- package/src/diff.js +95 -0
- package/src/discover.js +284 -0
- package/src/doctor.js +295 -0
- package/src/event-log.js +268 -0
- package/src/events-cli.js +102 -0
- package/src/events.js +113 -0
- package/src/export.js +119 -0
- package/src/feedback.js +246 -0
- package/src/github.js +551 -0
- package/src/hosted/LICENSE.md +105 -0
- package/src/hosted/access-cli.js +78 -0
- package/src/hosted/admin.js +682 -0
- package/src/hosted/agent-approvals.js +163 -0
- package/src/hosted/agent-policy.js +189 -0
- package/src/hosted/app.js +510 -0
- package/src/hosted/auth-routes.js +540 -0
- package/src/hosted/auth.js +536 -0
- package/src/hosted/backup.js +483 -0
- package/src/hosted/board-context.js +35 -0
- package/src/hosted/board-routes.js +486 -0
- package/src/hosted/board-view.js +94 -0
- package/src/hosted/clean-worker.js +24 -0
- package/src/hosted/cleaner.js +89 -0
- package/src/hosted/comments.js +355 -0
- package/src/hosted/console-routes.js +401 -0
- package/src/hosted/cookies.js +18 -0
- package/src/hosted/crypto.js +80 -0
- package/src/hosted/db.js +496 -0
- package/src/hosted/device-routes.js +175 -0
- package/src/hosted/device.js +233 -0
- package/src/hosted/events.js +63 -0
- package/src/hosted/guards.js +172 -0
- package/src/hosted/guest-view.js +65 -0
- package/src/hosted/http.js +39 -0
- package/src/hosted/import.js +300 -0
- package/src/hosted/mail.js +73 -0
- package/src/hosted/mcp-http.js +71 -0
- package/src/hosted/membership.js +114 -0
- package/src/hosted/operator.js +478 -0
- package/src/hosted/ops-cli.js +345 -0
- package/src/hosted/pages.js +146 -0
- package/src/hosted/permissions.js +113 -0
- package/src/hosted/presence.js +372 -0
- package/src/hosted/projects.js +124 -0
- package/src/hosted/public.js +109 -0
- package/src/hosted/push.js +622 -0
- package/src/hosted/quotas.js +115 -0
- package/src/hosted/ratelimit.js +96 -0
- package/src/hosted/rebind.js +316 -0
- package/src/hosted/retention.js +128 -0
- package/src/hosted/server.js +260 -0
- package/src/hosted/setup-link.js +64 -0
- package/src/hosted/setup.js +323 -0
- package/src/hosted/shares.js +444 -0
- package/src/hosted/tailscale.js +204 -0
- package/src/hosted/tenancy.js +301 -0
- package/src/hosted/token-api.js +455 -0
- package/src/hosted/token-events.js +60 -0
- package/src/hosted/tokens.js +57 -0
- package/src/hosted/turnstile.js +49 -0
- package/src/hosted/usercontent.js +154 -0
- package/src/hosted/zip.js +155 -0
- package/src/invocation.js +58 -0
- package/src/journey-paths.js +282 -0
- package/src/journeys.js +189 -0
- package/src/links.js +106 -0
- package/src/local-projects.js +182 -0
- package/src/lock.js +193 -0
- package/src/mcp.js +417 -0
- package/src/mentions.js +151 -0
- package/src/net.js +15 -0
- package/src/notify/config.js +275 -0
- package/src/notify/index.js +301 -0
- package/src/notify/lease.js +73 -0
- package/src/notify/messages.js +212 -0
- package/src/notify/run.js +174 -0
- package/src/pixeldiff.js +49 -0
- package/src/png.js +143 -0
- package/src/reactions.js +111 -0
- package/src/remote/cli.js +133 -0
- package/src/remote/credentials.js +62 -0
- package/src/remote/ids.js +12 -0
- package/src/remote/login.js +155 -0
- package/src/remote/remote-mcp.js +237 -0
- package/src/remote/remote-watch.js +291 -0
- package/src/remote/remote.js +313 -0
- package/src/remote/share-state.js +78 -0
- package/src/remote/share.js +369 -0
- package/src/remote/terminal.js +13 -0
- package/src/serve-state.js +64 -0
- package/src/server/app.js +824 -0
- package/src/server/devices.js +186 -0
- package/src/server/local-console.js +28 -0
- package/src/server/local-user.js +59 -0
- package/src/server/pairing-routes.js +159 -0
- package/src/server/share-routes.js +89 -0
- package/src/server/tailscale.js +97 -0
- package/src/sitemap.js +431 -0
- package/src/store.js +983 -0
- package/src/tokens.js +11 -0
- package/src/update/routes.js +245 -0
- package/src/watch.js +403 -0
- package/src/which.js +58 -0
package/src/reactions.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Emoji reactions on comments and replies. No imports, so the local store,
|
|
2
|
+
// the hosted server, the static export's browser comments and the public
|
|
3
|
+
// demo's in-browser backend all keep and show reactions the same way.
|
|
4
|
+
//
|
|
5
|
+
// Stored on a comment or reply as `reactions: [{ emoji, by: [person] }]`,
|
|
6
|
+
// one entry per emoji (in REACTIONS order), each person once. A person is
|
|
7
|
+
// { name } on a local board (matched by name), { name, handle, user } on a
|
|
8
|
+
// hosted one (matched by account; `user` never leaves the server). Readers
|
|
9
|
+
// get { emoji, count, by: [{ name, handle? }] }. Reactions are for people:
|
|
10
|
+
// agents never set them, and agent-facing outputs (MCP, `shapewall comments`,
|
|
11
|
+
// the token API, the chat) leave them out.
|
|
12
|
+
|
|
13
|
+
// A small fixed set, so a reaction is never arbitrary text.
|
|
14
|
+
export const REACTIONS = ['👍', '❤️', '🎉', '😄', '👀', '🚀']
|
|
15
|
+
export const REACTION_PEOPLE_MAX = 200
|
|
16
|
+
|
|
17
|
+
export const REACTION_LABELS = {
|
|
18
|
+
'👍': 'thumbs up',
|
|
19
|
+
'❤️': 'heart',
|
|
20
|
+
'🎉': 'party',
|
|
21
|
+
'😄': 'smile',
|
|
22
|
+
'👀': 'eyes',
|
|
23
|
+
'🚀': 'rocket',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const isReaction = (value) => typeof value === 'string' && REACTIONS.includes(value)
|
|
27
|
+
|
|
28
|
+
const cleanName = (value) =>
|
|
29
|
+
typeof value === 'string'
|
|
30
|
+
? value
|
|
31
|
+
// eslint-disable-next-line no-control-regex
|
|
32
|
+
.replace(/[\u0000-\u001f\u007f]+/g, ' ')
|
|
33
|
+
.replace(/\s+/g, ' ')
|
|
34
|
+
.trim()
|
|
35
|
+
.slice(0, 80)
|
|
36
|
+
: ''
|
|
37
|
+
|
|
38
|
+
// Who a person is, for "has this person reacted": the account when there is
|
|
39
|
+
// one, otherwise the name (case and spacing ignored).
|
|
40
|
+
export function reactorKey(person) {
|
|
41
|
+
if (!person || typeof person !== 'object') return ''
|
|
42
|
+
if (typeof person.user === 'string' && person.user) return `u:${person.user}`
|
|
43
|
+
return `n:${cleanName(person.name).toLowerCase()}`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function cleanPerson(person) {
|
|
47
|
+
const name = cleanName(person?.name)
|
|
48
|
+
if (!name) return null
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
...(typeof person.handle === 'string' && /^[a-z][\w.-]{0,39}$/.test(person.handle) ? { handle: person.handle } : {}),
|
|
52
|
+
...(typeof person.user === 'string' && person.user ? { user: person.user.slice(0, 80) } : {}),
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The stored list, cleaned: known emoji only, in order, each person once,
|
|
57
|
+
// empty entries dropped. Anything else (older data, a hand edit) reads as none.
|
|
58
|
+
export function normalizeReactions(value) {
|
|
59
|
+
if (!Array.isArray(value)) return []
|
|
60
|
+
const byEmoji = new Map()
|
|
61
|
+
for (const entry of value) {
|
|
62
|
+
if (!entry || !isReaction(entry.emoji) || !Array.isArray(entry.by)) continue
|
|
63
|
+
const people = byEmoji.get(entry.emoji) || []
|
|
64
|
+
const seen = new Set(people.map(reactorKey))
|
|
65
|
+
for (const raw of entry.by) {
|
|
66
|
+
const person = cleanPerson(raw)
|
|
67
|
+
if (!person || seen.has(reactorKey(person)) || people.length >= REACTION_PEOPLE_MAX) continue
|
|
68
|
+
seen.add(reactorKey(person))
|
|
69
|
+
people.push(person)
|
|
70
|
+
}
|
|
71
|
+
byEmoji.set(entry.emoji, people)
|
|
72
|
+
}
|
|
73
|
+
return REACTIONS.filter((emoji) => byEmoji.get(emoji)?.length).map((emoji) => ({ emoji, by: byEmoji.get(emoji) }))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Adds the person's reaction, or takes it away when they had it. Returns
|
|
77
|
+
// { reactions, added }. Throws a plain Error with `code` for a bad emoji or a
|
|
78
|
+
// full list; callers turn it into their own error type.
|
|
79
|
+
export function toggleReaction(list, emoji, person) {
|
|
80
|
+
if (!isReaction(emoji)) throw Object.assign(new Error(`Reactions are ${REACTIONS.join(' ')}.`), { code: 'invalid_reaction' })
|
|
81
|
+
const who = cleanPerson(person)
|
|
82
|
+
if (!who) throw Object.assign(new Error('A reaction needs a name.'), { code: 'invalid_reaction' })
|
|
83
|
+
const key = reactorKey(who)
|
|
84
|
+
const current = normalizeReactions(list)
|
|
85
|
+
const entry = current.find((item) => item.emoji === emoji)
|
|
86
|
+
const had = Boolean(entry?.by.some((item) => reactorKey(item) === key))
|
|
87
|
+
if (!had && (entry?.by.length || 0) >= REACTION_PEOPLE_MAX)
|
|
88
|
+
throw Object.assign(new Error('That reaction is full.'), { code: 'too_many_reactions' })
|
|
89
|
+
const next = had
|
|
90
|
+
? current.map((item) => (item.emoji === emoji ? { ...item, by: item.by.filter((person) => reactorKey(person) !== key) } : item))
|
|
91
|
+
: entry
|
|
92
|
+
? current.map((item) => (item.emoji === emoji ? { ...item, by: [...item.by, who] } : item))
|
|
93
|
+
: [...current, { emoji, by: [who] }]
|
|
94
|
+
return { reactions: normalizeReactions(next), added: !had }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// What readers get: counts, and names and handles only (never the account id).
|
|
98
|
+
export function publicReactions(value) {
|
|
99
|
+
return normalizeReactions(value).map((entry) => ({
|
|
100
|
+
emoji: entry.emoji,
|
|
101
|
+
count: entry.by.length,
|
|
102
|
+
by: entry.by.map((person) => ({ name: person.name, ...(person.handle ? { handle: person.handle } : {}) })),
|
|
103
|
+
}))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// For share link guests: how many, not who.
|
|
107
|
+
export function countedReactions(value) {
|
|
108
|
+
return (Array.isArray(value) ? value : [])
|
|
109
|
+
.filter((entry) => entry && isReaction(entry.emoji) && Number(entry.count) > 0)
|
|
110
|
+
.map((entry) => ({ emoji: entry.emoji, count: Number(entry.count), by: [] }))
|
|
111
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Command-line parts that talk to a hosted Shapewall: `push`, `hosted`, and
|
|
2
|
+
// the --remote forms of `comments`, `watch` and `mcp`.
|
|
3
|
+
|
|
4
|
+
import { portableChecks } from '../checks/transport.js'
|
|
5
|
+
import { getBoard, loadConfig } from '../config.js'
|
|
6
|
+
import { formatFeedback, formatFeedbackForAgent, untrustedJson } from '../feedback.js'
|
|
7
|
+
import { AGENT_STATUSES, readManifest, readVariants } from '../store.js'
|
|
8
|
+
import { createRemote, pushDefinition, pushFiles, readCaptureFile, remoteSettings } from './remote.js'
|
|
9
|
+
import { safeOut, terminalSafe } from './terminal.js'
|
|
10
|
+
|
|
11
|
+
export async function push(flags, print) {
|
|
12
|
+
// Names and URLs here come from the server: cleaned before printing.
|
|
13
|
+
const out = safeOut(print)
|
|
14
|
+
const config = loadConfig(flags.config)
|
|
15
|
+
const remote = createRemote(remoteSettings(flags))
|
|
16
|
+
const boards = flags.board ? [getBoard(config, flags.board)] : config.boards
|
|
17
|
+
const project = await remote.project()
|
|
18
|
+
for (const board of boards) {
|
|
19
|
+
const manifest = readManifest(config, board.id)
|
|
20
|
+
if (!manifest) throw new Error(`Board "${board.id}" has no captures yet. Run "shapewall capture --board ${board.id}" first.`)
|
|
21
|
+
const checks = portableChecks(config, board, { includeChecks: !!flags['include-checks'] })
|
|
22
|
+
const files = pushFiles(config, board)
|
|
23
|
+
const started = await remote.startPush(pushDefinition(config, board))
|
|
24
|
+
if (checks && !started.limits.checks)
|
|
25
|
+
throw new Error('This server does not support checks. Update it before explicitly including diagnostics.')
|
|
26
|
+
out(`Pushing board "${board.id}" (${files.length} files) to ${project.workspace.name} / ${project.project.name}`)
|
|
27
|
+
let bytes = 0
|
|
28
|
+
let done = 0
|
|
29
|
+
for (const [area, name, file] of files) {
|
|
30
|
+
// A server from before element maps does not take them (its boards keep x/y pins).
|
|
31
|
+
if (name.endsWith('.elements.json') && !started.limits.elements) continue
|
|
32
|
+
// Never through a symlink (see readCaptureFile).
|
|
33
|
+
const data = readCaptureFile(config, file)
|
|
34
|
+
const cap = name.endsWith('.html')
|
|
35
|
+
? started.limits.html
|
|
36
|
+
: name.endsWith('.elements.json')
|
|
37
|
+
? started.limits.elements
|
|
38
|
+
: started.limits.png
|
|
39
|
+
if (data.length > cap) {
|
|
40
|
+
out(` skipped ${area}/${name}: ${(data.length / 1048576).toFixed(1)} MB is over the server's cap`)
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
await remote.pushFile(started.id, area, name, data)
|
|
44
|
+
bytes += data.length
|
|
45
|
+
done += 1
|
|
46
|
+
if (done % 25 === 0) out(` ${done}/${files.length} files`)
|
|
47
|
+
}
|
|
48
|
+
const result = await remote.commitPush(started.id, { manifest, variants: readVariants(config, board.id), checks })
|
|
49
|
+
if (checks && result.checks !== checks.reports.length) throw new Error('The server did not confirm all included check reports.')
|
|
50
|
+
out(`Pushed ${result.files} files (${(bytes / 1048576).toFixed(1)} MB). Board: ${result.url}`)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function mentionOf(value) {
|
|
55
|
+
if (value === undefined) return null
|
|
56
|
+
const handle = String(value).replace(/^@/, '').toLowerCase()
|
|
57
|
+
if (!/^[a-z][\w.-]{0,39}$/.test(handle)) throw new Error('--mention needs a name like robin or agent')
|
|
58
|
+
return handle
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The board on the hosted project: --board, else the only/first one pushed.
|
|
62
|
+
export async function remoteBoard(remote, wanted) {
|
|
63
|
+
const project = await remote.project()
|
|
64
|
+
if (!project.boards.length) throw new Error(`Nothing is pushed to ${project.project.name} yet. Run "shapewall push".`)
|
|
65
|
+
if (wanted) {
|
|
66
|
+
if (!project.boards.some((item) => item.id === wanted))
|
|
67
|
+
throw new Error(`No board "${wanted}" on ${project.project.name} (have: ${project.boards.map((item) => item.id).join(', ')})`)
|
|
68
|
+
return { project, boardId: wanted }
|
|
69
|
+
}
|
|
70
|
+
return { project, boardId: project.boards[0].id }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function remoteComments(positional, flags, print) {
|
|
74
|
+
// --json prints JSON as is (escaped); text is cleaned before printing.
|
|
75
|
+
const out = (text) => print(flags.json ? text : terminalSafe(text))
|
|
76
|
+
const remote = createRemote(remoteSettings(flags))
|
|
77
|
+
const { boardId } = await remoteBoard(remote, flags.board)
|
|
78
|
+
const action = positional[0] || 'list'
|
|
79
|
+
if (action === 'list') {
|
|
80
|
+
const status = flags.all ? 'all' : flags.resolved ? 'resolved' : 'open'
|
|
81
|
+
const report = await remote.comments(boardId, {
|
|
82
|
+
status,
|
|
83
|
+
page: flags.page || null,
|
|
84
|
+
mention: mentionOf(flags.mention),
|
|
85
|
+
guests: Boolean(flags['include-guests']),
|
|
86
|
+
})
|
|
87
|
+
out(
|
|
88
|
+
flags['for-agent']
|
|
89
|
+
? formatFeedbackForAgent(report)
|
|
90
|
+
: flags.json
|
|
91
|
+
? JSON.stringify(untrustedJson(report), null, 2)
|
|
92
|
+
: formatFeedback(report),
|
|
93
|
+
)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
const id = positional[1]
|
|
97
|
+
// A share link guest's comment needs --include-guests here too.
|
|
98
|
+
const guests = Boolean(flags['include-guests'])
|
|
99
|
+
if (action === 'resolve' || action === 'reopen') {
|
|
100
|
+
if (!id) throw new Error(`usage: shapewall comments ${action} ID --remote URL`)
|
|
101
|
+
const { comment } =
|
|
102
|
+
action === 'resolve'
|
|
103
|
+
? await remote.resolve(boardId, id, {
|
|
104
|
+
note: typeof flags.note === 'string' ? flags.note : undefined,
|
|
105
|
+
fixRef: typeof flags.ref === 'string' ? flags.ref : undefined,
|
|
106
|
+
guests,
|
|
107
|
+
})
|
|
108
|
+
: await remote.reopen(boardId, id, { guests })
|
|
109
|
+
out(flags.json ? JSON.stringify({ comment }, null, 2) : `#${comment.id} is ${comment.status}`)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
if (action === 'reply') {
|
|
113
|
+
const body = typeof flags.body === 'string' ? flags.body : positional[2]
|
|
114
|
+
if (!id || !body) throw new Error('usage: shapewall comments reply ID --body TEXT --remote URL')
|
|
115
|
+
const { comment, reply } = await remote.reply(boardId, id, { body, guests })
|
|
116
|
+
out(flags.json ? JSON.stringify({ comment, reply }, null, 2) : `Replied to #${comment.id} as ${reply.author}`)
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
if (action === 'status') {
|
|
120
|
+
const value = positional[2]
|
|
121
|
+
if (!id || !value) throw new Error(`usage: shapewall comments status ID ${[...AGENT_STATUSES, 'clear'].join('|')} --remote URL`)
|
|
122
|
+
if (![...AGENT_STATUSES, 'clear'].includes(value)) {
|
|
123
|
+
throw new Error(`unknown status '${value.slice(0, 40)}' (use: ${[...AGENT_STATUSES, 'clear'].join(', ')})`)
|
|
124
|
+
}
|
|
125
|
+
if (typeof flags.note === 'string' && flags.note.trim()) {
|
|
126
|
+
await remote.reply(boardId, id, { body: flags.note, guests })
|
|
127
|
+
}
|
|
128
|
+
const { comment } = await remote.setAgentStatus(boardId, id, value === 'clear' ? null : value, { guests })
|
|
129
|
+
out(flags.json ? JSON.stringify({ comment }, null, 2) : `#${comment.id} agent status: ${comment.agentStatus || 'none'}`)
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
throw new Error(`unknown comments action "${action}" (list, resolve, reopen, reply, status)`)
|
|
133
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Tokens that `shapewall login` saved, one per hosted server, in
|
|
2
|
+
// $XDG_CONFIG_HOME/shapewall/credentials.json (default ~/.config/...): the
|
|
3
|
+
// folder 0700, the file 0600, written whole through a temporary file. The
|
|
4
|
+
// --remote commands read it when $SHAPEWALL_TOKEN and --token-file are not
|
|
5
|
+
// set. Nothing here ever prints a token.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import { randomBytes } from 'node:crypto'
|
|
9
|
+
import os from 'node:os'
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
|
|
12
|
+
export function credentialsFile(env = process.env) {
|
|
13
|
+
const base = env.XDG_CONFIG_HOME && path.isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(os.homedir(), '.config')
|
|
14
|
+
return path.join(base, 'shapewall', 'credentials.json')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function readAll(file) {
|
|
18
|
+
let text
|
|
19
|
+
try {
|
|
20
|
+
text = fs.readFileSync(file, 'utf8')
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error.code === 'ENOENT') return { version: 1, servers: {} }
|
|
23
|
+
throw error
|
|
24
|
+
}
|
|
25
|
+
if (process.platform !== 'win32') {
|
|
26
|
+
const mode = fs.statSync(file).mode & 0o777
|
|
27
|
+
if (mode & 0o077) throw new Error(`${file} can be read by other users of this machine. Run: chmod 600 "${file}"`)
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const data = JSON.parse(text)
|
|
31
|
+
return data && typeof data.servers === 'object' && data.servers ? data : { version: 1, servers: {} }
|
|
32
|
+
} catch {
|
|
33
|
+
throw new Error(`${file} is not valid JSON. Delete it and run shapewall login again.`)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The saved login for one origin (https://app.example.com), or null.
|
|
38
|
+
export function readCredential(origin, env = process.env) {
|
|
39
|
+
const entry = readAll(credentialsFile(env)).servers[origin]
|
|
40
|
+
return entry && typeof entry.token === 'string' ? entry : null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function saveCredential(origin, entry, env = process.env) {
|
|
44
|
+
const file = credentialsFile(env)
|
|
45
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 })
|
|
46
|
+
// mkdir's mode only applies to a folder it creates: make an existing one private too.
|
|
47
|
+
if (process.platform !== 'win32') fs.chmodSync(path.dirname(file), 0o700)
|
|
48
|
+
const data = readAll(file)
|
|
49
|
+
data.version = 1
|
|
50
|
+
data.servers[origin] = entry
|
|
51
|
+
// A fresh, unguessable temporary file ('wx' never follows a planted symlink).
|
|
52
|
+
const temp = `${file}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`
|
|
53
|
+
try {
|
|
54
|
+
fs.writeFileSync(temp, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600, flag: 'wx' })
|
|
55
|
+
fs.renameSync(temp, file)
|
|
56
|
+
} catch (error) {
|
|
57
|
+
fs.rmSync(temp, { force: true })
|
|
58
|
+
throw error
|
|
59
|
+
}
|
|
60
|
+
if (process.platform !== 'win32') fs.chmodSync(file, 0o600)
|
|
61
|
+
return file
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Id formats shared by the hosted server and its clients (push, remote
|
|
2
|
+
// comments, watch, MCP). Kept outside src/hosted so the Apache-2.0 client code
|
|
3
|
+
// does not depend on the FSL-licensed server.
|
|
4
|
+
|
|
5
|
+
export const ID_PATTERNS = {
|
|
6
|
+
workspace: /^ws_[a-f0-9]{24}$/,
|
|
7
|
+
project: /^pr_[a-f0-9]{24}$/,
|
|
8
|
+
user: /^us_[a-f0-9]{24}$/,
|
|
9
|
+
token: /^tk_[a-f0-9]{24}$/,
|
|
10
|
+
invite: /^iv_[a-f0-9]{24}$/,
|
|
11
|
+
push: /^ps_[a-f0-9]{24}$/,
|
|
12
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// `shapewall login --remote URL`: gets a project token through the browser
|
|
2
|
+
// instead of copying one. It starts a login on the server, shows a short
|
|
3
|
+
// code and opens the console's /device page; someone with the admin role
|
|
4
|
+
// types the code there, picks the project and approves (with a passkey
|
|
5
|
+
// check). The server makes a token named after this machine and hands it
|
|
6
|
+
// over once; it goes into the credentials file (0600, see credentials.js)
|
|
7
|
+
// and is never printed. `push`, `comments`, `watch` and `mcp --remote` use
|
|
8
|
+
// it from then on.
|
|
9
|
+
|
|
10
|
+
import os from 'node:os'
|
|
11
|
+
import { spawn } from 'node:child_process'
|
|
12
|
+
import { credentialsFile, saveCredential } from './credentials.js'
|
|
13
|
+
import { readBounded, remoteOrigin } from './remote.js'
|
|
14
|
+
import { safeOut, terminalSafe } from './terminal.js'
|
|
15
|
+
|
|
16
|
+
// No shell anywhere: on Windows `cmd /c start` would run `&`, `|` or `^` in
|
|
17
|
+
// the URL as commands, so the URL goes to the URL handler directly.
|
|
18
|
+
const OPENERS = { darwin: ['open'], win32: ['rundll32', 'url.dll,FileProtocolHandler'] }
|
|
19
|
+
|
|
20
|
+
// The console's approval page for an origin from remoteOrigin (https, or
|
|
21
|
+
// http to this machine). The CLI builds it itself: never a URL the server
|
|
22
|
+
// sent, which could point anywhere or carry characters a shell would run.
|
|
23
|
+
// Null when the origin is not a plain http(s) origin with an ordinary host.
|
|
24
|
+
export function deviceLoginUrl(origin) {
|
|
25
|
+
let url
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(String(origin))
|
|
28
|
+
} catch {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') return null
|
|
32
|
+
if (url.username || url.password || url.origin !== String(origin).replace(/\/+$/, '')) return null
|
|
33
|
+
// Hostnames (letters, digits, dots, dashes; IDNs are punycode by now) and IP literals only.
|
|
34
|
+
if (!/^(?:[a-z0-9-]+(?:\.[a-z0-9-]+)*\.?|\[[0-9a-f:.]+\])$/i.test(url.hostname)) return null
|
|
35
|
+
return `${url.origin}/device`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The command and arguments that open a URL on a platform (no shell).
|
|
39
|
+
export function openerFor(url, platform = process.platform) {
|
|
40
|
+
const [command, ...args] = OPENERS[platform] || ['xdg-open']
|
|
41
|
+
return [command, [...args, url]]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Opens the URL in a browser, quietly; failing is fine (the URL is printed).
|
|
45
|
+
function openBrowser(url, env) {
|
|
46
|
+
if (env.SHAPEWALL_NO_BROWSER === '1' || env.CI) return false
|
|
47
|
+
if (process.platform === 'linux' && !env.DISPLAY && !env.WAYLAND_DISPLAY) return false
|
|
48
|
+
// Only the page this CLI built (deviceLoginUrl), never anything else.
|
|
49
|
+
if (typeof url !== 'string' || !/^https?:\/\/[A-Za-z0-9.:[\]-]+\/device$/.test(url)) return false
|
|
50
|
+
const [command, args] = openerFor(url)
|
|
51
|
+
try {
|
|
52
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true, windowsHide: true, shell: false })
|
|
53
|
+
child.on('error', () => {})
|
|
54
|
+
child.unref()
|
|
55
|
+
return true
|
|
56
|
+
} catch {
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function post(fetchImpl, origin, pathname, body) {
|
|
62
|
+
const response = await fetchImpl(`${origin}${pathname}`, {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
65
|
+
body: JSON.stringify(body),
|
|
66
|
+
redirect: 'error',
|
|
67
|
+
})
|
|
68
|
+
let data = null
|
|
69
|
+
try {
|
|
70
|
+
// A login answer is small: a server cannot stream this process full.
|
|
71
|
+
data = JSON.parse((await readBounded(response, 65536)).toString('utf8'))
|
|
72
|
+
} catch {
|
|
73
|
+
data = null
|
|
74
|
+
}
|
|
75
|
+
return { status: response.status, data }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function login(
|
|
79
|
+
flags,
|
|
80
|
+
out,
|
|
81
|
+
{
|
|
82
|
+
env = process.env,
|
|
83
|
+
fetchImpl = fetch,
|
|
84
|
+
open = openBrowser,
|
|
85
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
86
|
+
signal = null,
|
|
87
|
+
purpose = null,
|
|
88
|
+
} = {},
|
|
89
|
+
) {
|
|
90
|
+
out = safeOut(out)
|
|
91
|
+
const origin = remoteOrigin(flags, env)
|
|
92
|
+
const machine = os.hostname().split('.')[0] || 'this computer'
|
|
93
|
+
const started = await post(fetchImpl, origin, '/api/v1/device/start', { name: machine, ...(purpose === 'import' ? { purpose } : {}) })
|
|
94
|
+
if (started.status !== 201 || !started.data?.deviceCode) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
terminalSafe(started.data?.error?.message) || `Could not start a login on ${origin} (${started.status}). Is it a Shapewall server?`,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
const { deviceCode, interval = 3, expiresIn = 600 } = started.data
|
|
100
|
+
const userCode = terminalSafe(started.data.userCode)
|
|
101
|
+
if (!/^[A-Z]{4}-[A-Z]{4}$/.test(userCode)) throw new Error('The server sent no usable login code.')
|
|
102
|
+
// The page is ours to build: the server's verificationUrl is not used.
|
|
103
|
+
const page = deviceLoginUrl(origin)
|
|
104
|
+
if (!page) throw new Error(`Cannot build a login page for ${origin}; open its /device page yourself.`)
|
|
105
|
+
out(`To log in, open ${page} and enter this code:`)
|
|
106
|
+
out('')
|
|
107
|
+
out(` ${userCode}`)
|
|
108
|
+
out('')
|
|
109
|
+
out(`Check that the console shows the same code and "${machine}". It expires in ${Math.round(Number(expiresIn) / 60) || 10} minutes.`)
|
|
110
|
+
if (open(page, env)) out('(Opened it in your browser.)')
|
|
111
|
+
const deadline = Date.now() + Math.min(Math.max(Number(expiresIn) || 600, 1), 3600) * 1000
|
|
112
|
+
for (;;) {
|
|
113
|
+
if (signal?.aborted) throw new Error('Login cancelled.')
|
|
114
|
+
if (Date.now() > deadline) throw new Error('The code expired before anyone approved it. Run shapewall login again.')
|
|
115
|
+
// 1 to 30 seconds whatever the server says (NaN would poll in a tight loop).
|
|
116
|
+
await sleep(Math.min(Math.max(Number(interval) || 3, 1), 30) * 1000)
|
|
117
|
+
let polled
|
|
118
|
+
try {
|
|
119
|
+
polled = await post(fetchImpl, origin, '/api/v1/device/poll', { deviceCode })
|
|
120
|
+
} catch {
|
|
121
|
+
continue // the network blinked: try again on the next tick
|
|
122
|
+
}
|
|
123
|
+
if (polled.status === 202) continue
|
|
124
|
+
if (polled.status === 429) {
|
|
125
|
+
await sleep(5000)
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
if (polled.status !== 200 || polled.data?.status !== 'approved') {
|
|
129
|
+
throw new Error(terminalSafe(polled.data?.error?.message) || `The login did not finish (${polled.status}).`)
|
|
130
|
+
}
|
|
131
|
+
const result = polled.data
|
|
132
|
+
if (typeof result.token !== 'string' || !/^swp_[A-Za-z0-9_-]{43}$/.test(result.token)) throw new Error('The server sent no token.')
|
|
133
|
+
const file = saveCredential(
|
|
134
|
+
origin,
|
|
135
|
+
{
|
|
136
|
+
token: result.token,
|
|
137
|
+
tokenName: result.tokenName || null,
|
|
138
|
+
workspace: result.workspace || null,
|
|
139
|
+
project: result.project || null,
|
|
140
|
+
scopes: Array.isArray(result.scopes) ? result.scopes : [],
|
|
141
|
+
expiresAt: result.expiresAt || null,
|
|
142
|
+
savedAt: new Date().toISOString(),
|
|
143
|
+
},
|
|
144
|
+
env,
|
|
145
|
+
)
|
|
146
|
+
out(
|
|
147
|
+
`Logged in to ${result.workspace?.name || 'the workspace'} / ${result.project?.name || 'the project'} as the token "${result.tokenName}" (${(result.scopes || []).join(', ')}).`,
|
|
148
|
+
)
|
|
149
|
+
out(`Saved to ${file} (only you can read it). push, comments, watch and mcp with --remote ${origin} use it.`)
|
|
150
|
+
if (env.SHAPEWALL_TOKEN) out('Note: SHAPEWALL_TOKEN is set in this shell, and it wins over the saved login.')
|
|
151
|
+
return { file }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { credentialsFile }
|