genaicode 2.33.0 → 2.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/README.md +1 -0
  2. package/dist/agents/artifacts.d.ts +1 -1
  3. package/dist/agents/artifacts.js +4 -65
  4. package/dist/agents/artifacts.js.map +1 -1
  5. package/dist/agents/cli-agent.d.ts +3 -0
  6. package/dist/agents/cli-agent.js +1 -0
  7. package/dist/agents/cli-agent.js.map +1 -1
  8. package/dist/agents/drivers/anthropic-managed.d.ts +145 -0
  9. package/dist/agents/drivers/anthropic-managed.js +799 -0
  10. package/dist/agents/drivers/anthropic-managed.js.map +1 -0
  11. package/dist/agents/drivers/antigravity.js +2 -0
  12. package/dist/agents/drivers/antigravity.js.map +1 -1
  13. package/dist/agents/drivers/claude.js +2 -0
  14. package/dist/agents/drivers/claude.js.map +1 -1
  15. package/dist/agents/drivers/codex-live.js +2 -0
  16. package/dist/agents/drivers/codex-live.js.map +1 -1
  17. package/dist/agents/drivers/codex.js +2 -0
  18. package/dist/agents/drivers/codex.js.map +1 -1
  19. package/dist/agents/drivers/copilot.js +2 -0
  20. package/dist/agents/drivers/copilot.js.map +1 -1
  21. package/dist/agents/drivers/cursor-cloud.d.ts +78 -0
  22. package/dist/agents/drivers/cursor-cloud.js +523 -0
  23. package/dist/agents/drivers/cursor-cloud.js.map +1 -0
  24. package/dist/agents/drivers/cursor.js +2 -0
  25. package/dist/agents/drivers/cursor.js.map +1 -1
  26. package/dist/agents/drivers/gemini-managed.d.ts +78 -0
  27. package/dist/agents/drivers/gemini-managed.js +528 -0
  28. package/dist/agents/drivers/gemini-managed.js.map +1 -0
  29. package/dist/agents/drivers/gemini.js +2 -0
  30. package/dist/agents/drivers/gemini.js.map +1 -1
  31. package/dist/agents/drivers/managed-http.d.ts +28 -0
  32. package/dist/agents/drivers/managed-http.js +142 -0
  33. package/dist/agents/drivers/managed-http.js.map +1 -0
  34. package/dist/agents/drivers/muse-live.js +2 -0
  35. package/dist/agents/drivers/muse-live.js.map +1 -1
  36. package/dist/agents/drivers/muse.js +2 -0
  37. package/dist/agents/drivers/muse.js.map +1 -1
  38. package/dist/agents/drivers/openai-managed.d.ts +79 -0
  39. package/dist/agents/drivers/openai-managed.js +404 -0
  40. package/dist/agents/drivers/openai-managed.js.map +1 -0
  41. package/dist/agents/drivers/opencode.js +2 -0
  42. package/dist/agents/drivers/opencode.js.map +1 -1
  43. package/dist/agents/drivers/vibe.js +2 -0
  44. package/dist/agents/drivers/vibe.js.map +1 -1
  45. package/dist/agents/failover.d.ts +19 -1
  46. package/dist/agents/failover.js +63 -2
  47. package/dist/agents/failover.js.map +1 -1
  48. package/dist/agents/hosted.d.ts +5 -1
  49. package/dist/agents/hosted.js +47 -132
  50. package/dist/agents/hosted.js.map +1 -1
  51. package/dist/agents/live-agent.d.ts +3 -0
  52. package/dist/agents/live-agent.js +1 -0
  53. package/dist/agents/live-agent.js.map +1 -1
  54. package/dist/agents/managed.d.ts +157 -0
  55. package/dist/agents/managed.js +562 -0
  56. package/dist/agents/managed.js.map +1 -0
  57. package/dist/agents/mcp-server.d.ts +19 -0
  58. package/dist/agents/mcp-server.js +74 -0
  59. package/dist/agents/mcp-server.js.map +1 -0
  60. package/dist/agents/pack-git.d.ts +23 -0
  61. package/dist/agents/pack-git.js +112 -0
  62. package/dist/agents/pack-git.js.map +1 -0
  63. package/dist/agents/pack.d.ts +68 -0
  64. package/dist/agents/pack.js +611 -0
  65. package/dist/agents/pack.js.map +1 -0
  66. package/dist/agents/runtime.d.ts +5 -1
  67. package/dist/agents/runtime.js +9 -0
  68. package/dist/agents/runtime.js.map +1 -1
  69. package/dist/agents/session.d.ts +10 -0
  70. package/dist/agents/session.js +26 -0
  71. package/dist/agents/session.js.map +1 -1
  72. package/dist/agents/sessions/claude.d.ts +14 -0
  73. package/dist/agents/sessions/claude.js +233 -0
  74. package/dist/agents/sessions/claude.js.map +1 -0
  75. package/dist/agents/sessions/codex-api.d.ts +32 -0
  76. package/dist/agents/sessions/codex-api.js +233 -0
  77. package/dist/agents/sessions/codex-api.js.map +1 -0
  78. package/dist/agents/sessions/codex.d.ts +28 -0
  79. package/dist/agents/sessions/codex.js +430 -0
  80. package/dist/agents/sessions/codex.js.map +1 -0
  81. package/dist/agents/sessions/doctor.d.ts +67 -0
  82. package/dist/agents/sessions/doctor.js +182 -0
  83. package/dist/agents/sessions/doctor.js.map +1 -0
  84. package/dist/agents/sessions/files.d.ts +44 -0
  85. package/dist/agents/sessions/files.js +150 -0
  86. package/dist/agents/sessions/files.js.map +1 -0
  87. package/dist/agents/sessions/group.d.ts +24 -0
  88. package/dist/agents/sessions/group.js +27 -0
  89. package/dist/agents/sessions/group.js.map +1 -0
  90. package/dist/agents/sessions/hooks.d.ts +32 -0
  91. package/dist/agents/sessions/hooks.js +155 -0
  92. package/dist/agents/sessions/hooks.js.map +1 -0
  93. package/dist/agents/sessions/index.d.ts +42 -0
  94. package/dist/agents/sessions/index.js +97 -0
  95. package/dist/agents/sessions/index.js.map +1 -0
  96. package/dist/agents/sessions/live.d.ts +67 -0
  97. package/dist/agents/sessions/live.js +308 -0
  98. package/dist/agents/sessions/live.js.map +1 -0
  99. package/dist/agents/sessions/sqlite.d.ts +12 -0
  100. package/dist/agents/sessions/sqlite.js +61 -0
  101. package/dist/agents/sessions/sqlite.js.map +1 -0
  102. package/dist/agents/sessions/stores.d.ts +38 -0
  103. package/dist/agents/sessions/stores.js +616 -0
  104. package/dist/agents/sessions/stores.js.map +1 -0
  105. package/dist/agents/sessions/transcript.d.ts +20 -0
  106. package/dist/agents/sessions/transcript.js +134 -0
  107. package/dist/agents/sessions/transcript.js.map +1 -0
  108. package/dist/agents/sessions/types.d.ts +95 -0
  109. package/dist/agents/sessions/types.js +2 -0
  110. package/dist/agents/sessions/types.js.map +1 -0
  111. package/dist/agents/types.d.ts +31 -0
  112. package/dist/agents.d.ts +17 -1
  113. package/dist/agents.js +9 -1
  114. package/dist/agents.js.map +1 -1
  115. package/dist/backend/backend.d.ts +131 -0
  116. package/dist/backend/backend.js +773 -0
  117. package/dist/backend/backend.js.map +1 -0
  118. package/dist/backend/limiter.d.ts +34 -0
  119. package/dist/backend/limiter.js +76 -0
  120. package/dist/backend/limiter.js.map +1 -0
  121. package/dist/backend/node.d.ts +10 -0
  122. package/dist/backend/node.js +124 -0
  123. package/dist/backend/node.js.map +1 -0
  124. package/dist/backend/protocol.d.ts +98 -0
  125. package/dist/backend/protocol.js +2 -0
  126. package/dist/backend/protocol.js.map +1 -0
  127. package/dist/backend/seal.d.ts +7 -0
  128. package/dist/backend/seal.js +60 -0
  129. package/dist/backend/seal.js.map +1 -0
  130. package/dist/backend.d.ts +27 -0
  131. package/dist/backend.js +25 -0
  132. package/dist/backend.js.map +1 -0
  133. package/dist/browser/invoke.d.ts +17 -0
  134. package/dist/browser/invoke.js +69 -0
  135. package/dist/browser/invoke.js.map +1 -0
  136. package/dist/browser/nano.d.ts +10 -0
  137. package/dist/browser/nano.js +10 -56
  138. package/dist/browser/nano.js.map +1 -1
  139. package/dist/browser/page-agent.d.ts +7 -0
  140. package/dist/browser/page-agent.js +26 -5
  141. package/dist/browser/page-agent.js.map +1 -1
  142. package/dist/browser/remote.d.ts +44 -0
  143. package/dist/browser/remote.js +372 -0
  144. package/dist/browser/remote.js.map +1 -0
  145. package/dist/browser.d.ts +9 -2
  146. package/dist/browser.js +8 -2
  147. package/dist/browser.js.map +1 -1
  148. package/dist/cli/args.d.ts +26 -0
  149. package/dist/cli/args.js +66 -0
  150. package/dist/cli/args.js.map +1 -1
  151. package/dist/cli/hook.d.ts +7 -0
  152. package/dist/cli/hook.js +21 -0
  153. package/dist/cli/hook.js.map +1 -0
  154. package/dist/cli/main.d.ts +3 -1
  155. package/dist/cli/main.js +237 -2
  156. package/dist/cli/main.js.map +1 -1
  157. package/dist/cli.js +31 -21
  158. package/dist/cli.js.map +1 -1
  159. package/dist/core/types.d.ts +5 -0
  160. package/dist/core/types.js.map +1 -1
  161. package/dist/index.d.ts +1 -1
  162. package/dist/index.js +1 -1
  163. package/dist/index.js.map +1 -1
  164. package/dist/providers/google-converter.js +21 -8
  165. package/dist/providers/google-converter.js.map +1 -1
  166. package/dist/providers/google.js +7 -10
  167. package/dist/providers/google.js.map +1 -1
  168. package/dist/providers/openai-converter.js +3 -2
  169. package/dist/providers/openai-converter.js.map +1 -1
  170. package/dist/providers/openai-responses-converter.d.ts +35 -0
  171. package/dist/providers/openai-responses-converter.js +188 -0
  172. package/dist/providers/openai-responses-converter.js.map +1 -0
  173. package/dist/providers/openai.d.ts +6 -1
  174. package/dist/providers/openai.js +16 -1
  175. package/dist/providers/openai.js.map +1 -1
  176. package/dist/providers.d.ts +1 -0
  177. package/dist/providers.js +1 -0
  178. package/dist/providers.js.map +1 -1
  179. package/dist/react/page-agent-chat.js +6 -2
  180. package/dist/react/page-agent-chat.js.map +1 -1
  181. package/dist/ui/index.js +109 -82
  182. package/dist/ui/sessions.d.ts +19 -0
  183. package/dist/ui/sessions.js +59 -0
  184. package/dist/ui/sessions.js.map +1 -0
  185. package/dist/ui/web-client.js +15 -14
  186. package/docs/CHANGELOG.md +51 -388
  187. package/docs/agents.md +417 -2
  188. package/docs/backend.md +125 -0
  189. package/docs/browser.md +6 -1
  190. package/docs/changelog-2.26-and-older.md +441 -0
  191. package/docs/cli.md +39 -0
  192. package/docs/llm.md +6 -1
  193. package/docs/pivot.md +1 -1
  194. package/package.json +5 -1
@@ -0,0 +1,20 @@
1
+ import type { SessionTurn } from '../session.js';
2
+ import type { SessionReadOptions } from './types.js';
3
+ /** The JSON lines of the last megabytes of a transcript file. */
4
+ export declare function transcriptLines(file: string): Promise<unknown[]>;
5
+ /** The content of a zstd file, where this Node can read zstd (22.15 and later) and the file is not huge. */
6
+ export declare function zstdFile(file: string): Promise<Buffer | undefined>;
7
+ /** The JSON lines at the end of a transcript that is already in memory. */
8
+ export declare function linesOf(data: Buffer): unknown[];
9
+ /**
10
+ * Collects what a store's reader finds, in order, into turns the way `createAgentSession` keeps
11
+ * them. What comes before the first prompt (the cut of a long transcript) is left out.
12
+ */
13
+ export declare function transcriptBuilder(agent: string, options?: SessionReadOptions): {
14
+ prompt(text: string, at?: number): void;
15
+ text(text: string, at?: number): void;
16
+ tool(id: string | undefined, name: string, input: unknown, at?: number): void;
17
+ toolResult(id: string | undefined, output: string | undefined, isError?: boolean, at?: number): void;
18
+ /** The latest `maxTurns` turns, each ended: a session that was read is not running here. */
19
+ turns(): SessionTurn[];
20
+ };
@@ -0,0 +1,134 @@
1
+ import { promises as fs } from 'node:fs';
2
+ // The end of a long transcript is what the next agent needs; the start is left out.
3
+ const TAIL_BYTES = 8 * 1024 * 1024;
4
+ const MAX_COMPRESSED = 32 * 1024 * 1024;
5
+ /** The JSON lines of the last megabytes of a transcript file. */
6
+ export async function transcriptLines(file) {
7
+ const handle = await fs.open(file, 'r');
8
+ try {
9
+ const { size } = await handle.stat();
10
+ if (size <= TAIL_BYTES)
11
+ return parse((await handle.readFile('utf8')).split('\n'));
12
+ const tail = Buffer.alloc(TAIL_BYTES);
13
+ await handle.read(tail, 0, TAIL_BYTES, size - TAIL_BYTES);
14
+ // The cut falls inside a line.
15
+ return parse(tail.toString('utf8').split('\n').slice(1));
16
+ }
17
+ finally {
18
+ await handle.close();
19
+ }
20
+ }
21
+ /** The content of a zstd file, where this Node can read zstd (22.15 and later) and the file is not huge. */
22
+ export async function zstdFile(file) {
23
+ const zlib = (await import('node:zlib'));
24
+ const decompress = zlib.zstdDecompress;
25
+ if (!decompress)
26
+ return undefined;
27
+ const handle = await fs.open(file, 'r');
28
+ let data;
29
+ try {
30
+ if ((await handle.stat()).size > MAX_COMPRESSED)
31
+ return undefined;
32
+ data = await handle.readFile();
33
+ }
34
+ finally {
35
+ await handle.close();
36
+ }
37
+ return new Promise((resolve, reject) => decompress(data, (error, out) => (error ? reject(error) : resolve(out))));
38
+ }
39
+ /** The JSON lines at the end of a transcript that is already in memory. */
40
+ export function linesOf(data) {
41
+ if (data.length <= TAIL_BYTES)
42
+ return parse(data.toString('utf8').split('\n'));
43
+ return parse(data
44
+ .subarray(data.length - TAIL_BYTES)
45
+ .toString('utf8')
46
+ .split('\n')
47
+ .slice(1));
48
+ }
49
+ function parse(lines) {
50
+ const values = [];
51
+ for (const line of lines) {
52
+ if (!line.trim())
53
+ continue;
54
+ try {
55
+ values.push(JSON.parse(line));
56
+ }
57
+ catch {
58
+ // A half-written last line.
59
+ }
60
+ }
61
+ return values;
62
+ }
63
+ /**
64
+ * Collects what a store's reader finds, in order, into turns the way `createAgentSession` keeps
65
+ * them. What comes before the first prompt (the cut of a long transcript) is left out.
66
+ */
67
+ export function transcriptBuilder(agent, options = {}) {
68
+ const maxToolOutput = options.maxToolOutput ?? 4_000;
69
+ const turns = [];
70
+ const tools = new Map();
71
+ let current;
72
+ let clock = 0;
73
+ const tick = (at) => {
74
+ if (at !== undefined)
75
+ clock = at;
76
+ if (current)
77
+ current.endedAt = clock;
78
+ };
79
+ return {
80
+ prompt(text, at) {
81
+ if (at !== undefined)
82
+ clock = at;
83
+ current = { id: turns.length + 1, agent, prompt: text, entries: [], startedAt: clock, endedAt: clock };
84
+ turns.push(current);
85
+ },
86
+ text(text, at) {
87
+ if (!current || !text.trim())
88
+ return;
89
+ current.entries.push({ kind: 'text', text, streaming: false });
90
+ tick(at);
91
+ },
92
+ tool(id, name, input, at) {
93
+ if (!current)
94
+ return;
95
+ const entry = { kind: 'tool', ...(id ? { id } : {}), name, input, done: false };
96
+ current.entries.push(entry);
97
+ if (id)
98
+ tools.set(id, entry);
99
+ tick(at);
100
+ },
101
+ toolResult(id, output, isError, at) {
102
+ const entry = id ? tools.get(id) : undefined;
103
+ if (!entry)
104
+ return;
105
+ if (output !== undefined) {
106
+ entry.output = output.length <= maxToolOutput ? output : `${output.slice(0, maxToolOutput)}\n… (truncated)`;
107
+ }
108
+ if (isError)
109
+ entry.isError = true;
110
+ entry.done = true;
111
+ tick(at);
112
+ },
113
+ /** The latest `maxTurns` turns, each ended: a session that was read is not running here. */
114
+ turns() {
115
+ const kept = turns.slice(-(options.maxTurns ?? 100));
116
+ return kept.map((turn, index) => {
117
+ const last = turn.entries.findLast((entry) => entry.kind === 'text');
118
+ return {
119
+ ...turn,
120
+ id: index + 1,
121
+ entries: turn.entries.map((entry) => (entry.kind === 'tool' ? { ...entry, done: true } : entry)),
122
+ result: {
123
+ status: 'completed',
124
+ ok: true,
125
+ exitCode: null,
126
+ signal: null,
127
+ ...(last?.kind === 'text' ? { text: last.text.trim() } : {}),
128
+ },
129
+ };
130
+ });
131
+ },
132
+ };
133
+ }
134
+ //# sourceMappingURL=transcript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../../src/agents/sessions/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AAIzC,oFAAoF;AACpF,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACnC,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAExC,iEAAiE;AACjE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,IAAI,IAAI,UAAU;YAAE,OAAO,KAAK,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAClF,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACtC,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,GAAG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,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC7D;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,95 @@
1
+ import type { TokenUsage } from '../../core/types.js';
2
+ import type { SessionTurn } from '../session.js';
3
+ /**
4
+ * - `active`: written to in the last couple of minutes; an agent is probably working in it.
5
+ * - `waiting`: the agent had the last word; the next move is the user's.
6
+ * - `unfinished`: it stops at the user's message or in the middle of the agent's work.
7
+ */
8
+ export type SessionActivity = 'active' | 'waiting' | 'unfinished';
9
+ /** One conversation with a coding agent, wherever the agent keeps it. */
10
+ export interface SessionInfo {
11
+ /** The `SessionSource` that found it. */
12
+ source: string;
13
+ /** The `genaicode/agents` driver name that can continue it (`claude`, `codex`...). */
14
+ agent: string;
15
+ /** The agent's own session id: what `AgentTask.resume` takes. */
16
+ id: string;
17
+ where: 'local' | 'cloud';
18
+ /** Directory the session works in (local), or the repository it works on (cloud). */
19
+ cwd?: string;
20
+ repository?: string;
21
+ branch?: string;
22
+ /** The agent's or the user's name for it, when there is one. */
23
+ title?: string;
24
+ /** The first and the latest thing the user asked. */
25
+ firstPrompt?: string;
26
+ lastPrompt?: string;
27
+ /** The end of the agent's latest message. */
28
+ lastReply?: string;
29
+ startedAt?: number;
30
+ /** Last activity, epoch milliseconds. */
31
+ updatedAt: number;
32
+ state?: SessionActivity;
33
+ /**
34
+ * What a `waiting` session waits for, where the agent's hooks report it (`genaicode hooks
35
+ * install`): `approval` when it asked whether it may use a tool, `reply` when its turn is over.
36
+ */
37
+ waitingFor?: 'approval' | 'reply';
38
+ /** The tool it asks to use, while `waitingFor` is `approval`. */
39
+ waitingTool?: string;
40
+ model?: string;
41
+ usage?: TokenUsage;
42
+ costUsd?: number;
43
+ /** The file holding it (local). */
44
+ path?: string;
45
+ /** Where to open it in a browser (cloud). */
46
+ url?: string;
47
+ }
48
+ export interface SessionQuery {
49
+ /** Only sessions active at or after this time, epoch milliseconds. */
50
+ since?: number;
51
+ /** Only sessions in this directory or below it. */
52
+ cwd?: string;
53
+ /** At most this many, newest first. */
54
+ limit?: number;
55
+ /** Environment that says where the stores are (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `HOME`). Default `process.env`. */
56
+ env?: NodeJS.ProcessEnv;
57
+ /** `false`: leave out what the agents' hooks reported (`listSessions()` adds it by default). */
58
+ live?: boolean;
59
+ signal?: AbortSignal;
60
+ }
61
+ /** A place sessions are kept: an agent's local store, or a vendor's cloud. */
62
+ export interface SessionSource {
63
+ name: string;
64
+ where: 'local' | 'cloud';
65
+ /**
66
+ * The version of the agent's CLI whose store this source was last checked against. A newer CLI
67
+ * may keep its sessions differently: `checkSessions()` says whether the source still reads them.
68
+ */
69
+ verified?: string;
70
+ /**
71
+ * The same sessions asked of the agent itself, where it can be asked (Codex's app server):
72
+ * `checkSessions({ reference: true })` compares them with what `list()` reads. Undefined when
73
+ * the agent is not installed or does not answer.
74
+ */
75
+ reference?(query?: SessionQuery): Promise<SessionInfo[] | undefined>;
76
+ /** Newest first. Rejects when the store cannot be read at all; a missing store is an empty list. */
77
+ list(query?: SessionQuery): Promise<SessionInfo[]>;
78
+ /**
79
+ * Sessions whose id is `id` or starts with it, for stores where that is quicker than listing
80
+ * everything (`findSession()` uses it when present).
81
+ */
82
+ find?(id: string, query?: SessionQuery): Promise<SessionInfo[]>;
83
+ /**
84
+ * What was said in a session this source listed, as turns `AgentSession.adopt()` takes: prompts,
85
+ * the agent's messages and tool calls, oldest first. Only the end of a very long one is read.
86
+ * Absent where the store's conversations cannot be read (yet).
87
+ */
88
+ read?(session: SessionInfo, options?: SessionReadOptions): Promise<SessionTurn[]>;
89
+ }
90
+ export interface SessionReadOptions {
91
+ /** At most this many turns, the latest ones. Default 100. */
92
+ maxTurns?: number;
93
+ /** Tool output longer than this is cut. Default 4000 characters. */
94
+ maxToolOutput?: number;
95
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/agents/sessions/types.ts"],"names":[],"mappings":""}
@@ -1,4 +1,5 @@
1
1
  import type { TokenUsage } from '../core/types.js';
2
+ import type { SessionSource } from './sessions/types.js';
2
3
  /**
3
4
  * One unit of work handed to a coding agent: a prompt and the directory it may edit.
4
5
  *
@@ -211,6 +212,30 @@ export type AgentEvent = {
211
212
  from: string;
212
213
  to: string;
213
214
  failure: AgentFailure;
215
+ }
216
+ /** `pack()`: the lead handed `prompt` to another agent. `cwd` is where that agent works. */
217
+ | {
218
+ type: 'subtask-start';
219
+ id: string;
220
+ agent: string;
221
+ prompt: string;
222
+ cwd: string;
223
+ mode: 'worktree' | 'shared';
224
+ }
225
+ /** `pack()`: an event of a delegated task. Its `done` event ends the task. */
226
+ | {
227
+ type: 'subtask';
228
+ id: string;
229
+ agent: string;
230
+ event: AgentEvent;
231
+ }
232
+ /** `pack()`: a delegated task's changes were merged into the working directory, or dropped. */
233
+ | {
234
+ type: 'subtask-update';
235
+ id: string;
236
+ agent: string;
237
+ state: 'merged' | 'discarded';
238
+ paths?: string[];
214
239
  } | {
215
240
  type: 'error';
216
241
  message: string;
@@ -297,5 +322,11 @@ export interface CodingAgent {
297
322
  /** Executable looked up on PATH (or an absolute path). */
298
323
  readonly command: string;
299
324
  readonly capabilities: AgentCapabilities;
325
+ /**
326
+ * Where the agent keeps its sessions, for `listSessions()`: a source that lists them, or `null`
327
+ * when it keeps none that can be read. Every genaicode driver says one or the other; absent on a
328
+ * custom driver means nobody looked.
329
+ */
330
+ readonly sessions?: SessionSource | null;
300
331
  run(task: AgentTask): AgentRun;
301
332
  }
package/dist/agents.d.ts CHANGED
@@ -31,6 +31,12 @@ export { PROVIDER_CREDENTIAL_VARS, scrubEnv, withoutProviderCredentials } from '
31
31
  export type { ScrubEnvOptions } from './agents/env.js';
32
32
  export { runWithVerify } from './agents/verify.js';
33
33
  export { describeFailover, shouldFailOver, withFallback } from './agents/failover.js';
34
+ export { pack } from './agents/pack.js';
35
+ export type { Pack, PackMember, PackOptions, PackTask, PackTaskStatus } from './agents/pack.js';
36
+ export { startLocalMcpServer } from './agents/mcp-server.js';
37
+ export type { LocalMcpServer, LocalMcpServerOptions } from './agents/mcp-server.js';
38
+ export { agentSessionSources, antigravitySessions, claudeSessions, codexSessions, copilotSessions, cursorSessions, geminiSessions, museSessions, vibeSessions, groupSessions, listSessions, readClaudeSession, readCodexSession, claudeTranscript, codexTranscript, antigravityTranscript, copilotTranscript, geminiTranscript, museTranscript, vibeTranscript, findSession, readSession, HOOK_AGENTS, hookCommand, hooksFile, hooksStatus, installHooks, uninstallHooks, liveDir, liveEvent, readLive, recordHook, withLive, checkSessions, cliVersion, codexThreads, codexTurns, openCodexServer, readCodexThread, } from './agents/sessions/index.js';
39
+ export type { ClaudeSessionsOptions, CodexSessionsOptions, SessionInfo, SessionListing, SessionProject, SessionQuery, SessionReadOptions, SessionSource, SessionActivity, StoreOptions, HookAgent, HooksOptions, HooksStatus, LiveRecord, LiveState, SessionCheck, SessionCheckOptions, CodexServer, CodexServerOptions, CodexSessionsVia, } from './agents/sessions/index.js';
34
40
  export type { VerifyAttempt, VerifyLoopOptions, VerifyLoopResult, VerifyReport } from './agents/verify.js';
35
41
  export type { PrepareContext, PreparedRun } from './agents/prepare.js';
36
42
  export { claudeMcpConfig } from './agents/drivers/claude.js';
@@ -41,7 +47,17 @@ export { createCursorParser, cursor, cursorArgs, cursorPermissionFlags } from '.
41
47
  export type { CursorAgentOptions } from './agents/drivers/cursor.js';
42
48
  export { createOpencodeParser, opencode, opencodeArgs, opencodePermissionFlags } from './agents/drivers/opencode.js';
43
49
  export type { OpencodeAgentOptions } from './agents/drivers/opencode.js';
44
- export { hostedAgent } from './agents/hosted.js';
50
+ export { fromHosted, hostedAgent } from './agents/hosted.js';
51
+ export { anthropicManaged, anthropicManagedProvider } from './agents/drivers/anthropic-managed.js';
52
+ export type { AnthropicManagedAgentConfig, AnthropicManagedClient, AnthropicManagedEvent, AnthropicManagedModel, AnthropicManagedOptions, AnthropicManagedSession, AnthropicManagedToolHandler, } from './agents/drivers/anthropic-managed.js';
53
+ export { geminiManaged, geminiManagedProvider } from './agents/drivers/gemini-managed.js';
54
+ export type { GeminiInteraction, GeminiInteractionStep, GeminiManagedOptions, GeminiUsage, } from './agents/drivers/gemini-managed.js';
55
+ export { openaiManaged, openaiManagedProvider } from './agents/drivers/openai-managed.js';
56
+ export type { OpenAiManagedOptions, OpenAiResponse, OpenAiResponseItem, OpenAiUsage, } from './agents/drivers/openai-managed.js';
57
+ export { cursorCloud, cursorCloudProvider } from './agents/drivers/cursor-cloud.js';
58
+ export type { CursorAgent, CursorCloudOptions, CursorRun, CursorUsage } from './agents/drivers/cursor-cloud.js';
59
+ export { isManagedSettled, managedAgent } from './agents/managed.js';
60
+ export type { ManagedAgentOptions, ManagedCapabilities, ManagedEventPage, ManagedFile, ManagedProvider, ManagedSnapshot, ManagedStart, ManagedState, ManagedStopReason, ManagedUpdate, ManagedUsage, } from './agents/managed.js';
45
61
  export type { HostedAgentOptions, HostedAgentProvider, HostedPoll, HostedTaskRequest, HostedTaskState, } from './agents/hosted.js';
46
62
  export { copilot, copilotArgs, copilotMcpConfig, copilotPermissionFlags, createCopilotParser, } from './agents/drivers/copilot.js';
47
63
  export type { CopilotAgentOptions } from './agents/drivers/copilot.js';
package/dist/agents.js CHANGED
@@ -17,12 +17,20 @@ export { museLive, museNotification } from './agents/drivers/muse-live.js';
17
17
  export { PROVIDER_CREDENTIAL_VARS, scrubEnv, withoutProviderCredentials } from './agents/env.js';
18
18
  export { runWithVerify } from './agents/verify.js';
19
19
  export { describeFailover, shouldFailOver, withFallback } from './agents/failover.js';
20
+ export { pack } from './agents/pack.js';
21
+ export { startLocalMcpServer } from './agents/mcp-server.js';
22
+ export { agentSessionSources, antigravitySessions, claudeSessions, codexSessions, copilotSessions, cursorSessions, geminiSessions, museSessions, vibeSessions, groupSessions, listSessions, readClaudeSession, readCodexSession, claudeTranscript, codexTranscript, antigravityTranscript, copilotTranscript, geminiTranscript, museTranscript, vibeTranscript, findSession, readSession, HOOK_AGENTS, hookCommand, hooksFile, hooksStatus, installHooks, uninstallHooks, liveDir, liveEvent, readLive, recordHook, withLive, checkSessions, cliVersion, codexThreads, codexTurns, openCodexServer, readCodexThread, } from './agents/sessions/index.js';
20
23
  export { claudeMcpConfig } from './agents/drivers/claude.js';
21
24
  export { codexMcpOverrides } from './agents/drivers/codex.js';
22
25
  export { createGeminiParser, gemini, geminiArgs, geminiPermissionFlags } from './agents/drivers/gemini.js';
23
26
  export { createCursorParser, cursor, cursorArgs, cursorPermissionFlags } from './agents/drivers/cursor.js';
24
27
  export { createOpencodeParser, opencode, opencodeArgs, opencodePermissionFlags } from './agents/drivers/opencode.js';
25
- export { hostedAgent } from './agents/hosted.js';
28
+ export { fromHosted, hostedAgent } from './agents/hosted.js';
29
+ export { anthropicManaged, anthropicManagedProvider } from './agents/drivers/anthropic-managed.js';
30
+ export { geminiManaged, geminiManagedProvider } from './agents/drivers/gemini-managed.js';
31
+ export { openaiManaged, openaiManagedProvider } from './agents/drivers/openai-managed.js';
32
+ export { cursorCloud, cursorCloudProvider } from './agents/drivers/cursor-cloud.js';
33
+ export { isManagedSettled, managedAgent } from './agents/managed.js';
26
34
  export { copilot, copilotArgs, copilotMcpConfig, copilotPermissionFlags, createCopilotParser, } from './agents/drivers/copilot.js';
27
35
  export { createVibeParser, vibe, vibeArgs, vibePermissionFlags } from './agents/drivers/vibe.js';
28
36
  export { antigravity, antigravityAcpArgs, antigravityArgs, antigravityMcpServers, antigravityInput, antigravityToolName, antigravityPermissionFlags, createAntigravityParser, } from './agents/drivers/antigravity.js';
@@ -1 +1 @@
1
- {"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,c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AE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAUnG,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAO1F,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAO1F,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEpF,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAqBrE,OAAO,EACL,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEjG,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,131 @@
1
+ import type { GenAIClient } from '../core/client.js';
2
+ import { type PageToolOutput } from '../browser/tools.js';
3
+ import { type BackendLimiter } from './limiter.js';
4
+ import type { PageToolSpec, TurnEnd } from './protocol.js';
5
+ /** Who `authorize` says sent the request. */
6
+ export interface BackendUser {
7
+ id: string;
8
+ [key: string]: unknown;
9
+ }
10
+ export interface ServerToolContext {
11
+ /** The user `authorize` returned; undefined on a public backend. */
12
+ user?: BackendUser;
13
+ signal: AbortSignal;
14
+ }
15
+ /**
16
+ * An error a server tool throws to tell the model (and the page) what went wrong. Any other
17
+ * error shows as `The tool failed.` and goes to `onError` only, so a database or network
18
+ * message never leaves the server.
19
+ */
20
+ export declare class ToolError extends Error {
21
+ name: string;
22
+ }
23
+ /**
24
+ * A tool that runs on the server. It acts for the user who sent the request: check what that
25
+ * user may do from `context.user`, never from the arguments, which the model wrote.
26
+ */
27
+ export interface ServerTool {
28
+ name: string;
29
+ description: string;
30
+ /** JSON Schema of the arguments (an object schema). Default: no arguments. */
31
+ inputSchema?: Record<string, unknown>;
32
+ /** Changes something: the user approves each call in the page first. */
33
+ write?: boolean;
34
+ /** The one line the user reads before approving a `write` call. */
35
+ summary?(args: Record<string, unknown>): string;
36
+ run(args: Record<string, unknown>, context: ServerToolContext): Promise<PageToolOutput> | PageToolOutput;
37
+ }
38
+ export interface AgentBackendLimits {
39
+ /** Longest answer of one model call, in tokens. Default 1,024. */
40
+ maxOutputTokens?: number;
41
+ /** Model calls for one prompt, tool steps included. The last one may not call tools. Default 8. */
42
+ maxSteps?: number;
43
+ /** Tokens one conversation may use in all; past it the user starts a new one. Default 100,000. */
44
+ conversationTokens?: number;
45
+ /** Longest tool output the model is shown, in characters. Default 8,000. */
46
+ maxToolOutput?: number;
47
+ /**
48
+ * Longest prompt, in characters, with the text of attached files (`remote()` sends up to 4,000
49
+ * of each). Default 24,000.
50
+ */
51
+ maxPromptChars?: number;
52
+ /** Largest request body, in bytes. Default 2 MB (images included). */
53
+ maxBodyBytes?: number;
54
+ /** Images on one prompt (`images: true`). Default 4. */
55
+ maxImages?: number;
56
+ /** Page tools a page may offer (`pageTools: 'from-client'`). Default 32. */
57
+ maxPageTools?: number;
58
+ /** Largest transcript kept in the state token, in bytes; the oldest exchanges go first. Default 256 KB. */
59
+ maxStateBytes?: number;
60
+ /** How long a conversation lives after its last turn. Default 24 hours. */
61
+ stateTtlMs?: number;
62
+ }
63
+ /** Where conversations live when they should not travel in the token (`store`). */
64
+ export interface BackendStore {
65
+ get(id: string): Promise<unknown> | unknown;
66
+ set(id: string, value: unknown, ttlMs: number): Promise<void> | void;
67
+ }
68
+ /** What one request did, for metrics. Never the conversation's text. */
69
+ export interface BackendTurnReport {
70
+ user?: string;
71
+ status: TurnEnd['status'];
72
+ tokens: number;
73
+ steps: number;
74
+ toolCalls: string[];
75
+ error?: string;
76
+ }
77
+ export interface AgentBackendOptions {
78
+ /** The model: any `genaicode()` client whose provider calls tools. */
79
+ client: GenAIClient;
80
+ /** Who the assistant is and what it is for. A function gets the user. */
81
+ instructions?: string | ((user: BackendUser | undefined) => string);
82
+ /** Encrypts the state token. At least 32 characters; keep it out of the page. */
83
+ secret: string;
84
+ /**
85
+ * The app's own check of the request (a session cookie, a bearer). Return the user, or
86
+ * null to refuse with 401. Required unless `public: true`.
87
+ */
88
+ authorize?(request: Request): BackendUser | null | undefined | Promise<BackendUser | null | undefined>;
89
+ /** Serve anyone who can reach the URL. Costs are then held only by `limits` and `limiter`. */
90
+ public?: boolean;
91
+ /** A visitor key for `limiter` on a public backend (a client IP your proxy sets). */
92
+ identify?(request: Request): string | undefined;
93
+ /** Other origins whose pages may call the backend (CORS, no cookies). Same-origin is always allowed. */
94
+ allowedOrigins?: readonly string[];
95
+ /** Where the routes live. Default `/api/assistant`. */
96
+ basePath?: string;
97
+ /** Shown in the chat. Default `assistant`. */
98
+ name?: string;
99
+ /**
100
+ * The page tools the model may call: fixed here (the safe default), or `'from-client'` to take
101
+ * whatever the page sends with each request. Default: none.
102
+ */
103
+ pageTools?: readonly PageToolSpec[] | 'from-client';
104
+ /** Tools that run on the server, for the user who asked. */
105
+ tools?: readonly ServerTool[];
106
+ /** Take images on prompts (the model must read them). Default false. */
107
+ images?: boolean;
108
+ limits?: AgentBackendLimits;
109
+ /** Daily allowances. Default `memoryLimiter()`. */
110
+ limiter?: BackendLimiter;
111
+ /** Keep conversations here instead of in the token. */
112
+ store?: BackendStore;
113
+ /** After every request. */
114
+ onTurn?(report: BackendTurnReport): void;
115
+ /** A model or tool error, before the page gets a short description of it. */
116
+ onError?(error: unknown): void;
117
+ }
118
+ export interface AgentBackend {
119
+ readonly basePath: string;
120
+ /** Serve one request: `GET <base>/info`, `POST <base>/turn`, CORS preflights. Anything else is 404. */
121
+ handle(request: Request): Promise<Response>;
122
+ }
123
+ /**
124
+ * A model behind your server for `remote()` pages in `genaicode/browser`: the model and its key
125
+ * stay here, page tools run in the page, server tools run here for the signed-in user.
126
+ * `handle` takes a web `Request` (Node 20+ with `toNodeListener`, Workers, Deno, Bun, Vercel).
127
+ *
128
+ * Nothing that comes from the page is trusted: the conversation travels encrypted, tool results
129
+ * are data, and costs are held by `limits` and `limiter`.
130
+ */
131
+ export declare function createAgentBackend(options: AgentBackendOptions): AgentBackend;