tnega 0.1.0 → 0.3.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/README.md +115 -189
- package/dist/agent.js +2907 -0
- package/dist/agent.js.map +7 -0
- package/dist/bin.js +32512 -4419
- package/dist/bin.js.map +4 -4
- package/dist/cli-runtime.js +33404 -0
- package/dist/cli-runtime.js.map +7 -0
- package/dist/coding-agent.js +19088 -0
- package/dist/coding-agent.js.map +7 -0
- package/dist/core.js +1398 -0
- package/dist/core.js.map +7 -0
- package/dist/eval.js +23905 -0
- package/dist/eval.js.map +7 -0
- package/dist/events.js +1215 -0
- package/dist/events.js.map +7 -0
- package/dist/evolve.js +18303 -0
- package/dist/evolve.js.map +7 -0
- package/dist/index.js +33087 -4450
- package/dist/index.js.map +4 -4
- package/dist/llm.js +1016 -0
- package/dist/llm.js.map +7 -0
- package/dist/services.js +1142 -0
- package/dist/services.js.map +7 -0
- package/dist/session.js +1045 -0
- package/dist/session.js.map +7 -0
- package/dist/tools.js +2577 -0
- package/dist/tools.js.map +7 -0
- package/dist/types/packages/agent/src/definition.d.ts +17 -0
- package/dist/types/packages/agent/src/inbox-durable.d.ts +54 -0
- package/dist/types/packages/agent/src/index.d.ts +7 -0
- package/dist/types/packages/agent/src/live.d.ts +115 -0
- package/dist/types/packages/agent/src/llm-service.d.ts +32 -0
- package/dist/types/packages/agent/src/prompt.d.ts +55 -0
- package/dist/types/packages/agent/src/service.d.ts +68 -0
- package/dist/types/packages/agent/src/types.d.ts +215 -0
- package/dist/types/packages/benchmark/src/bigcodebench.d.ts +6 -0
- package/dist/types/packages/benchmark/src/humaneval.d.ts +11 -0
- package/dist/types/packages/benchmark/src/index.d.ts +9 -0
- package/dist/types/packages/benchmark/src/manifest.d.ts +10 -0
- package/dist/types/packages/benchmark/src/mbpp.d.ts +10 -0
- package/dist/types/packages/benchmark/src/parquet.d.ts +2 -0
- package/dist/types/packages/benchmark/src/stdlib.d.ts +3 -0
- package/dist/types/packages/benchmark/src/swebench.d.ts +2 -0
- package/dist/types/packages/benchmark/src/types.d.ts +58 -0
- package/dist/types/packages/cli/src/bin.d.ts +2 -0
- package/dist/types/packages/cli/src/commands.d.ts +146 -0
- package/dist/types/packages/cli/src/config.d.ts +28 -0
- package/dist/types/packages/cli/src/index.d.ts +9 -0
- package/dist/types/packages/cli/src/profile-file.d.ts +26 -0
- package/dist/types/packages/cli/src/profile.d.ts +9 -0
- package/dist/types/packages/cli/src/server.d.ts +14 -0
- package/dist/types/packages/cli/src/store.d.ts +60 -0
- package/dist/types/packages/cli/src/yaml.d.ts +1 -0
- package/dist/types/packages/coding-agent/src/codingAgent.d.ts +25 -0
- package/dist/types/packages/coding-agent/src/index.d.ts +6 -0
- package/dist/types/packages/coding-agent/src/mcp.d.ts +24 -0
- package/dist/types/packages/coding-agent/src/plan.d.ts +13 -0
- package/dist/types/packages/coding-agent/src/skills.d.ts +12 -0
- package/dist/types/packages/coding-agent/src/slash.d.ts +28 -0
- package/dist/types/packages/coding-agent/src/types.d.ts +41 -0
- package/dist/types/packages/core/src/context.d.ts +28 -0
- package/dist/types/packages/core/src/events.d.ts +57 -0
- package/dist/types/packages/core/src/fiber.d.ts +79 -0
- package/dist/types/packages/core/src/index.d.ts +10 -0
- package/dist/types/packages/core/src/invariant.d.ts +45 -0
- package/dist/types/packages/core/src/logger.d.ts +48 -0
- package/dist/types/packages/core/src/reflect.d.ts +42 -0
- package/dist/types/packages/core/src/registry.d.ts +54 -0
- package/dist/types/packages/core/src/service.d.ts +19 -0
- package/dist/types/packages/core/src/utils.d.ts +54 -0
- package/dist/types/packages/eval/src/codingRuntime.d.ts +18 -0
- package/dist/types/packages/eval/src/index.d.ts +5 -0
- package/dist/types/packages/eval/src/policy.d.ts +8 -0
- package/dist/types/packages/eval/src/runner.d.ts +31 -0
- package/dist/types/packages/eval/src/service.d.ts +23 -0
- package/dist/types/packages/eval/src/strategies.d.ts +58 -0
- package/dist/types/packages/eval/src/trace.d.ts +7 -0
- package/dist/types/packages/eval/src/types.d.ts +281 -0
- package/dist/types/packages/eval/src/utils.d.ts +5 -0
- package/dist/types/packages/eval/src/workspace.d.ts +17 -0
- package/dist/types/packages/evolve/src/diagnose.d.ts +9 -0
- package/dist/types/packages/evolve/src/index.d.ts +7 -0
- package/dist/types/packages/evolve/src/llm.d.ts +39 -0
- package/dist/types/packages/evolve/src/log.d.ts +26 -0
- package/dist/types/packages/evolve/src/select.d.ts +3 -0
- package/dist/types/packages/evolve/src/service.d.ts +29 -0
- package/dist/types/packages/evolve/src/types.d.ts +176 -0
- package/dist/types/packages/llm/src/anthropic-messages.d.ts +4 -0
- package/dist/types/packages/llm/src/errors.d.ts +6 -0
- package/dist/types/packages/llm/src/index.d.ts +7 -0
- package/dist/types/packages/llm/src/models.d.ts +29 -0
- package/dist/types/packages/llm/src/openai.d.ts +4 -0
- package/dist/types/packages/llm/src/provider.d.ts +3 -0
- package/dist/types/packages/llm/src/shared.d.ts +15 -0
- package/dist/types/packages/llm/src/types.d.ts +13 -0
- package/dist/types/packages/session/src/index.d.ts +500 -0
- package/dist/types/packages/session/src/invariant.d.ts +33 -0
- package/dist/types/packages/tools/src/builtins.d.ts +25 -0
- package/dist/types/packages/tools/src/calc.d.ts +4 -0
- package/dist/types/packages/tools/src/execution.d.ts +31 -0
- package/dist/types/packages/tools/src/index.d.ts +107 -0
- package/dist/types/packages/tools/src/path.d.ts +4 -0
- package/dist/types/packages/tools/src/policy.d.ts +14 -0
- package/dist/types/src/events.d.ts +1 -0
- package/dist/types/src/index.d.ts +15 -0
- package/dist/types/src/services.d.ts +4 -0
- package/dist/web/assets/index-45pokiBH.js +270 -0
- package/dist/web/assets/index-DCLL69Kz.css +1 -0
- package/dist/web/index.html +13 -0
- package/package.json +92 -35
package/README.md
CHANGED
|
@@ -1,189 +1,115 @@
|
|
|
1
|
-
# Tnega
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Tnega
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
pnpm
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
pnpm tnega run --allow-network "fetch https://example.com"
|
|
117
|
-
pnpm tnega run --allow-shell "list files and summarize"
|
|
118
|
-
pnpm tnega eval run tasks.yml # 运行评测
|
|
119
|
-
pnpm tnega eval compare a b # 比较两次评测
|
|
120
|
-
pnpm tnega evolve run tasks.yml # 运行真实 LLM 自进化闭环
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
不需要 API key 的快速试用:
|
|
124
|
-
|
|
125
|
-
```text
|
|
126
|
-
pnpm tnega eval run examples/tasks.yml
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## 真实 LLM 接入
|
|
130
|
-
|
|
131
|
-
`tnega run` 通过 OpenAI 兼容协议调用 OpenCode Go 的 DeepSeek 端点,key 只从环境变量读取,不写入代码或仓库文件:
|
|
132
|
-
|
|
133
|
-
```text
|
|
134
|
-
OPENCODE_GO_API_KEY=sk-xxx pnpm tnega run "Reply with: hello"
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
也可以使用 `OPENAI_API_KEY` 或 `DEEPSEEK_API_KEY` 作为兼容变量。默认端点为 `https://opencode.ai/zen/go/v1`,默认模型为 `deepseek-v4-flash`;可通过 `OPENCODE_GO_BASE_URL`、`OPENCODE_GO_MODEL` 或 `--base-url`、`--model`、`--max-tokens`、`--temperature` 覆盖。
|
|
138
|
-
|
|
139
|
-
会话记录默认写入 `.tnega/run.jsonl`,可以使用 `--session <file>` 指定位置。
|
|
140
|
-
|
|
141
|
-
## 内置工具
|
|
142
|
-
|
|
143
|
-
`tnega run` 默认挂载一个最小内置工具集,每个工具都是普通 `ToolDefinition`,通过 `builtinTools` 插件注册;插件卸载时工具自动注销,符合“工具也是可插拔”的架构。
|
|
144
|
-
|
|
145
|
-
默认工具:
|
|
146
|
-
|
|
147
|
-
```text
|
|
148
|
-
echo, now, calculator, json,
|
|
149
|
-
read_file, write_file, list_dir, glob, grep
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
高权限工具默认不注册:
|
|
153
|
-
|
|
154
|
-
- `http_get`:需要 `--allow-network`
|
|
155
|
-
- `shell`:需要 `--allow-shell`,工作目录被限制在 `--cwd` 内
|
|
156
|
-
|
|
157
|
-
文件工具使用路径沙箱:`read_file / write_file / list_dir / glob / grep / shell` 均被限制在 `--cwd` 内,拒绝绝对路径越界、`..` 越界与 symlink 越界。读取默认上限 256 KiB,写入与搜索默认上限 1 MiB,搜索结果默认 200 条,shell 默认 15 秒超时。
|
|
158
|
-
|
|
159
|
-
以插件方式接入时,`builtinTools` 接受 `BuiltinToolsConfig`:`cwd / allowNetwork / allowShell / disabled / maxReadBytes / maxWriteBytes / maxSearchBytes / maxResults / timeoutMs`,`disabled` 可进一步关闭任一内置工具。
|
|
160
|
-
|
|
161
|
-
`tnega evolve run tasks.yml` 把自进化闭环接到真实 LLM:baseline 和候选都由 LLM 驱动,提案规则要求 LLM 返回 JSON 形态的系统提示词候选,评测后由确定性 gate 决定接受或拒绝。实验树默认写入 `.tnega/experiments/log.json`,候选 run 写入 `.tnega/experiments/runs/`,文件中不含 key。
|
|
162
|
-
|
|
163
|
-
tasks.yml 支持候选声明;没有接入真实 LLM 时可以用内置确定性 loop 跑通完整评测链路:
|
|
164
|
-
|
|
165
|
-
```yaml
|
|
166
|
-
tasks:
|
|
167
|
-
- id: echo-good
|
|
168
|
-
inputText: good
|
|
169
|
-
assertion:
|
|
170
|
-
expect: good
|
|
171
|
-
candidates:
|
|
172
|
-
echo:
|
|
173
|
-
version: "1"
|
|
174
|
-
loop: echo
|
|
175
|
-
defaultCandidate: echo
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## 状态
|
|
179
|
-
|
|
180
|
-
- M1 core 时空语义:已完成。Context / Fiber / Effect / Event / Registry / Reflect 已落地,支持插件热插拔、失败回滚、依赖联动与 scope 隔离,配套 94 个 core 测试。
|
|
181
|
-
- M2 agent + tools + session:已完成。SessionLog 以 JSONL 记录可重放的会话事件并支持 fork / compact;ToolsService 提供注册表与可插拔执行管线;AgentService 提供可替换 agentLoop、inbox 与 fake LLM 端到端工具调用,配套 45 个测试。
|
|
182
|
-
- M3 eval 评测运行时:已完成。EvalRunner 在隔离子 Context 中加载候选,逐 task 创建独立会话与工具 scope,支持预算、缓存、持久化与 eval/* 事件;策略 assert / llm-judge / regression / all / weighted / gate 可注册、替换和卸载;CLI 支持 `tnega eval run` 与 `tnega eval compare`,配套 29 个测试。
|
|
183
|
-
- M4 evolve 进化循环:已完成。Candidate / propose / ExperimentLog 树提供候选生成与可回放实验;selection gate 支持 min-score、safety、退化阈值、显著性规则与审批 seam;确定性多轮闭环验证候选失败不影响主 runtime,配套 11 个 evolve 测试。
|
|
184
|
-
- M5 真实 LLM 接入:已完成。`@tnega/llm` 提供 OpenAI 兼容适配器与 `listModels`;`tnega run` 只从环境变量读取 key,支持模型、端点、温度、token 上限与 session 文件参数,配套 OpenAI 协议与 CLI 端到端测试。
|
|
185
|
-
- M6 时空可组合极端压力测试:已完成。新增 10 个压力测试,覆盖 100 次热插拔、20 代 provider 替换、128 插件级联、64 scope 隔离、64 fiber 并发挂载卸载、65 次健康检查拨动与 update 风暴。
|
|
186
|
-
- M7 真实 LLM 自进化闭环:已完成。`evolve run` 用真实 DeepSeek 驱动 baseline、提案与候选评测,gate 选择后持久化实验树;真实端到端实验与记录见 `docs/test/evolve-llm-e2e.md`。
|
|
187
|
-
- M8 最小内置工具集:已完成。`builtinTools` 以插件形式提供 `echo / now / calculator / json / read_file / write_file / list_dir / glob / grep`,`http_get` 与 `shell` 默认关闭,文件与 shell 工具受路径沙箱与字节/结果/超时上限约束;配套 16 个测试。
|
|
188
|
-
- M9 真实 LLM 工具调用端到端测试:已完成。mock 端到端 4 个测试覆盖 calculator / http_get / shell / 路径沙箱;真实 DeepSeek 冒烟 3 个测试覆盖 calculator / read_file / shell,session 记录 tool-call 与 tool-result,测试记录见 `docs/test/tools-llm-e2e.md`。
|
|
189
|
-
- M10 npm / pnpm 发布准备:已完成。`tnega` 根包发布为公共自包含 CLI,`bin` 指向 esbuild 打包的 `dist/bin.js`,`prepublishOnly` 自动构建并跑发布测试;npm 与 pnpm 本地安装验证通过,测试记录见 `docs/test/npm-publish.md`。
|
|
1
|
+
# Tnega
|
|
2
|
+
|
|
3
|
+
[中文](docs/zh-CN.md)
|
|
4
|
+
|
|
5
|
+
**Tnega** is "agent" spelled backwards. It is an eval-first agent harness with spacetime-composable plugin lifecycles: components can be hot-swapped and rolled back safely, and Eval is a first-class citizen on par with the agent loop and tools.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Requires Node.js >= 22.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g tnega
|
|
13
|
+
# or
|
|
14
|
+
pnpm add -g tnega
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export OPENCODE_GO_API_KEY=sk-...
|
|
21
|
+
tnega run "Reply with: hello"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`tnega run` uses OpenCode Go's `deepseek-v4-flash` model through the OpenAI compatible endpoint by default. `minimax-m3` is also available through the Anthropic Messages endpoint. The API key can also come from `~/.tnega/config.json` (Windows: `%USERPROFILE%\.tnega\config.json`) with fields `apiKey`, `model`, `baseUrl`, and `temperature`. Precedence: CLI flags > environment variables > config file > defaults.
|
|
25
|
+
|
|
26
|
+
Run a deterministic eval without an API key:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
tnega eval run examples/tasks.yml
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Start the local web UI:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
tnega web
|
|
36
|
+
# http://127.0.0.1:3080
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The web UI creates sessions as either `general` or `coding` agents. Coding
|
|
40
|
+
sessions support `auto` / `plan` / `execute` modes; plan mode shows the LLM
|
|
41
|
+
generated todo list above the composer and updates each item as tools mark it
|
|
42
|
+
done or failed. `/` slash commands such as `/mode`, `/skills`, and `/mcp` are
|
|
43
|
+
available in coding sessions.
|
|
44
|
+
|
|
45
|
+
## CLI
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
tnega run "prompt" # one agent session
|
|
49
|
+
tnega run --allow-shell "list files" # enable high-permission tools
|
|
50
|
+
tnega web # local web UI
|
|
51
|
+
tnega eval run tasks.yml # run evals
|
|
52
|
+
tnega eval compare <base> <head> # compare two eval runs
|
|
53
|
+
tnega evolve run tasks.yml # run a self-evolution loop
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Options include `--model`, `--base-url`, `--max-tokens`, `--temperature`, `--cwd`, `--session`, `--timeout-ms`, `--max-retries`, and `--retry-delay-ms`. Sessions are recorded as JSONL under `.tnega/`.
|
|
57
|
+
|
|
58
|
+
## Built-in Tools
|
|
59
|
+
|
|
60
|
+
The default tool set is `echo`, `now`, `calculator`, `json`, `read_file`, `write_file`, `list_dir`, `glob`, and `grep`. High-permission tools are opt-in: `http_get` requires `--allow-network`, `shell` requires `--allow-shell`. File and shell tools are confined to the working directory.
|
|
61
|
+
|
|
62
|
+
## Coding Agent
|
|
63
|
+
|
|
64
|
+
`tnega/coding-agent` is a packaged agent plugin for workspace-oriented coding
|
|
65
|
+
sessions. It contributes plan generation, `plan_execute_mark` /
|
|
66
|
+
`plan_execute_result` tools, workspace skills (`skills_list` / `skill_read`),
|
|
67
|
+
stdio MCP servers from `.tnega/mcp.json`, and a slash command registry. The web
|
|
68
|
+
server enables it per session through `agentType: "coding"`, while general
|
|
69
|
+
sessions keep the default loop unchanged.
|
|
70
|
+
|
|
71
|
+
## Library
|
|
72
|
+
|
|
73
|
+
Tnega is published as a library as well as a CLI. Use the root package or domain subpaths (`tnega/core`, `tnega/agent`, `tnega/coding-agent`, `tnega/eval`, `tnega/evolve`, `tnega/session`, `tnega/tools`, `tnega/llm`, ...):
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { Context, defineAgent, openaiCompatAdapter } from 'tnega'
|
|
77
|
+
|
|
78
|
+
const root = new Context()
|
|
79
|
+
const fiber = await root.plugin(
|
|
80
|
+
defineAgent({
|
|
81
|
+
name: 'coding-agent',
|
|
82
|
+
version: '0.3.0',
|
|
83
|
+
system: 'You are a coding agent.',
|
|
84
|
+
}),
|
|
85
|
+
{ llm: openaiCompatAdapter({ apiKey: process.env.OPENCODE_GO_API_KEY! }) },
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const loop = root.get('agentLoop')
|
|
89
|
+
const result = await loop({ text: 'implement the feature' })
|
|
90
|
+
console.log(result.output)
|
|
91
|
+
|
|
92
|
+
await fiber.dispose()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Concepts
|
|
96
|
+
|
|
97
|
+
- **Spacetime composability**: components can be inserted, replaced, and removed at runtime; effects are reversed in order on teardown, so hot-swaps leave no residue.
|
|
98
|
+
- **Eval as infrastructure**: strategies, tasks, evidence, verdicts, and runs are pluggable primitives, and evaluation is also the fitness function for self-evolution.
|
|
99
|
+
- **Self-evolution**: `evolve` proposes candidates, evaluates them in isolated scopes, and accepts or rejects them through deterministic gates.
|
|
100
|
+
|
|
101
|
+
See the [Chinese guide](docs/zh-CN.md) for the detailed design, model pricing table, library contracts, and roadmap.
|
|
102
|
+
|
|
103
|
+
## Development
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pnpm install
|
|
107
|
+
pnpm test
|
|
108
|
+
pnpm typecheck
|
|
109
|
+
pnpm lint
|
|
110
|
+
pnpm build
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT
|