@1agh/maude 2.0.2 → 2.0.4
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/README.md +6 -5
- package/apps/studio/access/request.ts +0 -1
- package/apps/studio/acp/adapter-stderr.ts +43 -13
- package/apps/studio/acp/background-tasks.ts +155 -0
- package/apps/studio/acp/bridge.ts +44 -5
- package/apps/studio/acp/connected-fact.ts +15 -4
- package/apps/studio/acp/index.ts +14 -5
- package/apps/studio/actions/agents.ts +5 -0
- package/apps/studio/actions/defs/view.ts +12 -0
- package/apps/studio/actions.manifest.json +13 -1
- package/apps/studio/actions.parity.json +7 -1
- package/apps/studio/api.ts +31 -24
- package/apps/studio/asset-placeholder.tsx +157 -62
- package/apps/studio/bin/_png-playwright.mjs +10 -1
- package/apps/studio/bin/_pw-launch.mjs +14 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +4 -1
- package/apps/studio/boot-progress.ts +31 -0
- package/apps/studio/bridge/dgn-protocol.ts +34 -4
- package/apps/studio/canvas-build-sandbox.ts +275 -42
- package/apps/studio/canvas-build-worker.ts +10 -0
- package/apps/studio/canvas-create.ts +24 -0
- package/apps/studio/canvas-module-cache.ts +93 -0
- package/apps/studio/canvas-source/errors.ts +39 -0
- package/apps/studio/canvas-source/waiting.ts +290 -0
- package/apps/studio/client/actions/shell-key-handlers.js +5 -0
- package/apps/studio/client/app.jsx +22 -9
- package/apps/studio/client/github.js +23 -3
- package/apps/studio/client/home/home-api.js +30 -19
- package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
- package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
- package/apps/studio/client/hooks/use-tabs.jsx +64 -35
- package/apps/studio/client/index-loader.ts +23 -3
- package/apps/studio/client/panels/ChatPanel.jsx +22 -37
- package/apps/studio/client/panels/DiffView.jsx +314 -248
- package/apps/studio/client/panels/TeamProjects.jsx +119 -69
- package/apps/studio/client/panels/acp-runtime.js +25 -0
- package/apps/studio/client/panels/chat-finish.js +66 -0
- package/apps/studio/client/shell/frame-cap.js +53 -0
- package/apps/studio/client/shell/viewport.jsx +9 -0
- package/apps/studio/client/styles/_index.css +2 -0
- package/apps/studio/client/tree/tree.jsx +48 -21
- package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
- package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
- package/apps/studio/client/v2/ai/ai-run.css +87 -3
- package/apps/studio/client/v2/ai/background-model.js +113 -0
- package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
- package/apps/studio/client/v2/ai/run-api.js +7 -3
- package/apps/studio/client/v2/ai/runs-store.js +2 -1
- package/apps/studio/client/v2/annotations/vote-store.js +11 -5
- package/apps/studio/client/v2/assets/asset-state-lane.js +176 -8
- package/apps/studio/client/v2/assets/assets-bus.js +10 -8
- package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
- package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
- package/apps/studio/client/v2/assets/missing-frame.jsx +8 -4
- package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
- package/apps/studio/client/v2/assets/spotlight.css +153 -0
- package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
- package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
- package/apps/studio/client/v2/assets/tile.jsx +3 -0
- package/apps/studio/client/v2/assets/use-assets.js +2 -1
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
- package/apps/studio/client/v2/canvases/covers.js +11 -5
- package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
- package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
- package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
- package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
- package/apps/studio/client/v2/canvases/use-pins.js +2 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
- package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
- package/apps/studio/client/v2/code/code.css +67 -0
- package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
- package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
- package/apps/studio/client/v2/create/name-dialog.css +10 -0
- package/apps/studio/client/v2/ds/advanced-host.jsx +5 -2
- package/apps/studio/client/v2/ds/make-host.jsx +5 -2
- package/apps/studio/client/v2/ds/off-system-host.jsx +5 -2
- package/apps/studio/client/v2/ds/truth-host.jsx +5 -2
- package/apps/studio/client/v2/empty/arriving.jsx +29 -12
- package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
- package/apps/studio/client/v2/empty/not-local.jsx +31 -1
- package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
- package/apps/studio/client/v2/export/last-finished.js +2 -1
- package/apps/studio/client/v2/export/native-save.js +44 -0
- package/apps/studio/client/v2/history/git-model.js +18 -4
- package/apps/studio/client/v2/history/git-parts.jsx +60 -42
- package/apps/studio/client/v2/history/history.css +6 -0
- package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
- package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
- package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
- package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
- package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
- package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
- package/apps/studio/client/v2/search/search-recent.js +3 -1
- package/apps/studio/client/v2/search/search-remote.js +6 -4
- package/apps/studio/client/v2/settings/connections-model.js +1 -1
- package/apps/studio/client/v2/shell/menu-runner.js +1 -0
- package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
- package/apps/studio/client/v2/shell/recovery-store.js +2 -1
- package/apps/studio/client/v2/shell/served-routes.js +120 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +2 -1
- package/apps/studio/client/v2/shell/shell-activity.js +19 -0
- package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
- package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
- package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
- package/apps/studio/cloud/endpoints.ts +23 -1
- package/apps/studio/dist/client.bundle.js +798 -801
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds-assets.ts +138 -48
- package/apps/studio/editing/minimap-context.tsx +3 -3
- package/apps/studio/editing/page-activity.ts +251 -0
- package/apps/studio/editing/rotate-handle.tsx +9 -5
- package/apps/studio/editing/sticky-name.tsx +4 -4
- package/apps/studio/history/restore-artboard-action.ts +40 -0
- package/apps/studio/home/hub.ts +77 -175
- package/apps/studio/home/routes.ts +47 -8
- package/apps/studio/http.ts +117 -66
- package/apps/studio/index-flight.ts +40 -0
- package/apps/studio/managed-projects.ts +52 -24
- package/apps/studio/migrate/hub.ts +7 -1
- package/apps/studio/routes/asset-state.ts +12 -0
- package/apps/studio/routes/canvas-source.ts +44 -2
- package/apps/studio/routes/ds-assets.ts +8 -0
- package/apps/studio/routes/history.ts +28 -5
- package/apps/studio/routes/hub-signin.ts +115 -0
- package/apps/studio/routes/index.ts +4 -0
- package/apps/studio/routes/table.ts +7 -0
- package/apps/studio/routes/trash.ts +3 -0
- package/apps/studio/server.ts +11 -0
- package/apps/studio/sync/accepted-cold-start.ts +26 -3
- package/apps/studio/sync/accepted-link.ts +9 -4
- package/apps/studio/sync/asset-push.ts +8 -1
- package/apps/studio/sync/asset-state.ts +27 -2
- package/apps/studio/sync/code-module-consent.ts +74 -0
- package/apps/studio/sync/file-ledger.ts +35 -0
- package/apps/studio/sync/file-plane.ts +479 -84
- package/apps/studio/sync/hub-browser-signin.ts +377 -0
- package/apps/studio/sync/hub-text-undo.ts +30 -10
- package/apps/studio/sync/index.ts +73 -11
- package/apps/studio/sync/lfs-pointer.ts +137 -0
- package/apps/studio/sync/projection.ts +44 -2
- package/apps/studio/sync/pull-pacer.ts +160 -0
- package/apps/studio/sync/pull-priority.ts +119 -0
- package/apps/studio/sync/seed-progress.ts +47 -3
- package/apps/studio/sync/transaction-client.ts +71 -6
- package/apps/studio/sync/workspace-signin.ts +6 -256
- package/apps/studio/sync/writer-registry.ts +5 -1
- package/apps/studio/video-links-overlay.tsx +3 -2
- package/apps/studio/whats-new.json +63 -0
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/workspace-plan.mjs +14 -0
- package/package.json +8 -8
package/apps/studio/home/hub.ts
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
// home/hub.ts — Home's "Connect to your own hub" (S6.6; the TeamProjects door's hub form).
|
|
2
2
|
//
|
|
3
|
-
// POST /_home/hub/test
|
|
4
|
-
// POST /_home/hub/prepare
|
|
5
|
-
//
|
|
6
|
-
// POST /_home/hub/
|
|
7
|
-
//
|
|
8
|
-
//
|
|
3
|
+
// POST /_home/hub/test { url } → is a Maude hub answering there?
|
|
4
|
+
// POST /_home/hub/prepare { profile, url } → prepareManagedProject (known-hub)
|
|
5
|
+
// for THAT profile
|
|
6
|
+
// POST /_home/hub/signin/start { profile, url, invite? } → #204 K2: the hub's own page to
|
|
7
|
+
// open in the browser
|
|
8
|
+
// POST /_home/hub/signin/poll { id } → pending · signed in · why not
|
|
9
|
+
// POST /_home/hub/signin/cancel { id }
|
|
10
|
+
// GET /_api/hub-signin/return ?state&code | ?state&error → the browser's hop back (routes.ts
|
|
11
|
+
// serves it outside the table)
|
|
9
12
|
//
|
|
10
|
-
// Rules (contract S6-slices S6.6):
|
|
13
|
+
// Rules (contract S6-slices S6.6; issue #204, decision maude/v2-michal-team-server-signin-via-hub-page):
|
|
11
14
|
// - the address is https, or http only on loopback — checked before any byte leaves; never
|
|
12
15
|
// userinfo, never a query or fragment;
|
|
13
16
|
// - Test connection sends ONE tokenless GET /health: no credential, no body, no redirect followed;
|
|
14
|
-
// -
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
// - Home owns NO login method for a team server: no email, no password, no invite redeem of its
|
|
18
|
+
// own. Sign in opens the hub's `/studio/signin` (an invite: the hub's own `/join/<key>`) in the
|
|
19
|
+
// browser with a desktop request (sync/hub-browser-signin.ts); the hub sends the browser back to
|
|
20
|
+
// HOME's loopback return with a one-time code that only this process's PKCE verifier redeems.
|
|
21
|
+
// Only the exchanged token is kept, in THIS profile's hubs.json (the profile is fixed when the
|
|
22
|
+
// attempt starts, never read from the return). Every request to the hub refuses redirects.
|
|
23
|
+
|
|
24
|
+
import { NO_PASSWORD_WORDS, prepareManagedProject } from '../managed-projects.ts';
|
|
25
|
+
import {
|
|
26
|
+
createHubBrowserSignIn,
|
|
27
|
+
HUB_SIGNIN_WORDS,
|
|
28
|
+
type PollAnswer,
|
|
29
|
+
} from '../sync/hub-browser-signin.ts';
|
|
21
30
|
import { saveHubCredential } from '../sync/hub-link.ts';
|
|
22
31
|
import { normalizeUrl } from '../sync/hubs-config.ts';
|
|
23
32
|
import { profileCloudPath, profileHubsPath } from './cloud.ts';
|
|
24
33
|
import type { HomeAnswer } from './signin.ts';
|
|
25
34
|
|
|
26
35
|
const MAX_URL = 2048;
|
|
27
|
-
const MAX_EMAIL = 320;
|
|
28
|
-
const MAX_PASSWORD = 1024;
|
|
29
36
|
const PROBE_TIMEOUT_MS = 4000;
|
|
30
37
|
const MAX_HEALTH_BYTES = 64 * 1024;
|
|
31
38
|
const VERSION_RE = /^[0-9A-Za-z.+-]{1,32}$/;
|
|
@@ -61,10 +68,17 @@ export function hubAddress(raw: unknown): { ok: true; url: string } | { ok: fals
|
|
|
61
68
|
export interface HomeHub {
|
|
62
69
|
test(body: unknown): Promise<HomeAnswer>;
|
|
63
70
|
prepare(body: unknown): Promise<HomeAnswer>;
|
|
64
|
-
/**
|
|
65
|
-
|
|
71
|
+
/** #204 K2 — a sign-in (or an invite accept) on the hub's own page; `origin` is Home's. */
|
|
72
|
+
signInStart(body: unknown, origin: string): Promise<HomeAnswer>;
|
|
73
|
+
signInPoll(body: unknown): Promise<HomeAnswer>;
|
|
74
|
+
signInCancel(body: unknown): Promise<HomeAnswer>;
|
|
75
|
+
/** The browser came back to Home's loopback return. */
|
|
76
|
+
signInReturn(params: URLSearchParams): Promise<{ ok: boolean; message: string }>;
|
|
66
77
|
}
|
|
67
78
|
|
|
79
|
+
/** The words for an email or password sent to Home — it takes neither (issue #204). */
|
|
80
|
+
export { NO_PASSWORD_WORDS };
|
|
81
|
+
|
|
68
82
|
const answer = (status: number, body: unknown): HomeAnswer => ({ status, body });
|
|
69
83
|
|
|
70
84
|
export function createHomeHub(opts: { fetchImpl?: typeof fetch } = {}): HomeHub {
|
|
@@ -76,6 +90,8 @@ export function createHomeHub(opts: { fetchImpl?: typeof fetch } = {}): HomeHub
|
|
|
76
90
|
redirect: 'error',
|
|
77
91
|
credentials: 'omit',
|
|
78
92
|
})) as typeof fetch;
|
|
93
|
+
// #204 K2 — one flow per Home process; each attempt carries the profile it may write
|
|
94
|
+
const browserSignIn = createHubBrowserSignIn({ fetchImpl: hubFetch });
|
|
79
95
|
|
|
80
96
|
async function test(body: unknown): Promise<HomeAnswer> {
|
|
81
97
|
const a = hubAddress((body as { url?: unknown } | null)?.url);
|
|
@@ -126,138 +142,75 @@ export function createHomeHub(opts: { fetchImpl?: typeof fetch } = {}): HomeHub
|
|
|
126
142
|
const a = hubAddress(body.url);
|
|
127
143
|
if (!a.ok) return answer(400, { ok: false, error: a.error });
|
|
128
144
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
r = await prepareManagedProject(
|
|
138
|
-
{},
|
|
139
|
-
{ kind: 'hub', url: a.url, email: email.trim(), password },
|
|
140
|
-
{ cloudConfigPath, hubsConfigPath, fetchImpl: hubFetch }
|
|
141
|
-
);
|
|
142
|
-
} else {
|
|
143
|
-
r = await prepareManagedProject(
|
|
144
|
-
{},
|
|
145
|
-
{ kind: 'known-hub', url: a.url },
|
|
146
|
-
{ cloudConfigPath, hubsConfigPath, fetchImpl: hubFetch }
|
|
147
|
-
);
|
|
148
|
-
}
|
|
145
|
+
// Home owns no login method for a team server (#204): a credential sent here is refused, unsent
|
|
146
|
+
if (body.email !== undefined || body.password !== undefined)
|
|
147
|
+
return answer(400, { ok: false, reason: 'password-retired', error: NO_PASSWORD_WORDS });
|
|
148
|
+
const r = await prepareManagedProject(
|
|
149
|
+
{},
|
|
150
|
+
{ kind: 'known-hub', url: a.url },
|
|
151
|
+
{ cloudConfigPath, hubsConfigPath, fetchImpl: hubFetch }
|
|
152
|
+
);
|
|
149
153
|
if (!r.ok) return answer(r.status || 502, { ok: false, error: r.error });
|
|
150
154
|
return answer(200, { ...r, profile });
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
// exactly like a hub this Mac already holds a sign-in for.
|
|
158
|
-
async function join(raw: unknown): Promise<HomeAnswer> {
|
|
157
|
+
// #204 K2 — "Sign in" / "Invite link or key": the hub's own page in the browser. The address and
|
|
158
|
+
// an invite are checked here before anything leaves; the invite key (or the hub's own invite link,
|
|
159
|
+
// which must name THIS hub) only ever becomes the path of the page the browser opens.
|
|
160
|
+
async function signInStart(raw: unknown, origin: string): Promise<HomeAnswer> {
|
|
159
161
|
const body = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>;
|
|
160
162
|
const profile = typeof body.profile === 'string' ? body.profile : '';
|
|
161
|
-
const cloudConfigPath = profileCloudPath(profile);
|
|
162
163
|
const hubsConfigPath = profileHubsPath(profile);
|
|
163
|
-
if (!
|
|
164
|
+
if (!profileCloudPath(profile) || !hubsConfigPath)
|
|
164
165
|
return answer(400, { ok: false, error: 'unknown profile' });
|
|
165
166
|
const a = hubAddress(body.url);
|
|
166
167
|
if (!a.ok) return answer(400, { ok: false, error: a.error });
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (typeof password !== 'string' || !password || password.length > MAX_PASSWORD)
|
|
173
|
-
return answer(400, { ok: false, error: 'Enter your password.' });
|
|
174
|
-
|
|
175
|
-
// the same tokenless probe Test connection sends: nothing secret goes to a non-hub
|
|
176
|
-
const probe = await test({ url: a.url });
|
|
177
|
-
if (probe.status !== 200) {
|
|
178
|
-
const b = probe.body as { error?: string };
|
|
179
|
-
return answer(probe.status, { ok: false, error: b.error ?? JOIN_WORDS.unreachable });
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
let res: Response;
|
|
183
|
-
try {
|
|
184
|
-
res = await hubFetch(`${a.url}/join`, {
|
|
185
|
-
method: 'POST',
|
|
186
|
-
// the caller honours a canvas invite's access claim (S9.6b), or the hub refuses to spend it
|
|
187
|
-
headers: {
|
|
188
|
-
'content-type': 'application/json',
|
|
189
|
-
accept: 'application/json',
|
|
190
|
-
'x-maude-access': String(ACCESS_VERSION),
|
|
191
|
-
},
|
|
192
|
-
body: JSON.stringify({ token: token.value, email: email.trim(), password }),
|
|
193
|
-
signal: AbortSignal.timeout(JOIN_TIMEOUT_MS),
|
|
194
|
-
});
|
|
195
|
-
} catch {
|
|
196
|
-
return answer(502, { ok: false, error: JOIN_WORDS.unreachable });
|
|
197
|
-
}
|
|
198
|
-
let j: Record<string, unknown> | null = null;
|
|
199
|
-
try {
|
|
200
|
-
const text = await res.text();
|
|
201
|
-
j = text.length <= MAX_HEALTH_BYTES ? (JSON.parse(text) as Record<string, unknown>) : null;
|
|
202
|
-
} catch {
|
|
203
|
-
j = null;
|
|
204
|
-
}
|
|
205
|
-
if (res.status !== 201 || j?.ok !== true || typeof j.token !== 'string' || !j.token) {
|
|
206
|
-
return answer(joinStatus(res.status), {
|
|
207
|
-
ok: false,
|
|
208
|
-
reason: joinReason(res.status, j?.reason),
|
|
209
|
-
error: joinError(res.status, j?.reason, j?.error),
|
|
210
|
-
});
|
|
168
|
+
let invite: string | undefined;
|
|
169
|
+
if (body.invite !== undefined && body.invite !== null && body.invite !== '') {
|
|
170
|
+
const t = hubInviteToken(body.invite, a.url);
|
|
171
|
+
if (!t.ok) return answer(400, { ok: false, error: t.error });
|
|
172
|
+
invite = t.value;
|
|
211
173
|
}
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
saveHubCredential(
|
|
220
|
-
a.url,
|
|
221
|
-
j.token,
|
|
222
|
-
role,
|
|
223
|
-
expiresAt,
|
|
224
|
-
hubsConfigPath,
|
|
225
|
-
typeof user.email === 'string' ? user.email : email.trim()
|
|
226
|
-
);
|
|
227
|
-
} catch {
|
|
228
|
-
return answer(500, {
|
|
174
|
+
const r = await browserSignIn.start(a.url, origin, {
|
|
175
|
+
invite,
|
|
176
|
+
save: (u, token, role, expiresAt, account) =>
|
|
177
|
+
saveHubCredential(u, token, role, expiresAt, hubsConfigPath, account),
|
|
178
|
+
});
|
|
179
|
+
if (!r.ok)
|
|
180
|
+
return answer(r.status, {
|
|
229
181
|
ok: false,
|
|
230
|
-
error:
|
|
182
|
+
error: r.error,
|
|
183
|
+
...(r.reason ? { reason: r.reason } : {}),
|
|
231
184
|
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
|
|
185
|
+
return answer(200, { ...r, profile });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function signInPoll(raw: unknown): Promise<HomeAnswer> {
|
|
189
|
+
const r: PollAnswer = browserSignIn.poll((raw as { id?: unknown } | null)?.id);
|
|
190
|
+
return answer(200, r);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function signInCancel(raw: unknown): Promise<HomeAnswer> {
|
|
194
|
+
browserSignIn.cancel((raw as { id?: unknown } | null)?.id);
|
|
195
|
+
return answer(200, { ok: true });
|
|
240
196
|
}
|
|
241
197
|
|
|
242
|
-
|
|
198
|
+
const signInReturn = (params: URLSearchParams) => browserSignIn.onReturn(params);
|
|
199
|
+
|
|
200
|
+
return { test, prepare, signInStart, signInPoll, signInCancel, signInReturn };
|
|
243
201
|
}
|
|
244
202
|
|
|
245
|
-
const JOIN_TIMEOUT_MS = 15_000;
|
|
246
203
|
const MAX_INVITE = 256;
|
|
247
204
|
const INVITE_RE = /^inv_[A-Za-z0-9_-]{16,200}$/;
|
|
248
205
|
|
|
249
206
|
const JOIN_WORDS = {
|
|
250
|
-
|
|
251
|
-
badInvite: "That doesn't look like an invite link or key.",
|
|
207
|
+
badInvite: HUB_SIGNIN_WORDS.badInvite,
|
|
252
208
|
otherHub: 'That invite is for a different hub address.',
|
|
253
|
-
dead: "This invite doesn't work any more. Ask whoever invited you for a new one.",
|
|
254
|
-
rateLimited: 'Too many attempts. Wait a minute and try again.',
|
|
255
|
-
refused: 'The hub refused the invite.',
|
|
256
209
|
};
|
|
257
210
|
|
|
258
211
|
/**
|
|
259
212
|
* The invite a person pasted: the key itself (`inv_…`), or the hub's own invite link
|
|
260
|
-
* `<hub>/join/<key>` — which must name THIS hub, so a link can't send the
|
|
213
|
+
* `<hub>/join/<key>` — which must name THIS hub, so a link can't send the person to another host's page.
|
|
261
214
|
*/
|
|
262
215
|
export function hubInviteToken(
|
|
263
216
|
raw: unknown,
|
|
@@ -287,54 +240,3 @@ export function hubInviteToken(
|
|
|
287
240
|
if (!at.ok || at.url !== hubUrl) return { ok: false, error: JOIN_WORDS.otherHub };
|
|
288
241
|
return { ok: true, value: key };
|
|
289
242
|
}
|
|
290
|
-
|
|
291
|
-
const joinStatus = (status: number) =>
|
|
292
|
-
status === 410 || status === 400 || status === 403 || status === 429 || status === 426
|
|
293
|
-
? status
|
|
294
|
-
: 502;
|
|
295
|
-
|
|
296
|
-
const REASONS = new Set([
|
|
297
|
-
'expired',
|
|
298
|
-
'already-used',
|
|
299
|
-
'revoked',
|
|
300
|
-
'unknown',
|
|
301
|
-
'email-mismatch',
|
|
302
|
-
'email-required',
|
|
303
|
-
'account-failed',
|
|
304
|
-
'no-access',
|
|
305
|
-
'password-refused-oidc-strict',
|
|
306
|
-
]);
|
|
307
|
-
const joinReason = (status: number, reason: unknown) =>
|
|
308
|
-
typeof reason === 'string' && REASONS.has(reason)
|
|
309
|
-
? reason
|
|
310
|
-
: status === 429
|
|
311
|
-
? 'rate-limited'
|
|
312
|
-
: status === 410
|
|
313
|
-
? 'gone'
|
|
314
|
-
: 'refused';
|
|
315
|
-
|
|
316
|
-
/** A refused join's reason → our words. */
|
|
317
|
-
const REASON_WORDS: Record<string, string> = {
|
|
318
|
-
expired: JOIN_WORDS.dead,
|
|
319
|
-
revoked: JOIN_WORDS.dead,
|
|
320
|
-
'already-used': 'This invite was already used. Ask whoever invited you for a new one.',
|
|
321
|
-
'email-mismatch': 'This invite is for a different email address.',
|
|
322
|
-
'email-required': 'Enter your email address.',
|
|
323
|
-
'account-failed': "The hub couldn't create your account. Try again in a minute.",
|
|
324
|
-
'no-access': "This account can't open that hub.",
|
|
325
|
-
'password-refused-oidc-strict':
|
|
326
|
-
'This hub signs you in through your organisation, not a password.',
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Always OUR words (gate-b-sec1): the hub's own `error` text is never shown — Home is a trusted surface and a
|
|
331
|
-
* hostile or compromised hub could put phishing words there ("call support at …"). Only the status and the
|
|
332
|
-
* reason code pick the sentence.
|
|
333
|
-
*/
|
|
334
|
-
function joinError(status: number, reason: unknown, _error?: unknown): string {
|
|
335
|
-
if (status === 429) return JOIN_WORDS.rateLimited;
|
|
336
|
-
if (typeof reason === 'string' && Object.hasOwn(REASON_WORDS, reason))
|
|
337
|
-
return REASON_WORDS[reason] as string;
|
|
338
|
-
if (status === 410) return JOIN_WORDS.dead;
|
|
339
|
-
return JOIN_WORDS.refused;
|
|
340
|
-
}
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
// - `/_home/internal/*` (Rust only): a constant-time `Authorization: Bearer $MAUDE_HOME_TOKEN`,
|
|
23
23
|
// refused outright when the request carries `Origin` or `Sec-Fetch-Site` — a browser never
|
|
24
24
|
// gets in, even holding the token
|
|
25
|
+
// - `/_api/hub-signin/return` (#204 K2, the team server's page sending the browser back): the
|
|
26
|
+
// ONE path outside the table — GET, a top-level navigation only, a loopback Host; it acts only
|
|
27
|
+
// on a sign-in this process started (createHomeFetch's navigation lane)
|
|
25
28
|
// - a picture is served only when that pid's snapshot references its key; missing and forbidden
|
|
26
29
|
// are the same 404 (no existence oracle)
|
|
27
30
|
// So a project page (same site, other port), a canvas iframe or a web page can neither read nor
|
|
@@ -35,6 +38,7 @@ import { nameFromPrompt } from '../canvas-create.ts';
|
|
|
35
38
|
import { fold } from '../index/match.ts';
|
|
36
39
|
import { DIST_DIR } from '../paths.ts';
|
|
37
40
|
import { serveClientAsset, serveFile, serveIndexHtml } from '../static-lane.ts';
|
|
41
|
+
import { HUB_SIGNIN_RETURN_PATH, returnPage } from '../sync/hub-browser-signin.ts';
|
|
38
42
|
import { thumbNotFound, thumbResponse } from '../thumbs/routes.ts';
|
|
39
43
|
import { checkJpeg } from '../thumbs/validate.ts';
|
|
40
44
|
import { isLoopbackHost } from '../ws.ts';
|
|
@@ -240,7 +244,7 @@ interface HomeRoute {
|
|
|
240
244
|
function post(
|
|
241
245
|
path: string,
|
|
242
246
|
kind: Kind,
|
|
243
|
-
run: (body: unknown) => HomeAnswer | Promise<HomeAnswer>
|
|
247
|
+
run: (body: unknown, req: Request) => HomeAnswer | Promise<HomeAnswer>
|
|
244
248
|
): HomeRoute {
|
|
245
249
|
return {
|
|
246
250
|
method: 'POST',
|
|
@@ -249,7 +253,7 @@ function post(
|
|
|
249
253
|
handle: async (req) => {
|
|
250
254
|
const b = await readBody(req);
|
|
251
255
|
if (!b.ok) return b.res;
|
|
252
|
-
const r = await run(b.value);
|
|
256
|
+
const r = await run(b.value, req);
|
|
253
257
|
return json(r.status, r.body);
|
|
254
258
|
},
|
|
255
259
|
};
|
|
@@ -466,13 +470,17 @@ export function homeRouteTable(deps: HomeDeps): HomeRoute[] {
|
|
|
466
470
|
post('/_home/invite/pending/accept', 'home', (b) => invite.pendingAccept(b)),
|
|
467
471
|
post('/_home/invite/pending/leave', 'home', (b) => invite.pendingLeave(b)),
|
|
468
472
|
post('/_home/internal/signin/profile', 'internal', (b) => signin.register(b)),
|
|
469
|
-
// S6.6 — page routes behind the page secret.
|
|
470
|
-
// `prepare` and
|
|
473
|
+
// S6.6 — page routes behind the page secret. Issue #204 K2: Home takes no team-server password
|
|
474
|
+
// (`prepare` refuses one); Sign in — and an invite — goes through the hub's own page in the
|
|
475
|
+
// browser (home/hub.ts), and the browser comes back to HUB_SIGNIN_RETURN_PATH, served outside
|
|
476
|
+
// this table (createHomeFetch's navigation lane).
|
|
471
477
|
post('/_home/hub/test', 'home', (b) => hub.test(b)),
|
|
472
478
|
post('/_home/hub/prepare', 'home', (b) => hub.prepare(b)),
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
479
|
+
post('/_home/hub/signin/start', 'home', (b, req) =>
|
|
480
|
+
hub.signInStart(b, new URL(req.url).origin)
|
|
481
|
+
),
|
|
482
|
+
post('/_home/hub/signin/poll', 'home', (b) => hub.signInPoll(b)),
|
|
483
|
+
post('/_home/hub/signin/cancel', 'home', (b) => hub.signInCancel(b)),
|
|
476
484
|
get('/_home/ai/status', () => ai.status()),
|
|
477
485
|
post('/_home/ai/connect', 'home', (b) => ai.connect(b)),
|
|
478
486
|
get('/_home/cli/status', () => cli.status()),
|
|
@@ -519,6 +527,15 @@ export function homeRouteTable(deps: HomeDeps): HomeRoute[] {
|
|
|
519
527
|
];
|
|
520
528
|
}
|
|
521
529
|
|
|
530
|
+
/** A browser's top-level GET navigation (Fetch Metadata) — the same test http.ts applies. */
|
|
531
|
+
function isTopLevelNavigation(req: Request): boolean {
|
|
532
|
+
return (
|
|
533
|
+
req.method === 'GET' &&
|
|
534
|
+
req.headers.get('sec-fetch-mode') === 'navigate' &&
|
|
535
|
+
req.headers.get('sec-fetch-dest') === 'document'
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
522
539
|
function isStatic(pathname: string): boolean {
|
|
523
540
|
return (
|
|
524
541
|
pathname === '/' ||
|
|
@@ -544,7 +561,9 @@ async function serveStatic(pathname: string): Promise<Response> {
|
|
|
544
561
|
|
|
545
562
|
/** The Home server's whole `fetch`: guards first, then the table. */
|
|
546
563
|
export function createHomeFetch(deps: HomeDeps): (req: Request) => Promise<Response> {
|
|
547
|
-
|
|
564
|
+
// one hub flow for the table (start/poll/cancel) AND the navigation lane (the return)
|
|
565
|
+
const hub = deps.hub ?? createHomeHub();
|
|
566
|
+
const table = homeRouteTable({ ...deps, hub });
|
|
548
567
|
// fail closed: a page secret that IS the internal bearer would let the bearer open page routes
|
|
549
568
|
const pageSecret = deps.pageSecret && deps.pageSecret !== deps.token ? deps.pageSecret : null;
|
|
550
569
|
return async (req) => {
|
|
@@ -562,6 +581,26 @@ export function createHomeFetch(deps: HomeDeps): (req: Request) => Promise<Respo
|
|
|
562
581
|
if (req.method !== 'GET' && req.method !== 'HEAD') return refuse(405, 'Method Not Allowed');
|
|
563
582
|
return serveStatic(pathname);
|
|
564
583
|
}
|
|
584
|
+
// #204 K2 — THE NAVIGATION LANE: the one path a cross-site page may reach, where the team
|
|
585
|
+
// server's own page sends the browser back with a one-time code. No page secret (a browser tab
|
|
586
|
+
// has none) and no Sec-Fetch-Site gate (it IS cross-site), so only a top-level navigation
|
|
587
|
+
// (Sec-Fetch-Mode navigate + Dest document) of a GET is answered: a fetch, an image or a frame
|
|
588
|
+
// from any page gets 403. What protects it is what protects any OAuth redirect endpoint — it
|
|
589
|
+
// acts only on a `state` this process minted, once, and the code is worthless without the
|
|
590
|
+
// verifier that never left this process (sync/hub-browser-signin.ts).
|
|
591
|
+
if (pathname === HUB_SIGNIN_RETURN_PATH) {
|
|
592
|
+
if (req.method !== 'GET') return refuse(405, 'Method Not Allowed');
|
|
593
|
+
if (!isTopLevelNavigation(req)) return refuse(403, 'navigation only');
|
|
594
|
+
try {
|
|
595
|
+
return returnPage(await hub.signInReturn(url.searchParams));
|
|
596
|
+
} catch (err) {
|
|
597
|
+
console.error(
|
|
598
|
+
'[home] hub sign-in return failed:',
|
|
599
|
+
err instanceof Error ? err.message : err
|
|
600
|
+
);
|
|
601
|
+
return refuse(500, 'Server error');
|
|
602
|
+
}
|
|
603
|
+
}
|
|
565
604
|
const candidates = table.filter((r) =>
|
|
566
605
|
r.prefix ? pathname.startsWith(r.path) : pathname === r.path
|
|
567
606
|
);
|