@rantingjs/studio 0.0.0-stage → 0.1.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 (54) hide show
  1. package/README.md +146 -2
  2. package/dist/badge.d.ts +2 -0
  3. package/dist/badge.js +17 -0
  4. package/dist/badge.js.map +1 -0
  5. package/dist/commands.d.ts +8 -0
  6. package/dist/commands.js +49 -0
  7. package/dist/commands.js.map +1 -0
  8. package/dist/config.d.ts +24 -0
  9. package/dist/config.js +26 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/forge.d.ts +67 -0
  12. package/dist/forge.js +138 -0
  13. package/dist/forge.js.map +1 -0
  14. package/dist/http.d.ts +25 -0
  15. package/dist/http.js +248 -0
  16. package/dist/http.js.map +1 -0
  17. package/dist/index.d.ts +4 -0
  18. package/dist/index.js +4 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/opencode.d.ts +30 -0
  21. package/dist/opencode.js +113 -0
  22. package/dist/opencode.js.map +1 -0
  23. package/dist/page.d.ts +11 -0
  24. package/dist/page.js +31 -0
  25. package/dist/page.js.map +1 -0
  26. package/dist/studio.module.d.ts +21 -0
  27. package/dist/studio.module.js +129 -0
  28. package/dist/studio.module.js.map +1 -0
  29. package/package.json +99 -4
  30. package/src/config.ts +26 -0
  31. package/ui/app.tsx +862 -0
  32. package/ui/changes.tsx +420 -0
  33. package/ui/code.tsx +194 -0
  34. package/ui/composer.tsx +362 -0
  35. package/ui/conversations.tsx +103 -0
  36. package/ui/editor.ts +144 -0
  37. package/ui/forge.tsx +236 -0
  38. package/ui/icons.tsx +59 -0
  39. package/ui/logic.ts +304 -0
  40. package/ui/logs.tsx +87 -0
  41. package/ui/model-picker.tsx +121 -0
  42. package/ui/notify.ts +45 -0
  43. package/ui/page.ts +27 -0
  44. package/ui/popover.tsx +66 -0
  45. package/ui/prose.tsx +50 -0
  46. package/ui/providers.tsx +386 -0
  47. package/ui/queue.tsx +89 -0
  48. package/ui/shared.ts +74 -0
  49. package/ui/splitter.tsx +70 -0
  50. package/ui/styles.css +2632 -0
  51. package/ui/terminal.tsx +108 -0
  52. package/ui/tsconfig.json +13 -0
  53. package/ui/urls.ts +9 -0
  54. package/ui/usage.tsx +86 -0
package/README.md CHANGED
@@ -1,3 +1,147 @@
1
- # Temporary Holding Version
1
+ # @rantingjs/studio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A panel beside the local app, for changing it with a coding agent: a chat with [OpenCode](https://opencode.ai) per
4
+ project, the app itself in a live preview next to it, the files the agent changed as a diff, the code in an editor, a
5
+ terminal, the log as it is written, the queue's failed jobs, and the app's last exception, which one click hands to
6
+ the agent. Every page of the app gets an "Edit with Studio" button that opens the
7
+ panel on that page.
8
+
9
+ ```bash
10
+ bun add -d @rantingjs/studio @opencode/cli
11
+ bunx ranting install @rantingjs/studio --skip-add # src/config/studio.ts
12
+ bunx ranting dev
13
+ ```
14
+
15
+ Open `/ranting-studio`, or click "Edit with Studio" at the bottom right of any page.
16
+
17
+ It runs only on a developer's machine: in an app with `APP_ENV=local` (or `APP_DEBUG=true`), never in tests or
18
+ production, where the module does nothing and `studio:serve` ends at once.
19
+
20
+ ## The agent
21
+
22
+ Studio brings no agent of its own. `bunx ranting dev` starts the project's OpenCode server beside the app (the
23
+ `studio` process, `bunx ranting studio:serve`): on `127.0.0.1`, on a free port, with a password made for the run.
24
+ Where it listens is written to `storage/framework/studio.json`, which goes when the server ends. The page talks to it
25
+ through the app (`/ranting-studio/api/opencode/*`), which adds the password, so the browser never holds it.
26
+
27
+ - **Conversations**: as many as you like per project, kept by OpenCode for this directory. The title above the chat
28
+ opens them: search, start a new one, delete one (each shows its mode, model and when it last changed).
29
+ - **Build or Plan**: Build changes the code; Plan talks it through first and changes nothing. Shift+Tab in the message
30
+ box switches; the choice is kept on the conversation.
31
+ - **The message box** grows with what you type, and its top edge drags it taller.
32
+ - **Panes**: drag the divider between the chat and the stage (and between the file tree and the editor, the changed
33
+ files and their diff) to resize them; double-click puts one back. The widths are kept.
34
+ - **Attachments**: the paperclip uploads files (images, PDFs, text, code; up to 20 MB each), or drop them on the chat,
35
+ or paste them. Type `@` to point at a file or folder of the project: the agent reads it in place, nothing is
36
+ uploaded. A chip warns when the chosen model cannot read one (an image for a model of text only).
37
+ - **Commands and skills**: a `/` that starts the message lists OpenCode's commands (`/review`, `/init`…) and the
38
+ skills it found, each with where it comes from: the project's (`.claude/skills`, `.opencode/skills`,
39
+ `.agents/skills`), a folder above it (its repository), yours (`~/.claude/skills`) or OpenCode's own. A command
40
+ runs with the rest of the message as its input; a skill picked so is one the agent must use. Without a `/`, the
41
+ agent still loads the skills a task calls for by itself. A long message (a command's prompt, a pasted log) shows
42
+ its first lines until opened.
43
+ - **Model and effort**: one picker, its button naming what answers ("Sonnet 5.5 · High"). Models by provider with a
44
+ search, what each reads (images, PDFs), its context window, and the free ones marked. Effort (how much the model
45
+ thinks before it answers, `low` to `max`) is always a level the model has: `high` to start, then the last chosen
46
+ for that model. Both are kept on the conversation.
47
+ - **Providers**: the gear (or "Manage providers" in the picker) shows what is connected and how, popular providers
48
+ to add, and a search over all of them. A provider opens on its own with its ways to connect: an API key, a sign-in
49
+ on the provider's page, or the environment variable to set. OpenCode keeps them in your user profile, for every
50
+ project; its free models need none. Claude comes through an Anthropic API key (Claude Console), or a cloud provider
51
+ (Amazon Bedrock, Google Cloud, Microsoft Foundry), as Anthropic asks of tools other than its own.
52
+ - **Undo**: "Undo this turn" under the last answer (or above the agent's last turn in Changes) hides your last
53
+ message and what came of it, and puts back the files it changed; your message goes back in the box. "Redo" brings
54
+ both back, until a new message makes the undo final.
55
+ - **Context**: a ring beside the model fills as the conversation takes up the model's context window ("16K"). It
56
+ opens on what the last request sent (from the cache, new), the conversation's tokens and cost, and "Summarize
57
+ earlier messages", which frees it. From 80% it turns to the accent color.
58
+ - **While you are elsewhere**: when the agent is done, fails or asks for something while Studio's tab is hidden or
59
+ another window has the focus, the tab's title says so ("(Done)", "(Needs you)", "(Failed)") until you come back.
60
+ The bell turns on the browser's notifications too; one opens Studio on that conversation.
61
+ - **Asking first**: when the agent wants to do something its rules ask about (edit a file, run a command), the chat
62
+ shows the request: allow it once, always, or reject it.
63
+ - **Stop**: ends what the agent is doing.
64
+
65
+ ### The forge: GitHub or GitLab
66
+
67
+ Studio finds where the repository lives from `origin`, and gives the agent that forge's MCP server. The agent can then
68
+ read and open pull or merge requests, issues and pipelines there, as you. A chip beside the branch, above the stage,
69
+ shows the forge and whether it is connected; it opens on what to do next.
70
+
71
+ - **GitLab**, on gitlab.com or your own server: **Sign in to GitLab** opens its sign-in in a tab, and OpenCode keeps
72
+ the token in your profile. A host that is neither github.com nor gitlab.com is asked: a GitLab answers on
73
+ `/api/v4/mcp`, whatever its domain. Its MCP server needs GitLab 18.6 or later, allowed by an administrator
74
+ (Admin area → Settings → Visibility and access controls). Where apps may not sign in by themselves, set
75
+ `GITLAB_TOKEN` (a fine-grained token with the MCP permission), and `GITLAB_TOKEN_HOST` to your GitLab's host when it
76
+ is not gitlab.com.
77
+ - **GitHub** (github.com, and `*.ghe.com`): its MCP server has no sign-in for agents and takes a token. Studio uses
78
+ `GITHUB_TOKEN` for github.com when it is set, else the GitHub CLI's login for the host (`gh auth login`, once). A
79
+ GitHub Enterprise Server has no MCP server of its own to connect.
80
+
81
+ **Check again** in the chip picks up a token or a login made since. Tokens go from this machine to OpenCode only:
82
+ they are never written to a file nor sent to the browser. A token goes only to the host it was made for, over HTTPS:
83
+ `origin` may name any server, and one that answers like a GitLab does not get the token of yours. Set `forge` in the config to `false` to leave it out, or to
84
+ `{ type: 'gitlab', url: 'https://example.com/gitlab' }` for a GitLab under a sub-path.
85
+
86
+ With `@rantingjs/assist` installed, OpenCode gets its MCP server too: the app's database schema and queries, logs,
87
+ browser logs, last error and documentation.
88
+
89
+ `@opencode/cli` is a devDependency of the app, so each project has the OpenCode it was tested with. Bun runs its
90
+ postinstall only for a trusted dependency; Studio does not need it and takes the binary of the platform's package.
91
+ On an x64 CPU without AVX2, run `bun pm trust @opencode/cli`, whose postinstall picks the build for it.
92
+
93
+ ## The stage
94
+
95
+ - **Preview**: the app in a frame, on the page the button was clicked on; type another path, reload, or open it in a
96
+ tab. It reloads when the agent finishes. The app's pages refuse frames (`x-frame-options: DENY`); a page loaded by
97
+ this preview, from the app's own origin, may be framed by that origin.
98
+ - **Changes**: everything not committed yet (git's working tree: the agent's edits and yours), or what the agent
99
+ changed in the conversation's last turn; files on the left with their status and lines added and removed, the diff
100
+ of the one picked on the right. The branch and how many files changed show above the stage.
101
+ - **Commit, reviewed first**: "Commit…" starts a conversation of the plan agent (it changes nothing) running OpenCode's
102
+ `/review` on what is not committed in the project's folder, with the model and effort chosen. You can open it in the
103
+ chat while it runs, or skip it. Then the review shows above the commit message, which you write, or "Suggest" asks
104
+ the model for one from the diff. Then:
105
+ - "Commit" commits everything changed in the project's folder (only there: the app may live in a bigger
106
+ repository). Studio runs git itself, with no shell; a hook's refusal shows as git printed it.
107
+ - "Fix with agent" switches the review's conversation to build and asks it to fix what it found. The commit waits
108
+ for a new review.
109
+ - **Without git**: the Changes tab shows the agent's last turn, "Review the agent's changes" (a plan conversation reads
110
+ the files it changed, in place) and "Initialize git".
111
+ - **Code**: the project's files, a folder at a time, and a search by name. A file opens in an editor (CodeMirror):
112
+ syntax colors for TypeScript, JavaScript, JSX, JSON, CSS, HTML (Vue, Svelte), Markdown and YAML in the page's light
113
+ or dark theme, line numbers, folding, undo, Ctrl+F to search, brackets closed and matched, Tab to indent. Ctrl+S
114
+ saves it (through OpenCode). "Ask agent" starts a message about it. A file the agent changes is read again, unless it has
115
+ edits not saved yet. Saving a source file restarts the app (`bun --watch`); Studio waits for it and checks the
116
+ file was saved.
117
+ - **Terminal**: a shell in the project (OpenCode's terminal). It stays while Studio is open, and a reloaded page goes
118
+ back to the same shell. The page asks the app for a one-use ticket, then talks to OpenCode on `127.0.0.1`.
119
+ - **Logs**: the app's log file as it is written, every process of `ranting dev` included: errors and warnings marked,
120
+ filtered by a word. It needs a log written to a file (`LOG_CHANNEL=single`, `daily`, or a stack with one).
121
+ - **Queue**: how many jobs wait on the default connection, and the failed jobs with their exception: "Retry" puts
122
+ one back on its queue (as `queue:retry` does), "Forget" removes it, "Send to agent" asks the agent to fix it.
123
+ - **The last exception**: the last error the app logged with an exception (a failed request, a listener) shows above
124
+ the message box, and "Send to agent" asks the agent to fix it with the Markdown the debug page offers: the message,
125
+ the failing line with its code, the app's frames and the request.
126
+
127
+ ## Who gets in
128
+
129
+ The `viewStudio` ability decides, for the signed-in user or a guest; until the app defines its own, it lets everyone
130
+ in while `app.env` is `local`. An app without the auth component gets that rule without the gate. Every API call must
131
+ come from the app's own origin: the agent edits files and runs commands, so another site may not drive it.
132
+
133
+ Its routes are the framework's development-tool routes (`devHosts`): in a local app they answer only connections from
134
+ this machine, sent to `localhost`, `127.0.0.1`, `[::1]` or the host of `app.url`. The development server listens on
135
+ every interface: another machine of the network gets a 403, whatever Host it names, and so does a site that points its
136
+ own name at 127.0.0.1 (DNS rebinding), though its pages look same-origin to the browser. An app in a container opened
137
+ from outside it needs `DEV_TOOLS_FROM` set to the gateway address (`172.17.0.1`).
138
+
139
+ ## Config
140
+
141
+ | Key | Default | |
142
+ |---|---|---|
143
+ | `enabled` | `STUDIO_ENABLED`, `true` | The panel, the button and the OpenCode server. |
144
+ | `path` | `STUDIO_PATH`, `ranting-studio` | Where it lives; its API is under `<path>/api`. |
145
+ | `badge` | `STUDIO_BADGE`, `true` | The "Edit with Studio" button on every HTML page. |
146
+ | `opencode` | `{}` | OpenCode config over the project's `opencode.json` and the user's: `{ model: 'anthropic/claude-opus-5-5' }`. |
147
+ | `forge` | `'auto'` | The repository's forge, found from `origin`; `false` for none; `{ type: 'gitlab', url }` to name one. |
@@ -0,0 +1,2 @@
1
+ /** The script that draws the button, in a shadow root so the page's styles do not reach it. */
2
+ export declare function badgeScript(base: string, nonce?: string): string;
package/dist/badge.js ADDED
@@ -0,0 +1,17 @@
1
+ // The "Edit with Studio" button every HTML page of the local app gets. It opens Studio on the page it was on, and stays
2
+ // out of Studio's own preview (a frame).
3
+ /** The script that draws the button, in a shadow root so the page's styles do not reach it. */
4
+ export function badgeScript(base, nonce) {
5
+ const draw = `function(){if(window.top!==window||document.getElementById('ranting-studio-badge'))return;
6
+ var host=document.createElement('div');host.id='ranting-studio-badge';
7
+ var root=host.attachShadow({mode:'closed'});
8
+ var link=document.createElement('a');
9
+ link.href=${JSON.stringify(base)}+'?path='+encodeURIComponent(location.pathname+location.search+location.hash);
10
+ link.textContent='Edit with Studio';link.title='Open this page in ranting Studio';
11
+ var style=document.createElement('style');
12
+ style.textContent='a{position:fixed;right:16px;bottom:16px;z-index:2147483647;display:flex;align-items:center;gap:8px;padding:8px 14px 8px 12px;border-radius:999px;background:#14181f;color:#f4f1ea;font:600 13px/1 system-ui,sans-serif;text-decoration:none;box-shadow:0 6px 24px rgba(0,0,0,.25);opacity:.88;transition:opacity .15s,transform .15s}a:hover{opacity:1;transform:translateY(-1px)}a:before{content:"";width:8px;height:8px;border-radius:50%;background:#e8590c}';
13
+ root.append(style,link);document.body.append(host);}`;
14
+ const script = `(function(draw){document.readyState==='loading'?document.addEventListener('DOMContentLoaded',draw):draw()})(${draw});`;
15
+ return `<script id="ranting-studio-badge-script"${nonce ? ` nonce="${nonce}"` : ''}>${script}</script>`;
16
+ }
17
+ //# sourceMappingURL=badge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"badge.js","sourceRoot":"","sources":["../src/badge.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,yCAAyC;AAEzC,+FAA+F;AAC/F,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAc;IACtD,MAAM,IAAI,GAAG;;;;YAIH,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;;;;qDAIqB,CAAC;IACpD,MAAM,MAAM,GAAG,+GAA+G,IAAI,IAAI,CAAC;IACvI,OAAO,2CAA2C,KAAK,CAAC,CAAC,CAAC,WAAW,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,MAAM,WAAW,CAAC;AAC1G,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type Command } from '@rantingjs/framework';
2
+ import type { StudioOptions } from './studio.module.js';
3
+ /** Studio's config, and whether it runs: in a local app or one with APP_DEBUG on, never in tests. */
4
+ export declare function studioConfig(basePath: string): Promise<{
5
+ config: StudioOptions;
6
+ runs: boolean;
7
+ }>;
8
+ export declare const commands: Command[];
@@ -0,0 +1,49 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { defineCommand, mergeConfig } from '@rantingjs/framework';
5
+ import defaults from './config.js';
6
+ import { detectForge, forgeMcp, forgeServerName, forgeToken } from './forge.js';
7
+ import { openCodeBinary, openCodeConfig, startServer } from './opencode.js';
8
+ /** The app's config (src/config/index.ts) read without booting the app. */
9
+ async function appConfig(basePath) {
10
+ const file = join(basePath, 'src/config/index.ts');
11
+ return existsSync(file) ? ((await import(pathToFileURL(file).href)).config ?? {}) : {};
12
+ }
13
+ /** Studio's config, and whether it runs: in a local app or one with APP_DEBUG on, never in tests. */
14
+ export async function studioConfig(basePath) {
15
+ const all = await appConfig(basePath);
16
+ const config = mergeConfig(defaults, all.studio);
17
+ const app = (all.app ?? {});
18
+ const env = app.env ?? process.env.APP_ENV ?? 'production';
19
+ const debug = app.debug ?? ['true', '1'].includes(String(process.env.APP_DEBUG));
20
+ return { config, runs: Boolean(config.enabled) && env !== 'testing' && (env === 'local' || debug === true) };
21
+ }
22
+ export const commands = [
23
+ defineCommand({
24
+ name: 'studio:serve',
25
+ description: "Starts the project's OpenCode server for Studio (`ranting dev` runs it)",
26
+ async run({ basePath, print }) {
27
+ const { config, runs } = await studioConfig(basePath);
28
+ // Ends quietly (exit 0 is not restarted by `dev`): a production-like app simply has no Studio.
29
+ if (!runs)
30
+ return print('Studio runs only in a local app (APP_ENV=local) or with APP_DEBUG=true, while studio.enabled is on.');
31
+ // The repository's forge (GitHub, GitLab, one's own GitLab), its MCP server given to the agent.
32
+ const { forge } = await detectForge(basePath, config.forge);
33
+ const token = forge ? await forgeToken(forge) : undefined;
34
+ const forgeServer = forge ? forgeMcp(forge, token?.token) : undefined;
35
+ if (forge)
36
+ print(`Studio: ${forge.type === 'gitlab' ? 'GitLab' : 'GitHub'} at ${forge.web}${forgeServer ? '' : ' (no MCP server: see the forge in Studio)'}`);
37
+ const server = await startServer(basePath, [openCodeBinary(basePath)], openCodeConfig(basePath, config.opencode, forge && forgeServer ? { [forgeServerName(forge)]: forgeServer } : {}));
38
+ print(`Studio: OpenCode listens on ${server.url}`);
39
+ const stop = () => {
40
+ server.stop();
41
+ process.exit(0);
42
+ };
43
+ process.on('SIGINT', stop);
44
+ process.on('SIGTERM', stop);
45
+ process.exitCode = await server.child.exited;
46
+ },
47
+ }),
48
+ ];
49
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAgB,MAAM,sBAAsB,CAAC;AAChF,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5E,2EAA2E;AAC3E,KAAK,UAAU,SAAS,CAAC,QAAgB;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IACnD,OAAO,UAAU,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AQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QAC/C,CAAC;KACF,CAAC;CACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ declare const _default: {
2
+ /** The panel, the badge and the OpenCode server `ranting dev` starts. */
3
+ enabled: boolean;
4
+ /** Where it lives: `/ranting-studio`. */
5
+ path: string;
6
+ /** The "Edit with Studio" button on every HTML page of the app. */
7
+ badge: boolean;
8
+ /**
9
+ * OpenCode config laid over the project's own (opencode.json) and the user's, as its JSON: `{ "model": "..." }`.
10
+ * The Assist MCP server is added to it when @rantingjs/assist is installed.
11
+ */
12
+ opencode: Record<string, unknown>;
13
+ /**
14
+ * The forge of the repository, whose MCP server the agent gets (merge requests, issues, pipelines): found from
15
+ * `origin` ('auto': GitHub, GitLab.com, or a GitLab of one's own, asked), none (false), or named:
16
+ * `{ type: 'gitlab', url: 'https://example.com/gitlab' }` for a GitLab under a sub-path.
17
+ */
18
+ forge: "auto" | false | {
19
+ type: "github" | "gitlab";
20
+ url: string;
21
+ project?: string;
22
+ };
23
+ };
24
+ export default _default;
package/dist/config.js ADDED
@@ -0,0 +1,26 @@
1
+ import { env } from '@rantingjs/framework';
2
+ /*
3
+ * Studio: a panel beside the local app with a coding agent (OpenCode) to chat with, a live preview, the agent's
4
+ * changes and the last exception. It runs only in a local app (or one with APP_DEBUG on), never in tests.
5
+ * `bunx ranting publish @rantingjs/studio --tag config` copies this file into the app.
6
+ */
7
+ export default {
8
+ /** The panel, the badge and the OpenCode server `ranting dev` starts. */
9
+ enabled: env('STUDIO_ENABLED', true),
10
+ /** Where it lives: `/ranting-studio`. */
11
+ path: env('STUDIO_PATH', 'ranting-studio'),
12
+ /** The "Edit with Studio" button on every HTML page of the app. */
13
+ badge: env('STUDIO_BADGE', true),
14
+ /**
15
+ * OpenCode config laid over the project's own (opencode.json) and the user's, as its JSON: `{ "model": "..." }`.
16
+ * The Assist MCP server is added to it when @rantingjs/assist is installed.
17
+ */
18
+ opencode: {},
19
+ /**
20
+ * The forge of the repository, whose MCP server the agent gets (merge requests, issues, pipelines): found from
21
+ * `origin` ('auto': GitHub, GitLab.com, or a GitLab of one's own, asked), none (false), or named:
22
+ * `{ type: 'gitlab', url: 'https://example.com/gitlab' }` for a GitLab under a sub-path.
23
+ */
24
+ forge: 'auto',
25
+ };
26
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE3C;;;;GAIG;AACH,eAAe;IACb,yEAAyE;IACzE,OAAO,EAAE,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC;IACpC,yCAAyC;IACzC,IAAI,EAAE,GAAG,CAAC,aAAa,EAAE,gBAAgB,CAAC;IAC1C,mEAAmE;IACnE,KAAK,EAAE,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC;IAChC;;;OAGG;IACH,QAAQ,EAAE,EAA6B;IACvC;;;;OAIG;IACH,KAAK,EAAE,MAAuF;CAC/F,CAAC"}
@@ -0,0 +1,67 @@
1
+ /** `origin` as its parts: where (host, the port of an HTTP one) and which project (`group/name`). */
2
+ export interface Remote {
3
+ protocol: 'https' | 'http' | 'ssh';
4
+ host: string;
5
+ /** The port of an http(s) remote; an SSH port says nothing of the web's. */
6
+ port?: string;
7
+ path: string;
8
+ }
9
+ /** A remote URL as git takes it: `git@host:group/name.git`, `ssh://git@host:2222/group/name`, `https://host/group/name.git`. */
10
+ export declare function parseRemote(url: string): Remote | undefined;
11
+ export type ForgeType = 'github' | 'gitlab';
12
+ /** The forge of the repository: what it is, its web address, the project's path on it and its MCP server. */
13
+ export interface Forge {
14
+ type: ForgeType;
15
+ host: string;
16
+ /** Where its pages are: `https://gitlab.example.com`. */
17
+ web: string;
18
+ /** `group/name`. */
19
+ project: string;
20
+ /** Its MCP server; none for GitHub Enterprise Server, which has no remote one. */
21
+ mcp?: string;
22
+ /** GitHub Enterprise Server: known, but without an MCP server to connect. */
23
+ enterprise?: boolean;
24
+ }
25
+ /** The name the forge's MCP server has in OpenCode. */
26
+ export declare const forgeServerName: (forge: Pick<Forge, "type">) => ForgeType;
27
+ /** The forges known by their host alone; others are asked (see probeForge()). */
28
+ export declare function knownForge(remote: Remote): Forge | undefined;
29
+ /** What a GitLab answers on its API: its `x-gitlab-meta` header, or its MCP endpoint's `realm="GitLab"`. */
30
+ export declare const isGitLabAnswer: (headers: Headers) => boolean;
31
+ /**
32
+ * A host of one's own: a GitLab answers its MCP endpoint (401 without a sign-in, with its header), a GitHub Enterprise
33
+ * Server its `/api/v3/meta`. Asked over HTTPS (HTTP only for an `http://` remote), each in `timeout` ms.
34
+ */
35
+ export declare function probeForge(remote: Remote, timeout?: number, fetcher?: typeof fetch): Promise<Forge | undefined>;
36
+ /** The `forge` setting: found from `origin` (`'auto'`), none (`false`), or named (a GitLab under a sub-path). */
37
+ export type ForgeSetting = 'auto' | false | {
38
+ type: ForgeType;
39
+ url: string;
40
+ project?: string;
41
+ };
42
+ /** A forge named in the config: its MCP server where that kind of forge has it. */
43
+ export declare function namedForge(setting: Exclude<ForgeSetting, 'auto' | false>, remote: Remote | undefined): Forge;
44
+ /** The repository's forge: from the setting, else `origin`'s host (asked when it is not a known one). */
45
+ export declare function detectForge(basePath: string, setting?: ForgeSetting): Promise<{
46
+ forge?: Forge;
47
+ origin?: string;
48
+ }>;
49
+ /** Where the token for a forge comes from: the environment, or the GitHub CLI's login. Its value never leaves the server. */
50
+ export type TokenSource = 'env' | 'gh';
51
+ /**
52
+ * The token for the forge's MCP server, when it takes one: GitHub (GITHUB_TOKEN, else `gh auth token`), or a GitLab
53
+ * whose OAuth sign-in is off (GITLAB_TOKEN, a fine-grained token with the MCP permission).
54
+ *
55
+ * A token goes only to the host it was made for, and only over HTTPS: `origin` may name any server, and one that
56
+ * answers like a GitLab must not get the token of yours. GITLAB_TOKEN is gitlab.com's unless GITLAB_TOKEN_HOST names
57
+ * another host; GITHUB_TOKEN is github.com's; the GitHub CLI's login is asked for the very host.
58
+ */
59
+ export declare function forgeToken(forge: Forge, env?: Record<string, string | undefined>, run?: typeof gitHubCli): Promise<{
60
+ token: string;
61
+ source: TokenSource;
62
+ } | undefined>;
63
+ /** The GitHub CLI's output, or undefined (not installed, not signed in to that host). No shell. */
64
+ declare function gitHubCli(args: string[]): Promise<string | undefined>;
65
+ /** The forge's MCP server as OpenCode's config takes it: with the token in a header, else OAuth (GitLab). */
66
+ export declare function forgeMcp(forge: Forge, token: string | undefined): Record<string, unknown> | undefined;
67
+ export {};
package/dist/forge.js ADDED
@@ -0,0 +1,138 @@
1
+ // The forge the app's repository lives on (GitHub, GitLab, a GitLab of one's own), found from `origin`, and the MCP
2
+ // server of it that OpenCode gets: the agent then reads and opens merge requests, issues and pipelines there.
3
+ //
4
+ // GitLab's MCP server signs in with OAuth (dynamic client registration): OpenCode keeps the token, nothing here holds
5
+ // one. GitHub's takes a token only: GITHUB_TOKEN, else the GitHub CLI's login (`gh auth token`). It goes to OpenCode
6
+ // in its config (the environment of its process) or through its API; it is never written to a file.
7
+ /** A remote URL as git takes it: `git@host:group/name.git`, `ssh://git@host:2222/group/name`, `https://host/group/name.git`. */
8
+ export function parseRemote(url) {
9
+ const value = url.trim();
10
+ const clean = (path) => path.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
11
+ // scp-like: [user@]host:path (no scheme, no slash before the colon).
12
+ const scp = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/\/)(.+)$/.exec(value);
13
+ // A drive letter (C:\repo) is a local path, not a host.
14
+ if (scp && scp[1].length > 1 && !/^[a-z][a-z0-9+.-]*:\/\//i.test(value))
15
+ return { protocol: 'ssh', host: scp[1].toLowerCase(), path: clean(scp[2]) };
16
+ try {
17
+ const parsed = new URL(value);
18
+ const scheme = parsed.protocol.replace(/:$/, '');
19
+ const protocol = scheme === 'https' || scheme === 'http' ? scheme : scheme === 'ssh' || scheme === 'git+ssh' ? 'ssh' : undefined;
20
+ if (!protocol || !parsed.hostname)
21
+ return undefined;
22
+ return { protocol, host: parsed.hostname.toLowerCase(), ...(protocol !== 'ssh' && parsed.port ? { port: parsed.port } : {}), path: clean(decodeURIComponent(parsed.pathname)) };
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ /** The name the forge's MCP server has in OpenCode. */
29
+ export const forgeServerName = (forge) => forge.type;
30
+ /** The forges known by their host alone; others are asked (see probeForge()). */
31
+ export function knownForge(remote) {
32
+ const web = `https://${remote.host}`;
33
+ if (remote.host === 'github.com')
34
+ return { type: 'github', host: remote.host, web, project: remote.path, mcp: 'https://api.githubcopilot.com/mcp/' };
35
+ // GitHub Enterprise Cloud with data residency: <name>.ghe.com.
36
+ const ghe = /^([a-z0-9-]+)\.ghe\.com$/.exec(remote.host);
37
+ if (ghe)
38
+ return { type: 'github', host: remote.host, web, project: remote.path, mcp: `https://copilot-api.${ghe[1]}.ghe.com/mcp` };
39
+ if (remote.host === 'gitlab.com')
40
+ return { type: 'gitlab', host: remote.host, web, project: remote.path, mcp: `${web}/api/v4/mcp` };
41
+ return undefined;
42
+ }
43
+ /** What a GitLab answers on its API: its `x-gitlab-meta` header, or its MCP endpoint's `realm="GitLab"`. */
44
+ export const isGitLabAnswer = (headers) => headers.has('x-gitlab-meta') || /realm="GitLab"/i.test(headers.get('www-authenticate') ?? '');
45
+ /**
46
+ * A host of one's own: a GitLab answers its MCP endpoint (401 without a sign-in, with its header), a GitHub Enterprise
47
+ * Server its `/api/v3/meta`. Asked over HTTPS (HTTP only for an `http://` remote), each in `timeout` ms.
48
+ */
49
+ export async function probeForge(remote, timeout = 3000, fetcher = fetch) {
50
+ const web = `${remote.protocol === 'http' ? 'http' : 'https'}://${remote.host}${remote.port ? `:${remote.port}` : ''}`;
51
+ const ask = (path, init = {}) => fetcher(`${web}${path}`, { ...init, redirect: 'manual', signal: AbortSignal.timeout(timeout) }).catch(() => undefined);
52
+ const mcp = await ask('/api/v4/mcp', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' });
53
+ if (mcp && isGitLabAnswer(mcp.headers))
54
+ return { type: 'gitlab', host: remote.host, web, project: remote.path, mcp: `${web}/api/v4/mcp` };
55
+ const meta = await ask('/api/v3/meta');
56
+ if (meta?.ok) {
57
+ const body = (await meta.json().catch(() => ({})));
58
+ if (body.installed_version)
59
+ return { type: 'github', host: remote.host, web, project: remote.path, enterprise: true };
60
+ }
61
+ return undefined;
62
+ }
63
+ /** A forge named in the config: its MCP server where that kind of forge has it. */
64
+ export function namedForge(setting, remote) {
65
+ const url = new URL(setting.url);
66
+ const web = url.origin + url.pathname.replace(/\/+$/, '');
67
+ const project = setting.project ?? remote?.path ?? '';
68
+ if (setting.type === 'gitlab')
69
+ return { type: 'gitlab', host: url.hostname, web, project, mcp: `${web}/api/v4/mcp` };
70
+ return knownForge({ protocol: 'https', host: url.hostname, path: project }) ?? { type: 'github', host: url.hostname, web, project, enterprise: true };
71
+ }
72
+ /** git run in `cwd`: its output, or undefined when it fails (not a repository, no such remote, no git). */
73
+ async function gitOutput(cwd, args) {
74
+ try {
75
+ const child = Bun.spawn(['git', ...args], { cwd, stdin: 'ignore', stdout: 'pipe', stderr: 'ignore', env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } });
76
+ const [out, code] = await Promise.all([new Response(child.stdout).text(), child.exited]);
77
+ return code === 0 ? out.trim() : undefined;
78
+ }
79
+ catch {
80
+ return undefined;
81
+ }
82
+ }
83
+ /** The repository's forge: from the setting, else `origin`'s host (asked when it is not a known one). */
84
+ export async function detectForge(basePath, setting = 'auto') {
85
+ if (setting === false)
86
+ return {};
87
+ const origin = await gitOutput(basePath, ['remote', 'get-url', 'origin']);
88
+ const remote = origin ? parseRemote(origin) : undefined;
89
+ if (typeof setting === 'object')
90
+ return { forge: namedForge(setting, remote), ...(origin ? { origin } : {}) };
91
+ if (!remote)
92
+ return origin ? { origin } : {};
93
+ const forge = knownForge(remote) ?? (await probeForge(remote));
94
+ return { ...(forge ? { forge } : {}), origin };
95
+ }
96
+ /**
97
+ * The token for the forge's MCP server, when it takes one: GitHub (GITHUB_TOKEN, else `gh auth token`), or a GitLab
98
+ * whose OAuth sign-in is off (GITLAB_TOKEN, a fine-grained token with the MCP permission).
99
+ *
100
+ * A token goes only to the host it was made for, and only over HTTPS: `origin` may name any server, and one that
101
+ * answers like a GitLab must not get the token of yours. GITLAB_TOKEN is gitlab.com's unless GITLAB_TOKEN_HOST names
102
+ * another host; GITHUB_TOKEN is github.com's; the GitHub CLI's login is asked for the very host.
103
+ */
104
+ export async function forgeToken(forge, env = process.env, run = gitHubCli) {
105
+ if (!forge.web.startsWith('https://'))
106
+ return undefined;
107
+ if (forge.type === 'gitlab') {
108
+ const host = (env.GITLAB_TOKEN_HOST || 'gitlab.com').toLowerCase();
109
+ return env.GITLAB_TOKEN && host === forge.host ? { token: env.GITLAB_TOKEN, source: 'env' } : undefined;
110
+ }
111
+ if (env.GITHUB_TOKEN && forge.host === 'github.com')
112
+ return { token: env.GITHUB_TOKEN, source: 'env' };
113
+ const token = await run(['auth', 'token', '--hostname', forge.host]);
114
+ return token ? { token, source: 'gh' } : undefined;
115
+ }
116
+ /** The GitHub CLI's output, or undefined (not installed, not signed in to that host). No shell. */
117
+ async function gitHubCli(args) {
118
+ try {
119
+ const child = Bun.spawn(['gh', ...args], { stdin: 'ignore', stdout: 'pipe', stderr: 'ignore', env: { ...process.env, GH_PROMPT_DISABLED: '1' } });
120
+ const timer = setTimeout(() => child.kill(), 5000);
121
+ const [out, code] = await Promise.all([new Response(child.stdout).text(), child.exited]);
122
+ clearTimeout(timer);
123
+ return code === 0 && out.trim() ? out.trim() : undefined;
124
+ }
125
+ catch {
126
+ return undefined;
127
+ }
128
+ }
129
+ /** The forge's MCP server as OpenCode's config takes it: with the token in a header, else OAuth (GitLab). */
130
+ export function forgeMcp(forge, token) {
131
+ if (!forge.mcp)
132
+ return undefined;
133
+ if (token)
134
+ return { type: 'remote', url: forge.mcp, headers: { Authorization: `Bearer ${token}` }, oauth: false };
135
+ // GitHub has no sign-in for agents: without a token it is left out (Studio says how to give one).
136
+ return forge.type === 'gitlab' ? { type: 'remote', url: forge.mcp } : undefined;
137
+ }
138
+ //# sourceMappingURL=forge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forge.js","sourceRoot":"","sources":["../src/forge.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,8GAA8G;AAC9G,EAAE;AACF,sHAAsH;AACtH,qHAAqH;AACrH,oGAAoG;AAWpG,gIAAgI;AAChI,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrF,qEAAqE;IACrE,MAAM,GAAG,GAAG,yCAAyC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClE,wDAAwD;IACxD,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAE,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC;IACxJ,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjD,MAAM,QAAQ,GAAG,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,MAAM,CAAC,CAAC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C,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,QAAQ,CAAC,KAAY,EAAE,KAAyB;IAC9D,IAAI,CAAC,KAAK,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IACjC,IAAI,KAAK;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAClH,kGAAkG;IAClG,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAClF,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { type QueueManager } from '@rantingjs/framework';
2
+ import type { FastifyInstance } from 'fastify';
3
+ import { type ForgeSetting } from './forge.js';
4
+ /** The last error the app logged, for the agent. */
5
+ export interface LastException {
6
+ exception: string;
7
+ message: string;
8
+ markdown: string;
9
+ time: string;
10
+ }
11
+ export interface StudioSite {
12
+ basePath: string;
13
+ appEnv: () => unknown;
14
+ appName: string;
15
+ appUrl: string;
16
+ lastException: () => Promise<LastException | undefined>;
17
+ /** The file the app logs to now, if it logs to one. */
18
+ logFile: () => string | undefined;
19
+ queues: () => QueueManager;
20
+ queueConnection: () => string | undefined;
21
+ /** The `forge` setting: found from `origin`, none, or named. */
22
+ forge: ForgeSetting;
23
+ }
24
+ /** Registers the page, the API it reads and the proxy to the project's OpenCode server on the app's Fastify instance. */
25
+ export declare function registerRoutes(fastify: FastifyInstance, path: string, site: StudioSite): void;