@1agents/acp-service 0.3.0 → 0.4.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.
- package/README.md +57 -33
- package/dist/bin/acp-service.js +2 -2
- package/dist/src/bridge.d.ts +2 -2
- package/dist/src/bridge.js +1 -1
- package/dist/src/catalog.js +20 -3
- package/dist/src/manifest.js +1 -1
- package/package.json +27 -8
- package/vendor/runtime/LICENSE +21 -0
- package/vendor/runtime/README.md +115 -0
- package/vendor/runtime/dist/agent-registry-CMg8LHKY.js +806 -0
- package/vendor/runtime/dist/agent-registry-CMg8LHKY.js.map +1 -0
- package/vendor/runtime/dist/agent-registry.d.ts +70 -0
- package/vendor/runtime/dist/agent-registry.d.ts.map +1 -0
- package/vendor/runtime/dist/agent-registry.js +2 -0
- package/vendor/runtime/dist/cli-DUHyAADv.js +182 -0
- package/vendor/runtime/dist/cli-DUHyAADv.js.map +1 -0
- package/vendor/runtime/dist/cli.d.ts +12 -0
- package/vendor/runtime/dist/cli.d.ts.map +1 -0
- package/vendor/runtime/dist/cli.js +2632 -0
- package/vendor/runtime/dist/cli.js.map +1 -0
- package/vendor/runtime/dist/client-DjkWknf7.d.ts +262 -0
- package/vendor/runtime/dist/client-DjkWknf7.d.ts.map +1 -0
- package/vendor/runtime/dist/docs-site/.nojekyll +0 -0
- package/vendor/runtime/dist/docs-site/CLI.html +832 -0
- package/vendor/runtime/dist/docs-site/CNAME +1 -0
- package/vendor/runtime/dist/docs-site/VISION.html +415 -0
- package/vendor/runtime/dist/docs-site/agents.html +391 -0
- package/vendor/runtime/dist/docs-site/compare.html +359 -0
- package/vendor/runtime/dist/docs-site/config.html +450 -0
- package/vendor/runtime/dist/docs-site/custom-agents.html +408 -0
- package/vendor/runtime/dist/docs-site/exit-codes.html +347 -0
- package/vendor/runtime/dist/docs-site/favicon.svg +21 -0
- package/vendor/runtime/dist/docs-site/flows.html +497 -0
- package/vendor/runtime/dist/docs-site/index.html +367 -0
- package/vendor/runtime/dist/docs-site/install.html +386 -0
- package/vendor/runtime/dist/docs-site/llms.txt +35 -0
- package/vendor/runtime/dist/docs-site/output-formats.html +403 -0
- package/vendor/runtime/dist/docs-site/permissions.html +413 -0
- package/vendor/runtime/dist/docs-site/prompting.html +460 -0
- package/vendor/runtime/dist/docs-site/proof-2026-07-18-grok-ext-methods/index.html +336 -0
- package/vendor/runtime/dist/docs-site/quickstart.html +382 -0
- package/vendor/runtime/dist/docs-site/runtime-environment.html +329 -0
- package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +335 -0
- package/vendor/runtime/dist/docs-site/session-control.html +406 -0
- package/vendor/runtime/dist/docs-site/session-watch.html +354 -0
- package/vendor/runtime/dist/docs-site/sessions.html +486 -0
- package/vendor/runtime/dist/docs-site/shared-sessions.html +377 -0
- package/vendor/runtime/dist/flows-CiJSCy4D.js +2474 -0
- package/vendor/runtime/dist/flows-CiJSCy4D.js.map +1 -0
- package/vendor/runtime/dist/flows.d.ts +334 -0
- package/vendor/runtime/dist/flows.d.ts.map +1 -0
- package/vendor/runtime/dist/flows.js +2 -0
- package/vendor/runtime/dist/invocation-options-BlIySxIw.js +345 -0
- package/vendor/runtime/dist/invocation-options-BlIySxIw.js.map +1 -0
- package/vendor/runtime/dist/ipc-BlljKR2b.js +5336 -0
- package/vendor/runtime/dist/ipc-BlljKR2b.js.map +1 -0
- package/vendor/runtime/dist/output-BzXQKArM.js +1012 -0
- package/vendor/runtime/dist/output-BzXQKArM.js.map +1 -0
- package/vendor/runtime/dist/queue-owner-runtime-DSFdsS_y.js +8867 -0
- package/vendor/runtime/dist/queue-owner-runtime-DSFdsS_y.js.map +1 -0
- package/vendor/runtime/dist/runtime.d.ts +1156 -0
- package/vendor/runtime/dist/runtime.d.ts.map +1 -0
- package/vendor/runtime/dist/runtime.js +3675 -0
- package/vendor/runtime/dist/runtime.js.map +1 -0
- package/vendor/runtime/dist/session-options-ORCchZGk.d.ts +426 -0
- package/vendor/runtime/dist/session-options-ORCchZGk.d.ts.map +1 -0
- package/vendor/runtime/dist/session-watch-BiBTBMz4.js +76 -0
- package/vendor/runtime/dist/session-watch-BiBTBMz4.js.map +1 -0
- package/vendor/runtime/dist/watch-iYiP-lOo.js +85 -0
- package/vendor/runtime/dist/watch-iYiP-lOo.js.map +1 -0
- package/vendor/runtime/package.json +46 -0
- package/vendor/runtime/skills/acpx/SKILL.md +688 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { AgentCapabilities, AnyMessage, ContentBlock, CreateElicitationRequest, ElicitationContentValue, JsonRpcId, McpServer, McpServer as McpServer$1, RequestPermissionRequest, SessionConfigOption, SessionNotification, SetSessionConfigOptionResponse, ToolKind } from "@1agents/acp-runtime-sdk";
|
|
2
|
+
//#region src/acp/grok-ask-user.d.ts
|
|
3
|
+
type GrokAskUserOption = {
|
|
4
|
+
label: string;
|
|
5
|
+
description: string;
|
|
6
|
+
preview?: string | null;
|
|
7
|
+
};
|
|
8
|
+
type GrokAskUserQuestionItem = {
|
|
9
|
+
question: string;
|
|
10
|
+
options: GrokAskUserOption[];
|
|
11
|
+
/** Wire uses camelCase `multiSelect` (tool JSON schema uses multi_select). */
|
|
12
|
+
multiSelect?: boolean | null;
|
|
13
|
+
};
|
|
14
|
+
type GrokAskUserQuestionRequest = {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
toolCallId: string;
|
|
17
|
+
questions: GrokAskUserQuestionItem[];
|
|
18
|
+
mode?: string | null;
|
|
19
|
+
};
|
|
20
|
+
/** Answer value is serde untagged StringOrVec. */
|
|
21
|
+
type GrokAskUserAnswerValue = string | string[];
|
|
22
|
+
type GrokAskUserAnswers = Record<string, GrokAskUserAnswerValue>;
|
|
23
|
+
type GrokAskUserQuestionResponse = {
|
|
24
|
+
outcome: "accepted";
|
|
25
|
+
answers: GrokAskUserAnswers;
|
|
26
|
+
partial_answers?: boolean | null;
|
|
27
|
+
} | {
|
|
28
|
+
outcome: "skip_interview";
|
|
29
|
+
} | {
|
|
30
|
+
outcome: "chat_about_this";
|
|
31
|
+
} | {
|
|
32
|
+
outcome: "cancelled";
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/acp/grok-exit-plan.d.ts
|
|
36
|
+
type GrokExitPlanModeRequest = {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
toolCallId: string;
|
|
39
|
+
planContent: string;
|
|
40
|
+
};
|
|
41
|
+
type GrokExitPlanOutcome = "approved" | "rejected" | "abandoned";
|
|
42
|
+
type GrokExitPlanModeResponse = {
|
|
43
|
+
outcome: GrokExitPlanOutcome;
|
|
44
|
+
comments?: string | null;
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/prompt-content.d.ts
|
|
48
|
+
type PromptInput = ContentBlock[];
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/types.d.ts
|
|
51
|
+
type AcpPermissionRequest = {
|
|
52
|
+
sessionId: string;
|
|
53
|
+
raw: RequestPermissionRequest;
|
|
54
|
+
inferredKind: ToolKind | undefined;
|
|
55
|
+
};
|
|
56
|
+
type AcpPermissionDecision = {
|
|
57
|
+
outcome: "allow_once";
|
|
58
|
+
} | {
|
|
59
|
+
outcome: "allow_always";
|
|
60
|
+
} | {
|
|
61
|
+
outcome: "reject_once";
|
|
62
|
+
} | {
|
|
63
|
+
outcome: "reject_always";
|
|
64
|
+
} | {
|
|
65
|
+
outcome: "cancel";
|
|
66
|
+
};
|
|
67
|
+
type AcpPermissionHandler = (request: AcpPermissionRequest, context: {
|
|
68
|
+
signal: AbortSignal;
|
|
69
|
+
}) => Promise<AcpPermissionDecision | undefined>;
|
|
70
|
+
declare const ACP_ELICITATION_MODES: readonly ["form", "url"];
|
|
71
|
+
type AcpElicitationMode = (typeof ACP_ELICITATION_MODES)[number];
|
|
72
|
+
type AcpElicitationRequest = CreateElicitationRequest;
|
|
73
|
+
type AcpElicitationContext = {
|
|
74
|
+
/** Exact JSON-RPC id of the outer `elicitation/create` request. */
|
|
75
|
+
requestId: JsonRpcId;
|
|
76
|
+
/** Aborts with the request itself or its owning prompt turn/session. */
|
|
77
|
+
signal: AbortSignal;
|
|
78
|
+
};
|
|
79
|
+
type AcpElicitationResponseMeta = {
|
|
80
|
+
_meta?: Record<string, unknown> | null;
|
|
81
|
+
};
|
|
82
|
+
type AcpElicitationResponse = ({
|
|
83
|
+
action: "accept";
|
|
84
|
+
content?: Record<string, ElicitationContentValue> | null;
|
|
85
|
+
} & AcpElicitationResponseMeta) | ({
|
|
86
|
+
action: "decline";
|
|
87
|
+
} & AcpElicitationResponseMeta) | ({
|
|
88
|
+
action: "cancel";
|
|
89
|
+
} & AcpElicitationResponseMeta);
|
|
90
|
+
type AcpElicitationHandler = (request: AcpElicitationRequest, context: AcpElicitationContext) => Promise<AcpElicitationResponse>;
|
|
91
|
+
declare const PERMISSION_MODES: readonly ["approve-all", "approve-reads", "deny-all"];
|
|
92
|
+
type PermissionMode = (typeof PERMISSION_MODES)[number];
|
|
93
|
+
declare const AUTH_POLICIES: readonly ["skip", "fail"];
|
|
94
|
+
type AuthPolicy = (typeof AUTH_POLICIES)[number];
|
|
95
|
+
declare const NON_INTERACTIVE_PERMISSION_POLICIES: readonly ["deny", "fail"];
|
|
96
|
+
type NonInteractivePermissionPolicy = (typeof NON_INTERACTIVE_PERMISSION_POLICIES)[number];
|
|
97
|
+
declare const PERMISSION_POLICY_ACTIONS: readonly ["approve", "deny", "escalate"];
|
|
98
|
+
type PermissionPolicyAction = (typeof PERMISSION_POLICY_ACTIONS)[number];
|
|
99
|
+
type PermissionPolicy = {
|
|
100
|
+
autoApprove?: string[];
|
|
101
|
+
autoDeny?: string[];
|
|
102
|
+
escalate?: string[];
|
|
103
|
+
defaultAction?: PermissionPolicyAction;
|
|
104
|
+
};
|
|
105
|
+
type PermissionEscalationEvent = {
|
|
106
|
+
type: "permission_escalation";
|
|
107
|
+
sessionId: string;
|
|
108
|
+
toolCallId: string;
|
|
109
|
+
toolName?: string;
|
|
110
|
+
toolTitle: string;
|
|
111
|
+
toolInput?: unknown;
|
|
112
|
+
toolKind?: ToolKind;
|
|
113
|
+
action: "escalate";
|
|
114
|
+
matchedRule?: string;
|
|
115
|
+
message: string;
|
|
116
|
+
timestamp: string;
|
|
117
|
+
};
|
|
118
|
+
type AcpJsonRpcMessage = AnyMessage;
|
|
119
|
+
type AcpMessageDirection = "outbound" | "inbound";
|
|
120
|
+
type PermissionStats = {
|
|
121
|
+
requested: number;
|
|
122
|
+
approved: number;
|
|
123
|
+
denied: number;
|
|
124
|
+
cancelled: number;
|
|
125
|
+
};
|
|
126
|
+
type ClientOperationMethod = "session/request_permission" | "fs/read_text_file" | "fs/write_text_file" | "terminal/create" | "terminal/output" | "terminal/wait_for_exit" | "terminal/kill" | "terminal/release";
|
|
127
|
+
type ClientOperationStatus = "running" | "completed" | "failed";
|
|
128
|
+
type ClientOperation = {
|
|
129
|
+
method: ClientOperationMethod;
|
|
130
|
+
status: ClientOperationStatus;
|
|
131
|
+
summary: string;
|
|
132
|
+
details?: string;
|
|
133
|
+
timestamp: string;
|
|
134
|
+
};
|
|
135
|
+
type SessionEventLog = {
|
|
136
|
+
active_path: string;
|
|
137
|
+
segment_count: number;
|
|
138
|
+
max_segment_bytes: number;
|
|
139
|
+
max_segments: number;
|
|
140
|
+
last_write_at?: string;
|
|
141
|
+
last_write_error?: string | null;
|
|
142
|
+
};
|
|
143
|
+
type AcpProcessLaunchScope = Readonly<{
|
|
144
|
+
kind: "client";
|
|
145
|
+
}> | Readonly<{
|
|
146
|
+
kind: "runtime-session";
|
|
147
|
+
sessionKey: string;
|
|
148
|
+
}> | Readonly<{
|
|
149
|
+
kind: "runtime-probe";
|
|
150
|
+
agent: string;
|
|
151
|
+
}>;
|
|
152
|
+
type AcpProcessLaunch = Readonly<{
|
|
153
|
+
launchId: string;
|
|
154
|
+
scope: AcpProcessLaunchScope;
|
|
155
|
+
command: string;
|
|
156
|
+
args: readonly string[];
|
|
157
|
+
cwd: string;
|
|
158
|
+
}>;
|
|
159
|
+
type AcpProcessStarted = AcpProcessLaunch & Readonly<{
|
|
160
|
+
pid: number;
|
|
161
|
+
startedAt: string;
|
|
162
|
+
}>;
|
|
163
|
+
type AcpProcessSpawnFailure = AcpProcessLaunch & Readonly<{
|
|
164
|
+
error: unknown;
|
|
165
|
+
failedAt: string;
|
|
166
|
+
}>;
|
|
167
|
+
type AcpProcessExit = AcpProcessStarted & Readonly<{
|
|
168
|
+
exitCode: number | null;
|
|
169
|
+
signal: NodeJS.Signals | null;
|
|
170
|
+
exitedAt: string;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Optional process lifecycle seam for embedding hosts that persist their own
|
|
174
|
+
* launch ownership. Pre-spawn and spawned hooks are admission boundaries:
|
|
175
|
+
* rejecting either aborts startup, and a process rejected after spawn is
|
|
176
|
+
* terminated before the error is returned. Failure and exit hooks are
|
|
177
|
+
* best-effort observations and cannot replace the launch or exit outcome.
|
|
178
|
+
*/
|
|
179
|
+
type AcpProcessLifecycle = {
|
|
180
|
+
onBeforeSpawn?: (launch: AcpProcessLaunch) => Promise<void> | void;
|
|
181
|
+
onSpawned?: (process: AcpProcessStarted) => Promise<void> | void;
|
|
182
|
+
onSpawnFailed?: (failure: AcpProcessSpawnFailure) => Promise<void> | void;
|
|
183
|
+
onExit?: (exit: AcpProcessExit) => Promise<void> | void;
|
|
184
|
+
};
|
|
185
|
+
type AcpClientOptions = {
|
|
186
|
+
agentCommand: string;
|
|
187
|
+
agentArgv?: string[];
|
|
188
|
+
/** Trusted child-only environment overlay; never persisted as session options. */
|
|
189
|
+
agentProcessEnv?: Record<string, string>;
|
|
190
|
+
cwd: string;
|
|
191
|
+
mcpServers?: McpServer[];
|
|
192
|
+
permissionMode: PermissionMode;
|
|
193
|
+
nonInteractivePermissions?: NonInteractivePermissionPolicy;
|
|
194
|
+
permissionPolicy?: PermissionPolicy;
|
|
195
|
+
authCredentials?: Record<string, string>;
|
|
196
|
+
authPolicy?: AuthPolicy;
|
|
197
|
+
fs?: boolean;
|
|
198
|
+
terminal?: boolean;
|
|
199
|
+
elicitationModes?: readonly AcpElicitationMode[];
|
|
200
|
+
processLifecycle?: AcpProcessLifecycle;
|
|
201
|
+
processLaunchScope?: AcpProcessLaunchScope;
|
|
202
|
+
suppressSdkConsoleErrors?: boolean;
|
|
203
|
+
verbose?: boolean;
|
|
204
|
+
sessionOptions?: {
|
|
205
|
+
model?: string;
|
|
206
|
+
allowedTools?: string[];
|
|
207
|
+
maxTurns?: number;
|
|
208
|
+
systemPrompt?: string | {
|
|
209
|
+
append: string;
|
|
210
|
+
};
|
|
211
|
+
env?: Record<string, string>;
|
|
212
|
+
};
|
|
213
|
+
onAcpMessage?: (direction: AcpMessageDirection, message: AcpJsonRpcMessage) => void;
|
|
214
|
+
onAcpOutputMessage?: (direction: AcpMessageDirection, message: AcpJsonRpcMessage) => void;
|
|
215
|
+
onSessionUpdate?: (notification: SessionNotification) => void;
|
|
216
|
+
onClientOperation?: (operation: ClientOperation) => void;
|
|
217
|
+
onPermissionEscalation?: (event: PermissionEscalationEvent) => void;
|
|
218
|
+
onPermissionRequest?: AcpPermissionHandler;
|
|
219
|
+
/**
|
|
220
|
+
* Host-driven handler for Grok Build's `_x.ai/ask_user_question` extension.
|
|
221
|
+
* Return a wire response, a bare answers map, or undefined to fall through
|
|
222
|
+
* to the interactive CLI prompt (TTY) / cancelled (non-TTY).
|
|
223
|
+
*/
|
|
224
|
+
onAskUserQuestion?: (req: GrokAskUserQuestionRequest, ctx: {
|
|
225
|
+
signal: AbortSignal;
|
|
226
|
+
}) => Promise<GrokAskUserQuestionResponse | GrokAskUserAnswers | undefined>;
|
|
227
|
+
/**
|
|
228
|
+
* Host-driven handler for Grok Build's `_x.ai/exit_plan_mode` extension.
|
|
229
|
+
* Return a wire response, a bare outcome string, or undefined to fall through
|
|
230
|
+
* to the interactive CLI prompt (TTY) / abandoned (non-TTY).
|
|
231
|
+
*/
|
|
232
|
+
onExitPlanMode?: (req: GrokExitPlanModeRequest, ctx: {
|
|
233
|
+
signal: AbortSignal;
|
|
234
|
+
}) => Promise<GrokExitPlanModeResponse | GrokExitPlanOutcome | undefined>;
|
|
235
|
+
};
|
|
236
|
+
declare const SESSION_RECORD_SCHEMA: "acpx.session.v1";
|
|
237
|
+
type SessionMessageImage = {
|
|
238
|
+
source: string;
|
|
239
|
+
mime_type?: string;
|
|
240
|
+
size?: {
|
|
241
|
+
width: number;
|
|
242
|
+
height: number;
|
|
243
|
+
} | null;
|
|
244
|
+
};
|
|
245
|
+
type SessionMessageAudio = {
|
|
246
|
+
source: string;
|
|
247
|
+
mime_type: string;
|
|
248
|
+
};
|
|
249
|
+
type SessionUserContent = {
|
|
250
|
+
Text: string;
|
|
251
|
+
} | {
|
|
252
|
+
Mention: {
|
|
253
|
+
uri: string;
|
|
254
|
+
content: string;
|
|
255
|
+
};
|
|
256
|
+
} | {
|
|
257
|
+
Image: SessionMessageImage;
|
|
258
|
+
} | {
|
|
259
|
+
Audio: SessionMessageAudio;
|
|
260
|
+
};
|
|
261
|
+
type SessionToolUse = {
|
|
262
|
+
id: string;
|
|
263
|
+
name: string;
|
|
264
|
+
raw_input: string;
|
|
265
|
+
input: unknown;
|
|
266
|
+
is_input_complete: boolean;
|
|
267
|
+
thought_signature?: string | null;
|
|
268
|
+
/** ACP ToolKind when the adapter sent one (Cursor often titles tools "Edit File"). */
|
|
269
|
+
kind?: string;
|
|
270
|
+
/** ACP locations — Cursor file tools persist empty input and only put paths here. */
|
|
271
|
+
locations?: Array<{
|
|
272
|
+
path: string;
|
|
273
|
+
line?: number;
|
|
274
|
+
}>;
|
|
275
|
+
};
|
|
276
|
+
type SessionToolResultContent = {
|
|
277
|
+
Text: string;
|
|
278
|
+
} | {
|
|
279
|
+
Image: SessionMessageImage;
|
|
280
|
+
};
|
|
281
|
+
type SessionToolResult = {
|
|
282
|
+
tool_use_id: string;
|
|
283
|
+
tool_name: string;
|
|
284
|
+
is_error: boolean;
|
|
285
|
+
content: SessionToolResultContent;
|
|
286
|
+
output?: unknown;
|
|
287
|
+
};
|
|
288
|
+
type SessionAgentContent = {
|
|
289
|
+
Text: string;
|
|
290
|
+
} | {
|
|
291
|
+
Thinking: {
|
|
292
|
+
text: string;
|
|
293
|
+
signature?: string | null;
|
|
294
|
+
};
|
|
295
|
+
} | {
|
|
296
|
+
RedactedThinking: string;
|
|
297
|
+
} | {
|
|
298
|
+
ToolUse: SessionToolUse;
|
|
299
|
+
};
|
|
300
|
+
type SessionUserMessage = {
|
|
301
|
+
id: string;
|
|
302
|
+
content: SessionUserContent[];
|
|
303
|
+
};
|
|
304
|
+
type SessionAgentMessage = {
|
|
305
|
+
content: SessionAgentContent[];
|
|
306
|
+
tool_results: Record<string, SessionToolResult>;
|
|
307
|
+
reasoning_details?: unknown;
|
|
308
|
+
};
|
|
309
|
+
type SessionMessage = {
|
|
310
|
+
User: SessionUserMessage;
|
|
311
|
+
} | {
|
|
312
|
+
Agent: SessionAgentMessage;
|
|
313
|
+
} | "Resume";
|
|
314
|
+
type SessionTokenUsage = {
|
|
315
|
+
input_tokens?: number;
|
|
316
|
+
output_tokens?: number;
|
|
317
|
+
cache_creation_input_tokens?: number;
|
|
318
|
+
cache_read_input_tokens?: number;
|
|
319
|
+
thought_tokens?: number;
|
|
320
|
+
total_tokens?: number;
|
|
321
|
+
};
|
|
322
|
+
type SessionUsageCost = {
|
|
323
|
+
amount?: number;
|
|
324
|
+
currency?: string;
|
|
325
|
+
};
|
|
326
|
+
type SessionAvailableCommand = {
|
|
327
|
+
name: string;
|
|
328
|
+
description?: string;
|
|
329
|
+
has_input?: boolean;
|
|
330
|
+
};
|
|
331
|
+
type RuntimeTurnResultSnapshot = {
|
|
332
|
+
status: "running" | "completed" | "failed" | "cancelled";
|
|
333
|
+
prompt_message_id: string;
|
|
334
|
+
started_at: string;
|
|
335
|
+
completed_at?: string;
|
|
336
|
+
stop_reason?: string;
|
|
337
|
+
last_event_seq?: number;
|
|
338
|
+
error_code?: string;
|
|
339
|
+
};
|
|
340
|
+
type SessionAcpxState = {
|
|
341
|
+
reset_on_next_ensure?: boolean;
|
|
342
|
+
current_mode_id?: string;
|
|
343
|
+
desired_mode_id?: string;
|
|
344
|
+
desired_config_options?: Record<string, string>;
|
|
345
|
+
current_model_id?: string;
|
|
346
|
+
available_models?: string[];
|
|
347
|
+
available_model_names?: Record<string, string>;
|
|
348
|
+
model_control?: "config_option" | "legacy_set_model";
|
|
349
|
+
available_commands?: SessionAvailableCommand[];
|
|
350
|
+
config_options?: SessionConfigOption[];
|
|
351
|
+
session_options?: {
|
|
352
|
+
model?: string;
|
|
353
|
+
allowed_tools?: string[];
|
|
354
|
+
max_turns?: number;
|
|
355
|
+
system_prompt?: string | {
|
|
356
|
+
append: string;
|
|
357
|
+
};
|
|
358
|
+
env?: Record<string, string>;
|
|
359
|
+
};
|
|
360
|
+
turn_results?: Record<string, RuntimeTurnResultSnapshot>;
|
|
361
|
+
};
|
|
362
|
+
type SessionImportedFrom = {
|
|
363
|
+
recordId: string;
|
|
364
|
+
cwdOriginal: string;
|
|
365
|
+
exportedBy: string;
|
|
366
|
+
exportedAt: string;
|
|
367
|
+
};
|
|
368
|
+
type SessionRecord = {
|
|
369
|
+
schema: typeof SESSION_RECORD_SCHEMA;
|
|
370
|
+
acpxRecordId: string;
|
|
371
|
+
acpSessionId: string;
|
|
372
|
+
agentSessionId?: string;
|
|
373
|
+
agentCommand: string;
|
|
374
|
+
agentArgv?: string[];
|
|
375
|
+
cwd: string;
|
|
376
|
+
name?: string;
|
|
377
|
+
createdAt: string;
|
|
378
|
+
lastUsedAt: string;
|
|
379
|
+
lastSeq: number;
|
|
380
|
+
lastRequestId?: string;
|
|
381
|
+
eventLog: SessionEventLog;
|
|
382
|
+
closed?: boolean;
|
|
383
|
+
closedAt?: string;
|
|
384
|
+
pid?: number;
|
|
385
|
+
agentStartedAt?: string;
|
|
386
|
+
lastPromptAt?: string;
|
|
387
|
+
lastAgentExitCode?: number | null;
|
|
388
|
+
lastAgentExitSignal?: NodeJS.Signals | null;
|
|
389
|
+
lastAgentExitAt?: string;
|
|
390
|
+
lastAgentDisconnectReason?: string;
|
|
391
|
+
protocolVersion?: number;
|
|
392
|
+
agentCapabilities?: AgentCapabilities;
|
|
393
|
+
title?: string | null;
|
|
394
|
+
messages: SessionMessage[];
|
|
395
|
+
updated_at: string;
|
|
396
|
+
cumulative_token_usage: SessionTokenUsage;
|
|
397
|
+
cumulative_cost?: SessionUsageCost;
|
|
398
|
+
request_token_usage: Record<string, SessionTokenUsage>;
|
|
399
|
+
acpx?: SessionAcpxState;
|
|
400
|
+
importedFrom?: SessionImportedFrom;
|
|
401
|
+
};
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/runtime/engine/session-options.d.ts
|
|
404
|
+
type SystemPromptOption = string | {
|
|
405
|
+
append: string;
|
|
406
|
+
};
|
|
407
|
+
type SessionAgentOptions = {
|
|
408
|
+
model?: string;
|
|
409
|
+
allowedTools?: string[];
|
|
410
|
+
maxTurns?: number;
|
|
411
|
+
systemPrompt?: SystemPromptOption;
|
|
412
|
+
mcpServers?: McpServer$1[];
|
|
413
|
+
/**
|
|
414
|
+
* Per-agent environment variables injected into the spawned agent child
|
|
415
|
+
* process and persisted with the session record for reconnects. Keys here
|
|
416
|
+
* override the parent process environment for the spawned child, except
|
|
417
|
+
* acpx-managed auth credential keys. Do not put secrets here; use
|
|
418
|
+
* authCredentials for credentials. Callers are responsible for sanitizing
|
|
419
|
+
* dangerous keys such as `PATH`, `LD_PRELOAD`, and `NODE_OPTIONS` before
|
|
420
|
+
* passing them to acpx.
|
|
421
|
+
*/
|
|
422
|
+
env?: Record<string, string>;
|
|
423
|
+
};
|
|
424
|
+
//#endregion
|
|
425
|
+
export { GrokAskUserAnswers as A, PermissionPolicy as C, GrokExitPlanModeRequest as D, PromptInput as E, GrokAskUserQuestionResponse as M, GrokExitPlanModeResponse as O, PermissionMode as S, SessionRecord as T, AcpProcessSpawnFailure as _, AcpElicitationHandler as a, McpServer$1 as b, AcpElicitationResponse as c, AcpPermissionHandler as d, AcpPermissionRequest as f, AcpProcessLifecycle as g, AcpProcessLaunchScope as h, AcpElicitationContext as i, GrokAskUserQuestionRequest as j, GrokExitPlanOutcome as k, AcpJsonRpcMessage as l, AcpProcessLaunch as m, SystemPromptOption as n, AcpElicitationMode as o, AcpProcessExit as p, AcpClientOptions as r, AcpElicitationRequest as s, SessionAgentOptions as t, AcpPermissionDecision as u, AcpProcessStarted as v, PermissionStats as w, NonInteractivePermissionPolicy as x, AuthPolicy as y };
|
|
426
|
+
//# sourceMappingURL=session-options-ORCchZGk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-options-ORCchZGk.d.ts","names":[],"sources":["../src/acp/grok-ask-user.ts","../src/acp/grok-exit-plan.ts","../src/prompt-content.ts","../src/types.ts","../src/runtime/engine/session-options.ts"],"mappings":"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"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { i as JsonMessageSanitizer, t as createOutputFormatter } from "./output-BzXQKArM.js";
|
|
2
|
+
import { ct as parsePromptStopReason, rt as isAcpJsonRpcMessage } from "./ipc-BlljKR2b.js";
|
|
3
|
+
import { t as watchSession } from "./watch-iYiP-lOo.js";
|
|
4
|
+
import { once } from "node:events";
|
|
5
|
+
//#region src/cli/session-watch.ts
|
|
6
|
+
function watchRenderer(policy) {
|
|
7
|
+
const chunks = [];
|
|
8
|
+
const stdout = { write: (chunk) => {
|
|
9
|
+
chunks.push(chunk);
|
|
10
|
+
} };
|
|
11
|
+
let sanitizer = new JsonMessageSanitizer(policy.suppressReads, true);
|
|
12
|
+
let formatter = createOutputFormatter(policy.format, { stdout });
|
|
13
|
+
return (event) => {
|
|
14
|
+
chunks.length = 0;
|
|
15
|
+
if (event.type === "turn_started") {
|
|
16
|
+
sanitizer = new JsonMessageSanitizer(policy.suppressReads, true);
|
|
17
|
+
formatter = createOutputFormatter(policy.format, { stdout });
|
|
18
|
+
}
|
|
19
|
+
if (policy.format === "json") chunks.push(JSON.stringify(event.type === "message" ? {
|
|
20
|
+
...event,
|
|
21
|
+
message: sanitizer.sanitize(event.message)
|
|
22
|
+
} : event) + "\n");
|
|
23
|
+
else if (event.type === "message") renderWatchMessage(event, sanitizer, formatter, policy.format === "quiet");
|
|
24
|
+
else {
|
|
25
|
+
if (event.type === "turn_result") formatter.flush();
|
|
26
|
+
if (policy.format !== "quiet") chunks.push(watchLifecycleLine(event));
|
|
27
|
+
}
|
|
28
|
+
return chunks;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function renderWatchMessage(event, sanitizer, formatter, quiet) {
|
|
32
|
+
const message = sanitizer.sanitize(event.message);
|
|
33
|
+
if (!isAcpJsonRpcMessage(message)) throw new Error("Invalid sanitized session message");
|
|
34
|
+
if (quiet || parsePromptStopReason(message) === void 0) formatter.onAcpMessage(message);
|
|
35
|
+
}
|
|
36
|
+
function watchLifecycleLine(event) {
|
|
37
|
+
if (event.type === "turn_started") return `\n[${event.requestId}] started cursor=${event.cursor}\n`;
|
|
38
|
+
const detail = event.result.status === "failed" ? event.result.error.message : event.result.stopReason;
|
|
39
|
+
return `\n[${event.requestId}] ${event.result.status}${detail ? `: ${detail}` : ""} cursor=${event.cursor}\n`;
|
|
40
|
+
}
|
|
41
|
+
async function runSessionWatch(record, options) {
|
|
42
|
+
const stopped = new AbortController();
|
|
43
|
+
let outputError;
|
|
44
|
+
const stop = () => stopped.abort();
|
|
45
|
+
const onOutputError = (error) => {
|
|
46
|
+
if (error.code !== "EPIPE") outputError = error;
|
|
47
|
+
stop();
|
|
48
|
+
};
|
|
49
|
+
const render = watchRenderer(options.policy);
|
|
50
|
+
process.on("SIGINT", stop);
|
|
51
|
+
process.on("SIGTERM", stop);
|
|
52
|
+
process.on("SIGHUP", stop);
|
|
53
|
+
process.stdout.on("error", onOutputError);
|
|
54
|
+
try {
|
|
55
|
+
for await (const event of watchSession({
|
|
56
|
+
record,
|
|
57
|
+
cursor: options.cursor,
|
|
58
|
+
signal: stopped.signal
|
|
59
|
+
})) for (const chunk of render(event)) {
|
|
60
|
+
if (stopped.signal.aborted) break;
|
|
61
|
+
if (!process.stdout.write(chunk)) await once(process.stdout, "drain", { signal: stopped.signal });
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (!stopped.signal.aborted) throw error;
|
|
65
|
+
} finally {
|
|
66
|
+
process.off("SIGINT", stop);
|
|
67
|
+
process.off("SIGTERM", stop);
|
|
68
|
+
process.off("SIGHUP", stop);
|
|
69
|
+
process.stdout.off("error", onOutputError);
|
|
70
|
+
}
|
|
71
|
+
if (outputError) throw outputError;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { runSessionWatch };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=session-watch-BiBTBMz4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-watch-BiBTBMz4.js","names":[],"sources":["../src/cli/session-watch.ts"],"sourcesContent":["import { once } from \"node:events\";\nimport { isAcpJsonRpcMessage, parsePromptStopReason } from \"../acp/jsonrpc.js\";\nimport type { SessionWatchEvent } from \"../session/journal.js\";\nimport { watchSession } from \"../session/watch.js\";\nimport type { OutputFormatter, OutputPolicy, SessionRecord } from \"../types.js\";\nimport { JsonMessageSanitizer } from \"./output/json-formatter.js\";\nimport { createOutputFormatter } from \"./output/output.js\";\n\nfunction watchRenderer(policy: OutputPolicy): (event: SessionWatchEvent) => string[] {\n const chunks: string[] = [];\n const stdout = {\n write: (chunk: string) => {\n chunks.push(chunk);\n },\n };\n let sanitizer = new JsonMessageSanitizer(policy.suppressReads, true);\n let formatter = createOutputFormatter(policy.format, { stdout });\n return (event) => {\n chunks.length = 0;\n if (event.type === \"turn_started\") {\n sanitizer = new JsonMessageSanitizer(policy.suppressReads, true);\n formatter = createOutputFormatter(policy.format, { stdout });\n }\n if (policy.format === \"json\") {\n chunks.push(\n JSON.stringify(\n event.type === \"message\"\n ? { ...event, message: sanitizer.sanitize(event.message) }\n : event,\n ) + \"\\n\",\n );\n } else if (event.type === \"message\") {\n renderWatchMessage(event, sanitizer, formatter, policy.format === \"quiet\");\n } else {\n if (event.type === \"turn_result\") {\n formatter.flush();\n }\n if (policy.format !== \"quiet\") {\n chunks.push(watchLifecycleLine(event));\n }\n }\n return chunks;\n };\n}\n\nfunction renderWatchMessage(\n event: Extract<SessionWatchEvent, { type: \"message\" }>,\n sanitizer: JsonMessageSanitizer,\n formatter: OutputFormatter,\n quiet: boolean,\n): void {\n const message = sanitizer.sanitize(event.message);\n if (!isAcpJsonRpcMessage(message)) {\n throw new Error(\"Invalid sanitized session message\");\n }\n if (quiet || parsePromptStopReason(message) === undefined) {\n formatter.onAcpMessage(message);\n }\n}\n\nfunction watchLifecycleLine(event: Exclude<SessionWatchEvent, { type: \"message\" }>): string {\n if (event.type === \"turn_started\") {\n return `\\n[${event.requestId}] started cursor=${event.cursor}\\n`;\n }\n const detail =\n event.result.status === \"failed\" ? event.result.error.message : event.result.stopReason;\n return `\\n[${event.requestId}] ${event.result.status}${detail ? `: ${detail}` : \"\"} cursor=${event.cursor}\\n`;\n}\n\nexport async function runSessionWatch(\n record: SessionRecord,\n options: { cursor?: string; policy: OutputPolicy },\n): Promise<void> {\n const stopped = new AbortController();\n let outputError: Error | undefined;\n const stop = () => stopped.abort();\n const onOutputError = (error: Error) => {\n if ((error as NodeJS.ErrnoException).code !== \"EPIPE\") {\n outputError = error;\n }\n stop();\n };\n const render = watchRenderer(options.policy);\n process.on(\"SIGINT\", stop);\n process.on(\"SIGTERM\", stop);\n process.on(\"SIGHUP\", stop);\n process.stdout.on(\"error\", onOutputError);\n try {\n for await (const event of watchSession({\n record,\n cursor: options.cursor,\n signal: stopped.signal,\n })) {\n for (const chunk of render(event)) {\n if (stopped.signal.aborted) {\n break;\n }\n if (!process.stdout.write(chunk)) {\n await once(process.stdout, \"drain\", { signal: stopped.signal });\n }\n }\n }\n } catch (error) {\n if (!stopped.signal.aborted) {\n throw error;\n }\n } finally {\n process.off(\"SIGINT\", stop);\n process.off(\"SIGTERM\", stop);\n process.off(\"SIGHUP\", stop);\n process.stdout.off(\"error\", onOutputError);\n }\n if (outputError) {\n throw outputError;\n }\n}\n"],"mappings":";;;;;AAQA,SAAS,cAAc,QAA8D;CACnF,MAAM,SAAmB,CAAC;CAC1B,MAAM,SAAS,EACb,QAAQ,UAAkB;EACxB,OAAO,KAAK,KAAK;CACnB,EACF;CACA,IAAI,YAAY,IAAI,qBAAqB,OAAO,eAAe,IAAI;CACnE,IAAI,YAAY,sBAAsB,OAAO,QAAQ,EAAE,OAAO,CAAC;CAC/D,QAAQ,UAAU;EAChB,OAAO,SAAS;EAChB,IAAI,MAAM,SAAS,gBAAgB;GACjC,YAAY,IAAI,qBAAqB,OAAO,eAAe,IAAI;GAC/D,YAAY,sBAAsB,OAAO,QAAQ,EAAE,OAAO,CAAC;EAC7D;EACA,IAAI,OAAO,WAAW,QACpB,OAAO,KACL,KAAK,UACH,MAAM,SAAS,YACX;GAAE,GAAG;GAAO,SAAS,UAAU,SAAS,MAAM,OAAO;EAAE,IACvD,KACN,IAAI,IACN;OACK,IAAI,MAAM,SAAS,WACxB,mBAAmB,OAAO,WAAW,WAAW,OAAO,WAAW,OAAO;OACpE;GACL,IAAI,MAAM,SAAS,eACjB,UAAU,MAAM;GAElB,IAAI,OAAO,WAAW,SACpB,OAAO,KAAK,mBAAmB,KAAK,CAAC;EAEzC;EACA,OAAO;CACT;AACF;AAEA,SAAS,mBACP,OACA,WACA,WACA,OACM;CACN,MAAM,UAAU,UAAU,SAAS,MAAM,OAAO;CAChD,IAAI,CAAC,oBAAoB,OAAO,GAC9B,MAAM,IAAI,MAAM,mCAAmC;CAErD,IAAI,SAAS,sBAAsB,OAAO,MAAM,KAAA,GAC9C,UAAU,aAAa,OAAO;AAElC;AAEA,SAAS,mBAAmB,OAAgE;CAC1F,IAAI,MAAM,SAAS,gBACjB,OAAO,MAAM,MAAM,UAAU,mBAAmB,MAAM,OAAO;CAE/D,MAAM,SACJ,MAAM,OAAO,WAAW,WAAW,MAAM,OAAO,MAAM,UAAU,MAAM,OAAO;CAC/E,OAAO,MAAM,MAAM,UAAU,IAAI,MAAM,OAAO,SAAS,SAAS,KAAK,WAAW,GAAG,UAAU,MAAM,OAAO;AAC5G;AAEA,eAAsB,gBACpB,QACA,SACe;CACf,MAAM,UAAU,IAAI,gBAAgB;CACpC,IAAI;CACJ,MAAM,aAAa,QAAQ,MAAM;CACjC,MAAM,iBAAiB,UAAiB;EACtC,IAAK,MAAgC,SAAS,SAC5C,cAAc;EAEhB,KAAK;CACP;CACA,MAAM,SAAS,cAAc,QAAQ,MAAM;CAC3C,QAAQ,GAAG,UAAU,IAAI;CACzB,QAAQ,GAAG,WAAW,IAAI;CAC1B,QAAQ,GAAG,UAAU,IAAI;CACzB,QAAQ,OAAO,GAAG,SAAS,aAAa;CACxC,IAAI;EACF,WAAW,MAAM,SAAS,aAAa;GACrC;GACA,QAAQ,QAAQ;GAChB,QAAQ,QAAQ;EAClB,CAAC,GACC,KAAK,MAAM,SAAS,OAAO,KAAK,GAAG;GACjC,IAAI,QAAQ,OAAO,SACjB;GAEF,IAAI,CAAC,QAAQ,OAAO,MAAM,KAAK,GAC7B,MAAM,KAAK,QAAQ,QAAQ,SAAS,EAAE,QAAQ,QAAQ,OAAO,CAAC;EAElE;CAEJ,SAAS,OAAO;EACd,IAAI,CAAC,QAAQ,OAAO,SAClB,MAAM;CAEV,UAAU;EACR,QAAQ,IAAI,UAAU,IAAI;EAC1B,QAAQ,IAAI,WAAW,IAAI;EAC3B,QAAQ,IAAI,UAAU,IAAI;EAC1B,QAAQ,OAAO,IAAI,SAAS,aAAa;CAC3C;CACA,IAAI,aACF,MAAM;AAEV"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { E as observeProcessIncarnation, J as watchSession$1, L as readSessionRecord, l as readQueueOwnerRecord, q as SessionWatchError, qt as SessionNotFoundError } from "./ipc-BlljKR2b.js";
|
|
2
|
+
//#region src/session/watch.ts
|
|
3
|
+
const OWNER_OBSERVATION_REUSE_MS = 1e3;
|
|
4
|
+
function reuseObservation(cached) {
|
|
5
|
+
if (!cached) return false;
|
|
6
|
+
if (cached.decisionPending) {
|
|
7
|
+
cached.decisionPending = false;
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return cached.state === "gone" || performance.now() - cached.checkedAt < OWNER_OBSERVATION_REUSE_MS;
|
|
11
|
+
}
|
|
12
|
+
function selectOwner(owner, observation) {
|
|
13
|
+
const key = owner ? JSON.stringify([
|
|
14
|
+
owner.pid,
|
|
15
|
+
owner.ownerGeneration,
|
|
16
|
+
owner.processIdentity
|
|
17
|
+
]) : null;
|
|
18
|
+
if (key === observation.ownerKey) return false;
|
|
19
|
+
observation.ownerKey = key;
|
|
20
|
+
observation.incarnation = void 0;
|
|
21
|
+
observation.missingRequest = null;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
async function runningOwner(recordId, observation) {
|
|
25
|
+
let owner = await readQueueOwnerRecord(recordId);
|
|
26
|
+
selectOwner(owner, observation);
|
|
27
|
+
if (!owner) return { queried: false };
|
|
28
|
+
const cached = observation.incarnation;
|
|
29
|
+
let queried = false;
|
|
30
|
+
if (!reuseObservation(cached)) {
|
|
31
|
+
queried = true;
|
|
32
|
+
const state = await observeProcessIncarnation(owner.pid, owner.processIdentity);
|
|
33
|
+
owner = await readQueueOwnerRecord(recordId);
|
|
34
|
+
if (selectOwner(owner, observation)) return {
|
|
35
|
+
owner,
|
|
36
|
+
queried
|
|
37
|
+
};
|
|
38
|
+
observation.incarnation = {
|
|
39
|
+
state,
|
|
40
|
+
checkedAt: performance.now(),
|
|
41
|
+
decisionPending: true
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
owner: observation.incarnation?.state === "gone" ? void 0 : owner,
|
|
46
|
+
queried
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function continueWatching(recordId, pendingRequestId, observation) {
|
|
50
|
+
const { owner, queried } = await runningOwner(recordId, observation);
|
|
51
|
+
if (queried) {
|
|
52
|
+
observation.missingRequest = owner ? null : pendingRequestId;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (owner) {
|
|
56
|
+
if (!owner.sessionWatch) throw new SessionWatchError("WATCH_OWNER_UNSUPPORTED", "This running session owner predates passive watching. Let it expire when idle or explicitly close the session before starting new work.");
|
|
57
|
+
observation.missingRequest = null;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (pendingRequestId && pendingRequestId === observation.missingRequest) throw new SessionWatchError("WATCH_OUTCOME_UNKNOWN", `Session owner ended without a settled result for request ${pendingRequestId}; its outcome is unknown. Resume watching from the last cursor after recovery, and do not automatically replay the prompt.`);
|
|
61
|
+
observation.missingRequest = pendingRequestId;
|
|
62
|
+
if (pendingRequestId) return true;
|
|
63
|
+
return await isSessionOpen(recordId);
|
|
64
|
+
}
|
|
65
|
+
async function isSessionOpen(recordId) {
|
|
66
|
+
const record = await readSessionRecord(recordId);
|
|
67
|
+
if (!record || record.acpxRecordId !== recordId) throw new SessionNotFoundError(recordId);
|
|
68
|
+
return record.closed !== true;
|
|
69
|
+
}
|
|
70
|
+
function watchSession(options) {
|
|
71
|
+
return { [Symbol.asyncIterator]() {
|
|
72
|
+
const observation = {
|
|
73
|
+
ownerKey: null,
|
|
74
|
+
missingRequest: null
|
|
75
|
+
};
|
|
76
|
+
return watchSession$1({
|
|
77
|
+
...options,
|
|
78
|
+
continueWatching: (record, requestId) => continueWatching(record.acpxRecordId, requestId, observation)
|
|
79
|
+
})[Symbol.asyncIterator]();
|
|
80
|
+
} };
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { watchSession as t };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=watch-iYiP-lOo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-iYiP-lOo.js","names":["watchJournal"],"sources":["../src/session/watch.ts"],"sourcesContent":["import { SessionNotFoundError } from \"../errors.js\";\nimport { observeProcessIncarnation, type ProcessIncarnation } from \"../process-identity.js\";\nimport type { SessionRecord } from \"../types.js\";\nimport {\n SessionWatchError,\n watchSession as watchJournal,\n type SessionWatchEvent,\n} from \"./journal.js\";\nimport { readSessionRecord } from \"./persistence.js\";\nimport { readQueueOwnerRecord, type QueueOwnerRecord } from \"./queue/lease-store.js\";\n\nconst OWNER_OBSERVATION_REUSE_MS = 1_000;\n\ntype WatchObservation = {\n ownerKey: string | null;\n incarnation?: { state: ProcessIncarnation; checkedAt: number; decisionPending: boolean };\n missingRequest: string | null;\n};\n\nfunction reuseObservation(cached: WatchObservation[\"incarnation\"]): boolean {\n if (!cached) {\n return false;\n }\n // A query first forces a journal reread, then gets one decision pass even\n // after a slow consumer. Otherwise repeated probes can defer errors forever.\n if (cached.decisionPending) {\n cached.decisionPending = false;\n return true;\n }\n return (\n cached.state === \"gone\" || performance.now() - cached.checkedAt < OWNER_OBSERVATION_REUSE_MS\n );\n}\n\nfunction selectOwner(owner: QueueOwnerRecord | undefined, observation: WatchObservation): boolean {\n // Heartbeats and retirement receipts do not change the owner's incarnation.\n // Keep only this small key, never the potentially large descendant receipt.\n const key = owner\n ? JSON.stringify([owner.pid, owner.ownerGeneration, owner.processIdentity])\n : null;\n if (key === observation.ownerKey) {\n return false;\n }\n observation.ownerKey = key;\n observation.incarnation = undefined;\n observation.missingRequest = null;\n return true;\n}\n\nasync function runningOwner(\n recordId: string,\n observation: WatchObservation,\n): Promise<{ owner?: QueueOwnerRecord; queried: boolean }> {\n let owner = await readQueueOwnerRecord(recordId);\n selectOwner(owner, observation);\n if (!owner) {\n return { queried: false };\n }\n const cached = observation.incarnation;\n let queried = false;\n // A verified departed incarnation cannot return. Cache that fact even for\n // idle watches; other observations are bounded independently of journal polls.\n if (!reuseObservation(cached)) {\n queried = true;\n // Observation cadence must not truncate the canonical provider's query budget.\n const state = await observeProcessIncarnation(owner.pid, owner.processIdentity);\n owner = await readQueueOwnerRecord(recordId);\n if (selectOwner(owner, observation)) {\n // A replacement may have settled or recovered the journal during the\n // query. Let the reader revisit it before interpreting the old result.\n return { owner, queried };\n }\n observation.incarnation = { state, checkedAt: performance.now(), decisionPending: true };\n }\n return { owner: observation.incarnation?.state === \"gone\" ? undefined : owner, queried };\n}\n\nasync function continueWatching(\n recordId: string,\n pendingRequestId: string | null,\n observation: WatchObservation,\n): Promise<boolean> {\n const { owner, queried } = await runningOwner(recordId, observation);\n if (queried) {\n // A probe can outlast a journal update, including replacement by an older\n // owner. Revisit the journal before any unsupported/unknown/end decision.\n observation.missingRequest = owner ? null : pendingRequestId;\n return true;\n }\n if (owner) {\n if (!owner.sessionWatch) {\n throw new SessionWatchError(\n \"WATCH_OWNER_UNSUPPORTED\",\n \"This running session owner predates passive watching. Let it expire when idle or explicitly close the session before starting new work.\",\n );\n }\n observation.missingRequest = null;\n return true;\n }\n if (pendingRequestId && pendingRequestId === observation.missingRequest) {\n throw new SessionWatchError(\n \"WATCH_OUTCOME_UNKNOWN\",\n `Session owner ended without a settled result for request ${pendingRequestId}; its outcome is unknown. Resume watching from the last cursor after recovery, and do not automatically replay the prompt.`,\n );\n }\n observation.missingRequest = pendingRequestId;\n if (pendingRequestId) {\n return true;\n }\n return await isSessionOpen(recordId);\n}\n\nasync function isSessionOpen(recordId: string): Promise<boolean> {\n const record = await readSessionRecord(recordId);\n if (!record || record.acpxRecordId !== recordId) {\n throw new SessionNotFoundError(recordId);\n }\n return record.closed !== true;\n}\n\nexport function watchSession(options: {\n record: SessionRecord | Promise<SessionRecord>;\n cursor?: string;\n signal?: AbortSignal;\n}): AsyncIterable<SessionWatchEvent> {\n return {\n [Symbol.asyncIterator]() {\n const observation: WatchObservation = { ownerKey: null, missingRequest: null };\n return watchJournal({\n ...options,\n continueWatching: (record, requestId) =>\n continueWatching(record.acpxRecordId, requestId, observation),\n })[Symbol.asyncIterator]();\n },\n };\n}\n"],"mappings":";;AAWA,MAAM,6BAA6B;AAQnC,SAAS,iBAAiB,QAAkD;CAC1E,IAAI,CAAC,QACH,OAAO;CAIT,IAAI,OAAO,iBAAiB;EAC1B,OAAO,kBAAkB;EACzB,OAAO;CACT;CACA,OACE,OAAO,UAAU,UAAU,YAAY,IAAI,IAAI,OAAO,YAAY;AAEtE;AAEA,SAAS,YAAY,OAAqC,aAAwC;CAGhG,MAAM,MAAM,QACR,KAAK,UAAU;EAAC,MAAM;EAAK,MAAM;EAAiB,MAAM;CAAe,CAAC,IACxE;CACJ,IAAI,QAAQ,YAAY,UACtB,OAAO;CAET,YAAY,WAAW;CACvB,YAAY,cAAc,KAAA;CAC1B,YAAY,iBAAiB;CAC7B,OAAO;AACT;AAEA,eAAe,aACb,UACA,aACyD;CACzD,IAAI,QAAQ,MAAM,qBAAqB,QAAQ;CAC/C,YAAY,OAAO,WAAW;CAC9B,IAAI,CAAC,OACH,OAAO,EAAE,SAAS,MAAM;CAE1B,MAAM,SAAS,YAAY;CAC3B,IAAI,UAAU;CAGd,IAAI,CAAC,iBAAiB,MAAM,GAAG;EAC7B,UAAU;EAEV,MAAM,QAAQ,MAAM,0BAA0B,MAAM,KAAK,MAAM,eAAe;EAC9E,QAAQ,MAAM,qBAAqB,QAAQ;EAC3C,IAAI,YAAY,OAAO,WAAW,GAGhC,OAAO;GAAE;GAAO;EAAQ;EAE1B,YAAY,cAAc;GAAE;GAAO,WAAW,YAAY,IAAI;GAAG,iBAAiB;EAAK;CACzF;CACA,OAAO;EAAE,OAAO,YAAY,aAAa,UAAU,SAAS,KAAA,IAAY;EAAO;CAAQ;AACzF;AAEA,eAAe,iBACb,UACA,kBACA,aACkB;CAClB,MAAM,EAAE,OAAO,YAAY,MAAM,aAAa,UAAU,WAAW;CACnE,IAAI,SAAS;EAGX,YAAY,iBAAiB,QAAQ,OAAO;EAC5C,OAAO;CACT;CACA,IAAI,OAAO;EACT,IAAI,CAAC,MAAM,cACT,MAAM,IAAI,kBACR,2BACA,yIACF;EAEF,YAAY,iBAAiB;EAC7B,OAAO;CACT;CACA,IAAI,oBAAoB,qBAAqB,YAAY,gBACvD,MAAM,IAAI,kBACR,yBACA,4DAA4D,iBAAiB,2HAC/E;CAEF,YAAY,iBAAiB;CAC7B,IAAI,kBACF,OAAO;CAET,OAAO,MAAM,cAAc,QAAQ;AACrC;AAEA,eAAe,cAAc,UAAoC;CAC/D,MAAM,SAAS,MAAM,kBAAkB,QAAQ;CAC/C,IAAI,CAAC,UAAU,OAAO,iBAAiB,UACrC,MAAM,IAAI,qBAAqB,QAAQ;CAEzC,OAAO,OAAO,WAAW;AAC3B;AAEA,SAAgB,aAAa,SAIQ;CACnC,OAAO,EACL,CAAC,OAAO,iBAAiB;EACvB,MAAM,cAAgC;GAAE,UAAU;GAAM,gBAAgB;EAAK;EAC7E,OAAOA,eAAa;GAClB,GAAG;GACH,mBAAmB,QAAQ,cACzB,iBAAiB,OAAO,cAAc,WAAW,WAAW;EAChE,CAAC,CAAC,CAAC,OAAO,cAAc,CAAC;CAC3B,EACF;AACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scottzx/1acp",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Headless CLI client for the Agent Client Protocol (ACP) — talk to coding agents from the command line",
|
|
6
|
+
"homepage": null,
|
|
7
|
+
"bugs": null,
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "scottzx",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/scottzx/1acp.git",
|
|
13
|
+
"directory": "packages/runtime"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"1acp": "dist/cli.js",
|
|
17
|
+
"acpx": "dist/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"skills",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./dist/cli.js",
|
|
28
|
+
"./flows": "./dist/flows.js",
|
|
29
|
+
"./dist/*": "./dist/*",
|
|
30
|
+
"./runtime": "./dist/runtime.js",
|
|
31
|
+
"./package.json": "./package.json",
|
|
32
|
+
"./agent-registry": "./dist/agent-registry.js"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@1agents/acp-runtime-sdk": "npm:@agentclientprotocol/sdk@^1.5.0",
|
|
36
|
+
"@openclaw/fs-safe": "^0.20.0",
|
|
37
|
+
"commander": "^15.0.0",
|
|
38
|
+
"skillflag": "^0.2.1",
|
|
39
|
+
"tsx": "^4.23.15",
|
|
40
|
+
"zod": "^4.6.5"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22.13.0"
|
|
44
|
+
},
|
|
45
|
+
"packageManager": "pnpm@11.27.1"
|
|
46
|
+
}
|