@aria-cli/cli 1.0.57 → 1.0.59
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/bin/aria.mjs +799 -668
- package/package.json +17 -76
- package/dist/.tsbuildinfo +0 -1
- package/dist/attached-local-control-client.js +0 -826
- package/dist/bootstrap-local-control-client.js +0 -2
- package/dist/capability-aware-method-proxy.js +0 -42
- package/dist/cli-context.js +0 -160
- package/dist/commands/arions.js +0 -174
- package/dist/commands/auth.js +0 -123
- package/dist/commands/daemon.js +0 -367
- package/dist/commands/definitions.js +0 -176
- package/dist/commands/index.js +0 -80
- package/dist/commands/login-handler.js +0 -1108
- package/dist/commands/logout-handler.js +0 -92
- package/dist/commands/memory-handlers.js +0 -89
- package/dist/commands/pairing.js +0 -60
- package/dist/commands/runtime-cutover-reset-command.js +0 -12
- package/dist/commands/runtime-cutover-reset.js +0 -265
- package/dist/commands/terminal-setup.js +0 -84
- package/dist/config/aria-config.js +0 -238
- package/dist/config/index.js +0 -3
- package/dist/config/loader.js +0 -97
- package/dist/config.js +0 -142
- package/dist/daemon-info.js +0 -10
- package/dist/ensure-daemon.js +0 -128
- package/dist/entrypoints/command-mode.js +0 -5
- package/dist/entrypoints/daemon.js +0 -50
- package/dist/entrypoints/headless-stdio.js +0 -25
- package/dist/entrypoints/interactive.js +0 -80
- package/dist/event-loop-watchdog.js +0 -73
- package/dist/headless/auth-orchestrator.js +0 -508
- package/dist/headless/auth-service.js +0 -43
- package/dist/headless/bootstrap-fast-path.js +0 -112
- package/dist/headless/call-command.js +0 -143
- package/dist/headless/daemon-service.js +0 -318
- package/dist/headless/hook-actions.js +0 -235
- package/dist/headless/hook-service.js +0 -42
- package/dist/headless/kernel-services.js +0 -216
- package/dist/headless/kernel.js +0 -785
- package/dist/headless/operations/arion.js +0 -119
- package/dist/headless/operations/auth.js +0 -45
- package/dist/headless/operations/client.js +0 -31
- package/dist/headless/operations/config.js +0 -69
- package/dist/headless/operations/daemon.js +0 -47
- package/dist/headless/operations/hook.js +0 -56
- package/dist/headless/operations/index.js +0 -11
- package/dist/headless/operations/memory.js +0 -102
- package/dist/headless/operations/message.js +0 -279
- package/dist/headless/operations/model.js +0 -100
- package/dist/headless/operations/peer.js +0 -56
- package/dist/headless/operations/run.js +0 -24
- package/dist/headless/operations/session.js +0 -90
- package/dist/headless/operations/system.js +0 -19
- package/dist/headless/operations/utils.js +0 -35
- package/dist/headless/run-orchestrator.js +0 -703
- package/dist/headless/stdio-server.js +0 -439
- package/dist/history/SessionHistory.js +0 -8
- package/dist/history/SessionHistoryClient.js +0 -186
- package/dist/history/conversation-message.js +0 -112
- package/dist/history/index.js +0 -8
- package/dist/history/jsonl-replay.js +0 -154
- package/dist/history/repair-tool-pairing.js +0 -84
- package/dist/history/stall-phase-bridge.js +0 -11
- package/dist/history/turn-accumulator.js +0 -427
- package/dist/index.js +0 -7
- package/dist/ink-repl.js +0 -4183
- package/dist/local-control-bootstrap.js +0 -26
- package/dist/local-control-client.js +0 -2
- package/dist/local-control-error-reporting.js +0 -34
- package/dist/local-control-http-client.js +0 -362
- package/dist/local-control-lazy-wrapper.js +0 -363
- package/dist/local-control-manager.js +0 -146
- package/dist/main.js +0 -62
- package/dist/network-security.js +0 -62
- package/dist/networking-server.js +0 -38
- package/dist/peer-identity.js +0 -23
- package/dist/polling-subscription.js +0 -34
- package/dist/relaunch.js +0 -617
- package/dist/release-notes.js +0 -35
- package/dist/repl-cleanup.js +0 -47
- package/dist/runtime/configure-bun-sqlite.js +0 -3
- package/dist/runtime/crash-handlers.js +0 -111
- package/dist/runtime/interactive-invocation.js +0 -39
- package/dist/runtime/internal-mode.js +0 -14
- package/dist/runtime/launch-spec.js +0 -64
- package/dist/runtime/owner-lease.js +0 -44
- package/dist/runtime/public-mode.js +0 -20
- package/dist/runtime/run-internal-mode.js +0 -18
- package/dist/runtime/runtime-kind.js +0 -32
- package/dist/runtime/spawn-aria.js +0 -38
- package/dist/selectable-client.js +0 -2
- package/dist/selectable-peer.js +0 -2
- package/dist/session.js +0 -203
- package/dist/slash-commands.js +0 -80
- package/dist/sounds.js +0 -210
- package/dist/ui/App.js +0 -526
- package/dist/ui/components/AnthropicMethodPicker.js +0 -6
- package/dist/ui/components/ArionPrompt.js +0 -15
- package/dist/ui/components/AutocompleteDropdown.js +0 -23
- package/dist/ui/components/AutonomySelector.js +0 -55
- package/dist/ui/components/Banner.js +0 -98
- package/dist/ui/components/ConversationHistory.js +0 -175
- package/dist/ui/components/CopilotDeviceLoginFlow.js +0 -88
- package/dist/ui/components/CopilotSourcePicker.js +0 -50
- package/dist/ui/components/Cost.js +0 -10
- package/dist/ui/components/CustomSelect/option-map.js +0 -30
- package/dist/ui/components/CustomSelect/select-option.js +0 -13
- package/dist/ui/components/CustomSelect/select.js +0 -42
- package/dist/ui/components/CustomSelect/use-select-state.js +0 -179
- package/dist/ui/components/CustomSelect/use-select.js +0 -15
- package/dist/ui/components/ErrorDisplay.js +0 -35
- package/dist/ui/components/FallbackToolUseRejectedMessage.js +0 -7
- package/dist/ui/components/FileEditToolUpdatedMessage.js +0 -57
- package/dist/ui/components/HandoffMarker.js +0 -18
- package/dist/ui/components/HighlightedCode.js +0 -21
- package/dist/ui/components/InputArea.js +0 -187
- package/dist/ui/components/Message.js +0 -25
- package/dist/ui/components/OAuthLoginFlow.js +0 -113
- package/dist/ui/components/OutputTruncation.js +0 -35
- package/dist/ui/components/PermissionPrompt.js +0 -79
- package/dist/ui/components/PipelineTimingPanel.js +0 -15
- package/dist/ui/components/ProviderMethodPicker.js +0 -61
- package/dist/ui/components/ProviderPicker.js +0 -63
- package/dist/ui/components/RenderItemView.js +0 -71
- package/dist/ui/components/Spinner.js +0 -46
- package/dist/ui/components/StatusBar.js +0 -95
- package/dist/ui/components/StreamingIndicator.js +0 -55
- package/dist/ui/components/StructuredDiff.js +0 -168
- package/dist/ui/components/TextInputOverlay.js +0 -43
- package/dist/ui/components/ThinkingBlock.js +0 -82
- package/dist/ui/components/ToolCost.js +0 -17
- package/dist/ui/components/ToolExecution.js +0 -61
- package/dist/ui/components/ToolHeader.js +0 -51
- package/dist/ui/components/ToolRenderLayoutContext.js +0 -14
- package/dist/ui/components/ToolResultWrapper.js +0 -6
- package/dist/ui/components/ToolUseLoader.js +0 -35
- package/dist/ui/components/TraceWaterfall.js +0 -91
- package/dist/ui/components/index.js +0 -33
- package/dist/ui/components/messages/AssistantTextMessage.js +0 -25
- package/dist/ui/components/messages/UserImageMessage.js +0 -12
- package/dist/ui/components/messages/UserTextMessage.js +0 -12
- package/dist/ui/components/overlays/ArionSelector.js +0 -68
- package/dist/ui/components/overlays/ClientSelector.js +0 -62
- package/dist/ui/components/overlays/CommandPalette.js +0 -67
- package/dist/ui/components/overlays/DaemonControl.js +0 -87
- package/dist/ui/components/overlays/InviteShareOverlay.js +0 -15
- package/dist/ui/components/overlays/JoinInviteOverlay.js +0 -32
- package/dist/ui/components/overlays/MemoryBrowser.js +0 -100
- package/dist/ui/components/overlays/MessageSelector.js +0 -123
- package/dist/ui/components/overlays/ModelSelector.js +0 -211
- package/dist/ui/components/overlays/PairRequestOverlay.js +0 -42
- package/dist/ui/components/overlays/PeerSelector.js +0 -84
- package/dist/ui/components/overlays/SessionSelector.js +0 -102
- package/dist/ui/components/overlays/SoundSelector.js +0 -86
- package/dist/ui/components/overlays/ThemeSelector.js +0 -139
- package/dist/ui/components/overlays/index.js +0 -15
- package/dist/ui/components/permissions/BashPermissionRequest/BashPermissionRequest.js +0 -53
- package/dist/ui/components/permissions/FallbackPermissionRequest.js +0 -56
- package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +0 -76
- package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js +0 -18
- package/dist/ui/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +0 -64
- package/dist/ui/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +0 -26
- package/dist/ui/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +0 -141
- package/dist/ui/components/permissions/PermissionRequest.js +0 -70
- package/dist/ui/components/permissions/PermissionRequestTitle.js +0 -41
- package/dist/ui/components/permissions/hooks.js +0 -10
- package/dist/ui/components/permissions/toolUseOptions.js +0 -68
- package/dist/ui/components/permissions/utils.js +0 -10
- package/dist/ui/components/text-input/Cursor.js +0 -326
- package/dist/ui/components/text-input/TextInput.js +0 -231
- package/dist/ui/components/text-input/imagePaste.js +0 -28
- package/dist/ui/components/text-input/index.js +0 -6
- package/dist/ui/components/text-input/useDoublePress.js +0 -30
- package/dist/ui/components/text-input/useTextInput.js +0 -245
- package/dist/ui/components/tool-types.js +0 -9
- package/dist/ui/constants/figures.js +0 -4
- package/dist/ui/constants/index.js +0 -3
- package/dist/ui/display-mode.js +0 -93
- package/dist/ui/display-policy.js +0 -19
- package/dist/ui/hooks/index.js +0 -6
- package/dist/ui/hooks/useCommandAutocomplete.js +0 -93
- package/dist/ui/hooks/useDoublePress.js +0 -37
- package/dist/ui/hooks/useIndicatorState.js +0 -55
- package/dist/ui/hooks/useInterval.js +0 -23
- package/dist/ui/hooks/useKeyboardShortcuts.js +0 -127
- package/dist/ui/hooks/useTerminalSize.js +0 -55
- package/dist/ui/hooks/useUnifiedMessages.js +0 -117
- package/dist/ui/indicator-state.js +0 -44
- package/dist/ui/markdown/highlight.js +0 -44
- package/dist/ui/markdown/index.js +0 -1460
- package/dist/ui/markdown/tokenizer.js +0 -24
- package/dist/ui/render-item.js +0 -5
- package/dist/ui/screens/REPL.js +0 -119
- package/dist/ui/screens/approval-lifecycle.js +0 -38
- package/dist/ui/status-line.js +0 -72
- package/dist/ui/theme/index.js +0 -51
- package/dist/ui/theme/themes/claude-dark-daltonized.js +0 -51
- package/dist/ui/theme/themes/claude-dark.js +0 -50
- package/dist/ui/theme/themes/claude-light-daltonized.js +0 -51
- package/dist/ui/theme/themes/claude-light.js +0 -50
- package/dist/ui/theme/themes/dark-accessible.js +0 -18
- package/dist/ui/theme/themes/dark.js +0 -49
- package/dist/ui/theme/themes/light-accessible.js +0 -18
- package/dist/ui/theme/themes/light.js +0 -49
- package/dist/ui/theme/types.js +0 -3
- package/dist/ui/theme.js +0 -142
- package/dist/ui/to-render-items.js +0 -145
- package/dist/ui/tools/AgentTool/index.js +0 -30
- package/dist/ui/tools/ArchitectTool/index.js +0 -31
- package/dist/ui/tools/AskUserTool/index.js +0 -46
- package/dist/ui/tools/BashTool/BashToolResultMessage.js +0 -11
- package/dist/ui/tools/BashTool/OutputLine.js +0 -21
- package/dist/ui/tools/BashTool/index.js +0 -91
- package/dist/ui/tools/BrowseTool/index.js +0 -43
- package/dist/ui/tools/BrowserTool/index.js +0 -47
- package/dist/ui/tools/CbmTool/index.js +0 -188
- package/dist/ui/tools/CheckDelegationTool/index.js +0 -46
- package/dist/ui/tools/CheckMessagesTool/index.js +0 -85
- package/dist/ui/tools/CreateQuipTool/index.js +0 -30
- package/dist/ui/tools/CreateSkillTool/index.js +0 -22
- package/dist/ui/tools/CreateToolTool/index.js +0 -31
- package/dist/ui/tools/DelegateRemoteTool/index.js +0 -42
- package/dist/ui/tools/DeployTool/index.js +0 -47
- package/dist/ui/tools/FffTool/index.js +0 -103
- package/dist/ui/tools/FileEditTool/index.js +0 -67
- package/dist/ui/tools/FileReadTool/index.js +0 -68
- package/dist/ui/tools/FileWriteTool/index.js +0 -61
- package/dist/ui/tools/ForkTool/index.js +0 -47
- package/dist/ui/tools/FrgTool/index.js +0 -96
- package/dist/ui/tools/GetThreadTool/index.js +0 -39
- package/dist/ui/tools/GlobTool/index.js +0 -50
- package/dist/ui/tools/GrepTool/index.js +0 -84
- package/dist/ui/tools/HatchArionTool/index.js +0 -36
- package/dist/ui/tools/LearnSkillTool/index.js +0 -22
- package/dist/ui/tools/LearnTool/index.js +0 -43
- package/dist/ui/tools/LearnToolTool/index.js +0 -22
- package/dist/ui/tools/ListClientsTool/index.js +0 -39
- package/dist/ui/tools/LspTool/index.js +0 -261
- package/dist/ui/tools/MCPTool/index.js +0 -33
- package/dist/ui/tools/ManageNetworkTool/index.js +0 -53
- package/dist/ui/tools/MemoryReadTool/index.js +0 -64
- package/dist/ui/tools/MemoryWriteTool/index.js +0 -20
- package/dist/ui/tools/NotebookEditTool/index.js +0 -33
- package/dist/ui/tools/NotebookReadTool/index.js +0 -25
- package/dist/ui/tools/OutlookReadTool/index.js +0 -66
- package/dist/ui/tools/OutlookReplyTool/index.js +0 -49
- package/dist/ui/tools/OutlookSendTool/index.js +0 -49
- package/dist/ui/tools/PauseDelegationTool/index.js +0 -35
- package/dist/ui/tools/ProbeTool/index.js +0 -121
- package/dist/ui/tools/ProcessTool/index.js +0 -66
- package/dist/ui/tools/QuestListTool/index.js +0 -46
- package/dist/ui/tools/QuestReportTool/index.js +0 -49
- package/dist/ui/tools/QuestUpdateTool/index.js +0 -87
- package/dist/ui/tools/QuipCommentTool/index.js +0 -69
- package/dist/ui/tools/QuipReadTool/index.js +0 -71
- package/dist/ui/tools/RestArionTool/index.js +0 -32
- package/dist/ui/tools/RestartTool/index.js +0 -35
- package/dist/ui/tools/ResumeDelegationTool/index.js +0 -35
- package/dist/ui/tools/RetireArionTool/index.js +0 -32
- package/dist/ui/tools/RgTool/index.js +0 -73
- package/dist/ui/tools/SearchKnowledgeTool/index.js +0 -43
- package/dist/ui/tools/SearchMessagesTool/index.js +0 -43
- package/dist/ui/tools/SelfDiagnoseTool/index.js +0 -61
- package/dist/ui/tools/SendMessageTool/index.js +0 -45
- package/dist/ui/tools/SerenaTool/index.js +0 -124
- package/dist/ui/tools/SessionHistoryTool/index.js +0 -52
- package/dist/ui/tools/SgTool/index.js +0 -80
- package/dist/ui/tools/SlackReactTool/index.js +0 -41
- package/dist/ui/tools/SlackReadTool/index.js +0 -48
- package/dist/ui/tools/SlackSendTool/index.js +0 -45
- package/dist/ui/tools/SpawnWorkerTool/index.js +0 -33
- package/dist/ui/tools/StickerRequestTool/index.js +0 -19
- package/dist/ui/tools/ThinkTool/index.js +0 -17
- package/dist/ui/tools/UgTool/index.js +0 -108
- package/dist/ui/tools/UseSkillTool/index.js +0 -22
- package/dist/ui/tools/WakeArionTool/index.js +0 -32
- package/dist/ui/tools/WebFetchTool/index.js +0 -56
- package/dist/ui/tools/WebSearchTool/index.js +0 -44
- package/dist/ui/tools/lsTool/index.js +0 -58
- package/dist/ui/tools/registry.js +0 -197
- package/dist/ui/tools/tool-renderer.js +0 -11
- package/dist/ui/tools/truncation.js +0 -35
- package/dist/ui/types/anthropic.js +0 -4
- package/dist/ui/types/index.js +0 -2
- package/dist/ui/types/message.js +0 -3
- package/dist/ui/types/tool.js +0 -4
- package/dist/ui/utils/array.js +0 -4
- package/dist/ui/utils/cursor.js +0 -131
- package/dist/ui/utils/diff.js +0 -120
- package/dist/ui/utils/format.js +0 -42
- package/dist/ui/utils/fuzzy.js +0 -59
- package/dist/ui/utils/index.js +0 -11
- package/dist/ui/utils/keys.js +0 -8
- package/dist/ui/utils/patch.js +0 -17
- package/dist/ui/utils/risk.js +0 -114
- package/dist/ui/utils/terminal-image.js +0 -70
- package/dist/ui/utils/validation.js +0 -48
- package/dist/ui/verb-pairs.js +0 -248
- package/dist/ui.js +0 -131
- package/src/entrypoints/command-mode.ts +0 -5
- package/src/entrypoints/daemon.ts +0 -54
- package/src/entrypoints/headless-stdio.ts +0 -27
- package/src/entrypoints/interactive.ts +0 -112
- package/src/main.ts +0 -72
- package/src/runtime/configure-bun-sqlite.ts +0 -3
- package/src/runtime/crash-handlers.ts +0 -128
- package/src/runtime/interactive-invocation.test.ts +0 -42
- package/src/runtime/interactive-invocation.ts +0 -51
- package/src/runtime/internal-mode.test.ts +0 -19
- package/src/runtime/internal-mode.ts +0 -24
- package/src/runtime/launch-spec.test.ts +0 -26
- package/src/runtime/launch-spec.ts +0 -84
- package/src/runtime/owner-lease.ts +0 -52
- package/src/runtime/public-mode.test.ts +0 -18
- package/src/runtime/public-mode.ts +0 -19
- package/src/runtime/run-internal-mode.ts +0 -19
- package/src/runtime/runtime-kind.test.ts +0 -23
- package/src/runtime/runtime-kind.ts +0 -41
- package/src/runtime/spawn-aria.ts +0 -62
package/dist/headless/kernel.js
DELETED
|
@@ -1,785 +0,0 @@
|
|
|
1
|
-
import path, { join } from "node:path";
|
|
2
|
-
import { createLazyAttachedLocalControlApi, logReattach, } from "../local-control-lazy-wrapper.js";
|
|
3
|
-
import { ArionManager, ArionStorage, MemoriaPool } from "@aria-cli/aria";
|
|
4
|
-
import { selectRunnableModelVariant, } from "@aria-cli/models";
|
|
5
|
-
import { HEADLESS_OPERATION_SCHEMAS } from "@aria-cli/tools";
|
|
6
|
-
import { createCliContext } from "../cli-context.js";
|
|
7
|
-
import { loadConfig, saveConfig } from "../config.js";
|
|
8
|
-
import { SessionHistory, } from "../history/index.js";
|
|
9
|
-
import { cliStallPhase } from "../history/stall-phase-bridge.js";
|
|
10
|
-
import { attachLocalControlClient } from "../local-control-client.js";
|
|
11
|
-
import { createArionOperationHandlers } from "./operations/arion.js";
|
|
12
|
-
import { createAuthOperationHandlers } from "./operations/auth.js";
|
|
13
|
-
import { buildStructuredLoginArgs, buildStructuredLogoutArgs, getHeadlessAuthProviders, runHeadlessLogin, runHeadlessLogout, } from "./auth-service.js";
|
|
14
|
-
import { createClientOperationHandlers } from "./operations/client.js";
|
|
15
|
-
import { createConfigOperationHandlers } from "./operations/config.js";
|
|
16
|
-
import { createDaemonOperationHandlers } from "./operations/daemon.js";
|
|
17
|
-
import { createRunOperationHandlers } from "./operations/index.js";
|
|
18
|
-
import { createHookOperationHandlers } from "./operations/hook.js";
|
|
19
|
-
import { createMemoryOperationHandlers } from "./operations/memory.js";
|
|
20
|
-
import { createMessageOperationHandlers } from "./operations/message.js";
|
|
21
|
-
import { createModelOperationHandlers } from "./operations/model.js";
|
|
22
|
-
import { createPeerOperationHandlers } from "./operations/peer.js";
|
|
23
|
-
import { createSessionOperationHandlers } from "./operations/session.js";
|
|
24
|
-
import { createSystemOperationHandlers } from "./operations/system.js";
|
|
25
|
-
import { createDaemonService } from "./daemon-service.js";
|
|
26
|
-
import { createHookService } from "./hook-service.js";
|
|
27
|
-
import { HeadlessAuthOrchestrator } from "./auth-orchestrator.js";
|
|
28
|
-
import { HeadlessRunOrchestrator } from "./run-orchestrator.js";
|
|
29
|
-
import { isTerminalSetupSupported, runTerminalSetup } from "../commands/terminal-setup.js";
|
|
30
|
-
import { getAvailableThemes, getTheme, setTheme } from "../ui/theme/index.js";
|
|
31
|
-
async function releaseHeadlessKernelBootstrapResources(resources) {
|
|
32
|
-
const failures = [];
|
|
33
|
-
for (const sessionLedger of resources.sessionLedgers ?? []) {
|
|
34
|
-
try {
|
|
35
|
-
sessionLedger?.close();
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
failures.push(error);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
for (const attachedClient of resources.attachedClients ?? []) {
|
|
42
|
-
try {
|
|
43
|
-
await attachedClient?.release();
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
failures.push(error);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
await resources.daemon?.releaseAll?.();
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
failures.push(error);
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
await resources.managerPool?.closeAll();
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
failures.push(error);
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
await resources.cli?.pool.closeAll();
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
failures.push(error);
|
|
66
|
-
}
|
|
67
|
-
if (failures.length === 1) {
|
|
68
|
-
throw failures[0];
|
|
69
|
-
}
|
|
70
|
-
if (failures.length > 1) {
|
|
71
|
-
throw new AggregateError(failures, "Failed to release headless kernel bootstrap resources");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const ATTACHED_CLIENT_ATTACH_TIMEOUT_MS = 10_000;
|
|
75
|
-
function withTimeout(promise, timeoutMs, message) {
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
const timeoutId = setTimeout(() => {
|
|
78
|
-
reject(new Error(message));
|
|
79
|
-
}, timeoutMs);
|
|
80
|
-
timeoutId.unref?.();
|
|
81
|
-
promise.then((value) => {
|
|
82
|
-
clearTimeout(timeoutId);
|
|
83
|
-
resolve(value);
|
|
84
|
-
}, (error) => {
|
|
85
|
-
clearTimeout(timeoutId);
|
|
86
|
-
reject(error);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function failureResult(requestId, op, code, message, details) {
|
|
91
|
-
return {
|
|
92
|
-
kind: "result",
|
|
93
|
-
requestId,
|
|
94
|
-
op,
|
|
95
|
-
ok: false,
|
|
96
|
-
error: {
|
|
97
|
-
code,
|
|
98
|
-
message,
|
|
99
|
-
...(details ? { details } : {}),
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function resolveModelFromCommandArg(modelArg, availableModels, credentialHints) {
|
|
104
|
-
const normalized = modelArg.trim().toLowerCase();
|
|
105
|
-
if (!normalized) {
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
const sorted = [...availableModels].sort((a, b) => a.shortName.localeCompare(b.shortName));
|
|
109
|
-
const byQualifiedExact = sorted.find((model) => {
|
|
110
|
-
const qualified = `${model.provider}/${model.shortName}`.toLowerCase();
|
|
111
|
-
return qualified === normalized;
|
|
112
|
-
});
|
|
113
|
-
if (byQualifiedExact) {
|
|
114
|
-
return byQualifiedExact;
|
|
115
|
-
}
|
|
116
|
-
const exact = sorted.find((model) => model.shortName.toLowerCase() === normalized);
|
|
117
|
-
if (exact) {
|
|
118
|
-
return selectRunnableModelVariant(exact, credentialHints);
|
|
119
|
-
}
|
|
120
|
-
const byPrefix = sorted.find((model) => model.shortName.toLowerCase().startsWith(normalized));
|
|
121
|
-
if (byPrefix) {
|
|
122
|
-
return selectRunnableModelVariant(byPrefix, credentialHints);
|
|
123
|
-
}
|
|
124
|
-
const byQualifiedPrefix = sorted.find((model) => {
|
|
125
|
-
const qualified = `${model.provider}/${model.shortName}`.toLowerCase();
|
|
126
|
-
return qualified.startsWith(normalized);
|
|
127
|
-
});
|
|
128
|
-
if (byQualifiedPrefix) {
|
|
129
|
-
return byQualifiedPrefix;
|
|
130
|
-
}
|
|
131
|
-
const byTier = sorted.find((model) => model.tier.toLowerCase() === normalized);
|
|
132
|
-
if (byTier) {
|
|
133
|
-
return selectRunnableModelVariant(byTier, credentialHints);
|
|
134
|
-
}
|
|
135
|
-
const byDisplay = sorted.find((model) => model.displayName.toLowerCase().includes(normalized));
|
|
136
|
-
if (byDisplay) {
|
|
137
|
-
return selectRunnableModelVariant(byDisplay, credentialHints);
|
|
138
|
-
}
|
|
139
|
-
const byProvider = sorted.find((model) => model.provider.toLowerCase().includes(normalized));
|
|
140
|
-
return byProvider ? selectRunnableModelVariant(byProvider, credentialHints) : undefined;
|
|
141
|
-
}
|
|
142
|
-
function unsupportedOperationHandler(op) {
|
|
143
|
-
return async function* (requestId) {
|
|
144
|
-
yield failureResult(requestId, op, "UNSUPPORTED_OPERATION", `Operation ${op} is not implemented in the kernel yet.`);
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
export function createHeadlessKernelHandlers(ctx) {
|
|
148
|
-
// If no daemon service was provided (e.g. the REPL path), create one
|
|
149
|
-
// using the caller-supplied localControl — the REPL's already-attached
|
|
150
|
-
// connection that reliably reaches the shared daemon.
|
|
151
|
-
if (!ctx.daemon) {
|
|
152
|
-
ctx.daemon = createDaemonService({
|
|
153
|
-
cli: ctx.cli,
|
|
154
|
-
cwd: process.cwd(),
|
|
155
|
-
arionName: ctx.getSessionArion?.() ?? ctx.cli.config.activeArion ?? "ARIA",
|
|
156
|
-
localControl: ctx.localControl,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
const orchestrator = new HeadlessRunOrchestrator({
|
|
160
|
-
localControl: ctx.localControl,
|
|
161
|
-
sessionLedger: ctx.sessionLedger,
|
|
162
|
-
activeRunController: ctx.activeRunController,
|
|
163
|
-
getSessionModel: ctx.getSessionModel,
|
|
164
|
-
getSessionArion: ctx.getSessionArion,
|
|
165
|
-
});
|
|
166
|
-
const authOrchestrator = new HeadlessAuthOrchestrator(ctx.auth, ctx.sessionLedger, async () => (await ctx.config?.getActiveArion?.()) ??
|
|
167
|
-
ctx.cli?.config?.activeArion ??
|
|
168
|
-
"ARIA");
|
|
169
|
-
const runHandlers = createRunOperationHandlers(orchestrator);
|
|
170
|
-
const memoryHandlers = createMemoryOperationHandlers(ctx);
|
|
171
|
-
const arionHandlers = createArionOperationHandlers(ctx);
|
|
172
|
-
const modelHandlers = createModelOperationHandlers(ctx);
|
|
173
|
-
const authHandlers = createAuthOperationHandlers(ctx, authOrchestrator);
|
|
174
|
-
const configHandlers = createConfigOperationHandlers(ctx);
|
|
175
|
-
const daemonHandlers = createDaemonOperationHandlers(ctx);
|
|
176
|
-
const hookHandlers = createHookOperationHandlers(ctx);
|
|
177
|
-
const systemHandlers = createSystemOperationHandlers(ctx);
|
|
178
|
-
const peerHandlers = createPeerOperationHandlers(ctx);
|
|
179
|
-
const clientHandlers = createClientOperationHandlers(ctx);
|
|
180
|
-
const messageHandlers = createMessageOperationHandlers(ctx);
|
|
181
|
-
const sessionHandlers = createSessionOperationHandlers(ctx);
|
|
182
|
-
return {
|
|
183
|
-
"run.start": runHandlers["run.start"],
|
|
184
|
-
"run.resume": runHandlers["run.resume"],
|
|
185
|
-
"run.abort": runHandlers["run.abort"],
|
|
186
|
-
"interaction.respond": async function* (requestId, input, context) {
|
|
187
|
-
const response = input && typeof input === "object" && "kind" in input
|
|
188
|
-
? input
|
|
189
|
-
: {
|
|
190
|
-
kind: "interaction.respond",
|
|
191
|
-
requestId,
|
|
192
|
-
...input,
|
|
193
|
-
};
|
|
194
|
-
const interaction = ctx.sessionLedger.getInteraction(response.interactionId);
|
|
195
|
-
if (interaction?.source === "auth") {
|
|
196
|
-
yield* authOrchestrator.respond(response, context);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
yield* runHandlers["interaction.respond"](requestId, response, context);
|
|
200
|
-
},
|
|
201
|
-
"session.list": sessionHandlers["session.list"],
|
|
202
|
-
"session.read": sessionHandlers["session.read"],
|
|
203
|
-
"session.load": sessionHandlers["session.load"],
|
|
204
|
-
"session.fork": sessionHandlers["session.fork"],
|
|
205
|
-
"memory.remember": memoryHandlers["memory.remember"],
|
|
206
|
-
"memory.recall": memoryHandlers["memory.recall"],
|
|
207
|
-
"memory.list": memoryHandlers["memory.list"],
|
|
208
|
-
"memory.forget": memoryHandlers["memory.forget"],
|
|
209
|
-
"memory.recall_knowledge": memoryHandlers["memory.recall_knowledge"],
|
|
210
|
-
"arion.list": arionHandlers["arion.list"],
|
|
211
|
-
"arion.hatch": arionHandlers["arion.hatch"],
|
|
212
|
-
"arion.become": arionHandlers["arion.become"],
|
|
213
|
-
"arion.rest": arionHandlers["arion.rest"],
|
|
214
|
-
"arion.wake": arionHandlers["arion.wake"],
|
|
215
|
-
"arion.create": arionHandlers["arion.create"],
|
|
216
|
-
"model.list": modelHandlers["model.list"],
|
|
217
|
-
"model.set": modelHandlers["model.set"],
|
|
218
|
-
"model.refresh": modelHandlers["model.refresh"],
|
|
219
|
-
"auth.status": authHandlers["auth.status"],
|
|
220
|
-
"auth.login": authHandlers["auth.login"],
|
|
221
|
-
"auth.logout": authHandlers["auth.logout"],
|
|
222
|
-
"auth.clear_session": authHandlers["auth.clear_session"],
|
|
223
|
-
"auth.import_env_session": authHandlers["auth.import_env_session"],
|
|
224
|
-
"peer.list": peerHandlers["peer.list"],
|
|
225
|
-
"peer.list_nearby": peerHandlers["peer.list_nearby"],
|
|
226
|
-
"peer.pending.list": peerHandlers["peer.pending.list"],
|
|
227
|
-
"peer.pending.respond": peerHandlers["peer.pending.respond"],
|
|
228
|
-
"peer.invite": peerHandlers["peer.invite"],
|
|
229
|
-
"peer.connect": peerHandlers["peer.connect"],
|
|
230
|
-
"peer.accept_invite": peerHandlers["peer.accept_invite"],
|
|
231
|
-
"peer.direct_pair": peerHandlers["peer.direct_pair"],
|
|
232
|
-
"peer.repair": peerHandlers["peer.repair"],
|
|
233
|
-
"peer.revoke": peerHandlers["peer.revoke"],
|
|
234
|
-
"client.list": clientHandlers["client.list"],
|
|
235
|
-
"client.inbox.list": clientHandlers["client.inbox.list"],
|
|
236
|
-
"message.send": messageHandlers["message.send"],
|
|
237
|
-
"message.inbox.list": messageHandlers["message.inbox.list"],
|
|
238
|
-
"config.theme.get": configHandlers["config.theme.get"],
|
|
239
|
-
"config.theme.set": configHandlers["config.theme.set"],
|
|
240
|
-
"config.autonomy.get": configHandlers["config.autonomy.get"],
|
|
241
|
-
"config.autonomy.set": configHandlers["config.autonomy.set"],
|
|
242
|
-
"system.restart": systemHandlers["system.restart"],
|
|
243
|
-
"system.terminal_setup": systemHandlers["system.terminal_setup"],
|
|
244
|
-
"daemon.start": daemonHandlers["daemon.start"],
|
|
245
|
-
"daemon.status": daemonHandlers["daemon.status"],
|
|
246
|
-
"daemon.stop": daemonHandlers["daemon.stop"],
|
|
247
|
-
"daemon.restart": daemonHandlers["daemon.restart"],
|
|
248
|
-
"hook.extract": hookHandlers["hook.extract"],
|
|
249
|
-
"hook.reflect": hookHandlers["hook.reflect"],
|
|
250
|
-
"hook.consolidate": hookHandlers["hook.consolidate"],
|
|
251
|
-
"hook.ingest": hookHandlers["hook.ingest"],
|
|
252
|
-
"hook.harvest": hookHandlers["hook.harvest"],
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
export class HeadlessKernel {
|
|
256
|
-
ctx;
|
|
257
|
-
handlers;
|
|
258
|
-
constructor(ctx, handlers) {
|
|
259
|
-
this.ctx = ctx;
|
|
260
|
-
// connectToPublishedRuntimeSocket returns a createResilientAttachedClient-
|
|
261
|
-
// backed client that handles network failures (ECONNREFUSED, ECONNRESET)
|
|
262
|
-
// transparently. However, if the ResilientAttachedClient is RELEASED
|
|
263
|
-
// (e.g. SIGINT race, cleanup ordering), its `released` flag is permanent
|
|
264
|
-
// and no amount of internal retry can recover — a completely new client
|
|
265
|
-
// is needed. Wrap with createLazyAttachedLocalControlApi so that
|
|
266
|
-
// "has been released" (recognized by isStaleLeaseError) triggers cache
|
|
267
|
-
// invalidation and reconnection via a fresh ResilientAttachedClient.
|
|
268
|
-
if (!handlers) {
|
|
269
|
-
const alreadyManaged = ctx.localControl?.__ariaLazyControl;
|
|
270
|
-
let stale = false;
|
|
271
|
-
const originalControl = ctx.localControl;
|
|
272
|
-
if (!alreadyManaged) {
|
|
273
|
-
ctx.localControl = createLazyAttachedLocalControlApi(async () => {
|
|
274
|
-
if (!stale)
|
|
275
|
-
return originalControl;
|
|
276
|
-
const { createResilientAttachedClient } = await import("../attached-local-control-client.js");
|
|
277
|
-
const server = await import("@aria-cli/server");
|
|
278
|
-
const runtimeRoot = server.resolveRuntimeRootDirectory();
|
|
279
|
-
const owner = server.findRuntimeOwnerRecordByAriaHome(runtimeRoot, ctx.cli.ariaDir);
|
|
280
|
-
if (!owner?.runtimeSocket) {
|
|
281
|
-
throw new Error("Cannot reconnect: no daemon found after restart");
|
|
282
|
-
}
|
|
283
|
-
const resilient = await createResilientAttachedClient({
|
|
284
|
-
runtimeSocket: owner.runtimeSocket,
|
|
285
|
-
clientKind: "local-api",
|
|
286
|
-
logDir: join(ctx.cli.ariaDir, "logs"),
|
|
287
|
-
});
|
|
288
|
-
return resilient.api;
|
|
289
|
-
}, () => {
|
|
290
|
-
stale = true;
|
|
291
|
-
}, ctx.cli.ariaDir);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
this.handlers = handlers ?? createHeadlessKernelHandlers(ctx);
|
|
295
|
-
}
|
|
296
|
-
async *dispatch(frame, context = {}) {
|
|
297
|
-
if (frame.kind === "interaction.respond") {
|
|
298
|
-
const parsed = HEADLESS_OPERATION_SCHEMAS["interaction.respond"].input.safeParse({
|
|
299
|
-
interactionId: frame.interactionId,
|
|
300
|
-
response: frame.response,
|
|
301
|
-
});
|
|
302
|
-
if (!parsed.success) {
|
|
303
|
-
yield failureResult(frame.requestId, "interaction.respond", "INVALID_INPUT", parsed.error.issues
|
|
304
|
-
.map((issue) => `${issue.path.join(".") || "<root>"} ${issue.message}`)
|
|
305
|
-
.join("; "));
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
yield* this.handlers["interaction.respond"](frame.requestId, frame, context);
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const request = frame;
|
|
312
|
-
const parsed = HEADLESS_OPERATION_SCHEMAS[request.op].input.safeParse(request.input);
|
|
313
|
-
if (!parsed.success) {
|
|
314
|
-
yield failureResult(request.requestId, request.op, "INVALID_INPUT", parsed.error.issues
|
|
315
|
-
.map((issue) => `${issue.path.join(".") || "<root>"} ${issue.message}`)
|
|
316
|
-
.join("; "));
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
yield* this.handlers[request.op](request.requestId, parsed.data, context);
|
|
320
|
-
}
|
|
321
|
-
subscribeDirectClientInbox(cursor) {
|
|
322
|
-
return this.ctx.localControl.subscribeDirectClientInbox(cursor);
|
|
323
|
-
}
|
|
324
|
-
getConnectionState() {
|
|
325
|
-
const control = this.ctx.localControl;
|
|
326
|
-
return control.getConnectionState?.() ?? "connected";
|
|
327
|
-
}
|
|
328
|
-
onConnectionStateChange(listener) {
|
|
329
|
-
const control = this.ctx.localControl;
|
|
330
|
-
return control.onConnectionStateChange?.(listener) ?? (() => { });
|
|
331
|
-
}
|
|
332
|
-
getAttachedCredentials() {
|
|
333
|
-
const control = this.ctx.localControl;
|
|
334
|
-
const clientId = control.getClientId?.();
|
|
335
|
-
const clientAuthToken = control.getClientAuthToken?.();
|
|
336
|
-
if (!clientId || !clientAuthToken)
|
|
337
|
-
return null;
|
|
338
|
-
return { clientId, clientAuthToken };
|
|
339
|
-
}
|
|
340
|
-
async resolveRuntimeSocket() {
|
|
341
|
-
return (await this.ctx.resolveRuntimeSocket?.()) ?? null;
|
|
342
|
-
}
|
|
343
|
-
getContext() {
|
|
344
|
-
return this.ctx;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
export async function createHeadlessKernelRuntime(options) {
|
|
348
|
-
let cli = null;
|
|
349
|
-
let managerPool = null;
|
|
350
|
-
let daemonService = null;
|
|
351
|
-
const sessionLedgers = new Map();
|
|
352
|
-
const attachedClientLoads = new Map();
|
|
353
|
-
const orphanedAttachedClientLoads = new Set();
|
|
354
|
-
let released = false;
|
|
355
|
-
const releaseResources = async () => {
|
|
356
|
-
if (released) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
released = true;
|
|
360
|
-
const attachedClients = await Promise.allSettled([
|
|
361
|
-
...attachedClientLoads.values(),
|
|
362
|
-
...orphanedAttachedClientLoads.values(),
|
|
363
|
-
]);
|
|
364
|
-
await releaseHeadlessKernelBootstrapResources({
|
|
365
|
-
sessionLedgers: [...sessionLedgers.values()],
|
|
366
|
-
attachedClients: attachedClients.flatMap((result) => result.status === "fulfilled" ? [result.value] : []),
|
|
367
|
-
daemon: daemonService,
|
|
368
|
-
managerPool,
|
|
369
|
-
cli,
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
|
-
try {
|
|
373
|
-
cli = await createCliContext({
|
|
374
|
-
cwd: options?.cwd,
|
|
375
|
-
skipDiscoveryRefresh: true,
|
|
376
|
-
});
|
|
377
|
-
const activeCli = cli;
|
|
378
|
-
let currentArionName = options?.arionName ?? activeCli.config.activeArion ?? "ARIA";
|
|
379
|
-
let currentModelName;
|
|
380
|
-
const getCurrentArionName = () => currentArionName;
|
|
381
|
-
const getCurrentModelName = () => currentModelName;
|
|
382
|
-
const persistCurrentArionName = (name) => {
|
|
383
|
-
currentArionName = name;
|
|
384
|
-
const config = loadConfig();
|
|
385
|
-
config.activeArion = name;
|
|
386
|
-
saveConfig(config);
|
|
387
|
-
};
|
|
388
|
-
const ensureSessionLedger = (arionName) => {
|
|
389
|
-
let ledger = sessionLedgers.get(arionName);
|
|
390
|
-
if (!ledger) {
|
|
391
|
-
ledger = new SessionHistory(SessionHistory.resolvePerArionPath(activeCli.ariaDir, arionName), { stallPhase: cliStallPhase });
|
|
392
|
-
sessionLedgers.set(arionName, ledger);
|
|
393
|
-
}
|
|
394
|
-
return ledger;
|
|
395
|
-
};
|
|
396
|
-
const tryConnectToDaemonSocket = async () => {
|
|
397
|
-
try {
|
|
398
|
-
const { resolveRuntimeRootDirectory, findRuntimeOwnerRecordByAriaHome } = await import("@aria-cli/server");
|
|
399
|
-
const { createResilientAttachedClient } = await import("../local-control-client.js");
|
|
400
|
-
const runtimeRoot = resolveRuntimeRootDirectory();
|
|
401
|
-
const owner = findRuntimeOwnerRecordByAriaHome(runtimeRoot, activeCli.ariaDir);
|
|
402
|
-
if (!owner?.runtimeSocket) {
|
|
403
|
-
return null;
|
|
404
|
-
}
|
|
405
|
-
// Use the resilient client factory — it owns lease acquisition,
|
|
406
|
-
// auth, reattach with backoff, and logging. The returned API
|
|
407
|
-
// survives daemon restarts transparently.
|
|
408
|
-
const resilient = await createResilientAttachedClient({
|
|
409
|
-
runtimeSocket: owner.runtimeSocket,
|
|
410
|
-
clientKind: "local-api",
|
|
411
|
-
logDir: join(activeCli.ariaDir, "logs"),
|
|
412
|
-
});
|
|
413
|
-
return {
|
|
414
|
-
nodeId: owner.nodeId,
|
|
415
|
-
runtimeId: (owner.runtimeId ?? "daemon"),
|
|
416
|
-
port: 0,
|
|
417
|
-
ownership: "reattached",
|
|
418
|
-
control: resilient.api,
|
|
419
|
-
attachedClientId: resilient.getClientId(),
|
|
420
|
-
attachedClientAuthToken: resilient.getClientAuthToken(),
|
|
421
|
-
release: () => resilient.release(),
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
catch (err) {
|
|
425
|
-
logReattach(activeCli.ariaDir, {
|
|
426
|
-
event: "daemon_socket_connect_failed",
|
|
427
|
-
error: err instanceof Error ? err.message : String(err),
|
|
428
|
-
});
|
|
429
|
-
return null;
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
const ensureAttachedClient = async (arionName) => {
|
|
433
|
-
let managedLoad = attachedClientLoads.get(arionName);
|
|
434
|
-
if (!managedLoad) {
|
|
435
|
-
managedLoad = (async () => {
|
|
436
|
-
// Connect to the running daemon's socket. CLI subcommands are
|
|
437
|
-
// pure clients — they never create runtimes. Only the daemon
|
|
438
|
-
// and interactive REPL own runtimes.
|
|
439
|
-
const daemonClient = await tryConnectToDaemonSocket();
|
|
440
|
-
if (daemonClient) {
|
|
441
|
-
logReattach(activeCli.ariaDir, {
|
|
442
|
-
event: "ensureAttachedClient_resolved",
|
|
443
|
-
path: "daemon_socket",
|
|
444
|
-
arionName,
|
|
445
|
-
});
|
|
446
|
-
if (released) {
|
|
447
|
-
await daemonClient.release().catch(() => { });
|
|
448
|
-
}
|
|
449
|
-
return daemonClient;
|
|
450
|
-
}
|
|
451
|
-
logReattach(activeCli.ariaDir, {
|
|
452
|
-
event: "ensureAttachedClient_fallback",
|
|
453
|
-
path: "attachLocalControlClient",
|
|
454
|
-
arionName,
|
|
455
|
-
});
|
|
456
|
-
// No daemon found via runtime root. Fall back to
|
|
457
|
-
// attachLocalControlClient which goes through the HostSupervisor.
|
|
458
|
-
// If a daemon IS running (missed by tryConnectToDaemonSocket due
|
|
459
|
-
// to ARIA_HOME mismatch), the supervisor's split-brain detection
|
|
460
|
-
// will catch it and connect to the daemon's socket. Otherwise it
|
|
461
|
-
// creates a standalone scoped runtime (for aria headless mode).
|
|
462
|
-
let client;
|
|
463
|
-
try {
|
|
464
|
-
client = await attachLocalControlClient({
|
|
465
|
-
ariaHome: activeCli.ariaDir,
|
|
466
|
-
arionName,
|
|
467
|
-
clientKind: "local-api",
|
|
468
|
-
runtimeLifecycle: "scoped",
|
|
469
|
-
memoriaFactory: activeCli.memoriaFactory,
|
|
470
|
-
router: activeCli.router,
|
|
471
|
-
authResolver: activeCli.authResolver,
|
|
472
|
-
runSessionConfig: activeCli.config,
|
|
473
|
-
mcpServers: activeCli.projectConfig.mcp?.servers,
|
|
474
|
-
silent: true,
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
catch (err) {
|
|
478
|
-
if (err instanceof Error && err.message.includes("already in use")) {
|
|
479
|
-
throw new Error("A daemon is running but could not be reached. " +
|
|
480
|
-
"Ensure ARIA_HOME matches the daemon's home directory, " +
|
|
481
|
-
"or stop the daemon with: aria-stop");
|
|
482
|
-
}
|
|
483
|
-
throw err;
|
|
484
|
-
}
|
|
485
|
-
if (released) {
|
|
486
|
-
await client.release().catch(() => { });
|
|
487
|
-
}
|
|
488
|
-
return client;
|
|
489
|
-
})();
|
|
490
|
-
attachedClientLoads.set(arionName, managedLoad);
|
|
491
|
-
}
|
|
492
|
-
return withTimeout(managedLoad, ATTACHED_CLIENT_ATTACH_TIMEOUT_MS, `Timed out attaching local control for ${arionName}`).catch((error) => {
|
|
493
|
-
orphanedAttachedClientLoads.add(managedLoad);
|
|
494
|
-
void managedLoad.finally(() => {
|
|
495
|
-
orphanedAttachedClientLoads.delete(managedLoad);
|
|
496
|
-
});
|
|
497
|
-
attachedClientLoads.delete(arionName);
|
|
498
|
-
throw error;
|
|
499
|
-
});
|
|
500
|
-
};
|
|
501
|
-
const localControl = createLazyAttachedLocalControlApi(async () => {
|
|
502
|
-
const attachedClient = await ensureAttachedClient(getCurrentArionName());
|
|
503
|
-
return attachedClient.control;
|
|
504
|
-
}, () => {
|
|
505
|
-
// Server restarted — our lease is stale. Clear the cached client
|
|
506
|
-
// so ensureAttachedClient performs a fresh attach on the next call.
|
|
507
|
-
const arionName = getCurrentArionName();
|
|
508
|
-
const staleLoad = attachedClientLoads.get(arionName);
|
|
509
|
-
if (staleLoad) {
|
|
510
|
-
orphanedAttachedClientLoads.add(staleLoad);
|
|
511
|
-
void staleLoad
|
|
512
|
-
.then((client) => client.release().catch(() => { }))
|
|
513
|
-
.finally(() => orphanedAttachedClientLoads.delete(staleLoad));
|
|
514
|
-
attachedClientLoads.delete(arionName);
|
|
515
|
-
}
|
|
516
|
-
}, activeCli.ariaDir);
|
|
517
|
-
const sessionLedger = new Proxy({}, {
|
|
518
|
-
get(_target, propertyKey) {
|
|
519
|
-
const ledger = ensureSessionLedger(getCurrentArionName());
|
|
520
|
-
const member = ledger[propertyKey];
|
|
521
|
-
return typeof member === "function" ? member.bind(ledger) : member;
|
|
522
|
-
},
|
|
523
|
-
});
|
|
524
|
-
ensureSessionLedger(currentArionName);
|
|
525
|
-
managerPool = new MemoriaPool(activeCli.ariaDir);
|
|
526
|
-
const arionManager = new ArionManager(new ArionStorage(activeCli.ariaDir), managerPool.toFactory());
|
|
527
|
-
arionManager.setRouter(activeCli.router);
|
|
528
|
-
await arionManager.initialize();
|
|
529
|
-
let availableModels = activeCli.availableModels;
|
|
530
|
-
const resolveMemoriaPath = async () => {
|
|
531
|
-
const configuredArionName = getCurrentArionName();
|
|
532
|
-
const configuredArion = await arionManager.get(configuredArionName);
|
|
533
|
-
return configuredArion?.memoriaPath ?? path.join("arions", configuredArionName, "memory.db");
|
|
534
|
-
};
|
|
535
|
-
const loadMemoria = async () => {
|
|
536
|
-
const resolvedMemoria = await activeCli.pool.get(await resolveMemoriaPath());
|
|
537
|
-
return resolvedMemoria;
|
|
538
|
-
};
|
|
539
|
-
const memoria = new Proxy({}, {
|
|
540
|
-
get(_target, propertyKey) {
|
|
541
|
-
return async (...args) => {
|
|
542
|
-
const resolvedMemoria = await loadMemoria();
|
|
543
|
-
const member = resolvedMemoria[propertyKey];
|
|
544
|
-
if (typeof member !== "function") {
|
|
545
|
-
return member;
|
|
546
|
-
}
|
|
547
|
-
return member.apply(resolvedMemoria, args);
|
|
548
|
-
};
|
|
549
|
-
},
|
|
550
|
-
});
|
|
551
|
-
daemonService = createDaemonService({
|
|
552
|
-
cli: activeCli,
|
|
553
|
-
cwd: options?.cwd ?? process.cwd(),
|
|
554
|
-
arionName: getCurrentArionName(),
|
|
555
|
-
getArionName: getCurrentArionName,
|
|
556
|
-
localControl,
|
|
557
|
-
});
|
|
558
|
-
const hookService = createHookService({
|
|
559
|
-
cli: activeCli,
|
|
560
|
-
arionName: getCurrentArionName(),
|
|
561
|
-
getArionName: getCurrentArionName,
|
|
562
|
-
resolveMemoriaPath,
|
|
563
|
-
});
|
|
564
|
-
const ctx = {
|
|
565
|
-
cli: activeCli,
|
|
566
|
-
localControl,
|
|
567
|
-
sessionLedger,
|
|
568
|
-
arionManager: {
|
|
569
|
-
list: () => arionManager.list(),
|
|
570
|
-
hatch: (input) => arionManager.hatch(input),
|
|
571
|
-
get: (name) => arionManager.get(name),
|
|
572
|
-
wake: (name) => arionManager.wake(name),
|
|
573
|
-
rest: (name, restOptions) => arionManager.rest(name, restOptions),
|
|
574
|
-
},
|
|
575
|
-
memoria,
|
|
576
|
-
config: {
|
|
577
|
-
async getTheme() {
|
|
578
|
-
return loadConfig().theme ?? getTheme().name;
|
|
579
|
-
},
|
|
580
|
-
async setTheme(theme) {
|
|
581
|
-
const validThemes = getAvailableThemes();
|
|
582
|
-
if (!validThemes.includes(theme)) {
|
|
583
|
-
throw new Error(`Unknown theme: ${theme}`);
|
|
584
|
-
}
|
|
585
|
-
setTheme(theme);
|
|
586
|
-
const config = loadConfig();
|
|
587
|
-
config.theme = theme;
|
|
588
|
-
saveConfig(config);
|
|
589
|
-
return { theme };
|
|
590
|
-
},
|
|
591
|
-
async getAutonomy() {
|
|
592
|
-
return loadConfig().autonomy ?? "balanced";
|
|
593
|
-
},
|
|
594
|
-
async setAutonomy(autonomy) {
|
|
595
|
-
if (!["minimal", "balanced", "high", "full"].includes(autonomy)) {
|
|
596
|
-
throw new Error(`Invalid autonomy level: ${autonomy}`);
|
|
597
|
-
}
|
|
598
|
-
const config = loadConfig();
|
|
599
|
-
config.autonomy = autonomy;
|
|
600
|
-
saveConfig(config);
|
|
601
|
-
return { autonomy };
|
|
602
|
-
},
|
|
603
|
-
async getActiveArion() {
|
|
604
|
-
return getCurrentArionName();
|
|
605
|
-
},
|
|
606
|
-
async setActiveArion(name) {
|
|
607
|
-
persistCurrentArionName(name);
|
|
608
|
-
},
|
|
609
|
-
},
|
|
610
|
-
auth: (() => {
|
|
611
|
-
return {
|
|
612
|
-
async status() {
|
|
613
|
-
let sessionProviders = [];
|
|
614
|
-
try {
|
|
615
|
-
const state = await ctx.localControl.getSessionCredentialOverlayState?.();
|
|
616
|
-
sessionProviders = state?.providers ?? [];
|
|
617
|
-
}
|
|
618
|
-
catch {
|
|
619
|
-
// Session overlay state not available
|
|
620
|
-
}
|
|
621
|
-
return {
|
|
622
|
-
providers: getHeadlessAuthProviders(),
|
|
623
|
-
sessionProviders,
|
|
624
|
-
};
|
|
625
|
-
},
|
|
626
|
-
async login(input) {
|
|
627
|
-
return runHeadlessLogin(buildStructuredLoginArgs(input));
|
|
628
|
-
},
|
|
629
|
-
async logout(input) {
|
|
630
|
-
return runHeadlessLogout(buildStructuredLogoutArgs(input));
|
|
631
|
-
},
|
|
632
|
-
async clearSessionOverlay() {
|
|
633
|
-
const result = await ctx.localControl.clearSessionCredentialOverlay?.();
|
|
634
|
-
return { providers: result?.providers ?? [] };
|
|
635
|
-
},
|
|
636
|
-
async importEnvSessionOverlay(input) {
|
|
637
|
-
const ENV_VAR_MAP = {
|
|
638
|
-
anthropic: ["ANTHROPIC_API_KEY"],
|
|
639
|
-
openai: ["OPENAI_API_KEY"],
|
|
640
|
-
google: ["GOOGLE_API_KEY", "GEMINI_API_KEY"],
|
|
641
|
-
groq: ["GROQ_API_KEY"],
|
|
642
|
-
deepseek: ["DEEPSEEK_API_KEY"],
|
|
643
|
-
xai: ["XAI_API_KEY"],
|
|
644
|
-
mistral: ["MISTRAL_API_KEY"],
|
|
645
|
-
openrouter: ["OPENROUTER_API_KEY"],
|
|
646
|
-
};
|
|
647
|
-
const providers = Array.isArray(input?.providers) && input.providers.length > 0
|
|
648
|
-
? input.providers
|
|
649
|
-
.filter((value) => typeof value === "string" && value.trim().length > 0)
|
|
650
|
-
.map((value) => value.trim())
|
|
651
|
-
: Object.keys(ENV_VAR_MAP);
|
|
652
|
-
// Resolve env values in the CLIENT process (where env is available),
|
|
653
|
-
// then send explicit credentials to the daemon (whose env is sanitized).
|
|
654
|
-
const credentials = [];
|
|
655
|
-
for (const provider of providers) {
|
|
656
|
-
const normalized = provider.toLowerCase();
|
|
657
|
-
const envVars = ENV_VAR_MAP[normalized] ?? [
|
|
658
|
-
`${normalized.toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_API_KEY`,
|
|
659
|
-
];
|
|
660
|
-
for (const envVar of envVars) {
|
|
661
|
-
const value = process.env[envVar];
|
|
662
|
-
if (typeof value === "string" && value.trim().length > 8) {
|
|
663
|
-
credentials.push({
|
|
664
|
-
provider: normalized,
|
|
665
|
-
apiKey: value.trim(),
|
|
666
|
-
source: "env",
|
|
667
|
-
credentialType: "api_key",
|
|
668
|
-
});
|
|
669
|
-
break;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
const result = await ctx.localControl.setSessionCredentialOverlay?.({
|
|
674
|
-
credentials,
|
|
675
|
-
});
|
|
676
|
-
return { providers: result?.providers ?? [] };
|
|
677
|
-
},
|
|
678
|
-
};
|
|
679
|
-
})(),
|
|
680
|
-
modelDiscovery: {
|
|
681
|
-
async listAvailable() {
|
|
682
|
-
return availableModels;
|
|
683
|
-
},
|
|
684
|
-
async refresh(force) {
|
|
685
|
-
availableModels = await activeCli.refreshAvailableModels(force);
|
|
686
|
-
return availableModels;
|
|
687
|
-
},
|
|
688
|
-
async getCurrentModel() {
|
|
689
|
-
if (currentModelName) {
|
|
690
|
-
return currentModelName;
|
|
691
|
-
}
|
|
692
|
-
const currentArion = await arionManager.get(getCurrentArionName());
|
|
693
|
-
if (currentArion?.preferredModel) {
|
|
694
|
-
currentModelName = currentArion.preferredModel;
|
|
695
|
-
return currentModelName;
|
|
696
|
-
}
|
|
697
|
-
const preferredTier = loadConfig().preferredTier ?? activeCli.config.preferredTier;
|
|
698
|
-
if (!preferredTier) {
|
|
699
|
-
return availableModels[0]?.shortName;
|
|
700
|
-
}
|
|
701
|
-
currentModelName =
|
|
702
|
-
selectRunnableModelVariant(availableModels.find((candidate) => candidate.tier === preferredTier) ??
|
|
703
|
-
availableModels[0], activeCli.credentialHints)?.shortName ?? availableModels[0]?.shortName;
|
|
704
|
-
return currentModelName;
|
|
705
|
-
},
|
|
706
|
-
async setCurrentModel(model) {
|
|
707
|
-
const selectedModel = resolveModelFromCommandArg(model, availableModels, activeCli.credentialHints);
|
|
708
|
-
if (!selectedModel) {
|
|
709
|
-
throw new Error(`Unknown model: ${model}`);
|
|
710
|
-
}
|
|
711
|
-
currentModelName = selectedModel.shortName;
|
|
712
|
-
const configuredArionName = getCurrentArionName();
|
|
713
|
-
const configuredArion = await arionManager.get(configuredArionName);
|
|
714
|
-
if (configuredArion) {
|
|
715
|
-
await arionManager.setPreferredModel(configuredArionName, selectedModel.shortName);
|
|
716
|
-
}
|
|
717
|
-
const config = loadConfig();
|
|
718
|
-
config.preferredTier = selectedModel.tier;
|
|
719
|
-
saveConfig(config);
|
|
720
|
-
return {
|
|
721
|
-
currentModel: selectedModel.shortName,
|
|
722
|
-
tier: selectedModel.tier,
|
|
723
|
-
};
|
|
724
|
-
},
|
|
725
|
-
async getSessionModel() {
|
|
726
|
-
return currentModelName;
|
|
727
|
-
},
|
|
728
|
-
},
|
|
729
|
-
daemon: daemonService,
|
|
730
|
-
hook: hookService,
|
|
731
|
-
system: {
|
|
732
|
-
async restart(input) {
|
|
733
|
-
const reason = typeof input.reason === "string" && input.reason.trim().length > 0
|
|
734
|
-
? input.reason.trim()
|
|
735
|
-
: "Restart requested";
|
|
736
|
-
return {
|
|
737
|
-
accepted: true,
|
|
738
|
-
reason,
|
|
739
|
-
};
|
|
740
|
-
},
|
|
741
|
-
async terminalSetup() {
|
|
742
|
-
if (!isTerminalSetupSupported()) {
|
|
743
|
-
return {
|
|
744
|
-
supported: false,
|
|
745
|
-
message: "terminal-setup is supported only in iTerm2 (macOS) and VSCode terminal.",
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
return {
|
|
749
|
-
supported: true,
|
|
750
|
-
output: runTerminalSetup().trim(),
|
|
751
|
-
};
|
|
752
|
-
},
|
|
753
|
-
},
|
|
754
|
-
getSessionModel: getCurrentModelName,
|
|
755
|
-
getSessionArion: getCurrentArionName,
|
|
756
|
-
};
|
|
757
|
-
const initialConfiguredArion = await arionManager.get(getCurrentArionName());
|
|
758
|
-
if (initialConfiguredArion?.preferredModel) {
|
|
759
|
-
currentModelName = initialConfiguredArion.preferredModel;
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
const startupPreferredTier = loadConfig().preferredTier ?? activeCli.config.preferredTier;
|
|
763
|
-
currentModelName =
|
|
764
|
-
selectRunnableModelVariant(availableModels.find((candidate) => candidate.tier === startupPreferredTier) ??
|
|
765
|
-
availableModels[0], activeCli.credentialHints)?.shortName ?? availableModels[0]?.shortName;
|
|
766
|
-
}
|
|
767
|
-
return {
|
|
768
|
-
kernel: new HeadlessKernel(ctx),
|
|
769
|
-
ctx,
|
|
770
|
-
async release() {
|
|
771
|
-
await releaseResources();
|
|
772
|
-
},
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
catch (error) {
|
|
776
|
-
try {
|
|
777
|
-
await releaseResources();
|
|
778
|
-
}
|
|
779
|
-
catch (releaseError) {
|
|
780
|
-
throw new AggregateError([error, releaseError], "Headless kernel bootstrap failed and resource cleanup also failed");
|
|
781
|
-
}
|
|
782
|
-
throw error;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
//# sourceMappingURL=kernel.js.map
|