Skip to content

Commit 6761822

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 cd736e2 commit 6761822

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"
@@ -361,9 +360,10 @@ export const RunCommand = cmd({
361360
describe: "fork the session before continuing (requires --continue or --session)",
362361
type: "boolean",
363362
})
363+
// Removed (#189); still parsed so the run can fail with a clear error.
364364
.option("share", {
365365
type: "boolean",
366-
describe: "share the session",
366+
hidden: true,
367367
})
368368
.option("model", {
369369
type: "string",
@@ -431,6 +431,10 @@ export const RunCommand = cmd({
431431
process.exit(exit)
432432
}
433433

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

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

971959
emit("session_start", {
972960
schemaVersion: SCHEMA_VERSION,
@@ -1147,10 +1135,6 @@ export const RunCommand = cmd({
11471135
})
11481136
return { data: session }
11491137
},
1150-
async share(opts: any) {
1151-
const share = await Session.share(opts.sessionID)
1152-
return { data: { share } }
1153-
},
11541138
abort(opts: any) {
11551139
return SessionPrompt.cancel(opts.sessionID)
11561140
},
@@ -1176,11 +1160,6 @@ export const RunCommand = cmd({
11761160
})
11771161
},
11781162
},
1179-
config: {
1180-
async get() {
1181-
return { data: await Config.get() }
1182-
},
1183-
},
11841163
event: {
11851164
async subscribe(opts: { signal: AbortSignal }) {
11861165
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 }
@@ -776,8 +768,6 @@ export namespace Config {
776768
stash_delete: z.string().optional().default("ctrl+d").describe("Delete stash entry"),
777769
model_provider_list: z.string().optional().default("ctrl+a").describe("Open provider list from model dialog"),
778770
model_favorite_toggle: z.string().optional().default("ctrl+f").describe("Toggle model favorite status"),
779-
session_share: z.string().optional().default("none").describe("Share current session"),
780-
session_unshare: z.string().optional().default("none").describe("Unshare current session"),
781771
session_interrupt: z.string().optional().default("escape").describe("Interrupt current session"),
782772
session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
783773
messages_page_up: z.string().optional().default("pageup,ctrl+alt+b").describe("Scroll messages up by one page"),
@@ -1005,16 +995,8 @@ export namespace Config {
1005995
.boolean()
1006996
.optional()
1007997
.describe("@deprecated Worktree snapshots were removed; this key is accepted and ignored."),
1008-
share: z
1009-
.enum(["manual", "auto", "disabled"])
1010-
.optional()
1011-
.describe(
1012-
"Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing",
1013-
),
1014-
autoshare: z
1015-
.boolean()
1016-
.optional()
1017-
.describe("@deprecated Use 'share' field instead. Share newly created sessions automatically"),
998+
share: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
999+
autoshare: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
10181000
autoupdate: z
10191001
.union([z.boolean(), z.literal("notify")])
10201002
.optional()
@@ -1101,11 +1083,7 @@ export namespace Config {
11011083
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
11021084
permission: Permission.optional(),
11031085
tools: z.record(z.string(), z.boolean()).optional(),
1104-
enterprise: z
1105-
.object({
1106-
url: z.string().optional().describe("Enterprise URL"),
1107-
})
1108-
.optional(),
1086+
enterprise: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
11091087
compaction: z
11101088
.object({
11111089
auto: z.boolean().optional().describe("Enable automatic compaction when context is full (default: true)"),
@@ -1185,14 +1163,20 @@ export namespace Config {
11851163
return load(text, { path: filepath })
11861164
}
11871165

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

11981182
async function load(text: string, options: { path: string } | { dir: string; source: string }) {
@@ -1207,7 +1191,7 @@ export namespace Config {
12071191
const normalized = (() => {
12081192
if (!data || typeof data !== "object" || Array.isArray(data)) return data
12091193
const copy = { ...(data as Record<string, unknown>) }
1210-
warnDeprecatedLsp(copy, source)
1194+
warnRemovedKeys(copy, source)
12111195
const hadLegacy = "theme" in copy || "keybinds" in copy || "tui" in copy
12121196
if (!hadLegacy) return copy
12131197
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)