@visual-z/xeno 0.8.4 → 0.9.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/CHANGELOG.md +8 -0
- package/README.md +31 -746
- package/bin/xeno.exe +26 -0
- package/install.cjs +88 -0
- package/package.json +18 -48
- package/docs/app-server.md +0 -115
- package/docs/foundations.md +0 -88
- package/docs/install.md +0 -244
- package/docs/providers.md +0 -172
- package/docs/research/foundation-clients-2026-10-09.md +0 -27
- package/docs/research/foundation-editing-2026-10-09.md +0 -56
- package/docs/research/foundation-network-2026-10-09.md +0 -37
- package/docs/research/foundation-workflow-2026-10-09.md +0 -37
- package/src/apps/acp-server.ts +0 -41
- package/src/apps/agent-profiles.ts +0 -19
- package/src/apps/app-server.ts +0 -30
- package/src/apps/approve.ts +0 -49
- package/src/apps/cli.ts +0 -99
- package/src/apps/commands.ts +0 -319
- package/src/apps/completions.ts +0 -87
- package/src/apps/control-transport.ts +0 -90
- package/src/apps/export-cli.ts +0 -24
- package/src/apps/goal-flow.ts +0 -70
- package/src/apps/image-draft.ts +0 -46
- package/src/apps/input.ts +0 -312
- package/src/apps/model-catalog.ts +0 -69
- package/src/apps/preferences.ts +0 -20
- package/src/apps/project-trust.ts +0 -9
- package/src/apps/provider-connect.ts +0 -346
- package/src/apps/question-ui.ts +0 -27
- package/src/apps/render.ts +0 -181
- package/src/apps/resources.ts +0 -66
- package/src/apps/review.ts +0 -109
- package/src/apps/session-hub.ts +0 -96
- package/src/apps/session-lifecycle.ts +0 -64
- package/src/apps/shell.ts +0 -2071
- package/src/apps/startup-input.ts +0 -135
- package/src/apps/startup.ts +0 -1677
- package/src/apps/ui/app.ts +0 -1818
- package/src/apps/ui/control-model.ts +0 -43
- package/src/apps/ui/extension-host.ts +0 -194
- package/src/apps/ui/image-cache.ts +0 -121
- package/src/apps/ui/palette.ts +0 -88
- package/src/apps/ui/project.ts +0 -127
- package/src/apps/ui/standalone.ts +0 -148
- package/src/apps/ui/status-model.ts +0 -68
- package/src/apps/ui/surface.ts +0 -91
- package/src/apps/ui/theme.ts +0 -86
- package/src/apps/update-check.ts +0 -112
- package/src/apps/workflow.ts +0 -58
- package/src/core/acceptance.ts +0 -139
- package/src/core/action-defaults.ts +0 -58
- package/src/core/activity-status.ts +0 -52
- package/src/core/agent-profile.ts +0 -130
- package/src/core/attachment-input.ts +0 -17
- package/src/core/blind-checks.ts +0 -72
- package/src/core/boundary.ts +0 -174
- package/src/core/branch-receipt.ts +0 -26
- package/src/core/catalog-merge.ts +0 -19
- package/src/core/checkpoints.ts +0 -85
- package/src/core/churn.ts +0 -61
- package/src/core/command-artifacts.ts +0 -94
- package/src/core/command-contract.ts +0 -151
- package/src/core/completion-action.ts +0 -20
- package/src/core/completion-review.ts +0 -98
- package/src/core/context-detail.ts +0 -37
- package/src/core/context-policy.ts +0 -133
- package/src/core/context-window.ts +0 -54
- package/src/core/continuation.ts +0 -130
- package/src/core/control-protocol.ts +0 -69
- package/src/core/control-view.ts +0 -39
- package/src/core/cycle.ts +0 -17
- package/src/core/data-query.ts +0 -201
- package/src/core/deadline.ts +0 -40
- package/src/core/derive.ts +0 -516
- package/src/core/draft-images.ts +0 -56
- package/src/core/edit-plan.ts +0 -200
- package/src/core/environment.ts +0 -181
- package/src/core/event-validation.ts +0 -220
- package/src/core/events.ts +0 -670
- package/src/core/evidence-ladder.ts +0 -62
- package/src/core/evidence-links.ts +0 -68
- package/src/core/evidence.ts +0 -240
- package/src/core/execution.ts +0 -18
- package/src/core/exhaustive.ts +0 -18
- package/src/core/export.ts +0 -179
- package/src/core/extension-flags.ts +0 -14
- package/src/core/external-effects.ts +0 -488
- package/src/core/failure-recovery.ts +0 -173
- package/src/core/file-precondition.ts +0 -78
- package/src/core/file-references.ts +0 -35
- package/src/core/frontmatter.ts +0 -213
- package/src/core/git-status.ts +0 -29
- package/src/core/goal-view.ts +0 -64
- package/src/core/goal.ts +0 -200
- package/src/core/handoff.ts +0 -479
- package/src/core/history-query.ts +0 -139
- package/src/core/history.ts +0 -237
- package/src/core/image-limits.ts +0 -72
- package/src/core/images.ts +0 -46
- package/src/core/integration-health.ts +0 -34
- package/src/core/json-event.ts +0 -131
- package/src/core/json-pointer.ts +0 -46
- package/src/core/keymap.ts +0 -153
- package/src/core/lsp-framing.ts +0 -34
- package/src/core/mcp-config.ts +0 -68
- package/src/core/model-picker.ts +0 -64
- package/src/core/model-preferences.ts +0 -28
- package/src/core/model-replay.ts +0 -22
- package/src/core/model-scope.ts +0 -53
- package/src/core/note-guidance.ts +0 -34
- package/src/core/oauth-fields.ts +0 -44
- package/src/core/observation-view.ts +0 -152
- package/src/core/outcome.ts +0 -44
- package/src/core/overflow.ts +0 -59
- package/src/core/packages.ts +0 -47
- package/src/core/patch.ts +0 -130
- package/src/core/path-suggestions.ts +0 -59
- package/src/core/permissions.ts +0 -410
- package/src/core/process-receipt.ts +0 -105
- package/src/core/process-state.ts +0 -37
- package/src/core/program-status.ts +0 -40
- package/src/core/progress.ts +0 -150
- package/src/core/project.ts +0 -431
- package/src/core/prompt-policy.ts +0 -46
- package/src/core/prompts.ts +0 -111
- package/src/core/question.ts +0 -94
- package/src/core/queue.ts +0 -78
- package/src/core/read-bounds.ts +0 -24
- package/src/core/read-observation.ts +0 -106
- package/src/core/recovery-sources.ts +0 -74
- package/src/core/regex-dialect.ts +0 -25
- package/src/core/request-budget.ts +0 -23
- package/src/core/request-progress.ts +0 -87
- package/src/core/request-state.ts +0 -273
- package/src/core/resource-selection.ts +0 -36
- package/src/core/response-recovery.ts +0 -59
- package/src/core/resume.ts +0 -59
- package/src/core/review.ts +0 -68
- package/src/core/ripgrep-release.ts +0 -64
- package/src/core/runtime-target.ts +0 -94
- package/src/core/scheduling.ts +0 -8
- package/src/core/search-observation.ts +0 -97
- package/src/core/secrets.ts +0 -188
- package/src/core/session-archive.ts +0 -4
- package/src/core/session-browser.ts +0 -82
- package/src/core/session-entry.ts +0 -61
- package/src/core/session-exit.ts +0 -42
- package/src/core/session-format.ts +0 -169
- package/src/core/session-position.ts +0 -26
- package/src/core/session-tree.ts +0 -147
- package/src/core/settings.ts +0 -192
- package/src/core/skills.ts +0 -165
- package/src/core/sql-query.ts +0 -211
- package/src/core/stall.ts +0 -128
- package/src/core/stop-report.ts +0 -68
- package/src/core/text-normalize.ts +0 -81
- package/src/core/theme.ts +0 -166
- package/src/core/thinking.ts +0 -26
- package/src/core/tokens.ts +0 -151
- package/src/core/tool-contract.ts +0 -153
- package/src/core/tool-discovery.ts +0 -87
- package/src/core/tool-failure.ts +0 -81
- package/src/core/tool-input.ts +0 -44
- package/src/core/transcript.ts +0 -108
- package/src/core/tui-mode.ts +0 -29
- package/src/core/update-check.ts +0 -157
- package/src/core/version.ts +0 -55
- package/src/core/web-content.ts +0 -80
- package/src/core/work-state.ts +0 -154
- package/src/core/workflow-mode.ts +0 -34
- package/src/core/working-set.ts +0 -119
- package/src/core/yaml.ts +0 -282
- package/src/runtime/acp-agent.ts +0 -289
- package/src/runtime/agent-profiles.ts +0 -21
- package/src/runtime/auth.ts +0 -367
- package/src/runtime/blind-check.ts +0 -36
- package/src/runtime/branch-jobs.ts +0 -36
- package/src/runtime/catalog.ts +0 -285
- package/src/runtime/clipboard.ts +0 -125
- package/src/runtime/command-artifacts.ts +0 -64
- package/src/runtime/connection-reuse.ts +0 -40
- package/src/runtime/control-client.ts +0 -149
- package/src/runtime/control-connection.ts +0 -139
- package/src/runtime/counter-check.ts +0 -74
- package/src/runtime/environment-tools.ts +0 -60
- package/src/runtime/evidence-notes.ts +0 -35
- package/src/runtime/exec-sessions.ts +0 -456
- package/src/runtime/execution-control.ts +0 -40
- package/src/runtime/extension-loader.ts +0 -37
- package/src/runtime/extension-ui.ts +0 -47
- package/src/runtime/extensions.ts +0 -370
- package/src/runtime/formatter-tool.ts +0 -38
- package/src/runtime/formatter.ts +0 -50
- package/src/runtime/foundation.ts +0 -116
- package/src/runtime/history-cache.ts +0 -57
- package/src/runtime/history-tools.ts +0 -168
- package/src/runtime/images.ts +0 -80
- package/src/runtime/integrations.ts +0 -216
- package/src/runtime/loop.ts +0 -3108
- package/src/runtime/lsp-client.ts +0 -201
- package/src/runtime/mcp-client.ts +0 -264
- package/src/runtime/mcp-oauth.ts +0 -168
- package/src/runtime/mcp-schema.ts +0 -51
- package/src/runtime/model-config.ts +0 -232
- package/src/runtime/model-data.LICENSE +0 -27
- package/src/runtime/model-data.ts +0 -21
- package/src/runtime/model-discovery.ts +0 -208
- package/src/runtime/model-replay.ts +0 -10
- package/src/runtime/model-scope.ts +0 -20
- package/src/runtime/model-sources.ts +0 -151
- package/src/runtime/model.ts +0 -686
- package/src/runtime/models-fetch.ts +0 -57
- package/src/runtime/oauth-device.ts +0 -86
- package/src/runtime/oauth.ts +0 -853
- package/src/runtime/open-image.ts +0 -42
- package/src/runtime/openai-responses.ts +0 -304
- package/src/runtime/openai.ts +0 -697
- package/src/runtime/output-schema.ts +0 -26
- package/src/runtime/package-manager.ts +0 -125
- package/src/runtime/patch-tool.ts +0 -38
- package/src/runtime/permission-resources.ts +0 -18
- package/src/runtime/pi-provider.ts +0 -423
- package/src/runtime/program-status.ts +0 -38
- package/src/runtime/progress.ts +0 -26
- package/src/runtime/provider-access.ts +0 -21
- package/src/runtime/provider-connect.ts +0 -109
- package/src/runtime/provider-presets.ts +0 -98
- package/src/runtime/provider-protocols.ts +0 -29
- package/src/runtime/provider-request.ts +0 -87
- package/src/runtime/provider-tool-policy.ts +0 -33
- package/src/runtime/provider.ts +0 -580
- package/src/runtime/question-tool.ts +0 -62
- package/src/runtime/retry.ts +0 -447
- package/src/runtime/review-tool.ts +0 -48
- package/src/runtime/rich-text.ts +0 -36
- package/src/runtime/runtime-target.ts +0 -149
- package/src/runtime/secrets.ts +0 -79
- package/src/runtime/self-update.ts +0 -74
- package/src/runtime/session-control.ts +0 -265
- package/src/runtime/session-hub.ts +0 -85
- package/src/runtime/stream-idle.ts +0 -80
- package/src/runtime/tool-broker.ts +0 -137
- package/src/runtime/tool-discovery.ts +0 -58
- package/src/runtime/tool-queue.ts +0 -77
- package/src/runtime/tools.ts +0 -1820
- package/src/runtime/turn-effects.ts +0 -31
- package/src/runtime/update-check.ts +0 -48
- package/src/runtime/usage.ts +0 -253
- package/src/runtime/version.ts +0 -12
- package/src/runtime/web-http.ts +0 -56
- package/src/runtime/web-tools.ts +0 -88
- package/src/runtime/working-notes.ts +0 -60
- package/src/runtime/workspace-lifecycle.ts +0 -141
- package/src/store/acceptance.ts +0 -15
- package/src/store/agent-profile-files.ts +0 -13
- package/src/store/atomic.ts +0 -31
- package/src/store/auth-store.ts +0 -50
- package/src/store/blind-checks.ts +0 -32
- package/src/store/blobs.ts +0 -143
- package/src/store/checkpoint-history.ts +0 -32
- package/src/store/command-artifacts.ts +0 -96
- package/src/store/command.ts +0 -111
- package/src/store/config.ts +0 -69
- package/src/store/context-files.ts +0 -436
- package/src/store/file-checkpoints.ts +0 -108
- package/src/store/file-index.ts +0 -174
- package/src/store/foundation-config.ts +0 -24
- package/src/store/git-checkpoints.ts +0 -67
- package/src/store/git-status.ts +0 -15
- package/src/store/history-search.ts +0 -19
- package/src/store/log.ts +0 -725
- package/src/store/lsp-document.ts +0 -30
- package/src/store/mcp-credentials.ts +0 -85
- package/src/store/models.ts +0 -60
- package/src/store/observations.ts +0 -224
- package/src/store/packages.ts +0 -98
- package/src/store/patch.ts +0 -92
- package/src/store/permission-paths.ts +0 -34
- package/src/store/process-receipts.ts +0 -34
- package/src/store/query-source.ts +0 -49
- package/src/store/recovery.ts +0 -44
- package/src/store/replay.ts +0 -76
- package/src/store/resource-index.ts +0 -170
- package/src/store/resources.ts +0 -285
- package/src/store/restore.ts +0 -110
- package/src/store/review.ts +0 -109
- package/src/store/runtime-target.ts +0 -64
- package/src/store/search.ts +0 -728
- package/src/store/secrets.ts +0 -44
- package/src/store/serial.ts +0 -13
- package/src/store/session-archive.ts +0 -165
- package/src/store/session-browser.ts +0 -68
- package/src/store/session-position.ts +0 -27
- package/src/store/sessions.ts +0 -525
- package/src/store/source-cancellation.ts +0 -6
- package/src/store/tool-binaries.ts +0 -90
- package/src/store/trust.ts +0 -82
- package/src/store/update-cache.ts +0 -36
- package/src/store/user-settings.ts +0 -30
- package/src/store/workspace-clone.ts +0 -42
- package/src/store/workspace-observation.ts +0 -113
- package/src/store/workspace.ts +0 -115
- package/src/store/worktree.ts +0 -278
- package/src/tui/ansi-spans.ts +0 -126
- package/src/tui/diff.ts +0 -160
- package/src/tui/exhaustive.ts +0 -14
- package/src/tui/fuzzy.ts +0 -75
- package/src/tui/style.ts +0 -208
- package/src/tui/ui/atomic-draft.ts +0 -121
- package/src/tui/ui/branch-panel.ts +0 -47
- package/src/tui/ui/canvas.ts +0 -96
- package/src/tui/ui/colors.ts +0 -70
- package/src/tui/ui/composer.ts +0 -199
- package/src/tui/ui/control-panel.ts +0 -25
- package/src/tui/ui/control-sidebar.ts +0 -49
- package/src/tui/ui/dialog.ts +0 -398
- package/src/tui/ui/draft.ts +0 -23
- package/src/tui/ui/duration.ts +0 -16
- package/src/tui/ui/edge.ts +0 -186
- package/src/tui/ui/image-size.ts +0 -44
- package/src/tui/ui/ink.ts +0 -210
- package/src/tui/ui/items.ts +0 -42
- package/src/tui/ui/keys.ts +0 -40
- package/src/tui/ui/layout.ts +0 -74
- package/src/tui/ui/list-model.ts +0 -86
- package/src/tui/ui/list-view.ts +0 -172
- package/src/tui/ui/mascot.ts +0 -67
- package/src/tui/ui/messages.ts +0 -518
- package/src/tui/ui/motion.ts +0 -28
- package/src/tui/ui/paths.ts +0 -10
- package/src/tui/ui/pictures.ts +0 -108
- package/src/tui/ui/prompt-history.ts +0 -60
- package/src/tui/ui/screen.ts +0 -579
- package/src/tui/ui/status.ts +0 -403
- package/src/tui/ui/styled.ts +0 -85
- package/src/tui/ui/tool-card.ts +0 -150
- package/src/tui/width.ts +0 -567
- package/src/vendor/pi-rich/LICENSE.upstream +0 -21
- package/src/vendor/pi-rich/UPSTREAM.json +0 -17
- package/src/vendor/pi-rich/clipboard-command.ts +0 -44
- package/src/vendor/pi-rich/exif-orientation.ts +0 -182
- package/src/vendor/pi-rich/html.ts +0 -51
- package/src/vendor/pi-rich/image-convert.ts +0 -49
- package/src/vendor/pi-rich/image-resize-core.ts +0 -164
- package/src/vendor/pi-rich/image-resize-worker.ts +0 -42
- package/src/vendor/pi-rich/image-resize.ts +0 -123
- package/src/vendor/pi-rich/mime.ts +0 -116
- package/src/vendor/pi-rich/photon.ts +0 -139
- package/src/vendor/pi-rich/syntax-highlight.ts +0 -214
package/src/runtime/acp-agent.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/** ACP is a transport over the existing session owner, never a second agent loop (Q24/D8). */
|
|
2
|
-
import { isAbsolute, resolve } from "node:path";
|
|
3
|
-
import { agent, PROTOCOL_VERSION, RequestError, type AgentApp, type AgentConnection, type AgentContext,
|
|
4
|
-
type ClientCapabilities, type ContentBlock, type ElicitationPropertySchema, type McpServer,
|
|
5
|
-
type SessionModeState, type SessionUpdate, type StopReason, type ToolCall, type RequestPermissionResponse } from "@agentclientprotocol/sdk";
|
|
6
|
-
import { CONTROL_SCHEMA } from "../core/control-protocol.ts";
|
|
7
|
-
import { parseMcpServers, type McpServers } from "../core/mcp-config.ts";
|
|
8
|
-
import type { LogEvent } from "../core/events.ts";
|
|
9
|
-
import type { QuestionRequest, QuestionReply } from "../core/question.ts";
|
|
10
|
-
import type { ExecutionOutcome } from "../core/outcome.ts";
|
|
11
|
-
import type { PendingApproval, SessionControl } from "./session-control.ts";
|
|
12
|
-
import type { ApprovalChoice } from "./tools.ts";
|
|
13
|
-
import type { SessionHub } from "./session-hub.ts";
|
|
14
|
-
|
|
15
|
-
function invalid(message: string): never { throw RequestError.invalidParams(undefined, message); }
|
|
16
|
-
function object(value: unknown): Record<string, unknown> | undefined {
|
|
17
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Normalize explicit client configuration; annotations and tool output cannot configure processes. */
|
|
21
|
-
export function acpMcpServers(servers: readonly McpServer[]): McpServers {
|
|
22
|
-
const result: Record<string, unknown> = Object.create(null);
|
|
23
|
-
for (const server of servers) {
|
|
24
|
-
if (Object.hasOwn(result, server.name)) invalid("MCP server names must be unique");
|
|
25
|
-
if ("type" in server) {
|
|
26
|
-
if (server.type !== "http") invalid("This agent supports stdio and HTTP MCP servers only");
|
|
27
|
-
result[server.name] = { transport: "http", url: server.url, headers: pairs(server.headers) };
|
|
28
|
-
} else result[server.name] = { transport: "stdio", command: server.command, args: [...server.args], env: pairs(server.env) };
|
|
29
|
-
}
|
|
30
|
-
try { return parseMcpServers(result); } catch { return invalid("Invalid MCP server configuration"); }
|
|
31
|
-
}
|
|
32
|
-
function pairs(values: readonly { name: string; value: string }[]): Record<string, string> {
|
|
33
|
-
const result: Record<string, string> = Object.create(null);
|
|
34
|
-
for (const value of values) {
|
|
35
|
-
if (Object.hasOwn(result, value.name)) invalid("Duplicate MCP environment or header name");
|
|
36
|
-
result[value.name] = value.value;
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
function modes(control: SessionControl): SessionModeState | undefined {
|
|
41
|
-
return control.configureWorkflow ? { currentModeId: control.session.config.tools.workflowMode ?? "build", availableModes: [
|
|
42
|
-
{ id: "build", name: "Build", description: "Implement and verify workspace changes." },
|
|
43
|
-
{ id: "plan", name: "Plan", description: "Inspect and plan with read-only tools." },
|
|
44
|
-
] } : undefined;
|
|
45
|
-
}
|
|
46
|
-
function promptText(blocks: readonly ContentBlock[]): string {
|
|
47
|
-
const parts = blocks.map(block => {
|
|
48
|
-
if (block.type === "text") return block.text;
|
|
49
|
-
// Baseline resource links remain references. Reading them goes through the normal tool admission.
|
|
50
|
-
if (block.type === "resource_link") return `Resource ${JSON.stringify(block.name)}: ${JSON.stringify(block.uri)}${block.description ? `\n${block.description}` : ""}`;
|
|
51
|
-
if (block.type === "resource" && "text" in block.resource) return `Resource ${JSON.stringify(block.resource.uri)}:\n${block.resource.text}`;
|
|
52
|
-
return invalid("This agent accepts text, resource links and embedded text; image/audio/binary prompts are unavailable");
|
|
53
|
-
});
|
|
54
|
-
const text = parts.join("\n\n");
|
|
55
|
-
if (!text.trim() || Buffer.byteLength(text) > CONTROL_SCHEMA.limits.frameBytes) invalid("Prompt must contain text within the ACP message limit");
|
|
56
|
-
return text;
|
|
57
|
-
}
|
|
58
|
-
function stopReason(outcome: ExecutionOutcome | undefined, cancelled: boolean): StopReason {
|
|
59
|
-
if (cancelled || outcome?.status === "cancelled") return "cancelled";
|
|
60
|
-
if (outcome?.reason === "model_refusal") return "refusal";
|
|
61
|
-
if (outcome?.reason === "output_limit") return "max_tokens";
|
|
62
|
-
if (outcome?.status === "completed") return "end_turn";
|
|
63
|
-
if (outcome?.status === "stopped") return "max_turn_requests";
|
|
64
|
-
throw RequestError.internalError(undefined, "The session failed or its termination is unknown; inspect the durable outcome");
|
|
65
|
-
}
|
|
66
|
-
function title(name: string, input: unknown): string {
|
|
67
|
-
const raw = object(input), detail = raw?.["cmd"] ?? raw?.["command"] ?? raw?.["path"];
|
|
68
|
-
return typeof detail === "string" ? `${name}: ${detail}` : name;
|
|
69
|
-
}
|
|
70
|
-
function kind(name: string): ToolCall["kind"] {
|
|
71
|
-
if (["read", "diff"].includes(name)) return "read";
|
|
72
|
-
if (["write", "edit", "apply_patch", "format"].includes(name)) return "edit";
|
|
73
|
-
if (["bash", "exec_command", "write_stdin"].includes(name)) return "execute";
|
|
74
|
-
if (["search", "glob", "grep"].includes(name)) return "search";
|
|
75
|
-
if (["webfetch", "websearch"].includes(name)) return "fetch";
|
|
76
|
-
return "other";
|
|
77
|
-
}
|
|
78
|
-
function content(text: string) { return [{ type: "content" as const, content: { type: "text" as const, text } }]; }
|
|
79
|
-
|
|
80
|
-
/** SDK cancellation is cooperative; a peer ignoring it cannot hold the tool owner indefinitely. */
|
|
81
|
-
async function cancellable<T>(request: Promise<T>, signal: AbortSignal): Promise<T | undefined> {
|
|
82
|
-
if (signal.aborted) { void request.catch(() => {}); return undefined; }
|
|
83
|
-
let cancel = () => {};
|
|
84
|
-
const aborted = new Promise<undefined>(done => { cancel = () => done(undefined); signal.addEventListener("abort", cancel, { once: true }); });
|
|
85
|
-
try { return await Promise.race([request, aborted]); } finally { signal.removeEventListener("abort", cancel); }
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function elicit(client: AgentContext, sessionId: string, toolCallId: string, request: QuestionRequest, signal: AbortSignal): Promise<QuestionReply | undefined> {
|
|
89
|
-
const properties: Record<string, ElicitationPropertySchema> = Object.create(null), required: string[] = [];
|
|
90
|
-
request.questions.forEach((question, index) => {
|
|
91
|
-
const key = `q${index}`, options = question.options.map(option => ({ const: option.id, title: option.label,
|
|
92
|
-
...(option.description ? { description: option.description } : {}) }));
|
|
93
|
-
if (options.length) {
|
|
94
|
-
properties[key] = question.multiple ? { type: "array", title: question.header, description: question.question,
|
|
95
|
-
items: { anyOf: options }, minItems: question.custom ? 0 : 1, maxItems: options.length } :
|
|
96
|
-
{ type: "string", title: question.header, description: question.question, oneOf: options };
|
|
97
|
-
if (!question.custom) required.push(key);
|
|
98
|
-
}
|
|
99
|
-
if (question.custom || !options.length) {
|
|
100
|
-
properties[`${key}_text`] = { type: "string", title: `${question.header}: your answer`, description: question.question, minLength: 1 };
|
|
101
|
-
if (!options.length) required.push(`${key}_text`);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
const response = await cancellable(client.request("elicitation/create", { sessionId, toolCallId, mode: "form",
|
|
105
|
-
message: request.questions.map(question => question.question).join("\n"), requestedSchema: { type: "object", properties, required } },
|
|
106
|
-
{ cancellationSignal: signal }), signal);
|
|
107
|
-
if (response?.action !== "accept") return undefined;
|
|
108
|
-
const answers = object(response["content"]);
|
|
109
|
-
if (!answers || Object.keys(answers).some(key => !Object.hasOwn(properties, key))) return undefined;
|
|
110
|
-
return { request_id: request.request_id, turn_id: request.turn_id, answers: request.questions.map((question, index) => {
|
|
111
|
-
const value = answers[`q${index}`], text = answers[`q${index}_text`];
|
|
112
|
-
return { id: question.id, choices: typeof value === "string" ? [value] : Array.isArray(value) && value.every(item => typeof item === "string") ? value : [],
|
|
113
|
-
...(typeof text === "string" && text.trim() ? { text } : {}) };
|
|
114
|
-
}) };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
interface Binding {
|
|
118
|
-
control: SessionControl;
|
|
119
|
-
abort: AbortController | null;
|
|
120
|
-
pending: Map<string, ToolCall>;
|
|
121
|
-
send(update: SessionUpdate): void;
|
|
122
|
-
replay(node: number, event: LogEvent): void;
|
|
123
|
-
drain(): Promise<void>;
|
|
124
|
-
close(): void;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** One AgentApp serves one client connection. Each workspace has an explicit host-owned hub. */
|
|
128
|
-
export function createAcpAgent(hub: SessionHub): AgentApp {
|
|
129
|
-
const app = agent({ name: "xeno" }), bindings = new Map<string, Binding>();
|
|
130
|
-
let connection: AgentConnection | undefined, initialized = false, capabilities: ClientCapabilities = {};
|
|
131
|
-
let inFlight = 0;
|
|
132
|
-
const admit = async <T>(operation: () => Promise<T>): Promise<T> => {
|
|
133
|
-
// Assumed ingress cap: SDK schema validation bounds frames, not concurrent async handlers.
|
|
134
|
-
if (inFlight >= CONTROL_SCHEMA.limits.queuedRequests) throw RequestError.invalidRequest(undefined, "ACP request concurrency limit exceeded");
|
|
135
|
-
inFlight++; try { return await operation(); } finally { inFlight--; }
|
|
136
|
-
};
|
|
137
|
-
const requireInitialized = () => { if (!initialized || !connection || connection.signal.aborted) throw RequestError.invalidRequest(undefined, "initialize must complete before session requests"); };
|
|
138
|
-
const workspace = (params: { cwd: string; additionalDirectories?: string[]; mcpServers: McpServer[] }) => {
|
|
139
|
-
requireInitialized();
|
|
140
|
-
if (!isAbsolute(params.cwd) || resolve(params.cwd) !== resolve(hub.initial.session.config.tools.root))
|
|
141
|
-
invalid("cwd must match this agent process workspace; start one process per workspace");
|
|
142
|
-
if (params.additionalDirectories?.length) invalid("Additional workspace directories are unavailable");
|
|
143
|
-
return { cwd: params.cwd, acpMcpServers: acpMcpServers(params.mcpServers) };
|
|
144
|
-
};
|
|
145
|
-
const get = (id: string) => { requireInitialized(); const value = bindings.get(id); if (!value) throw RequestError.resourceNotFound(id); return value; };
|
|
146
|
-
const bind = (control: SessionControl): Binding => {
|
|
147
|
-
const existing = bindings.get(control.threadId); if (existing) return existing;
|
|
148
|
-
const peer = connection!;
|
|
149
|
-
let queuedBytes = 0, tail: Promise<void> = Promise.resolve(), deliveryError: unknown;
|
|
150
|
-
const pending = new Map<string, ToolCall>(), originalInputs = new Map<string, unknown>();
|
|
151
|
-
const send = (update: SessionUpdate) => {
|
|
152
|
-
const bytes = Buffer.byteLength(JSON.stringify(update)); queuedBytes += bytes;
|
|
153
|
-
if (bytes > CONTROL_SCHEMA.limits.frameBytes || queuedBytes > CONTROL_SCHEMA.limits.outputBytes) { peer.close(Error("ACP output queue exceeded its limit")); return; }
|
|
154
|
-
tail = tail.then(async () => { if (deliveryError) return; await peer.client.notify("session/update", { sessionId: control.threadId, update }); })
|
|
155
|
-
.catch(error => { deliveryError = error; peer.close(Error("ACP notification delivery failed")); })
|
|
156
|
-
.finally(() => { queuedBytes -= bytes; });
|
|
157
|
-
};
|
|
158
|
-
const record = (node: number, event: LogEvent, replay = false) => {
|
|
159
|
-
if (event.t === "user" && replay) send({ sessionUpdate: "user_message_chunk", content: { type: "text", text: event.text }, messageId: `${node}:${event.id}` });
|
|
160
|
-
if (event.t === "assistant" && replay) for (const block of event.blocks) if (block.type === "text")
|
|
161
|
-
send({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: block.text }, messageId: `${node}:${event.id}` });
|
|
162
|
-
if (event.t === "assistant") for (const block of event.blocks) if (block.type === "tool_use") originalInputs.set(`${node}:${block.call_id}`, block.input);
|
|
163
|
-
if (event.t === "tool_invocation") {
|
|
164
|
-
// Unchanged direct calls omit inline input; recover it from the original model request.
|
|
165
|
-
const key = `${node}:${event.call_id}`, input = event.input ?? originalInputs.get(key); originalInputs.delete(key);
|
|
166
|
-
const call: ToolCall = { toolCallId: `${node}:${event.id}`, name: event.name, title: title(event.name, input), kind: kind(event.name)!, status: "pending",
|
|
167
|
-
...(input !== undefined ? { rawInput: input } : {}) };
|
|
168
|
-
pending.set(`${node}:${event.call_id}`, call); send({ sessionUpdate: "tool_call", ...call });
|
|
169
|
-
}
|
|
170
|
-
if (event.t === "tool_result") {
|
|
171
|
-
const key = `${node}:${event.call_id}`, call = pending.get(key);
|
|
172
|
-
if (!call) {
|
|
173
|
-
send({ sessionUpdate: "tool_call", toolCallId: `${node}:${event.id}`, title: "Recorded tool result", status: "pending" });
|
|
174
|
-
}
|
|
175
|
-
send({ sessionUpdate: "tool_call_update", toolCallId: call?.toolCallId ?? `${node}:${event.id}`,
|
|
176
|
-
status: event.ok && (!event.outcome || event.outcome.status === "completed") ? "completed" : "failed", content: content(event.content), rawOutput: event.data ?? event.content });
|
|
177
|
-
pending.delete(key);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
const permission = async (approval: PendingApproval) => {
|
|
181
|
-
const abort = binding.abort; if (!abort || abort.signal.aborted || peer.signal.aborted) return;
|
|
182
|
-
const request = approval.request;
|
|
183
|
-
const matches = [...pending.values()].filter(call => call.name === request.tool &&
|
|
184
|
-
(!request.command || object(call.rawInput)?.["cmd"] === request.command || object(call.rawInput)?.["command"] === request.command));
|
|
185
|
-
const call = matches.length === 1 ? matches[0]! : undefined;
|
|
186
|
-
const toolCall = { toolCallId: call?.toolCallId ?? `permission:${approval.id}`, name: request.tool,
|
|
187
|
-
title: title(request.tool, request), status: "pending" as const,
|
|
188
|
-
rawInput: call?.rawInput ?? request, ...(request.paths ? { locations: request.paths.map(path => ({ path: resolve(control.session.config.tools.root, path) })) } : {}) };
|
|
189
|
-
if (!call) send({ sessionUpdate: "tool_call", ...toolCall });
|
|
190
|
-
let choice: ApprovalChoice = "deny";
|
|
191
|
-
try {
|
|
192
|
-
await binding.drain();
|
|
193
|
-
if (abort.signal.aborted || peer.signal.aborted) return;
|
|
194
|
-
const response = await cancellable(peer.client.request<RequestPermissionResponse>("session/request_permission", { sessionId: control.threadId, toolCall,
|
|
195
|
-
options: [{ optionId: "once", name: "Allow once", kind: "allow_once" }, { optionId: "deny", name: "Reject", kind: "reject_once" }] },
|
|
196
|
-
{ cancellationSignal: abort.signal }), abort.signal);
|
|
197
|
-
if (response?.outcome.outcome === "selected" && response.outcome.optionId === "once") choice = "once";
|
|
198
|
-
} catch { /* A failed permission request denies the original invocation; never retry it. */ }
|
|
199
|
-
if (!abort.signal.aborted && control.activeTurnId === approval.turnId) {
|
|
200
|
-
try { control.respond(approval.turnId, approval.id, choice); } catch { /* another legitimate client/cancel already resolved it */ }
|
|
201
|
-
}
|
|
202
|
-
if (!call) send({ sessionUpdate: "tool_call_update", toolCallId: toolCall.toolCallId, status: choice === "once" ? "completed" : "failed" });
|
|
203
|
-
};
|
|
204
|
-
const previousAsk = control.session.config.tools.askSlot?.current;
|
|
205
|
-
const ask = (request: Parameters<SessionControl["ask"]>[0]) => control.ask(request);
|
|
206
|
-
const askSlot = control.session.config.tools.askSlot;
|
|
207
|
-
if (askSlot) askSlot.current = ask;
|
|
208
|
-
const slot = control.questionSlot, previousQuestion = slot.current;
|
|
209
|
-
const question = (request: QuestionRequest, signal: AbortSignal) => control.askQuestion(request, signal,
|
|
210
|
-
value => elicit(peer.client, control.threadId, pending.get(`${control.session.state.node}:${value.call_id}`)?.toolCallId ?? value.call_id, value, signal));
|
|
211
|
-
// Capability negotiation must precede installation; unsupported form questions fail explicitly.
|
|
212
|
-
if (capabilities.elicitation?.form != null) slot.current = question;
|
|
213
|
-
const unsubscribe = control.subscribe(notice => {
|
|
214
|
-
if (notice.method === "approval/request") void permission(notice.params["approval"] as PendingApproval);
|
|
215
|
-
if (notice.method === "item/completed") {
|
|
216
|
-
const item = notice.params["item"] as { id: string; node: number };
|
|
217
|
-
const event = control.session.state.events.find(value => value.id === item.id);
|
|
218
|
-
if (event) record(item.node, event);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
const binding: Binding = { control, abort: null, pending, send, replay: (node, event) => record(node, event, true), drain: async () => { await tail; if (deliveryError) throw RequestError.internalError(undefined, "ACP notification delivery failed"); },
|
|
222
|
-
close: () => { binding.abort?.abort(); if (control.activeTurnId && binding.abort) control.interrupt(control.activeTurnId); unsubscribe();
|
|
223
|
-
if (askSlot?.current === ask) { if (previousAsk) askSlot.current = previousAsk; else delete askSlot.current; }
|
|
224
|
-
if (slot.current === question) { if (previousQuestion) slot.current = previousQuestion; else delete slot.current; }
|
|
225
|
-
} };
|
|
226
|
-
bindings.set(control.threadId, binding);
|
|
227
|
-
return binding;
|
|
228
|
-
};
|
|
229
|
-
app.onConnect(peer => {
|
|
230
|
-
if (connection && !connection.signal.aborted) throw Error("ACP AgentApp already has a client connection");
|
|
231
|
-
connection = peer; initialized = false; capabilities = {};
|
|
232
|
-
peer.signal.addEventListener("abort", () => { for (const binding of bindings.values()) binding.close(); bindings.clear(); }, { once: true });
|
|
233
|
-
});
|
|
234
|
-
app.onRequest("initialize", ({ params }) => {
|
|
235
|
-
if (initialized) throw RequestError.invalidRequest(undefined, "Connection is already initialized");
|
|
236
|
-
if (params.protocolVersion < 1) invalid("ACP protocol version 1 is required");
|
|
237
|
-
capabilities = params.clientCapabilities ?? {}; initialized = true;
|
|
238
|
-
return { protocolVersion: PROTOCOL_VERSION, agentInfo: { name: "xeno", version: "0.1.0" },
|
|
239
|
-
agentCapabilities: { loadSession: true, promptCapabilities: { embeddedContext: true }, mcpCapabilities: { http: true }, sessionCapabilities: { close: {} } } };
|
|
240
|
-
});
|
|
241
|
-
app.onRequest("session/new", ({ params, signal }) => admit(async () => {
|
|
242
|
-
const forwarded = workspace(params), control = await hub.open("new", forwarded);
|
|
243
|
-
if (signal.aborted || connection!.signal.aborted) { await hub.close(control.threadId); throw RequestError.requestCancelled(); }
|
|
244
|
-
bind(control); const state = modes(control);
|
|
245
|
-
return { sessionId: control.threadId, ...(state ? { modes: state } : {}) };
|
|
246
|
-
}));
|
|
247
|
-
app.onRequest("session/load", ({ params, signal }) => admit(async () => {
|
|
248
|
-
const forwarded = workspace(params), control = await hub.open("resume", { ...forwarded, session: params.sessionId });
|
|
249
|
-
if (signal.aborted || connection!.signal.aborted) throw RequestError.requestCancelled();
|
|
250
|
-
if (control.busy) throw RequestError.invalidRequest(undefined, "Cannot replay a session with an active turn");
|
|
251
|
-
const binding = bind(control);
|
|
252
|
-
// Replay durable original messages/results only. Loading never executes tools or sends provider requests.
|
|
253
|
-
for (const { node, event } of await control.items()) { binding.replay(node, event); await binding.drain(); }
|
|
254
|
-
await binding.drain(); const state = modes(control); return state ? { modes: state } : {};
|
|
255
|
-
}));
|
|
256
|
-
app.onRequest("session/prompt", ({ params, signal }) => admit(async () => {
|
|
257
|
-
const binding = get(params.sessionId), control = binding.control, input = promptText(params.prompt);
|
|
258
|
-
if (control.busy || binding.abort) throw RequestError.invalidRequest(undefined, "A prompt is already running for this session");
|
|
259
|
-
const abort = new AbortController(); binding.abort = abort; binding.pending.clear();
|
|
260
|
-
const signals = AbortSignal.any([signal, abort.signal, connection!.signal]);
|
|
261
|
-
let outcome: ExecutionOutcome | undefined;
|
|
262
|
-
try {
|
|
263
|
-
for await (const event of control.send(input, signals)) {
|
|
264
|
-
// Emit committed model text once. Provider retry/discard deltas cannot become durable conversation.
|
|
265
|
-
if (event.kind === "assistant_text" && event.text) { binding.send({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: event.text } }); await binding.drain(); }
|
|
266
|
-
if (event.kind === "done") outcome = event.outcome;
|
|
267
|
-
}
|
|
268
|
-
await binding.drain(); return { stopReason: stopReason(outcome, signals.aborted) };
|
|
269
|
-
} catch {
|
|
270
|
-
if (signals.aborted) return { stopReason: "cancelled" as const };
|
|
271
|
-
throw RequestError.internalError(undefined, "Session prompt failed; inspect its durable outcome before continuing");
|
|
272
|
-
} finally { binding.abort = null; binding.pending.clear(); }
|
|
273
|
-
}));
|
|
274
|
-
app.onNotification("session/cancel", ({ params }) => {
|
|
275
|
-
const binding = get(params.sessionId); binding.abort?.abort();
|
|
276
|
-
if (binding.abort && binding.control.activeTurnId) binding.control.interrupt(binding.control.activeTurnId);
|
|
277
|
-
});
|
|
278
|
-
app.onRequest("session/set_mode", ({ params }) => admit(async () => {
|
|
279
|
-
const binding = get(params.sessionId), control = binding.control;
|
|
280
|
-
if (params.modeId !== "plan" && params.modeId !== "build") invalid("Unknown session mode");
|
|
281
|
-
if (!control.configureWorkflow) throw RequestError.methodNotFound("session/set_mode");
|
|
282
|
-
if (control.busy) throw RequestError.invalidRequest(undefined, "Mode changes require an idle checkpoint");
|
|
283
|
-
await control.configureWorkflow(params.modeId); binding.send({ sessionUpdate: "current_mode_update", currentModeId: params.modeId }); await binding.drain(); return {};
|
|
284
|
-
}));
|
|
285
|
-
app.onRequest("session/close", ({ params }) => admit(async () => {
|
|
286
|
-
const binding = get(params.sessionId); binding.close(); bindings.delete(params.sessionId); await hub.close(binding.control.threadId); return {};
|
|
287
|
-
}));
|
|
288
|
-
return app;
|
|
289
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/** R13: configuration loading is separate from applying a role to a live Session. */
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { configDir } from "../store/config.ts";
|
|
4
|
-
import { readAgentProfileFile } from "../store/agent-profile-files.ts";
|
|
5
|
-
import { parseAgentProfiles, type AgentProfileLayer } from "../core/agent-profile.ts";
|
|
6
|
-
|
|
7
|
-
export async function loadAgentProfileLayers(options: { readonly workspace: string; readonly trustProject: boolean; readonly userDir?: string }):
|
|
8
|
-
Promise<{ readonly layers: readonly AgentProfileLayer[]; readonly diagnostics: readonly string[] }> {
|
|
9
|
-
const paths = [{ kind: "user" as const, path: join(options.userDir ?? configDir(), "agents.json") },
|
|
10
|
-
...(options.trustProject ? [{ kind: "project" as const, path: join(options.workspace, ".xeno", "agents.json") }] : [])];
|
|
11
|
-
const layers: AgentProfileLayer[] = [], diagnostics: string[] = [];
|
|
12
|
-
for (const source of paths) {
|
|
13
|
-
const file = await readAgentProfileFile(source.path);
|
|
14
|
-
if (!file) continue;
|
|
15
|
-
if (file.diagnostic) { diagnostics.push(file.diagnostic); continue; }
|
|
16
|
-
const parsed = parseAgentProfiles(file.value);
|
|
17
|
-
diagnostics.push(...parsed.diagnostics.map(diagnostic => `${source.path}: ${diagnostic}`));
|
|
18
|
-
if (parsed.diagnostics.length === 0) layers.push({ source, profiles: parsed.profiles });
|
|
19
|
-
}
|
|
20
|
-
return { layers, diagnostics };
|
|
21
|
-
}
|