@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,144 @@
1
+ /**
2
+ * Gemini CLI output fixtures for parser regression testing.
3
+ *
4
+ * Gemini has unique characteristics:
5
+ * - Uses sparkle character (✦) as output prefix
6
+ * - Can drop into shell mode ($ prompt)
7
+ * - Has specific keyword interpretation issues
8
+ */
9
+ /**
10
+ * Gemini-specific characters and patterns
11
+ */
12
+ export const GEMINI = {
13
+ SPARKLE: '✦',
14
+ SHELL_PROMPT: '$',
15
+ };
16
+ export const geminiOutputFixtures = [
17
+ // =====================================================================
18
+ // Sparkle prefix handling
19
+ // =====================================================================
20
+ {
21
+ name: 'gemini-sparkle-prefix',
22
+ description: 'Relay command with Gemini sparkle prefix',
23
+ input: `${GEMINI.SPARKLE} ->relay:Lead STATUS: Ready for task
24
+ `,
25
+ expectedCommands: [
26
+ { to: 'Lead', body: 'STATUS: Ready for task' },
27
+ ],
28
+ },
29
+ {
30
+ name: 'gemini-sparkle-with-space',
31
+ description: 'Sparkle with extra spacing',
32
+ input: `${GEMINI.SPARKLE} ->relay:Lead Message with extra space
33
+ `,
34
+ expectedCommands: [
35
+ { to: 'Lead', body: 'Message with extra space' },
36
+ ],
37
+ },
38
+ {
39
+ name: 'gemini-multiple-sparkle-lines',
40
+ description: 'Multiple lines with sparkle prefix',
41
+ input: `${GEMINI.SPARKLE} Processing your request...
42
+ ${GEMINI.SPARKLE} ->relay:Lead Task complete
43
+ ${GEMINI.SPARKLE} Ready for next task.
44
+ `,
45
+ expectedCommands: [
46
+ { to: 'Lead', body: 'Task complete' },
47
+ ],
48
+ expectedOutputContains: ['Processing your request', 'Ready for next task'],
49
+ },
50
+ // =====================================================================
51
+ // Shell mode detection
52
+ // =====================================================================
53
+ {
54
+ name: 'gemini-shell-mode-output',
55
+ description: 'Output that includes shell prompt',
56
+ input: `${GEMINI.SPARKLE} Let me run that command for you.
57
+ $ ls -la
58
+ total 48
59
+ drwxr-xr-x 5 user user 4096 Jan 23 10:00 .
60
+ ${GEMINI.SPARKLE} ->relay:Lead Command executed successfully
61
+ `,
62
+ expectedCommands: [
63
+ { to: 'Lead', body: 'Command executed successfully' },
64
+ ],
65
+ expectedOutputContains: ['$ ls -la', 'total 48'],
66
+ },
67
+ // =====================================================================
68
+ // Gemini-specific edge cases
69
+ // =====================================================================
70
+ {
71
+ name: 'gemini-fenced-with-sparkle',
72
+ description: 'Fenced message with sparkle prefix',
73
+ input: `${GEMINI.SPARKLE} ->relay:Lead <<<
74
+ Here's my detailed analysis:
75
+
76
+ The issue is in the authentication flow.
77
+ Consider these changes:
78
+ 1. Update token validation
79
+ 2. Add refresh logic
80
+ >>>
81
+ `,
82
+ expectedCommands: [
83
+ {
84
+ to: 'Lead',
85
+ body: `Here's my detailed analysis:
86
+
87
+ The issue is in the authentication flow.
88
+ Consider these changes:
89
+ 1. Update token validation
90
+ 2. Add refresh logic`,
91
+ },
92
+ ],
93
+ },
94
+ {
95
+ name: 'gemini-mixed-output',
96
+ description: 'Mix of sparkle and non-sparkle output',
97
+ input: `Processing...
98
+ ${GEMINI.SPARKLE} Analyzing the codebase
99
+ ${GEMINI.SPARKLE} Found 3 issues
100
+ ->relay:Lead Analysis complete with 3 issues found
101
+ ${GEMINI.SPARKLE} Done!
102
+ `,
103
+ expectedCommands: [
104
+ { to: 'Lead', body: 'Analysis complete with 3 issues found' },
105
+ ],
106
+ },
107
+ // =====================================================================
108
+ // Complex Gemini scenarios
109
+ // =====================================================================
110
+ {
111
+ name: 'gemini-code-execution-output',
112
+ description: 'Gemini executing code with relay after',
113
+ input: `${GEMINI.SPARKLE} I'll run the tests for you.
114
+
115
+ $ npm test
116
+
117
+ > project@1.0.0 test
118
+ > vitest run
119
+
120
+ ✓ src/auth.test.ts (5 tests)
121
+ ✓ src/api.test.ts (12 tests)
122
+
123
+ Test Files 2 passed
124
+ Tests 17 passed
125
+
126
+ ${GEMINI.SPARKLE} ->relay:Lead Tests passed: 17/17. Build is green.
127
+ `,
128
+ expectedCommands: [
129
+ { to: 'Lead', body: 'Tests passed: 17/17. Build is green.' },
130
+ ],
131
+ expectedOutputContains: ['npm test', '17 passed'],
132
+ },
133
+ {
134
+ name: 'gemini-broadcast',
135
+ description: 'Gemini sending broadcast message',
136
+ input: `${GEMINI.SPARKLE} ->relay:* All agents: deployment starting in 5 minutes
137
+ `,
138
+ expectedCommands: [
139
+ { to: '*', body: 'All agents: deployment starting in 5 minutes' },
140
+ ],
141
+ },
142
+ ];
143
+ export default geminiOutputFixtures;
144
+ //# sourceMappingURL=gemini-outputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini-outputs.js","sourceRoot":"","sources":["../../src/__fixtures__/gemini-outputs.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,OAAO,EAAE,GAAG;IACZ,YAAY,EAAE,GAAG;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAoB;IACnD,wEAAwE;IACxE,0BAA0B;IAC1B,wEAAwE;IACxE;QACE,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EAAE,0CAA0C;QACvD,KAAK,EAAE,GAAG,MAAM,CAAC,OAAO;CAC3B;QACG,gBAAgB,EAAE;YAChB,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,wBAAwB,EAAE;SAC/C;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,WAAW,EAAE,4BAA4B;QACzC,KAAK,EAAE,GAAG,MAAM,CAAC,OAAO;CAC3B;QACG,gBAAgB,EAAE;YAChB,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,0BAA0B,EAAE;SACjD;KACF;IACD;QACE,IAAI,EAAE,+BAA+B;QACrC,WAAW,EAAE,oCAAoC;QACjD,KAAK,EAAE,GAAG,MAAM,CAAC,OAAO;EAC1B,MAAM,CAAC,OAAO;EACd,MAAM,CAAC,OAAO;CACf;QACG,gBAAgB,EAAE;YAChB,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE;SACtC;QACD,sBAAsB,EAAE,CAAC,yBAAyB,EAAE,qBAAqB,CAAC;KAC3E;IAED,wEAAwE;IACxE,uBAAuB;IACvB,wEAAwE;IACxE;QACE,IAAI,EAAE,0BAA0B;QAChC,WAAW,EAAE,mCAAmC;QAChD,KAAK,EAAE,GAAG,MAAM,CAAC,OAAO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oBAAoB,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Parser regression test fixtures
3
+ *
4
+ * This module exports CLI output fixtures for testing the parser
5
+ * against real-world terminal output patterns.
6
+ *
7
+ * To add new fixtures:
8
+ * 1. Capture the problematic output from a real CLI session
9
+ * 2. Add it to the appropriate CLI-specific fixture file
10
+ * 3. Run tests to ensure parser handles it correctly
11
+ *
12
+ * When a parser bug is fixed, add a regression test fixture
13
+ * to prevent the bug from recurring.
14
+ */
15
+ export { claudeOutputFixtures, type OutputFixture, ANSI } from './claude-outputs.js';
16
+ export { geminiOutputFixtures, GEMINI } from './gemini-outputs.js';
17
+ export { codexOutputFixtures } from './codex-outputs.js';
18
+ /**
19
+ * All fixtures combined for comprehensive testing
20
+ */
21
+ export declare const allFixtures: ({
22
+ cli: "claude";
23
+ name: string;
24
+ description: string;
25
+ input: string;
26
+ expectedCommands: Array<{
27
+ to: string;
28
+ body: string;
29
+ kind?: string;
30
+ thread?: string;
31
+ project?: string;
32
+ }>;
33
+ expectedOutputContains?: string[];
34
+ expectedOutputNotContains?: string[];
35
+ } | {
36
+ cli: "gemini";
37
+ name: string;
38
+ description: string;
39
+ input: string;
40
+ expectedCommands: Array<{
41
+ to: string;
42
+ body: string;
43
+ kind?: string;
44
+ thread?: string;
45
+ project?: string;
46
+ }>;
47
+ expectedOutputContains?: string[];
48
+ expectedOutputNotContains?: string[];
49
+ } | {
50
+ cli: "codex";
51
+ name: string;
52
+ description: string;
53
+ input: string;
54
+ expectedCommands: Array<{
55
+ to: string;
56
+ body: string;
57
+ kind?: string;
58
+ thread?: string;
59
+ project?: string;
60
+ }>;
61
+ expectedOutputContains?: string[];
62
+ expectedOutputNotContains?: string[];
63
+ })[];
64
+ /**
65
+ * Get fixtures by CLI type
66
+ */
67
+ export declare function getFixturesByCli(cli: 'claude' | 'gemini' | 'codex'): import("./claude-outputs.js").OutputFixture[];
68
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,oBAAoB,EAAE,KAAK,aAAa,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAMzD;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;YAXY,CAAC;cAAqB,CAAA;eAAqB,CAAC;;;;;;;;;;;;YAA5C,CAAC;cAAqB,CAAA;eAAqB,CAAC;;;;;;;;;;;;YAA5C,CAAC;cAAqB,CAAA;eAAqB,CAAC;;;;IAe/E,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,iDAWlE"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Parser regression test fixtures
3
+ *
4
+ * This module exports CLI output fixtures for testing the parser
5
+ * against real-world terminal output patterns.
6
+ *
7
+ * To add new fixtures:
8
+ * 1. Capture the problematic output from a real CLI session
9
+ * 2. Add it to the appropriate CLI-specific fixture file
10
+ * 3. Run tests to ensure parser handles it correctly
11
+ *
12
+ * When a parser bug is fixed, add a regression test fixture
13
+ * to prevent the bug from recurring.
14
+ */
15
+ export { claudeOutputFixtures, ANSI } from './claude-outputs.js';
16
+ export { geminiOutputFixtures, GEMINI } from './gemini-outputs.js';
17
+ export { codexOutputFixtures } from './codex-outputs.js';
18
+ import { claudeOutputFixtures } from './claude-outputs.js';
19
+ import { geminiOutputFixtures } from './gemini-outputs.js';
20
+ import { codexOutputFixtures } from './codex-outputs.js';
21
+ /**
22
+ * All fixtures combined for comprehensive testing
23
+ */
24
+ export const allFixtures = [
25
+ ...claudeOutputFixtures.map(f => ({ ...f, cli: 'claude' })),
26
+ ...geminiOutputFixtures.map(f => ({ ...f, cli: 'gemini' })),
27
+ ...codexOutputFixtures.map(f => ({ ...f, cli: 'codex' })),
28
+ ];
29
+ /**
30
+ * Get fixtures by CLI type
31
+ */
32
+ export function getFixturesByCli(cli) {
33
+ switch (cli) {
34
+ case 'claude':
35
+ return claudeOutputFixtures;
36
+ case 'gemini':
37
+ return geminiOutputFixtures;
38
+ case 'codex':
39
+ return codexOutputFixtures;
40
+ default:
41
+ return [];
42
+ }
43
+ }
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/__fixtures__/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,oBAAoB,EAAsB,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,QAAiB,EAAE,CAAC,CAAC;IACpE,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,QAAiB,EAAE,CAAC,CAAC;IACpE,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,OAAgB,EAAE,CAAC,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAkC;IACjE,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,QAAQ;YACX,OAAO,oBAAoB,CAAC;QAC9B,KAAK,QAAQ;YACX,OAAO,oBAAoB,CAAC;QAC9B,KAAK,OAAO;YACV,OAAO,mBAAmB,CAAC;QAC7B;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Auth Revocation Detection
3
+ *
4
+ * Detects when an AI CLI's authentication has been revoked.
5
+ * This can happen when:
6
+ * 1. User authenticates the same provider elsewhere (limited sessions)
7
+ * 2. Token expires or is invalidated
8
+ * 3. OAuth refresh fails
9
+ */
10
+ /**
11
+ * Patterns that indicate authentication has been revoked or expired.
12
+ * These are typically output by Claude CLI, Codex, etc. when auth fails.
13
+ */
14
+ export declare const AUTH_REVOCATION_PATTERNS: RegExp[];
15
+ /**
16
+ * Patterns that should NOT trigger auth revocation detection.
17
+ * These are false positives that might match auth patterns but aren't actual auth errors.
18
+ */
19
+ export declare const AUTH_FALSE_POSITIVE_PATTERNS: RegExp[];
20
+ export interface AuthRevocationResult {
21
+ detected: boolean;
22
+ pattern?: string;
23
+ confidence: 'high' | 'medium' | 'low';
24
+ message?: string;
25
+ }
26
+ /**
27
+ * Detect if output indicates authentication has been revoked.
28
+ *
29
+ * @param output - The CLI output to analyze
30
+ * @param recentOutputOnly - If true, only check the last ~500 chars (for real-time detection)
31
+ * @returns Detection result with confidence level
32
+ */
33
+ export declare function detectAuthRevocation(output: string, recentOutputOnly?: boolean): AuthRevocationResult;
34
+ /**
35
+ * Check if the given text looks like an auth-related CLI prompt
36
+ * that's waiting for user action (not an error, but a request to auth).
37
+ */
38
+ export declare function isAuthPrompt(text: string): boolean;
39
+ /**
40
+ * Provider-specific auth detection configuration.
41
+ * Different AI CLIs may have different error messages.
42
+ */
43
+ export declare const PROVIDER_AUTH_PATTERNS: Record<string, RegExp[]>;
44
+ /**
45
+ * Detect auth revocation for a specific provider.
46
+ * Uses provider-specific patterns in addition to general patterns.
47
+ */
48
+ export declare function detectProviderAuthRevocation(output: string, provider: string): AuthRevocationResult;
49
+ //# sourceMappingURL=auth-detection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-detection.d.ts","sourceRoot":"","sources":["../src/auth-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,EA2C5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAoBhD,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,gBAAgB,UAAQ,GACvB,oBAAoB,CA4BtB;AAwCD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWlD;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAmB3D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,oBAAoB,CAwBtB"}
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Auth Revocation Detection
3
+ *
4
+ * Detects when an AI CLI's authentication has been revoked.
5
+ * This can happen when:
6
+ * 1. User authenticates the same provider elsewhere (limited sessions)
7
+ * 2. Token expires or is invalidated
8
+ * 3. OAuth refresh fails
9
+ */
10
+ /**
11
+ * Patterns that indicate authentication has been revoked or expired.
12
+ * These are typically output by Claude CLI, Codex, etc. when auth fails.
13
+ */
14
+ export const AUTH_REVOCATION_PATTERNS = [
15
+ // Session/token expiration
16
+ /session\s+(has\s+)?expired/i,
17
+ /token\s+(has\s+)?expired/i,
18
+ /credentials?\s+(have\s+)?expired/i,
19
+ // Login required
20
+ /please\s+log\s*in\s+again/i,
21
+ /login\s+required/i,
22
+ /authentication\s+required/i,
23
+ /must\s+(be\s+)?log(ged)?\s*in/i,
24
+ /you\s+need\s+to\s+log\s*in/i,
25
+ // Unauthorized
26
+ /\bunauthorized\b/i,
27
+ /not\s+authorized/i,
28
+ /access\s+denied/i,
29
+ // Invalid credentials
30
+ /invalid\s+credentials?/i,
31
+ /invalid\s+token/i,
32
+ /invalid\s+session/i,
33
+ /not\s+authenticated/i,
34
+ // OAuth specific
35
+ /oauth\s+error.*401/i,
36
+ /oauth\s+error.*403/i,
37
+ /oauth\s+token\s+(has\s+)?expired/i,
38
+ /refresh\s+token\s+(is\s+)?invalid/i,
39
+ /failed\s+to\s+refresh/i,
40
+ /please\s+obtain\s+a\s+new\s+token/i,
41
+ // API errors that indicate auth issues
42
+ /api\s+error.*401/i,
43
+ /api\s+error.*403/i,
44
+ /http\s+401/i,
45
+ /http\s+403/i,
46
+ // Claude-specific patterns
47
+ /your\s+api\s+key\s+is\s+invalid/i,
48
+ /api\s+key\s+not\s+found/i,
49
+ /signed\s+out/i,
50
+ /session\s+revoked/i,
51
+ ];
52
+ /**
53
+ * Patterns that should NOT trigger auth revocation detection.
54
+ * These are false positives that might match auth patterns but aren't actual auth errors.
55
+ */
56
+ export const AUTH_FALSE_POSITIVE_PATTERNS = [
57
+ // Documentation or help text
58
+ /how\s+to\s+log\s*in/i,
59
+ /login\s+instructions/i,
60
+ /authentication\s+guide/i,
61
+ // Code comments or strings
62
+ /\/\/.*unauthorized/i,
63
+ /\/\*.*unauthorized.*\*\//i,
64
+ /".*unauthorized.*"/i,
65
+ /'.*unauthorized.*'/i,
66
+ // Error handling code
67
+ /catch.*unauthorized/i,
68
+ /handle.*auth.*error/i,
69
+ /if.*session.*expired/i,
70
+ // Instructional content
71
+ /you\s+should\s+log\s*in/i,
72
+ /make\s+sure\s+you('re)?\s+logged\s*in/i,
73
+ ];
74
+ /**
75
+ * Detect if output indicates authentication has been revoked.
76
+ *
77
+ * @param output - The CLI output to analyze
78
+ * @param recentOutputOnly - If true, only check the last ~500 chars (for real-time detection)
79
+ * @returns Detection result with confidence level
80
+ */
81
+ export function detectAuthRevocation(output, recentOutputOnly = false) {
82
+ // If checking recent output only, truncate to last 500 chars
83
+ const textToCheck = recentOutputOnly ? output.slice(-500) : output;
84
+ // First check for false positives
85
+ for (const falsePositive of AUTH_FALSE_POSITIVE_PATTERNS) {
86
+ if (falsePositive.test(textToCheck)) {
87
+ return { detected: false, confidence: 'low' };
88
+ }
89
+ }
90
+ // Check each auth revocation pattern
91
+ for (const pattern of AUTH_REVOCATION_PATTERNS) {
92
+ const match = textToCheck.match(pattern);
93
+ if (match) {
94
+ // Determine confidence based on pattern specificity
95
+ const confidence = getConfidenceLevel(pattern, match[0]);
96
+ return {
97
+ detected: true,
98
+ pattern: pattern.source,
99
+ confidence,
100
+ message: match[0],
101
+ };
102
+ }
103
+ }
104
+ return { detected: false, confidence: 'low' };
105
+ }
106
+ /**
107
+ * Determine confidence level based on the matched pattern.
108
+ */
109
+ function getConfidenceLevel(pattern, _matchedText) {
110
+ const patternStr = pattern.source.toLowerCase();
111
+ // High confidence: Explicit auth failure messages
112
+ if (patternStr.includes('session') && patternStr.includes('expired') ||
113
+ patternStr.includes('please') && patternStr.includes('log') ||
114
+ patternStr.includes('authentication required') ||
115
+ patternStr.includes('token') && patternStr.includes('expired') ||
116
+ patternStr.includes('oauth') && patternStr.includes('expired') ||
117
+ patternStr.includes('authentication_error') ||
118
+ patternStr.includes('signed out') ||
119
+ patternStr.includes('session revoked') ||
120
+ patternStr.includes('obtain') && patternStr.includes('token')) {
121
+ return 'high';
122
+ }
123
+ // Medium confidence: General auth errors
124
+ if (patternStr.includes('unauthorized') ||
125
+ patternStr.includes('401') ||
126
+ patternStr.includes('403') ||
127
+ patternStr.includes('invalid') && patternStr.includes('credentials')) {
128
+ return 'medium';
129
+ }
130
+ // Low confidence: Could be related to other errors
131
+ return 'low';
132
+ }
133
+ /**
134
+ * Check if the given text looks like an auth-related CLI prompt
135
+ * that's waiting for user action (not an error, but a request to auth).
136
+ */
137
+ export function isAuthPrompt(text) {
138
+ const authPromptPatterns = [
139
+ /open\s+this\s+url/i,
140
+ /visit\s+.*to\s+authorize/i,
141
+ /enter\s+your\s+api\s+key/i,
142
+ /paste\s+your\s+token/i,
143
+ /waiting\s+for\s+authorization/i,
144
+ /complete\s+login\s+in\s+browser/i,
145
+ ];
146
+ return authPromptPatterns.some(pattern => pattern.test(text));
147
+ }
148
+ /**
149
+ * Provider-specific auth detection configuration.
150
+ * Different AI CLIs may have different error messages.
151
+ */
152
+ export const PROVIDER_AUTH_PATTERNS = {
153
+ claude: [
154
+ /claude.*session.*expired/i,
155
+ /anthropic.*unauthorized/i,
156
+ /claude.*not\s+authenticated/i,
157
+ /please\s+run\s+claude\s+login/i,
158
+ /please\s+run\s+\/login/i,
159
+ /authentication_error/i,
160
+ ],
161
+ codex: [
162
+ /codex.*session.*expired/i,
163
+ /openai.*unauthorized/i,
164
+ /codex.*not\s+authenticated/i,
165
+ ],
166
+ gemini: [
167
+ /gemini.*session.*expired/i,
168
+ /google.*unauthorized/i,
169
+ /gemini.*not\s+authenticated/i,
170
+ ],
171
+ };
172
+ /**
173
+ * Detect auth revocation for a specific provider.
174
+ * Uses provider-specific patterns in addition to general patterns.
175
+ */
176
+ export function detectProviderAuthRevocation(output, provider) {
177
+ // First check general patterns
178
+ const generalResult = detectAuthRevocation(output, true);
179
+ if (generalResult.detected && generalResult.confidence === 'high') {
180
+ return generalResult;
181
+ }
182
+ // Check provider-specific patterns
183
+ const providerPatterns = PROVIDER_AUTH_PATTERNS[provider.toLowerCase()];
184
+ if (providerPatterns) {
185
+ for (const pattern of providerPatterns) {
186
+ const match = output.match(pattern);
187
+ if (match) {
188
+ return {
189
+ detected: true,
190
+ pattern: pattern.source,
191
+ confidence: 'high',
192
+ message: match[0],
193
+ };
194
+ }
195
+ }
196
+ }
197
+ return generalResult;
198
+ }
199
+ //# sourceMappingURL=auth-detection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-detection.js","sourceRoot":"","sources":["../src/auth-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAa;IAChD,2BAA2B;IAC3B,6BAA6B;IAC7B,2BAA2B;IAC3B,mCAAmC;IAEnC,iBAAiB;IACjB,4BAA4B;IAC5B,mBAAmB;IACnB,4BAA4B;IAC5B,gCAAgC;IAChC,6BAA6B;IAE7B,eAAe;IACf,mBAAmB;IACnB,mBAAmB;IACnB,kBAAkB;IAElB,sBAAsB;IACtB,yBAAyB;IACzB,kBAAkB;IAClB,oBAAoB;IACpB,sBAAsB;IAEtB,iBAAiB;IACjB,qBAAqB;IACrB,qBAAqB;IACrB,mCAAmC;IACnC,oCAAoC;IACpC,wBAAwB;IACxB,oCAAoC;IAEpC,uCAAuC;IACvC,mBAAmB;IACnB,mBAAmB;IACnB,aAAa;IACb,aAAa;IAEb,2BAA2B;IAC3B,kCAAkC;IAClC,0BAA0B;IAC1B,eAAe;IACf,oBAAoB;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAa;IACpD,6BAA6B;IAC7B,sBAAsB;IACtB,uBAAuB;IACvB,yBAAyB;IAEzB,2BAA2B;IAC3B,qBAAqB;IACrB,2BAA2B;IAC3B,qBAAqB;IACrB,qBAAqB;IAErB,sBAAsB;IACtB,sBAAsB;IACtB,sBAAsB;IACtB,uBAAuB;IAEvB,wBAAwB;IACxB,0BAA0B;IAC1B,wCAAwC;CACzC,CAAC;AASF;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,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