Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
marketplace.tsx17.4 KB · 542 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
/**
 * Block H — Marketplace UI + developer-side app management.
 *
 *   GET  /marketplace                       — public app directory (search)
 *   GET  /marketplace/:slug                 — app detail + install CTA
 *   POST /marketplace/:slug/install         — install to user (v1 only)
 *   POST /marketplace/installations/:id/uninstall
 *                                           — revoke access
 *   GET  /settings/apps                     — list installed apps
 *   GET  /developer/apps-new                — register a new app
 *   POST /developer/apps-new                — create app + bot
 *   GET  /developer/apps/:slug/manage       — event log + install count
 *   POST /developer/apps/:slug/tokens/new   — issue install token (for testing)
 */

import { Hono } from "hono";
import { eq } from "drizzle-orm";
import { db } from "../db";
import { apps, appInstallations } from "../db/schema";
import { Layout } from "../views/layout";
import { softAuth, requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import {
  KNOWN_PERMISSIONS,
  KNOWN_EVENTS,
  countInstalls,
  createApp,
  getAppBySlug,
  installApp,
  issueInstallToken,
  listEventsForApp,
  listInstallationsForApp,
  listInstallationsForTarget,
  listPublicApps,
  normalisePermissions,
  parsePermissions,
  uninstallApp,
} from "../lib/marketplace";
import { audit } from "../lib/notify";

const marketplace = new Hono<AuthEnv>();
marketplace.use("*", softAuth);

// ---------- Public directory ----------

marketplace.get("/marketplace", async (c) => {
  const user = c.get("user");
  const q = c.req.query("q") || "";
  const list = await listPublicApps(q);
  return c.html(
    <Layout title="Marketplace — Gluecron" user={user}>
      <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px">
        <h2>Marketplace</h2>
        {user && (
          <a href="/developer/apps-new" class="btn btn-sm">
            + Register app
          </a>
        )}
      </div>
      <form method="GET" action="/marketplace" style="margin-bottom:16px">
        <input
          type="text"
          name="q"
          value={q}
          placeholder="Search apps"
          style="width:320px"
        />{" "}
        <button type="submit" class="btn">
          Search
        </button>
      </form>
      <div
        style="display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px"
      >
        {list.length === 0 ? (
          <div class="panel-empty">No apps found.</div>
        ) : (
          list.map((a) => (
            <a
              href={`/marketplace/${a.slug}`}
              class="panel"
              style="padding:16px;color:inherit;text-decoration:none"
            >
              <div style="font-size:15px;font-weight:700">{a.name}</div>
              <div
                style="font-size:12px;color:var(--text-muted);margin-top:4px;line-height:1.4"
              >
                {a.description.slice(0, 140) || "No description."}
              </div>
              <div
                style="font-size:11px;color:var(--text-muted);margin-top:8px;text-transform:uppercase"
              >
                {parsePermissions(a.permissions).length} permissions
              </div>
            </a>
          ))
        )}
      </div>
    </Layout>
  );
});

marketplace.get("/marketplace/:slug", async (c) => {
  const user = c.get("user");
  const slug = c.req.param("slug");
  const app = await getAppBySlug(slug);
  if (!app || !app.isPublic) return c.notFound();
  const [installs, perms] = await Promise.all([
    countInstalls(app.id),
    Promise.resolve(parsePermissions(app.permissions)),
  ]);
  return c.html(
    <Layout title={`${app.name} — Marketplace`} user={user}>
      <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px">
        <h2>{app.name}</h2>
        <a href="/marketplace" class="btn btn-sm">
          Back
        </a>
      </div>
      <div class="panel" style="padding:16px;margin-bottom:20px">
        <p>{app.description || "No description."}</p>
        {app.homepageUrl && (
          <p style="margin-top:8px">
            Homepage: <a href={app.homepageUrl}>{app.homepageUrl}</a>
          </p>
        )}
        <div style="font-size:12px;color:var(--text-muted);margin-top:8px">
          {installs} install{installs === 1 ? "" : "s"} · bot username{" "}
          <code>{app.slug}[bot]</code>
        </div>
      </div>

      <h3>Permissions</h3>
      <div class="panel" style="margin-bottom:20px">
        {perms.length === 0 ? (
          <div class="panel-empty">No permissions requested.</div>
        ) : (
          perms.map((p) => (
            <div class="panel-item">
              <code>{p}</code>
            </div>
          ))
        )}
      </div>

      {user ? (
        <form method="POST" action={`/marketplace/${slug}/install`}>
          <div class="form-group">
            <p
              style="font-size:13px;color:var(--text-muted);margin-bottom:8px"
            >
              Installing grants {perms.length} permission
              {perms.length === 1 ? "" : "s"} to <strong>{app.name}</strong>{" "}
              on your personal account.
            </p>
          </div>
          {perms.map((p) => (
            <label
              style="display:inline-block;margin-right:10px;font-size:13px"
            >
              <input
                type="checkbox"
                name="permissions"
                value={p}
                checked
              />{" "}
              {p}
            </label>
          ))}
          <div style="margin-top:12px">
            <button type="submit" class="btn btn-primary">
              Install
            </button>
          </div>
        </form>
      ) : (
        <div class="panel" style="padding:16px;text-align:center">
          <a href={`/login?next=/marketplace/${slug}`}>Sign in to install</a>
        </div>
      )}
    </Layout>
  );
});

marketplace.post("/marketplace/:slug/install", requireAuth, async (c) => {
  const user = c.get("user")!;
  const slug = c.req.param("slug");
  const app = await getAppBySlug(slug);
  if (!app) return c.notFound();
  const body = await c.req.parseBody({ all: true });
  const rawPerms = body.permissions;
  const perms = Array.isArray(rawPerms)
    ? rawPerms.map(String)
    : rawPerms
    ? [String(rawPerms)]
    : [];
  const inst = await installApp({
    appId: app.id,
    installedBy: user.id,
    targetType: "user",
    targetId: user.id,
    grantedPermissions: perms,
  });
  if (inst) {
    await audit({
      userId: user.id,
      action: "marketplace.install",
      targetType: "app",
      targetId: app.id,
      metadata: { grantedPermissions: normalisePermissions(perms) },
    });
  }
  return c.redirect("/settings/apps");
});

marketplace.post(
  "/marketplace/installations/:id/uninstall",
  requireAuth,
  async (c) => {
    const user = c.get("user")!;
    const id = c.req.param("id");
    // Only the installer can uninstall
    const [inst] = await db
      .select()
      .from(appInstallations)
      .where(eq(appInstallations.id, id))
      .limit(1);
    if (!inst || inst.installedBy !== user.id) {
      return c.text("forbidden", 403);
    }
    const ok = await uninstallApp(id);
    if (ok) {
      await audit({
        userId: user.id,
        action: "marketplace.uninstall",
        targetType: "app_installation",
        targetId: id,
      });
    }
    return c.redirect("/settings/apps");
  }
);

// ---------- Personal installs ----------

marketplace.get("/settings/apps", requireAuth, async (c) => {
  const user = c.get("user")!;
  const installs = await listInstallationsForTarget("user", user.id);
  return c.html(
    <Layout title="Installed apps — Gluecron" user={user}>
      <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px">
        <h2>Installed apps</h2>
        <a href="/marketplace" class="btn btn-sm">
          Browse marketplace
        </a>
      </div>
      <div class="panel">
        {installs.length === 0 ? (
          <div class="panel-empty">
            No apps installed.{" "}
            <a href="/marketplace">Browse the marketplace</a>.
          </div>
        ) : (
          installs.map((i) => (
            <div class="panel-item" style="justify-content:space-between">
              <div style="flex:1;min-width:0">
                <a
                  href={i.app ? `/marketplace/${i.app.slug}` : "#"}
                  style="font-weight:600"
                >
                  {i.app?.name || "(unknown app)"}
                </a>
                <div
                  style="font-size:12px;color:var(--text-muted);margin-top:2px"
                >
                  {parsePermissions(i.grantedPermissions).length} permissions ·
                  installed{" "}
                  {i.createdAt
                    ? new Date(i.createdAt).toLocaleDateString()
                    : ""}
                </div>
              </div>
              <form
                method="POST"
                action={`/marketplace/installations/${i.id}/uninstall`}
                onsubmit="return confirm('Uninstall this app?')"
              >
                <button type="submit" class="btn btn-sm btn-danger">
                  Uninstall
                </button>
              </form>
            </div>
          ))
        )}
      </div>
    </Layout>
  );
});

// ---------- Developer UX ----------

marketplace.get("/developer/apps-new", requireAuth, async (c) => {
  const user = c.get("user")!;
  return c.html(
    <Layout title="New app — Marketplace" user={user}>
      <h2>Register a new app</h2>
      <form method="POST" action="/developer/apps-new" class="panel" style="padding:16px">
        <div class="form-group">
          <label>Name</label>
          <input type="text" name="name" required style="width:100%" />
        </div>
        <div class="form-group">
          <label>Description</label>
          <textarea name="description" rows="3" style="width:100%" />
        </div>
        <div class="form-group">
          <label>Homepage URL</label>
          <input type="url" name="homepageUrl" style="width:100%" />
        </div>
        <div class="form-group">
          <label>Webhook URL (optional)</label>
          <input type="url" name="webhookUrl" style="width:100%" />
        </div>
        <div class="form-group">
          <label>Permissions</label>
          <div
            style="display:grid;grid-template-columns:repeat(2,1fr);gap:4px;font-size:13px"
          >
            {KNOWN_PERMISSIONS.map((p) => (
              <label>
                <input type="checkbox" name="permissions" value={p} /> {p}
              </label>
            ))}
          </div>
        </div>
        <div class="form-group">
          <label>Events</label>
          <div
            style="display:grid;grid-template-columns:repeat(3,1fr);gap:4px;font-size:13px"
          >
            {KNOWN_EVENTS.map((e) => (
              <label>
                <input type="checkbox" name="events" value={e} /> {e}
              </label>
            ))}
          </div>
        </div>
        <div class="form-group">
          <label>
            <input type="checkbox" name="isPublic" value="1" checked /> List in
            public marketplace
          </label>
        </div>
        <button type="submit" class="btn btn-primary">
          Create app
        </button>
      </form>
    </Layout>
  );
});

marketplace.post("/developer/apps-new", requireAuth, async (c) => {
  const user = c.get("user")!;
  const body = await c.req.parseBody({ all: true });
  const name = String(body.name || "").trim();
  if (!name) return c.redirect("/developer/apps-new");
  const rawPerms = body.permissions;
  const perms = Array.isArray(rawPerms)
    ? rawPerms.map(String)
    : rawPerms
    ? [String(rawPerms)]
    : [];
  const rawEvents = body.events;
  const events = Array.isArray(rawEvents)
    ? rawEvents.map(String)
    : rawEvents
    ? [String(rawEvents)]
    : [];
  const app = await createApp({
    name,
    description: String(body.description || ""),
    homepageUrl: String(body.homepageUrl || "") || undefined,
    webhookUrl: String(body.webhookUrl || "") || undefined,
    creatorId: user.id,
    permissions: perms,
    defaultEvents: events,
    isPublic: !!body.isPublic,
  });
  if (!app) return c.text("failed to create", 500);
  await audit({
    userId: user.id,
    action: "marketplace.app.create",
    targetType: "app",
    targetId: app.id,
  });
  return c.redirect(`/developer/apps/${app.slug}/manage`);
});

marketplace.get("/developer/apps/:slug/manage", requireAuth, async (c) => {
  const user = c.get("user")!;
  const slug = c.req.param("slug");
  const app = await getAppBySlug(slug);
  if (!app) return c.notFound();
  if (app.creatorId !== user.id) return c.text("forbidden", 403);
  const [installs, events] = await Promise.all([
    listInstallationsForApp(app.id),
    listEventsForApp(app.id, 20),
  ]);
  return c.html(
    <Layout title={`Manage ${app.name}`} user={user}>
      <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px">
        <h2>{app.name} · Developer</h2>
        <a href={`/marketplace/${app.slug}`} class="btn btn-sm">
          Public page
        </a>
      </div>
      <div class="panel" style="padding:12px;margin-bottom:20px">
        <div style="font-size:12px;color:var(--text-muted)">Bot identity</div>
        <div style="font-family:var(--font-mono)">{app.slug}[bot]</div>
        {app.webhookSecret && (
          <div style="margin-top:8px;font-size:12px">
            <span style="color:var(--text-muted)">Webhook secret:</span>{" "}
            <code>{app.webhookSecret}</code>
          </div>
        )}
      </div>

      <h3>Installations ({installs.length})</h3>
      <div class="panel" style="margin-bottom:20px">
        {installs.length === 0 ? (
          <div class="panel-empty">No installs yet.</div>
        ) : (
          installs.map((i) => (
            <div class="panel-item" style="justify-content:space-between">
              <div>
                {i.targetType}: <code>{i.targetId}</code>
              </div>
              <div style="font-size:12px;color:var(--text-muted)">
                {parsePermissions(i.grantedPermissions).length} perms ·{" "}
                {i.createdAt
                  ? new Date(i.createdAt).toLocaleDateString()
                  : ""}
              </div>
            </div>
          ))
        )}
      </div>

      <h3>Recent events</h3>
      <div class="panel" style="margin-bottom:20px">
        {events.length === 0 ? (
          <div class="panel-empty">No events yet.</div>
        ) : (
          events.map((e) => (
            <div class="panel-item" style="justify-content:space-between">
              <span>{e.kind}</span>
              <span style="font-size:12px;color:var(--text-muted)">
                {e.createdAt
                  ? new Date(e.createdAt).toLocaleString()
                  : ""}
              </span>
            </div>
          ))
        )}
      </div>

      <h3>Installation tokens</h3>
      <form
        method="POST"
        action={`/developer/apps/${app.slug}/tokens/new`}
        class="panel"
        style="padding:16px"
      >
        <p style="font-size:13px;color:var(--text-muted);margin-bottom:12px">
          Issue a bearer token for an existing installation. Use this to test
          bot API calls. Tokens are shown once and expire after 1 hour.
        </p>
        <select name="installationId">
          {installs.map((i) => (
            <option value={i.id}>
              {i.targetType}:{i.targetId.slice(0, 8)}
            </option>
          ))}
        </select>{" "}
        <button type="submit" class="btn btn-sm" disabled={installs.length === 0}>
          Issue token
        </button>
      </form>
    </Layout>
  );
});

marketplace.post(
  "/developer/apps/:slug/tokens/new",
  requireAuth,
  async (c) => {
    const user = c.get("user")!;
    const slug = c.req.param("slug");
    const app = await getAppBySlug(slug);
    if (!app) return c.notFound();
    if (app.creatorId !== user.id) return c.text("forbidden", 403);
    const body = await c.req.parseBody();
    const installationId = String(body.installationId || "");
    if (!installationId) return c.redirect(`/developer/apps/${slug}/manage`);
    // Validate the installation belongs to this app
    const [inst] = await db
      .select()
      .from(appInstallations)
      .where(eq(appInstallations.id, installationId))
      .limit(1);
    if (!inst || inst.appId !== app.id) return c.text("forbidden", 403);
    const t = await issueInstallToken(installationId);
    if (!t) return c.text("failed", 500);
    await audit({
      userId: user.id,
      action: "marketplace.token.issue",
      targetType: "app_installation",
      targetId: installationId,
    });
    return c.html(
      <Layout title="Token issued" user={user}>
        <h2>Token issued</h2>
        <div class="panel" style="padding:16px">
          <p>Copy this token now — it won't be shown again.</p>
          <pre
            style="font-family:var(--font-mono);background:var(--bg-secondary);padding:12px;border-radius:6px;word-break:break-all"
          >
            {t.token}
          </pre>
          <p style="font-size:12px;color:var(--text-muted)">
            Expires at {t.expiresAt.toISOString()}
          </p>
          <a href={`/developer/apps/${slug}/manage`} class="btn" style="margin-top:12px">
            Back
          </a>
        </div>
      </Layout>
    );
  }
);

export default marketplace;