MCPcopy Index your code
hub / github.com/anomalyco/opencode / session

Function session

packages/opencode/src/cli/cmd/run.ts:456–533  ·  view source on GitHub ↗
(sdk: OpencodeClient)

Source from the content-addressed store, hash-verified

454 }
455
456 async function session(sdk: OpencodeClient): Promise<SessionInfo | undefined> {
457 if (args.session) {
458 const current = await sdk.session
459 .get({
460 sessionID: args.session,
461 })
462 .catch(() => undefined)
463
464 if (!current?.data) {
465 UI.error("Session not found")
466 process.exit(1)
467 }
468
469 if (args.fork) {
470 const forked = await sdk.session.fork({
471 sessionID: args.session,
472 })
473 const id = forked.data?.id
474 if (!id) {
475 return
476 }
477
478 return {
479 id,
480 title: forked.data?.title ?? current.data.title,
481 directory: forked.data?.directory ?? current.data.directory,
482 }
483 }
484
485 return {
486 id: current.data.id,
487 title: current.data.title,
488 directory: current.data.directory,
489 }
490 }
491
492 const base = args.continue ? (await sdk.session.list()).data?.find((item) => !item.parentID) : undefined
493
494 if (base && args.fork) {
495 const forked = await sdk.session.fork({
496 sessionID: base.id,
497 })
498 const id = forked.data?.id
499 if (!id) {
500 return
501 }
502
503 return {
504 id,
505 title: forked.data?.title ?? base.title,
506 directory: forked.data?.directory ?? base.directory,
507 }
508 }
509
510 if (base) {
511 return {
512 id: base.id,
513 title: base.title,

Callers 1

executeFunction · 0.70

Calls 6

titleFunction · 0.70
getMethod · 0.65
findMethod · 0.65
listMethod · 0.65
createMethod · 0.65
forkMethod · 0.45

Tested by

no test coverage detected