lastlight-core 0.21.3 → 0.21.5
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/dist/admin/auth.d.ts +13 -1
- package/dist/admin/auth.js +24 -2
- package/dist/admin/auth.js.map +1 -1
- package/dist/admin/routes.d.ts +31 -0
- package/dist/admin/routes.js +171 -19
- package/dist/admin/routes.js.map +1 -1
- package/dist/connectors/github-webhook.js +30 -16
- package/dist/connectors/github-webhook.js.map +1 -1
- package/dist/connectors/slack/connector.d.ts +25 -1
- package/dist/connectors/slack/connector.js +45 -3
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/dependabot-discovery.d.ts +20 -3
- package/dist/cron/dependabot-discovery.js +64 -11
- package/dist/cron/dependabot-discovery.js.map +1 -1
- package/dist/engine/dispatcher.js +7 -0
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/router.js +5 -1
- package/dist/engine/router.js.map +1 -1
- package/dist/index.js +63 -5
- package/dist/index.js.map +1 -1
- package/dist/managed-repos.d.ts +11 -0
- package/dist/managed-repos.js +18 -0
- package/dist/managed-repos.js.map +1 -1
- package/dist/state/db.d.ts +5 -0
- package/dist/state/db.js +5 -0
- package/dist/state/db.js.map +1 -1
- package/dist/state/execution-store.d.ts +9 -0
- package/dist/state/execution-store.js +3 -3
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/migrate.js +44 -0
- package/dist/state/migrate.js.map +1 -1
- package/dist/state/user-store.d.ts +99 -0
- package/dist/state/user-store.js +149 -0
- package/dist/state/user-store.js.map +1 -0
- package/dist/state/workflow-run-store.d.ts +10 -0
- package/dist/state/workflow-run-store.js +6 -3
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/simple.d.ts +8 -1
- package/dist/workflows/simple.js +4 -0
- package/dist/workflows/simple.js.map +1 -1
- package/package.json +4 -4
package/dist/admin/auth.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Context, Next } from "hono";
|
|
|
6
6
|
* being bounced back through a full login. Beyond this, they must re-login.
|
|
7
7
|
*/
|
|
8
8
|
export declare const REFRESH_GRACE_SECONDS: number;
|
|
9
|
-
export declare function createToken(secret: string, method?: "password" | "slack" | "github"): string;
|
|
9
|
+
export declare function createToken(secret: string, method?: "password" | "slack" | "github", login?: string): string;
|
|
10
10
|
export declare function verifyToken(token: string, secret: string): boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Like `verifyToken`, but also accepts a token that expired within the last
|
|
@@ -18,6 +18,9 @@ export declare function verifyTokenForRefresh(token: string, secret: string): bo
|
|
|
18
18
|
export interface TokenPayload {
|
|
19
19
|
exp: number;
|
|
20
20
|
method?: "password" | "slack" | "github";
|
|
21
|
+
/** Verified identity carried across refresh (issue #205) — GitHub login, or
|
|
22
|
+
* a Slack-matched login. Absent for password / unmatched-Slack sessions. */
|
|
23
|
+
login?: string;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* Decode a token's payload WITHOUT verifying its signature or expiry — used to
|
|
@@ -49,3 +52,12 @@ export declare function authIsEnabled(opts: {
|
|
|
49
52
|
export declare function authMiddleware(enabled: boolean, secret: string): (c: Context, next: Next) => Promise<void | (Response & import("hono").TypedResponse<{
|
|
50
53
|
error: string;
|
|
51
54
|
}, 401, "json">)>;
|
|
55
|
+
/**
|
|
56
|
+
* The authenticated actor's GitHub login for the current request, or undefined
|
|
57
|
+
* when auth is disabled / the session carries no login (password or
|
|
58
|
+
* unmatched-Slack). `authMiddleware` sets `actorLogin` after verifying the
|
|
59
|
+
* token; this is the single read seam every actor-hardcoded admin route uses to
|
|
60
|
+
* attribute an action (retry / cancel / approve / CLI build) to a real person,
|
|
61
|
+
* falling back to `cli`/`admin` when it returns undefined (issue #205).
|
|
62
|
+
*/
|
|
63
|
+
export declare function actorFromContext(c: Context): string | undefined;
|
package/dist/admin/auth.js
CHANGED
|
@@ -7,10 +7,17 @@ const TOKEN_TTL_SECONDS = 60 * 60 * 24 * 30; // 30 days
|
|
|
7
7
|
* being bounced back through a full login. Beyond this, they must re-login.
|
|
8
8
|
*/
|
|
9
9
|
export const REFRESH_GRACE_SECONDS = 60 * 60 * 24 * 7; // 7 days
|
|
10
|
-
export function createToken(secret, method) {
|
|
11
|
-
const payload = {
|
|
10
|
+
export function createToken(secret, method, login) {
|
|
11
|
+
const payload = {
|
|
12
|
+
exp: Math.floor(Date.now() / 1000) + TOKEN_TTL_SECONDS,
|
|
13
|
+
};
|
|
12
14
|
if (method)
|
|
13
15
|
payload.method = method;
|
|
16
|
+
// The verified identity (issue #205) rides the token so actor-hardcoded
|
|
17
|
+
// routes can attribute an action to a real person. Additive and
|
|
18
|
+
// signature-compatible — existing 2-arg callers mint tokens without it.
|
|
19
|
+
if (login)
|
|
20
|
+
payload.login = login;
|
|
14
21
|
const payloadB64 = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
15
22
|
const sig = crypto.createHmac("sha256", secret).update(payloadB64).digest("base64url");
|
|
16
23
|
return `${payloadB64}.${sig}`;
|
|
@@ -68,6 +75,7 @@ export function decodeToken(token) {
|
|
|
68
75
|
return {
|
|
69
76
|
exp: payload.exp,
|
|
70
77
|
method: method === "password" || method === "slack" || method === "github" ? method : undefined,
|
|
78
|
+
login: typeof payload.login === "string" ? payload.login : undefined,
|
|
71
79
|
};
|
|
72
80
|
}
|
|
73
81
|
catch {
|
|
@@ -115,7 +123,21 @@ export function authMiddleware(enabled, secret) {
|
|
|
115
123
|
if (!token || !verifyToken(token, secret)) {
|
|
116
124
|
return c.json({ error: "unauthorized" }, 401);
|
|
117
125
|
}
|
|
126
|
+
// Surface the verified identity to downstream routes (issue #205). The
|
|
127
|
+
// single seam every actor-hardcoded route reads via {@link actorFromContext}.
|
|
128
|
+
c.set("actorLogin", decodeToken(token)?.login);
|
|
118
129
|
return next();
|
|
119
130
|
};
|
|
120
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The authenticated actor's GitHub login for the current request, or undefined
|
|
134
|
+
* when auth is disabled / the session carries no login (password or
|
|
135
|
+
* unmatched-Slack). `authMiddleware` sets `actorLogin` after verifying the
|
|
136
|
+
* token; this is the single read seam every actor-hardcoded admin route uses to
|
|
137
|
+
* attribute an action (retry / cancel / approve / CLI build) to a real person,
|
|
138
|
+
* falling back to `cli`/`admin` when it returns undefined (issue #205).
|
|
139
|
+
*/
|
|
140
|
+
export function actorFromContext(c) {
|
|
141
|
+
return c.get("actorLogin");
|
|
142
|
+
}
|
|
121
143
|
//# sourceMappingURL=auth.js.map
|
package/dist/admin/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/admin/auth.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS;AAEhE,MAAM,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/admin/auth.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS;AAEhE,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,MAAwC,EACxC,KAAc;IAEd,MAAM,OAAO,GAAqD;QAChE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,iBAAiB;KACvD,CAAC;IACF,IAAI,MAAM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G,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC7C,IAAI,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,8DAA8D;QAC9D,IAAI,CAAC,KAAK;YAAE,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC;QAEtD,IAAI,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;YAC1C,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,GAAG,CAAC,CAAC;QAChD,CAAC;QACD,uEAAuE;QACvE,8EAA8E;QAC9E,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAU;IACzC,OAAO,CAAC,CAAC,GAAG,CAAC,YAAY,CAAuB,CAAC;AACnD,CAAC"}
|
package/dist/admin/routes.d.ts
CHANGED
|
@@ -85,4 +85,35 @@ export interface AdminConfig {
|
|
|
85
85
|
*/
|
|
86
86
|
githubAllowedOrg?: string;
|
|
87
87
|
}
|
|
88
|
+
/** Token endpoints for the confidential-client OAuth2 code exchange. */
|
|
89
|
+
export declare const GITHUB_TOKEN_ENDPOINT = "https://github.com/login/oauth/access_token";
|
|
90
|
+
export declare const SLACK_TOKEN_ENDPOINT = "https://slack.com/api/openid.connect.token";
|
|
91
|
+
/**
|
|
92
|
+
* Exchange an OAuth2 authorization code for an access token — our own tiny
|
|
93
|
+
* confidential-client (Basic-auth) exchange, used instead of arctic's
|
|
94
|
+
* `validateAuthorizationCode` for the dashboard's GitHub + Slack logins.
|
|
95
|
+
*
|
|
96
|
+
* Why not arctic: arctic's `createOAuth2Request` **pre-sets a `Content-Length`
|
|
97
|
+
* header** on the token POST. That's fine on Node's built-in fetch, but an
|
|
98
|
+
* in-process agent run (agentic-pi / pi-ai) replaces Node's global undici
|
|
99
|
+
* dispatcher with a non-default undici build ("poisons" the global fetch — see
|
|
100
|
+
* `sandbox.ts` + `chat-skills.ts`), and that dispatcher **rejects a manually-set
|
|
101
|
+
* Content-Length** with `UND_ERR_INVALID_ARG: invalid content-length header`.
|
|
102
|
+
* Result: once any in-process run has happened, every GitHub/Slack OAuth login
|
|
103
|
+
* throws `ArcticFetchError` and users can't sign in. The follow-up userInfo GETs
|
|
104
|
+
* work because they carry no body / no Content-Length.
|
|
105
|
+
*
|
|
106
|
+
* The fix is simply to not set Content-Length ourselves — undici computes it
|
|
107
|
+
* internally, which never trips the header validation. Semantics match arctic's
|
|
108
|
+
* confidential-client path exactly (grant_type=authorization_code, Basic auth,
|
|
109
|
+
* form body), so GitHub and Slack differ only by `tokenEndpoint`.
|
|
110
|
+
*/
|
|
111
|
+
export declare function exchangeOAuth2Code(opts: {
|
|
112
|
+
tokenEndpoint: string;
|
|
113
|
+
code: string;
|
|
114
|
+
clientId: string;
|
|
115
|
+
clientSecret: string;
|
|
116
|
+
redirectUri: string;
|
|
117
|
+
fetchImpl?: typeof fetch;
|
|
118
|
+
}): Promise<string>;
|
|
88
119
|
export declare function createAdminRoutes(db: StateDb, sessions: SessionSource, chatSessions: SessionSource, config: AdminConfig): Hono;
|
package/dist/admin/routes.js
CHANGED
|
@@ -5,7 +5,7 @@ import { getCookie, setCookie, deleteCookie } from "hono/cookie";
|
|
|
5
5
|
import { Slack, GitHub } from "arctic";
|
|
6
6
|
import { tailJsonl } from "./tail.js";
|
|
7
7
|
import { listRunningContainers, killContainer, getContainerStats, getHostStats, listServerContainers, resolveServerContainer, getContainerLogs, streamContainerLogs, } from "./docker.js";
|
|
8
|
-
import { authMiddleware, createToken, verifyTokenForRefresh, decodeToken } from "./auth.js";
|
|
8
|
+
import { authMiddleware, createToken, verifyTokenForRefresh, decodeToken, actorFromContext } from "./auth.js";
|
|
9
9
|
import { Cron } from "croner";
|
|
10
10
|
import { enumerateOverlayAssets } from "lastlight-shared/overlay-assets";
|
|
11
11
|
import { getCronWorkflows, getWorkflow, listAgentWorkflows, loadWorkflowYamlRaw, loadPromptTemplate, loadSkillRaw, } from "../workflows/loader.js";
|
|
@@ -266,6 +266,57 @@ function mountSessionRoutes(app, sessions, prefix) {
|
|
|
266
266
|
});
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
|
+
/** Token endpoints for the confidential-client OAuth2 code exchange. */
|
|
270
|
+
export const GITHUB_TOKEN_ENDPOINT = "https://github.com/login/oauth/access_token";
|
|
271
|
+
export const SLACK_TOKEN_ENDPOINT = "https://slack.com/api/openid.connect.token";
|
|
272
|
+
/**
|
|
273
|
+
* Exchange an OAuth2 authorization code for an access token — our own tiny
|
|
274
|
+
* confidential-client (Basic-auth) exchange, used instead of arctic's
|
|
275
|
+
* `validateAuthorizationCode` for the dashboard's GitHub + Slack logins.
|
|
276
|
+
*
|
|
277
|
+
* Why not arctic: arctic's `createOAuth2Request` **pre-sets a `Content-Length`
|
|
278
|
+
* header** on the token POST. That's fine on Node's built-in fetch, but an
|
|
279
|
+
* in-process agent run (agentic-pi / pi-ai) replaces Node's global undici
|
|
280
|
+
* dispatcher with a non-default undici build ("poisons" the global fetch — see
|
|
281
|
+
* `sandbox.ts` + `chat-skills.ts`), and that dispatcher **rejects a manually-set
|
|
282
|
+
* Content-Length** with `UND_ERR_INVALID_ARG: invalid content-length header`.
|
|
283
|
+
* Result: once any in-process run has happened, every GitHub/Slack OAuth login
|
|
284
|
+
* throws `ArcticFetchError` and users can't sign in. The follow-up userInfo GETs
|
|
285
|
+
* work because they carry no body / no Content-Length.
|
|
286
|
+
*
|
|
287
|
+
* The fix is simply to not set Content-Length ourselves — undici computes it
|
|
288
|
+
* internally, which never trips the header validation. Semantics match arctic's
|
|
289
|
+
* confidential-client path exactly (grant_type=authorization_code, Basic auth,
|
|
290
|
+
* form body), so GitHub and Slack differ only by `tokenEndpoint`.
|
|
291
|
+
*/
|
|
292
|
+
export async function exchangeOAuth2Code(opts) {
|
|
293
|
+
const body = new URLSearchParams({
|
|
294
|
+
grant_type: "authorization_code",
|
|
295
|
+
code: opts.code,
|
|
296
|
+
});
|
|
297
|
+
if (opts.redirectUri)
|
|
298
|
+
body.set("redirect_uri", opts.redirectUri);
|
|
299
|
+
const credentials = Buffer.from(`${opts.clientId}:${opts.clientSecret}`).toString("base64");
|
|
300
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
301
|
+
const res = await doFetch(opts.tokenEndpoint, {
|
|
302
|
+
method: "POST",
|
|
303
|
+
// Deliberately NO Content-Length header — see the doc comment above.
|
|
304
|
+
headers: {
|
|
305
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
306
|
+
Accept: "application/json",
|
|
307
|
+
Authorization: `Basic ${credentials}`,
|
|
308
|
+
"User-Agent": "lastlight-admin",
|
|
309
|
+
},
|
|
310
|
+
body: body.toString(),
|
|
311
|
+
});
|
|
312
|
+
const data = (await res.json().catch(() => null));
|
|
313
|
+
const accessToken = data?.access_token;
|
|
314
|
+
if (res.status !== 200 || !accessToken) {
|
|
315
|
+
const detail = data?.error_description ?? data?.error ?? `status ${res.status}`;
|
|
316
|
+
throw new Error(`OAuth token exchange failed: ${detail}`);
|
|
317
|
+
}
|
|
318
|
+
return accessToken;
|
|
319
|
+
}
|
|
269
320
|
export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
270
321
|
const app = new Hono();
|
|
271
322
|
const slackOAuthEnabled = Boolean(config.slackOAuthClientId && config.slackOAuthClientSecret);
|
|
@@ -353,7 +404,8 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
353
404
|
if (!current || !verifyTokenForRefresh(current, config.adminSecret)) {
|
|
354
405
|
return c.json({ error: "unauthorized" }, 401);
|
|
355
406
|
}
|
|
356
|
-
|
|
407
|
+
const decoded = decodeToken(current);
|
|
408
|
+
return c.json({ token: createToken(config.adminSecret, decoded?.method, decoded?.login) });
|
|
357
409
|
});
|
|
358
410
|
// Slack OAuth routes (only active when Slack OAuth env vars are configured)
|
|
359
411
|
app.get("/oauth/slack/authorize", (c) => {
|
|
@@ -368,7 +420,10 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
368
420
|
path: "/",
|
|
369
421
|
maxAge: 600, // 10 minutes
|
|
370
422
|
});
|
|
371
|
-
|
|
423
|
+
// `email` is requested (issue #205) so the OIDC userInfo carries the
|
|
424
|
+
// address we match Slack logins to a `users` row on (and store as the
|
|
425
|
+
// future email hook).
|
|
426
|
+
const url = slack.createAuthorizationURL(state, ["openid", "profile", "email"]);
|
|
372
427
|
return c.redirect(url.toString());
|
|
373
428
|
});
|
|
374
429
|
app.get("/oauth/slack/callback", async (c) => {
|
|
@@ -385,13 +440,17 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
385
440
|
return c.json({ error: "missing authorization code" }, 400);
|
|
386
441
|
}
|
|
387
442
|
try {
|
|
388
|
-
const slack = new Slack(config.slackOAuthClientId, config.slackOAuthClientSecret, config.slackOAuthRedirectUri ?? "");
|
|
389
443
|
// "Sign in with Slack" issues OIDC-scoped tokens (openid + profile),
|
|
390
444
|
// which Slack's classic auth.test endpoint rejects with invalid_auth.
|
|
391
445
|
// Use the OIDC userInfo endpoint instead — it returns a JWT-style
|
|
392
446
|
// payload with claims under namespaced URLs.
|
|
393
|
-
const
|
|
394
|
-
|
|
447
|
+
const accessToken = await exchangeOAuth2Code({
|
|
448
|
+
tokenEndpoint: SLACK_TOKEN_ENDPOINT,
|
|
449
|
+
code,
|
|
450
|
+
clientId: config.slackOAuthClientId,
|
|
451
|
+
clientSecret: config.slackOAuthClientSecret,
|
|
452
|
+
redirectUri: config.slackOAuthRedirectUri ?? "",
|
|
453
|
+
});
|
|
395
454
|
const res = await fetch("https://slack.com/api/openid.connect.userInfo", {
|
|
396
455
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
397
456
|
});
|
|
@@ -412,7 +471,28 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
412
471
|
return c.json({ error: "workspace not allowed" }, 403);
|
|
413
472
|
}
|
|
414
473
|
}
|
|
415
|
-
|
|
474
|
+
// Capture / match a first-class user identity (issue #205): match the
|
|
475
|
+
// Slack email to an existing (GitHub) `users` row and link the Slack id
|
|
476
|
+
// onto it, else create a Slack-only row. When matched, the person's
|
|
477
|
+
// GitHub login rides the token so a Slack dashboard session attributes to
|
|
478
|
+
// the same user. Best-effort — never block a valid login on it.
|
|
479
|
+
let matchedLogin;
|
|
480
|
+
const slackUserId = userInfo["https://slack.com/user_id"];
|
|
481
|
+
if (slackUserId) {
|
|
482
|
+
try {
|
|
483
|
+
const user = db.users.upsertSlackUser({
|
|
484
|
+
slackUserId,
|
|
485
|
+
name: userInfo.name ?? null,
|
|
486
|
+
email: userInfo.email ?? null,
|
|
487
|
+
});
|
|
488
|
+
matchedLogin = user.login;
|
|
489
|
+
}
|
|
490
|
+
catch (err) {
|
|
491
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
492
|
+
console.warn(`[oauth] failed to persist Slack user ${slackUserId}: ${msg}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const token = createToken(config.adminSecret, "slack", matchedLogin);
|
|
416
496
|
// Redirect to dashboard with token in URL; App.tsx strips it immediately.
|
|
417
497
|
// Trailing slash matters: Vite serves the SPA with base "/admin/" so a
|
|
418
498
|
// bare "/admin" 404s in dev. Production static serving accepts both.
|
|
@@ -461,9 +541,13 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
461
541
|
return fail("oauth_code");
|
|
462
542
|
}
|
|
463
543
|
try {
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
544
|
+
const accessToken = await exchangeOAuth2Code({
|
|
545
|
+
tokenEndpoint: GITHUB_TOKEN_ENDPOINT,
|
|
546
|
+
code,
|
|
547
|
+
clientId: config.githubOAuthClientId,
|
|
548
|
+
clientSecret: config.githubOAuthClientSecret,
|
|
549
|
+
redirectUri: config.githubOAuthRedirectUri ?? "",
|
|
550
|
+
});
|
|
467
551
|
const res = await fetch("https://api.github.com/user", {
|
|
468
552
|
headers: {
|
|
469
553
|
Authorization: `Bearer ${accessToken}`,
|
|
@@ -496,7 +580,51 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
496
580
|
console.warn(`[oauth] GitHub login rejected: ${login} not a confirmed member of ${config.githubAllowedOrg} (status ${memberStatus})`);
|
|
497
581
|
return fail("github_org");
|
|
498
582
|
}
|
|
499
|
-
|
|
583
|
+
// Capture a first-class user identity (issue #205). A public GitHub
|
|
584
|
+
// profile often hides the email on GET /user, so fall back to the
|
|
585
|
+
// authenticated /user/emails list and pick the primary+verified one —
|
|
586
|
+
// this is the future outbound-email hook (nothing sends yet). Persisting
|
|
587
|
+
// is orthogonal to the org gate above, so it runs even for
|
|
588
|
+
// githubAllowAnyUser logins.
|
|
589
|
+
let email = userInfo.email ?? null;
|
|
590
|
+
if (!email) {
|
|
591
|
+
try {
|
|
592
|
+
const emailsRes = await fetch("https://api.github.com/user/emails", {
|
|
593
|
+
headers: {
|
|
594
|
+
Authorization: `Bearer ${accessToken}`,
|
|
595
|
+
"User-Agent": "lastlight-admin",
|
|
596
|
+
Accept: "application/vnd.github+json",
|
|
597
|
+
},
|
|
598
|
+
});
|
|
599
|
+
if (emailsRes.ok) {
|
|
600
|
+
const emails = (await emailsRes.json());
|
|
601
|
+
email = emails.find((e) => e.primary && e.verified)?.email ?? null;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
catch (err) {
|
|
605
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
606
|
+
console.warn(`[oauth] GitHub /user/emails lookup failed for ${login}: ${msg}`);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (typeof userInfo.id === "number") {
|
|
610
|
+
try {
|
|
611
|
+
db.users.getOrCreateUserByGithub({
|
|
612
|
+
githubId: userInfo.id,
|
|
613
|
+
login,
|
|
614
|
+
name: userInfo.name ?? null,
|
|
615
|
+
email,
|
|
616
|
+
avatarUrl: userInfo.avatar_url ?? null,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
catch (err) {
|
|
620
|
+
// Identity capture is best-effort — never block a valid login on it.
|
|
621
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
622
|
+
console.warn(`[oauth] failed to persist user ${login}: ${msg}`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
// Carry the verified login in the token so actor-hardcoded routes
|
|
626
|
+
// attribute to this person.
|
|
627
|
+
const token = createToken(config.adminSecret, "github", login);
|
|
500
628
|
return c.redirect(`/admin/?token=${encodeURIComponent(token)}`);
|
|
501
629
|
}
|
|
502
630
|
catch (err) {
|
|
@@ -736,7 +864,21 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
736
864
|
const run = db.runs.getRun(id);
|
|
737
865
|
if (!run)
|
|
738
866
|
return c.json({ error: "workflow run not found" }, 404);
|
|
739
|
-
|
|
867
|
+
// Enrich the actor with the `users` identity (issue #205) so the run
|
|
868
|
+
// detail panel can show a real name + avatar, not just the raw login.
|
|
869
|
+
// Best-effort: absent (password/cron/system actors, or a login with no
|
|
870
|
+
// row) → the panel falls back to the login string + actor-type badge.
|
|
871
|
+
const triggeredByUser = run.triggeredBy ? db.users.findByLogin(run.triggeredBy) : null;
|
|
872
|
+
return c.json({
|
|
873
|
+
workflowRun: run,
|
|
874
|
+
triggeredByUser: triggeredByUser
|
|
875
|
+
? {
|
|
876
|
+
login: triggeredByUser.login,
|
|
877
|
+
name: triggeredByUser.name,
|
|
878
|
+
avatarUrl: triggeredByUser.avatarUrl,
|
|
879
|
+
}
|
|
880
|
+
: null,
|
|
881
|
+
});
|
|
740
882
|
});
|
|
741
883
|
// List the executions belonging to a workflow run, ordered by start time.
|
|
742
884
|
// Used by the dashboard's pipeline-detail view to look up the session id
|
|
@@ -792,6 +934,10 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
792
934
|
if (run.status !== "running" && run.status !== "paused" && run.status !== "queued") {
|
|
793
935
|
return c.json({ error: `cannot cancel a run with status '${run.status}'` }, 400);
|
|
794
936
|
}
|
|
937
|
+
// Actor logging (issue #205): the canceller lands on the append-only
|
|
938
|
+
// executions ledger (via the finish error below), never overwriting the
|
|
939
|
+
// run's original `triggered_by`.
|
|
940
|
+
const actor = actorFromContext(c) ?? "admin";
|
|
795
941
|
db.runs.cancelRun(id);
|
|
796
942
|
// Flipping the DB row alone only stops the runner before the NEXT phase.
|
|
797
943
|
// Kill any sandbox container currently executing a phase of this run so
|
|
@@ -821,7 +967,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
821
967
|
// raced before dedup closed.
|
|
822
968
|
for (const e of db.executions.runningExecutions()) {
|
|
823
969
|
if (e.workflowRunId === id) {
|
|
824
|
-
db.executions.recordFinish(e.id, { success: false, error:
|
|
970
|
+
db.executions.recordFinish(e.id, { success: false, error: `cancelled via admin dashboard by ${actor}` });
|
|
825
971
|
}
|
|
826
972
|
}
|
|
827
973
|
}
|
|
@@ -850,7 +996,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
850
996
|
}
|
|
851
997
|
// Fire-and-forget: restartRun (inside the callback) flips status→running
|
|
852
998
|
// atomically, so a second immediate retry click 400s on the status guard.
|
|
853
|
-
config.retryWorkflow(run, "admin").catch((err) => console.error(`[admin] retry ${id} failed:`, err));
|
|
999
|
+
config.retryWorkflow(run, actorFromContext(c) ?? "admin").catch((err) => console.error(`[admin] retry ${id} failed:`, err));
|
|
854
1000
|
return c.json({ retrying: id });
|
|
855
1001
|
});
|
|
856
1002
|
// ── Workflow definitions ─────────────────────────────────────────
|
|
@@ -1286,9 +1432,12 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1286
1432
|
return c.json({ error: "approval not found" }, 404);
|
|
1287
1433
|
if (approval.status !== "pending")
|
|
1288
1434
|
return c.json({ error: `already ${approval.status}` }, 400);
|
|
1435
|
+
// Actor logging (issue #205): attribute the approval to the authenticated
|
|
1436
|
+
// user, falling back to `admin` for password/anonymous sessions.
|
|
1437
|
+
const actor = actorFromContext(c) ?? "admin";
|
|
1289
1438
|
if (body.decision === "rejected") {
|
|
1290
1439
|
// One transaction: respond 'rejected' + fail the run.
|
|
1291
|
-
db.runs.resolveGateAndFail(id,
|
|
1440
|
+
db.runs.resolveGateAndFail(id, actor, body.reason);
|
|
1292
1441
|
}
|
|
1293
1442
|
else {
|
|
1294
1443
|
// Record the approval, then let resumeWorkflow flip the run back to
|
|
@@ -1304,13 +1453,13 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1304
1453
|
// respond() is a compare-and-set on the still-pending row, so a racing
|
|
1305
1454
|
// responder (the status check above is a TOCTOU read) changes 0 rows.
|
|
1306
1455
|
// Only the winner resumes — the loser must not dispatch a second time.
|
|
1307
|
-
const changed = db.approvals.respond(id, "approved",
|
|
1456
|
+
const changed = db.approvals.respond(id, "approved", actor, body.reason);
|
|
1308
1457
|
if (changed !== 1) {
|
|
1309
1458
|
return c.json({ error: "already resolved" }, 409);
|
|
1310
1459
|
}
|
|
1311
1460
|
const workflowRun = db.runs.getRun(approval.workflowRunId);
|
|
1312
1461
|
if (workflowRun && config.resumeWorkflow) {
|
|
1313
|
-
config.resumeWorkflow(workflowRun,
|
|
1462
|
+
config.resumeWorkflow(workflowRun, actor).catch((err) => {
|
|
1314
1463
|
console.error(`[admin] Failed to resume workflow ${workflowRun.id}:`, err);
|
|
1315
1464
|
});
|
|
1316
1465
|
}
|
|
@@ -1472,8 +1621,11 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1472
1621
|
if (!config.triggerCron) {
|
|
1473
1622
|
return c.json({ error: "cron trigger not configured" }, 503);
|
|
1474
1623
|
}
|
|
1475
|
-
// Same context shape the scheduler + toggle handler build
|
|
1476
|
-
|
|
1624
|
+
// Same context shape the scheduler + toggle handler build, plus the
|
|
1625
|
+
// acting user (issue #205) so a manually-fired cron attributes to the
|
|
1626
|
+
// person who clicked "Run now" rather than the anonymous scheduler.
|
|
1627
|
+
// `dispatchWorkflow` destructures `sender` for free.
|
|
1628
|
+
const context = { repos: getManagedRepos(), sender: actorFromContext(c), ...def.context };
|
|
1477
1629
|
config.triggerCron(def.workflow, context).catch((err) => {
|
|
1478
1630
|
console.error(`[admin] cron trigger ${name} failed:`, err);
|
|
1479
1631
|
});
|