@bytespell/amux 0.0.11 → 0.0.13

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 (89) hide show
  1. package/.claude/settings.local.json +11 -0
  2. package/CLAUDE.md +104 -0
  3. package/LICENSE +21 -0
  4. package/README.md +215 -0
  5. package/dist/cli.d.ts +14 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +118 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/client.d.ts +68 -0
  10. package/dist/client.d.ts.map +1 -0
  11. package/dist/client.js +135 -0
  12. package/dist/client.js.map +1 -0
  13. package/dist/index.d.ts +41 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +44 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/{lib/mentions.d.ts → message-parser.d.ts} +3 -5
  18. package/dist/message-parser.d.ts.map +1 -0
  19. package/dist/message-parser.js +45 -0
  20. package/dist/message-parser.js.map +1 -0
  21. package/dist/message-parser.test.d.ts +2 -0
  22. package/dist/message-parser.test.d.ts.map +1 -0
  23. package/dist/message-parser.test.js +188 -0
  24. package/dist/message-parser.test.js.map +1 -0
  25. package/dist/server.d.ts +24 -0
  26. package/dist/server.d.ts.map +1 -0
  27. package/dist/server.js +356 -0
  28. package/dist/server.js.map +1 -0
  29. package/dist/session-updates.d.ts +26 -0
  30. package/dist/session-updates.d.ts.map +1 -0
  31. package/dist/session-updates.js +68 -0
  32. package/dist/session-updates.js.map +1 -0
  33. package/dist/session-updates.test.d.ts +2 -0
  34. package/dist/session-updates.test.d.ts.map +1 -0
  35. package/dist/session-updates.test.js +223 -0
  36. package/dist/session-updates.test.js.map +1 -0
  37. package/dist/session.d.ts +208 -0
  38. package/dist/session.d.ts.map +1 -0
  39. package/dist/session.js +580 -0
  40. package/dist/session.js.map +1 -0
  41. package/dist/state.d.ts +74 -0
  42. package/dist/state.d.ts.map +1 -0
  43. package/dist/state.js +250 -0
  44. package/dist/state.js.map +1 -0
  45. package/dist/terminal.d.ts +47 -0
  46. package/dist/terminal.d.ts.map +1 -0
  47. package/dist/terminal.js +137 -0
  48. package/dist/terminal.js.map +1 -0
  49. package/dist/types.d.ts +64 -2
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +16 -31
  52. package/dist/types.js.map +1 -1
  53. package/dist/ws-adapter.d.ts +39 -0
  54. package/dist/ws-adapter.d.ts.map +1 -0
  55. package/dist/ws-adapter.js +198 -0
  56. package/dist/ws-adapter.js.map +1 -0
  57. package/package.json +47 -24
  58. package/src/client.ts +162 -0
  59. package/src/index.ts +66 -0
  60. package/src/message-parser.test.ts +207 -0
  61. package/src/message-parser.ts +54 -0
  62. package/src/session-updates.test.ts +265 -0
  63. package/src/session-updates.ts +87 -0
  64. package/src/session.ts +737 -0
  65. package/src/state.ts +287 -0
  66. package/src/terminal.ts +164 -0
  67. package/src/types.ts +88 -0
  68. package/src/ws-adapter.ts +245 -0
  69. package/tsconfig.json +22 -0
  70. package/vitest.config.ts +7 -0
  71. package/dist/chunk-5IPYOXBE.js +0 -32
  72. package/dist/chunk-5IPYOXBE.js.map +0 -1
  73. package/dist/chunk-C73RKCTS.js +0 -36
  74. package/dist/chunk-C73RKCTS.js.map +0 -1
  75. package/dist/chunk-VVXT4HQM.js +0 -779
  76. package/dist/chunk-VVXT4HQM.js.map +0 -1
  77. package/dist/lib/logger.d.ts +0 -24
  78. package/dist/lib/logger.js +0 -17
  79. package/dist/lib/logger.js.map +0 -1
  80. package/dist/lib/mentions.js +0 -7
  81. package/dist/lib/mentions.js.map +0 -1
  82. package/dist/streams/backends/index.d.ts +0 -88
  83. package/dist/streams/backends/index.js +0 -13
  84. package/dist/streams/backends/index.js.map +0 -1
  85. package/dist/streams/manager.d.ts +0 -55
  86. package/dist/streams/manager.js +0 -248
  87. package/dist/streams/manager.js.map +0 -1
  88. package/dist/types-DCRtrjjj.d.ts +0 -192
  89. package/scripts/fix-pty.cjs +0 -21
package/dist/client.js ADDED
@@ -0,0 +1,135 @@
1
+ import fs from 'fs';
2
+ import crypto from 'crypto';
3
+ import { isToolCallUpdate, normalizeSessionUpdate } from './session-updates.js';
4
+ /**
5
+ * ACP Client implementation.
6
+ * Bridges agent notifications to WebSocket clients and handles
7
+ * file operations and terminal management.
8
+ */
9
+ export class AmuxClient {
10
+ terminalManager;
11
+ onEvent;
12
+ pendingPermissions = new Map();
13
+ constructor(terminalManager, onEvent) {
14
+ this.terminalManager = terminalManager;
15
+ this.onEvent = onEvent;
16
+ }
17
+ /**
18
+ * Handle permission request from agent
19
+ */
20
+ async requestPermission(params) {
21
+ console.log('[amux] Permission request:', params.toolCall?.title);
22
+ // Send permission request
23
+ const requestId = crypto.randomUUID();
24
+ this.onEvent({
25
+ type: 'permission_request',
26
+ requestId,
27
+ toolCall: params.toolCall,
28
+ options: params.options,
29
+ });
30
+ // Wait for response from client (with timeout)
31
+ return new Promise((resolve, reject) => {
32
+ const timeout = setTimeout(() => {
33
+ this.pendingPermissions.delete(requestId);
34
+ resolve({ outcome: { outcome: 'cancelled' } });
35
+ }, 300000); // 5 minute timeout
36
+ this.pendingPermissions.set(requestId, { resolve, reject, timeout });
37
+ });
38
+ }
39
+ /**
40
+ * Handle permission response from UI
41
+ */
42
+ handlePermissionResponse(requestId, optionId) {
43
+ const pending = this.pendingPermissions.get(requestId);
44
+ if (pending) {
45
+ clearTimeout(pending.timeout);
46
+ this.pendingPermissions.delete(requestId);
47
+ pending.resolve({
48
+ outcome: { outcome: 'selected', optionId },
49
+ });
50
+ }
51
+ }
52
+ /**
53
+ * Handle session update from agent
54
+ */
55
+ async sessionUpdate(params) {
56
+ const update = params.update;
57
+ // Normalize the update (convert Claude-style diffs to unified format)
58
+ const normalized = normalizeSessionUpdate(update);
59
+ // Route to session
60
+ this.onEvent({ type: 'session_update', update: normalized });
61
+ // Log updates for debugging
62
+ if (update.sessionUpdate === 'agent_message_chunk') {
63
+ // Don't log every chunk
64
+ }
65
+ else if (isToolCallUpdate(update)) {
66
+ console.log(`[amux] Tool call: ${update.title} (${update.status}) id=${update.toolCallId}`);
67
+ }
68
+ else if (update.sessionUpdate === 'tool_call_update') {
69
+ // Don't log every update
70
+ }
71
+ else if (update.sessionUpdate === 'current_mode_update') {
72
+ console.log(`[amux] Mode update: ${update.currentModeId}`);
73
+ }
74
+ else {
75
+ console.log(`[amux] Session update: ${update.sessionUpdate}`);
76
+ }
77
+ }
78
+ /**
79
+ * Write text file (ACP fs capability)
80
+ */
81
+ async writeTextFile(params) {
82
+ console.log('[amux] Write text file:', params.path);
83
+ try {
84
+ fs.writeFileSync(params.path, params.content);
85
+ return {};
86
+ }
87
+ catch (err) {
88
+ throw new Error(`Failed to write file: ${err.message}`);
89
+ }
90
+ }
91
+ /**
92
+ * Read text file (ACP fs capability)
93
+ */
94
+ async readTextFile(params) {
95
+ console.log('[amux] Read text file:', params.path);
96
+ try {
97
+ const content = fs.readFileSync(params.path, 'utf-8');
98
+ return { content };
99
+ }
100
+ catch (err) {
101
+ throw new Error(`Failed to read file: ${err.message}`);
102
+ }
103
+ }
104
+ /**
105
+ * Create terminal (ACP terminal capability)
106
+ */
107
+ async createTerminal(params) {
108
+ return this.terminalManager.create(params);
109
+ }
110
+ /**
111
+ * Get terminal output (ACP terminal capability)
112
+ */
113
+ async terminalOutput(params) {
114
+ return this.terminalManager.getOutput(params.terminalId);
115
+ }
116
+ /**
117
+ * Wait for terminal exit (ACP terminal capability)
118
+ */
119
+ async waitForTerminalExit(params) {
120
+ return this.terminalManager.waitForExit(params.terminalId);
121
+ }
122
+ /**
123
+ * Kill terminal (ACP terminal capability)
124
+ */
125
+ async killTerminal(params) {
126
+ return this.terminalManager.kill(params.terminalId);
127
+ }
128
+ /**
129
+ * Release terminal (ACP terminal capability)
130
+ */
131
+ async releaseTerminal(params) {
132
+ return this.terminalManager.release(params.terminalId);
133
+ }
134
+ }
135
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot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AAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,MAAsC;QACvD,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,MAAkC;QACtD,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACzD,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * amux - Agent Multiplexer
3
+ *
4
+ * A library for managing ACP agent sessions with an EventEmitter interface.
5
+ * Transport-agnostic - wire up to WebSocket, HTTP, IPC, or anything else.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { AgentSession, createWsAdapter } from '@bytespell/amux';
10
+ * import { WebSocketServer } from 'ws';
11
+ *
12
+ * const session = new AgentSession({
13
+ * instanceId: 'my-instance',
14
+ * basePath: __dirname,
15
+ * systemContext: 'You are a helpful assistant...',
16
+ * });
17
+ *
18
+ * // Option 1: Use the WebSocket adapter
19
+ * const wss = new WebSocketServer({ port: 3000 });
20
+ * createWsAdapter(session, wss);
21
+ *
22
+ * // Option 2: Handle events yourself
23
+ * session.on('ready', (data) => console.log('Ready:', data));
24
+ * session.on('update', (data) => myTransport.send(data));
25
+ *
26
+ * await session.spawnAgent();
27
+ * await session.prompt('Hello!');
28
+ * ```
29
+ */
30
+ export { AgentSession } from './session.js';
31
+ export type { AgentSessionEvents } from './session.js';
32
+ export { createWsAdapter } from './ws-adapter.js';
33
+ export type { WsAdapterOptions } from './ws-adapter.js';
34
+ export { AmuxClient } from './client.js';
35
+ export { TerminalManager } from './terminal.js';
36
+ export { StateManager } from './state.js';
37
+ export { isToolCallUpdate, isToolCallUpdateMessage, isDiffContent, normalizeSessionUpdate, } from './session-updates.js';
38
+ export { parseMessageToContentBlocks } from './message-parser.js';
39
+ export type { AgentSessionConfig, AgentConfig, SessionMetadata, SessionState, SessionRestoreInfo, StoredEvent, } from './types.js';
40
+ export { AGENTS } from './types.js';
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAGlE,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * amux - Agent Multiplexer
3
+ *
4
+ * A library for managing ACP agent sessions with an EventEmitter interface.
5
+ * Transport-agnostic - wire up to WebSocket, HTTP, IPC, or anything else.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { AgentSession, createWsAdapter } from '@bytespell/amux';
10
+ * import { WebSocketServer } from 'ws';
11
+ *
12
+ * const session = new AgentSession({
13
+ * instanceId: 'my-instance',
14
+ * basePath: __dirname,
15
+ * systemContext: 'You are a helpful assistant...',
16
+ * });
17
+ *
18
+ * // Option 1: Use the WebSocket adapter
19
+ * const wss = new WebSocketServer({ port: 3000 });
20
+ * createWsAdapter(session, wss);
21
+ *
22
+ * // Option 2: Handle events yourself
23
+ * session.on('ready', (data) => console.log('Ready:', data));
24
+ * session.on('update', (data) => myTransport.send(data));
25
+ *
26
+ * await session.spawnAgent();
27
+ * await session.prompt('Hello!');
28
+ * ```
29
+ */
30
+ // Core session management
31
+ export { AgentSession } from './session.js';
32
+ // WebSocket adapter
33
+ export { createWsAdapter } from './ws-adapter.js';
34
+ // Supporting components (for advanced usage)
35
+ export { AmuxClient } from './client.js';
36
+ export { TerminalManager } from './terminal.js';
37
+ export { StateManager } from './state.js';
38
+ // Session update utilities
39
+ export { isToolCallUpdate, isToolCallUpdateMessage, isDiffContent, normalizeSessionUpdate, } from './session-updates.js';
40
+ // Message parsing utilities
41
+ export { parseMessageToContentBlocks } from './message-parser.js';
42
+ // Built-in agents registry
43
+ export { AGENTS } from './types.js';
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,0BAA0B;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,oBAAoB;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,6CAA6C;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,2BAA2B;AAC3B,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,4BAA4B;AAC5B,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAYlE,2BAA2B;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
@@ -1,5 +1,4 @@
1
- import { ContentBlock } from '@agentclientprotocol/sdk';
2
-
1
+ import type * as acp from '@agentclientprotocol/sdk';
3
2
  /**
4
3
  * Parse message text with @mentions into ContentBlock array.
5
4
  * @mentions become resource_link blocks, other text becomes text blocks.
@@ -9,6 +8,5 @@ import { ContentBlock } from '@agentclientprotocol/sdk';
9
8
  * - "@src/foo.ts" → [{ type: 'resource_link', uri: 'file://...', name: 'src/foo.ts' }]
10
9
  * - "check @src/foo.ts for bugs" → text + resource_link + text
11
10
  */
12
- declare function parseMessageToContentBlocks(message: string, workingDir: string): ContentBlock[];
13
-
14
- export { parseMessageToContentBlocks };
11
+ export declare function parseMessageToContentBlocks(message: string, workingDir: string): acp.ContentBlock[];
12
+ //# sourceMappingURL=message-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-parser.d.ts","sourceRoot":"","sources":["../src/message-parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,GAAG,MAAM,0BAA0B,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,GAAG,CAAC,YAAY,EAAE,CAsCpB"}
@@ -0,0 +1,45 @@
1
+ import path from 'path';
2
+ /**
3
+ * Parse message text with @mentions into ContentBlock array.
4
+ * @mentions become resource_link blocks, other text becomes text blocks.
5
+ *
6
+ * Examples:
7
+ * - "hello world" → [{ type: 'text', text: 'hello world' }]
8
+ * - "@src/foo.ts" → [{ type: 'resource_link', uri: 'file://...', name: 'src/foo.ts' }]
9
+ * - "check @src/foo.ts for bugs" → text + resource_link + text
10
+ */
11
+ export function parseMessageToContentBlocks(message, workingDir) {
12
+ const blocks = [];
13
+ // Match @path/to/file.ts, @./local.ts, @../parent/file.ts
14
+ // Allows leading ./ or ../ followed by path characters
15
+ const mentionRegex = /@(\.{0,2}[\w\/\.\-]+)/g;
16
+ let lastIndex = 0;
17
+ for (const match of message.matchAll(mentionRegex)) {
18
+ // Add text before mention
19
+ if (match.index > lastIndex) {
20
+ const text = message.slice(lastIndex, match.index);
21
+ if (text.trim()) {
22
+ blocks.push({ type: 'text', text });
23
+ }
24
+ }
25
+ // Add resource_link for mention
26
+ const relativePath = match[1];
27
+ const absolutePath = path.resolve(workingDir, relativePath);
28
+ blocks.push({
29
+ type: 'resource_link',
30
+ uri: `file://${absolutePath}`,
31
+ name: relativePath,
32
+ });
33
+ lastIndex = match.index + match[0].length;
34
+ }
35
+ // Add remaining text
36
+ if (lastIndex < message.length) {
37
+ const text = message.slice(lastIndex);
38
+ if (text.trim()) {
39
+ blocks.push({ type: 'text', text });
40
+ }
41
+ }
42
+ // If no mentions found, return single text block
43
+ return blocks.length > 0 ? blocks : [{ type: 'text', text: message }];
44
+ }
45
+ //# sourceMappingURL=message-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-parser.js","sourceRoot":"","sources":["../src/message-parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAAe,EACf,UAAkB;IAElB,MAAM,MAAM,GAAuB,EAAE,CAAC;IACtC,0DAA0D;IAC1D,uDAAuD;IACvD,MAAM,YAAY,GAAG,wBAAwB,CAAC;IAE9C,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QACnD,0BAA0B;QAC1B,IAAI,KAAK,CAAC,KAAM,GAAG,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACnD,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;gBAChB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;QAED,gCAAgC;QAChC,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAC5D,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,eAAe;YACrB,GAAG,EAAE,UAAU,YAAY,EAAE;YAC7B,IAAI,EAAE,YAAY;SACnB,CAAC,CAAC;QAEH,SAAS,GAAG,KAAK,CAAC,KAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC7C,CAAC;IAED,qBAAqB;IACrB,IAAI,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,iDAAiD;IACjD,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=message-parser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-parser.test.d.ts","sourceRoot":"","sources":["../src/message-parser.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,188 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { parseMessageToContentBlocks } from './message-parser.js';
3
+ describe('parseMessageToContentBlocks', () => {
4
+ const workingDir = '/home/user/project';
5
+ describe('plain text messages', () => {
6
+ it('returns single text block for plain text', () => {
7
+ const result = parseMessageToContentBlocks('hello world', workingDir);
8
+ expect(result).toEqual([{ type: 'text', text: 'hello world' }]);
9
+ });
10
+ it('returns single text block for empty message', () => {
11
+ const result = parseMessageToContentBlocks('', workingDir);
12
+ expect(result).toEqual([{ type: 'text', text: '' }]);
13
+ });
14
+ it('returns single text block for whitespace-only message', () => {
15
+ const result = parseMessageToContentBlocks(' ', workingDir);
16
+ expect(result).toEqual([{ type: 'text', text: ' ' }]);
17
+ });
18
+ it('preserves multi-line text', () => {
19
+ const result = parseMessageToContentBlocks('line one\nline two', workingDir);
20
+ expect(result).toEqual([{ type: 'text', text: 'line one\nline two' }]);
21
+ });
22
+ });
23
+ describe('single @mentions', () => {
24
+ it('parses single @mention as resource_link', () => {
25
+ const result = parseMessageToContentBlocks('@src/foo.ts', workingDir);
26
+ expect(result).toEqual([
27
+ {
28
+ type: 'resource_link',
29
+ uri: 'file:///home/user/project/src/foo.ts',
30
+ name: 'src/foo.ts',
31
+ },
32
+ ]);
33
+ });
34
+ it('parses relative path with ./', () => {
35
+ const result = parseMessageToContentBlocks('@./local.ts', workingDir);
36
+ expect(result).toEqual([
37
+ {
38
+ type: 'resource_link',
39
+ uri: 'file:///home/user/project/local.ts',
40
+ name: './local.ts',
41
+ },
42
+ ]);
43
+ });
44
+ it('parses relative path with ../', () => {
45
+ const result = parseMessageToContentBlocks('@../parent/file.ts', workingDir);
46
+ expect(result).toEqual([
47
+ {
48
+ type: 'resource_link',
49
+ uri: 'file:///home/user/parent/file.ts',
50
+ name: '../parent/file.ts',
51
+ },
52
+ ]);
53
+ });
54
+ it('handles file with dashes in name', () => {
55
+ const result = parseMessageToContentBlocks('@src/my-file.ts', workingDir);
56
+ expect(result).toEqual([
57
+ {
58
+ type: 'resource_link',
59
+ uri: 'file:///home/user/project/src/my-file.ts',
60
+ name: 'src/my-file.ts',
61
+ },
62
+ ]);
63
+ });
64
+ it('handles deeply nested paths', () => {
65
+ const result = parseMessageToContentBlocks('@src/a/b/c/d.ts', workingDir);
66
+ expect(result).toEqual([
67
+ {
68
+ type: 'resource_link',
69
+ uri: 'file:///home/user/project/src/a/b/c/d.ts',
70
+ name: 'src/a/b/c/d.ts',
71
+ },
72
+ ]);
73
+ });
74
+ });
75
+ describe('mixed text and @mentions', () => {
76
+ it('parses text before and after mention', () => {
77
+ const result = parseMessageToContentBlocks('check @src/foo.ts for bugs', workingDir);
78
+ expect(result).toEqual([
79
+ { type: 'text', text: 'check ' },
80
+ {
81
+ type: 'resource_link',
82
+ uri: 'file:///home/user/project/src/foo.ts',
83
+ name: 'src/foo.ts',
84
+ },
85
+ { type: 'text', text: ' for bugs' },
86
+ ]);
87
+ });
88
+ it('parses text only before mention', () => {
89
+ const result = parseMessageToContentBlocks('look at @src/foo.ts', workingDir);
90
+ expect(result).toEqual([
91
+ { type: 'text', text: 'look at ' },
92
+ {
93
+ type: 'resource_link',
94
+ uri: 'file:///home/user/project/src/foo.ts',
95
+ name: 'src/foo.ts',
96
+ },
97
+ ]);
98
+ });
99
+ it('parses text only after mention', () => {
100
+ const result = parseMessageToContentBlocks('@src/foo.ts has a bug', workingDir);
101
+ expect(result).toEqual([
102
+ {
103
+ type: 'resource_link',
104
+ uri: 'file:///home/user/project/src/foo.ts',
105
+ name: 'src/foo.ts',
106
+ },
107
+ { type: 'text', text: ' has a bug' },
108
+ ]);
109
+ });
110
+ });
111
+ describe('multiple @mentions', () => {
112
+ it('parses multiple mentions with text between', () => {
113
+ const result = parseMessageToContentBlocks('@src/a.ts and @src/b.ts', workingDir);
114
+ expect(result).toEqual([
115
+ {
116
+ type: 'resource_link',
117
+ uri: 'file:///home/user/project/src/a.ts',
118
+ name: 'src/a.ts',
119
+ },
120
+ { type: 'text', text: ' and ' },
121
+ {
122
+ type: 'resource_link',
123
+ uri: 'file:///home/user/project/src/b.ts',
124
+ name: 'src/b.ts',
125
+ },
126
+ ]);
127
+ });
128
+ it('parses consecutive mentions without text between', () => {
129
+ const result = parseMessageToContentBlocks('@a.ts @b.ts', workingDir);
130
+ // The space between becomes whitespace-only and gets skipped
131
+ expect(result).toEqual([
132
+ {
133
+ type: 'resource_link',
134
+ uri: 'file:///home/user/project/a.ts',
135
+ name: 'a.ts',
136
+ },
137
+ {
138
+ type: 'resource_link',
139
+ uri: 'file:///home/user/project/b.ts',
140
+ name: 'b.ts',
141
+ },
142
+ ]);
143
+ });
144
+ });
145
+ describe('edge cases', () => {
146
+ it('handles email-like patterns (should not match)', () => {
147
+ // Email addresses should be matched by regex, which may not be desired
148
+ // This test documents current behavior
149
+ const result = parseMessageToContentBlocks('email user@example.com', workingDir);
150
+ // The regex matches @example.com as a mention
151
+ expect(result[0]).toEqual({ type: 'text', text: 'email user' });
152
+ expect(result[1]).toHaveProperty('type', 'resource_link');
153
+ });
154
+ it('handles @ at end of string without path', () => {
155
+ const result = parseMessageToContentBlocks('just an @', workingDir);
156
+ expect(result).toEqual([{ type: 'text', text: 'just an @' }]);
157
+ });
158
+ it('handles multiple @ signs', () => {
159
+ const result = parseMessageToContentBlocks('@@foo.ts', workingDir);
160
+ // First @ doesn't match (followed by @), second @ matches
161
+ expect(result).toHaveLength(2);
162
+ expect(result[0]).toEqual({ type: 'text', text: '@' });
163
+ });
164
+ });
165
+ describe('working directory resolution', () => {
166
+ it('uses provided working directory for absolute path resolution', () => {
167
+ const result = parseMessageToContentBlocks('@file.ts', '/custom/dir');
168
+ expect(result).toEqual([
169
+ {
170
+ type: 'resource_link',
171
+ uri: 'file:///custom/dir/file.ts',
172
+ name: 'file.ts',
173
+ },
174
+ ]);
175
+ });
176
+ it('resolves relative paths correctly from working directory', () => {
177
+ const result = parseMessageToContentBlocks('@../sibling/file.ts', '/home/user/project');
178
+ expect(result).toEqual([
179
+ {
180
+ type: 'resource_link',
181
+ uri: 'file:///home/user/sibling/file.ts',
182
+ name: '../sibling/file.ts',
183
+ },
184
+ ]);
185
+ });
186
+ });
187
+ });
188
+ //# sourceMappingURL=message-parser.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-parser.test.js","sourceRoot":"","sources":["../src/message-parser.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAElE,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,MAAM,UAAU,GAAG,oBAAoB,CAAC;IAExC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACnC,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,MAAM,MAAM,GAAG,2BAA2B,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;YACtE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;YACrD,MAAM,MAAM,GAAG,2BAA2B,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;YAC3D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;YAC/D,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YAC9D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;YACnC,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,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;QAC5C,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;YACtE,MAAM,MAAM,GAAG,2BAA2B,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACtE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB;oBACE,IAAI,EAAE,eAAe;oBACrB,GAAG,EAAE,4BAA4B;oBACjC,IAAI,EAAE,SAAS;iBAChB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;YAClE,MAAM,MAAM,GAAG,2BAA2B,CAAC,qBAAqB,EAAE,oBAAoB,CAAC,CAAC;YACxF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB;oBACE,IAAI,EAAE,eAAe;oBACrB,GAAG,EAAE,mCAAmC;oBACxC,IAAI,EAAE,oBAAoB;iBAC3B;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { type Application } from 'express';
2
+ import { type Server } from 'http';
3
+ import { AgentSession } from './session.js';
4
+ import type { AmuxServerConfig } from './types.js';
5
+ /**
6
+ * Create an amux server with full Express + WebSocket setup.
7
+ * This is the "batteries included" API for building agent-powered plugins.
8
+ */
9
+ export declare function createAmuxServer(config?: AmuxServerConfig): {
10
+ app: Application;
11
+ server: Server;
12
+ start: () => Promise<void>;
13
+ shutdown: () => void;
14
+ };
15
+ /**
16
+ * Attach amux to an existing Express app and HTTP server.
17
+ * For when you want more control over the server setup.
18
+ */
19
+ export declare function attachAmux(_app: Application, server: Server, config: Omit<AmuxServerConfig, 'port' | 'dev' | 'staticDir'>): {
20
+ agentSession: AgentSession;
21
+ start: () => Promise<void>;
22
+ shutdown: () => void;
23
+ };
24
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAkD,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AAMjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,gBAAgB,EAA0B,MAAM,YAAY,CAAC;AAY3E;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,gBAAqB,GAAG;IAC/D,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CA0SA;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,KAAK,GAAG,WAAW,CAAC,GAC3D;IACD,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CA2EA"}