Skip to content

Commit 4e3ba7e

Browse files
byapparovclaude
andcommitted
refactor(session): remove session sharing to opncd.ai (#189)
Session sharing synced session content (messages, parts, diffs, models) to upstream opencode's share service at https://opncd.ai. A headless engine must not send session content to a third-party endpoint, so the subsystem is removed rather than disabled. Removed: - src/share/ (ShareNext sync client and the session_share table definition) - ShareNext.init in instance bootstrap - Session.share/unshare, the share field on Session.Info, auto-share on create - run's local SDK share/config stubs and share URL printing - import from a share URL; pr's opncd.ai session-link import - github run share handling and the action's `share` input - AICTRL_DISABLE_SHARE, the share/autoshare/enterprise config schema and the session_share/session_unshare keybinds - json-migration of legacy session_share files Compatibility: - config `share`, `autoshare` and `enterprise` still load as no-ops with one warning per config file - `aictrl run --share` fails with INVOCATION_INVALID_ARGUMENTS before any model request - `aictrl import <url>` fails with a "was removed" error and makes no request - stored share metadata (session.share_url, session_share rows) is left in place and ignored; such sessions still continue with --continue Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f30eda8 commit 4e3ba7e

23 files changed

Lines changed: 319 additions & 592 deletions

‎.opencode/agent/translator.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ aictrl auth logout
340340
aictrl auth ls
341341
aictrl export [sessionID]
342342
aictrl import <file>
343-
aictrl import https://opncd.ai/s/abc123
344343
aictrl import session.json
345344
aictrl mcp [command]
346345
aictrl mcp add
@@ -494,7 +493,6 @@ aictrl.server.close()
494493
--prompt
495494
--refresh
496495
--session
497-
--share
498496
--title
499497
--token
500498
--tools
@@ -797,7 +795,6 @@ aictrl/gpt-5.1-codex
797795
aictrl/gpt-5.2-codex
798796
aictrl/kimi-k2
799797
openrouter/google/gemini-2.5-flash
800-
opncd.ai/s/<share-id>
801798
packages/*/AGENTS.md
802799
plugins/
803800
project/

‎packages/cli/src/cli/cmd/import.ts‎

Lines changed: 16 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,40 @@
11
import type { Argv } from "yargs"
2-
import type { Session as SDKSession, Message, Part } from "@aictrl/sdk/v2"
2+
import type { Message, Part } from "@aictrl/sdk/v2"
33
import { Session } from "../../session"
44
import { cmd } from "./cmd"
55
import { bootstrap } from "../bootstrap"
66
import { Database } from "../../storage/db"
77
import { SessionTable, MessageTable, PartTable } from "../../session/session.sql"
88
import { Instance } from "../../project/instance"
9-
import { ShareNext } from "../../share/share-next"
109
import { EOL } from "os"
1110
import { Filesystem } from "../../util/filesystem"
1211

13-
/** Discriminated union returned by the ShareNext API (GET /api/share/:id/data) */
14-
export type ShareData =
15-
| { type: "session"; data: SDKSession }
16-
| { type: "message"; data: Message }
17-
| { type: "part"; data: Part }
18-
| { type: "session_diff"; data: unknown }
19-
| { type: "model"; data: unknown }
20-
21-
/** Extract share ID from a share URL like https://opncd.ai/share/abc123 */
22-
export function parseShareUrl(url: string): string | null {
23-
const match = url.match(/^https?:\/\/[^/]+\/share\/([a-zA-Z0-9_-]+)$/)
24-
return match ? match[1] : null
25-
}
26-
27-
/**
28-
* Transform ShareNext API response (flat array) into the nested structure for local file storage.
29-
*
30-
* The API returns a flat array: [session, message, message, part, part, ...]
31-
* Local storage expects: { info: session, messages: [{ info: message, parts: [part, ...] }, ...] }
32-
*
33-
* This groups parts by their messageID to reconstruct the hierarchy before writing to disk.
34-
*/
35-
export function transformShareData(shareData: ShareData[]): {
36-
info: SDKSession
37-
messages: Array<{ info: Message; parts: Part[] }>
38-
} | null {
39-
const sessionItem = shareData.find((d) => d.type === "session")
40-
if (!sessionItem) return null
41-
42-
const messageMap = new Map<string, Message>()
43-
const partMap = new Map<string, Part[]>()
44-
45-
for (const item of shareData) {
46-
if (item.type === "message") {
47-
messageMap.set(item.data.id, item.data)
48-
} else if (item.type === "part") {
49-
if (!partMap.has(item.data.messageID)) {
50-
partMap.set(item.data.messageID, [])
51-
}
52-
partMap.get(item.data.messageID)!.push(item.data)
53-
}
54-
}
55-
56-
if (messageMap.size === 0) return null
57-
58-
return {
59-
info: sessionItem.data,
60-
messages: Array.from(messageMap.values()).map((msg) => ({
61-
info: msg,
62-
parts: partMap.get(msg.id) ?? [],
63-
})),
64-
}
65-
}
66-
6712
export const ImportCommand = cmd({
6813
command: "import <file>",
69-
describe: "import session data from JSON file or URL",
14+
describe: "import session data from a JSON file",
7015
builder: (yargs: Argv) => {
7116
return yargs.positional("file", {
72-
describe: "path to JSON file or share URL",
17+
describe: "path to JSON file",
7318
type: "string",
7419
demandOption: true,
7520
})
7621
},
7722
handler: async (args) => {
78-
await bootstrap(process.cwd(), async () => {
79-
let exportData:
80-
| {
81-
info: Session.Info
82-
messages: Array<{
83-
info: Message
84-
parts: Part[]
85-
}>
86-
}
87-
| undefined
88-
89-
const isUrl = args.file.startsWith("http://") || args.file.startsWith("https://")
90-
91-
if (isUrl) {
92-
const slug = parseShareUrl(args.file)
93-
if (!slug) {
94-
const baseUrl = await ShareNext.url()
95-
process.stdout.write(`Invalid URL format. Expected: ${baseUrl}/share/<slug>`)
96-
process.stdout.write(EOL)
97-
return
98-
}
99-
100-
const baseUrl = await ShareNext.url()
101-
const response = await fetch(`${baseUrl}/api/share/${slug}/data`)
102-
103-
if (!response.ok) {
104-
process.stdout.write(`Failed to fetch share data: ${response.statusText}`)
105-
process.stdout.write(EOL)
106-
return
107-
}
108-
109-
const shareData: ShareData[] = await response.json()
110-
const transformed = transformShareData(shareData)
111-
112-
if (!transformed) {
113-
process.stdout.write(`Share not found or empty: ${slug}`)
114-
process.stdout.write(EOL)
115-
return
116-
}
117-
118-
exportData = transformed
119-
} else {
120-
exportData = await Filesystem.readJson<NonNullable<typeof exportData>>(args.file).catch(() => undefined)
121-
if (!exportData) {
122-
process.stdout.write(`File not found: ${args.file}`)
123-
process.stdout.write(EOL)
124-
return
125-
}
126-
}
23+
// Importing from a share URL was removed with session sharing (#189).
24+
if (args.file.startsWith("http://") || args.file.startsWith("https://")) {
25+
process.stdout.write(`Importing from a share URL was removed: session sharing is no longer supported`)
26+
process.stdout.write(EOL)
27+
process.exitCode = 1
28+
return
29+
}
12730

31+
await bootstrap(process.cwd(), async () => {
32+
const exportData = await Filesystem.readJson<{
33+
info: Session.Info
34+
messages: Array<{ info: Message; parts: Part[] }>
35+
}>(args.file).catch(() => undefined)
12836
if (!exportData) {
129-
process.stdout.write(`Failed to read session data`)
37+
process.stdout.write(`File not found: ${args.file}`)
13038
process.stdout.write(EOL)
13139
return
13240
}

‎packages/cli/src/cli/cmd/run.ts‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { Session } from "../../session"
2424
import type { MessageV2 } from "../../session/message-v2"
2525
import { SessionPrompt } from "../../session/prompt"
2626
import { Snapshot } from "../../snapshot"
27-
import { Config } from "../../config/config"
2827
import { GlobalBus } from "../../bus/global"
2928
import { Instance } from "../../project/instance"
3029
import { Tool } from "../../tool/tool"
@@ -362,9 +361,10 @@ export const RunCommand = cmd({
362361
describe: "fork the session before continuing (requires --continue or --session)",
363362
type: "boolean",
364363
})
364+
// Removed (#189); still parsed so the run can fail with a clear error.
365365
.option("share", {
366366
type: "boolean",
367-
describe: "share the session",
367+
hidden: true,
368368
})
369369
.option("model", {
370370
type: "string",
@@ -432,6 +432,10 @@ export const RunCommand = cmd({
432432
process.exit(exit)
433433
}
434434

435+
if (args.share !== undefined) {
436+
await fail("--share was removed: session sharing is no longer supported", "INVOCATION_INVALID_ARGUMENTS")
437+
}
438+
435439
let message = [...args.message, ...(args["--"] || [])]
436440
.map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg))
437441
.join(" ")
@@ -535,21 +539,6 @@ export const RunCommand = cmd({
535539
return result.data?.id
536540
}
537541

538-
async function share(sdk: any, sessionID: string) {
539-
const cfg = await sdk.config.get()
540-
if (!cfg.data) return
541-
if (cfg.data.share !== "auto" && !args.share) return
542-
const res = await sdk.session.share(input(sessionID)).catch((error: any) => {
543-
if (error instanceof Error && error.message.includes("disabled")) {
544-
UI.println(UI.Style.TEXT_DANGER_BOLD + "! " + error.message)
545-
}
546-
return { error }
547-
})
548-
if (!res.error && "data" in res && res.data?.share?.url) {
549-
UI.println(UI.Style.TEXT_INFO_BOLD + "~ " + res.data.share.url)
550-
}
551-
}
552-
553542
// Promise variable for racing against loopDone in execute().
554543
// Must be in handler() scope to be accessible by both the local SDK stub
555544
// (which writes to it inside bootstrap()) and execute() (which reads it).
@@ -967,7 +956,6 @@ export const RunCommand = cmd({
967956
await fail("Session not found", "INVOCATION_SESSION_CREATE_FAILED")
968957
}
969958
invocation.link(sessionID)
970-
await share(sdk, sessionID)
971959

972960
emit("session_start", {
973961
schemaVersion: SCHEMA_VERSION,
@@ -1152,10 +1140,6 @@ export const RunCommand = cmd({
11521140
})
11531141
return { data: session }
11541142
},
1155-
async share(opts: any) {
1156-
const share = await Session.share(opts.sessionID)
1157-
return { data: { share } }
1158-
},
11591143
abort(opts: any) {
11601144
return SessionPrompt.cancel(opts.sessionID)
11611145
},
@@ -1181,11 +1165,6 @@ export const RunCommand = cmd({
11811165
})
11821166
},
11831167
},
1184-
config: {
1185-
async get() {
1186-
return { data: await Config.get() }
1187-
},
1188-
},
11891168
event: {
11901169
async subscribe(opts: { signal: AbortSignal }) {
11911170
const queue: any[] = []

‎packages/cli/src/config/config.ts‎

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export namespace Config {
197197

198198
if (Flag.AICTRL_PERMISSION) {
199199
const permission = JSON.parse(Flag.AICTRL_PERMISSION)
200-
warnDeprecatedLsp({ permission }, "AICTRL_PERMISSION")
200+
warnRemovedKeys({ permission }, "AICTRL_PERMISSION")
201201
result.permission = mergeDeep(result.permission ?? {}, permission)
202202
}
203203

@@ -217,11 +217,6 @@ export namespace Config {
217217

218218
if (!result.username) result.username = os.userInfo().username
219219

220-
// Handle migration from autoshare to share field
221-
if (result.autoshare === true && !result.share) {
222-
result.share = "auto"
223-
}
224-
225220
// Apply flag overrides for compaction settings
226221
if (Flag.AICTRL_DISABLE_AUTOCOMPACT) {
227222
result.compaction = { ...result.compaction, auto: false }
@@ -773,8 +768,6 @@ export namespace Config {
773768
stash_delete: z.string().optional().default("ctrl+d").describe("Delete stash entry"),
774769
model_provider_list: z.string().optional().default("ctrl+a").describe("Open provider list from model dialog"),
775770
model_favorite_toggle: z.string().optional().default("ctrl+f").describe("Toggle model favorite status"),
776-
session_share: z.string().optional().default("none").describe("Share current session"),
777-
session_unshare: z.string().optional().default("none").describe("Unshare current session"),
778771
session_interrupt: z.string().optional().default("escape").describe("Interrupt current session"),
779772
session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
780773
messages_page_up: z.string().optional().default("pageup,ctrl+alt+b").describe("Scroll messages up by one page"),
@@ -999,16 +992,8 @@ export namespace Config {
999992
.optional(),
1000993
plugin: z.string().array().optional(),
1001994
snapshot: z.boolean().optional(),
1002-
share: z
1003-
.enum(["manual", "auto", "disabled"])
1004-
.optional()
1005-
.describe(
1006-
"Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing",
1007-
),
1008-
autoshare: z
1009-
.boolean()
1010-
.optional()
1011-
.describe("@deprecated Use 'share' field instead. Share newly created sessions automatically"),
995+
share: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
996+
autoshare: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
1012997
autoupdate: z
1013998
.union([z.boolean(), z.literal("notify")])
1014999
.optional()
@@ -1095,11 +1080,7 @@ export namespace Config {
10951080
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
10961081
permission: Permission.optional(),
10971082
tools: z.record(z.string(), z.boolean()).optional(),
1098-
enterprise: z
1099-
.object({
1100-
url: z.string().optional().describe("Enterprise URL"),
1101-
})
1102-
.optional(),
1083+
enterprise: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
11031084
compaction: z
11041085
.object({
11051086
auto: z.boolean().optional().describe("Enable automatic compaction when context is full (default: true)"),
@@ -1179,14 +1160,19 @@ export namespace Config {
11791160
return load(text, { path: filepath })
11801161
}
11811162

1182-
// The LSP subsystem was removed (#144). Configs written before then may still set the
1183-
// `lsp` block or an `lsp` permission rule. The schema accepts both as no-ops and keeps
1184-
// them, so rewriting a config file preserves them; each config file that sets one warns once.
1185-
function warnDeprecatedLsp(config: Record<string, unknown>, source: string) {
1186-
const permission = config.permission
1187-
const hasLspPermission = typeof permission === "object" && permission !== null && "lsp" in permission
1188-
if (!("lsp" in config) && !hasLspPermission) return
1189-
log.warn("lsp config is deprecated and ignored; the LSP subsystem was removed", { path: source })
1163+
// Config keys of subsystems that were removed: LSP (#144) and session sharing (#189;
1164+
// `enterprise.url` was the share service URL). The schema accepts them as no-ops and keeps
1165+
// them, so rewriting a config file preserves them; each config source that sets any warns once.
1166+
function removedKeys(config: Record<string, unknown>) {
1167+
const keys = ["lsp", "share", "autoshare", "enterprise"].filter((key) => key in config)
1168+
if (isRecord(config.permission) && "lsp" in config.permission) keys.push("permission.lsp")
1169+
return keys
1170+
}
1171+
1172+
function warnRemovedKeys(config: Record<string, unknown>, source: string) {
1173+
const keys = removedKeys(config)
1174+
if (keys.length === 0) return
1175+
log.warn(`deprecated config is ignored, its subsystem was removed: ${keys.join(", ")}`, { path: source })
11901176
}
11911177

11921178
async function load(text: string, options: { path: string } | { dir: string; source: string }) {
@@ -1201,7 +1187,7 @@ export namespace Config {
12011187
const normalized = (() => {
12021188
if (!data || typeof data !== "object" || Array.isArray(data)) return data
12031189
const copy = { ...(data as Record<string, unknown>) }
1204-
warnDeprecatedLsp(copy, source)
1190+
warnRemovedKeys(copy, source)
12051191
const hadLegacy = "theme" in copy || "keybinds" in copy || "tui" in copy
12061192
if (!hadLegacy) return copy
12071193
delete copy.theme

‎packages/cli/src/project/bootstrap.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import { Command } from "../command"
88
import { Instance } from "./instance"
99
import { Vcs } from "./vcs"
1010
import { Log } from "@/util/log"
11-
import { ShareNext } from "@/share/share-next"
1211
import { Snapshot } from "../snapshot"
1312
import { Truncate } from "../tool/truncation"
1413

1514
export async function InstanceBootstrap() {
1615
Log.Default.info("bootstrapping", { directory: Instance.directory })
1716
await Plugin.init()
18-
ShareNext.init()
1917
Format.init()
2018
FileWatcher.init()
2119
File.init()

0 commit comments

Comments
 (0)