@agent-link/agent 0.1.338 → 0.1.340

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 (82) hide show
  1. package/dist/backends/types.d.ts +58 -0
  2. package/dist/backends/types.js +15 -4
  3. package/dist/backends/types.js.map +1 -1
  4. package/dist/connection.d.ts +2 -1
  5. package/dist/connection.js +279 -48
  6. package/dist/connection.js.map +1 -1
  7. package/dist/copilot-capabilities-offline.d.ts +254 -0
  8. package/dist/copilot-capabilities-offline.js +392 -0
  9. package/dist/copilot-capabilities-offline.js.map +1 -0
  10. package/dist/copilot-capabilities.d.ts +43 -0
  11. package/dist/copilot-capabilities.js +128 -0
  12. package/dist/copilot-capabilities.js.map +1 -0
  13. package/dist/copilot-capability-service.d.ts +24 -0
  14. package/dist/copilot-capability-service.js +116 -0
  15. package/dist/copilot-capability-service.js.map +1 -0
  16. package/dist/copilot-command-bridge.d.ts +184 -0
  17. package/dist/copilot-command-bridge.js +1800 -0
  18. package/dist/copilot-command-bridge.js.map +1 -0
  19. package/dist/copilot-compaction-barrier.d.ts +36 -0
  20. package/dist/copilot-compaction-barrier.js +152 -0
  21. package/dist/copilot-compaction-barrier.js.map +1 -0
  22. package/dist/copilot-compaction-lifecycle.d.ts +34 -0
  23. package/dist/copilot-compaction-lifecycle.js +88 -0
  24. package/dist/copilot-compaction-lifecycle.js.map +1 -0
  25. package/dist/copilot-compaction-policy.d.ts +5 -0
  26. package/dist/copilot-compaction-policy.js +7 -0
  27. package/dist/copilot-compaction-policy.js.map +1 -0
  28. package/dist/copilot-configuration.d.ts +63 -0
  29. package/dist/copilot-configuration.js +283 -0
  30. package/dist/copilot-configuration.js.map +1 -0
  31. package/dist/copilot-event-scope.d.ts +13 -0
  32. package/dist/copilot-event-scope.js +26 -0
  33. package/dist/copilot-event-scope.js.map +1 -0
  34. package/dist/copilot-fork-metadata.d.ts +9 -0
  35. package/dist/copilot-fork-metadata.js +86 -0
  36. package/dist/copilot-fork-metadata.js.map +1 -0
  37. package/dist/copilot-message-kind.d.ts +21 -0
  38. package/dist/copilot-message-kind.js +45 -0
  39. package/dist/copilot-message-kind.js.map +1 -0
  40. package/dist/copilot-plan-state.d.ts +19 -0
  41. package/dist/copilot-plan-state.js +180 -0
  42. package/dist/copilot-plan-state.js.map +1 -0
  43. package/dist/copilot-request-dispatch.d.ts +10 -0
  44. package/dist/copilot-request-dispatch.js +31 -0
  45. package/dist/copilot-request-dispatch.js.map +1 -0
  46. package/dist/copilot-review-documents.d.ts +17 -0
  47. package/dist/copilot-review-documents.js +162 -0
  48. package/dist/copilot-review-documents.js.map +1 -0
  49. package/dist/copilot-session-activity.d.ts +4 -0
  50. package/dist/copilot-session-activity.js +185 -0
  51. package/dist/copilot-session-activity.js.map +1 -0
  52. package/dist/copilot-sidecar.d.ts +2 -0
  53. package/dist/copilot-sidecar.js +17 -0
  54. package/dist/copilot-sidecar.js.map +1 -0
  55. package/dist/copilot-turn-journal.d.ts +36 -0
  56. package/dist/copilot-turn-journal.js +246 -0
  57. package/dist/copilot-turn-journal.js.map +1 -0
  58. package/dist/copilot-user-requests.d.ts +11 -0
  59. package/dist/copilot-user-requests.js +84 -0
  60. package/dist/copilot-user-requests.js.map +1 -0
  61. package/dist/copilot.d.ts +202 -9
  62. package/dist/copilot.js +5120 -243
  63. package/dist/copilot.js.map +1 -1
  64. package/dist/file-cache.d.ts +6 -1
  65. package/dist/file-cache.js +62 -1
  66. package/dist/file-cache.js.map +1 -1
  67. package/dist/history-message-transform.d.ts +47 -1
  68. package/dist/history-message-transform.js +67 -0
  69. package/dist/history-message-transform.js.map +1 -1
  70. package/dist/history.d.ts +8 -0
  71. package/dist/history.js.map +1 -1
  72. package/dist/provider-command-discovery.d.ts +5 -0
  73. package/dist/provider-command-discovery.js +49 -1
  74. package/dist/provider-command-discovery.js.map +1 -1
  75. package/dist/provider-command-types.d.ts +5 -0
  76. package/dist/provider-command-types.js.map +1 -1
  77. package/dist/runtime.d.ts +1 -1
  78. package/dist/runtime.js +1 -1
  79. package/dist/runtime.js.map +1 -1
  80. package/dist/search-sessions.js +2 -1
  81. package/dist/search-sessions.js.map +1 -1
  82. package/package.json +3 -1
package/dist/copilot.d.ts CHANGED
@@ -1,19 +1,26 @@
1
1
  /**
2
2
  * Copilot CLI process driver for AgentLink.
3
3
  *
4
- * Parallel to claude.ts but simpler:
5
- * - Each turn spawns a new `copilot --output-format json` process
6
- * - Prompt is written to stdin to avoid command-line length limits
7
- * - No persistent process, no control_request protocol
8
- * - JSONL stdout parsed and emitted as backend_event messages
9
- * - Session state stored at ~/.copilot/session-state/<id>/
4
+ * Parallel to claude.ts, with a conversation-scoped persistent SDK runtime:
5
+ * - Chat, Plan, /goal, and /compact share one provider Session; discovery is static
6
+ * - Agency attachments use SDK; Direct native attachments retain the CLI fallback
7
+ * - Provider events are normalized into backend_event messages
8
+ * - Session state remains stored at ~/.copilot/session-state/<id>/
10
9
  */
11
10
  import { type ChildProcess } from 'child_process';
11
+ import { CopilotReviewDocuments, type CopilotReviewDocument } from './copilot-review-documents.js';
12
+ import { type CopilotUserRequest } from './copilot-user-requests.js';
13
+ import { CopilotCompactionBarrier } from './copilot-compaction-barrier.js';
14
+ import { CopilotCompactionLifecycle, type CopilotCompactionRecord } from './copilot-compaction-lifecycle.js';
12
15
  import type { SendFn } from './claude.js';
13
16
  import type { SessionInfo } from './history.js';
14
17
  import { type HistoryMessage } from './history-message-transform.js';
15
- import { copilotCapabilities } from './backends/types.js';
18
+ import { copilotCapabilities, type UsageInfo } from './backends/types.js';
19
+ import { CopilotCommandRuntime } from './copilot-command-bridge.js';
20
+ import type { ProviderCommand } from './provider-command-types.js';
21
+ import { type CopilotConfiguration } from './copilot-configuration.js';
16
22
  export interface CopilotConversationState {
23
+ configuration?: CopilotConfiguration;
17
24
  conversationId: string;
18
25
  child: ChildProcess | null;
19
26
  abortController: AbortController | null;
@@ -21,6 +28,8 @@ export interface CopilotConversationState {
21
28
  lastCopilotSessionId: string | null;
22
29
  workDir: string;
23
30
  turnActive: boolean;
31
+ turnStartedAt?: number;
32
+ userRequest?: CopilotUserRequest;
24
33
  providerId: string;
25
34
  model: string | null;
26
35
  contextTier: CopilotContextTier | null;
@@ -30,9 +39,100 @@ export interface CopilotConversationState {
30
39
  heartbeatTimer: ReturnType<typeof setInterval> | null;
31
40
  /** True once we've sent session_started for sidebar refresh */
32
41
  sessionNotified: boolean;
42
+ copilotMode: CopilotSessionMode;
43
+ planMode: boolean;
44
+ planModePending: boolean;
45
+ isCompacting: boolean;
46
+ commandRuntime: CopilotCommandRuntime | null;
47
+ commandSessionId: string | null;
48
+ deferredCommandUsage: UsageInfo | null;
49
+ runtimeInitPromise: Promise<void> | null;
50
+ runtimeDisposal: Promise<void> | null;
51
+ runtimeConfigKey: string | null;
52
+ runtimeGeneration: number;
53
+ runtimeUnused: boolean;
54
+ cachedCommands: ProviderCommand[] | null;
55
+ activeOperation: 'chat' | 'command' | 'auto-compact' | null;
56
+ activeCommand?: CopilotNativeCommand;
57
+ /** A changed configuration skips maintenance before its first real request. */
58
+ skipNextPreRequestCompaction?: boolean;
59
+ lastUsage: UsageInfo | null;
60
+ contextUsageBeforeOptionsChange?: UsageInfo;
61
+ /** Invalidates a recount across native usage, compaction and cancellation. */
62
+ contextMeasurementVersion?: number;
63
+ contextPublishSequence?: number;
64
+ nativeContextFloor?: {
65
+ generation: number;
66
+ key: string;
67
+ tokens: number;
68
+ at: number;
69
+ activity: number;
70
+ };
71
+ contextActivityVersion?: number;
72
+ compactionBarrier?: CopilotCompactionBarrier;
73
+ compactionStartAt?: number;
74
+ compactionBase?: {
75
+ systemTokens?: number;
76
+ toolDefinitionsTokens?: number;
77
+ currentTokens?: number;
78
+ conversationTokens?: number;
79
+ model?: string;
80
+ contextTier?: string;
81
+ generation: number;
82
+ };
83
+ publishedUsage?: UsageInfo | null;
84
+ pendingTurnCompletion?: boolean;
85
+ contextCompactionAt?: number;
86
+ contextBoundarySessionId?: string;
87
+ compactionEventKeys?: Set<string>;
88
+ lastCompactionEventAt?: number;
89
+ compactionLifecycle?: CopilotCompactionLifecycle;
90
+ compactionLifecycleGeneration?: number;
91
+ compactionRecord?: CopilotCompactionRecord;
92
+ compactionRecords?: Map<string, CopilotCompactionRecord>;
93
+ compactionPublications?: Map<string, string>;
94
+ autoCompactionWatermark: string | null;
95
+ autoCompactionPending: boolean;
96
+ compactionFailed: boolean;
97
+ compactionTrigger: string | null;
98
+ /** Allow the next provider usage sample to cross a confirmed compaction boundary. */
99
+ contextUsageDecreaseAllowed: boolean;
100
+ /** Actual session usage reported during maintenance, committed only on success. */
101
+ pendingCompactionUsage?: Partial<UsageInfo> | null;
102
+ compactionHasConfirmedUsage?: boolean;
103
+ toolNamesByCallId: Map<string, string>;
104
+ toolStartKeys?: Set<string>;
105
+ reviewDocuments?: CopilotReviewDocuments;
106
+ streamedMessageTextById: Map<string, string>;
107
+ finalizedMessageIds: Set<string>;
108
+ lastMainMessageId?: string;
109
+ pendingMainReply?: {
110
+ id: string;
111
+ text: string;
112
+ published: boolean;
113
+ };
114
+ assistantReplyStarted?: boolean;
115
+ subagentMessages?: Map<string, Map<string, {
116
+ text: string;
117
+ thinking: string;
118
+ }>>;
119
+ subagentToolIds?: Map<string, string>;
120
+ /** Agency ACP text is held until reasoning and tool blocks for the turn finish. */
121
+ agencyResponseBuffer: string;
122
+ taskCompleteReplyEmitted: boolean;
123
+ taskCompleteSucceeded: boolean;
124
+ pendingPlanReview: PendingCopilotPlanReview | null;
125
+ nativePlanExit?: boolean;
126
+ planControlPending?: boolean;
127
+ readyPlanId: string | null;
128
+ planImplementationStarting: boolean;
129
+ createdAt: number;
130
+ lastActivityAt: number;
131
+ timestampMessageId?: string;
33
132
  }
34
133
  export type CopilotContextTier = 'default' | 'long_context';
35
134
  export type CopilotReasoningEffort = 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
135
+ export type CopilotSessionMode = 'interactive' | 'plan' | 'autopilot';
36
136
  export interface CopilotRunOptions {
37
137
  model?: string;
38
138
  context?: string;
@@ -48,7 +148,58 @@ interface CopilotChatFile {
48
148
  mimeType: string;
49
149
  data: string;
50
150
  }
151
+ export declare const COPILOT_AUTO_COMPACTION_THRESHOLD: 0.8;
152
+ export declare const COPILOT_IDLE_CONVERSATION_TIMEOUT_MS: number;
153
+ export declare const COPILOT_STALE_RUNTIME_TIMEOUT_MS: number;
154
+ export declare const COPILOT_MAX_CONVERSATIONS = 15;
155
+ interface CopilotDecisionRequestPayload {
156
+ reviewDocuments?: CopilotReviewDocument[];
157
+ questions: Array<{
158
+ question: string;
159
+ header?: string;
160
+ options: Array<{
161
+ label: string;
162
+ value?: string;
163
+ description?: string;
164
+ }>;
165
+ multiSelect?: boolean;
166
+ }>;
167
+ source: 'tool_request_user_input';
168
+ presentation: 'inline';
169
+ kind?: 'plan_input';
170
+ allowFreeform: boolean;
171
+ expiresAt?: number;
172
+ timeoutAction?: 'first_option' | 'continue_plan';
173
+ }
174
+ interface PendingCopilotPlanReview {
175
+ sessionId: string;
176
+ content?: string;
177
+ languageHint: string;
178
+ }
179
+ export interface CopilotPlanQuestion {
180
+ question: string;
181
+ options: Array<{
182
+ label: string;
183
+ description?: string;
184
+ }>;
185
+ multiSelect?: boolean;
186
+ }
187
+ interface CopilotPlanAnswerRecord extends CopilotPlanQuestion {
188
+ answer: string;
189
+ }
190
+ export interface PendingCopilotDecisionSnapshot {
191
+ requestId: string;
192
+ conversationId: string;
193
+ providerId: string;
194
+ sessionId: string;
195
+ request: CopilotDecisionRequestPayload;
196
+ }
51
197
  export declare function addCopilotSendFn(fn: SendFn): () => void;
198
+ export declare function getPendingCopilotDecisions(conversationId: string): PendingCopilotDecisionSnapshot[];
199
+ export declare function handleCopilotUserAnswer(requestId: string, answers: Record<string, unknown>, scope?: {
200
+ conversationId?: string;
201
+ providerId?: string;
202
+ }): boolean;
52
203
  export declare function getCopilotConversation(conversationId: string): CopilotConversationState | undefined;
53
204
  export declare function getCopilotConversations(): Map<string, CopilotConversationState>;
54
205
  /**
@@ -63,23 +214,48 @@ export declare function createCopilotPlaceholder(conversationId: string, opts?:
63
214
  export declare function restartCopilotConversation(conversationId: string, opts?: {
64
215
  providerId?: string;
65
216
  model?: string;
217
+ preserveSession?: boolean;
66
218
  }): {
67
219
  wasTurnActive: boolean;
68
220
  copilotSessionId: string | null;
69
221
  };
70
222
  export declare function setModel(conversationId: string | undefined, model: string): void;
223
+ export type CopilotNativeCommand = 'compact' | 'plan' | 'goal';
224
+ /** Change routing without allocating a replacement native Session or Runtime. */
225
+ export declare function setCopilotProvider(conversationId: string, providerId: string, options?: {
226
+ resumeSessionId?: string;
227
+ workDir?: string;
228
+ restoreOnly?: boolean;
229
+ }): string;
230
+ export declare function parseCopilotPlanAnswerHistory(content: string): CopilotPlanAnswerRecord[];
231
+ export declare function extractCopilotPlanQuestions(content: string): CopilotPlanQuestion[];
232
+ export declare function discoverCopilotCommandsForConversation(_conversationId: string, _providerId: string, _workDir: string, _copilotOptions?: CopilotRunOptions): Promise<ProviderCommand[]>;
233
+ export declare function executeCopilotCommand(conversationId: string, command: CopilotNativeCommand, input: string, workDir: string, options?: CopilotChatOptions): Promise<void>;
234
+ export declare function setCopilotPlanMode(conversationId: string, enabled: boolean, workDir: string, providerId?: string, copilotOptions?: CopilotRunOptions, resumeSessionId?: string): Promise<void>;
235
+ export declare function startCopilotPlanImplementation(conversationId: string, planId: string, workDir: string, options?: {
236
+ providerId?: string;
237
+ resumeSessionId?: string;
238
+ prompt?: string;
239
+ copilotOptions?: CopilotRunOptions;
240
+ }): Promise<void>;
71
241
  export interface CopilotChatOptions {
242
+ /** User-visible input for implicit Plan dispatch; never the expanded prompt. */
243
+ displayPrompt?: string;
72
244
  resumeSessionId?: string;
73
245
  providerId?: string;
74
246
  copilotOptions?: CopilotRunOptions;
247
+ forkSourceSessionId?: string;
248
+ /** Internal: mode override for the legacy native-attachment CLI path. */
249
+ oneShotMode?: 'plan' | 'autopilot';
75
250
  }
76
251
  export declare function normalizeCopilotRunOptions(input?: CopilotRunOptions): {
77
252
  options: NormalizedCopilotRunOptions;
78
253
  error?: string;
79
254
  };
80
- export declare function handleCopilotChat(conversationId: string, text: string, workDir: string, options?: CopilotChatOptions, files?: CopilotChatFile[]): void;
255
+ export declare function handleCopilotChat(conversationId: string, text: string, workDir: string, options?: CopilotChatOptions, files?: CopilotChatFile[]): Promise<void>;
81
256
  export declare function cancelCopilotExecution(conversationId: string): void;
82
257
  export declare function cleanupAllCopilotConversations(): void;
258
+ export declare function readCopilotSessionProvider(sessionId: string): string | undefined;
83
259
  interface CopilotSessionPage {
84
260
  sessions: SessionInfo[];
85
261
  hasMore: boolean;
@@ -93,6 +269,10 @@ interface CopilotGlobalSessionInfo {
93
269
  title: string;
94
270
  firstPrompt: string;
95
271
  lastModified: number;
272
+ providerId?: string;
273
+ isFork?: boolean;
274
+ forkNumber?: number;
275
+ forkSourceSessionId?: string;
96
276
  }
97
277
  interface CopilotGlobalSessionPage {
98
278
  sessions: CopilotGlobalSessionInfo[];
@@ -100,6 +280,10 @@ interface CopilotGlobalSessionPage {
100
280
  nextCursor?: string;
101
281
  indexState: 'ready';
102
282
  }
283
+ export declare function listCopilotSessionsPageAsync(workDir: string, options?: {
284
+ limit?: number;
285
+ cursor?: string;
286
+ }): Promise<CopilotSessionPage>;
103
287
  export declare function listCopilotSessions(workDir: string, options?: {
104
288
  strictReadErrors?: boolean;
105
289
  }): SessionInfo[];
@@ -111,6 +295,8 @@ export declare function listCopilotSessionsPage(workDir: string, options?: {
111
295
  export declare function readCopilotSessionMessages(_workDir: string, sessionId: string, options?: {
112
296
  strictReadErrors?: boolean;
113
297
  }): HistoryMessage[];
298
+ export declare function readCopilotSessionMode(sessionId: string): CopilotSessionMode;
299
+ export declare function readCopilotSessionUsage(sessionId: string): UsageInfo | null;
114
300
  export declare function getCopilotSessionWorkDir(sessionId: string): string | undefined;
115
301
  export declare function listAllCopilotSessions(limit?: number): Array<{
116
302
  sessionId: string;
@@ -119,12 +305,19 @@ export declare function listAllCopilotSessions(limit?: number): Array<{
119
305
  title: string;
120
306
  firstPrompt: string;
121
307
  lastModified: number;
308
+ isFork?: boolean;
309
+ forkNumber?: number;
310
+ forkSourceSessionId?: string;
122
311
  }>;
123
312
  export declare function listAllCopilotSessionsPage(options?: {
124
313
  limit?: number;
125
314
  cursor?: string;
126
315
  }): CopilotGlobalSessionPage;
316
+ export declare function listAllCopilotSessionsPageAsync(options?: {
317
+ limit?: number;
318
+ cursor?: string;
319
+ }): Promise<CopilotGlobalSessionPage>;
127
320
  export declare function renameCopilotSession(_workDir: string, sessionId: string, newTitle: string): boolean;
128
321
  export declare function moveCopilotSession(_fromWorkDir: string, toWorkDir: string, sessionId: string): boolean;
129
- export declare function deleteCopilotSession(_workDir: string, sessionId: string): boolean;
322
+ export declare function deleteCopilotSession(_workDir: string, sessionId: string): Promise<boolean>;
130
323
  export { copilotCapabilities };