@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
package/dist/inbox.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * File-based Inbox Manager
3
+ * Writes incoming messages to a file that the CLI agent reads itself.
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ export const DEFAULT_INBOX_DIR = '/tmp/agent-relay';
8
+ export class InboxManager {
9
+ config;
10
+ inboxPath;
11
+ constructor(config) {
12
+ this.config = {
13
+ inboxDir: DEFAULT_INBOX_DIR,
14
+ ...config,
15
+ };
16
+ this.inboxPath = path.join(this.config.inboxDir, this.config.agentName, 'inbox.md');
17
+ }
18
+ /**
19
+ * Initialize inbox directory and file.
20
+ */
21
+ init() {
22
+ const dir = path.dirname(this.inboxPath);
23
+ if (!fs.existsSync(dir)) {
24
+ fs.mkdirSync(dir, { recursive: true });
25
+ }
26
+ // Start with empty inbox
27
+ this.clear();
28
+ }
29
+ /**
30
+ * Get the inbox file path (for telling the agent where to read).
31
+ */
32
+ getInboxPath() {
33
+ return this.inboxPath;
34
+ }
35
+ /**
36
+ * Add a message to the inbox.
37
+ */
38
+ addMessage(from, body) {
39
+ const timestamp = new Date().toISOString();
40
+ const entry = `\n## Message from ${from} | ${timestamp}\n${body}\n`;
41
+ // Read existing content
42
+ let content = '';
43
+ if (fs.existsSync(this.inboxPath)) {
44
+ content = fs.readFileSync(this.inboxPath, 'utf-8');
45
+ }
46
+ // If empty, add header
47
+ if (!content.trim()) {
48
+ content = `# 📬 INBOX - CHECK AND RESPOND TO ALL MESSAGES\n`;
49
+ }
50
+ // Append new message
51
+ content += entry;
52
+ // Atomic write (write to temp, then rename)
53
+ const tmpPath = `${this.inboxPath}.tmp`;
54
+ fs.writeFileSync(tmpPath, content, 'utf-8');
55
+ fs.renameSync(tmpPath, this.inboxPath);
56
+ }
57
+ /**
58
+ * Clear the inbox.
59
+ */
60
+ clear() {
61
+ fs.writeFileSync(this.inboxPath, '', 'utf-8');
62
+ }
63
+ /**
64
+ * Check if inbox has messages.
65
+ */
66
+ hasMessages() {
67
+ if (!fs.existsSync(this.inboxPath))
68
+ return false;
69
+ const content = fs.readFileSync(this.inboxPath, 'utf-8');
70
+ return content.includes('## Message from');
71
+ }
72
+ }
73
+ //# sourceMappingURL=inbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox.js","sourceRoot":"","sources":["../src/inbox.ts"],"names":[],"mappings":"AAAA;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OAAO,CAAC,CAAC;QACrD,CAAC;QAED,uBAAuB;QACvB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YACpB,OAAO,GAAG,kDAAkD,CAAC;QAC/D,CAAC;QAED,qBAAqB;QACrB,OAAO,IAAI,KAAK,CAAC;QAEjB,4CAA4C;QAC5C,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,SAAS,MAAM,CAAC;QACxC,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,WAAW;QACT,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;YAAE,OAAO,KAAK,CAAC;QACjD,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACzD,OAAO,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @agent-relay/wrapper
3
+ *
4
+ * CLI agent wrappers for Agent Relay.
5
+ * Phase 2B extraction - utilities and types.
6
+ */
7
+ export { IdGenerator, idGen, generateId } from './id-generator.js';
8
+ export { getTmuxPath, resolveTmux, isTmuxAvailable, checkTmuxVersion, getBundledTmuxDir, getBundledTmuxPath, getPlatformIdentifier, TmuxNotFoundError, type TmuxInfo, BUNDLED_TMUX_DIR, BUNDLED_TMUX_PATH, MIN_TMUX_VERSION, } from './tmux-resolver.js';
9
+ export { OutputParser, parseSummaryFromOutput, parseSummaryWithDetails, parseSessionEndFromOutput, parseRelayMetadataFromOutput, isPlaceholderTarget, type ParsedCommand, type ParserOptions, type ParsedSummary, type ParsedMessageMetadata, type MetadataParseResult, type SummaryParseResult, type SessionEndMarker, } from './parser.js';
10
+ export { stripAnsi, sleep, getDefaultRelayPrefix, buildInjectionString, injectWithRetry, INJECTION_CONSTANTS, CLI_QUIRKS, type QueuedMessage, type InjectionResult, type InjectionMetrics, type CliType, type InjectionCallbacks, } from './shared.js';
11
+ export { AUTH_REVOCATION_PATTERNS, AUTH_FALSE_POSITIVE_PATTERNS, PROVIDER_AUTH_PATTERNS, detectProviderAuthRevocation, type AuthRevocationResult, } from './auth-detection.js';
12
+ export { UniversalIdleDetector, getTmuxPanePid, type IdleSignal, type IdleResult, type IdleDetectorConfig, } from './idle-detector.js';
13
+ export { TrajectoryIntegration, getTrajectoryIntegration, detectPhaseFromContent, detectToolCalls, detectErrors, getCompactTrailInstructions, getTrailEnvVars, getTrailInstructions, isTrailAvailable, startTrajectory, getTrajectoryStatus, transitionPhase, recordDecision, recordEvent, recordMessage, completeTrajectory, abandonTrajectory, listTrajectorySteps, getTrajectoryHistory, type PDEROPhase, type StartTrajectoryOptions, type CompleteTrajectoryOptions, type DecisionOptions, type TrajectoryStepData, type TrajectoryHistoryEntry, type DetectedToolCall, type DetectedError, } from './trajectory-integration.js';
14
+ export { type InjectionFailedEvent, type SummaryEvent, type SessionEndEvent, type AuthRevokedEvent, } from './wrapper-types.js';
15
+ export { StuckDetector, type StuckEvent, type StuckReason, type StuckDetectorConfig, } from './stuck-detector.js';
16
+ export { composeForAgent, getAvailableRoles, parseRoleFromProfile, clearPromptCache, type AgentRole, type AgentProfile, type ComposedPrompt, } from './prompt-composer.js';
17
+ /**
18
+ * Relay client (internal use only)
19
+ *
20
+ * @deprecated **MIGRATION REQUIRED** - Use `@agent-relay/sdk` instead.
21
+ *
22
+ * ```typescript
23
+ * // BEFORE (deprecated)
24
+ * import { RelayClient } from '@agent-relay/wrapper';
25
+ *
26
+ * // AFTER (recommended)
27
+ * import { RelayClient } from '@agent-relay/sdk';
28
+ * ```
29
+ *
30
+ * This export is retained only for internal daemon/wrapper integration.
31
+ * External consumers should migrate to `@agent-relay/sdk`.
32
+ * This export will be removed in a future major version.
33
+ */
34
+ export { RelayClient, type ClientState, type ClientConfig, type SyncOptions, } from './client.js';
35
+ export { BaseWrapper, type BaseWrapperConfig, } from './base-wrapper.js';
36
+ export { RelayPtyOrchestrator, type RelayPtyOrchestratorConfig, } from './relay-pty-orchestrator.js';
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGnE,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,KAAK,QAAQ,EACb,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,4BAA4B,EAC5B,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,SAAS,EACT,KAAK,EACL,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,sBAAsB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,0BAA0B,GAChC,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @agent-relay/wrapper
3
+ *
4
+ * CLI agent wrappers for Agent Relay.
5
+ * Phase 2B extraction - utilities and types.
6
+ */
7
+ // ID generation
8
+ export { IdGenerator, idGen, generateId } from './id-generator.js';
9
+ // Tmux binary resolution
10
+ export { getTmuxPath, resolveTmux, isTmuxAvailable, checkTmuxVersion, getBundledTmuxDir, getBundledTmuxPath, getPlatformIdentifier, TmuxNotFoundError, BUNDLED_TMUX_DIR, BUNDLED_TMUX_PATH, MIN_TMUX_VERSION, } from './tmux-resolver.js';
11
+ // Output parser
12
+ export { OutputParser, parseSummaryFromOutput, parseSummaryWithDetails, parseSessionEndFromOutput, parseRelayMetadataFromOutput, isPlaceholderTarget, } from './parser.js';
13
+ // Shared wrapper utilities and types
14
+ export { stripAnsi, sleep, getDefaultRelayPrefix, buildInjectionString, injectWithRetry, INJECTION_CONSTANTS, CLI_QUIRKS, } from './shared.js';
15
+ // Auth revocation detection
16
+ export { AUTH_REVOCATION_PATTERNS, AUTH_FALSE_POSITIVE_PATTERNS, PROVIDER_AUTH_PATTERNS, detectProviderAuthRevocation, } from './auth-detection.js';
17
+ // Idle detection
18
+ export { UniversalIdleDetector, getTmuxPanePid, } from './idle-detector.js';
19
+ // Trajectory integration (PDERO paradigm tracking)
20
+ export { TrajectoryIntegration, getTrajectoryIntegration, detectPhaseFromContent, detectToolCalls, detectErrors, getCompactTrailInstructions, getTrailEnvVars, getTrailInstructions, isTrailAvailable, startTrajectory, getTrajectoryStatus, transitionPhase, recordDecision, recordEvent, recordMessage, completeTrajectory, abandonTrajectory, listTrajectorySteps, getTrajectoryHistory, } from './trajectory-integration.js';
21
+ // Stuck detection
22
+ export { StuckDetector, } from './stuck-detector.js';
23
+ // Prompt composition
24
+ export { composeForAgent, getAvailableRoles, parseRoleFromProfile, clearPromptCache, } from './prompt-composer.js';
25
+ /**
26
+ * Relay client (internal use only)
27
+ *
28
+ * @deprecated **MIGRATION REQUIRED** - Use `@agent-relay/sdk` instead.
29
+ *
30
+ * ```typescript
31
+ * // BEFORE (deprecated)
32
+ * import { RelayClient } from '@agent-relay/wrapper';
33
+ *
34
+ * // AFTER (recommended)
35
+ * import { RelayClient } from '@agent-relay/sdk';
36
+ * ```
37
+ *
38
+ * This export is retained only for internal daemon/wrapper integration.
39
+ * External consumers should migrate to `@agent-relay/sdk`.
40
+ * This export will be removed in a future major version.
41
+ */
42
+ export { RelayClient, } from './client.js';
43
+ // Base wrapper class
44
+ export { BaseWrapper, } from './base-wrapper.js';
45
+ // RelayPtyOrchestrator (relay-pty Rust binary)
46
+ export { RelayPtyOrchestrator, } from './relay-pty-orchestrator.js';
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gBAAgB;AAChB,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEnE,yBAAyB;AACzB,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EAEjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,4BAA4B,EAC5B,mBAAmB,GAQpB,MAAM,aAAa,CAAC;AAErB,qCAAqC;AACrC,OAAO,EACL,SAAS,EACT,KAAK,EACL,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,UAAU,GAMX,MAAM,aAAa,CAAC;AAErB,4BAA4B;AAC5B,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,sBAAsB,EACtB,4BAA4B,GAE7B,MAAM,qBAAqB,CAAC;AAE7B,iBAAiB;AACjB,OAAO,EACL,qBAAqB,EACrB,cAAc,GAIf,MAAM,oBAAoB,CAAC;AAE5B,mDAAmD;AACnD,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,2BAA2B,EAC3B,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,GASrB,MAAM,6BAA6B,CAAC;AAUrC,kBAAkB;AAClB,OAAO,EACL,aAAa,GAId,MAAM,qBAAqB,CAAC;AAE7B,qBAAqB;AACrB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GAIjB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,WAAW,GAIZ,MAAM,aAAa,CAAC;AAErB,qBAAqB;AACrB,OAAO,EACL,WAAW,GAEZ,MAAM,mBAAmB,CAAC;AAE3B,+CAA+C;AAC/C,OAAO,EACL,oBAAoB,GAErB,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,236 @@
1
+ /**
2
+ * PTY Output Parser
3
+ * Extracts relay commands from agent terminal output.
4
+ *
5
+ * Supports two formats:
6
+ * 1. Inline: ->relay:<target> <message> (single line, start of line only)
7
+ * 2. Block: [[RELAY]]{ json }[[/RELAY]] (multi-line, structured)
8
+ *
9
+ * Rules:
10
+ * - Inline only matches at start of line (after whitespace)
11
+ * - Ignores content inside code fences
12
+ * - Escape with \->relay: to output literal
13
+ * - Block format is preferred for structured data
14
+ */
15
+ import type { PayloadKind } from '@agent-relay/protocol/types';
16
+ export interface ParsedCommand {
17
+ to: string;
18
+ kind: PayloadKind;
19
+ body: string;
20
+ data?: Record<string, unknown>;
21
+ /** Optional thread ID for grouping related messages */
22
+ thread?: string;
23
+ /** Optional project for cross-project messaging (e.g., ->relay:project:agent) */
24
+ project?: string;
25
+ /** Optional thread project for cross-project threads (e.g., [thread:project:id]) */
26
+ threadProject?: string;
27
+ /** Optional sync metadata parsed from [await] */
28
+ sync?: {
29
+ blocking: boolean;
30
+ timeoutMs?: number;
31
+ };
32
+ raw: string;
33
+ meta?: ParsedMessageMetadata;
34
+ }
35
+ export interface ParserOptions {
36
+ maxBlockBytes?: number;
37
+ enableInline?: boolean;
38
+ enableBlock?: boolean;
39
+ /** Relay prefix pattern (default: '->relay:') */
40
+ prefix?: string;
41
+ /** Thinking prefix pattern (default: '->thinking:') */
42
+ thinkingPrefix?: string;
43
+ }
44
+ /**
45
+ * Check if a target name is a placeholder commonly used in documentation/examples.
46
+ * These should not be treated as real message targets.
47
+ */
48
+ export declare function isPlaceholderTarget(target: string): boolean;
49
+ export declare class OutputParser {
50
+ private options;
51
+ private inCodeFence;
52
+ private inBlock;
53
+ private blockBuffer;
54
+ private blockType;
55
+ private lastParsedMetadata;
56
+ private inThinkingBlock;
57
+ private inFencedInline;
58
+ private fencedInlineBuffer;
59
+ private fencedInlineTarget;
60
+ private fencedInlineThread;
61
+ private fencedInlineThreadProject;
62
+ private fencedInlineProject;
63
+ private fencedInlineRaw;
64
+ private fencedInlineKind;
65
+ private fencedInlineSync;
66
+ private inlineRelayPattern;
67
+ private inlineThinkingPattern;
68
+ private fencedRelayPattern;
69
+ private fencedThinkingPattern;
70
+ private escapePattern;
71
+ constructor(options?: ParserOptions);
72
+ /**
73
+ * Get the configured relay prefix
74
+ */
75
+ get prefix(): string;
76
+ /**
77
+ * Push data into the parser and extract commands.
78
+ * Returns array of parsed commands and cleaned output.
79
+ *
80
+ * Design: Pass through data with minimal buffering to preserve terminal rendering.
81
+ * Only buffer content when inside [[RELAY]]...[[/RELAY]] blocks.
82
+ */
83
+ parse(data: string): {
84
+ commands: ParsedCommand[];
85
+ output: string;
86
+ };
87
+ /**
88
+ * Find [[RELAY_METADATA]] or [[RELAY]] that's at the start of a line and not inside a code fence.
89
+ * Returns the index and identifier, or -1 and null if not found.
90
+ */
91
+ private findBlockStart;
92
+ /**
93
+ * Parse data in pass-through mode - TRUE pass-through for terminal rendering.
94
+ * Output is exactly the input data, minus any relay command lines found in this chunk.
95
+ * No cross-chunk buffering to avoid double-output issues.
96
+ *
97
+ * IMPORTANT: We ONLY parse complete lines (i.e. those terminated by `\n` in the
98
+ * current chunk). The final unterminated line (if any) is passed through without
99
+ * parsing. This intentionally avoids cross-chunk detection when a line is split
100
+ * across chunks.
101
+ */
102
+ private parsePassThrough;
103
+ /**
104
+ * Parse while inside a [[RELAY]] block - buffer until we see [[/RELAY]].
105
+ */
106
+ private parseInBlockMode;
107
+ /**
108
+ * Process a single complete line for inline relay commands.
109
+ * Block handling is done at the parse() level, not here.
110
+ *
111
+ * IMPORTANT: We strip ANSI codes for pattern matching, but preserve
112
+ * the original line for output to maintain terminal rendering.
113
+ *
114
+ * OPTIMIZATION: Early exit for lines that can't possibly be relay commands.
115
+ * Most lines don't contain relay patterns, so we avoid expensive regex/ANSI
116
+ * stripping for the common case.
117
+ */
118
+ private processLine;
119
+ /**
120
+ * Finish processing a block and extract command.
121
+ * Returns the command (if valid) and any remaining content after [[/RELAY]].
122
+ */
123
+ private finishBlock;
124
+ /**
125
+ * Check if the current fenced inline command should be filtered out.
126
+ * Returns true if the command looks like instructional/example text.
127
+ */
128
+ private shouldFilterFencedInline;
129
+ /**
130
+ * Parse while inside a fenced inline block (->relay:Target <<< ... >>>).
131
+ * Accumulates lines until >>> is seen on its own line.
132
+ */
133
+ private parseFencedInlineMode;
134
+ /**
135
+ * Flush any remaining buffer (call on stream end).
136
+ */
137
+ flush(): {
138
+ commands: ParsedCommand[];
139
+ output: string;
140
+ };
141
+ /**
142
+ * Reset parser state.
143
+ */
144
+ reset(): void;
145
+ }
146
+ /**
147
+ * Parsed message metadata block from agent output.
148
+ */
149
+ export interface ParsedMessageMetadata {
150
+ subject?: string;
151
+ importance?: number;
152
+ replyTo?: string;
153
+ ackRequired?: boolean;
154
+ }
155
+ /**
156
+ * Result of attempting to parse a RELAY_METADATA block.
157
+ */
158
+ export interface MetadataParseResult {
159
+ found: boolean;
160
+ valid: boolean;
161
+ metadata: ParsedMessageMetadata | null;
162
+ rawContent: string | null;
163
+ }
164
+ /**
165
+ * Parse [[RELAY_METADATA]]...[[/RELAY_METADATA]] blocks from agent output.
166
+ * Agents can output metadata to enhance messages.
167
+ *
168
+ * Format:
169
+ * [[RELAY_METADATA]]
170
+ * {
171
+ * "subject": "Task update",
172
+ * "importance": 80,
173
+ * "replyTo": "msg-abc123",
174
+ * "ackRequired": true
175
+ * }
176
+ * [[/RELAY_METADATA]]
177
+ */
178
+ export declare function parseRelayMetadataFromOutput(output: string): MetadataParseResult;
179
+ /**
180
+ * Parsed summary block from agent output.
181
+ */
182
+ export interface ParsedSummary {
183
+ currentTask?: string;
184
+ completedTasks?: string[];
185
+ decisions?: string[];
186
+ context?: string;
187
+ files?: string[];
188
+ }
189
+ /**
190
+ * Result of attempting to parse a SUMMARY block.
191
+ */
192
+ export interface SummaryParseResult {
193
+ found: boolean;
194
+ valid: boolean;
195
+ summary: ParsedSummary | null;
196
+ rawContent: string | null;
197
+ }
198
+ /**
199
+ * Parse [[SUMMARY]]...[[/SUMMARY]] blocks from agent output.
200
+ * Agents can output summaries to keep a running context of their work.
201
+ *
202
+ * Format:
203
+ * [[SUMMARY]]
204
+ * {
205
+ * "currentTask": "Working on auth module",
206
+ * "context": "Completed login flow, now implementing logout",
207
+ * "files": ["src/auth.ts", "src/session.ts"]
208
+ * }
209
+ * [[/SUMMARY]]
210
+ */
211
+ export declare function parseSummaryFromOutput(output: string): ParsedSummary | null;
212
+ /**
213
+ * Parse SUMMARY block with full details for deduplication.
214
+ * Returns raw content to allow caller to dedupe before logging errors.
215
+ */
216
+ export declare function parseSummaryWithDetails(output: string): SummaryParseResult;
217
+ /**
218
+ * Session end marker from agent output.
219
+ */
220
+ export interface SessionEndMarker {
221
+ summary?: string;
222
+ completedTasks?: string[];
223
+ }
224
+ /**
225
+ * Parse [[SESSION_END]]...[[/SESSION_END]] blocks from agent output.
226
+ * Agents output this to explicitly mark their session as complete.
227
+ *
228
+ * Format:
229
+ * [[SESSION_END]]
230
+ * {"summary": "Completed auth module implementation", "completedTasks": ["login", "logout"]}
231
+ * [[/SESSION_END]]
232
+ *
233
+ * Or simply: [[SESSION_END]][[/SESSION_END]] for a clean close without summary.
234
+ */
235
+ export declare function parseSessionEndFromOutput(output: string): SessionEndMarker | null;
236
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,IAAI,CAAC,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,qBAAqB,CAAC;CAC9B;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB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