@moxt-ai/mobius 0.0.5 → 0.0.6

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 (73) hide show
  1. package/dist/acp/native-session.d.ts +30 -0
  2. package/dist/acp/native-session.d.ts.map +1 -0
  3. package/dist/acp/native-session.js +25 -0
  4. package/dist/acp/native-session.js.map +1 -0
  5. package/dist/acp/session-history.d.ts +9 -0
  6. package/dist/acp/session-history.d.ts.map +1 -0
  7. package/dist/acp/session-history.js +69 -0
  8. package/dist/acp/session-history.js.map +1 -0
  9. package/dist/acp/session-manager.d.ts +16 -5
  10. package/dist/acp/session-manager.d.ts.map +1 -1
  11. package/dist/acp/session-manager.js +211 -12
  12. package/dist/acp/session-manager.js.map +1 -1
  13. package/dist/acp/session-store.d.ts +9 -0
  14. package/dist/acp/session-store.d.ts.map +1 -1
  15. package/dist/acp/session-store.js +43 -0
  16. package/dist/acp/session-store.js.map +1 -1
  17. package/dist/agent-catalog/discover-local-agents.d.ts +1 -1
  18. package/dist/agent-catalog/discover-local-agents.d.ts.map +1 -1
  19. package/dist/agent-catalog/discover-local-agents.js +19 -30
  20. package/dist/agent-catalog/discover-local-agents.js.map +1 -1
  21. package/dist/agent-installation/automatic-adapter-provisioner.d.ts +1 -1
  22. package/dist/agent-installation/automatic-adapter-provisioner.d.ts.map +1 -1
  23. package/dist/agent-installation/automatic-adapter-provisioner.js +1 -1
  24. package/dist/agent-installation/automatic-adapter-provisioner.js.map +1 -1
  25. package/dist/agent-installation/fixed-installation-executor.d.ts +1 -1
  26. package/dist/agent-installation/fixed-installation-executor.d.ts.map +1 -1
  27. package/dist/agent-installation/fixed-installation-executor.js +9 -18
  28. package/dist/agent-installation/fixed-installation-executor.js.map +1 -1
  29. package/dist/agent-installation/managed-adapter-installer.d.ts +0 -1
  30. package/dist/agent-installation/managed-adapter-installer.d.ts.map +1 -1
  31. package/dist/agent-installation/managed-adapter-installer.js +1 -3
  32. package/dist/agent-installation/managed-adapter-installer.js.map +1 -1
  33. package/dist/authorization/local-authorization-error.d.ts +5 -0
  34. package/dist/authorization/local-authorization-error.d.ts.map +1 -0
  35. package/dist/authorization/local-authorization-error.js +8 -0
  36. package/dist/authorization/local-authorization-error.js.map +1 -0
  37. package/dist/authorization/workspace-directory.d.ts +16 -5
  38. package/dist/authorization/workspace-directory.d.ts.map +1 -1
  39. package/dist/authorization/workspace-directory.js +109 -119
  40. package/dist/authorization/workspace-directory.js.map +1 -1
  41. package/dist/cli.js +1851 -543
  42. package/dist/cli.js.map +4 -4
  43. package/dist/config.d.ts +3 -3
  44. package/dist/config.d.ts.map +1 -1
  45. package/dist/config.js +7 -5
  46. package/dist/config.js.map +1 -1
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +1866 -593
  50. package/dist/index.js.map +4 -4
  51. package/dist/native-sessions/codex-history.d.ts +11 -0
  52. package/dist/native-sessions/codex-history.d.ts.map +1 -0
  53. package/dist/native-sessions/codex-history.js +223 -0
  54. package/dist/native-sessions/codex-history.js.map +1 -0
  55. package/dist/native-sessions/service.d.ts +14 -0
  56. package/dist/native-sessions/service.d.ts.map +1 -0
  57. package/dist/native-sessions/service.js +249 -0
  58. package/dist/native-sessions/service.js.map +1 -0
  59. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  60. package/dist/pairing/pair-local-machine.js +29 -26
  61. package/dist/pairing/pair-local-machine.js.map +1 -1
  62. package/dist/process/executable.d.ts +1 -1
  63. package/dist/process/executable.d.ts.map +1 -1
  64. package/dist/process/executable.js +3 -11
  65. package/dist/process/executable.js.map +1 -1
  66. package/dist/run-daemon.d.ts.map +1 -1
  67. package/dist/run-daemon.js +274 -193
  68. package/dist/run-daemon.js.map +1 -1
  69. package/package.json +3 -2
  70. package/dist/authorization/authorize-binding.d.ts +0 -6
  71. package/dist/authorization/authorize-binding.d.ts.map +0 -1
  72. package/dist/authorization/authorize-binding.js +0 -30
  73. package/dist/authorization/authorize-binding.js.map +0 -1
@@ -0,0 +1,30 @@
1
+ import { z } from "zod";
2
+ export declare const nativeSessionIdSchema: z.ZodString;
3
+ declare const nativeSessionInfoSchema: z.ZodReadonly<z.ZodObject<{
4
+ sessionId: z.ZodString;
5
+ cwd: z.ZodString;
6
+ additionalDirectories: z.ZodReadonly<z.ZodDefault<z.ZodArray<z.ZodString>>>;
7
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ updatedAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
9
+ }, z.core.$strip>>;
10
+ export type NativeSessionInfo = z.infer<typeof nativeSessionInfoSchema>;
11
+ export declare const nativeSessionPageSchema: z.ZodReadonly<z.ZodObject<{
12
+ sessions: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
13
+ sessionId: z.ZodString;
14
+ cwd: z.ZodString;
15
+ additionalDirectories: z.ZodReadonly<z.ZodDefault<z.ZodArray<z.ZodString>>>;
16
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
17
+ updatedAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
18
+ }, z.core.$strip>>>>;
19
+ nextCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
+ }, z.core.$strip>>;
21
+ export type NativeSessionPage = z.infer<typeof nativeSessionPageSchema>;
22
+ export type NativeSessionOrigin = {
23
+ readonly kind: "import";
24
+ readonly nativeSessionId: string;
25
+ } | {
26
+ readonly kind: "fork";
27
+ readonly nativeSessionId: string;
28
+ };
29
+ export {};
30
+ //# sourceMappingURL=native-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-session.d.ts","sourceRoot":"","sources":["../../src/acp/native-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,qBAAqB,aAEa,CAAC;AAChD,QAAA,MAAM,uBAAuB;;;;;;kBAQhB,CAAC;AACd,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,eAAO,MAAM,uBAAuB;;;;;;;;;kBAKvB,CAAC;AACd,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { z } from "zod";
2
+ const path = z
3
+ .string()
4
+ .min(1)
5
+ .max(2_048)
6
+ .refine((value) => !value.includes("\0"));
7
+ export const nativeSessionIdSchema = z
8
+ .string()
9
+ .regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,255}$/);
10
+ const nativeSessionInfoSchema = z
11
+ .object({
12
+ sessionId: nativeSessionIdSchema,
13
+ cwd: path,
14
+ additionalDirectories: z.array(path).max(16).default([]).readonly(),
15
+ title: z.string().max(500).nullish(),
16
+ updatedAt: z.iso.datetime({ offset: true }).nullish(),
17
+ })
18
+ .readonly();
19
+ export const nativeSessionPageSchema = z
20
+ .object({
21
+ sessions: z.array(nativeSessionInfoSchema).max(500).readonly(),
22
+ nextCursor: z.string().min(1).max(4_096).nullish(),
23
+ })
24
+ .readonly();
25
+ //# sourceMappingURL=native-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-session.js","sourceRoot":"","sources":["../../src/acp/native-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,IAAI,GAAG,CAAC;KACX,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,KAAK,CAAC;KACV,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC;KACnC,MAAM,EAAE;KACR,KAAK,CAAC,qCAAqC,CAAC,CAAC;AAChD,MAAM,uBAAuB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACN,SAAS,EAAE,qBAAqB;IAChC,GAAG,EAAE,IAAI;IACT,qBAAqB,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;IACnE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE;IACpC,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;CACtD,CAAC;KACD,QAAQ,EAAE,CAAC;AAEd,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IAC9D,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE;CACnD,CAAC;KACD,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { SessionNotification } from "@agentclientprotocol/sdk";
2
+ import { type NativeSessionHistory } from "@moxt-ai/mobius-protocol";
3
+ /** Captures ACP load replay without turning historical updates into live turns. */
4
+ export declare class AcpHistoryReplay {
5
+ #private;
6
+ readonly record: (update: SessionNotification["update"]) => void;
7
+ readonly snapshot: () => NativeSessionHistory;
8
+ }
9
+ //# sourceMappingURL=session-history.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-history.d.ts","sourceRoot":"","sources":["../../src/acp/session-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAEL,KAAK,oBAAoB,EAK1B,MAAM,0BAA0B,CAAC;AAGlC,mFAAmF;AACnF,qBAAa,gBAAgB;;IAO3B,QAAQ,CAAC,MAAM,WAAY,mBAAmB,CAAC,QAAQ,CAAC,KAAG,IAAI,CAoE7D;IAEF,QAAQ,CAAC,QAAQ,QAAO,oBAAoB,CAKzC;CACJ"}
@@ -0,0 +1,69 @@
1
+ import { parseNativeHistoryText, SESSION_HISTORY_CHARACTER_LIMIT, SESSION_HISTORY_IMAGE_CHARACTER_LIMIT, SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT, } from "@moxt-ai/mobius-protocol";
2
+ import { isProgressMessage } from "./activity.js";
3
+ /** Captures ACP load replay without turning historical updates into live turns. */
4
+ export class AcpHistoryReplay {
5
+ #messages = [];
6
+ #lastMessageId = null;
7
+ #characters = 0;
8
+ #imageCharacters = 0;
9
+ #truncated = false;
10
+ record = (update) => {
11
+ if (update.sessionUpdate !== "user_message_chunk" &&
12
+ update.sessionUpdate !== "agent_message_chunk")
13
+ return;
14
+ if (update.sessionUpdate === "agent_message_chunk" &&
15
+ isProgressMessage(update))
16
+ return;
17
+ const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
18
+ const content = update.content;
19
+ const parsed = parseNativeHistoryText(content.type === "text"
20
+ ? content.text
21
+ : content.type === "image"
22
+ ? `[@image](data:${content.mimeType};base64,${content.data})`
23
+ : `[${content.type} attachment]`);
24
+ const text = parsed.text;
25
+ if (text.length === 0 && parsed.images.length === 0)
26
+ return;
27
+ const previous = this.#messages.at(-1);
28
+ const id = update.messageId ?? null;
29
+ const continuation = previous?.role === role && id === this.#lastMessageId;
30
+ const combined = continuation ? `${previous.text}${text}` : text;
31
+ const allImages = continuation
32
+ ? [...(previous.images ?? []), ...parsed.images]
33
+ : parsed.images;
34
+ const images = allImages.slice(0, 8);
35
+ this.#truncated ||= images.length < allImages.length;
36
+ if (continuation) {
37
+ this.#messages.pop();
38
+ this.#characters -= previous.text.length;
39
+ this.#imageCharacters -= (previous.images ?? []).reduce((size, image) => size + image.data.length, 0);
40
+ }
41
+ const bounded = combined.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
42
+ this.#truncated ||= bounded.length < combined.length;
43
+ this.#messages.push({
44
+ role,
45
+ text: bounded,
46
+ ...(images.length > 0 ? { images } : {}),
47
+ });
48
+ this.#characters += bounded.length;
49
+ this.#imageCharacters += images.reduce((size, image) => size + image.data.length, 0);
50
+ this.#lastMessageId = id;
51
+ while (this.#messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT ||
52
+ this.#characters > SESSION_HISTORY_CHARACTER_LIMIT ||
53
+ this.#imageCharacters > SESSION_HISTORY_IMAGE_CHARACTER_LIMIT) {
54
+ const removed = this.#messages.shift();
55
+ if (removed !== undefined) {
56
+ this.#characters -= removed.text.length;
57
+ this.#imageCharacters -= (removed.images ?? []).reduce((size, image) => size + image.data.length, 0);
58
+ }
59
+ this.#truncated = true;
60
+ }
61
+ };
62
+ snapshot = () => ({
63
+ status: "available",
64
+ messages: [...this.#messages],
65
+ truncated: this.#truncated,
66
+ coveredCommandIds: [],
67
+ });
68
+ }
69
+ //# sourceMappingURL=session-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-history.js","sourceRoot":"","sources":["../../src/acp/session-history.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,sBAAsB,EACtB,+BAA+B,EAC/B,qCAAqC,EACrC,qCAAqC,GACtC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,mFAAmF;AACnF,MAAM,OAAO,gBAAgB;IAClB,SAAS,GAA2B,EAAE,CA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IAAI,MAAM,CAAC,MAAM,CACpC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EACzC,CAAC,CACF,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,OACE,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,qCAAqC;YAC7D,IAAI,CAAC,WAAW,GAAG,+BAA+B;YAClD,IAAI,CAAC,gBAAgB,GAAG,qCAAqC,EAC7D,CAAC;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACvC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;gBACxC,IAAI,CAAC,gBAAgB,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CACpD,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EACzC,CAAC,CACF,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;IACH,CAAC,CAAC;IAEO,QAAQ,GAAG,GAAyB,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;QAC7B,SAAS,EAAE,IAAI,CAAC,UAAU;QAC1B,iBAAiB,EAAE,EAAE;KACtB,CAAC,CAAC;CACJ"}
@@ -1,8 +1,9 @@
1
1
  import { type CompleteElicitationNotification, type CreateElicitationRequest, type CreateElicitationResponse, type RequestPermissionRequest, type RequestPermissionResponse, type SessionNotification } from "@agentclientprotocol/sdk";
2
- import { type AgentContentEvent, type PromptImage, type PromptResource, type SessionCapabilities, type SessionCommand, type SessionCommandsUpdatedEvent, type SessionConfigOption, type SessionConfigUpdatedEvent, type SessionElicitationRequestedEvent, type SessionElicitationResolvedEvent, type SessionInfoUpdatedEvent, type SessionPermissionRequestedEvent, type SessionPermissionResolvedEvent, type SessionUsageUpdatedEvent } from "@moxt-ai/mobius-protocol";
2
+ import { type AgentContentEvent, type AgentPromptResponse, type NativeSessionHistory, type PromptImage, type PromptResource, type SessionCapabilities, type SessionCommand, type SessionCommandsUpdatedEvent, type SessionConfigOption, type SessionConfigUpdatedEvent, type SessionElicitationRequestedEvent, type SessionElicitationResolvedEvent, type SessionInfoUpdatedEvent, type SessionPermissionRequestedEvent, type SessionPermissionResolvedEvent, type SessionUsageUpdatedEvent } from "@moxt-ai/mobius-protocol";
3
3
  import type { LocalAgentDefinition } from "../config.ts";
4
4
  import { type AcpActivity } from "./activity.ts";
5
5
  import { type AcpClientHandler } from "./create-client.ts";
6
+ import { type NativeSessionOrigin, type NativeSessionPage } from "./native-session.ts";
6
7
  import { type AcpSessionStore } from "./session-store.ts";
7
8
  export interface AcpPrepareOptions {
8
9
  readonly additionalDirectories: readonly string[];
@@ -10,6 +11,7 @@ export interface AcpPrepareOptions {
10
11
  readonly cwd: string;
11
12
  readonly sessionId: string;
12
13
  readonly signal: AbortSignal;
14
+ readonly origin?: NativeSessionOrigin;
13
15
  }
14
16
  export interface AcpConfigureOptions extends AcpPrepareOptions {
15
17
  readonly booleanValue: boolean;
@@ -38,9 +40,7 @@ export interface AcpElicitationResponseOptions {
38
40
  readonly interactionId: string;
39
41
  readonly sessionId: string;
40
42
  }
41
- export interface AcpPromptResult {
42
- readonly stopReason: string;
43
- }
43
+ export type AcpPromptResult = AgentPromptResponse;
44
44
  export interface AcpSessionObserver {
45
45
  readonly onCommands: (event: SessionCommandsUpdatedEvent) => Promise<void>;
46
46
  readonly onConfig: (event: SessionConfigUpdatedEvent) => Promise<void>;
@@ -84,7 +84,11 @@ declare class AcpProcessSession implements AcpClientHandler {
84
84
  readonly belongsTo: (agentId: string, cwd: string, additionalDirectories: readonly string[]) => boolean;
85
85
  readonly canRebind: () => boolean;
86
86
  readonly prepared: () => AcpPreparedSession;
87
- readonly initialize: (signal: AbortSignal) => Promise<void>;
87
+ readonly loadHistory: (signal: AbortSignal) => Promise<NativeSessionHistory>;
88
+ readonly initialize: (signal: AbortSignal, origin?: NativeSessionOrigin) => Promise<void>;
89
+ readonly listNativeSessions: (cursor: string | null, signal: AbortSignal) => Promise<NativeSessionPage>;
90
+ readonly deleteNativeSession: (nativeSessionId: string, signal: AbortSignal) => Promise<void>;
91
+ readonly nativeSessionId: () => string;
88
92
  readonly configure: (options: AcpConfigureOptions) => Promise<readonly SessionConfigOption[]>;
89
93
  readonly prompt: (options: AcpTurnOptions) => Promise<AcpPromptResult>;
90
94
  readonly cancel: () => Promise<void>;
@@ -116,6 +120,13 @@ export declare class AcpSessionManager {
116
120
  readonly respondElicitation: (options: AcpElicitationResponseOptions) => Promise<void>;
117
121
  readonly close: () => Promise<void>;
118
122
  readonly ensureSession: (options: AcpPrepareOptions) => Promise<AcpProcessSession>;
123
+ readonly listNativeSessions: (options: AcpPrepareOptions, cursor: string | null) => Promise<NativeSessionPage>;
124
+ readonly openNativeSession: (options: AcpPrepareOptions, origin: NativeSessionOrigin) => Promise<{
125
+ readonly sessionId: string;
126
+ readonly prepared: AcpPreparedSession;
127
+ readonly history: NativeSessionHistory;
128
+ }>;
129
+ readonly deleteNativeSession: (options: AcpPrepareOptions, nativeSessionId: string) => Promise<readonly string[]>;
119
130
  }
120
131
  export {};
121
132
  //# sourceMappingURL=session-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/acp/session-manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,+BAA+B,EAEpC,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAK9B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,KAAK,iB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BAAiB,YACf,iBAAiB,UAClB,mBAAmB,KAC1B,OAAO,CAAC;QACT,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;QACtC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;KACxC,CAAC,CAyFA;IAEF,QAAQ,CAAC,mBAAmB,YACjB,iBAAiB,mBACT,MAAM,KACtB,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAwC3B;CACH"}
@@ -1,10 +1,12 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { methods, ndJsonStream, PROTOCOL_VERSION, } from "@agentclientprotocol/sdk";
3
- import { AGENT_CONTENT_KIND, MOBIUS_PROTOCOL_VERSION, SESSION_COMMANDS_UPDATED_KIND, SESSION_CONFIG_UPDATED_KIND, SESSION_ELICITATION_REQUESTED_KIND, SESSION_ELICITATION_RESOLVED_KIND, SESSION_INFO_UPDATED_KIND, SESSION_PERMISSION_REQUESTED_KIND, SESSION_PERMISSION_RESOLVED_KIND, SESSION_USAGE_UPDATED_KIND, } from "@moxt-ai/mobius-protocol";
3
+ import { AGENT_CONTENT_KIND, decodeAgentPromptResponse, MOBIUS_PROTOCOL_VERSION, SESSION_COMMANDS_UPDATED_KIND, SESSION_CONFIG_UPDATED_KIND, SESSION_ELICITATION_REQUESTED_KIND, SESSION_ELICITATION_RESOLVED_KIND, SESSION_INFO_UPDATED_KIND, SESSION_PERMISSION_REQUESTED_KIND, SESSION_PERMISSION_RESOLVED_KIND, SESSION_USAGE_UPDATED_KIND, } from "@moxt-ai/mobius-protocol";
4
4
  import { revalidateExecutable, stopProcessTree, } from "../process/executable.js";
5
5
  import { AcpActivityTracker, isProgressMessage, normalizeContentBlock, } from "./activity.js";
6
6
  import { createAcpClient } from "./create-client.js";
7
- import { AcpStoredSession, FoundAcpStoredSession, MemoryAcpSessionStore, } from "./session-store.js";
7
+ import { nativeSessionIdSchema, nativeSessionPageSchema, } from "./native-session.js";
8
+ import { AcpHistoryReplay } from "./session-history.js";
9
+ import { AcpStoredSession, DeletedAcpStoredSession, FoundAcpStoredSession, MemoryAcpSessionStore, } from "./session-store.js";
8
10
  const PROCESS_STOP_TIMEOUT_MILLISECONDS = 1_000;
9
11
  const SESSION_CONTROL_COMMAND_ID = "session-control";
10
12
  export class NullAcpSessionObserver {
@@ -274,6 +276,7 @@ function normalizeCapabilities(capabilities) {
274
276
  listSessions: session?.list != null,
275
277
  loadSession: capabilities.loadSession === true,
276
278
  resumeSession: session?.resume != null,
279
+ unstableForkSession: session?.fork != null,
277
280
  };
278
281
  }
279
282
  function elicitationFieldType(value) {
@@ -582,14 +585,17 @@ class AcpProcessSession {
582
585
  listSessions: false,
583
586
  loadSession: false,
584
587
  resumeSession: false,
588
+ unstableForkSession: false,
585
589
  };
586
590
  #commands = [];
587
591
  #configOptions = [];
588
592
  #nativeSessionId = "";
589
593
  #prompted = false;
590
- #replaying = false;
594
+ #replay = {
595
+ kind: "idle",
596
+ };
591
597
  #restored = false;
592
- #sessionTitle = "";
598
+ #sessionTitle = null;
593
599
  #sessionUpdatedAt = "";
594
600
  #turn = new IdleAcpTurn();
595
601
  #updateTail = Promise.resolve();
@@ -637,11 +643,12 @@ class AcpProcessSession {
637
643
  }
638
644
  const runtime = new AcpProcessSession(options.agent, options.cwd, options.additionalDirectories, options.sessionId, getObserver, store);
639
645
  try {
640
- await runtime.initialize(options.signal);
646
+ await runtime.initialize(options.signal, options.origin);
641
647
  return runtime;
642
648
  }
643
649
  catch (error) {
644
650
  await runtime.closeProcess();
651
+ options.signal.throwIfAborted();
645
652
  if (error instanceof AcpExecutionError) {
646
653
  throw error;
647
654
  }
@@ -655,7 +662,27 @@ class AcpProcessSession {
655
662
  arraysEqual(this.#additionalDirectories, additionalDirectories);
656
663
  canRebind = () => !this.#prompted && !this.#turn.running;
657
664
  prepared = () => new AcpPreparedSession(this.#agentName, this.#agentVersion, this.#capabilities, this.#commands, this.#configOptions, this.#restored);
658
- initialize = async (signal) => {
665
+ loadHistory = async (signal) => {
666
+ if (!this.#capabilities.loadSession)
667
+ return { status: "unavailable" };
668
+ const history = new AcpHistoryReplay();
669
+ this.#replay = { kind: "capture", history };
670
+ try {
671
+ await this.race(this.#connection.agent.request(methods.agent.session.load, {
672
+ additionalDirectories: [...this.#additionalDirectories],
673
+ cwd: this.#cwd,
674
+ mcpServers: [],
675
+ sessionId: this.#nativeSessionId,
676
+ }, { cancellationSignal: signal }), "ACP agent exited while loading history", signal);
677
+ await this.#updateTail;
678
+ signal.throwIfAborted();
679
+ return history.snapshot();
680
+ }
681
+ finally {
682
+ this.#replay = { kind: "idle" };
683
+ }
684
+ };
685
+ initialize = async (signal, origin) => {
659
686
  const initialized = await this.race(this.#connection.agent.request(methods.agent.initialize, {
660
687
  clientCapabilities: {
661
688
  elicitation: { form: {}, url: {} },
@@ -674,9 +701,31 @@ class AcpProcessSession {
674
701
  initialized.agentInfo?.name ??
675
702
  this.#agentId, 255);
676
703
  this.#agentVersion = truncate(initialized.agentInfo?.version ?? "", 128);
677
- const stored = this.#store.read(this.#mobiusSessionId);
704
+ const stored = origin?.kind === "import"
705
+ ? new FoundAcpStoredSession(new AcpStoredSession(this.#mobiusSessionId, this.#agentId, nativeSessionIdSchema.parse(origin.nativeSessionId), this.#cwd, this.#additionalDirectories, true))
706
+ : this.#store.read(this.#mobiusSessionId);
707
+ if (stored instanceof DeletedAcpStoredSession)
708
+ throw new AcpExecutionError("The native Agent session was deleted. Start a new chat.", {}, "native_session_deleted");
678
709
  let lifecycleResponse;
679
- if (stored instanceof FoundAcpStoredSession &&
710
+ if (origin?.kind === "fork") {
711
+ if (!this.#capabilities.unstableForkSession)
712
+ throw new AcpExecutionError("This Agent does not support session forking", {}, "native_session_unsupported");
713
+ const forked = await this.race(this.#connection.agent.request(methods.agent.session.fork, {
714
+ sessionId: nativeSessionIdSchema.parse(origin.nativeSessionId),
715
+ cwd: this.#cwd,
716
+ additionalDirectories: [...this.#additionalDirectories],
717
+ mcpServers: [],
718
+ }, { cancellationSignal: signal }), "ACP agent exited while forking a session", signal);
719
+ this.#nativeSessionId = nativeSessionIdSchema.parse(forked.sessionId);
720
+ if (this.#nativeSessionId === origin.nativeSessionId ||
721
+ this.#store.findNative(this.#agentId, this.#nativeSessionId).length > 0) {
722
+ throw new AcpExecutionError("The Agent did not create an independent fork", {}, "invalid_native_session_response");
723
+ }
724
+ this.#prompted = true;
725
+ this.#restored = true;
726
+ lifecycleResponse = forked;
727
+ }
728
+ else if (stored instanceof FoundAcpStoredSession &&
680
729
  stored.session.agentId === this.#agentId &&
681
730
  stored.session.cwd === this.#cwd &&
682
731
  arraysEqual(stored.session.additionalDirectories, this.#additionalDirectories)) {
@@ -692,7 +741,7 @@ class AcpProcessSession {
692
741
  }, { cancellationSignal: signal }), "ACP agent exited while resuming a session", signal);
693
742
  }
694
743
  else if (this.#capabilities.loadSession) {
695
- this.#replaying = true;
744
+ this.#replay = { kind: "discard" };
696
745
  try {
697
746
  lifecycleResponse = await this.race(this.#connection.agent.request(methods.agent.session.load, {
698
747
  additionalDirectories: [...this.#additionalDirectories],
@@ -702,7 +751,8 @@ class AcpProcessSession {
702
751
  }, { cancellationSignal: signal }), "ACP agent exited while loading a session", signal);
703
752
  }
704
753
  finally {
705
- this.#replaying = false;
754
+ await this.#updateTail;
755
+ this.#replay = { kind: "idle" };
706
756
  }
707
757
  }
708
758
  else {
@@ -731,7 +781,23 @@ class AcpProcessSession {
731
781
  this.#configOptions = normalizeConfigOptions(lifecycleRecord["configOptions"], lifecycleRecord["modes"]);
732
782
  await this.#updateTail;
733
783
  signal.throwIfAborted();
784
+ this.#store.write(new AcpStoredSession(this.#mobiusSessionId, this.#agentId, this.#nativeSessionId, this.#cwd, this.#additionalDirectories, this.#prompted));
785
+ };
786
+ listNativeSessions = async (cursor, signal) => {
787
+ if (!this.#capabilities.listSessions)
788
+ throw new AcpExecutionError("This Agent does not support native session listing", {}, "native_session_unsupported");
789
+ const response = await this.race(this.#connection.agent.request(methods.agent.session.list, cursor === null ? {} : { cursor }, { cancellationSignal: signal }), "ACP agent exited while listing sessions", signal);
790
+ const decoded = nativeSessionPageSchema.safeParse(response);
791
+ if (!decoded.success)
792
+ throw new AcpExecutionError("The Agent returned an invalid native session list", { cause: decoded.error }, "invalid_native_session_response");
793
+ return decoded.data;
794
+ };
795
+ deleteNativeSession = async (nativeSessionId, signal) => {
796
+ if (!this.#capabilities.deleteSession || !this.#capabilities.listSessions)
797
+ throw new AcpExecutionError("This Agent does not support native session deletion", {}, "native_session_unsupported");
798
+ await this.race(this.#connection.agent.request(methods.agent.session.delete, { sessionId: nativeSessionIdSchema.parse(nativeSessionId) }, { cancellationSignal: signal }), "ACP agent exited while deleting a session", signal);
734
799
  };
800
+ nativeSessionId = () => this.#nativeSessionId;
735
801
  configure = async (options) => {
736
802
  const existing = this.#configOptions.find((option) => option.id === options.configId);
737
803
  if (existing === undefined || existing.type !== options.valueType) {
@@ -821,7 +887,25 @@ class AcpProcessSession {
821
887
  const response = await this.race(this.#connection.agent.request(methods.agent.session.prompt, { prompt, sessionId: this.#nativeSessionId }, { cancellationSignal: options.signal }), "ACP agent exited during a prompt", options.signal);
822
888
  await this.#updateTail;
823
889
  await running.activities.finish();
824
- return { stopReason: response.stopReason };
890
+ let result;
891
+ try {
892
+ result = decodeAgentPromptResponse(response);
893
+ }
894
+ catch (cause) {
895
+ throw new AcpExecutionError("ACP agent returned an invalid prompt response", { cause }, "acp_invalid_prompt_response");
896
+ }
897
+ if (result.usage != null || result._meta?.quota !== undefined) {
898
+ await this.#getObserver().onUsage({
899
+ _meta: result._meta ?? null,
900
+ commandId: options.commandId,
901
+ kind: SESSION_USAGE_UPDATED_KIND,
902
+ protocolVersion: MOBIUS_PROTOCOL_VERSION,
903
+ sessionId: this.#mobiusSessionId,
904
+ source: "prompt",
905
+ usage: result.usage ?? null,
906
+ });
907
+ }
908
+ return result;
825
909
  }
826
910
  catch (error) {
827
911
  await running.activities.finish();
@@ -1010,7 +1094,9 @@ class AcpProcessSession {
1010
1094
  processUpdate = async (notification) => {
1011
1095
  this.assertNativeSession(notification.sessionId);
1012
1096
  const update = notification.update;
1013
- if (this.#replaying &&
1097
+ if (this.#replay.kind === "capture")
1098
+ this.#replay.history.record(update);
1099
+ if (this.#replay.kind !== "idle" &&
1014
1100
  (update.sessionUpdate === "user_message_chunk" ||
1015
1101
  update.sessionUpdate === "agent_message_chunk" ||
1016
1102
  update.sessionUpdate === "agent_thought_chunk" ||
@@ -1126,6 +1212,7 @@ class AcpProcessSession {
1126
1212
  protocolVersion: MOBIUS_PROTOCOL_VERSION,
1127
1213
  sessionId: this.#mobiusSessionId,
1128
1214
  size: Math.max(0, Math.trunc(update.size)),
1215
+ source: "context",
1129
1216
  used: Math.max(0, Math.trunc(update.used)),
1130
1217
  });
1131
1218
  }
@@ -1239,6 +1326,7 @@ class AcpProcessSession {
1239
1326
  };
1240
1327
  }
1241
1328
  export class AcpSessionManager {
1329
+ #nativeOperations = new Set();
1242
1330
  #activeSessionIds = new Set();
1243
1331
  #cancellationRequests = new Set();
1244
1332
  #preparing = new Map();
@@ -1284,6 +1372,12 @@ export class AcpSessionManager {
1284
1372
  return await operation;
1285
1373
  }
1286
1374
  prepareSession = async (options) => {
1375
+ const stored = this.#store.read(options.sessionId);
1376
+ if (stored instanceof DeletedAcpStoredSession)
1377
+ throw new AcpExecutionError("The native Agent session was deleted. Start a new chat.", {}, "native_session_deleted");
1378
+ if (stored instanceof FoundAcpStoredSession &&
1379
+ this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`))
1380
+ throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
1287
1381
  const pending = this.#preparing.get(options.sessionId);
1288
1382
  if (pending !== undefined) {
1289
1383
  const runtime = await pending;
@@ -1318,6 +1412,11 @@ export class AcpSessionManager {
1318
1412
  }
1319
1413
  };
1320
1414
  runPrompt = async (options) => {
1415
+ const stored = this.#store.read(options.sessionId);
1416
+ if (stored instanceof FoundAcpStoredSession &&
1417
+ this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
1418
+ throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
1419
+ }
1321
1420
  if (this.#activeSessionIds.has(options.sessionId)) {
1322
1421
  throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
1323
1422
  }
@@ -1327,6 +1426,8 @@ export class AcpSessionManager {
1327
1426
  return { stopReason: "cancelled" };
1328
1427
  }
1329
1428
  const runtime = await this.ensureSession(options);
1429
+ if (this.#nativeOperations.has(`${options.agent.id}:${runtime.nativeSessionId()}`))
1430
+ throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
1330
1431
  if (this.#cancellationRequests.has(options.sessionId)) {
1331
1432
  return { stopReason: "cancelled" };
1332
1433
  }
@@ -1384,5 +1485,103 @@ export class AcpSessionManager {
1384
1485
  }
1385
1486
  return started;
1386
1487
  };
1488
+ listNativeSessions = async (options, cursor) => await (await this.ensureSession(options)).listNativeSessions(cursor, options.signal);
1489
+ openNativeSession = async (options, origin) => {
1490
+ const key = `${options.agent.id}:${origin.nativeSessionId}`;
1491
+ if (this.#nativeOperations.has(key))
1492
+ throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
1493
+ const linked = this.#store.findNative(options.agent.id, origin.nativeSessionId);
1494
+ if (linked.some((entry) => this.#activeSessionIds.has(entry.sessionId) ||
1495
+ this.#preparing.has(entry.sessionId)))
1496
+ throw new AcpExecutionError("Wait for the native session's running operation to finish", {}, "session_busy");
1497
+ const existing = linked[0];
1498
+ if (origin.kind === "import" && existing !== undefined) {
1499
+ const runtime = await this.ensureSession({
1500
+ ...options,
1501
+ sessionId: existing.sessionId,
1502
+ });
1503
+ if (this.#activeSessionIds.has(existing.sessionId) ||
1504
+ this.#nativeOperations.has(key))
1505
+ throw new AcpExecutionError("Wait for the native session's running operation to finish", {}, "session_busy");
1506
+ this.#nativeOperations.add(key);
1507
+ try {
1508
+ const history = await runtime.loadHistory(options.signal);
1509
+ return {
1510
+ prepared: runtime.prepared(),
1511
+ sessionId: existing.sessionId,
1512
+ history,
1513
+ };
1514
+ }
1515
+ catch (error) {
1516
+ this.#sessions.delete(existing.sessionId);
1517
+ await runtime.closeProcess();
1518
+ throw error;
1519
+ }
1520
+ finally {
1521
+ this.#nativeOperations.delete(key);
1522
+ }
1523
+ }
1524
+ if (this.#sessions.has(options.sessionId) ||
1525
+ this.#preparing.has(options.sessionId) ||
1526
+ this.#store.read(options.sessionId) instanceof FoundAcpStoredSession ||
1527
+ this.#store.read(options.sessionId) instanceof DeletedAcpStoredSession)
1528
+ throw new AcpExecutionError("The destination conversation already exists", {}, "session_identity_mismatch");
1529
+ this.#nativeOperations.add(key);
1530
+ try {
1531
+ const runtime = await this.#startPreparation({ ...options, origin });
1532
+ const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
1533
+ this.#nativeOperations.add(openedKey);
1534
+ try {
1535
+ const history = await runtime.loadHistory(options.signal);
1536
+ return {
1537
+ sessionId: options.sessionId,
1538
+ prepared: runtime.prepared(),
1539
+ history,
1540
+ };
1541
+ }
1542
+ catch (error) {
1543
+ this.#sessions.delete(options.sessionId);
1544
+ this.#store.remove(options.sessionId);
1545
+ await runtime.closeProcess();
1546
+ throw error;
1547
+ }
1548
+ finally {
1549
+ this.#nativeOperations.delete(openedKey);
1550
+ }
1551
+ }
1552
+ finally {
1553
+ this.#nativeOperations.delete(key);
1554
+ }
1555
+ };
1556
+ deleteNativeSession = async (options, nativeSessionId) => {
1557
+ const runtime = await this.ensureSession(options);
1558
+ const key = `${options.agent.id}:${nativeSessionId}`;
1559
+ const linked = this.#store.findNative(options.agent.id, nativeSessionId);
1560
+ if (this.#nativeOperations.has(key) ||
1561
+ linked.some((entry) => this.#activeSessionIds.has(entry.sessionId) ||
1562
+ this.#preparing.has(entry.sessionId)))
1563
+ throw new AcpExecutionError("Wait for the native session's running operation to finish", {}, "session_busy");
1564
+ this.#nativeOperations.add(key);
1565
+ try {
1566
+ for (const entry of linked) {
1567
+ const active = this.#sessions.get(entry.sessionId);
1568
+ if (active !== undefined && active !== runtime) {
1569
+ this.#sessions.delete(entry.sessionId);
1570
+ await active.close();
1571
+ }
1572
+ }
1573
+ options.signal.throwIfAborted();
1574
+ await runtime.deleteNativeSession(nativeSessionId, options.signal);
1575
+ const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
1576
+ if (runtime.nativeSessionId() === nativeSessionId) {
1577
+ this.#sessions.delete(options.sessionId);
1578
+ await runtime.close();
1579
+ }
1580
+ return deleted;
1581
+ }
1582
+ finally {
1583
+ this.#nativeOperations.delete(key);
1584
+ }
1585
+ };
1387
1586
  }
1388
1587
  //# sourceMappingURL=session-manager.js.map