@yumind-ai/harness 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 蔡元 (YuMind)
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.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # Yu Harness
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > 本地优先的 AI Agent 工作台。一条命令启动,浏览器里就是一个能调用工具、能读写你本地文件的 Agent 界面。
4
+
5
+ ```bash
6
+ npx -y @yumind-ai/harness run web
7
+ ```
8
+
9
+ 浏览器会自动打开 `http://127.0.0.1:1900`。
10
+
11
+ ## 特性
12
+
13
+ - **零后端依赖的数据存放**:会话、配置、虚拟文件全部存在浏览器 `localStorage`,不经过任何服务器。
14
+ - **对接任意 OpenAI 兼容接口**:填 Base URL / API Key / 模型名即可,兼容 `/chat/completions`。
15
+ - **流式输出**:SSE 逐字渲染,也可关闭走非流式;服务端忽略 `stream` 时会自动回落。
16
+ - **工具调用(Function Calling)**:内置 `calculator`、`now`、`file_read`、`file_write`、`file_list`,可单独开关。
17
+ - **真实文件读写**:通过 File System Access API 绑定本地文件夹,工具可直接读写磁盘文件(仅限你手动授权的目录)。
18
+ - **Markdown 渲染**:标题、列表、表格外的常见语法、代码块带一键复制;渲染先转义再套标签,无注入风险。
19
+ - **会话管理**:多会话、搜索、重命名、单条对话导出 Markdown、全量 JSON 导入导出。
20
+ - **运行轨迹**:每一步 Agent 决策、工具调用与耗时都在右栏可见,可复制为 JSON。
21
+ - **深浅色主题**、快捷键、窄屏折叠面板。
22
+
23
+ ## 命令
24
+
25
+ ```bash
26
+ yh # 启动并打开浏览器
27
+ yh run web # 同上
28
+ yh run web --port 3000 # 指定端口
29
+ yh run web --no-open # 不自动开浏览器
30
+ yh --help # 帮助
31
+ yh --version # 版本
32
+ ```
33
+
34
+ 安装后也可以用 `yu-harness` 这个别名。
35
+
36
+ 端口默认 `1900`;被占用时会自动往后顺延,最多试 20 个。
37
+
38
+ ## 使用
39
+
40
+ 1. 启动后,在左侧 **Provider** 区域填入:
41
+ - **Base URL**:例如 `https://api.deepseek.com/v1`、`http://localhost:11434/v1`(Ollama)、或你自己的网关地址
42
+ - **API Key**
43
+ - **Model**:例如 `deepseek-chat`
44
+ 2. 直接开始对话。需要让 Agent 操作文件时,点 **选择本地文件夹** 授权一个目录(Chrome / Edge 支持)。
45
+ 3. 没有绑定文件夹时,`file_write` 会写进浏览器内的虚拟文件系统,在右栏 **文件** 标签里查看。
46
+
47
+ ## 快捷键
48
+
49
+ | 操作 | 快捷键 |
50
+ | --- | --- |
51
+ | 发送 | `Enter` |
52
+ | 换行 | `Shift` + `Enter` |
53
+ | 停止生成 | `Esc` |
54
+ | 新建对话 | `Ctrl` + `N` |
55
+ | 搜索对话 | `Ctrl` + `K` |
56
+ | 收起左栏 / 右栏 | `Ctrl` + `B` / `Ctrl` + `J` |
57
+ | 重命名对话 | 双击左侧标题 |
58
+
59
+ ## 浏览器要求
60
+
61
+ 推荐最新版 Chrome 或 Edge。真实文件读写依赖 [File System Access API](https://developer.mozilla.org/docs/Web/API/File_System_API),Firefox / Safari 下会自动降级为虚拟文件系统。
62
+
63
+ ## 本地开发
64
+
65
+ ```bash
66
+ git clone <repo>
67
+ cd yu-harness
68
+ npm install
69
+ npm run build # src/index.html -> public/index.html
70
+ npm run dev # 起在 1900 端口
71
+ ```
72
+
73
+ `src/index.html` 是唯一源文件,`public/index.html` 是构建产物(两者内容一致,前者为开发入口)。
74
+
75
+ ## 隐私
76
+
77
+ Yu Harness 自身不收集、不上报任何数据。对话内容只会发往你在 **Base URL** 里填写的那个服务。注意 `localStorage` 明文保存 API Key,请勿在共用电脑上保存敏感密钥。
78
+
79
+ ## License
80
+
81
+ MIT
package/cli.js ADDED
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Yu Harness CLI
4
+ * 用法: yh [run] [web] [--port 1900] [--no-open]
5
+ */
6
+ 'use strict';
7
+
8
+ const path = require('path');
9
+ const fs = require('fs');
10
+ const { spawn } = require('child_process');
11
+
12
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
13
+ const PUBLIC_DIR = path.join(__dirname, 'public');
14
+ const ENTRY = path.join(PUBLIC_DIR, 'index.html');
15
+
16
+ const C = {
17
+ reset: '\x1b[0m', dim: '\x1b[2m', bold: '\x1b[1m',
18
+ cyan: '\x1b[36m', green: '\x1b[32m', yellow: '\x1b[33m', red: '\x1b[31m'
19
+ };
20
+ const c = (code, s) => `${code}${s}${C.reset}`;
21
+
22
+ function help() {
23
+ console.log(`
24
+ ${c(C.bold + C.cyan, 'Yu Harness')} ${c(C.dim, 'v' + pkg.version)} — 本地优先的 AI Agent 工作台
25
+
26
+ ${c(C.bold, '用法')}
27
+ ${c(C.green, 'yh')} 启动并打开浏览器(默认 http://127.0.0.1:1900)
28
+ ${c(C.green, 'yh run web')} 同上
29
+ ${c(C.green, 'yh run web --port 3000')} 指定端口
30
+ ${c(C.green, 'yh run web --no-open')} 不自动打开浏览器
31
+ ${c(C.green, 'yh --help')} 显示帮助
32
+ ${c(C.green, 'yh --version')} 显示版本
33
+
34
+ ${c(C.bold, '选项')}
35
+ -p, --port <n> 监听端口(默认 1900,被占用时自动顺延)
36
+ --no-open 启动后不自动打开浏览器
37
+ -h, --help 显示帮助
38
+ -v, --version 显示版本
39
+
40
+ ${c(C.bold, '说明')}
41
+ Yu Harness 是纯前端单页应用,所有会话与配置都保存在浏览器本地,
42
+ 不会上传任何数据。Provider 需兼容 OpenAI /chat/completions 接口。
43
+ `);
44
+ }
45
+
46
+ function parseArgs(argv) {
47
+ const out = { port: 1900, open: true, help: false, version: false, unknown: [] };
48
+ const rest = [];
49
+ for (let i = 0; i < argv.length; i++) {
50
+ const a = argv[i];
51
+ if (a === '-h' || a === '--help') out.help = true;
52
+ else if (a === '-v' || a === '--version') out.version = true;
53
+ else if (a === '--no-open') out.open = false;
54
+ else if (a === '--open') out.open = true;
55
+ else if (a === '-p' || a === '--port') {
56
+ const v = argv[++i];
57
+ if (v == null) { out.unknown.push(a); continue; }
58
+ const n = Number(v);
59
+ if (!Number.isInteger(n) || n < 1 || n > 65535) out.unknown.push(`${a} ${v}`);
60
+ else out.port = n;
61
+ } else if (a.startsWith('--port=')) {
62
+ const n = Number(a.slice(7));
63
+ if (Number.isInteger(n) && n >= 1 && n <= 65535) out.port = n;
64
+ else out.unknown.push(a);
65
+ } else rest.push(a);
66
+ }
67
+ // 位置参数:run / web / start / dev 都是同一件事
68
+ out.positional = rest.filter(r => !['run', 'web', 'start', 'dev'].includes(r));
69
+ if (out.positional.length) out.unknown.push(...out.positional);
70
+ return out;
71
+ }
72
+
73
+ function openBrowser(url) {
74
+ const cmd = process.platform === 'darwin'
75
+ ? ['open', [url]]
76
+ : process.platform === 'win32'
77
+ ? ['cmd', ['/c', 'start', '""', url]]
78
+ : ['xdg-open', [url]];
79
+ try {
80
+ const child = spawn(cmd[0], cmd[1], { stdio: 'ignore', detached: true, windowsHide: true });
81
+ child.on('error', () => {});
82
+ child.unref();
83
+ } catch { /* 打不开就算了,URL 已经打印出来 */ }
84
+ }
85
+
86
+ function main() {
87
+ const args = parseArgs(process.argv.slice(2));
88
+
89
+ if (args.version) { console.log(pkg.version); process.exit(0); }
90
+ if (args.help) { help(); process.exit(0); }
91
+
92
+ if (args.unknown.length) {
93
+ console.error(c(C.red, `\n✖ 无法识别的参数: ${args.unknown.join(' ')}`));
94
+ console.error(c(C.dim, ` 运行 "yh --help" 查看用法\n`));
95
+ process.exit(1);
96
+ }
97
+
98
+ if (!fs.existsSync(ENTRY)) {
99
+ console.error(c(C.red, `\n✖ 缺少前端文件: ${ENTRY}`));
100
+ console.error(c(C.dim, ' 安装可能不完整,请重新安装: npx -y ' + pkg.name + '\n'));
101
+ process.exit(1);
102
+ }
103
+
104
+ let express;
105
+ try {
106
+ express = require('express');
107
+ } catch {
108
+ console.error(c(C.red, '\n✖ 缺少依赖 express,请重新安装:npx -y ' + pkg.name + '\n'));
109
+ process.exit(1);
110
+ }
111
+
112
+ const app = express();
113
+ app.disable('x-powered-by');
114
+
115
+ app.use(express.static(PUBLIC_DIR, { extensions: ['html'], maxAge: 0 }));
116
+
117
+ app.use((req, res, next) => {
118
+ if (req.method !== 'GET' && req.method !== 'HEAD') return next();
119
+ if (req.path.startsWith('/api/')) return next();
120
+ res.sendFile(ENTRY);
121
+ });
122
+
123
+ app.use((err, req, res, _next) => {
124
+ console.error(c(C.red, '✖ ' + err.message));
125
+ res.status(500).type('text/plain').send('Internal Error: ' + err.message);
126
+ });
127
+
128
+ const server = app.listen(args.port, '127.0.0.1');
129
+ let tries = 0;
130
+ let bound = false;
131
+
132
+ server.on('listening', () => {
133
+ bound = true;
134
+ const { port } = server.address();
135
+ const url = `http://127.0.0.1:${port}`;
136
+ console.log('');
137
+ console.log(c(C.cyan, ' ◈ Yu Harness ') + c(C.dim, 'v' + pkg.version + ' · Agent 调度框架'));
138
+ console.log(c(C.dim, ' ──────────────────────────────────────'));
139
+ console.log(' ' + c(C.green, '本地地址 ') + c(C.bold, url));
140
+ console.log(' ' + c(C.dim, 'port ') + c(C.dim, String(port)));
141
+ console.log(' ' + c(C.dim, 'public ') + c(C.dim, PUBLIC_DIR));
142
+ console.log('');
143
+ console.log(c(C.dim, ' 按 Ctrl+C 停止。首次使用请在左侧填写 Base URL / API Key / 模型名。'));
144
+ console.log('');
145
+ if (args.open) openBrowser(url);
146
+ });
147
+
148
+ server.on('error', (err) => {
149
+ if (bound) {
150
+ console.error(c(C.red, `\n✖ 运行时错误: ${err.message}\n`));
151
+ return;
152
+ }
153
+ if (err.code === 'EADDRINUSE' && tries < 20) {
154
+ tries++;
155
+ const port = args.port + tries;
156
+ console.log(c(C.yellow, ` ⚠ 端口 ${port - 1} 已被占用,改用 ${port} …`));
157
+ setTimeout(() => server.listen(port, '127.0.0.1'), 60);
158
+ return;
159
+ }
160
+ if (err.code === 'EADDRINUSE') {
161
+ console.error(c(C.red, `\n✖ 连续 20 个端口都被占用,请用 --port 指定空闲端口。\n`));
162
+ } else if (err.code === 'EACCES') {
163
+ console.error(c(C.red, `\n✖ 没有权限绑定端口 ${args.port},请换一个 1024 以上的端口。\n`));
164
+ } else {
165
+ console.error(c(C.red, `\n✖ 启动失败: ${err.message}\n`));
166
+ }
167
+ process.exit(1);
168
+ });
169
+
170
+ const shutdown = () => {
171
+ console.log(c(C.dim, '\n 已停止 Yu Harness。'));
172
+ server.close(() => process.exit(0));
173
+ setTimeout(() => process.exit(0), 500).unref();
174
+ };
175
+ process.on('SIGINT', shutdown);
176
+ process.on('SIGTERM', shutdown);
177
+ }
178
+
179
+ main();
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@yumind-ai/harness",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Yu Harness - a single-file, local-first AI agent workbench that runs in your browser",
5
+ "main": "cli.js",
6
+ "bin": {
7
+ "yh": "cli.js",
8
+ "yu-harness": "cli.js"
9
+ },
10
+ "files": [
11
+ "cli.js",
12
+ "public/",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "start": "node cli.js run web",
18
+ "dev": "node cli.js run web --port 1900 --no-open",
19
+ "build": "node build.js",
20
+ "check": "node scripts/check.js",
21
+ "prepublishOnly": "node build.js && node scripts/check.js && node --check cli.js"
22
+ },
23
+ "keywords": [
24
+ "ai",
25
+ "agent",
26
+ "harness",
27
+ "llm",
28
+ "openai",
29
+ "workbench",
30
+ "yumind"
31
+ ],
32
+ "author": "蔡元",
33
+ "license": "MIT",
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "dependencies": {
38
+ "express": "^4.21.2"
39
+ }
40
+ }