@agent-relay/wrapper 0.1.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 (115) hide show
  1. package/dist/__fixtures__/claude-outputs.d.ts +49 -0
  2. package/dist/__fixtures__/claude-outputs.d.ts.map +1 -0
  3. package/dist/__fixtures__/claude-outputs.js +443 -0
  4. package/dist/__fixtures__/claude-outputs.js.map +1 -0
  5. package/dist/__fixtures__/codex-outputs.d.ts +9 -0
  6. package/dist/__fixtures__/codex-outputs.d.ts.map +1 -0
  7. package/dist/__fixtures__/codex-outputs.js +94 -0
  8. package/dist/__fixtures__/codex-outputs.js.map +1 -0
  9. package/dist/__fixtures__/gemini-outputs.d.ts +19 -0
  10. package/dist/__fixtures__/gemini-outputs.d.ts.map +1 -0
  11. package/dist/__fixtures__/gemini-outputs.js +144 -0
  12. package/dist/__fixtures__/gemini-outputs.js.map +1 -0
  13. package/dist/__fixtures__/index.d.ts +68 -0
  14. package/dist/__fixtures__/index.d.ts.map +1 -0
  15. package/dist/__fixtures__/index.js +44 -0
  16. package/dist/__fixtures__/index.js.map +1 -0
  17. package/dist/auth-detection.d.ts +49 -0
  18. package/dist/auth-detection.d.ts.map +1 -0
  19. package/dist/auth-detection.js +199 -0
  20. package/dist/auth-detection.js.map +1 -0
  21. package/dist/base-wrapper.d.ts +225 -0
  22. package/dist/base-wrapper.d.ts.map +1 -0
  23. package/dist/base-wrapper.js +572 -0
  24. package/dist/base-wrapper.js.map +1 -0
  25. package/dist/client.d.ts +254 -0
  26. package/dist/client.d.ts.map +1 -0
  27. package/dist/client.js +801 -0
  28. package/dist/client.js.map +1 -0
  29. package/dist/id-generator.d.ts +35 -0
  30. package/dist/id-generator.d.ts.map +1 -0
  31. package/dist/id-generator.js +60 -0
  32. package/dist/id-generator.js.map +1 -0
  33. package/dist/idle-detector.d.ts +110 -0
  34. package/dist/idle-detector.d.ts.map +1 -0
  35. package/dist/idle-detector.js +304 -0
  36. package/dist/idle-detector.js.map +1 -0
  37. package/dist/inbox.d.ts +37 -0
  38. package/dist/inbox.d.ts.map +1 -0
  39. package/dist/inbox.js +73 -0
  40. package/dist/inbox.js.map +1 -0
  41. package/dist/index.d.ts +37 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +47 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/parser.d.ts +236 -0
  46. package/dist/parser.d.ts.map +1 -0
  47. package/dist/parser.js +1238 -0
  48. package/dist/parser.js.map +1 -0
  49. package/dist/prompt-composer.d.ts +67 -0
  50. package/dist/prompt-composer.d.ts.map +1 -0
  51. package/dist/prompt-composer.js +168 -0
  52. package/dist/prompt-composer.js.map +1 -0
  53. package/dist/relay-pty-orchestrator.d.ts +407 -0
  54. package/dist/relay-pty-orchestrator.d.ts.map +1 -0
  55. package/dist/relay-pty-orchestrator.js +1885 -0
  56. package/dist/relay-pty-orchestrator.js.map +1 -0
  57. package/dist/shared.d.ts +201 -0
  58. package/dist/shared.d.ts.map +1 -0
  59. package/dist/shared.js +341 -0
  60. package/dist/shared.js.map +1 -0
  61. package/dist/stuck-detector.d.ts +161 -0
  62. package/dist/stuck-detector.d.ts.map +1 -0
  63. package/dist/stuck-detector.js +402 -0
  64. package/dist/stuck-detector.js.map +1 -0
  65. package/dist/tmux-resolver.d.ts +55 -0
  66. package/dist/tmux-resolver.d.ts.map +1 -0
  67. package/dist/tmux-resolver.js +175 -0
  68. package/dist/tmux-resolver.js.map +1 -0
  69. package/dist/tmux-wrapper.d.ts +345 -0
  70. package/dist/tmux-wrapper.d.ts.map +1 -0
  71. package/dist/tmux-wrapper.js +1747 -0
  72. package/dist/tmux-wrapper.js.map +1 -0
  73. package/dist/trajectory-integration.d.ts +292 -0
  74. package/dist/trajectory-integration.d.ts.map +1 -0
  75. package/dist/trajectory-integration.js +979 -0
  76. package/dist/trajectory-integration.js.map +1 -0
  77. package/dist/wrapper-types.d.ts +41 -0
  78. package/dist/wrapper-types.d.ts.map +1 -0
  79. package/dist/wrapper-types.js +7 -0
  80. package/dist/wrapper-types.js.map +1 -0
  81. package/package.json +63 -0
  82. package/src/__fixtures__/claude-outputs.ts +471 -0
  83. package/src/__fixtures__/codex-outputs.ts +99 -0
  84. package/src/__fixtures__/gemini-outputs.ts +151 -0
  85. package/src/__fixtures__/index.ts +47 -0
  86. package/src/auth-detection.ts +244 -0
  87. package/src/base-wrapper.test.ts +540 -0
  88. package/src/base-wrapper.ts +741 -0
  89. package/src/client.test.ts +262 -0
  90. package/src/client.ts +984 -0
  91. package/src/id-generator.test.ts +71 -0
  92. package/src/id-generator.ts +69 -0
  93. package/src/idle-detector.test.ts +390 -0
  94. package/src/idle-detector.ts +370 -0
  95. package/src/inbox.test.ts +233 -0
  96. package/src/inbox.ts +89 -0
  97. package/src/index.ts +170 -0
  98. package/src/parser.regression.test.ts +251 -0
  99. package/src/parser.test.ts +1359 -0
  100. package/src/parser.ts +1477 -0
  101. package/src/prompt-composer.test.ts +219 -0
  102. package/src/prompt-composer.ts +231 -0
  103. package/src/relay-pty-orchestrator.test.ts +1027 -0
  104. package/src/relay-pty-orchestrator.ts +2270 -0
  105. package/src/shared.test.ts +221 -0
  106. package/src/shared.ts +454 -0
  107. package/src/stuck-detector.test.ts +303 -0
  108. package/src/stuck-detector.ts +511 -0
  109. package/src/tmux-resolver.test.ts +104 -0
  110. package/src/tmux-resolver.ts +207 -0
  111. package/src/tmux-wrapper.test.ts +316 -0
  112. package/src/tmux-wrapper.ts +2010 -0
  113. package/src/trajectory-detection.test.ts +151 -0
  114. package/src/trajectory-integration.ts +1261 -0
  115. package/src/wrapper-types.ts +45 -0
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Tests for trajectory detection functions
3
+ */
4
+
5
+ import { describe, it, expect } from 'vitest';
6
+ import { detectToolCalls, detectErrors } from './trajectory-integration.js';
7
+
8
+ describe('detectToolCalls', () => {
9
+ it('detects tool completion markers', () => {
10
+ const output = `
11
+ ✓ Read file.ts
12
+ ✔ Bash completed
13
+ `;
14
+ const tools = detectToolCalls(output);
15
+ expect(tools).toHaveLength(2);
16
+ expect(tools[0].tool).toBe('Read');
17
+ expect(tools[0].status).toBe('completed');
18
+ expect(tools[1].tool).toBe('Bash');
19
+ expect(tools[1].status).toBe('completed');
20
+ });
21
+
22
+ it('detects tool invocation patterns', () => {
23
+ const output = `
24
+ Using tool Read to read the file
25
+ Calling Bash command
26
+ `;
27
+ const tools = detectToolCalls(output);
28
+ expect(tools.length).toBeGreaterThan(0);
29
+ expect(tools.some(t => t.tool === 'Read' || t.tool === 'Bash')).toBe(true);
30
+ });
31
+
32
+ it('deduplicates tools by position', () => {
33
+ const output = `
34
+ ✓ Read file.ts
35
+ ✓ Read file.ts
36
+ `;
37
+ const tools = detectToolCalls(output);
38
+ // Should detect both as they're at different positions
39
+ expect(tools).toHaveLength(2);
40
+ });
41
+
42
+ it('handles empty output', () => {
43
+ const tools = detectToolCalls('');
44
+ expect(tools).toHaveLength(0);
45
+ });
46
+
47
+ it('handles output with no tools', () => {
48
+ const tools = detectToolCalls('Just some regular text without any tools.');
49
+ expect(tools).toHaveLength(0);
50
+ });
51
+
52
+ it('detects newer tools like Skill and TaskOutput', () => {
53
+ const output = `
54
+ ✓ Skill invoked
55
+ TaskOutput({"task_id": "123"})
56
+ `;
57
+ const tools = detectToolCalls(output);
58
+ expect(tools.some(t => t.tool === 'Skill')).toBe(true);
59
+ expect(tools.some(t => t.tool === 'TaskOutput')).toBe(true);
60
+ });
61
+ });
62
+
63
+ describe('detectErrors', () => {
64
+ it('detects JavaScript/TypeScript errors', () => {
65
+ const output = `
66
+ TypeError: Cannot read property 'foo' of undefined
67
+ at Object.<anonymous> (test.ts:10:5)
68
+ `;
69
+ const errors = detectErrors(output);
70
+ expect(errors.length).toBeGreaterThan(0);
71
+ expect(errors.some(e => e.message.includes('TypeError'))).toBe(true);
72
+ expect(errors[0].type).toBe('error');
73
+ });
74
+
75
+ it('detects test failures', () => {
76
+ const output = `
77
+ FAIL src/test.ts
78
+ ✗ Test case failed
79
+ `;
80
+ const errors = detectErrors(output);
81
+ expect(errors.length).toBeGreaterThan(0);
82
+ expect(errors.some(e => e.type === 'error')).toBe(true);
83
+ });
84
+
85
+ it('detects warnings', () => {
86
+ const output = `
87
+ warning: Package is deprecated
88
+ WARN: Something might be wrong
89
+ `;
90
+ const errors = detectErrors(output);
91
+ expect(errors.some(e => e.type === 'warning')).toBe(true);
92
+ });
93
+
94
+ it('detects command failures', () => {
95
+ const output = `
96
+ Command failed with exit code 1
97
+ Exit code: 127
98
+ `;
99
+ const errors = detectErrors(output);
100
+ expect(errors.length).toBeGreaterThan(0);
101
+ });
102
+
103
+ it('deduplicates errors by message', () => {
104
+ const output = `
105
+ Error: Something went wrong
106
+ Error: Something went wrong
107
+ `;
108
+ const errors = detectErrors(output);
109
+ // The detection may find two different patterns matching (generic "Error:" prefix)
110
+ // but should deduplicate if the exact same message is found multiple times
111
+ expect(errors.length).toBeGreaterThan(0);
112
+ // Count unique messages about "Something went wrong"
113
+ const wrongMessages = errors.filter(e => e.message.includes('Something went wrong'));
114
+ // At least one should be found
115
+ expect(wrongMessages.length).toBeGreaterThanOrEqual(1);
116
+ });
117
+
118
+ it('handles empty output', () => {
119
+ const errors = detectErrors('');
120
+ expect(errors).toHaveLength(0);
121
+ });
122
+
123
+ it('handles output with no errors', () => {
124
+ const errors = detectErrors('Everything is working fine. Success!');
125
+ expect(errors).toHaveLength(0);
126
+ });
127
+
128
+ it('truncates long error messages', () => {
129
+ const longMessage = 'Error: ' + 'x'.repeat(500);
130
+ const errors = detectErrors(longMessage);
131
+ expect(errors.length).toBeGreaterThan(0);
132
+ expect(errors[0].message.length).toBeLessThanOrEqual(200);
133
+ });
134
+
135
+ it('detects TypeScript compilation errors', () => {
136
+ const output = `
137
+ error TS2339: Property 'foo' does not exist on type 'Bar'.
138
+ error[E0001]: Some rust error
139
+ `;
140
+ const errors = detectErrors(output);
141
+ expect(errors.length).toBeGreaterThan(0);
142
+ expect(errors.some(e => e.message.includes('TS2339'))).toBe(true);
143
+ });
144
+
145
+ it('does not match "error handling" as an error', () => {
146
+ const output = 'Implementing error handling for the API.';
147
+ const errors = detectErrors(output);
148
+ // Should not detect "error handling" as an error
149
+ expect(errors).toHaveLength(0);
150
+ });
151
+ });