agent-workspace-desktop 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.
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-workspace-desktop
3
+ Version: 0.1.0
4
+ Summary: 桌面 Agent 工作区内核:一个目录约定、一条 dispatch、一条事件流、一份能力面
5
+ Author: Agent Workspace contributors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/YY-Yifei/agent-workspace
8
+ Project-URL: Source, https://github.com/YY-Yifei/agent-workspace
9
+ Project-URL: Issues, https://github.com/YY-Yifei/agent-workspace/issues
10
+ Keywords: agent,aaas,desktop,pywebview,workspace,plugins
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Win32 (MS Windows)
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: Microsoft :: Windows
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: User Interfaces
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: aaas>=0.3.0
24
+ Provides-Extra: gui
25
+ Requires-Dist: pywebview>=5.0; extra == "gui"
26
+ Dynamic: license-file
27
+
28
+ # Agent Workspace
29
+
30
+ 桌面上的 **Agent 工作区**:用户攒程序(番茄钟、心情日记、记账…),每个程序都有自己的助手;
31
+ 智能全在远端 `aaas-service`,本进程只做四件事 —— **落盘、执行被点名的那一个、广播、传话**。
32
+
33
+ > **内核不含一克智能。** 它不选工具、不决定下一步、不重试、不兜底。
34
+ > 判据:本仓库里出现的每个分支,都只回答「参数/状态是否合法」,不回答「接下来做什么」。
35
+
36
+ ## 谱系
37
+
38
+ ```
39
+ 道 = Agent(aaas-service,唯一的智能,不在本进程)
40
+ 一 = 内核(本仓库 agentworkspace/:一个目录约定、一条 dispatch、一条事件流、一份能力面)
41
+ 二 = 双入口(人走本地 HTTP,agent 走 invokeFunction,落到同一个 dispatch)
42
+ 三 = 程序三要素(backend.py 能力 / ui 页面 / data 状态)
43
+ 万物 = 工作区(用户攒出来的程序)
44
+ ```
45
+
46
+ 七个模块,各管一件事:
47
+
48
+ | 文件 | 它是谁 |
49
+ |---|---|
50
+ | `kernel.py` | **一**:目录约定 / 唯一 `dispatch()` / 事件总线 / 能力面(按 pid 隔离) |
51
+ | `link.py` | **道**:aaas 接线(connect / declare / send / 转发被点名的那一个),每个程序一条会话 |
52
+ | `server.py` | **二之一**:人的门(本地 HTTP + SSE) |
53
+ | `shell.py` | 窗口壳:pywebview(`--browser` 是它的退化形态) |
54
+ | `native.py` | 原生程序宿主:不是第二条执行路径,是「人的门」的第三种壳 |
55
+ | `main.py` | 入口:装配,没有第四样东西 |
56
+ | `web/index.html` | 工作区视图 + 对话 + 能力面板(单文件,无构建步骤) |
57
+
58
+ 配套:`settings.py`(唯一一项设置:aaas-service 地址)、`devtools.py`(开发者模式那双手)、
59
+ `assistant.py`(内核唯一内置的程序:小助理)、`toolbox.py`(小助理的手)、
60
+ `selftest.py` / `qa.py` / `uiprobe.py`(三层的自检:逻辑 / 真窗口 / 真浏览器)。
61
+
62
+ ## 装
63
+
64
+ ```bash
65
+ pip install agent-workspace-desktop # 内核 + aaas 客户端
66
+ pip install "agent-workspace-desktop[gui]" # 再带上桌面窗口(pywebview)
67
+ ```
68
+
69
+ 需要 Python 3.10+,以及一个能连上的 `aaas-service`(地址在设置里改,默认 `ws://localhost:8888`)。
70
+
71
+ ## 跑
72
+
73
+ ```bash
74
+ agent-workspace # 桌面窗口
75
+ agent-workspace --browser # 换成浏览器(pywebview 起不来时的形态)
76
+ agent-workspace --cli # 命令行:跟小助理说一句
77
+ agent-workspace --cli -m "做个番茄钟" # 同上
78
+ agent-workspace --cli --as pomodoro -m "开始 25 分钟" # 跟某个程序自己的助手说
79
+ ```
80
+
81
+ `--cli` 是验收形态:`connect → declare → sendInput → invokeFunction → 本地执行 →
82
+ functionResult → 模型续写 → turn.completed`。这条不通,界面做得再漂亮也是空壳。
83
+
84
+ ## 工作区长什么样
85
+
86
+ 工作区(默认 `./workspace`,可用 `--workspace` 换)是**运行时**,不在本仓库里:
87
+
88
+ ```
89
+ workspace/
90
+ plugins/<pid>/ 程序:plugin.json + backend.py + ui/index.html + data/store.json
91
+ logs/events.jsonl 谁做了什么、谁点的(事件流)
92
+ prompts/ 每个程序的指令
93
+ config.json 设置(只有一项:aaas-service 地址)
94
+ dev.json 开发者模式开关(**只属于人**:程序写它一律被拒)
95
+ ```
96
+
97
+ 内核**没有任何内置的领域能力**:番茄钟、日记、记账都是工作区里长出来的程序,
98
+ 所以它们**不在这个仓库里** —— 这里只有内核。
99
+
100
+ ## 契约(写程序的人关心这几条)
101
+
102
+ 1. 公开函数 = 能力;`_` 前缀 = 私有;wire name = `<pid>_<fn>`
103
+ 2. 约束只写一处:`Annotated[int, {"minimum": 1}]` → schema / 表单 / 校验同源
104
+ 3. 双面返回:dict 含 `"text"` → 文本给模型,其余进 `data` 给界面
105
+ 4. 状态走 `ctx.get/set` → `data/store.json`(代码目录与数据目录分离)
106
+ 5. 事件总线:`call.ok` / `call.error` / `call.rejected` / `state.changed`
107
+
108
+ 隔离只写一处:`Runtime.capabilities_of(pid)`。别的程序在结构上就**拿不到** `plugin_write`。
109
+
110
+ ## 开发者模式
111
+
112
+ 一个开关(设置面板里拨),打开后当前程序多拿到一把**只够改自己**的手:
113
+
114
+ | 有 | 没有 |
115
+ |---|---|
116
+ | `dev_tree` / `dev_read` / `dev_search` | `plugin_list`(「有哪些程序」本身就是权限地图) |
117
+ | `dev_write`(普通文件) | `plugin_call`(能绕开别人的隔离) |
118
+ | `dev_plugin_write`(**没有 pid 参数**) | `plugin_delete` / `shell` |
119
+
120
+ 想改别人,在**签名**上就无从下手;`dev.json` 由人掌握,程序写它一律被拒。
121
+ 细节见 [`docs/dev-mode.md`](docs/dev-mode.md)。
122
+
123
+ ## 自检
124
+
125
+ ```bash
126
+ python -m agentworkspace.selftest # 逻辑层(内存里跑完整链路)
127
+ python -m agentworkspace.qa all # 真窗口
128
+ python -m agentworkspace.uiprobe # 真浏览器(拖动 / 折叠 / 设置 / 图标)
129
+ ```
130
+
131
+ 三层缺一不可:`selftest` 只能断言「文件里有这行字」,CSS 优先级、事件绑定、
132
+ 重绘时机任何一处错了都拦不住 —— 那要靠后两层。
133
+
134
+ ## 文档
135
+
136
+ - [`docs/vision.md`](docs/vision.md) —— 道 / 一 / 二 / 三 / 万物
137
+ - [`docs/desktop-workspace-plan.md`](docs/desktop-workspace-plan.md) —— 方案与三层分界
138
+ - [`docs/plugin-mechanism.md`](docs/plugin-mechanism.md) —— 程序三要素与契约五条
139
+ - [`docs/agent-per-program.md`](docs/agent-per-program.md) —— 每个程序一个智能体
140
+ - [`docs/dev-mode.md`](docs/dev-mode.md) —— 开发者模式的边界
141
+ - [`docs/settings-and-icon.md`](docs/settings-and-icon.md) —— 设置与窗口图标
142
+ - [`docs/shell-and-native.md`](docs/shell-and-native.md) —— 窗口壳与原生程序
143
+
144
+ ## License
145
+
146
+ MIT
@@ -0,0 +1,25 @@
1
+ agent_workspace_desktop-0.1.0.dist-info/licenses/LICENSE,sha256=roFqbdyHzs9W65X9Mv26GzwEYhwEA5pxmTMMg_FuPjU,1106
2
+ agentworkspace/__init__.py,sha256=rHtyAuthztBom-v2olGbrq70wdUqAKLwMMNnsy3KfZE,444
3
+ agentworkspace/assistant.py,sha256=AucbhpHds_jiyi8W_UDkadFJIwcaoV4R53Yb6LKilDA,1337
4
+ agentworkspace/devtools.py,sha256=RXPjhX4qBOj3cJz4vsXcCq9UDfb2FPkmk3jMs_cf4Rk,5206
5
+ agentworkspace/kernel.py,sha256=4bvDkC6mHwYZHxyHhL0NdGNZQ-LaogMWL1_hL6PKDwI,38147
6
+ agentworkspace/link.py,sha256=fytdamBGiOI089l9R2vzbvyQjNgxg3Nd2QVTPMl-0qw,27062
7
+ agentworkspace/main.py,sha256=PKLjRHeJGoPPqEqJAe-0K3RmwOaSnSI2Ho7GpjHoIRA,11926
8
+ agentworkspace/native.py,sha256=mtr9wI-tKfh4-s29GIdkc8Cf9_K_p-VY5FOJdfwjVlY,6740
9
+ agentworkspace/qa.py,sha256=khTxn4wdlN2JbkbxP4Mw738Ugtp5wxSVEzEhZbR0e_E,24248
10
+ agentworkspace/sdk.py,sha256=dHOz-57WHNmjJ_l4ovi1nlo2RDSIvSEM2D2sphje5ts,6307
11
+ agentworkspace/selftest.py,sha256=Wf9QBLLBo1SvSGKPLQ2XN8riakMq-jEOdAJT0Xj3MQQ,30948
12
+ agentworkspace/server.py,sha256=A520dbtUpCr2Shgib9-BNaDpK2w8GHPScEIGF6Hf3wI,13748
13
+ agentworkspace/settings.py,sha256=iPhxgCGz7rPskF0-N-9QMVZ3MoVA1bWEo-BgA6mGylw,4534
14
+ agentworkspace/shell.py,sha256=ynDn4OtAoD5lx0LxzOnWrZr5GXT6eTtNFVnf9nR8-xQ,5428
15
+ agentworkspace/toolbox.py,sha256=Im-LNyiiUMZKR3kQmhzPAquDrLO3sJN3uNgTNg75k-Y,21148
16
+ agentworkspace/uiprobe.py,sha256=WcrSQYGhj64BdlPZuYqbWhej1bg-Ls_hnxTszP90Z8A,17285
17
+ agentworkspace/winicon.py,sha256=T_NxjGEtDL8zuRRpKz8nXJLqsOOZyERYFrs299MFfhc,12234
18
+ agentworkspace/assets/icon.ico,sha256=0CUGLiaQvZxhEOe1wFukmm9RtncRkQihhL08N8OtMD0,41197
19
+ agentworkspace/assets/make_icon.py,sha256=wIBl21REaPijX8r1XEP5fGzhcTi0cUbh4WFWowcnOnc,8883
20
+ agentworkspace/web/index.html,sha256=Bjj68vaYrwjPySww_Yjmji4RY7nvF0ZDCcYzn7SHV9M,33099
21
+ agent_workspace_desktop-0.1.0.dist-info/METADATA,sha256=QN0vfKUOpRrFfBjEyvHwe9ZvuJR3-N8r2sZG-pCXFZ0,7098
22
+ agent_workspace_desktop-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
23
+ agent_workspace_desktop-0.1.0.dist-info/entry_points.txt,sha256=6MtElXPVQ8nZmCFNyTnGGAxQH3OZr8QuWH_UnDfwE3Q,61
24
+ agent_workspace_desktop-0.1.0.dist-info/top_level.txt,sha256=mdWtaOQOhm9S9aF_Qy8zGHKmiKoYvXxS6FW2fW_xfVM,15
25
+ agent_workspace_desktop-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ agent-workspace = agentworkspace.main:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agent Workspace contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ agentworkspace
@@ -0,0 +1,8 @@
1
+ """Agent Workspace —— 道 = Agent(aaas-service),一 = 内核(本包)。
2
+
3
+ 只有四样东西:
4
+ kernel.py 一:目录约定 / 唯一 dispatch / 事件流 / 能力面(不含一克智能)
5
+ link.py 道:aaas 接线(connect / declare / send / 转发被点名的那一个)
6
+ server.py 二之一:人的门(本地 HTTP + SSE)
7
+ web/ 前端:工作区视图 + 对话 + 自动能力面板
8
+ """
Binary file
@@ -0,0 +1,215 @@
1
+ """窗口图标 —— **自己画的那一个**,不是 python.exe 的标。
2
+
3
+ 为什么要有它:pywebview 在 Windows 上会把 ``Form.Icon`` 设成从 ``sys.executable``
4
+ 里抠出来的图标(见 ``webview/platforms/winforms.py``),于是窗口左上角、任务栏、
5
+ Alt-Tab 全是 Python 的蛇。一个产品不该顶着解释器的标。
6
+
7
+ 这个文件只用标准库(zlib + struct)画图并打包成 ICO:
8
+
9
+ 16/24/32/48/64 32 位 BMP(DIB)条目 —— 老外壳与新窗口管理器都认
10
+ 128/256 PNG 条目(Vista 起支持,体积小得多)
11
+
12
+ 图形语言和界面一致:左边一条亮色的「栏」,右边两张「卡」——
13
+ 就是这个窗口自己的样子(左窄栏 + 舞台),缩到 16px 也还认得出来。
14
+
15
+ 用法::
16
+
17
+ python -m agentworkspace.assets.make_icon # 写 agentworkspace/assets/icon.ico
18
+ python -m agentworkspace.assets.make_icon --preview .tmp/i.png # 额外出一张放大对照图
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import argparse
24
+ import math
25
+ import struct
26
+ import zlib
27
+ from pathlib import Path
28
+
29
+ DEFAULT_OUT = Path(__file__).resolve().parent / "icon.ico"
30
+
31
+ # 尺寸表:<=64 用 DIB,更大的用 PNG
32
+ DIB_SIZES = (16, 24, 32, 48, 64)
33
+ PNG_SIZES = (128, 256)
34
+ SIZES = DIB_SIZES + PNG_SIZES
35
+
36
+ TOP = (0x74, 0xB0, 0xFF) # 渐变上端(偏亮的强调色)
37
+ BOTTOM = (0x2F, 0x6F, 0xE0) # 渐变下端
38
+ RADIUS = 0.24 # 圆角半径(归一化)
39
+ SS = 4 # 每个像素 4x4 超采样
40
+
41
+ # 图形(归一化坐标):左栏 + 两张卡
42
+ RAIL = (0.150, 0.180, 0.320, 0.820, 0.060)
43
+ CARD1 = (0.395, 0.265, 0.850, 0.435, 0.070)
44
+ CARD2 = (0.395, 0.565, 0.850, 0.735, 0.070)
45
+
46
+
47
+ def _inside_round_rect(px: float, py: float, x0: float, y0: float,
48
+ x1: float, y1: float, r: float) -> bool:
49
+ """点是否落在圆角矩形里。四个角各判一次圆,其余按矩形判。"""
50
+ if px < x0 or px > x1 or py < y0 or py > y1:
51
+ return False
52
+ cx = min(max(px, x0 + r), x1 - r)
53
+ cy = min(max(py, y0 + r), y1 - r)
54
+ if cx == px and cy == py: # 在四条直边上,不是角
55
+ return True
56
+ dx, dy = px - cx, py - cy
57
+ return dx * dx + dy * dy <= r * r
58
+
59
+
60
+ def render(size: int) -> list[list[tuple[int, int, int, int]]]:
61
+ """画一张 ``size × size`` 的 RGBA 图(超采样求平均,边缘才不会锯齿)。"""
62
+ px = []
63
+ n = SS * SS
64
+ for y in range(size):
65
+ row = []
66
+ for x in range(size):
67
+ ar = ag = ab = aa = 0.0
68
+ for sy in range(SS):
69
+ ny = (y + (sy + 0.5) / SS) / size
70
+ for sx in range(SS):
71
+ nx = (x + (sx + 0.5) / SS) / size
72
+ if not _inside_round_rect(nx, ny, 0.0, 0.0, 1.0, 1.0, RADIUS):
73
+ continue
74
+ t = ny # 纵向渐变
75
+ r = TOP[0] + (BOTTOM[0] - TOP[0]) * t
76
+ g = TOP[1] + (BOTTOM[1] - TOP[1]) * t
77
+ b = TOP[2] + (BOTTOM[2] - TOP[2]) * t
78
+ if (_inside_round_rect(nx, ny, *RAIL)
79
+ or _inside_round_rect(nx, ny, *CARD1)
80
+ or _inside_round_rect(nx, ny, *CARD2)):
81
+ r, g, b = 255.0, 255.0, 255.0 # 白色图形
82
+ ar += r / n
83
+ ag += g / n
84
+ ab += b / n
85
+ aa += 1.0 / n
86
+ a = int(round(aa * 255))
87
+ if a == 0:
88
+ row.append((0, 0, 0, 0))
89
+ else: # 颜色按覆盖率归一,半透明边缘才不会发暗
90
+ row.append((int(round(ar / aa)), int(round(ag / aa)),
91
+ int(round(ab / aa)), a))
92
+ px.append(row)
93
+ return px
94
+
95
+
96
+ def _png(size: int, img) -> bytes:
97
+ """最小的 PNG 编码器:一张 RGBA 图,一个 IDAT。"""
98
+ raw = bytearray()
99
+ for row in img:
100
+ raw.append(0) # filter: none
101
+ for r, g, b, a in row:
102
+ raw += bytes((r, g, b, a))
103
+
104
+ def chunk(tag: bytes, data: bytes) -> bytes:
105
+ return (struct.pack(">I", len(data)) + tag + data
106
+ + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF))
107
+
108
+ ihdr = struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0)
109
+ return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", ihdr)
110
+ + chunk(b"IDAT", zlib.compress(bytes(raw), 9)) + chunk(b"IEND", b""))
111
+
112
+
113
+ def _dib(size: int, img) -> bytes:
114
+ """32 位 BMP(DIB)条目:BITMAPINFOHEADER + 自下而上的 BGRA + AND 掩码。"""
115
+ header = struct.pack("<IiiHHIIiiII", 40, size, size * 2, 1, 32, 0,
116
+ size * size * 4, 0, 0, 0, 0)
117
+ xor = bytearray()
118
+ for row in reversed(img): # BMP 是自下而上
119
+ for r, g, b, a in row:
120
+ xor += bytes((b, g, r, a))
121
+ stride = ((size + 31) // 32) * 4 # AND 掩码按 32 位对齐
122
+ and_mask = bytearray()
123
+ for row in reversed(img):
124
+ bits = bytearray(stride)
125
+ for x, (_r, _g, _b, a) in enumerate(row):
126
+ if a < 128: # 1 = 透明
127
+ bits[x // 8] |= 0x80 >> (x % 8)
128
+ and_mask += bits
129
+ return header + bytes(xor) + bytes(and_mask)
130
+
131
+
132
+ def build(out: Path = DEFAULT_OUT, preview: Path | None = None) -> Path:
133
+ """画出全部尺寸并打包成 ICO。返回写出的路径。"""
134
+ frames: list[tuple[int, bytes, bool]] = [] # (size, data, is_png)
135
+ for size in SIZES:
136
+ img = render(size)
137
+ if size in PNG_SIZES:
138
+ frames.append((size, _png(size, img), True))
139
+ else:
140
+ frames.append((size, _dib(size, img), False))
141
+
142
+ count = len(frames)
143
+ offset = 6 + 16 * count
144
+ entries, blobs = b"", b""
145
+ for size, data, _png_frame in frames:
146
+ entries += struct.pack("<BBBBHHII", size % 256, size % 256, 0, 0, 1, 32,
147
+ len(data), offset)
148
+ blobs += data
149
+ offset += len(data)
150
+ payload = struct.pack("<HHH", 0, 1, count) + entries + blobs
151
+
152
+ out = Path(out)
153
+ out.parent.mkdir(parents=True, exist_ok=True)
154
+ out.write_bytes(payload)
155
+
156
+ if preview is not None:
157
+ _sheet(frames, Path(preview))
158
+ return out
159
+
160
+
161
+ def _sheet(frames: list[tuple[int, bytes, bool]], out: Path) -> None:
162
+ """对照图:每个尺寸按整数倍放大,排成一行 —— 16px 认不认得出,看这张。"""
163
+ tiles = []
164
+ for size, _data, _png_frame in frames:
165
+ # 小尺寸放大到 128,大尺寸保持原样(1:1)—— 目的是看清 16px 认不认得出
166
+ scale = max(1, 128 // size)
167
+ big = size * scale
168
+ tiles.append((big, render(size)))
169
+ width = sum(big + 16 for big, _img in tiles) + 8
170
+ height = max(big for big, _img in tiles) + 32
171
+ canvas = [[(24, 27, 31, 255) for _ in range(width)] for _ in range(height)]
172
+ x0 = 8
173
+ for big, img in tiles:
174
+ size = len(img)
175
+ scale = big // size
176
+ oy = (height - big) // 2
177
+ for y in range(big):
178
+ for x in range(big):
179
+ r, g, b, a = img[y // scale][x // scale]
180
+ if a:
181
+ canvas[oy + y][x0 + x] = (r, g, b, 255)
182
+ x0 += big + 16
183
+ # 预览图不需要 alpha:直接转成不透明的 PNG
184
+ Path(out).parent.mkdir(parents=True, exist_ok=True)
185
+ Path(out).write_bytes(_png_flat(width, height, canvas))
186
+
187
+
188
+ def _png_flat(w: int, h: int, canvas) -> bytes:
189
+ raw = bytearray()
190
+ for row in canvas:
191
+ raw.append(0)
192
+ for r, g, b, _a in row:
193
+ raw += bytes((r, g, b))
194
+
195
+ def chunk(tag: bytes, data: bytes) -> bytes:
196
+ return (struct.pack(">I", len(data)) + tag + data
197
+ + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF))
198
+
199
+ ihdr = struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)
200
+ return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", ihdr)
201
+ + chunk(b"IDAT", zlib.compress(bytes(raw), 9)) + chunk(b"IEND", b""))
202
+
203
+
204
+ def main(argv: list[str] | None = None) -> int:
205
+ ap = argparse.ArgumentParser(prog="agentworkspace.assets.make_icon", description="画窗口图标")
206
+ ap.add_argument("--out", default=str(DEFAULT_OUT))
207
+ ap.add_argument("--preview", default=None, help="额外写一张放大对照图(PNG)")
208
+ a = ap.parse_args(argv)
209
+ path = build(Path(a.out), Path(a.preview) if a.preview else None)
210
+ print(f"[图标] 已写出 {path}({path.stat().st_size} 字节,{len(SIZES)} 个尺寸)")
211
+ return 0
212
+
213
+
214
+ if __name__ == "__main__":
215
+ raise SystemExit(main())
@@ -0,0 +1,34 @@
1
+ """内置程序插件:**小助理**(pid = ``assistant``)。
2
+
3
+ 整个内核里只内置这一个程序,而且它在数据结构上和别的插件**没有区别**:
4
+ 有 pid、有标题、有能力面、有自己的智能体上下文(自己的 aaas 会话 / 自己的指令)。
5
+
6
+ 它独有的只有两件事:
7
+
8
+ 1. **手** —— tree / read / write / search / shell(toolbox 里那些动词)
9
+ 2. **造程序** —— plugin_write / plugin_verify / plugin_delete / plugin_list / plugin_call
10
+
11
+ 于是「谁能造程序」不是提示词里劝出来的规矩,而是**结构**:
12
+ 别的程序的智能体拿不到 ``assistant_plugin_write`` 这个能力 —— 它们的能力面里
13
+ 压根没有这一项(见 ``Runtime.capabilities_of``)。
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ PID = "assistant"
19
+
20
+ PROGRAM = {
21
+ "title": "小助理",
22
+ "icon": "💬",
23
+ "description": "什么都能聊;也能给你造新程序",
24
+ }
25
+
26
+
27
+ def install(rt) -> str:
28
+ """把小助理挂上内核(调用一次,装配期)。"""
29
+ from . import devtools, toolbox
30
+
31
+ toolbox._install(rt)
32
+ devtools._install(rt)
33
+ dev = rt.mount_devtools(devtools) # 开发者模式借到的那双手(不属于任何程序)
34
+ return f"{rt.mount(toolbox, PID, program=PROGRAM)};{dev}"
@@ -0,0 +1,124 @@
1
+ """**开发者工具集** —— 一个程序「改自己」时借到的那双手。
2
+
3
+ 它不是程序:没有 pid、没有界面、不在左侧栏;它是一套**能力**。
4
+ 某个程序的人打开了开发者模式(``workspace/dev.json``),那个程序的智能体
5
+ 就能看见它;关掉立刻收回(见 ``Runtime.capabilities_of``)。
6
+
7
+ 能力面是**故意小**的,用户的原话就是判据:
8
+
9
+ 看:``dev_tree`` ``dev_read`` ``dev_search``
10
+ 写:``dev_write`` —— 工作区内的普通文件(不碰程序目录、不碰开关)
11
+ 改:``dev_plugin_write`` —— 改**自己**:**没有 pid 参数**,改别人在签名上就不可能
12
+
13
+ 没有 ``plugin_list`` / ``plugin_call`` / ``plugin_delete`` / ``plugin_verify`` /
14
+ ``shell`` —— 开发者模式是「给你一把改自己的螺丝刀」,不是「给你一整套造别人
15
+ 程序的能力」,也不是「给你一个终端」。边界写在**能力面**上,比写在提示词里
16
+ 劝模型「别乱来」可靠得多:模型看不见的能力,它连试都不会试。
17
+
18
+ 归属也不变:这些手写的是 ``dev_*``,工具卡上写「🛠 开发者 · write」——
19
+ 用户一眼能分清「这是它自己的手」还是「小助理的手」。
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ _RT = None # 由 _install() 注入
25
+
26
+
27
+ def _install(rt) -> None:
28
+ global _RT
29
+ _RT = rt
30
+
31
+
32
+ def _rt():
33
+ if _RT is None: # 理论上不可达:装配先于使用
34
+ raise RuntimeError("内核未装配")
35
+ return _RT
36
+
37
+
38
+ def _me() -> str:
39
+ """此刻动手的是**哪个程序**。内核的 caller 栈是唯一来源。
40
+
41
+ 为什么不用参数传 pid:一旦 pid 是参数,模型就能填别人的名字 ——
42
+ 那时「只能改自己」只能靠「拒绝」来守;而「改自己」这件事是这一层
43
+ 唯一的用途,它根本不需要知道名字。少一个参数,就少一条能走错的路。
44
+ """
45
+ me = _rt().caller()
46
+ if not me or me not in _rt().plugins:
47
+ raise ValueError("这条路只给打开了开发者模式的程序用:此刻不知道是哪个程序在动手")
48
+ return me
49
+
50
+
51
+ # ------------------------------------------------------------------ 看
52
+
53
+ def tree(max_depth: int = 3) -> dict:
54
+ """看工作区结构(只读)。你自己的文件在 plugins/<你的 id>/ 下。
55
+
56
+ max_depth: 递归深度,默认 3
57
+ """
58
+ from . import toolbox
59
+
60
+ out = toolbox.tree(max_depth)
61
+ me = _rt().caller()
62
+ if me in _rt().plugins:
63
+ out["text"] += f"\n\n(你是 {me}:改自己用 dev_plugin_write)"
64
+ return out
65
+
66
+
67
+ def read(path: str) -> dict:
68
+ """读一个文件(工作区内)。改自己之前,先把当前那一版读出来。
69
+
70
+ path: 相对工作区的路径,如 plugins/<你的 id>/backend.py
71
+ """
72
+ from . import toolbox
73
+
74
+ return toolbox.read(path)
75
+
76
+
77
+ def search(pattern: str, path: str = ".", limit: int = 30) -> dict:
78
+ """在工作区里按文本检索,返回「文件:行号: 内容」。
79
+
80
+ pattern: 要找的文本
81
+ path: 检索起点(相对工作区),默认整个工作区
82
+ limit: 最多返回多少条
83
+ """
84
+ from . import toolbox
85
+
86
+ return toolbox.search(pattern, path, limit)
87
+
88
+
89
+ # ------------------------------------------------------------------ 写
90
+
91
+ def write(path: str, content: str) -> dict:
92
+ """写一个普通文本文件(工作区内)。**不要用来改自己** —— 改自己用 dev_plugin_write。
93
+
94
+ path: 相对工作区的路径(plugins/**、dev.json、config.json 会被拒)
95
+ content: 完整内容
96
+ """
97
+ from . import toolbox
98
+
99
+ return toolbox.write(path, content)
100
+
101
+
102
+ def plugin_write(files: dict) -> dict:
103
+ """提交**你自己**的新版本:一次提交整份文件,四道校验后才落盘。
104
+
105
+ 提交的是整份文件,不是补丁:backend.py 里原有的函数、注解、docstring
106
+ 都得带上,否则那个能力(和用户用的那个按钮)就没了。
107
+
108
+ files: {文件名: 内容},只接受 plugin.json / backend.py / ui/**;
109
+ data/(用户攒下的数据)永远不许碰
110
+
111
+ 校验不过会**整份回滚**到提交前那一版,你什么也没改成。
112
+ 上一版留在 workspace/.backup/<你的 id>/,要退回去就把它再提交一遍。
113
+ """
114
+ me = _me()
115
+ from . import toolbox
116
+
117
+ caps, kind = toolbox._commit(me, files) # 与小助理的 plugin_write 同一条落盘路径
118
+ how = ("你的界面是原生窗口(ui/app.py)—— 用户点开就弹那个窗口。"
119
+ if kind == "native" else
120
+ "你的界面是网页(ui/index.html)—— 用户刷新一下就是新的。")
121
+ return {"text": f"**改的是你自己**:{me} 现在是这一版,能力 {caps}。\n"
122
+ f"{how}\n下一轮你的上下文里就是这套能力。\n"
123
+ f"(上一版留在 workspace/.backup/{me}/,要退回去用 plugin_write 提交它。)",
124
+ "plugin": me, "functions": caps, "self": True}