@a5c-ai/agent-comm-mux 5.0.1-staging.04ca6ab00d21

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 (263) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -0
  3. package/dist/adapter-registry.d.ts +51 -0
  4. package/dist/adapter-registry.d.ts.map +1 -0
  5. package/dist/adapter-registry.js +208 -0
  6. package/dist/adapter-registry.js.map +1 -0
  7. package/dist/adapter-types.d.ts +164 -0
  8. package/dist/adapter-types.d.ts.map +1 -0
  9. package/dist/adapter-types.js +27 -0
  10. package/dist/adapter-types.js.map +1 -0
  11. package/dist/adapter.d.ts +248 -0
  12. package/dist/adapter.d.ts.map +1 -0
  13. package/dist/adapter.js +18 -0
  14. package/dist/adapter.js.map +1 -0
  15. package/dist/atomic-fs.d.ts +33 -0
  16. package/dist/atomic-fs.d.ts.map +1 -0
  17. package/dist/atomic-fs.js +190 -0
  18. package/dist/atomic-fs.js.map +1 -0
  19. package/dist/auth-manager.d.ts +37 -0
  20. package/dist/auth-manager.d.ts.map +1 -0
  21. package/dist/auth-manager.js +94 -0
  22. package/dist/auth-manager.js.map +1 -0
  23. package/dist/auth-types.d.ts +83 -0
  24. package/dist/auth-types.d.ts.map +1 -0
  25. package/dist/auth-types.js +10 -0
  26. package/dist/auth-types.js.map +1 -0
  27. package/dist/automation.d.ts +104 -0
  28. package/dist/automation.d.ts.map +1 -0
  29. package/dist/automation.js +2 -0
  30. package/dist/automation.js.map +1 -0
  31. package/dist/browser.d.ts +5 -0
  32. package/dist/browser.d.ts.map +1 -0
  33. package/dist/browser.js +2 -0
  34. package/dist/browser.js.map +1 -0
  35. package/dist/builtin-hooks.d.ts +24 -0
  36. package/dist/builtin-hooks.d.ts.map +1 -0
  37. package/dist/builtin-hooks.js +80 -0
  38. package/dist/builtin-hooks.js.map +1 -0
  39. package/dist/capabilities.d.ts +251 -0
  40. package/dist/capabilities.d.ts.map +1 -0
  41. package/dist/capabilities.js +7 -0
  42. package/dist/capabilities.js.map +1 -0
  43. package/dist/client.d.ts +118 -0
  44. package/dist/client.d.ts.map +1 -0
  45. package/dist/client.js +316 -0
  46. package/dist/client.js.map +1 -0
  47. package/dist/config-manager.d.ts +85 -0
  48. package/dist/config-manager.d.ts.map +1 -0
  49. package/dist/config-manager.js +202 -0
  50. package/dist/config-manager.js.map +1 -0
  51. package/dist/config-types.d.ts +134 -0
  52. package/dist/config-types.d.ts.map +1 -0
  53. package/dist/config-types.js +10 -0
  54. package/dist/config-types.js.map +1 -0
  55. package/dist/cost-utils.d.ts +31 -0
  56. package/dist/cost-utils.d.ts.map +1 -0
  57. package/dist/cost-utils.js +69 -0
  58. package/dist/cost-utils.js.map +1 -0
  59. package/dist/errors.d.ts +50 -0
  60. package/dist/errors.d.ts.map +1 -0
  61. package/dist/errors.js +85 -0
  62. package/dist/errors.js.map +1 -0
  63. package/dist/events-control.d.ts +91 -0
  64. package/dist/events-control.d.ts.map +1 -0
  65. package/dist/events-control.js +8 -0
  66. package/dist/events-control.js.map +1 -0
  67. package/dist/events.d.ts +285 -0
  68. package/dist/events.d.ts.map +1 -0
  69. package/dist/events.js +8 -0
  70. package/dist/events.js.map +1 -0
  71. package/dist/hook-catalog.d.ts +20 -0
  72. package/dist/hook-catalog.d.ts.map +1 -0
  73. package/dist/hook-catalog.js +63 -0
  74. package/dist/hook-catalog.js.map +1 -0
  75. package/dist/hook-dispatcher.d.ts +24 -0
  76. package/dist/hook-dispatcher.d.ts.map +1 -0
  77. package/dist/hook-dispatcher.js +91 -0
  78. package/dist/hook-dispatcher.js.map +1 -0
  79. package/dist/hook-payload.d.ts +24 -0
  80. package/dist/hook-payload.d.ts.map +1 -0
  81. package/dist/hook-payload.js +62 -0
  82. package/dist/hook-payload.js.map +1 -0
  83. package/dist/hooks.d.ts +59 -0
  84. package/dist/hooks.d.ts.map +1 -0
  85. package/dist/hooks.js +118 -0
  86. package/dist/hooks.js.map +1 -0
  87. package/dist/host-detection.d.ts +67 -0
  88. package/dist/host-detection.d.ts.map +1 -0
  89. package/dist/host-detection.js +147 -0
  90. package/dist/host-detection.js.map +1 -0
  91. package/dist/index.d.ts +88 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +50 -0
  94. package/dist/index.js.map +1 -0
  95. package/dist/interaction-channel-impl.d.ts +56 -0
  96. package/dist/interaction-channel-impl.d.ts.map +1 -0
  97. package/dist/interaction-channel-impl.js +159 -0
  98. package/dist/interaction-channel-impl.js.map +1 -0
  99. package/dist/interaction.d.ts +93 -0
  100. package/dist/interaction.d.ts.map +1 -0
  101. package/dist/interaction.js +8 -0
  102. package/dist/interaction.js.map +1 -0
  103. package/dist/invocation.d.ts +100 -0
  104. package/dist/invocation.d.ts.map +1 -0
  105. package/dist/invocation.js +17 -0
  106. package/dist/invocation.js.map +1 -0
  107. package/dist/kanban.d.ts +894 -0
  108. package/dist/kanban.d.ts.map +1 -0
  109. package/dist/kanban.js +1155 -0
  110. package/dist/kanban.js.map +1 -0
  111. package/dist/merge.d.ts +37 -0
  112. package/dist/merge.d.ts.map +1 -0
  113. package/dist/merge.js +102 -0
  114. package/dist/merge.js.map +1 -0
  115. package/dist/model-registry.d.ts +61 -0
  116. package/dist/model-registry.d.ts.map +1 -0
  117. package/dist/model-registry.js +198 -0
  118. package/dist/model-registry.js.map +1 -0
  119. package/dist/plugin-manager-impl.d.ts +48 -0
  120. package/dist/plugin-manager-impl.d.ts.map +1 -0
  121. package/dist/plugin-manager-impl.js +343 -0
  122. package/dist/plugin-manager-impl.js.map +1 -0
  123. package/dist/plugin-manager.d.ts +81 -0
  124. package/dist/plugin-manager.d.ts.map +1 -0
  125. package/dist/plugin-manager.js +7 -0
  126. package/dist/plugin-manager.js.map +1 -0
  127. package/dist/plugin-types.d.ts +114 -0
  128. package/dist/plugin-types.d.ts.map +1 -0
  129. package/dist/plugin-types.js +7 -0
  130. package/dist/plugin-types.js.map +1 -0
  131. package/dist/process-tracker.d.ts +20 -0
  132. package/dist/process-tracker.d.ts.map +1 -0
  133. package/dist/process-tracker.js +96 -0
  134. package/dist/process-tracker.js.map +1 -0
  135. package/dist/profiles.d.ts +99 -0
  136. package/dist/profiles.d.ts.map +1 -0
  137. package/dist/profiles.js +231 -0
  138. package/dist/profiles.js.map +1 -0
  139. package/dist/programmatic-runner.d.ts +4 -0
  140. package/dist/programmatic-runner.d.ts.map +1 -0
  141. package/dist/programmatic-runner.js +110 -0
  142. package/dist/programmatic-runner.js.map +1 -0
  143. package/dist/provider-config.d.ts +40 -0
  144. package/dist/provider-config.d.ts.map +1 -0
  145. package/dist/provider-config.js +67 -0
  146. package/dist/provider-config.js.map +1 -0
  147. package/dist/provider-profiles.d.ts +47 -0
  148. package/dist/provider-profiles.d.ts.map +1 -0
  149. package/dist/provider-profiles.js +117 -0
  150. package/dist/provider-profiles.js.map +1 -0
  151. package/dist/provider-resolver.d.ts +15 -0
  152. package/dist/provider-resolver.d.ts.map +1 -0
  153. package/dist/provider-resolver.js +114 -0
  154. package/dist/provider-resolver.js.map +1 -0
  155. package/dist/provider-support-matrix.d.ts +12 -0
  156. package/dist/provider-support-matrix.d.ts.map +1 -0
  157. package/dist/provider-support-matrix.js +88 -0
  158. package/dist/provider-support-matrix.js.map +1 -0
  159. package/dist/remote-runner.d.ts +4 -0
  160. package/dist/remote-runner.d.ts.map +1 -0
  161. package/dist/remote-runner.js +114 -0
  162. package/dist/remote-runner.js.map +1 -0
  163. package/dist/retry.d.ts +13 -0
  164. package/dist/retry.d.ts.map +1 -0
  165. package/dist/retry.js +17 -0
  166. package/dist/retry.js.map +1 -0
  167. package/dist/run-handle-cost.d.ts +36 -0
  168. package/dist/run-handle-cost.d.ts.map +1 -0
  169. package/dist/run-handle-cost.js +62 -0
  170. package/dist/run-handle-cost.js.map +1 -0
  171. package/dist/run-handle-impl.d.ts +144 -0
  172. package/dist/run-handle-impl.d.ts.map +1 -0
  173. package/dist/run-handle-impl.js +695 -0
  174. package/dist/run-handle-impl.js.map +1 -0
  175. package/dist/run-handle.d.ts +222 -0
  176. package/dist/run-handle.d.ts.map +1 -0
  177. package/dist/run-handle.js +9 -0
  178. package/dist/run-handle.js.map +1 -0
  179. package/dist/run-options-validation.d.ts +23 -0
  180. package/dist/run-options-validation.d.ts.map +1 -0
  181. package/dist/run-options-validation.js +234 -0
  182. package/dist/run-options-validation.js.map +1 -0
  183. package/dist/run-options.d.ts +128 -0
  184. package/dist/run-options.d.ts.map +1 -0
  185. package/dist/run-options.js +329 -0
  186. package/dist/run-options.js.map +1 -0
  187. package/dist/runtime-hook-dispatcher.d.ts +19 -0
  188. package/dist/runtime-hook-dispatcher.d.ts.map +1 -0
  189. package/dist/runtime-hook-dispatcher.js +50 -0
  190. package/dist/runtime-hook-dispatcher.js.map +1 -0
  191. package/dist/runtime-hooks.d.ts +47 -0
  192. package/dist/runtime-hooks.d.ts.map +1 -0
  193. package/dist/runtime-hooks.js +2 -0
  194. package/dist/runtime-hooks.js.map +1 -0
  195. package/dist/schema/__tests__/event-schema.test.d.ts +1 -0
  196. package/dist/schema/__tests__/event-schema.test.d.ts.map +1 -0
  197. package/dist/schema/__tests__/event-schema.test.js +480 -0
  198. package/dist/schema/__tests__/event-schema.test.js.map +1 -0
  199. package/dist/schema/event-schema.d.ts +120 -0
  200. package/dist/schema/event-schema.d.ts.map +1 -0
  201. package/dist/schema/event-schema.js +546 -0
  202. package/dist/schema/event-schema.js.map +1 -0
  203. package/dist/schema/index.d.ts +7 -0
  204. package/dist/schema/index.d.ts.map +1 -0
  205. package/dist/schema/index.js +49 -0
  206. package/dist/schema/index.js.map +1 -0
  207. package/dist/session-manager-helpers.d.ts +33 -0
  208. package/dist/session-manager-helpers.d.ts.map +1 -0
  209. package/dist/session-manager-helpers.js +66 -0
  210. package/dist/session-manager-helpers.js.map +1 -0
  211. package/dist/session-manager.d.ts +70 -0
  212. package/dist/session-manager.d.ts.map +1 -0
  213. package/dist/session-manager.js +343 -0
  214. package/dist/session-manager.js.map +1 -0
  215. package/dist/session-types.d.ts +358 -0
  216. package/dist/session-types.d.ts.map +1 -0
  217. package/dist/session-types.js +10 -0
  218. package/dist/session-types.js.map +1 -0
  219. package/dist/spawn-invocation.d.ts +52 -0
  220. package/dist/spawn-invocation.d.ts.map +1 -0
  221. package/dist/spawn-invocation.js +218 -0
  222. package/dist/spawn-invocation.js.map +1 -0
  223. package/dist/spawn-runner-utils.d.ts +21 -0
  224. package/dist/spawn-runner-utils.d.ts.map +1 -0
  225. package/dist/spawn-runner-utils.js +102 -0
  226. package/dist/spawn-runner-utils.js.map +1 -0
  227. package/dist/spawn-runner.d.ts +21 -0
  228. package/dist/spawn-runner.d.ts.map +1 -0
  229. package/dist/spawn-runner.js +576 -0
  230. package/dist/spawn-runner.js.map +1 -0
  231. package/dist/spawn-runtime-hooks.d.ts +15 -0
  232. package/dist/spawn-runtime-hooks.d.ts.map +1 -0
  233. package/dist/spawn-runtime-hooks.js +136 -0
  234. package/dist/spawn-runtime-hooks.js.map +1 -0
  235. package/dist/state-machine.d.ts +33 -0
  236. package/dist/state-machine.d.ts.map +1 -0
  237. package/dist/state-machine.js +61 -0
  238. package/dist/state-machine.js.map +1 -0
  239. package/dist/storage.d.ts +47 -0
  240. package/dist/storage.d.ts.map +1 -0
  241. package/dist/storage.js +90 -0
  242. package/dist/storage.js.map +1 -0
  243. package/dist/stream-assembler.d.ts +51 -0
  244. package/dist/stream-assembler.d.ts.map +1 -0
  245. package/dist/stream-assembler.js +86 -0
  246. package/dist/stream-assembler.js.map +1 -0
  247. package/dist/tools/classify.d.ts +9 -0
  248. package/dist/tools/classify.d.ts.map +1 -0
  249. package/dist/tools/classify.js +77 -0
  250. package/dist/tools/classify.js.map +1 -0
  251. package/dist/tools/index.d.ts +2 -0
  252. package/dist/tools/index.d.ts.map +1 -0
  253. package/dist/tools/index.js +2 -0
  254. package/dist/tools/index.js.map +1 -0
  255. package/dist/types.d.ts +288 -0
  256. package/dist/types.d.ts.map +1 -0
  257. package/dist/types.js +8 -0
  258. package/dist/types.js.map +1 -0
  259. package/dist/workspaces.d.ts +142 -0
  260. package/dist/workspaces.d.ts.map +1 -0
  261. package/dist/workspaces.js +515 -0
  262. package/dist/workspaces.js.map +1 -0
  263. package/package.json +107 -0
@@ -0,0 +1,358 @@
1
+ /**
2
+ * Session-related types for @a5c-ai/agent-mux.
3
+ *
4
+ * Defines the data structures for session summaries, messages, tool calls,
5
+ * queries, cost aggregation, and session diffs.
6
+ *
7
+ * @see 07-session-manager.md
8
+ */
9
+ import type { AgentName, CostRecord } from './types.js';
10
+ import type { WorkspaceSessionContext } from './workspaces.js';
11
+ /** A tool call within a session message. */
12
+ export interface SessionToolCall {
13
+ /** Tool call ID (agent-assigned). */
14
+ readonly toolCallId: string;
15
+ /** Name of the tool that was called. */
16
+ readonly toolName: string;
17
+ /** Input arguments passed to the tool. */
18
+ readonly input: unknown;
19
+ /** Tool output, if available. */
20
+ readonly output?: unknown;
21
+ /** Duration of the tool call in milliseconds, if recorded. */
22
+ readonly durationMs?: number;
23
+ }
24
+ /** A single message within a session. */
25
+ export interface SessionMessage {
26
+ /** Role of the message author. */
27
+ readonly role: 'user' | 'assistant' | 'system' | 'tool';
28
+ /** Text content of the message. Empty string for tool-only messages. */
29
+ readonly content: string;
30
+ /** Timestamp when this message was recorded. */
31
+ readonly timestamp?: Date;
32
+ /** Tool calls initiated by this message (assistant role only). */
33
+ readonly toolCalls?: SessionToolCall[];
34
+ /** Tool result (tool role only). */
35
+ readonly toolResult?: {
36
+ readonly toolCallId: string;
37
+ readonly toolName: string;
38
+ readonly output: unknown;
39
+ };
40
+ /** Token usage for this message, if available. */
41
+ readonly tokenUsage?: {
42
+ readonly inputTokens: number;
43
+ readonly outputTokens: number;
44
+ readonly thinkingTokens?: number;
45
+ readonly cachedTokens?: number;
46
+ };
47
+ /** Cost for this individual message, if available. */
48
+ readonly cost?: CostRecord;
49
+ /** Thinking/reasoning content, if the agent exposed it. */
50
+ readonly thinking?: string;
51
+ /** Model used for this specific message (may differ within a session). */
52
+ readonly model?: string;
53
+ }
54
+ export interface WorkspaceRuntimeDeviceProfile {
55
+ readonly id: 'desktop' | 'tablet' | 'mobile';
56
+ readonly label: string;
57
+ readonly width: number;
58
+ readonly height: number;
59
+ }
60
+ export interface WorkspaceRuntimeLogLine {
61
+ readonly timestamp: number;
62
+ readonly stream: 'stdout' | 'stderr' | 'system';
63
+ readonly text: string;
64
+ }
65
+ export interface WorkspaceTerminalCommand {
66
+ readonly id: string;
67
+ readonly runId: string;
68
+ readonly source: 'shell' | 'tool';
69
+ readonly toolName?: string;
70
+ readonly command: string;
71
+ readonly status: 'running' | 'completed' | 'failed';
72
+ readonly startedAt: number;
73
+ readonly endedAt?: number;
74
+ readonly exitCode?: number;
75
+ readonly logs: readonly WorkspaceRuntimeLogLine[];
76
+ }
77
+ export interface WorkspacePreviewSurface {
78
+ readonly status: 'ready' | 'unavailable';
79
+ readonly primaryUrl?: string;
80
+ readonly urls: readonly string[];
81
+ readonly detectedAt?: number;
82
+ readonly deviceProfiles: readonly WorkspaceRuntimeDeviceProfile[];
83
+ }
84
+ export interface WorkspaceTerminalSurface {
85
+ readonly status: 'active' | 'idle';
86
+ readonly commands: readonly WorkspaceTerminalCommand[];
87
+ }
88
+ export interface WorkspaceDevServerSurface {
89
+ readonly status: 'running' | 'starting' | 'idle' | 'error';
90
+ readonly command?: string;
91
+ readonly primaryUrl?: string;
92
+ readonly urls: readonly string[];
93
+ readonly port?: number;
94
+ readonly detectedAt?: number;
95
+ readonly logs: readonly WorkspaceRuntimeLogLine[];
96
+ }
97
+ export type WorkspaceRebaseStatus = 'idle' | 'rebase-needed' | 'rebase-conflicts' | 'ready-for-review' | 'ready-for-merge';
98
+ export type WorkspaceRebaseLastAction = 'start' | 'auto-resolve' | 'open-in-editor' | 'manual-resolve' | 'abort';
99
+ export interface WorkspaceRebaseSurface {
100
+ readonly status: WorkspaceRebaseStatus;
101
+ readonly branch?: string;
102
+ readonly targetBranch?: string;
103
+ readonly attemptCount: number;
104
+ readonly unresolvedFiles: readonly string[];
105
+ readonly resolvedFiles: readonly string[];
106
+ readonly followUpInstructions: readonly string[];
107
+ readonly manualResolutionSuggested: boolean;
108
+ readonly readyFor: 'review' | 'merge';
109
+ readonly editorHref?: string;
110
+ readonly lastAction?: WorkspaceRebaseLastAction;
111
+ readonly persistedAt?: number;
112
+ }
113
+ export interface WorkspaceRuntimeSurface {
114
+ readonly workspacePath?: string;
115
+ readonly updatedAt: number;
116
+ readonly preview: WorkspacePreviewSurface;
117
+ readonly terminal: WorkspaceTerminalSurface;
118
+ readonly devServer: WorkspaceDevServerSurface;
119
+ readonly rebase?: WorkspaceRebaseSurface;
120
+ }
121
+ /** Lightweight session summary returned by list() and search(). */
122
+ export interface SessionSummary {
123
+ /** The agent that owns this session. */
124
+ readonly agent: AgentName;
125
+ /** The agent's native session identifier. */
126
+ readonly sessionId: string;
127
+ /** The deterministic unified ID: `<agent>:<sessionId>`. */
128
+ readonly unifiedId: string;
129
+ /** Human-readable session title. */
130
+ readonly title: string;
131
+ /** When the session was created. */
132
+ readonly createdAt: Date;
133
+ /** When the session was last modified. */
134
+ readonly updatedAt: Date;
135
+ /** Total number of conversational turns (user-assistant pairs). */
136
+ readonly turnCount: number;
137
+ /** Total number of messages (all roles). */
138
+ readonly messageCount: number;
139
+ /** Model ID used in the session. */
140
+ readonly model?: string;
141
+ /** Aggregated cost for the entire session, if available. */
142
+ readonly cost?: CostRecord;
143
+ /** Consumer-provided tags. */
144
+ readonly tags: string[];
145
+ /** Working directory at session start. */
146
+ readonly cwd?: string;
147
+ /** Workspace/worktree binding inferred or wrapped for this session. */
148
+ readonly workspace?: WorkspaceSessionContext;
149
+ /** Convenience alias for the bound workspace identifier, when known. */
150
+ readonly workspaceId?: string;
151
+ /** Whether this session was forked from another. */
152
+ readonly forkedFrom?: string;
153
+ /** Relevance score (0.0 to 1.0), present only in search results. */
154
+ readonly relevanceScore?: number;
155
+ /** Derived runtime surfaces for the session's workspace, when available. */
156
+ readonly runtime?: WorkspaceRuntimeSurface;
157
+ }
158
+ /** Full session object with all messages and metadata. */
159
+ export interface FullSession {
160
+ /** The agent that owns this session. */
161
+ readonly agent: AgentName;
162
+ /** The agent's native session identifier. */
163
+ readonly sessionId: string;
164
+ /** The deterministic unified ID: `<agent>:<sessionId>`. */
165
+ readonly unifiedId: string;
166
+ /** Human-readable session title. */
167
+ readonly title: string;
168
+ /** When the session was created. */
169
+ readonly createdAt: Date;
170
+ /** When the session was last modified. */
171
+ readonly updatedAt: Date;
172
+ /** Total number of conversational turns. */
173
+ readonly turnCount: number;
174
+ /** Model ID used in the session. */
175
+ readonly model?: string;
176
+ /** Aggregated cost for the entire session. */
177
+ readonly cost?: CostRecord;
178
+ /** Consumer-provided tags. */
179
+ readonly tags: string[];
180
+ /** Working directory at session start. */
181
+ readonly cwd?: string;
182
+ /** Workspace/worktree binding inferred or wrapped for this session. */
183
+ readonly workspace?: WorkspaceSessionContext;
184
+ /** Convenience alias for the bound workspace identifier, when known. */
185
+ readonly workspaceId?: string;
186
+ /** Parent session ID if forked. */
187
+ readonly forkedFrom?: string;
188
+ /** Derived runtime surfaces for the session's workspace, when available. */
189
+ readonly runtime?: WorkspaceRuntimeSurface;
190
+ /** The ordered list of messages in this session. */
191
+ readonly messages: SessionMessage[];
192
+ /** Raw session data in the agent's native format. */
193
+ readonly raw?: unknown;
194
+ }
195
+ /**
196
+ * Parsed session data returned by adapter.parseSessionFile().
197
+ *
198
+ * This is the adapter-level type. The SessionManager wraps it into
199
+ * a FullSession with unified IDs.
200
+ */
201
+ export interface Session {
202
+ /** Session identifier. */
203
+ readonly sessionId: string;
204
+ /** Agent that owns this session. */
205
+ readonly agent: AgentName;
206
+ /** Number of turns in the session. */
207
+ readonly turnCount: number;
208
+ /** When the session was created (ISO 8601). */
209
+ readonly createdAt: string;
210
+ /** When the session was last updated (ISO 8601). */
211
+ readonly updatedAt: string;
212
+ /** Human-readable session title. */
213
+ readonly title?: string;
214
+ /** Model used in the session. */
215
+ readonly model?: string;
216
+ /** Aggregated cost for the session. */
217
+ readonly cost?: CostRecord;
218
+ /** Consumer-provided tags. */
219
+ readonly tags?: string[];
220
+ /** Working directory at session start. */
221
+ readonly cwd?: string;
222
+ /** Workspace/worktree binding inferred or wrapped for this session. */
223
+ readonly workspace?: WorkspaceSessionContext;
224
+ /** Convenience alias for the bound workspace identifier, when known. */
225
+ readonly workspaceId?: string;
226
+ /** Parent session ID if forked. */
227
+ readonly forkedFrom?: string;
228
+ /** Parsed messages, if available. */
229
+ readonly messages?: SessionMessage[];
230
+ /** Raw session data. */
231
+ readonly raw?: unknown;
232
+ }
233
+ /** Options for the list() method. */
234
+ export interface SessionListOptions {
235
+ /** Only include sessions created on or after this date. */
236
+ readonly since?: Date;
237
+ /** Only include sessions created on or before this date. */
238
+ readonly until?: Date;
239
+ /** Filter to sessions that used a specific model. */
240
+ readonly model?: string;
241
+ /** Filter to sessions with any of the specified tags. */
242
+ readonly tags?: string[];
243
+ /** Maximum number of results to return. Default: 100. */
244
+ readonly limit?: number;
245
+ /** Sort field. Default: 'date'. */
246
+ readonly sort?: 'date' | 'cost' | 'turns';
247
+ /** Sort direction. Default: 'desc'. */
248
+ readonly sortDirection?: 'asc' | 'desc';
249
+ /** Filter to sessions started in a specific working directory. */
250
+ readonly cwd?: string;
251
+ }
252
+ /** Parameters for the search() method. */
253
+ export interface SessionQuery {
254
+ /** Free-text search string. */
255
+ readonly text: string;
256
+ /** Restrict search to a single agent. */
257
+ readonly agent?: AgentName;
258
+ /** Only include sessions created on or after this date. */
259
+ readonly since?: Date;
260
+ /** Only include sessions created on or before this date. */
261
+ readonly until?: Date;
262
+ /** Filter by model ID. */
263
+ readonly model?: string;
264
+ /** Filter by tags (OR match). */
265
+ readonly tags?: string[];
266
+ /** Maximum number of results. Default: 50. */
267
+ readonly limit?: number;
268
+ /** Sort order. Default: 'relevance'. */
269
+ readonly sort?: 'relevance' | 'date' | 'cost';
270
+ }
271
+ /** Parameters for cost aggregation. */
272
+ export interface CostAggregationOptions {
273
+ /** Restrict to a single agent. */
274
+ readonly agent?: AgentName;
275
+ /** Only include sessions on or after this date. */
276
+ readonly since?: Date;
277
+ /** Only include sessions on or before this date. */
278
+ readonly until?: Date;
279
+ /** Filter by model ID. */
280
+ readonly model?: string;
281
+ /** Filter by tags. */
282
+ readonly tags?: string[];
283
+ /** Group results by dimension. */
284
+ readonly groupBy?: 'agent' | 'model' | 'day' | 'tag';
285
+ }
286
+ /** Aggregated cost summary. */
287
+ export interface CostSummary {
288
+ /** Total cost in USD. */
289
+ totalUsd: number;
290
+ /** Total input tokens. */
291
+ inputTokens: number;
292
+ /** Total output tokens. */
293
+ outputTokens: number;
294
+ /** Total thinking tokens. */
295
+ thinkingTokens: number;
296
+ /** Total cached tokens. */
297
+ cachedTokens: number;
298
+ /** Sessions in aggregation. */
299
+ sessionCount: number;
300
+ /** Runs in aggregation. */
301
+ runCount: number;
302
+ /** Per-group breakdowns when groupBy is set. */
303
+ breakdowns?: Record<string, CostBreakdown>;
304
+ }
305
+ /** Cost breakdown for a single group. */
306
+ export interface CostBreakdown {
307
+ /** Group key. */
308
+ readonly key: string;
309
+ /** Total cost in USD for this group. */
310
+ totalUsd: number;
311
+ /** Input tokens for this group. */
312
+ inputTokens: number;
313
+ /** Output tokens for this group. */
314
+ outputTokens: number;
315
+ /** Thinking tokens for this group. */
316
+ thinkingTokens: number;
317
+ /** Cached tokens for this group. */
318
+ cachedTokens: number;
319
+ /** Sessions in this group. */
320
+ sessionCount: number;
321
+ }
322
+ /** Structural diff between two sessions. */
323
+ export interface SessionDiff {
324
+ /** Reference to the first session. */
325
+ readonly a: {
326
+ readonly agent: AgentName;
327
+ readonly sessionId: string;
328
+ readonly unifiedId: string;
329
+ };
330
+ /** Reference to the second session. */
331
+ readonly b: {
332
+ readonly agent: AgentName;
333
+ readonly sessionId: string;
334
+ readonly unifiedId: string;
335
+ };
336
+ /** Ordered list of diff operations. */
337
+ readonly operations: DiffOperation[];
338
+ /** Summary statistics. */
339
+ readonly summary: {
340
+ readonly added: number;
341
+ readonly removed: number;
342
+ readonly modified: number;
343
+ readonly unchanged: number;
344
+ };
345
+ }
346
+ /** A single diff operation describing a structural difference. */
347
+ export interface DiffOperation {
348
+ /** Type of change. */
349
+ readonly type: 'added' | 'removed' | 'modified' | 'unchanged';
350
+ /** Zero-based index in session A (undefined for additions). */
351
+ readonly indexA?: number;
352
+ /** Zero-based index in session B (undefined for removals). */
353
+ readonly indexB?: number;
354
+ /** Message from session A (undefined for additions). */
355
+ readonly messageA?: SessionMessage;
356
+ /** Message from session B (undefined for removals). */
357
+ readonly messageB?: SessionMessage;
358
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-types.d.ts","sourceRoot":"","sources":["../src/session-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAM/D,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,iCAAiC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAE1B,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAMD,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;IAExD,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,gDAAgD;IAChD,QAAQ,CAAC,SAAS,CA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AAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAElG,uCAAuC;IACvC,QAAQ,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;IAErC,0BAA0B;IAC1B,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH;AAED,kEAAkE;AAClE,MAAM,WAAW,aAAa;IAC5B,sBAAsB;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;IAE9D,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAEnC,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;CACpC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Session-related types for @a5c-ai/agent-mux.
3
+ *
4
+ * Defines the data structures for session summaries, messages, tool calls,
5
+ * queries, cost aggregation, and session diffs.
6
+ *
7
+ * @see 07-session-manager.md
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=session-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-types.js","sourceRoot":"","sources":["../src/session-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Invocation mode dispatch for spawn-runner.
3
+ *
4
+ * Pure function `buildInvocationCommand` transforms a SpawnArgs + agent name
5
+ * into a concrete host command based on the invocation mode (local, docker,
6
+ * ssh, k8s). Split out of spawn-runner.ts for file-size hygiene — no
7
+ * behavior change.
8
+ */
9
+ import type { SpawnArgs } from './adapter.js';
10
+ import type { InvocationMode } from './invocation.js';
11
+ /** Result of applying an invocation mode to a SpawnArgs. */
12
+ export interface InvocationCommand {
13
+ /** The process to spawn on the host machine. */
14
+ command: string;
15
+ /** Arguments passed to the host process. */
16
+ args: string[];
17
+ /** Environment variables for the host process (union of host-inherited + inline). */
18
+ env: Record<string, string>;
19
+ /** Working directory for the host process. */
20
+ cwd: string;
21
+ /** Initial stdin (forwarded verbatim). */
22
+ stdin?: string;
23
+ /** Whether the host process requires shell mode. */
24
+ shell: boolean;
25
+ }
26
+ /**
27
+ * Transform a SpawnArgs + agent name into an InvocationCommand based on the
28
+ * invocation mode. This is a pure function — no subprocess is started.
29
+ *
30
+ * Modes:
31
+ * - local — returns spawnArgs unchanged (env merged).
32
+ * - docker — `docker run --rm -i [-v cwd:/workspace] [-w /workspace] [-e K=V]* <image> <cmd> <args...>`.
33
+ * - ssh — `ssh [-p N] [-i key] [user@]host -- cd <cwd> && <K=V> <cmd> <args...>`.
34
+ * - k8s — `kubectl [--context C] [-n NS] exec -i <pod> -- <K=V> <cmd> <args...>`.
35
+ */
36
+ export declare function buildInvocationCommand(mode: InvocationMode | undefined, spawnArgs: SpawnArgs, agent: string): InvocationCommandWithCleanup;
37
+ /**
38
+ * Describe the k8s cleanup action the caller should perform on abort/exit.
39
+ * For ephemeral `kubectl run --rm` invocations we still emit a best-effort
40
+ * `kubectl delete pod --grace-period=0` so abandoned pods don't linger when
41
+ * the local ssh/kubectl client is killed before `--rm` fires.
42
+ */
43
+ export interface K8sCleanup {
44
+ readonly command: 'kubectl';
45
+ readonly args: readonly string[];
46
+ }
47
+ /** Cleanup attached to an InvocationCommand built in k8s-ephemeral mode. */
48
+ export interface InvocationCommandWithCleanup extends InvocationCommand {
49
+ readonly cleanup?: K8sCleanup;
50
+ }
51
+ /** Fire-and-forget a cleanup command (detached, stdio ignored, unref'd). */
52
+ export declare function runCleanupDetached(cleanup: K8sCleanup): void;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn-invocation.d.ts","sourceRoot":"","sources":["../src/spawn-invocation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,iBAAiB,CAAC;AAOrE,4DAA4D;AAC5D,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,qFAAqF;IACrF,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,KAAK,EAAE,OAAO,CAAC;CAChB;AAQD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,cAAc,GAAG,SAAS,EAChC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,GACZ,4BAA4B,CAgG9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED,4EAA4E;AAC5E,MAAM,WAAW,4BAA6B,SAAQ,iBAAiB;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;CAC/B;AAED,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAY5D"}
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Invocation mode dispatch for spawn-runner.
3
+ *
4
+ * Pure function `buildInvocationCommand` transforms a SpawnArgs + agent name
5
+ * into a concrete host command based on the invocation mode (local, docker,
6
+ * ssh, k8s). Split out of spawn-runner.ts for file-size hygiene — no
7
+ * behavior change.
8
+ */
9
+ import { spawn } from 'node:child_process';
10
+ import { lookupHarnessImage } from './invocation.js';
11
+ /** Shell-quote a single argument for use in a remote shell (ssh/docker sh -c). */
12
+ function shQuote(arg) {
13
+ if (arg.length > 0 && /^[A-Za-z0-9_\-./=:@%+,]+$/.test(arg))
14
+ return arg;
15
+ return `'${arg.replace(/'/g, `'\\''`)}'`;
16
+ }
17
+ /**
18
+ * Transform a SpawnArgs + agent name into an InvocationCommand based on the
19
+ * invocation mode. This is a pure function — no subprocess is started.
20
+ *
21
+ * Modes:
22
+ * - local — returns spawnArgs unchanged (env merged).
23
+ * - docker — `docker run --rm -i [-v cwd:/workspace] [-w /workspace] [-e K=V]* <image> <cmd> <args...>`.
24
+ * - ssh — `ssh [-p N] [-i key] [user@]host -- cd <cwd> && <K=V> <cmd> <args...>`.
25
+ * - k8s — `kubectl [--context C] [-n NS] exec -i <pod> -- <K=V> <cmd> <args...>`.
26
+ */
27
+ export function buildInvocationCommand(mode, spawnArgs, agent) {
28
+ const baseEnv = { ...spawnArgs.env };
29
+ if (!mode || mode.mode === 'local') {
30
+ return {
31
+ command: spawnArgs.command,
32
+ args: [...spawnArgs.args],
33
+ env: baseEnv,
34
+ cwd: spawnArgs.cwd,
35
+ stdin: spawnArgs.stdin,
36
+ shell: spawnArgs.shell ?? false,
37
+ };
38
+ }
39
+ if (mode.mode === 'docker') {
40
+ const image = mode.image ?? lookupHarnessImage(agent)?.image;
41
+ if (!image) {
42
+ throw new Error(`DockerInvocation: no image specified and no default docker image found for agent "${agent}"`);
43
+ }
44
+ const workdir = mode.workdir ?? '/workspace';
45
+ const args = ['run', '--rm', '-i'];
46
+ // Mount the host cwd into the container at workdir.
47
+ args.push('-v', `${spawnArgs.cwd}:${workdir}`);
48
+ args.push('-w', workdir);
49
+ for (const vol of mode.volumes ?? []) {
50
+ args.push('-v', vol);
51
+ }
52
+ if (mode.network)
53
+ args.push('--network', mode.network);
54
+ // Merge adapter env and invocation env into -e flags.
55
+ const merged = { ...baseEnv, ...(mode.env ?? {}) };
56
+ for (const [k, v] of Object.entries(merged)) {
57
+ args.push('-e', `${k}=${v}`);
58
+ }
59
+ args.push(image);
60
+ args.push(spawnArgs.command, ...spawnArgs.args);
61
+ return {
62
+ command: 'docker',
63
+ args,
64
+ env: {},
65
+ cwd: spawnArgs.cwd,
66
+ stdin: spawnArgs.stdin,
67
+ shell: false,
68
+ };
69
+ }
70
+ if (mode.mode === 'ssh') {
71
+ const host = mode.host;
72
+ const args = [];
73
+ if (mode.port !== undefined)
74
+ args.push('-p', String(mode.port));
75
+ if (mode.identityFile)
76
+ args.push('-i', mode.identityFile);
77
+ // `-t` forces pseudo-tty allocation so SIGTERM/SIGINT are propagated from
78
+ // the local ssh client to the remote process group. Required for clean
79
+ // teardown of long-running harness CLIs; see spec 11.
80
+ args.push('-t');
81
+ // Don't hang indefinitely on host key prompts in tests; still honour user config otherwise.
82
+ args.push('-o', 'BatchMode=yes');
83
+ args.push(host);
84
+ // Build the remote command: "cd <dir> && K=V ... cmd arg1 arg2" wrapped in
85
+ // a shell that forwards TERM/INT to the spawned child and `exec`s away so
86
+ // signal delivery is a single hop. `$$` is the wrapper shell's pid; since
87
+ // we launch the real command in the background and `wait` on its pid, the
88
+ // trap can forward TERM to it precisely.
89
+ const remoteDir = mode.remoteDir ?? spawnArgs.cwd;
90
+ const envPrefix = Object.entries(baseEnv)
91
+ .map(([k, v]) => `${k}=${shQuote(v)}`)
92
+ .join(' ');
93
+ const cmdLine = [spawnArgs.command, ...spawnArgs.args].map(shQuote).join(' ');
94
+ const inner = `cd ${shQuote(remoteDir)} && ${envPrefix ? envPrefix + ' ' : ''}${cmdLine}`;
95
+ // POSIX-sh compatible PID-forwarding wrapper. Single-quoted so the remote
96
+ // shell expands $! / $pid, not the local one.
97
+ const wrapper = `exec /bin/sh -c '` +
98
+ `${inner.replace(/'/g, `'\\''`)} & ` +
99
+ `pid=$!; ` +
100
+ `trap "kill -TERM $pid 2>/dev/null" TERM INT; ` +
101
+ `wait $pid'`;
102
+ args.push('--', wrapper);
103
+ return {
104
+ command: 'ssh',
105
+ args,
106
+ env: {},
107
+ cwd: spawnArgs.cwd,
108
+ stdin: spawnArgs.stdin,
109
+ shell: false,
110
+ };
111
+ }
112
+ if (mode.mode === 'k8s') {
113
+ return buildK8sInvocation(mode, spawnArgs, agent, baseEnv);
114
+ }
115
+ // Exhaustiveness guard.
116
+ const _never = mode;
117
+ throw new Error(`Unknown invocation mode: ${JSON.stringify(_never)}`);
118
+ }
119
+ /** Fire-and-forget a cleanup command (detached, stdio ignored, unref'd). */
120
+ export function runCleanupDetached(cleanup) {
121
+ try {
122
+ const child = spawn(cleanup.command, [...cleanup.args], {
123
+ stdio: 'ignore',
124
+ shell: false,
125
+ detached: true,
126
+ });
127
+ child.on('error', () => { });
128
+ child.unref();
129
+ }
130
+ catch {
131
+ // best-effort
132
+ }
133
+ }
134
+ let k8sPodCounter = 0;
135
+ function generatePodName(agent) {
136
+ const safe = agent.toLowerCase().replace(/[^a-z0-9-]/g, '-').slice(0, 30) || 'agent';
137
+ const rand = Math.random().toString(36).slice(2, 8);
138
+ const seq = (++k8sPodCounter).toString(36);
139
+ return `amux-${safe}-${Date.now().toString(36)}-${seq}-${rand}`;
140
+ }
141
+ function buildK8sInvocation(mode, spawnArgs, agent, baseEnv) {
142
+ // Existing-pod mode: explicit `pod` (or legacy AMUX_K8S_POD) and ephemeral not true.
143
+ const envPodOverride = process.env['AMUX_K8S_POD'];
144
+ const wantsEphemeral = mode.ephemeral ?? (!mode.pod && !envPodOverride);
145
+ const namespace = mode.namespace;
146
+ if (!wantsEphemeral) {
147
+ const args = [];
148
+ if (mode.context)
149
+ args.push('--context', mode.context);
150
+ if (namespace)
151
+ args.push('-n', namespace);
152
+ args.push('exec', '-i');
153
+ const pod = mode.pod ?? envPodOverride ?? agent;
154
+ args.push(pod);
155
+ args.push('--');
156
+ const envEntries = Object.entries(baseEnv);
157
+ if (envEntries.length > 0) {
158
+ args.push('env');
159
+ for (const [k, v] of envEntries)
160
+ args.push(`${k}=${v}`);
161
+ }
162
+ args.push(spawnArgs.command, ...spawnArgs.args);
163
+ return {
164
+ command: 'kubectl',
165
+ args,
166
+ env: {},
167
+ cwd: spawnArgs.cwd,
168
+ stdin: spawnArgs.stdin,
169
+ shell: false,
170
+ };
171
+ }
172
+ // Ephemeral pod lifecycle: create + run + auto-delete.
173
+ const image = mode.image ?? lookupHarnessImage(agent)?.image;
174
+ if (!image) {
175
+ throw new Error(`K8sInvocation: no image specified and no default docker image found for agent "${agent}"`);
176
+ }
177
+ const podName = generatePodName(agent);
178
+ const args = [];
179
+ if (mode.context)
180
+ args.push('--context', mode.context);
181
+ if (namespace)
182
+ args.push('-n', namespace);
183
+ args.push('run', '--rm', '-i', '--restart=Never', `--image=${image}`, podName);
184
+ if (mode.serviceAccount)
185
+ args.push(`--serviceaccount=${mode.serviceAccount}`);
186
+ if (mode.podStartupTimeoutMs !== undefined) {
187
+ // kubectl expects a duration; ms -> seconds rounded up.
188
+ const secs = Math.max(1, Math.ceil(mode.podStartupTimeoutMs / 1000));
189
+ args.push(`--timeout=${secs}s`);
190
+ }
191
+ const limitParts = [];
192
+ if (mode.resources?.cpu)
193
+ limitParts.push(`cpu=${mode.resources.cpu}`);
194
+ if (mode.resources?.memory)
195
+ limitParts.push(`memory=${mode.resources.memory}`);
196
+ if (limitParts.length > 0)
197
+ args.push(`--limits=${limitParts.join(',')}`);
198
+ for (const [k, v] of Object.entries(baseEnv)) {
199
+ args.push(`--env=${k}=${v}`);
200
+ }
201
+ args.push('--', spawnArgs.command, ...spawnArgs.args);
202
+ const cleanupArgs = [];
203
+ if (mode.context)
204
+ cleanupArgs.push('--context', mode.context);
205
+ if (namespace)
206
+ cleanupArgs.push('-n', namespace);
207
+ cleanupArgs.push('delete', 'pod', podName, '--grace-period=0', '--ignore-not-found=true');
208
+ return {
209
+ command: 'kubectl',
210
+ args,
211
+ env: {},
212
+ cwd: spawnArgs.cwd,
213
+ stdin: spawnArgs.stdin,
214
+ shell: false,
215
+ cleanup: { command: 'kubectl', args: cleanupArgs },
216
+ };
217
+ }
218
+ //# sourceMappingURL=spawn-invocation.js.map