Skip to content

Commit 27bc92f

Browse files
authored
Merge pull request #195 from aictrl-dev/chore/issue-189-remove-share
refactor(session): remove session sharing to opncd.ai (#189)
2 parents ac0550f + 9900ef0 commit 27bc92f

24 files changed

Lines changed: 344 additions & 584 deletions

‎.opencode/agent/translator.md‎

Lines changed: 0 additions & 5 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
@@ -444,13 +443,11 @@ aictrl.server.close()
444443
/session/:id/permissions/:permissionID
445444
/session/:id/prompt_async
446445
/session/:id/revert
447-
/session/:id/share
448446
/session/:id/shell
449447
/session/:id/summarize
450448
/session/:id/todo
451449
/session/:id/unrevert
452450
/session/status
453-
/share
454451
/summarize
455452
/theme
456453
/undo
@@ -494,7 +491,6 @@ aictrl.server.close()
494491
--prompt
495492
--refresh
496493
--session
497-
--share
498494
--title
499495
--token
500496
--tools
@@ -794,7 +790,6 @@ aictrl/gpt-5.1-codex
794790
aictrl/gpt-5.2-codex
795791
aictrl/kimi-k2
796792
openrouter/google/gemini-2.5-flash
797-
opncd.ai/s/<share-id>
798793
packages/*/AGENTS.md
799794
plugins/
800795
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"
12-
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-
}
11+
import { UI } from "../ui"
6512

6613
export const ImportCommand = cmd({
6714
command: "import <file>",
68-
describe: "import session data from JSON file or URL",
15+
describe: "import session data from a JSON file",
6916
builder: (yargs: Argv) => {
7017
return yargs.positional("file", {
71-
describe: "path to JSON file or share URL",
18+
describe: "path to JSON file",
7219
type: "string",
7320
demandOption: true,
7421
})
7522
},
7623
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-
}
24+
// Importing from a share URL was removed with session sharing (#189).
25+
if (args.file.startsWith("http://") || args.file.startsWith("https://")) {
26+
UI.error("Importing from a share URL was removed: session sharing is no longer supported")
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 === true) {
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(" ")
@@ -543,21 +547,6 @@ export const RunCommand = cmd({
543547
return result.data?.id
544548
}
545549

546-
async function share(sdk: any, sessionID: string) {
547-
const cfg = await sdk.config.get()
548-
if (!cfg.data) return
549-
if (cfg.data.share !== "auto" && !args.share) return
550-
const res = await sdk.session.share(input(sessionID)).catch((error: any) => {
551-
if (error instanceof Error && error.message.includes("disabled")) {
552-
UI.println(UI.Style.TEXT_DANGER_BOLD + "! " + error.message)
553-
}
554-
return { error }
555-
})
556-
if (!res.error && "data" in res && res.data?.share?.url) {
557-
UI.println(UI.Style.TEXT_INFO_BOLD + "~ " + res.data.share.url)
558-
}
559-
}
560-
561550
// Promise variable for racing against loopDone in execute().
562551
// Must be in handler() scope to be accessible by both the local SDK stub
563552
// (which writes to it inside bootstrap()) and execute() (which reads it).
@@ -975,7 +964,6 @@ export const RunCommand = cmd({
975964
await fail("Session not found", "INVOCATION_SESSION_CREATE_FAILED")
976965
}
977966
invocation.link(sessionID)
978-
await share(sdk, sessionID)
979967

980968
emit("session_start", {
981969
schemaVersion: SCHEMA_VERSION,
@@ -1157,10 +1145,6 @@ export const RunCommand = cmd({
11571145
})
11581146
return { data: session }
11591147
},
1160-
async share(opts: any) {
1161-
const share = await Session.share(opts.sessionID)
1162-
return { data: { share } }
1163-
},
11641148
abort(opts: any) {
11651149
return SessionPrompt.cancel(opts.sessionID)
11661150
},
@@ -1186,11 +1170,6 @@ export const RunCommand = cmd({
11861170
})
11871171
},
11881172
},
1189-
config: {
1190-
async get() {
1191-
return { data: await Config.get() }
1192-
},
1193-
},
11941173
event: {
11951174
async subscribe(opts: { signal: AbortSignal }) {
11961175
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 }
@@ -781,8 +773,6 @@ export namespace Config {
781773
stash_delete: z.string().optional().default("ctrl+d").describe("Delete stash entry"),
782774
model_provider_list: z.string().optional().default("ctrl+a").describe("Open provider list from model dialog"),
783775
model_favorite_toggle: z.string().optional().default("ctrl+f").describe("Toggle model favorite status"),
784-
session_share: z.string().optional().default("none").describe("Share current session"),
785-
session_unshare: z.string().optional().default("none").describe("Unshare current session"),
786776
session_interrupt: z.string().optional().default("escape").describe("Interrupt current session"),
787777
session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
788778
messages_page_up: z.string().optional().default("pageup,ctrl+alt+b").describe("Scroll messages up by one page"),
@@ -1009,16 +999,8 @@ export namespace Config {
1009999
.boolean()
10101000
.optional()
10111001
.describe("@deprecated Worktree snapshots were removed; this key is accepted and ignored."),
1012-
share: z
1013-
.enum(["manual", "auto", "disabled"])
1014-
.optional()
1015-
.describe(
1016-
"Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing",
1017-
),
1018-
autoshare: z
1019-
.boolean()
1020-
.optional()
1021-
.describe("@deprecated Use 'share' field instead. Share newly created sessions automatically"),
1002+
share: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
1003+
autoshare: z.unknown().optional().describe("@deprecated Session sharing was removed; this key is ignored."),
10221004
autoupdate: z
10231005
.union([z.boolean(), z.literal("notify")])
10241006
.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)