Skip to content

Commit 8e0b26e

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 aa80ae1 commit 8e0b26e

23 files changed

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

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)
12736
if (!exportData) {
128-
process.stdout.write(`Failed to read session data`)
37+
process.stdout.write(`File not found: ${args.file}`)
12938
process.stdout.write(EOL)
13039
return
13140
}

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { PermissionNext } from "../../permission/next"
2323
import { Session } from "../../session"
2424
import type { MessageV2 } from "../../session/message-v2"
2525
import { SessionPrompt } from "../../session/prompt"
26-
import { Config } from "../../config/config"
2726
import { GlobalBus } from "../../bus/global"
2827
import { Instance } from "../../project/instance"
2928
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",
@@ -439,6 +439,10 @@ export const RunCommand = cmd({
439439
process.exit(exit)
440440
}
441441

442+
if (args.share !== undefined) {
443+
await fail("--share was removed: session sharing is no longer supported", "INVOCATION_INVALID_ARGUMENTS")
444+
}
445+
442446
let message = [...args.message, ...(args["--"] || [])]
443447
.map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg))
444448
.join(" ")
@@ -553,21 +557,6 @@ export const RunCommand = cmd({
553557
return result.data?.id
554558
}
555559

556-
async function share(sdk: any, sessionID: string) {
557-
const cfg = await sdk.config.get()
558-
if (!cfg.data) return
559-
if (cfg.data.share !== "auto" && !args.share) return
560-
const res = await sdk.session.share(input(sessionID)).catch((error: any) => {
561-
if (error instanceof Error && error.message.includes("disabled")) {
562-
UI.println(UI.Style.TEXT_DANGER_BOLD + "! " + error.message)
563-
}
564-
return { error }
565-
})
566-
if (!res.error && "data" in res && res.data?.share?.url) {
567-
UI.println(UI.Style.TEXT_INFO_BOLD + "~ " + res.data.share.url)
568-
}
569-
}
570-
571560
// Promise variable for racing against loopDone in execute().
572561
// Must be in handler() scope to be accessible by both the local SDK stub
573562
// (which writes to it inside bootstrap()) and execute() (which reads it).
@@ -985,7 +974,6 @@ export const RunCommand = cmd({
985974
await fail("Session not found", "INVOCATION_SESSION_CREATE_FAILED")
986975
}
987976
invocation.link(sessionID)
988-
await share(sdk, sessionID)
989977

990978
emit("session_start", {
991979
schemaVersion: SCHEMA_VERSION,
@@ -1167,10 +1155,6 @@ export const RunCommand = cmd({
11671155
})
11681156
return { data: session }
11691157
},
1170-
async share(opts: any) {
1171-
const share = await Session.share(opts.sessionID)
1172-
return { data: { share } }
1173-
},
11741158
abort(opts: any) {
11751159
return SessionPrompt.cancel(opts.sessionID)
11761160
},
@@ -1196,11 +1180,6 @@ export const RunCommand = cmd({
11961180
})
11971181
},
11981182
},
1199-
config: {
1200-
async get() {
1201-
return { data: await Config.get() }
1202-
},
1203-
},
12041183
event: {
12051184
async subscribe(opts: { signal: AbortSignal }) {
12061185
const queue: any[] = []

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

Lines changed: 19 additions & 35 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,14 +217,6 @@ export namespace Config {
217217

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

220-
// `snapshot` toggled the removed worktree snapshots (#181). It stays valid so old configs still load.
221-
if (result.snapshot !== undefined) log.warn("config key `snapshot` is deprecated and ignored")
222-
223-
// Handle migration from autoshare to share field
224-
if (result.autoshare === true && !result.share) {
225-
result.share = "auto"
226-
}
227-
228220
// Apply flag overrides for compaction settings
229221
if (Flag.AICTRL_DISABLE_AUTOCOMPACT) {
230222
result.compaction = { ...result.compaction, auto: false }
@@ -782,8 +774,6 @@ export namespace Config {
782774
stash_delete: z.string().optional().default("ctrl+d").describe("Delete stash entry"),
783775
model_provider_list: z.string().optional().default("ctrl+a").describe("Open provider list from model dialog"),
784776
model_favorite_toggle: z.string().optional().default("ctrl+f").describe("Toggle model favorite status"),
785-
session_share: z.string().optional().default("none").describe("Share current session"),
786-
session_unshare: z.string().optional().default("none").describe("Unshare current session"),
787777
session_interrupt: z.string().optional().default("escape").describe("Interrupt current session"),
788778
session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
789779
messages_page_up: z.string().optional().default("pageup,ctrl+alt+b").describe("Scroll messages up by one page"),
@@ -1011,16 +1001,8 @@ export namespace Config {
10111001
.boolean()
10121002
.optional()
10131003
.describe("@deprecated Worktree snapshots were removed; this key is accepted and ignored."),
1014-
share: z
1015-
.enum(["manual", "auto", "disabled"])
1016-
.optional()
1017-
.describe(
1018-
"Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing",
1019-
),
1020-
autoshare: z
1021-
.boolean()
1022-
.optional()
1023-
.describe("@deprecated Use 'share' field instead. Share newly created sessions automatically"),
1004+
share: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
1005+
autoshare: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
10241006
autoupdate: z
10251007
.union([z.boolean(), z.literal("notify")])
10261008
.optional()
@@ -1107,11 +1089,7 @@ export namespace Config {
11071089
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
11081090
permission: Permission.optional(),
11091091
tools: z.record(z.string(), z.boolean()).optional(),
1110-
enterprise: z
1111-
.object({
1112-
url: z.string().optional().describe("Enterprise URL"),
1113-
})
1114-
.optional(),
1092+
enterprise: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
11151093
compaction: z
11161094
.object({
11171095
auto: z.boolean().optional().describe("Enable automatic compaction when context is full (default: true)"),
@@ -1191,14 +1169,20 @@ export namespace Config {
11911169
return load(text, { path: filepath })
11921170
}
11931171

1194-
// The LSP subsystem was removed (#144). Configs written before then may still set the
1195-
// `lsp` block or an `lsp` permission rule. The schema accepts both as no-ops and keeps
1196-
// them, so rewriting a config file preserves them; each config file that sets one warns once.
1197-
function warnDeprecatedLsp(config: Record<string, unknown>, source: string) {
1198-
const permission = config.permission
1199-
const hasLspPermission = typeof permission === "object" && permission !== null && "lsp" in permission
1200-
if (!("lsp" in config) && !hasLspPermission) return
1201-
log.warn("lsp config is deprecated and ignored; the LSP subsystem was removed", { path: source })
1172+
// Config keys of subsystems that were removed: LSP (#144), worktree snapshots (#181) and
1173+
// session sharing (#189; `enterprise.url` was the share service URL). The schema accepts them
1174+
// as no-ops and keeps them, so rewriting a config file preserves them; each config source
1175+
// that sets any warns once.
1176+
function removedKeys(config: Record<string, unknown>) {
1177+
const keys = ["lsp", "snapshot", "share", "autoshare", "enterprise"].filter((key) => key in config)
1178+
if (isRecord(config.permission) && "lsp" in config.permission) keys.push("permission.lsp")
1179+
return keys
1180+
}
1181+
1182+
function warnRemovedKeys(config: Record<string, unknown>, source: string) {
1183+
const keys = removedKeys(config)
1184+
if (keys.length === 0) return
1185+
log.warn(`deprecated config is ignored, its subsystem was removed: ${keys.join(", ")}`, { path: source })
12021186
}
12031187

12041188
async function load(text: string, options: { path: string } | { dir: string; source: string }) {
@@ -1213,7 +1197,7 @@ export namespace Config {
12131197
const normalized = (() => {
12141198
if (!data || typeof data !== "object" || Array.isArray(data)) return data
12151199
const copy = { ...(data as Record<string, unknown>) }
1216-
warnDeprecatedLsp(copy, source)
1200+
warnRemovedKeys(copy, source)
12171201
const hadLegacy = "theme" in copy || "keybinds" in copy || "tui" in copy
12181202
if (!hadLegacy) return copy
12191203
delete copy.theme

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ 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 { Truncate } from "../tool/truncation"
1312

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

0 commit comments

Comments
 (0)