@acryldev/blends-frame 0.2.7 → 0.2.9

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/lib/contract.d.ts CHANGED
@@ -195,6 +195,11 @@ export interface AppSharedView {
195
195
  }
196
196
  export declare function parseAppSharePlan(value: unknown): AppSharePlanView;
197
197
  export declare function parseAppShared(value: unknown): AppSharedView;
198
+ /**
199
+ * The GitHub account or organization a person typed to share a plugin to (blank: theirs). `undefined` when none was asked, `null` when what came is not a GitHub name
200
+ * (it goes to a command line: only a name that cannot start with a dash or hold a space or a slash).
201
+ */
202
+ export declare function parseShareOwner(value: unknown): string | undefined | null;
198
203
  export declare function parseAppShareRequest(value: unknown): AppShareRequest | undefined;
199
204
  export declare const FRAME_PLUGINS_SHARE_PLAN_PATH = "/api/acryl-blends-frame/plugins/share-plan";
200
205
  /** POST `{ name, confirm }`: publish it, only when `confirm` is the plan the person said yes to and it still holds. */
@@ -434,9 +439,12 @@ export interface PulledPluginView {
434
439
  /** @throws when the value is not what a pull answers. */
435
440
  export declare function parsePulledPlugin(value: unknown): PulledPluginView;
436
441
  /** Whether the person can share to GitHub now, and when not, the single thing to do about it. */
437
- export type GithubReadiness = {
442
+ export type GithubReadiness =
443
+ /** `via: 'acryl'`: the connection made with ACRYL's own sign-in (shared with Control Center), which the person can disconnect; absent: gh's own login or the person's own token. */
444
+ {
438
445
  readonly status: 'ready';
439
446
  readonly account: string;
447
+ readonly via?: 'acryl';
440
448
  } | {
441
449
  readonly status: 'signed-out';
442
450
  readonly say: string;
@@ -1,44 +1,61 @@
1
1
  /**
2
- * Connect GitHub from the app, for a person who has never opened a terminal: GitHub's own browser sign-in (`gh auth login --web`), started by a button.
3
- *
4
- * gh prints a one-time code and the address github.com/login/device, then waits until the person enters the code there and says yes. This module runs
5
- * that one gh process, reads the code from what it prints, and reports where the sign-in is. No password or token passes through the app: the person
6
- * signs in on github.com, and gh keeps its credential where it always does. When the sign-in succeeded, `gh auth setup-git` lets git push over HTTPS
7
- * with the same account, which a share needs.
2
+ * Connect GitHub from the app, for a person who has never opened a terminal: the same GitHub sign-in ACRYL Control Center has (one implementation, in
3
+ * `@acryldev/app-persistence`), started by a button. GitHub's device flow gives a one-time code and the address github.com/login/device; this module shows them,
4
+ * asks GitHub every few seconds whether the person approved, and then the token is in `<ACRYL home>/github.json`, the file Control Center reads too, so signing
5
+ * in once counts in both. The token never passes through the page. The process's own `GH_TOKEN` is then that token, so the `gh` and `git` a share starts use it.
8
6
  *
9
7
  * One sign-in at a time. The owner (the frame's Host) disposes it with the plugin, which ends a sign-in still waiting.
10
8
  */
11
- import { type ChildProcess } from 'node:child_process';
9
+ import { type GithubConnection } from '@acryldev/app-persistence';
12
10
  import type { GithubConnectState } from './contract.ts';
13
11
  export type { GithubConnectState };
14
- /** What this module needs from the computer: start gh's sign-in, and run one gh command to the end. Tests give their own. */
12
+ type FetchLike = typeof fetch;
13
+ /** What this module needs from the computer. Tests give their own. */
15
14
  export interface GithubConnectPorts {
16
- /** Start `gh auth login --web`; undefined when gh is not installed. */
17
- readonly startLogin: () => ChildProcess | undefined;
18
- /** Run `gh <args>` to the end; the exit status (non-zero when gh is missing). */
19
- readonly run: (args: readonly string[]) => number;
15
+ /** ACRYL's home: where `github.json` is, the same one Control Center uses. */
16
+ readonly home: string;
17
+ /** The process environment: its `GH_TOKEN` is what the `gh` and `git` a share starts read. */
18
+ readonly env: Record<string, string | undefined>;
19
+ /** The OAuth client id; undefined when none is valid. */
20
+ readonly clientId?: () => string | undefined;
21
+ readonly fetch?: FetchLike;
22
+ }
23
+ export interface GithubConnectOptions {
24
+ /** How long a code is waited for before giving up (GitHub's own is 15 minutes). */
25
+ readonly giveUpMs?: number;
26
+ /** Milliseconds between asking GitHub; GitHub's own interval when absent (a test sets it short). */
27
+ readonly pollMs?: number;
20
28
  }
21
- export declare const GITHUB_CONNECT_MISSING = "Connecting needs a free helper program from GitHub, and it is not installed on this computer. Install it from cli.github.com, then try again.";
22
- /** The gh this computer has, without a terminal: no prompts, no browser opened by gh itself (the page offers the link). */
23
- export declare function githubConnectPorts(): GithubConnectPorts;
29
+ export declare const GITHUB_CONNECT_UNAVAILABLE = "GitHub could not be reached. Check your internet connection and try again.";
30
+ export declare const GITHUB_CONNECT_NO_CLIENT = "GitHub sign-in is not set up in this copy of ACRYL.";
24
31
  export declare class GithubConnect {
25
32
  private readonly ports;
26
- private readonly giveUpMs;
33
+ private readonly options;
27
34
  private current;
28
- private child;
29
35
  private timer;
36
+ private giveUp;
37
+ /** Counts sign-ins: a poll still in flight when the sign-in ended or a new one began must not touch the state. */
38
+ private generation;
30
39
  private disposed;
31
- constructor(ports: GithubConnectPorts, giveUpMs?: number);
40
+ /** The token this process took into its environment from the file; a token the person's own environment named is never replaced. */
41
+ private adopted;
42
+ constructor(ports: GithubConnectPorts, options?: GithubConnectOptions);
32
43
  state(): GithubConnectState;
44
+ /** The stored connection, `{ token, login }`, or undefined. */
45
+ connection(): GithubConnection | undefined;
33
46
  /**
34
- * Start a sign-in, or return the one already waiting. Resolves when the code is known (or the start failed), which is well before the person
35
- * finishes on github.com; ask `state()` for the rest.
47
+ * Make the stored connection the one `gh` and `git` use in this process, unless the environment already names a token of the person's own.
48
+ * Returns whether the stored connection is the one in use.
36
49
  */
50
+ adopt(): boolean;
51
+ /** Forget the connection for every ACRYL place, and stop this process using it. Returns whether there was one. */
52
+ disconnect(): boolean;
53
+ /** Start a sign-in, or return the one already waiting. Resolves when the code is known (or the start failed); ask `state()` for the rest. */
37
54
  start(): Promise<GithubConnectState>;
38
55
  /** End a waiting sign-in (the person closed the chooser, or the plugin unloads). Nothing on GitHub changes. */
39
56
  cancel(): void;
40
57
  dispose(): void;
58
+ private schedule;
59
+ private poll;
41
60
  private finish;
42
- /** The code usually arrives within a second; give up waiting for it after a few, and let the page ask again. */
43
- private waitForCode;
44
61
  }
package/lib/index.d.ts CHANGED
@@ -62,9 +62,9 @@ export interface PluginsPort {
62
62
  read(): Promise<AppPluginsView>;
63
63
  switch(kind: AppPluginKind, name: string, on: boolean): Promise<void>;
64
64
  /** What sharing one local plugin would do (repository, version, visibility); nothing is sent. */
65
- planShare(name: string, visibility?: ShareVisibility, registry?: boolean): Promise<SharePlan>;
65
+ planShare(name: string, visibility?: ShareVisibility, registry?: boolean, owner?: string): Promise<SharePlan>;
66
66
  /** Publish one local plugin to its GitHub repository and release, through the plugin-hub path: only the plan the person confirmed. */
67
- share(name: string, confirmed: SharePlan): Promise<ShareAppPluginResult>;
67
+ share(name: string, confirmed: SharePlan, owner?: string): Promise<ShareAppPluginResult>;
68
68
  /** Keep a packed copy of one local plugin on this machine (the app's plugin store); nothing leaves the machine. */
69
69
  save(name: string): Promise<SavedPluginResult>;
70
70
  /** The public registry (cordisplugins.github.io), each entry marked with what this app has. Unreadable is an answer, not a failure. */
@@ -78,6 +78,8 @@ export interface PluginsPort {
78
78
  start(): Promise<GithubConnectState>;
79
79
  state(): GithubConnectState;
80
80
  cancel(): void;
81
+ /** Forget the connection ACRYL made, for every ACRYL place; answers with the readiness that is left. */
82
+ disconnect(): Promise<GithubReadiness>;
81
83
  };
82
84
  }
83
85
  /** A note's screenshot as the frame serves it: the bytes and their image type. */
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { appGeneration } from "./app-generation.js";
2
2
  import { createRequire } from "node:module";
3
- import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
3
+ import { execFile, execFileSync, spawn } from "node:child_process";
4
4
  import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
5
5
  import { mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
6
6
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
@@ -16,6 +16,7 @@ import { digestFolder } from "@acryldev/blends-core";
16
16
  import { parseDocument } from "yaml";
17
17
  import { boundContextSummary, createUserMessage } from "@deepseek-ai/dsh-llm";
18
18
  import { randomBytes } from "node:crypto";
19
+ import { clearGithub, githubClientId, githubHome, pollGithubSignIn, readGithub, startGithubSignIn } from "@acryldev/app-persistence";
19
20
  // src/contract.ts
20
21
  /** The one route the frame's client reads: what the frame shows around the app, from the Host that serves it. */
21
22
  const FRAME_API_PREFIX = "/api/acryl-blends-frame";
@@ -159,6 +160,14 @@ function parseAppShared(value) {
159
160
  ...listed === void 0 ? {} : { listed }
160
161
  };
161
162
  }
163
+ /**
164
+ * The GitHub account or organization a person typed to share a plugin to (blank: theirs). `undefined` when none was asked, `null` when what came is not a GitHub name
165
+ * (it goes to a command line: only a name that cannot start with a dash or hold a space or a slash).
166
+ */
167
+ function parseShareOwner(value) {
168
+ if (value === void 0 || value === "") return void 0;
169
+ return typeof value === "string" && GITHUB_NAME.test(value) ? value : null;
170
+ }
162
171
  function parseAppShareRequest(value) {
163
172
  if (!isRecord$2(value)) return void 0;
164
173
  const { owner, visibility, list } = value;
@@ -3205,153 +3214,139 @@ async function upstreamHead(git, root) {
3205
3214
  }
3206
3215
  // src/github-connect.ts
3207
3216
  /**
3208
- * Connect GitHub from the app, for a person who has never opened a terminal: GitHub's own browser sign-in (`gh auth login --web`), started by a button.
3209
- *
3210
- * gh prints a one-time code and the address github.com/login/device, then waits until the person enters the code there and says yes. This module runs
3211
- * that one gh process, reads the code from what it prints, and reports where the sign-in is. No password or token passes through the app: the person
3212
- * signs in on github.com, and gh keeps its credential where it always does. When the sign-in succeeded, `gh auth setup-git` lets git push over HTTPS
3213
- * with the same account, which a share needs.
3217
+ * Connect GitHub from the app, for a person who has never opened a terminal: the same GitHub sign-in ACRYL Control Center has (one implementation, in
3218
+ * `@acryldev/app-persistence`), started by a button. GitHub's device flow gives a one-time code and the address github.com/login/device; this module shows them,
3219
+ * asks GitHub every few seconds whether the person approved, and then the token is in `<ACRYL home>/github.json`, the file Control Center reads too, so signing
3220
+ * in once counts in both. The token never passes through the page. The process's own `GH_TOKEN` is then that token, so the `gh` and `git` a share starts use it.
3214
3221
  *
3215
3222
  * One sign-in at a time. The owner (the frame's Host) disposes it with the plugin, which ends a sign-in still waiting.
3216
3223
  */
3217
- const DEVICE_URL = "https://github.com/login/device";
3218
- const CODE = /\b([A-Z0-9]{4}-[A-Z0-9]{4})\b/u;
3219
- const URL_IN_TEXT = /https:\/\/github\.com\/login\/device\b/u;
3220
- /** How long a code stays usable on GitHub's side (15 minutes); after that this gives up and the person starts again. */
3221
- const GIVE_UP_MS = 9e5;
3222
- const GITHUB_CONNECT_MISSING = "Connecting needs a free helper program from GitHub, and it is not installed on this computer. Install it from cli.github.com, then try again.";
3223
- /** The gh this computer has, without a terminal: no prompts, no browser opened by gh itself (the page offers the link). */
3224
- function githubConnectPorts() {
3225
- const env = {
3226
- ...process.env,
3227
- GH_BROWSER: "true",
3228
- GH_PROMPT_DISABLED: "1",
3229
- GIT_TERMINAL_PROMPT: "0"
3230
- };
3231
- return {
3232
- startLogin: () => {
3233
- if (spawnSync("gh", ["--version"], {
3234
- env,
3235
- encoding: "utf8"
3236
- }).error !== void 0) return void 0;
3237
- return spawn("gh", [
3238
- "auth",
3239
- "login",
3240
- "--hostname",
3241
- "github.com",
3242
- "--git-protocol",
3243
- "https",
3244
- "--web",
3245
- "--skip-ssh-key"
3246
- ], {
3247
- env,
3248
- stdio: [
3249
- "pipe",
3250
- "pipe",
3251
- "pipe"
3252
- ]
3253
- });
3254
- },
3255
- run: (args) => {
3256
- const result = spawnSync("gh", [...args], {
3257
- env,
3258
- encoding: "utf8"
3259
- });
3260
- return result.error !== void 0 ? 1 : result.status ?? 1;
3261
- }
3262
- };
3263
- }
3224
+ const GITHUB_CONNECT_UNAVAILABLE = "GitHub could not be reached. Check your internet connection and try again.";
3225
+ const GITHUB_CONNECT_NO_CLIENT = "GitHub sign-in is not set up in this copy of ACRYL.";
3264
3226
  var GithubConnect = class {
3265
3227
  ports;
3266
- giveUpMs;
3228
+ options;
3267
3229
  current = { status: "idle" };
3268
- child;
3269
3230
  timer;
3231
+ giveUp;
3232
+ /** Counts sign-ins: a poll still in flight when the sign-in ended or a new one began must not touch the state. */
3233
+ generation = 0;
3270
3234
  disposed = false;
3271
- constructor(ports, giveUpMs = GIVE_UP_MS) {
3235
+ /** The token this process took into its environment from the file; a token the person's own environment named is never replaced. */
3236
+ adopted;
3237
+ constructor(ports, options = {}) {
3272
3238
  this.ports = ports;
3273
- this.giveUpMs = giveUpMs;
3239
+ this.options = options;
3274
3240
  }
3275
3241
  state() {
3276
3242
  return this.current;
3277
3243
  }
3244
+ /** The stored connection, `{ token, login }`, or undefined. */
3245
+ connection() {
3246
+ return readGithub(this.ports.home);
3247
+ }
3278
3248
  /**
3279
- * Start a sign-in, or return the one already waiting. Resolves when the code is known (or the start failed), which is well before the person
3280
- * finishes on github.com; ask `state()` for the rest.
3249
+ * Make the stored connection the one `gh` and `git` use in this process, unless the environment already names a token of the person's own.
3250
+ * Returns whether the stored connection is the one in use.
3281
3251
  */
3252
+ adopt() {
3253
+ const stored = readGithub(this.ports.home);
3254
+ if (stored === void 0) return false;
3255
+ const env = this.ports.env;
3256
+ if (env["GITHUB_TOKEN"] || env["GH_TOKEN"] && env["GH_TOKEN"] !== this.adopted && env["GH_TOKEN"] !== stored.token) return false;
3257
+ env["GH_TOKEN"] = stored.token;
3258
+ this.adopted = stored.token;
3259
+ return true;
3260
+ }
3261
+ /** Forget the connection for every ACRYL place, and stop this process using it. Returns whether there was one. */
3262
+ disconnect() {
3263
+ const stored = readGithub(this.ports.home);
3264
+ const had = clearGithub(this.ports.home);
3265
+ const env = this.ports.env;
3266
+ if (stored !== void 0 && (env["GH_TOKEN"] === stored.token || env["GH_TOKEN"] === this.adopted)) delete env["GH_TOKEN"];
3267
+ this.adopted = void 0;
3268
+ return had;
3269
+ }
3270
+ /** Start a sign-in, or return the one already waiting. Resolves when the code is known (or the start failed); ask `state()` for the rest. */
3282
3271
  async start() {
3283
3272
  if (this.disposed) return this.current;
3284
- if (this.child !== void 0) return this.waitForCode();
3285
- const child = this.ports.startLogin();
3286
- if (child === void 0) {
3273
+ if (this.current.status === "code" || this.current.status === "starting") return this.current;
3274
+ const clientId = (this.ports.clientId ?? githubClientId)();
3275
+ if (clientId === void 0) {
3287
3276
  this.current = {
3288
3277
  status: "failed",
3289
- say: GITHUB_CONNECT_MISSING
3278
+ say: GITHUB_CONNECT_NO_CLIENT
3290
3279
  };
3291
3280
  return this.current;
3292
3281
  }
3293
- this.child = child;
3282
+ const mine = ++this.generation;
3294
3283
  this.current = { status: "starting" };
3295
- let said = "";
3296
- const read = (chunk) => {
3297
- said += String(chunk);
3298
- if (this.current.status !== "starting") return;
3299
- const code = CODE.exec(said)?.[1];
3300
- if (code !== void 0) this.current = {
3284
+ try {
3285
+ const code = await startGithubSignIn(clientId, this.ports.fetch);
3286
+ if (mine !== this.generation) return this.current;
3287
+ const url = code.verificationUri.startsWith("https://github.com/") ? code.verificationUri : "https://github.com/login/device";
3288
+ this.current = {
3301
3289
  status: "code",
3302
- code,
3303
- url: URL_IN_TEXT.exec(said)?.[0] ?? DEVICE_URL
3290
+ code: code.userCode,
3291
+ url
3304
3292
  };
3305
- };
3306
- child.stdout?.on("data", read);
3307
- child.stderr?.on("data", read);
3308
- child.stdin?.on("error", () => {});
3309
- child.stdin?.write("\n");
3310
- child.on("error", (cause) => this.finish({
3311
- status: "failed",
3312
- say: GITHUB_CONNECT_MISSING,
3313
- details: cause.message
3314
- }));
3315
- child.on("exit", (status) => {
3316
- if (status === 0) {
3317
- this.ports.run(["auth", "setup-git"]);
3318
- this.finish({ status: "connected" });
3319
- } else if (this.current.status !== "failed") this.finish({
3320
- status: "failed",
3321
- say: "GitHub did not finish connecting. Press Connect GitHub to try again.",
3322
- details: said.trim().split("\n").at(-1) ?? ""
3323
- });
3324
- });
3325
- this.timer = setTimeout(() => {
3326
- this.finish({
3293
+ this.giveUp = setTimeout(() => {
3294
+ this.finish({
3295
+ status: "failed",
3296
+ say: "The code ran out before GitHub was connected. Press Connect GitHub to get a new one."
3297
+ });
3298
+ }, this.options.giveUpMs ?? Math.min(code.expiresIn * 1e3, 9e5));
3299
+ this.schedule(clientId, code.deviceCode, this.options.pollMs ?? code.interval * 1e3, mine);
3300
+ } catch (cause) {
3301
+ if (mine !== this.generation) return this.current;
3302
+ this.current = {
3327
3303
  status: "failed",
3328
- say: "The code ran out before GitHub was connected. Press Connect GitHub to get a new one."
3329
- });
3330
- }, this.giveUpMs);
3331
- return this.waitForCode();
3304
+ say: GITHUB_CONNECT_UNAVAILABLE,
3305
+ details: cause instanceof Error ? cause.message : String(cause)
3306
+ };
3307
+ }
3308
+ return this.current;
3332
3309
  }
3333
3310
  /** End a waiting sign-in (the person closed the chooser, or the plugin unloads). Nothing on GitHub changes. */
3334
3311
  cancel() {
3335
- if (this.child === void 0) return;
3312
+ if (this.current.status !== "code" && this.current.status !== "starting") return;
3336
3313
  this.finish({ status: "idle" });
3337
3314
  }
3338
3315
  dispose() {
3339
3316
  this.disposed = true;
3340
3317
  this.cancel();
3341
3318
  }
3319
+ schedule(clientId, deviceCode, waitMs, mine) {
3320
+ this.timer = setTimeout(() => {
3321
+ this.poll(clientId, deviceCode, waitMs, mine);
3322
+ }, waitMs);
3323
+ }
3324
+ async poll(clientId, deviceCode, waitMs, mine) {
3325
+ if (mine !== this.generation) return;
3326
+ try {
3327
+ const answer = await pollGithubSignIn(this.ports.home, clientId, deviceCode, this.ports.fetch);
3328
+ if (mine !== this.generation) return;
3329
+ if (answer.state === "pending") this.schedule(clientId, deviceCode, answer.interval === void 0 || this.options.pollMs !== void 0 ? waitMs : answer.interval * 1e3, mine);
3330
+ else if (answer.state === "connected") {
3331
+ this.adopt();
3332
+ this.finish({ status: "connected" });
3333
+ } else this.finish({
3334
+ status: "failed",
3335
+ say: `GitHub was not connected: ${answer.reason}. Press Connect GitHub to try again.`
3336
+ });
3337
+ } catch (cause) {
3338
+ if (mine !== this.generation) return;
3339
+ this.schedule(clientId, deviceCode, waitMs, mine);
3340
+ }
3341
+ }
3342
3342
  finish(next) {
3343
+ this.generation += 1;
3343
3344
  if (this.timer !== void 0) clearTimeout(this.timer);
3345
+ if (this.giveUp !== void 0) clearTimeout(this.giveUp);
3344
3346
  this.timer = void 0;
3345
- const child = this.child;
3346
- this.child = void 0;
3347
- if (child !== void 0 && child.exitCode === null && child.signalCode === null) child.kill();
3347
+ this.giveUp = void 0;
3348
3348
  this.current = next;
3349
3349
  }
3350
- /** The code usually arrives within a second; give up waiting for it after a few, and let the page ask again. */
3351
- async waitForCode() {
3352
- for (let waited = 0; waited < 5e3 && this.current.status === "starting"; waited += 50) await new Promise((resolve) => setTimeout(resolve, 50));
3353
- return this.current;
3354
- }
3355
3350
  };
3356
3351
  // src/app-snapshot.ts
3357
3352
  /**
@@ -3854,7 +3849,9 @@ function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branc
3854
3849
  try {
3855
3850
  const asked = body.visibility;
3856
3851
  const listed = body.registry === true;
3857
- return c.json(await plugins.planShare(name, listed ? "public" : asked === "public" || asked === "private" ? asked : void 0, listed));
3852
+ const owner = parseShareOwner(body.owner);
3853
+ if (owner === null) return c.json(error("the GitHub account or organization is not a GitHub name"), 400);
3854
+ return c.json(await plugins.planShare(name, listed ? "public" : asked === "public" || asked === "private" ? asked : void 0, listed, owner));
3858
3855
  } catch (cause) {
3859
3856
  report(cause);
3860
3857
  return c.json(plainBody(plainShareProblem(cause)), 409);
@@ -3885,8 +3882,10 @@ function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branc
3885
3882
  } catch {
3886
3883
  return c.json(error("a share is published only after the person confirms its plan"), 400);
3887
3884
  }
3885
+ const owner = parseShareOwner(fields?.owner);
3886
+ if (owner === null) return c.json(error("the GitHub account or organization is not a GitHub name"), 400);
3888
3887
  try {
3889
- return c.json(await plugins.share(name, confirmed));
3888
+ return c.json(await plugins.share(name, confirmed, owner));
3890
3889
  } catch (cause) {
3891
3890
  report(cause);
3892
3891
  return c.json(plainBody(plainShareProblem(cause)), 409);
@@ -3902,6 +3901,14 @@ function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branc
3902
3901
  });
3903
3902
  app.post(FRAME_PLUGINS_GITHUB_CONNECT_PATH, ownPage, async (c) => c.json(await plugins.connect.start()));
3904
3903
  app.get(FRAME_PLUGINS_GITHUB_CONNECT_PATH, ownPage, (c) => c.json(plugins.connect.state()));
3904
+ app.delete(FRAME_PLUGINS_GITHUB_PATH, ownPage, async (c) => {
3905
+ try {
3906
+ return c.json(await plugins.connect.disconnect());
3907
+ } catch (cause) {
3908
+ report(cause);
3909
+ return c.json(error("GitHub could not be disconnected"), 500);
3910
+ }
3911
+ });
3905
3912
  app.delete(FRAME_PLUGINS_GITHUB_CONNECT_PATH, ownPage, (c) => {
3906
3913
  plugins.connect.cancel();
3907
3914
  return c.json(plugins.connect.state());
@@ -4127,7 +4134,20 @@ function apply(ctx, config = {}) {
4127
4134
  fiberState: entry.fiber?.state
4128
4135
  }));
4129
4136
  };
4130
- const githubConnect = new GithubConnect(githubConnectPorts());
4137
+ const githubConnect = new GithubConnect({
4138
+ home: githubHome(process.env),
4139
+ env: process.env
4140
+ });
4141
+ githubConnect.adopt();
4142
+ const githubNow = async () => {
4143
+ const stored = githubConnect.connection();
4144
+ const inUse = stored !== void 0 && process.env["GH_TOKEN"] === stored.token;
4145
+ const ready = githubReadiness(() => inUse && stored.login !== "" ? stored.login : githubSharePorts().host.login());
4146
+ return ready.status === "ready" && inUse ? {
4147
+ ...ready,
4148
+ via: "acryl"
4149
+ } : ready;
4150
+ };
4131
4151
  ctx.effect(() => () => {
4132
4152
  githubConnect.dispose();
4133
4153
  }, "@acryldev/blends-frame: connecting GitHub");
@@ -4145,15 +4165,29 @@ function apply(ctx, config = {}) {
4145
4165
  const entry = loader === void 0 ? void 0 : [...loader.entries()].find((row) => row.options.id === APP_PLUGINS_ROW);
4146
4166
  if (entry?.fiber !== void 0) await entry.fiber.restart();
4147
4167
  },
4148
- planShare: async (name, visibility, registry) => planAppPluginShare(root, ctx.appInstance.home, name, {
4168
+ planShare: async (name, visibility, registry, owner) => planAppPluginShare(root, ctx.appInstance.home, name, {
4149
4169
  ...shareTo,
4170
+ ...owner === void 0 ? {} : { owner },
4150
4171
  ...visibility === void 0 ? {} : { visibility },
4151
4172
  ...registry === true ? { registry } : {}
4152
4173
  }, githubSharePorts()),
4153
- share: async (name, confirmed) => shareAppPlugin(root, ctx.appInstance.home, name, confirmed, shareTo, githubSharePorts()),
4174
+ share: async (name, confirmed, owner) => shareAppPlugin(root, ctx.appInstance.home, name, confirmed, {
4175
+ ...shareTo,
4176
+ ...owner === void 0 ? {} : { owner }
4177
+ }, githubSharePorts()),
4154
4178
  save: async (name) => saveAppPlugin(root, ctx.appInstance.home, name),
4155
- github: async () => githubReadiness(() => githubSharePorts().host.login()),
4156
- connect: githubConnect,
4179
+ github: githubNow,
4180
+ connect: {
4181
+ start: () => githubConnect.start(),
4182
+ state: () => githubConnect.state(),
4183
+ cancel: () => {
4184
+ githubConnect.cancel();
4185
+ },
4186
+ disconnect: async () => {
4187
+ githubConnect.disconnect();
4188
+ return githubNow();
4189
+ }
4190
+ },
4157
4191
  registry: async () => readRegistryView(registryRead, async () => registryMarks()),
4158
4192
  pull: async (source) => {
4159
4193
  const share = pluginShareOf(() => ctx.get("pluginShare"));
@@ -4175,7 +4209,7 @@ function apply(ctx, config = {}) {
4175
4209
  const names = /* @__PURE__ */ new Set([...frameRows().map((row) => bareName(row.name)), ...listed.map((info) => bareName(info.name))]);
4176
4210
  const repos = new Set(listed.flatMap((info) => info.pulledFrom === void 0 ? [] : [repoOfSource(info.pulledFrom) ?? ""]).filter((repo) => repo !== ""));
4177
4211
  if (signedIn === void 0 || Date.now() - signedIn.at > 6e4) {
4178
- const ready = githubReadiness(() => githubSharePorts().host.login());
4212
+ const ready = await githubNow();
4179
4213
  signedIn = {
4180
4214
  at: Date.now(),
4181
4215
  account: ready.status === "ready" ? ready.account : void 0