@gobing-ai/knowledge-kit 0.1.23 → 0.1.25

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 (106) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +418 -114
  3. package/package.json +5 -5
  4. package/plugins/generations/content-gen/dist/index.js +9 -9
  5. package/plugins/generations/core-facts-gen/dist/index.js +12 -12
  6. package/plugins/generations/daily-article-gen/dist/index.js +12 -12
  7. package/plugins/generations/dailynews-gen/dist/index.js +11 -11
  8. package/plugins/generations/dailynews-gen/src/script-plan.ts +2 -2
  9. package/plugins/generations/episode-plan-gen/dist/index.js +59 -18
  10. package/plugins/generations/episode-plan-gen/src/index.ts +71 -7
  11. package/plugins/generations/gemini-tts/dist/index.js +9 -9
  12. package/plugins/generations/image-gen/dist/index.js +9 -9
  13. package/plugins/generations/music-gen/dist/index.js +33 -29
  14. package/plugins/generations/music-gen/src/audio/measure.ts +25 -20
  15. package/plugins/generations/news-report-gen/dist/index.js +12 -12
  16. package/plugins/generations/vibe-voice-tts/dist/index.js +9 -9
  17. package/plugins/generations/voice-gen/dist/index.js +9 -9
  18. package/plugins/generations/voxcpm-tts/dist/index.js +9 -9
  19. package/plugins/ingestions/aihot-ingest/dist/index.js +12 -12
  20. package/plugins/ingestions/horizon-ingest/dist/index.js +12 -12
  21. package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
  22. package/plugins/ingestions/last30days-ingest/dist/index.js +12 -12
  23. package/plugins/ingestions/web-search/dist/index.js +10 -10
  24. package/plugins/kk/decisions/extract/ai-news.yaml +8 -1
  25. package/plugins/kk/plugin.json +1 -1
  26. package/plugins/kk/publish-presets/daily-ai-voice.json +20 -20
  27. package/plugins/kk/publish-presets/itc-main.json +39 -23
  28. package/plugins/kk/scripts/cover-compositor.ts +104 -26
  29. package/plugins/kk/scripts/daily-stages.ts +704 -53
  30. package/plugins/kk/scripts/kk-workflow-stages.ts +149 -6
  31. package/plugins/kk/scripts/series-names.ts +16 -3
  32. package/plugins/kk/skills/content-safety/references/platforms/apple-podcasts.md +12 -5
  33. package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +8 -0
  34. package/plugins/kk/skills/content-safety/references/platforms/xiaoyuzhou.md +5 -0
  35. package/plugins/kk/skills/daily-news-cover/SKILL.md +96 -0
  36. package/plugins/kk/skills/daily-news-illustrations/SKILL.md +123 -0
  37. package/plugins/kk/skills/news-editorial/SKILL.md +5 -3
  38. package/plugins/kk/skills/news-editorial/references/daily-visual-composition.md +150 -0
  39. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +3 -3
  40. package/plugins/kk/workflows/kk-article-generate.yaml +13 -1
  41. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +6 -3
  42. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -4
  43. package/plugins/kk/workflows/kk-news-generate.yaml +74 -1
  44. package/plugins/publishings/bilibili-pub/dist/index.js +25 -24
  45. package/plugins/publishings/bilibili-pub/dist/profile-check.js +25 -24
  46. package/plugins/publishings/cnblogs-pub/dist/index.js +25 -24
  47. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +25 -24
  48. package/plugins/publishings/csdn-pub/dist/index.js +25 -24
  49. package/plugins/publishings/csdn-pub/dist/profile-check.js +25 -24
  50. package/plugins/publishings/emdash-pub/dist/index.js +9 -9
  51. package/plugins/publishings/infoq-pub/dist/index.js +25 -24
  52. package/plugins/publishings/infoq-pub/dist/profile-check.js +25 -24
  53. package/plugins/publishings/jike-pub/dist/index.js +25 -24
  54. package/plugins/publishings/jike-pub/dist/profile-check.js +25 -24
  55. package/plugins/publishings/juejin-pub/dist/index.js +25 -24
  56. package/plugins/publishings/juejin-pub/dist/profile-check.js +25 -24
  57. package/plugins/publishings/linkedin-pub/dist/index.js +85 -26
  58. package/plugins/publishings/linkedin-pub/dist/profile-check.js +25 -24
  59. package/plugins/publishings/linkedin-pub/src/index.ts +93 -6
  60. package/plugins/publishings/medium-pub/dist/index.js +9206 -287
  61. package/plugins/publishings/medium-pub/dist/profile-check.js +21174 -0
  62. package/plugins/publishings/medium-pub/package.json +3 -1
  63. package/plugins/publishings/medium-pub/plugin.json +6 -1
  64. package/plugins/publishings/medium-pub/src/browser-rail.ts +280 -0
  65. package/plugins/publishings/medium-pub/src/index.ts +17 -1
  66. package/plugins/publishings/medium-pub/src/profile-check.ts +27 -0
  67. package/plugins/publishings/podcast-pub/dist/index.js +240 -37
  68. package/plugins/publishings/podcast-pub/src/index.ts +154 -3
  69. package/plugins/publishings/podcast-pub/src/seo.ts +25 -8
  70. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +93 -23
  71. package/plugins/publishings/podcast-pub/src/show-notes.ts +26 -6
  72. package/plugins/publishings/qiita-pub/dist/index.js +9 -9
  73. package/plugins/publishings/shipinhao-pub/dist/index.js +29 -26
  74. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +28 -26
  75. package/plugins/publishings/shipinhao-pub/src/flow.ts +5 -0
  76. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -5
  77. package/plugins/publishings/sspai-pub/dist/index.js +25 -24
  78. package/plugins/publishings/sspai-pub/dist/profile-check.js +25 -24
  79. package/plugins/publishings/substack-pub/dist/index.js +25 -24
  80. package/plugins/publishings/substack-pub/dist/profile-check.js +25 -24
  81. package/plugins/publishings/surfdash-pub/dist/index.js +200 -92
  82. package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
  83. package/plugins/publishings/surfdash-pub/src/index.ts +94 -75
  84. package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
  85. package/plugins/publishings/surfdash-pub/src/patch.ts +28 -23
  86. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
  87. package/plugins/publishings/threads-pub/dist/index.js +39 -24
  88. package/plugins/publishings/threads-pub/dist/profile-check.js +30 -24
  89. package/plugins/publishings/threads-pub/src/post-rail.ts +20 -0
  90. package/plugins/publishings/wechatmp-pub/dist/index.js +438 -102
  91. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +30 -25
  92. package/plugins/publishings/wechatmp-pub/src/enrich.ts +56 -10
  93. package/plugins/publishings/wechatmp-pub/src/flow.ts +589 -83
  94. package/plugins/publishings/wechatmp-pub/src/index.ts +4 -1
  95. package/plugins/publishings/wechatmp-pub/src/modes.ts +30 -12
  96. package/plugins/publishings/wechatmp-pub/src/page.ts +8 -0
  97. package/plugins/publishings/weibo-pub/dist/index.js +25 -24
  98. package/plugins/publishings/weibo-pub/dist/profile-check.js +25 -24
  99. package/plugins/publishings/x-pub/dist/index.js +54 -47
  100. package/plugins/publishings/x-pub/dist/profile-check.js +25 -24
  101. package/plugins/publishings/x-pub/src/post-rail.ts +40 -47
  102. package/plugins/publishings/xhs-pub/dist/index.js +25 -24
  103. package/plugins/publishings/xhs-pub/dist/profile-check.js +25 -24
  104. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +25 -24
  105. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +25 -24
  106. package/plugins/publishings/zenn-pub/dist/index.js +9 -9
@@ -8,8 +8,10 @@
8
8
  "dependencies": {
9
9
  "@gobing-ai/kk-core": "workspace:*",
10
10
  "@gobing-ai/publish-harness": "workspace:*",
11
+ "@gobing-ai/ts-browser-automation": "catalog:",
11
12
  "@gobing-ai/ts-runtime": "catalog:",
12
- "@gobing-ai/ts-utils": "catalog:"
13
+ "@gobing-ai/ts-utils": "catalog:",
14
+ "playwright": "catalog:"
13
15
  },
14
16
  "devDependencies": {
15
17
  "@types/bun": "1.4.3"
@@ -2,8 +2,13 @@
2
2
  "name": "medium-pub",
3
3
  "kind": "publish",
4
4
  "entry": "./dist/index.js",
5
+ "check": "./dist/profile-check.js",
5
6
  "version": "1.0.0",
6
- "description": "Publish plugin for Medium (medium.com) via the integration-token REST API",
7
+ "description": "Publish plugin for Medium (medium.com): integration-token REST API when a token is configured, otherwise a headed script browser rail that fails closed on Cloudflare challenges",
8
+ "browserSession": {
9
+ "profileName": "medium",
10
+ "homeUrl": "https://medium.com/new-story"
11
+ },
7
12
  "publishing": {
8
13
  "defaultProfile": "article",
9
14
  "profiles": {
@@ -0,0 +1,280 @@
1
+ // transcript: 2026-11-23 headed verification against ~/.config/kk/browser-profiles/medium:
2
+ // /new-story renders the authenticated editor with h3[data-testid="editorTitleParagraph"] and
3
+ // p[data-testid="editorParagraphText"] present; draft publish confirmed at /p/<id>/edit.
4
+ // Headless Chromium gets the Cloudflare interstitial (`Just a moment...`), so the rail is
5
+ // headed-only and fails closed on a challenge; Medium no longer issues integration tokens,
6
+ // which makes this browser rail the primary path.
7
+ import { type Content, type Result, ResultSchema } from '@gobing-ai/kk-core';
8
+ import {
9
+ type BrowserDriver,
10
+ type PublishTransport,
11
+ type PublishTransportPayload,
12
+ trySelectors,
13
+ } from '@gobing-ai/publish-harness';
14
+ import {
15
+ type ChannelBrowserConfig,
16
+ checkChannelSession,
17
+ ensureProfileDir,
18
+ expectOutcome,
19
+ kkBrowserLauncher,
20
+ markdownToHtml,
21
+ pasteHtml,
22
+ resolveChannelProfileDir,
23
+ resolveSelector,
24
+ } from '@gobing-ai/publish-harness/browser';
25
+ import {
26
+ type BrowserLauncher,
27
+ BrowserProfileMissingError,
28
+ type IsAuthenticatedPredicate,
29
+ LoginTimeoutError,
30
+ withProfilePage,
31
+ } from '@gobing-ai/ts-browser-automation';
32
+ import type { Page } from 'playwright';
33
+
34
+ export const CHANNEL = 'medium';
35
+ const TARGET = 'medium';
36
+ export const HOME_URL = 'https://medium.com/new-story';
37
+ export const LOGIN_URL_RE = /(\/m\/signin|\/signin|medium\.com\/m\/account)/i;
38
+ export const DRAFT_URL_RE = /\/p\/([a-f0-9]+)\/edit/i;
39
+ export const LIVE_URL_RE = /medium\.com\/@[^/]+\/[^/?#]+/i;
40
+
41
+ export const SELECTORS = {
42
+ title: [
43
+ 'h3[data-testid="editorTitleParagraph"]',
44
+ 'h3.graf--title[contenteditable="true"]',
45
+ '[data-default-value="Title"]',
46
+ 'h3.graf--title',
47
+ ],
48
+ body: [
49
+ 'p[data-testid="editorParagraphText"]',
50
+ '.section-content p.graf--p',
51
+ '[role="textbox"][contenteditable="true"]',
52
+ '[contenteditable="true"]',
53
+ ],
54
+ publishTrigger: ['button[data-testid="publishButton"]', 'button:has-text("Publish")'],
55
+ publishConfirm: ['button[data-testid="publishConfirmButton"]', 'button:has-text("Publish now")'],
56
+ } as const;
57
+
58
+ const STEP_TIMEOUT_MS = 30_000;
59
+ const LOGIN_TIMEOUT_MS = 180_000;
60
+ const LOGIN_INSTRUCTION = 'kk bot login medium (or set MEDIUM_INTEGRATION_TOKEN)';
61
+
62
+ /** A Cloudflare anti-bot interstitial instead of the site (measured headed + headless, 2026-11-22). */
63
+ export const CHALLENGE_RE = /(Just a moment\.\.\.|Performing security verification|Attention Required! \| Cloudflare)/i;
64
+
65
+ /**
66
+ * True when the page is a Cloudflare challenge rather than Medium. Never solved, waited out or
67
+ * bypassed: the caller fails closed with `effect: 'none'` and hands the decision to the operator.
68
+ */
69
+ export async function isChallengePage(page: Page): Promise<boolean> {
70
+ try {
71
+ return CHALLENGE_RE.test(await page.title());
72
+ } catch {
73
+ // A page that cannot report its title is not a detected challenge.
74
+ return false;
75
+ }
76
+ }
77
+
78
+ export const isAuthenticated: IsAuthenticatedPredicate = async (page) =>
79
+ !LOGIN_URL_RE.test(page.url()) &&
80
+ !(await isChallengePage(page)) &&
81
+ (await trySelectors(page, SELECTORS.title, { visible: false })).found;
82
+
83
+ /**
84
+ * A Cloudflare interstitial instead of the editor. Thrown out of the readiness predicate so the
85
+ * refusal names the challenge and the operator action, rather than a generic auth timeout.
86
+ */
87
+ export class ChallengeBlockedError extends Error {
88
+ constructor() {
89
+ super(
90
+ `${CHANNEL} refused: Cloudflare security verification is blocking the ${TARGET} session — open \`kk bot login ${HOME_URL} --save ${CHANNEL}\` in a visible browser and complete the check by hand`,
91
+ );
92
+ this.name = 'ChallengeBlockedError';
93
+ }
94
+ }
95
+
96
+ export function channelConfig(): ChannelBrowserConfig {
97
+ return {
98
+ channel: CHANNEL,
99
+ homeUrl: HOME_URL,
100
+ isAuthenticated,
101
+ loginTimeoutMs: LOGIN_TIMEOUT_MS,
102
+ // Headless load returns the Cloudflare interstitial on this profile (measured 2026-11-22),
103
+ // so a headless preflight pass is a guaranteed burn that shortens the headed budget.
104
+ checkHeadedOnly: true,
105
+ };
106
+ }
107
+
108
+ function fail(error: string, effect: 'none' | 'unknown' = 'unknown'): Result {
109
+ return ResultSchema.parse({
110
+ ok: false,
111
+ target: TARGET,
112
+ error,
113
+ ...(effect === 'none' ? { metadata: { itcDelivery: { schemaVersion: 1, effect: 'none' } } } : {}),
114
+ });
115
+ }
116
+
117
+ function needsLogin(error: unknown): boolean {
118
+ return error instanceof LoginTimeoutError || error instanceof BrowserProfileMissingError;
119
+ }
120
+
121
+ function resolveTitle(content: Content): string {
122
+ if (content.title && content.title.trim().length > 0) return content.title.trim();
123
+ const match = content.body.match(/^#\s+(.+)$/m);
124
+ return match?.[1] ? match[1].trim() : 'Untitled Post';
125
+ }
126
+
127
+ async function probeDraft(page: Page): Promise<string | null> {
128
+ const url = page.url();
129
+ return DRAFT_URL_RE.test(url) ? url : null;
130
+ }
131
+
132
+ async function probeLive(page: Page): Promise<string | null> {
133
+ const url = page.url();
134
+ return LIVE_URL_RE.test(url) && !DRAFT_URL_RE.test(url) ? url : null;
135
+ }
136
+
137
+ /**
138
+ * Browser fallback transport for Medium (`ts-browser-automation`, script driver).
139
+ * Used when `MEDIUM_INTEGRATION_TOKEN` is unset. Defaults strictly to `draft` (ADR-022):
140
+ * Medium autosaves `/new-story` to `/p/<id>/edit` without clicking Publish.
141
+ */
142
+ export class MediumBrowserTransport implements PublishTransport {
143
+ public readonly kind = 'browser';
144
+ public readonly driver: BrowserDriver;
145
+ private readonly launcher: BrowserLauncher;
146
+ private readonly stepTimeoutMs: number;
147
+
148
+ constructor(driver: BrowserDriver = 'script', deps: { launcher?: BrowserLauncher; stepTimeoutMs?: number } = {}) {
149
+ this.driver = driver;
150
+ this.launcher = deps.launcher ?? kkBrowserLauncher;
151
+ this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
152
+ }
153
+
154
+ public async publish(payload: PublishTransportPayload): Promise<Result> {
155
+ if (this.driver !== 'script') {
156
+ return fail(`unsupported driver '${this.driver}' for ${TARGET}`, 'none');
157
+ }
158
+ const requested = payload.options?.publishStatus ?? payload.content.metadata?.publishStatus;
159
+ if (requested !== undefined && requested !== 'draft' && requested !== 'public') {
160
+ return fail(`unknown publishStatus '${String(requested)}' (expected absent, 'draft' or 'public')`, 'none');
161
+ }
162
+
163
+ const override = typeof payload.options?.profileDir === 'string' ? payload.options.profileDir : undefined;
164
+ const profileDir = resolveChannelProfileDir(CHANNEL, override);
165
+
166
+ // 0423 R4: refuse an absent profile BEFORE the headed preflight. A headed launch creates a
167
+ // missing profile dir (`ensureProfileDir`) and holds its lease, so the preflight would
168
+ // fabricate a session, pop a window on an unattended run, and leak the lease on failure.
169
+ try {
170
+ await ensureProfileDir(profileDir, true);
171
+ } catch {
172
+ return fail(
173
+ `${CHANNEL} session preflight refused: no saved profile at ${profileDir} — run: ${LOGIN_INSTRUCTION}`,
174
+ 'none',
175
+ );
176
+ }
177
+
178
+ const session = await checkChannelSession(channelConfig(), {
179
+ profileDir,
180
+ launcher: this.launcher,
181
+ headedOnly: true,
182
+ timeoutMs: this.stepTimeoutMs,
183
+ });
184
+ if (session.status !== 'verified') {
185
+ return fail(`${CHANNEL} session preflight refused: ${session.detail} — run: ${LOGIN_INSTRUCTION}`, 'none');
186
+ }
187
+
188
+ const publishStatus = requested === 'public' ? 'public' : 'draft';
189
+ try {
190
+ return await withProfilePage(
191
+ {
192
+ profileDir,
193
+ url: HOME_URL,
194
+ isAuthenticated: async (page) => {
195
+ // Fail closed on a Cloudflare interstitial; never solve, wait it out or bypass it.
196
+ if (await isChallengePage(page)) throw new ChallengeBlockedError();
197
+ return isAuthenticated(page);
198
+ },
199
+ headless: payload.options?.headless === true,
200
+ launcher: this.launcher,
201
+ timeoutMs: this.stepTimeoutMs,
202
+ },
203
+ async ({ page }) => this.runEditorFlow(page, payload.content, publishStatus, profileDir),
204
+ );
205
+ } catch (error) {
206
+ if (error instanceof ChallengeBlockedError) return fail(error.message, 'none');
207
+ const msg = error instanceof Error ? error.message : String(error);
208
+ const hint = needsLogin(error) ? ` — run: ${LOGIN_INSTRUCTION}` : '';
209
+ return fail(`${msg}${hint}`, needsLogin(error) ? 'none' : 'unknown');
210
+ }
211
+ }
212
+
213
+ private async runEditorFlow(
214
+ page: Page,
215
+ content: Content,
216
+ publishStatus: 'draft' | 'public',
217
+ profileDir: string,
218
+ ): Promise<Result> {
219
+ const metadata = { driver: this.driver, publishStatus, profileDir };
220
+
221
+ const titleSelector = await resolveSelector(page, SELECTORS.title, {
222
+ timeoutMs: this.stepTimeoutMs,
223
+ label: 'title input',
224
+ });
225
+ const titleLocator = page.locator(titleSelector).first();
226
+ await titleLocator.click();
227
+ await titleLocator.fill(resolveTitle(content));
228
+
229
+ const bodySelector = await resolveSelector(page, SELECTORS.body, {
230
+ timeoutMs: this.stepTimeoutMs,
231
+ label: 'body editor',
232
+ });
233
+ await pasteHtml(page, bodySelector, markdownToHtml(content.body), { timeoutMs: this.stepTimeoutMs });
234
+
235
+ const draft = await expectOutcome(() => probeDraft(page), {
236
+ timeoutMs: this.stepTimeoutMs,
237
+ label: `medium draft signal in '${bodySelector}'`,
238
+ });
239
+ if (!draft.ok) return fail(draft.error);
240
+
241
+ const id = DRAFT_URL_RE.exec(draft.evidence)?.[1];
242
+ if (publishStatus === 'draft') {
243
+ return ResultSchema.parse({
244
+ ok: true,
245
+ target: TARGET,
246
+ ...(id === undefined ? {} : { id }),
247
+ url: draft.evidence,
248
+ message: `${TARGET} draft saved (unpublished) in profile ${profileDir}`,
249
+ metadata,
250
+ });
251
+ }
252
+
253
+ const triggerSelector = await resolveSelector(page, SELECTORS.publishTrigger, {
254
+ timeoutMs: this.stepTimeoutMs,
255
+ label: 'publish button',
256
+ });
257
+ await page.locator(triggerSelector).first().click();
258
+
259
+ const confirmSelector = await resolveSelector(page, SELECTORS.publishConfirm, {
260
+ timeoutMs: this.stepTimeoutMs,
261
+ label: 'publish confirm button',
262
+ });
263
+ await page.locator(confirmSelector).first().click();
264
+
265
+ const live = await expectOutcome(() => probeLive(page), {
266
+ timeoutMs: this.stepTimeoutMs,
267
+ label: `medium publish '${confirmSelector}'`,
268
+ });
269
+ if (!live.ok) return fail(live.error);
270
+
271
+ return ResultSchema.parse({
272
+ ok: true,
273
+ target: TARGET,
274
+ ...(id === undefined ? {} : { id }),
275
+ url: live.evidence,
276
+ message: `${TARGET} published live in profile ${profileDir}`,
277
+ metadata,
278
+ });
279
+ }
280
+ }
@@ -4,6 +4,18 @@ import { type Content, ContentSchema, type Result, ResultSchema } from '@gobing-
4
4
  import { FakeFileCliTransport, type PublishTransport, type PublishTransportPayload } from '@gobing-ai/publish-harness';
5
5
  import { createNodeFileSystem } from '@gobing-ai/ts-runtime';
6
6
  import { echoError } from '@gobing-ai/ts-utils';
7
+ import { MediumBrowserTransport } from './browser-rail';
8
+
9
+ export {
10
+ CHANNEL,
11
+ channelConfig,
12
+ DRAFT_URL_RE,
13
+ HOME_URL,
14
+ isAuthenticated,
15
+ LOGIN_URL_RE,
16
+ MediumBrowserTransport,
17
+ SELECTORS,
18
+ } from './browser-rail';
7
19
 
8
20
  /** Medium REST API v1 (integration tokens still post; official docs archived 2023). */
9
21
  const MEDIUM_API_BASE = 'https://api.medium.com/v1';
@@ -148,7 +160,11 @@ export function getPublishTransport(): PublishTransport {
148
160
  if (process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === 'fake') {
149
161
  return new FakeFileCliTransport();
150
162
  }
151
- return new MediumApiTransport();
163
+ const token = process.env[TOKEN_ENV];
164
+ if (token && token.trim().length > 0) {
165
+ return new MediumApiTransport();
166
+ }
167
+ return new MediumBrowserTransport('script');
152
168
  }
153
169
 
154
170
  async function writePublishResult(outputPath: string, result: Result): Promise<void> {
@@ -0,0 +1,27 @@
1
+ import { type ProfileCliDeps, runProfileCli } from '@gobing-ai/publish-harness/browser';
2
+ import { echo } from '@gobing-ai/ts-utils';
3
+ import { channelConfig } from './browser-rail';
4
+
5
+ /**
6
+ * Medium profile-session CLI (`login|check|open`).
7
+ *
8
+ * When `MEDIUM_INTEGRATION_TOKEN` is configured, `check` exits 0 immediately without requiring a
9
+ * browser profile so token-API users are never blocked by the browser fallback.
10
+ */
11
+ export async function main(argv: readonly string[] = Bun.argv.slice(2), deps: ProfileCliDeps = {}): Promise<number> {
12
+ const stdout =
13
+ deps.stdout ??
14
+ ((line: string) => {
15
+ echo(line);
16
+ });
17
+ const command = argv[0];
18
+ if (command === 'check' && (process.env.MEDIUM_INTEGRATION_TOKEN?.trim() ?? '').length > 0) {
19
+ stdout(JSON.stringify({ status: 'verified', detail: 'MEDIUM_INTEGRATION_TOKEN configured' }));
20
+ return 0;
21
+ }
22
+ return runProfileCli(channelConfig(), [...argv], { ...deps, stdout });
23
+ }
24
+
25
+ if (import.meta.main) {
26
+ process.exit(await main());
27
+ }