File size: 2,734 Bytes
68d7816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { PRIMARY_SUBAGENT_MODEL_CHOICE, type SubagentModelSource } from './configSection';

export const DEFAULT_PROFILE_NAME = 'coder';

export const FORK_WITH_RESUME_UNAVAILABLE =
  'Cannot set resume when forking the current context. Fork creates a new agent; resume continues an existing one.';
export const FORK_WITH_TYPE_UNAVAILABLE =
  'Cannot set a different subagent_type when forking the current context. A fork inherits this agent\'s own agent type.';
export const FORK_WITH_MODEL_UNAVAILABLE =
  'Cannot override the model when forking the current context. A fork inherits this agent\'s model.';
export const FORK_EXPERIMENTAL_UNAVAILABLE =
  'fork is disabled: the subagent_fork experimental flag is off.';
export const FORK_CONTEXT_NOTICE =
  'The conversation above is not your own history: it is a one-time snapshot inherited from the agent that forked you. Treat it as reference material only — you are an independent subagent, not a continuation of that agent. Do the task below directly yourself, then report the result.';

export interface ForkCompatibilityArgs {
  readonly resume?: string;
  readonly subagent_type?: string;
  readonly model?: string;
}

export function forkIncompatibility(
  args: ForkCompatibilityArgs,
  own: { readonly profileName?: string; readonly modelAlias?: string },
): string | undefined {
  const resumeAgentId = args.resume?.trim();
  if (resumeAgentId !== undefined && resumeAgentId.length > 0) {
    return FORK_WITH_RESUME_UNAVAILABLE;
  }
  const requestedProfileName =
    args.subagent_type !== undefined && args.subagent_type.length > 0
      ? args.subagent_type
      : undefined;
  if (requestedProfileName !== undefined && requestedProfileName !== own.profileName) {
    return FORK_WITH_TYPE_UNAVAILABLE;
  }
  if (
    args.model !== undefined &&
    args.model !== PRIMARY_SUBAGENT_MODEL_CHOICE &&
    args.model !== own.modelAlias
  ) {
    return FORK_WITH_MODEL_UNAVAILABLE;
  }
  return undefined;
}

export interface SubagentSpawnPlanInput {
  readonly callerAgentId: string;
  readonly profileName?: string;
  readonly model?: string;
  readonly fork?: boolean;
}

export interface SubagentSpawnPlan {
  readonly profileName: string;
  readonly model: string;
  readonly modelSource?: SubagentModelSource;
  readonly thinking?: string;
  readonly fork: boolean;
}

export interface SpawnSubagentOptions {
  readonly callerAgentId: string;
  readonly plan: SubagentSpawnPlan;
  readonly labels?: Readonly<Record<string, string>>;
  readonly prompt: string;
}

export interface SpawnedSubagent {
  readonly agentId: string;
  readonly profileName: string;
  readonly model: string;
  readonly modelSource?: SubagentModelSource;
  readonly promptText: string;
}