illusion-code 0.1.0__py3-none-any.whl
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.
- illusion/__init__.py +24 -0
- illusion/__main__.py +15 -0
- illusion/_frontend/dist/index.mjs +39208 -0
- illusion/_frontend/package.json +27 -0
- illusion/_frontend/src/App.tsx +624 -0
- illusion/_frontend/src/components/CommandPicker.tsx +98 -0
- illusion/_frontend/src/components/Composer.tsx +55 -0
- illusion/_frontend/src/components/ComposerController.tsx +128 -0
- illusion/_frontend/src/components/ConversationView.tsx +750 -0
- illusion/_frontend/src/components/Footer.tsx +25 -0
- illusion/_frontend/src/components/MarkdownContent.tsx +537 -0
- illusion/_frontend/src/components/MarkdownTable.tsx +245 -0
- illusion/_frontend/src/components/ModalHost.tsx +425 -0
- illusion/_frontend/src/components/MultilineTextInput.tsx +250 -0
- illusion/_frontend/src/components/PromptInput.tsx +64 -0
- illusion/_frontend/src/components/SelectModal.tsx +78 -0
- illusion/_frontend/src/components/SidePanel.tsx +175 -0
- illusion/_frontend/src/components/Spinner.tsx +77 -0
- illusion/_frontend/src/components/StatusBar.tsx +142 -0
- illusion/_frontend/src/components/SwarmPanel.tsx +141 -0
- illusion/_frontend/src/components/TodoPanel.tsx +126 -0
- illusion/_frontend/src/components/ToolCallDisplay.tsx +202 -0
- illusion/_frontend/src/components/TranscriptPane.tsx +79 -0
- illusion/_frontend/src/components/WelcomeBanner.tsx +37 -0
- illusion/_frontend/src/hooks/useBackendSession.ts +468 -0
- illusion/_frontend/src/hooks/useTerminalSize.ts +9 -0
- illusion/_frontend/src/i18n.ts +78 -0
- illusion/_frontend/src/index.tsx +42 -0
- illusion/_frontend/src/theme/ThemeContext.tsx +19 -0
- illusion/_frontend/src/theme/builtinThemes.ts +89 -0
- illusion/_frontend/src/types.ts +110 -0
- illusion/_frontend/src/utils/markdown.ts +33 -0
- illusion/_frontend/src/utils/thinking.ts +191 -0
- illusion/_frontend/tsconfig.json +13 -0
- illusion/_web_dist/assets/index-BseIw-ik.css +10 -0
- illusion/_web_dist/assets/index-C_0ZWMuW.js +82 -0
- illusion/_web_dist/index.html +16 -0
- illusion/api/__init__.py +36 -0
- illusion/api/client.py +568 -0
- illusion/api/codex_client.py +563 -0
- illusion/api/compat.py +138 -0
- illusion/api/effort.py +128 -0
- illusion/api/errors.py +57 -0
- illusion/api/openai_client.py +819 -0
- illusion/api/provider.py +148 -0
- illusion/api/registry.py +479 -0
- illusion/api/usage.py +45 -0
- illusion/auth/__init__.py +50 -0
- illusion/auth/copilot.py +419 -0
- illusion/auth/external.py +612 -0
- illusion/auth/flows.py +58 -0
- illusion/auth/manager.py +214 -0
- illusion/auth/storage.py +372 -0
- illusion/bridge/__init__.py +38 -0
- illusion/bridge/manager.py +190 -0
- illusion/bridge/session_runner.py +84 -0
- illusion/bridge/types.py +113 -0
- illusion/bridge/work_secret.py +131 -0
- illusion/cli.py +1228 -0
- illusion/commands/__init__.py +32 -0
- illusion/commands/registry.py +1934 -0
- illusion/config/__init__.py +39 -0
- illusion/config/i18n.py +522 -0
- illusion/config/paths.py +259 -0
- illusion/config/settings.py +564 -0
- illusion/coordinator/__init__.py +41 -0
- illusion/coordinator/agent_definitions.py +1093 -0
- illusion/coordinator/coordinator_mode.py +127 -0
- illusion/engine/__init__.py +95 -0
- illusion/engine/cost_tracker.py +55 -0
- illusion/engine/messages.py +369 -0
- illusion/engine/query.py +632 -0
- illusion/engine/query_engine.py +343 -0
- illusion/engine/stream_events.py +169 -0
- illusion/hooks/__init__.py +67 -0
- illusion/hooks/events.py +43 -0
- illusion/hooks/executor.py +397 -0
- illusion/hooks/hot_reload.py +74 -0
- illusion/hooks/loader.py +133 -0
- illusion/hooks/schemas.py +121 -0
- illusion/hooks/types.py +86 -0
- illusion/mcp/__init__.py +104 -0
- illusion/mcp/client.py +377 -0
- illusion/mcp/config.py +140 -0
- illusion/mcp/types.py +175 -0
- illusion/memory/__init__.py +36 -0
- illusion/memory/manager.py +94 -0
- illusion/memory/memdir.py +58 -0
- illusion/memory/paths.py +57 -0
- illusion/memory/scan.py +120 -0
- illusion/memory/search.py +83 -0
- illusion/memory/types.py +43 -0
- illusion/output_styles/__init__.py +15 -0
- illusion/output_styles/loader.py +64 -0
- illusion/permissions/__init__.py +39 -0
- illusion/permissions/checker.py +174 -0
- illusion/permissions/modes.py +38 -0
- illusion/platforms.py +148 -0
- illusion/plugins/__init__.py +71 -0
- illusion/plugins/bundled/__init__.py +0 -0
- illusion/plugins/installer.py +59 -0
- illusion/plugins/loader.py +301 -0
- illusion/plugins/schemas.py +51 -0
- illusion/plugins/types.py +56 -0
- illusion/prompts/__init__.py +29 -0
- illusion/prompts/claudemd.py +74 -0
- illusion/prompts/context.py +187 -0
- illusion/prompts/environment.py +189 -0
- illusion/prompts/system_prompt.py +155 -0
- illusion/py.typed +0 -0
- illusion/sandbox/__init__.py +29 -0
- illusion/sandbox/adapter.py +174 -0
- illusion/services/__init__.py +59 -0
- illusion/services/compact/__init__.py +1015 -0
- illusion/services/cron.py +338 -0
- illusion/services/cron_scheduler.py +715 -0
- illusion/services/file_history.py +258 -0
- illusion/services/lsp/__init__.py +455 -0
- illusion/services/session_storage.py +237 -0
- illusion/services/token_estimation.py +72 -0
- illusion/skills/__init__.py +60 -0
- illusion/skills/bundled/__init__.py +110 -0
- illusion/skills/bundled/content/batch.md +86 -0
- illusion/skills/bundled/content/coding-guidelines.md +70 -0
- illusion/skills/bundled/content/debug.md +38 -0
- illusion/skills/bundled/content/loop.md +82 -0
- illusion/skills/bundled/content/remember.md +105 -0
- illusion/skills/bundled/content/simplify.md +53 -0
- illusion/skills/bundled/content/skillify.md +113 -0
- illusion/skills/bundled/content/stuck.md +54 -0
- illusion/skills/bundled/content/update-config.md +329 -0
- illusion/skills/bundled/content/verify.md +74 -0
- illusion/skills/loader.py +219 -0
- illusion/skills/registry.py +40 -0
- illusion/skills/types.py +24 -0
- illusion/state/__init__.py +18 -0
- illusion/state/app_state.py +67 -0
- illusion/state/store.py +93 -0
- illusion/swarm/__init__.py +71 -0
- illusion/swarm/agent_executor.py +857 -0
- illusion/swarm/in_process.py +259 -0
- illusion/swarm/subprocess_backend.py +136 -0
- illusion/swarm/team_helpers.py +123 -0
- illusion/swarm/types.py +159 -0
- illusion/swarm/worktree.py +347 -0
- illusion/tasks/__init__.py +33 -0
- illusion/tasks/local_agent_task.py +42 -0
- illusion/tasks/local_shell_task.py +27 -0
- illusion/tasks/manager.py +377 -0
- illusion/tasks/stop_task.py +21 -0
- illusion/tasks/types.py +88 -0
- illusion/tools/__init__.py +126 -0
- illusion/tools/agent_tool.py +388 -0
- illusion/tools/ask_user_question_tool.py +186 -0
- illusion/tools/base.py +149 -0
- illusion/tools/bash_tool.py +413 -0
- illusion/tools/config_tool.py +90 -0
- illusion/tools/cron_tool.py +473 -0
- illusion/tools/enter_plan_mode_tool.py +147 -0
- illusion/tools/enter_worktree_tool.py +188 -0
- illusion/tools/exit_plan_mode_tool.py +69 -0
- illusion/tools/exit_worktree_tool.py +225 -0
- illusion/tools/file_edit_tool.py +283 -0
- illusion/tools/file_read_tool.py +294 -0
- illusion/tools/file_write_tool.py +184 -0
- illusion/tools/glob_tool.py +165 -0
- illusion/tools/grep_tool.py +190 -0
- illusion/tools/list_mcp_resources_tool.py +80 -0
- illusion/tools/lsp_tool.py +333 -0
- illusion/tools/mcp_auth_tool.py +100 -0
- illusion/tools/mcp_tool.py +75 -0
- illusion/tools/notebook_edit_tool.py +242 -0
- illusion/tools/powershell_tool.py +334 -0
- illusion/tools/read_mcp_resource_tool.py +63 -0
- illusion/tools/repl_tool.py +100 -0
- illusion/tools/send_message_tool.py +112 -0
- illusion/tools/shell_common.py +187 -0
- illusion/tools/skill_tool.py +86 -0
- illusion/tools/sleep_tool.py +62 -0
- illusion/tools/structured_output_tool.py +58 -0
- illusion/tools/task_create_tool.py +98 -0
- illusion/tools/task_get_tool.py +94 -0
- illusion/tools/task_list_tool.py +94 -0
- illusion/tools/task_output_tool.py +55 -0
- illusion/tools/task_stop_tool.py +52 -0
- illusion/tools/task_update_tool.py +224 -0
- illusion/tools/team_create_tool.py +236 -0
- illusion/tools/team_delete_tool.py +104 -0
- illusion/tools/todo_write_tool.py +198 -0
- illusion/tools/tool_search_tool.py +156 -0
- illusion/tools/web_fetch_tool.py +264 -0
- illusion/tools/web_search_tool.py +186 -0
- illusion/ui/__init__.py +23 -0
- illusion/ui/app.py +258 -0
- illusion/ui/backend_host.py +1180 -0
- illusion/ui/input.py +86 -0
- illusion/ui/output.py +363 -0
- illusion/ui/permission_dialog.py +47 -0
- illusion/ui/permission_store.py +99 -0
- illusion/ui/protocol.py +384 -0
- illusion/ui/react_launcher.py +280 -0
- illusion/ui/runtime.py +787 -0
- illusion/ui/textual_app.py +603 -0
- illusion/ui/web/__init__.py +10 -0
- illusion/ui/web/server.py +87 -0
- illusion/ui/web/ws_host.py +1197 -0
- illusion/utils/__init__.py +0 -0
- illusion/utils/ripgrep.py +299 -0
- illusion/utils/shell.py +248 -0
- illusion_code-0.1.0.dist-info/METADATA +1159 -0
- illusion_code-0.1.0.dist-info/RECORD +214 -0
- illusion_code-0.1.0.dist-info/WHEEL +4 -0
- illusion_code-0.1.0.dist-info/entry_points.txt +2 -0
- illusion_code-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""
|
|
2
|
+
沙箱运行时适配器模块
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
本模块实现围绕 srt(sandbox-runtime)CLI 的适配器,提供沙箱执行功能。
|
|
6
|
+
|
|
7
|
+
主要功能:
|
|
8
|
+
- 检查沙箱可用性
|
|
9
|
+
- 构建沙箱运行时配置
|
|
10
|
+
- 包装命令用于沙箱执行
|
|
11
|
+
|
|
12
|
+
类说明:
|
|
13
|
+
- SandboxUnavailableError: 当需要沙箱执行但不可用时抛出
|
|
14
|
+
- SandboxAvailability: 当前环境的沙箱运行时可用性
|
|
15
|
+
- build_sandbox_runtime_config: 构建 srt 设置 payload
|
|
16
|
+
- get_sandbox_availability: 获取沙箱可用性状态
|
|
17
|
+
- wrap_command_for_sandbox: 包装命令用于沙箱执行
|
|
18
|
+
|
|
19
|
+
使用示例:
|
|
20
|
+
>>> from illusion.sandbox import get_sandbox_availability, wrap_command_for_sandbox
|
|
21
|
+
>>> # 检查沙箱可用性
|
|
22
|
+
>>> availability = get_sandbox_availability()
|
|
23
|
+
>>> print(availability.active) # 是否启用沙箱
|
|
24
|
+
>>> # 包装命令
|
|
25
|
+
>>> wrapped_cmd, settings_path = wrap_command_for_sandbox(["ls", "-la"])
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import json
|
|
31
|
+
import shlex
|
|
32
|
+
import shutil
|
|
33
|
+
import tempfile
|
|
34
|
+
from dataclasses import dataclass
|
|
35
|
+
from pathlib import Path
|
|
36
|
+
from typing import Any
|
|
37
|
+
|
|
38
|
+
from illusion.config import Settings, load_settings
|
|
39
|
+
from illusion.platforms import get_platform, get_platform_capabilities
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class SandboxUnavailableError(RuntimeError):
|
|
43
|
+
"""当需要沙箱执行但不可用时抛出。"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class SandboxAvailability:
|
|
48
|
+
"""当前环境的沙箱运行时可用性计算结果。"""
|
|
49
|
+
|
|
50
|
+
enabled: bool
|
|
51
|
+
available: bool
|
|
52
|
+
reason: str | None = None
|
|
53
|
+
command: str | None = None
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def active(self) -> bool:
|
|
57
|
+
"""返回是否应该对子进程应用沙箱。"""
|
|
58
|
+
return self.enabled and self.available
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def build_sandbox_runtime_config(settings: Settings) -> dict[str, Any]:
|
|
62
|
+
"""将 IllusionCode 设置转换为 srt 设置 payload。"""
|
|
63
|
+
return {
|
|
64
|
+
"network": {
|
|
65
|
+
"allowedDomains": list(settings.sandbox.network.allowed_domains),
|
|
66
|
+
"deniedDomains": list(settings.sandbox.network.denied_domains),
|
|
67
|
+
},
|
|
68
|
+
"filesystem": {
|
|
69
|
+
"allowRead": list(settings.sandbox.filesystem.allow_read),
|
|
70
|
+
"denyRead": list(settings.sandbox.filesystem.deny_read),
|
|
71
|
+
"allowWrite": list(settings.sandbox.filesystem.allow_write),
|
|
72
|
+
"denyWrite": list(settings.sandbox.filesystem.deny_write),
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_sandbox_availability(settings: Settings | None = None) -> SandboxAvailability:
|
|
78
|
+
"""返回 srt 是否可用于当前运行时。"""
|
|
79
|
+
resolved_settings = settings or load_settings()
|
|
80
|
+
if not resolved_settings.sandbox.enabled:
|
|
81
|
+
return SandboxAvailability(enabled=False, available=False, reason="sandbox is disabled")
|
|
82
|
+
|
|
83
|
+
platform_name = get_platform()
|
|
84
|
+
capabilities = get_platform_capabilities(platform_name)
|
|
85
|
+
if not capabilities.supports_sandbox_runtime:
|
|
86
|
+
if platform_name == "windows":
|
|
87
|
+
reason = "sandbox runtime is not supported on native Windows; use WSL for sandboxed execution"
|
|
88
|
+
else:
|
|
89
|
+
reason = f"sandbox runtime is not supported on platform {platform_name}"
|
|
90
|
+
return SandboxAvailability(enabled=True, available=False, reason=reason)
|
|
91
|
+
|
|
92
|
+
enabled_platforms = {name.lower() for name in resolved_settings.sandbox.enabled_platforms}
|
|
93
|
+
if enabled_platforms and platform_name not in enabled_platforms:
|
|
94
|
+
return SandboxAvailability(
|
|
95
|
+
enabled=True,
|
|
96
|
+
available=False,
|
|
97
|
+
reason=f"sandbox is disabled for platform {platform_name} by configuration",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# 检查 srt CLI 是否存在
|
|
101
|
+
srt = shutil.which("srt")
|
|
102
|
+
if not srt:
|
|
103
|
+
return SandboxAvailability(
|
|
104
|
+
enabled=True,
|
|
105
|
+
available=False,
|
|
106
|
+
reason=(
|
|
107
|
+
"sandbox runtime CLI not found; install it with "
|
|
108
|
+
"`npm install -g @anthropic-ai/sandbox-runtime`"
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# 检查 Linux/WSL 需要的 bwrap
|
|
113
|
+
if platform_name in {"linux", "wsl"} and shutil.which("bwrap") is None:
|
|
114
|
+
return SandboxAvailability(
|
|
115
|
+
enabled=True,
|
|
116
|
+
available=False,
|
|
117
|
+
reason="bubblewrap (`bwrap`) is required for sandbox runtime on Linux/WSL",
|
|
118
|
+
command=srt,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# 检查 macOS 需要的 sandbox-exec
|
|
122
|
+
if platform_name == "macos" and shutil.which("sandbox-exec") is None:
|
|
123
|
+
return SandboxAvailability(
|
|
124
|
+
enabled=True,
|
|
125
|
+
available=False,
|
|
126
|
+
reason="`sandbox-exec` is required for sandbox runtime on macOS",
|
|
127
|
+
command=srt,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
return SandboxAvailability(enabled=True, available=True, command=srt)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def wrap_command_for_sandbox(
|
|
134
|
+
command: list[str],
|
|
135
|
+
*,
|
|
136
|
+
settings: Settings | None = None,
|
|
137
|
+
) -> tuple[list[str], Path | None]:
|
|
138
|
+
"""当沙箱激活时用 srt 包装 argv 列表。"""
|
|
139
|
+
resolved_settings = settings or load_settings()
|
|
140
|
+
availability = get_sandbox_availability(resolved_settings)
|
|
141
|
+
if not availability.active:
|
|
142
|
+
if resolved_settings.sandbox.enabled and resolved_settings.sandbox.fail_if_unavailable:
|
|
143
|
+
raise SandboxUnavailableError(availability.reason or "sandbox runtime is unavailable")
|
|
144
|
+
return command, None
|
|
145
|
+
|
|
146
|
+
# 写入运行时设置到临时文件
|
|
147
|
+
settings_path = _write_runtime_settings(build_sandbox_runtime_config(resolved_settings))
|
|
148
|
+
# srt argv 形式不能可靠地保留 shell 风格命令(如 bash -lc 'exit 1')的子进程退出码
|
|
149
|
+
# 构建单个转义命令字符串并通过 -c 传递,以便钩子/工具失败仍能正确传播
|
|
150
|
+
wrapped = [
|
|
151
|
+
availability.command or "srt",
|
|
152
|
+
"--settings",
|
|
153
|
+
str(settings_path),
|
|
154
|
+
"-c",
|
|
155
|
+
shlex.join(command),
|
|
156
|
+
]
|
|
157
|
+
return wrapped, settings_path
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _write_runtime_settings(payload: dict[str, Any]) -> Path:
|
|
161
|
+
"""为一个沙箱子进程持久化临时设置文件。"""
|
|
162
|
+
tmp = tempfile.NamedTemporaryFile(
|
|
163
|
+
mode="w",
|
|
164
|
+
encoding="utf-8",
|
|
165
|
+
prefix="illusion-sandbox-",
|
|
166
|
+
suffix=".json",
|
|
167
|
+
delete=False,
|
|
168
|
+
)
|
|
169
|
+
try:
|
|
170
|
+
json.dump(payload, tmp)
|
|
171
|
+
tmp.write("\n")
|
|
172
|
+
finally:
|
|
173
|
+
tmp.close()
|
|
174
|
+
return Path(tmp.name)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
服务模块导出
|
|
3
|
+
==========
|
|
4
|
+
|
|
5
|
+
本模块导出 services 子目录中的公共接口。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from illusion.services.compact import (
|
|
11
|
+
AutoCompactState,
|
|
12
|
+
TokenWarningState,
|
|
13
|
+
compact_conversation,
|
|
14
|
+
compact_messages,
|
|
15
|
+
create_compact_boundary_marker,
|
|
16
|
+
estimate_conversation_tokens,
|
|
17
|
+
get_autocompact_threshold,
|
|
18
|
+
get_context_window,
|
|
19
|
+
get_messages_after_compact_boundary,
|
|
20
|
+
is_compact_boundary_marker,
|
|
21
|
+
microcompact_messages,
|
|
22
|
+
reactive_compact,
|
|
23
|
+
should_autocompact,
|
|
24
|
+
strip_images_from_messages,
|
|
25
|
+
summarize_messages,
|
|
26
|
+
calculate_token_warning_state,
|
|
27
|
+
)
|
|
28
|
+
from illusion.services.session_storage import (
|
|
29
|
+
export_session_markdown,
|
|
30
|
+
get_project_session_dir,
|
|
31
|
+
load_session_snapshot,
|
|
32
|
+
save_session_snapshot,
|
|
33
|
+
)
|
|
34
|
+
from illusion.services.token_estimation import estimate_message_tokens, estimate_tokens
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"AutoCompactState",
|
|
38
|
+
"TokenWarningState",
|
|
39
|
+
"calculate_token_warning_state",
|
|
40
|
+
"compact_conversation",
|
|
41
|
+
"compact_messages",
|
|
42
|
+
"create_compact_boundary_marker",
|
|
43
|
+
"estimate_conversation_tokens",
|
|
44
|
+
"estimate_message_tokens",
|
|
45
|
+
"estimate_tokens",
|
|
46
|
+
"export_session_markdown",
|
|
47
|
+
"get_autocompact_threshold",
|
|
48
|
+
"get_context_window",
|
|
49
|
+
"get_messages_after_compact_boundary",
|
|
50
|
+
"get_project_session_dir",
|
|
51
|
+
"is_compact_boundary_marker",
|
|
52
|
+
"load_session_snapshot",
|
|
53
|
+
"microcompact_messages",
|
|
54
|
+
"reactive_compact",
|
|
55
|
+
"save_session_snapshot",
|
|
56
|
+
"should_autocompact",
|
|
57
|
+
"strip_images_from_messages",
|
|
58
|
+
"summarize_messages",
|
|
59
|
+
]
|