Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/opencode/src/cli/cmd/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export type ShareData =
| { type: "session_diff"; data: unknown }
| { type: "model"; data: unknown }

/** Extract share ID from a share URL like https://opncd.ai/share/abc123 */
/** Extract share ID from a share URL like https://opncd.ai/share/abc123 or https://opncd.ai/s/abc123 */
export function parseShareUrl(url: string): string | null {
const match = url.match(/^https?:\/\/[^/]+\/share\/([a-zA-Z0-9_-]+)$/)
const match = url.match(/^https?:\/\/[^/]+\/(?:share|s)\/([a-zA-Z0-9_-]+)$/)
return match ? match[1] : null
}

Expand Down Expand Up @@ -109,7 +109,7 @@ const runImport = Effect.fn("Cli.import.body")(function* (file: string, ctx: Ins
const slug = parseShareUrl(file)
if (!slug) {
const baseUrl = yield* Effect.orDie(share.url())
process.stdout.write(`Invalid URL format. Expected: ${baseUrl}/share/<slug>`)
process.stdout.write(`Invalid URL format. Expected: ${baseUrl}/share/<slug> or ${baseUrl}/s/<slug>`)
process.stdout.write(EOL)
return
}
Expand Down
5 changes: 4 additions & 1 deletion packages/opencode/test/cli/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import {
// parseShareUrl tests
test("parses valid share URLs", () => {
expect(parseShareUrl("https://opncd.ai/share/Jsj3hNIW")).toBe("Jsj3hNIW")
expect(parseShareUrl("https://opncd.ai/s/Jsj3hNIW")).toBe("Jsj3hNIW")
expect(parseShareUrl("https://custom.example.com/share/abc123")).toBe("abc123")
expect(parseShareUrl("https://custom.example.com/s/abc123")).toBe("abc123")
expect(parseShareUrl("http://localhost:3000/share/test_id-123")).toBe("test_id-123")
})

test("rejects invalid URLs", () => {
expect(parseShareUrl("https://opncd.ai/s/Jsj3hNIW")).toBeNull() // legacy format
expect(parseShareUrl("https://opncd.ai/share/")).toBeNull()
expect(parseShareUrl("https://opncd.ai/s/")).toBeNull()
expect(parseShareUrl("https://opncd.ai/share/id/extra")).toBeNull()
expect(parseShareUrl("https://opncd.ai/s/id/extra")).toBeNull()
expect(parseShareUrl("not-a-url")).toBeNull()
})

Expand Down
Loading