lastlight-core 0.24.5 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/config/default.yaml +39 -0
  2. package/dist/admin/chat-session-reader.js +3 -0
  3. package/dist/admin/chat-session-reader.js.map +1 -1
  4. package/dist/admin/index.js +3 -1
  5. package/dist/admin/index.js.map +1 -1
  6. package/dist/admin/routes.js +86 -19
  7. package/dist/admin/routes.js.map +1 -1
  8. package/dist/admin/sessions.d.ts +23 -2
  9. package/dist/admin/sessions.js +5 -1
  10. package/dist/admin/sessions.js.map +1 -1
  11. package/dist/config/config.d.ts +38 -0
  12. package/dist/config/config.js +16 -0
  13. package/dist/config/config.js.map +1 -1
  14. package/dist/connectors/github-webhook.d.ts +34 -0
  15. package/dist/connectors/github-webhook.js +69 -0
  16. package/dist/connectors/github-webhook.js.map +1 -1
  17. package/dist/engine/dispatcher.js +18 -4
  18. package/dist/engine/dispatcher.js.map +1 -1
  19. package/dist/engine/github/github.d.ts +53 -1
  20. package/dist/engine/github/github.js +176 -2
  21. package/dist/engine/github/github.js.map +1 -1
  22. package/dist/engine/github/team-visibility.d.ts +142 -0
  23. package/dist/engine/github/team-visibility.js +342 -0
  24. package/dist/engine/github/team-visibility.js.map +1 -0
  25. package/dist/index.js +25 -6
  26. package/dist/index.js.map +1 -1
  27. package/dist/state/db.d.ts +9 -0
  28. package/dist/state/db.js +9 -0
  29. package/dist/state/db.js.map +1 -1
  30. package/dist/state/execution-store.d.ts +33 -11
  31. package/dist/state/execution-store.js +174 -77
  32. package/dist/state/execution-store.js.map +1 -1
  33. package/dist/state/migrate.js +133 -0
  34. package/dist/state/migrate.js.map +1 -1
  35. package/dist/state/repo-ref.d.ts +75 -0
  36. package/dist/state/repo-ref.js +104 -0
  37. package/dist/state/repo-ref.js.map +1 -0
  38. package/dist/state/team-store.d.ts +108 -0
  39. package/dist/state/team-store.js +178 -0
  40. package/dist/state/team-store.js.map +1 -0
  41. package/dist/state/workflow-run-store.d.ts +32 -6
  42. package/dist/state/workflow-run-store.js +70 -31
  43. package/dist/state/workflow-run-store.js.map +1 -1
  44. package/dist/workflows/resume.js +5 -2
  45. package/dist/workflows/resume.js.map +1 -1
  46. package/package.json +3 -3
@@ -0,0 +1,342 @@
1
+ import { getManagedRepos } from "../../managed-repos.js";
2
+ import { getRuntimeConfig } from "../../config/config.js";
3
+ import { logger } from "../../logging/logger.js";
4
+ const log = logger("team-visibility");
5
+ const FAIL_OPEN = (reason, syncedAt = null) => ({
6
+ repos: null,
7
+ synced: false,
8
+ reason,
9
+ teams: [],
10
+ syncedAt,
11
+ });
12
+ export const DEFAULT_TEAM_VISIBILITY = {
13
+ enabled: false,
14
+ ttlMinutes: 60,
15
+ maxTeamsPerUser: 50,
16
+ maxPagesPerTeam: 20,
17
+ maxRequestsPerResolve: 60,
18
+ };
19
+ /**
20
+ * Resolves "which managed repos should this person see in the dashboard?" —
21
+ * the server half of issue #169.
22
+ *
23
+ * ## This answers a PREFERENCE, not an entitlement
24
+ *
25
+ * The repos returned here are the ones a person's teams own, **plus the ones
26
+ * their own account owns** — which is still **not** the same as the repos they
27
+ * can reach. Org owners and direct collaborators reach repos no team grants
28
+ * them: a dry run against the live nearform install found one maintainer's
29
+ * single team (`nearformers`) covering 4 of 8 managed repos, hiding
30
+ * `nearform/lastlight` itself, on which they hold `admin` via org ownership.
31
+ *
32
+ * The ownership union closes the one gap that was pure artefact rather than
33
+ * approximation: teams are an ORG concept, so a repo under somebody's personal
34
+ * account could never be granted by a team, and a strictly team-derived answer
35
+ * hid every one of them — on an instance managing mostly personal repos, that
36
+ * was most of the dashboard. See {@link ownedManagedRepos}, and note the test
37
+ * is `owner === login`, not "the owner is not an org".
38
+ *
39
+ * That is precisely why the dashboard filter this feeds is **opt-in and off by
40
+ * default**. As a default it would hide people's own work; as a filter somebody
41
+ * switched on for themselves it is the decluttering they asked for, reversible
42
+ * in one click. The distinction to hold onto is between "what can you reach"
43
+ * (permission) and "what do you work on" (involvement) — they coincide for a
44
+ * regular org member and diverge completely for an owner, for whom no
45
+ * access-derived rule could declutter anything at all.
46
+ *
47
+ * So: never present this as visibility or access, and never apply it to a user
48
+ * who did not ask for it.
49
+ *
50
+ * ## Why this is lazy
51
+ *
52
+ * The obvious design is an org-wide sync: walk every managed repo, list the
53
+ * teams with a grant, then pull each team's repos and members. In an org with
54
+ * thousands of repos and hundreds of teams that is thousands of API requests
55
+ * before it produces a single answer, and nearly all of it describes teams
56
+ * nobody who uses the dashboard belongs to.
57
+ *
58
+ * So nothing is enumerated up front. When a person asks, we ask GitHub for
59
+ * **their** teams (`Organization.teams(userLogins:)` — the filter is applied
60
+ * server-side, so it is one request for somebody in four teams), then each of
61
+ * those teams' repo grant, intersected with the managed set. A person in four
62
+ * teams costs roughly six GraphQL requests, once per TTL. The org's size drops
63
+ * out of the cost entirely.
64
+ *
65
+ * ## Why every failure shows MORE, never less
66
+ *
67
+ * This is UI declutter — the server keeps returning global data on every list
68
+ * endpoint and hand-crafted API calls still see everything (see the issue's
69
+ * non-goals). Nothing here is a security boundary. That is what licenses the
70
+ * budgets: when a team is too big to enumerate, or a person is in too many
71
+ * teams, or GitHub says no, we return the `null` sentinel and the dashboard
72
+ * filters nothing. A *partial* list would be the genuinely harmful outcome —
73
+ * it hides work somebody is responsible for, and looks exactly like the repo
74
+ * having no activity.
75
+ *
76
+ * ## Staleness
77
+ *
78
+ * A cached answer is served immediately and refreshed in the background once it
79
+ * is past `ttlMinutes`, so a dashboard request never waits on GitHub except on
80
+ * the very first resolution. `team` / `membership` / `organization` webhooks
81
+ * drop affected rows outright (see `connectors/github-webhook.ts`), which turns
82
+ * the next request into that first-resolution path.
83
+ */
84
+ export class TeamVisibilityResolver {
85
+ store;
86
+ github;
87
+ readConfig;
88
+ readManagedRepos;
89
+ /** login → in-flight resolution, so N dashboard polls cause ONE GitHub walk. */
90
+ inFlight = new Map();
91
+ constructor(deps) {
92
+ this.store = deps.store;
93
+ this.github = deps.github;
94
+ this.readConfig =
95
+ deps.config ?? (() => getRuntimeConfig()?.teamVisibility ?? DEFAULT_TEAM_VISIBILITY);
96
+ this.readManagedRepos = deps.managedRepos ?? getManagedRepos;
97
+ }
98
+ /**
99
+ * The repos `login` should see. Never throws and never blocks on GitHub when a
100
+ * cached answer exists — a stale one is returned as-is while a refresh runs
101
+ * in the background.
102
+ */
103
+ async visibleRepos(login) {
104
+ if (!login)
105
+ return FAIL_OPEN("no-identity");
106
+ const config = this.readConfig();
107
+ if (!config.enabled)
108
+ return FAIL_OPEN("disabled");
109
+ if (!this.github)
110
+ return FAIL_OPEN("unavailable");
111
+ const sync = this.store.getSync(login);
112
+ if (sync) {
113
+ const fresh = this.store.isFresh(login, config.ttlMinutes * 60_000);
114
+ if (!fresh) {
115
+ // Stale-while-revalidate: hand back what we have, refresh behind the
116
+ // request. Errors are swallowed — the cached answer already stands.
117
+ void this.resolve(login, config).catch(() => undefined);
118
+ }
119
+ return this.fromCache(login, sync.status, sync.syncedAt);
120
+ }
121
+ return this.resolve(login, config);
122
+ }
123
+ /** Force a fresh resolution, ignoring the TTL (the admin re-sync route). */
124
+ async resync(login) {
125
+ const config = this.readConfig();
126
+ if (!config.enabled)
127
+ return FAIL_OPEN("disabled");
128
+ if (!this.github)
129
+ return FAIL_OPEN("unavailable");
130
+ this.store.invalidateLogin(login);
131
+ return this.resolve(login, config);
132
+ }
133
+ /**
134
+ * Managed repos owned by this login's OWN account.
135
+ *
136
+ * A personal account has no teams — teams are an org concept — so a repo
137
+ * under your own login can never arrive via a team grant, and a purely
138
+ * team-derived filter hid every one of them. That is backwards: team grants
139
+ * are a proxy for involvement, and nobody is more involved in a repo than its
140
+ * owner.
141
+ *
142
+ * **The test is `owner === login`, NOT "the owner is not an organization".**
143
+ * The second reads as the same thing on a single-owner instance and is a
144
+ * disclosure bug on any other: it would put every OTHER person's personal
145
+ * repos into your filter. GitHub shares one namespace between users and orgs,
146
+ * so an exact login match is unambiguous — and free, because the owner is
147
+ * already in the managed string. No API call, nothing to cache.
148
+ */
149
+ ownedManagedRepos(login, managed) {
150
+ const owned = [];
151
+ for (const full of managed) {
152
+ const slash = full.indexOf("/");
153
+ if (slash > 0 && full.slice(0, slash) === login)
154
+ owned.push(full);
155
+ }
156
+ return owned;
157
+ }
158
+ /** Project a stored status + the cached rows into a result. */
159
+ fromCache(login, status, syncedAt) {
160
+ // An INCOMPLETE team answer stays fail-open, and is deliberately NOT
161
+ // rescued by the owned repos below. "Your own repos, plus an unknown
162
+ // fraction of your teams'" is still a partial answer, and filtering to it
163
+ // would hide precisely the org repos the truncated/errored half would have
164
+ // contributed — the same reasoning that makes a partial org set fail the
165
+ // whole pass. Only a COMPLETE team answer (`ok` or `empty`) is augmented.
166
+ if (status !== "ok" && status !== "empty") {
167
+ const reason = status === "truncated" ? "truncated" : status === "disabled" ? "disabled" : "error";
168
+ return FAIL_OPEN(reason, syncedAt);
169
+ }
170
+ const cached = this.store.reposForLogin(login);
171
+ // A team that has since been marked truncated, or rows that vanished under
172
+ // us, must not narrow the view.
173
+ if (cached.truncated)
174
+ return FAIL_OPEN("truncated", syncedAt);
175
+ // Re-intersect with the LIVE managed list: a repo removed from the
176
+ // installation since the resolution must not linger in somebody's filter.
177
+ // The owned set is derived from that same live list rather than persisted,
178
+ // so it has no cache of its own and cannot go stale against it — which is
179
+ // also why `status: "empty"` (no teams at all) can still yield a filter.
180
+ const managed = new Set(this.readManagedRepos());
181
+ const repos = [
182
+ ...new Set([
183
+ ...cached.repos.filter((r) => managed.has(r)),
184
+ ...this.ownedManagedRepos(login, managed),
185
+ ]),
186
+ ].sort();
187
+ if (repos.length === 0)
188
+ return { ...FAIL_OPEN("no-teams", syncedAt), synced: true };
189
+ return { repos, synced: true, reason: "ok", teams: cached.teams, syncedAt };
190
+ }
191
+ /** One resolution pass, deduped per login. */
192
+ resolve(login, config) {
193
+ const existing = this.inFlight.get(login);
194
+ if (existing)
195
+ return existing;
196
+ const pending = this.resolveUncached(login, config)
197
+ .catch((err) => {
198
+ // resolveUncached is already total; this is the last-resort net so a
199
+ // dashboard request can never 500 on a visibility lookup.
200
+ log.warn("Team visibility resolution failed", { login, err });
201
+ return FAIL_OPEN("error");
202
+ })
203
+ .finally(() => this.inFlight.delete(login));
204
+ this.inFlight.set(login, pending);
205
+ return pending;
206
+ }
207
+ async resolveUncached(login, config) {
208
+ const github = this.github;
209
+ if (!github)
210
+ return FAIL_OPEN("unavailable");
211
+ const managed = this.readManagedRepos();
212
+ // Nothing is managed yet (pre-boot-discovery, or a fresh install) — there
213
+ // is nothing to filter and no point spending requests to learn that.
214
+ if (managed.length === 0)
215
+ return FAIL_OPEN("unavailable");
216
+ const byOrg = new Map();
217
+ for (const full of managed) {
218
+ const owner = full.split("/")[0];
219
+ if (!owner)
220
+ continue;
221
+ const set = byOrg.get(owner) ?? new Set();
222
+ set.add(full);
223
+ byOrg.set(owner, set);
224
+ }
225
+ let requests = 0;
226
+ const budgetLeft = () => config.maxRequestsPerResolve - requests;
227
+ const teams = [];
228
+ let truncated = false;
229
+ let overBudget = false;
230
+ let tooManyTeams = false;
231
+ let failure;
232
+ for (const [org, orgManaged] of byOrg) {
233
+ if (budgetLeft() <= 0) {
234
+ overBudget = true;
235
+ break;
236
+ }
237
+ let orgTeams;
238
+ try {
239
+ const res = await github.listUserTeams(org, login, { maxPages: 5 });
240
+ requests += res.requests;
241
+ orgTeams = res.teams;
242
+ }
243
+ catch (err) {
244
+ // The App not being installed on this owner, or a missing
245
+ // `Members: read` grant. Either way we did not learn this org's answer,
246
+ // so the whole pass fails open — see the status computation below.
247
+ // (A personal-account owner is NOT here: `listUserTeams` reports it as
248
+ // an empty team list, because "not an org" is an answer, not a fault.)
249
+ failure = err instanceof Error ? err.message : String(err);
250
+ log.warn("Could not list teams for user", { org, login, err });
251
+ continue;
252
+ }
253
+ if (orgTeams.length > config.maxTeamsPerUser) {
254
+ tooManyTeams = true;
255
+ break;
256
+ }
257
+ for (const team of orgTeams) {
258
+ if (budgetLeft() <= 0) {
259
+ overBudget = true;
260
+ break;
261
+ }
262
+ try {
263
+ const pages = Math.max(1, Math.min(config.maxPagesPerTeam, budgetLeft()));
264
+ const grant = await github.listTeamRepos(org, team.slug, {
265
+ maxPages: pages,
266
+ // Stop the moment this team's grant already covers every managed
267
+ // repo in the org — the common case for an org-wide team, and it
268
+ // turns a 2000-repo walk into one page.
269
+ isDone: (seen) => countManaged(seen, orgManaged) === orgManaged.size,
270
+ });
271
+ requests += grant.requests;
272
+ if (grant.truncated)
273
+ truncated = true;
274
+ teams.push({
275
+ org,
276
+ slug: team.slug,
277
+ name: team.name,
278
+ repos: grant.repos.filter((r) => orgManaged.has(r)),
279
+ truncated: grant.truncated,
280
+ });
281
+ }
282
+ catch (err) {
283
+ failure = err instanceof Error ? err.message : String(err);
284
+ log.warn("Could not list repos for team", { org, team: team.slug, err });
285
+ }
286
+ }
287
+ if (overBudget || tooManyTeams)
288
+ break;
289
+ }
290
+ // ANY failure fails the whole pass, even when other orgs answered cleanly.
291
+ // A partial org set is a PARTIAL ANSWER: if `nearform` resolves and
292
+ // `mirevue` errors, filtering to nearform's repos alone hides every mirevue
293
+ // repo the person can see. Same reasoning as `truncated` — the only safe
294
+ // incomplete answer is no answer.
295
+ const status = tooManyTeams || overBudget || truncated
296
+ ? "truncated"
297
+ : failure
298
+ ? "error"
299
+ : teams.some((t) => t.repos.length > 0)
300
+ ? "ok"
301
+ : "empty";
302
+ this.store.recordResolution({
303
+ login,
304
+ // A truncated/errored pass persists nothing to join against — its rows
305
+ // would be a partial answer, and the status already forces fail-open.
306
+ teams: status === "ok" || status === "empty" ? teams : [],
307
+ status,
308
+ detail: tooManyTeams
309
+ ? `login is in more than ${config.maxTeamsPerUser} teams`
310
+ : overBudget
311
+ ? `resolution exceeded ${config.maxRequestsPerResolve} requests`
312
+ : truncated
313
+ ? "a team's repo grant exceeded the page budget"
314
+ : failure,
315
+ });
316
+ log.info("Resolved dashboard repo visibility", {
317
+ login,
318
+ status,
319
+ requests,
320
+ teams: teams.length,
321
+ repos: teams.reduce((n, t) => n + t.repos.length, 0),
322
+ });
323
+ if (tooManyTeams)
324
+ return FAIL_OPEN("too-many-teams");
325
+ if (overBudget)
326
+ return FAIL_OPEN("budget");
327
+ if (truncated)
328
+ return FAIL_OPEN("truncated");
329
+ if (status === "error")
330
+ return FAIL_OPEN("error");
331
+ return this.fromCache(login, status, this.store.getSync(login)?.syncedAt ?? null);
332
+ }
333
+ }
334
+ /** How many of `seen` are in the managed set — the early-exit predicate's input. */
335
+ function countManaged(seen, managed) {
336
+ let n = 0;
337
+ for (const repo of seen)
338
+ if (managed.has(repo))
339
+ n++;
340
+ return n;
341
+ }
342
+ //# sourceMappingURL=team-visibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"team-visibility.js","sourceRoot":"","sources":["../../../src/engine/github/team-visibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAA6B,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAIjD,MAAM,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAmCtC,MAAM,SAAS,GAAG,CAAC,MAAwB,EAAE,WAA0B,IAAI,EAAoB,EAAE,CAAC,CAAC;IACjG,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,KAAK;IACb,MAAM;IACN,KAAK,EAAE,EAAE;IACT,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAyB;IAC3D,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,EAAE;IACd,eAAe,EAAE,EAAE;IACnB,eAAe,EAAE,EAAE;IACnB,qBAAqB,EAAE,EAAE;CAC1B,CAAC;AAYF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,MA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MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;SACrD,CAAC,CAAC;QAEH,IAAI,YAAY;YAAE,OAAO,SAAS,CAAC,gBAAgB,CAAC,CAAC;QACrD,IAAI,UAAU;YAAE,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,MAAM,KAAK,OAAO;YAAE,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,QAAQ,IAAI,IAAI,CAAC,CAAC;IACpF,CAAC;CACF;AAED,oFAAoF;AACpF,SAAS,YAAY,CAAC,IAAc,EAAE,OAAoB;IACxD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,IAAI,IAAI,IAAI;QAAE,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,CAAC,EAAE,CAAC;IACpD,OAAO,CAAC,CAAC;AACX,CAAC"}
package/dist/index.js CHANGED
@@ -993,6 +993,26 @@ async function main() {
993
993
  // The harness client memoizes an Octokit per installation; drop it when
994
994
  // the App is uninstalled so a re-install can't be served by a dead one.
995
995
  onInstallationRemoved: (installationId) => github?.forgetInstallation(installationId),
996
+ // Team/org membership changed — forget the affected slice of the
997
+ // dashboard visibility cache (issue #169). Deleting rows is the whole
998
+ // response: the cache is filled on demand per logged-in user, so the next
999
+ // dashboard request re-resolves, and only for people who actually use it.
1000
+ onTeamChanged: ({ org, teamSlug, login }) => {
1001
+ try {
1002
+ if (login)
1003
+ db.teams.invalidateLogin(login);
1004
+ else if (teamSlug)
1005
+ db.teams.invalidateTeam(org, teamSlug);
1006
+ }
1007
+ catch (err) {
1008
+ logger("team-visibility").warn("Failed to invalidate team visibility cache", {
1009
+ org,
1010
+ teamSlug,
1011
+ login,
1012
+ err,
1013
+ });
1014
+ }
1015
+ },
996
1016
  });
997
1017
  registry.register(githubConnector);
998
1018
  }
@@ -1248,17 +1268,16 @@ async function main() {
1248
1268
  return;
1249
1269
  }
1250
1270
  // Derive owner/repo for the resume dispatch. Prefer the triggerId
1251
- // (owner/repo#N) but fall back to the stored repo + context.owner so a
1252
- // run keyed on a non-GitHub triggerId (e.g. a Slack-thread override)
1253
- // still resumes from the dashboard/focused-approval flow.
1271
+ // (owner/repo#N) but fall back to the row's own (owner, BARE repo) pair
1272
+ // so a run keyed on a non-GitHub triggerId (e.g. a Slack-thread
1273
+ // override) still resumes from the dashboard/focused-approval flow.
1254
1274
  let [owner, repo] = workflowRun.triggerId.includes("/")
1255
1275
  ? workflowRun.triggerId.replace(/#\d+$/, "").split("/")
1256
1276
  : ["", ""];
1257
1277
  if (!owner || !repo) {
1258
1278
  const ctxOwner = workflowRun.context?.owner || "";
1259
- const storedRepo = workflowRun.repo || "";
1260
- owner = ctxOwner || (storedRepo.includes("/") ? storedRepo.split("/")[0] : "");
1261
- repo = storedRepo.includes("/") ? storedRepo.split("/")[1] : storedRepo;
1279
+ owner = workflowRun.owner || ctxOwner;
1280
+ repo = workflowRun.repo || "";
1262
1281
  }
1263
1282
  const issueNumber = workflowRun.issueNumber;
1264
1283
  if (!owner || !repo || !issueNumber) {