Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(inbox): prefill the scout create modal from a #createScout deep link (#76893)

Sarah Sandersc31bdf17fe6b
diff --git a/products/signals/frontend/inbox/InboxScene.tsx b/products/signals/frontend/inbox/InboxScene.tsx
index edf62f1cccd6..9f226206517d 100644
--- a/products/signals/frontend/inbox/InboxScene.tsx
+++ b/products/signals/frontend/inbox/InboxScene.tsx
@@ -1,5 +1,5 @@
import { useActions, useValues } from 'kea'
-import { useEffect, useRef } from 'react'
+import React, { useEffect, useRef } from 'react'
import { IconArrowLeft, IconBug } from '@posthog/icons'
import { LemonButton, Tooltip } from '@posthog/lemon-ui'
@@ -27,6 +27,7 @@ import { RunsTab } from './components/tabs/RunsTab'
import { captureInboxPanelViewed } from './inboxAnalytics'
import { inboxSceneLogic } from './inboxSceneLogic'
import { inboxOnboardingLogic } from './logics/inboxOnboardingLogic'
+import { scoutFleetLogic } from './logics/scoutFleetLogic'
import { INBOX_TAB_DESCRIPTION, InboxTabKey, SignalReport, SignalRun } from './types'
export const scene: SceneExport = {
@@ -34,6 +35,37 @@ export const scene: SceneExport = {
logic: inboxSceneLogic,
}
+const LazyScoutCreateModal = React.lazy(async () => {
+ const { ScoutCreateModal } = await import('./components/config/scouts/ScoutCreateModal')
+ return { default: ScoutCreateModal }
+})
+
+/**
+ * Hosts the `#createScout=` modal at the scene level, not in the fleet section: on wide screens
+ * `/inbox/config` bounces to the setup rail, where the fleet section may never mount.
+ */
+function ScoutTemplateDraftModal(): JSX.Element | null {
+ const { scoutTemplateDraft } = useValues(inboxSceneLogic)
+ const { setScoutTemplateDraft } = useActions(inboxSceneLogic)
+
+ if (!scoutTemplateDraft) {
+ return null
+ }
+ return (
+ <React.Suspense fallback={null}>
+ <LazyScoutCreateModal
+ isOpen
+ initialValues={scoutTemplateDraft}
+ onClose={() => setScoutTemplateDraft(null)}
+ onCreated={() => {
+ // Refresh the fleet list only if it's already mounted — never mount it from here.
+ scoutFleetLogic.findMounted()?.actions.loadScoutConfigs()
+ }}
+ />
+ </React.Suspense>
+ )
+}
+
/** Min scene-container width at which the setup rail fits beside the list. */
const SETUP_RAIL_MIN_PX = 1024
@@ -286,6 +318,8 @@ export function InboxScene(): JSX.Element {
)}
</div>
)}
+
+ <ScoutTemplateDraftModal />
</SceneContent>
)
}
diff --git a/products/signals/frontend/inbox/inboxSceneLogic.ts b/products/signals/frontend/inbox/inboxSceneLogic.ts
index 6e3cb4190591..e70cf9aaee5a 100644
--- a/products/signals/frontend/inbox/inboxSceneLogic.ts
+++ b/products/signals/frontend/inbox/inboxSceneLogic.ts
@@ -25,6 +25,7 @@ import {
} from './inboxAnalytics'
import { inboxFiltersLogic } from './logics/inboxFiltersLogic'
import { INBOX_FLAT_TAB_LIST_PARAMS, reportListLogic } from './logics/reportListLogic'
+import type { ScoutCreateInitialValues } from './logics/scoutCreateModalLogic'
import { scratchpadLogic } from './logics/scratchpadLogic'
import { signalSourcesLogic } from './signalSourcesLogic'
import {
@@ -37,12 +38,34 @@ import {
SignalScoutRunStatus,
SignalScoutRunSummary,
} from './types'
+import { decodeScoutCreateTemplate } from './utils/scoutTemplateDeepLink'
// Newest-first scout runs to pull for the Runs tab. The scout-runs endpoint caps at 100 server-side.
const SCOUT_RUNS_LIMIT = 100
+
// Signal-pipeline tasks to pull. Bounded symmetrically with the scout side (the tasks endpoint caps
// at 100); passed explicitly so the cap is visible rather than relying on the server default.
const SIGNAL_TASKS_LIMIT = 100
+
+/** Strips `#createScout=` from the URL so a refresh can't re-trigger it, then opens the modal. */
+function consumeScoutTemplateHash(
+ actions: { setScoutTemplateDraft: (draft: ScoutCreateInitialValues | null) => void },
+ hashParams: Record<string, any> | undefined
+): void {
+ const raw = hashParams?.['createScout']
+ if (raw === undefined) {
+ return
+ }
+ const { createScout: _consumed, ...remainingHashParams } = hashParams ?? {}
+ router.actions.replace(router.values.location.pathname, router.values.searchParams, remainingHashParams)
+ const draft = decodeScoutCreateTemplate(raw)
+ if (draft) {
+ actions.setScoutTemplateDraft(draft)
+ } else {
+ lemonToast.error("Couldn't read the scout template from this link")
+ }
+}
+
// How often the Runs tab refetches while it's open, so live runs update in place.
const RUNS_POLL_INTERVAL_MS = 5000
@@ -198,6 +221,7 @@ export interface inboxSceneLogicValues {
isRunningSessionAnalysis: boolean
isScratchpadOpen: boolean
isStaff: boolean
+ scoutTemplateDraft: ScoutCreateInitialValues | null
selectedReport: SignalReport | null
selectedReportId: string | null
selectedReportLoading: boolean
@@ -268,6 +292,9 @@ export interface inboxSceneLogicActions {
setFindingsOpen: (open: boolean) => {
open: boolean
}
+ setScoutTemplateDraft: (draft: ScoutCreateInitialValues | null) => {
+ draft: ScoutCreateInitialValues | null
+ }
setScratchpadOpen: (open: boolean) => {
open: boolean
}
@@ -346,6 +373,8 @@ export const inboxSceneLogic = kea<inboxSceneLogicType>([
runSessionAnalysis: true,
runSessionAnalysisSuccess: true,
runSessionAnalysisFailure: (error: string) => ({ error }),
+ // A decoded `#createScout=` payload, prefilling the create modal. The user still submits it.
+ setScoutTemplateDraft: (draft: ScoutCreateInitialValues | null) => ({ draft }),
}),
loaders(() => ({
@@ -437,6 +466,12 @@ export const inboxSceneLogic = kea<inboxSceneLogicType>([
setScratchpadOpen: (state, { open }) => (open ? false : state),
},
],
+ scoutTemplateDraft: [
+ null as ScoutCreateInitialValues | null,
+ {
+ setScoutTemplateDraft: (_, { draft }) => draft,
+ },
+ ],
// The finding deep-linked within the selected scout, if any. Cleared whenever a scout is
// (re)selected without a finding — navigating to a scout from the fleet drops any prior finding.
selectedScoutFindingId: [
@@ -685,8 +720,9 @@ export const inboxSceneLogic = kea<inboxSceneLogicType>([
actions.setFindingsOpen(true)
}
},
- [urls.inbox()]: () => {
+ [urls.inbox()]: (_, __, hashParams) => {
cache.inboxListVisited = true
+ consumeScoutTemplateHash(actions, hashParams)
if (values.selectedReportId !== null) {
actions.setSelectedReportId(null)
}
@@ -700,7 +736,7 @@ export const inboxSceneLogic = kea<inboxSceneLogicType>([
actions.setFindingsOpen(false)
}
},
- [urls.inbox(':tab')]: ({ tab }: { tab?: string }) => {
+ [urls.inbox(':tab')]: ({ tab }: { tab?: string }, _, hashParams) => {
// A bare report deep-link `/inbox/<reportId>` redirected to report form. Mark the list as
// visited only when we're actually staying on a list view — otherwise the redirected report
// would be misclassified as an in-app click instead of a deep-link.
@@ -713,6 +749,7 @@ export const inboxSceneLogic = kea<inboxSceneLogicType>([
return
}
cache.inboxListVisited = true
+ consumeScoutTemplateHash(actions, hashParams)
// Staff-only tabs (Not actionable): bounce non-staff to the default tab.
if (isStaffOnlyTab(tab) && userLogic.values.user != null && !values.isStaff) {
actions.setActiveTab('pulls')
diff --git a/products/signals/frontend/inbox/utils/scoutTemplateDeepLink.test.ts b/products/signals/frontend/inbox/utils/scoutTemplateDeepLink.test.ts
new file mode 100644
index 000000000000..8a250850f235
--- /dev/null
+++ b/products/signals/frontend/inbox/utils/scoutTemplateDeepLink.test.ts
@@ -0,0 +1,62 @@
+import { SKILL_DESCRIPTION_MAX_LENGTH } from 'products/skills/frontend/skillConstants'
+
+import { decodeScoutCreateTemplate, encodeScoutCreateTemplate } from './scoutTemplateDeepLink'
+
+describe('scoutTemplateDeepLink', () => {
+ it('round-trips a full template', () => {
+ const encoded = encodeScoutCreateTemplate({
+ name: 'signals-scout-silent-failure',
+ description: 'Watches the core action for silent failures',
+ body: '# Scout\n\nSpeak up when completions fall while attempts hold steady.',
+ })
+ // URL-safe: must survive a hash fragment untouched.
+ expect(encoded).not.toMatch(/[+/=]/)
+ expect(decodeScoutCreateTemplate(encoded)).toEqual({
+ name: 'signals-scout-silent-failure',
+ description: 'Watches the core action for silent failures',
+ body: '# Scout\n\nSpeak up when completions fall while attempts hold steady.',
+ })
+ })
+
+ it('round-trips multibyte content', () => {
+ const encoded = encodeScoutCreateTemplate({ description: 'Watches naïve 🦔 flows – en dashes too' })
+ expect(decodeScoutCreateTemplate(encoded)).toEqual({ description: 'Watches naïve 🦔 flows – en dashes too' })
+ })
+
+ it('prefixes an unprefixed name', () => {
+ const encoded = encodeScoutCreateTemplate({ name: 'silent-failure', description: 'd' })
+ expect(decodeScoutCreateTemplate(encoded)?.name).toBe('signals-scout-silent-failure')
+ })
+
+ it('drops an invalid name but keeps the rest', () => {
+ const encoded = encodeScoutCreateTemplate({ name: 'signals-scout-INVALID NAME!', description: 'd' })
+ expect(decodeScoutCreateTemplate(encoded)).toEqual({ description: 'd' })
+ })
+
+ it('truncates an oversized description', () => {
+ const encoded = encodeScoutCreateTemplate({ description: 'x'.repeat(SKILL_DESCRIPTION_MAX_LENGTH + 50) })
+ expect(decodeScoutCreateTemplate(encoded)?.description).toHaveLength(SKILL_DESCRIPTION_MAX_LENGTH)
+ })
+
+ it('ignores config and unknown fields — scheduling is never URL-controlled', () => {
+ const encoded = encodeScoutCreateTemplate({
+ description: 'd',
+ // @ts-expect-error deliberately smuggling extra fields
+ config: { enabled: true, emit: true, run_interval_minutes: 30 },
+ extra: 'nope',
+ })
+ expect(decodeScoutCreateTemplate(encoded)).toEqual({ description: 'd' })
+ })
+
+ it.each([
+ ['undefined', undefined],
+ ['empty string', ''],
+ ['not base64', '!!!not-base64!!!'],
+ ['base64 of non-JSON', 'bm90IGpzb24'],
+ ['base64 of a JSON array', 'W10'],
+ ['name-only payload', encodeScoutCreateTemplate({ name: 'signals-scout-x' })],
+ ['oversized payload', 'A'.repeat(20000)],
+ ])('returns null for %s', (_label, raw) => {
+ expect(decodeScoutCreateTemplate(raw)).toBeNull()
+ })
+})
diff --git a/products/signals/frontend/inbox/utils/scoutTemplateDeepLink.ts b/products/signals/frontend/inbox/utils/scoutTemplateDeepLink.ts
new file mode 100644
index 000000000000..1272a57cfc25
--- /dev/null
+++ b/products/signals/frontend/inbox/utils/scoutTemplateDeepLink.ts
@@ -0,0 +1,71 @@
+import { base64Decode, base64Encode } from 'lib/utils/base64'
+
+import { SKILL_DESCRIPTION_MAX_LENGTH, validateSkillName } from 'products/skills/frontend/skillConstants'
+
+import type { ScoutCreateInitialValues } from '../logics/scoutCreateModalLogic'
+import { SIGNALS_SCOUT_SKILL_PREFIX } from './scoutRunsWindow'
+
+/**
+ * `/inbox/config#createScout=<url-safe base64 JSON>`, e.g. from a posthog.com template page.
+ * In the fragment so it never reaches server logs, and prefill-only: no schedule, no emit posture.
+ */
+export interface ScoutTemplatePayload {
+ name?: string
+ description?: string
+ body?: string
+}
+
+/** Whole-payload cap, before decoding. Far above any real template, far below abuse territory. */
+const MAX_ENCODED_LENGTH = 16384
+const MAX_BODY_LENGTH = 20000
+
+/** Encode a template as a URL-safe base64 fragment value (used by tests and by link authors). */
+export function encodeScoutCreateTemplate(template: ScoutTemplatePayload): string {
+ return base64Encode(JSON.stringify(template)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
+}
+
+/** Decodes a `#createScout=` value into modal initial values. Null means ignore the fragment. */
+export function decodeScoutCreateTemplate(raw: unknown): ScoutCreateInitialValues | null {
+ if (typeof raw !== 'string' || raw.length === 0 || raw.length > MAX_ENCODED_LENGTH) {
+ return null
+ }
+
+ let parsed: unknown
+ try {
+ // Accept both base64 alphabets and missing padding, like the desktop deep-link decoder.
+ const normalized = raw.replace(/-/g, '+').replace(/_/g, '/')
+ const padded = normalized + '='.repeat((4 - (normalized.length % 4)) % 4)
+ parsed = JSON.parse(base64Decode(padded))
+ } catch {
+ return null
+ }
+
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
+ return null
+ }
+
+ const { name, description, body } = parsed as Record<string, unknown>
+ const cleanDescription =
+ typeof description === 'string' ? description.trim().slice(0, SKILL_DESCRIPTION_MAX_LENGTH) : ''
+ const cleanBody = typeof body === 'string' ? body.trim().slice(0, MAX_BODY_LENGTH) : ''
+
+ // A link that prefills nothing but a name is indistinguishable from noise — require substance.
+ if (!cleanDescription && !cleanBody) {
+ return null
+ }
+
+ let cleanName = typeof name === 'string' ? name.trim() : ''
+ if (cleanName && !cleanName.startsWith(SIGNALS_SCOUT_SKILL_PREFIX)) {
+ cleanName = `${SIGNALS_SCOUT_SKILL_PREFIX}${cleanName}`
+ }
+ if (cleanName && validateSkillName(cleanName)) {
+ // Invalid name: drop it so the form's default prefix stands rather than the link failing.
+ cleanName = ''
+ }
+
+ return {
+ ...(cleanName ? { name: cleanName } : {}),
+ ...(cleanDescription ? { description: cleanDescription } : {}),
+ ...(cleanBody ? { body: cleanBody } : {}),
+ }
+}