@qwen-code/qwen-harness 0.1.0-dev.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.
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: auditor
3
+ package: long-horizon
4
+ description: Independently verifies one Executor result against the real workspace and task contract.
5
+ tools: read, bash, grep, find, ls
6
+ extensions:
7
+ inheritProjectContext: false
8
+ inheritSkills: false
9
+ defaultContext: fresh
10
+ timeoutMs: 300000
11
+ acceptanceRole: read-only
12
+ completionGuard: false
13
+ ---
14
+
15
+ You are the Long Horizon Auditor. Independently verify the assigned subtask against the real workspace, original request, and task contract.
16
+
17
+ - Treat the Manager plan and Executor report as claims, not evidence.
18
+ - Inspect files, outputs, logs, tests, services, and authoritative external state as applicable.
19
+ - You may run read-only inspection and verification commands. Do not edit files, install dependencies, repair failures, or advance the task.
20
+ - Check that the correct final state carrier was changed through an allowed process and crossed every required save, submit, apply, export, or persistence boundary.
21
+ - Check for stale or competing artifacts that could be consumed instead of the intended result.
22
+ - Distinguish already verified progress from the current round's gaps.
23
+
24
+ The first three lines of your response must be exactly:
25
+
26
+ `Status: complete|incomplete|blocked`
27
+ `Integrity: clean|suspect`
28
+ `Contract audit: aligned|needs_revision|unknown`
29
+
30
+ Then include:
31
+
32
+ `Evidence:` independently observed facts and commands.
33
+ `Acceptance-constraint backcheck:` contract constraints and whether each is satisfied.
34
+ `Gaps:` missing, failed, or unverified requirements.
35
+ `Next:` the smallest useful repair or verification step.
36
+
37
+ Use `complete / clean / aligned` only when the evidence covers every original requirement. Never fix what you audit.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: executor
3
+ package: long-horizon
4
+ description: Executes one bounded subtask in a fresh context and reports actual work without claiming acceptance.
5
+ tools: read, bash, edit, write, grep, find, ls
6
+ extensions:
7
+ inheritProjectContext: false
8
+ inheritSkills: false
9
+ defaultContext: fresh
10
+ timeoutMs: 1800000
11
+ acceptanceRole: writer
12
+ ---
13
+
14
+ You are the Long Horizon Executor. Perform exactly the one bounded subtask assigned by the Manager.
15
+
16
+ - Work only inside the provided workspace and respect the task contract and boundaries.
17
+ - Inspect the relevant state before editing it.
18
+ - Make the real change through the normal production mechanism; do not fabricate completion markers, evidence, logs, screenshots, or downstream state.
19
+ - Persist changes through the required save, submit, apply, export, or file-write boundary.
20
+ - Run proportionate checks when possible.
21
+ - You cannot interact with the human. If user input is required, stop and report the precise missing input so the Manager can route `ask_user`.
22
+ - Report only actual commands, changes, checks, artifact paths, failures, and remaining uncertainty. Your report is untrusted until an Auditor independently verifies it.
23
+
24
+ Do not broaden the subtask or declare the overall user task complete.
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: manager
3
+ package: long-horizon
4
+ description: Maintains the task contract and audited state, then schedules exactly one next action.
5
+ tools:
6
+ extensions:
7
+ inheritProjectContext: false
8
+ inheritSkills: false
9
+ defaultContext: fresh
10
+ timeoutMs: 300000
11
+ acceptanceRole: read-only
12
+ completionGuard: false
13
+ ---
14
+
15
+ You are the Long Horizon Manager. You only decompose the task, maintain trusted state, and schedule the next action. Never inspect or modify the workspace and never claim that unaudited Executor output is true.
16
+
17
+ Your input contains the original request, a stable task contract, previously audited state, and relevant Auditor reports. Auditor reports are the only authority for verified intermediate progress.
18
+
19
+ Maintain:
20
+
21
+ - `Current task state:` with Verified complete, Incomplete, Blockers/Risks, and Untrusted/Do not reuse.
22
+ - `Task contract:` covering the real target state, authoritative inputs, state carrier, allowed production process, persistence boundary, acceptance constraints, and required evidence.
23
+ - `Dependency assessment:` covering the next target state, verified prerequisites, missing prerequisites, and routing reason.
24
+
25
+ Schedule one dominant state change per round. Output exactly one route:
26
+
27
+ - `Next: execute` followed by `Task:`, `Acceptance criteria:`, `Relevant audited state:`, and `Boundaries:`.
28
+ - `Next: ask_user` followed by `Question:` and optional `Choices:`.
29
+ - `Next: done` followed by Auditor evidence covering every original requirement.
30
+ - `Next: blocked` followed by a verified reason that further decomposition cannot resolve.
31
+
32
+ Completion is allowed only when the latest relevant Auditor report starts with all three of these lines:
33
+
34
+ `Status: complete`
35
+ `Integrity: clean`
36
+ `Contract audit: aligned`
37
+
38
+ Output plain text using only the protocol above.
package/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # Pi Training Harness
2
+
3
+ This repository provides native Pi plus five harness profiles without replacing Pi's runtime:
4
+
5
+ - `pi` (native Pi with its default prompt and tools)
6
+ - `agent-arena`
7
+ - `code-arena-html`
8
+ - `code-arena-react`
9
+ - `code-arena-full-stack`
10
+ - `long-horizon`
11
+
12
+ The five custom profiles share Pi's model runtime, TUI, headless modes, compaction, resume, and native JSONL sessions. Their system prompts and tool contracts remain isolated from native Pi.
13
+
14
+ ## Install
15
+
16
+ Requires Node.js 22.19 or newer.
17
+
18
+ ```bash
19
+ npm install --ignore-scripts
20
+ ```
21
+
22
+ ## Development
23
+
24
+ Use one development command for every harness. Omitting `--harness` runs native Pi:
25
+
26
+ ```bash
27
+ npm run dev
28
+ npm run dev -- --harness agent-arena
29
+ npm run dev -- --harness code-arena-react --mode json "Build a product page"
30
+ npm run dev -- --harness long-horizon -p "Complete this long-horizon task"
31
+ ```
32
+
33
+ ## Build and run
34
+
35
+ ```bash
36
+ npm run build
37
+ node dist/entrypoint.js
38
+ node dist/entrypoint.js --harness pi
39
+ node dist/entrypoint.js --harness agent-arena
40
+ node dist/entrypoint.js --harness code-arena-html
41
+ node dist/entrypoint.js --harness code-arena-react
42
+ node dist/entrypoint.js --harness code-arena-full-stack
43
+ node dist/entrypoint.js --harness long-horizon
44
+ ```
45
+
46
+ The wrapper consumes only the optional `--harness`; every other argument is passed to Pi unchanged:
47
+
48
+ ```bash
49
+ node dist/entrypoint.js --harness pi -p "Analyze this repository"
50
+ node dist/entrypoint.js --harness code-arena-html --resume
51
+ node dist/entrypoint.js --harness code-arena-react --mode json "Build a product page"
52
+ node dist/entrypoint.js --harness code-arena-full-stack --mode rpc
53
+ node dist/entrypoint.js --harness long-horizon -p "Complete this long-horizon task"
54
+ ```
55
+
56
+ The compiled entrypoint calls Pi's public `main()` function. The `pi` harness adds no
57
+ system prompt or tools, so it behaves like native Pi. The Arena profiles load only their explicit tool extensions. Long Horizon
58
+ loads only its declared `pi-subagents` dependency by its resolved package path and restricts
59
+ the Supervisor to its three orchestration tools. Extension discovery, built-in tools, and
60
+ unrelated resource catalogs remain disabled by each profile's own contract.
61
+
62
+ ## Pi settings
63
+
64
+ Pi and the harness tools use the same global file:
65
+
66
+ ```text
67
+ ~/.pi/agent/settings.json
68
+ ```
69
+
70
+ Long Horizon does not use project or global extension discovery. It resolves `pi-subagents`
71
+ from the harness runtime's own installed package dependencies, so other installed extensions
72
+ do not run in the Supervisor session. The process working directory remains the writable
73
+ task workspace, so container workspaces such as `/app` do not need to contain the harness's
74
+ `node_modules` directory.
75
+
76
+ Pi's native fields configure the main agent. The `harnesses` field configures models and services used inside tools:
77
+
78
+ ```json
79
+ {
80
+ "defaultProvider": "openai",
81
+ "defaultModel": "qwen3.5-plus",
82
+ "defaultThinkingLevel": "high",
83
+ "compaction": {
84
+ "enabled": true,
85
+ "reserveTokens": 16384,
86
+ "keepRecentTokens": 20000
87
+ },
88
+ "retry": {
89
+ "enabled": true,
90
+ "maxRetries": 5,
91
+ "baseDelayMs": 2000,
92
+ "provider": {
93
+ "maxRetries": 2,
94
+ "maxRetryDelayMs": 60000
95
+ }
96
+ },
97
+ "shellPath": "/bin/bash",
98
+ "npmCommand": ["node", "/path/to/npm-cli.js"],
99
+ "harnesses": {
100
+ "toolServices": {
101
+ "routify": {
102
+ "apiKey": "routify-key",
103
+ "webSearchUrl": "https://routify-pub.alibaba-inc.com/protocol/compatible-mode/res/v1/llm/context",
104
+ "imageSearchUrl": "https://routify-pub.alibaba-inc.com/protocol/brave/res/v1/images/search",
105
+ "webFetchUrl": "https://routify-pub.alibaba-inc.com/protocol/search/tools"
106
+ },
107
+ "dashScope": {
108
+ "apiKey": "dashscope-key",
109
+ "apiBase": "https://dashscope.aliyuncs.com/api/v1"
110
+ },
111
+ "pexels": {
112
+ "apiKey": "pexels-key",
113
+ "cacheTtlMs": 86400000,
114
+ "cacheDir": "/tmp/pi-harness-pexels-cache"
115
+ }
116
+ },
117
+ "tools": {
118
+ "webSearch": {
119
+ "model": "brave.llm-context"
120
+ },
121
+ "generateImage": {
122
+ "model": "qwen-image-2.0-pro",
123
+ "size": "2048*2048",
124
+ "taskTimeoutMs": 300000,
125
+ "taskPollIntervalMs": 1000
126
+ },
127
+ "generateSpeech": {
128
+ "model": "qwen-audio-3.0-tts-flash",
129
+ "voice": "longanhuan_v3.6"
130
+ },
131
+ "imageCaption": {
132
+ "provider": "openai",
133
+ "model": "qwen-vl-max",
134
+ "systemPrompt": "Return an accurate image caption.",
135
+ "prompt": "Describe this image in detail for another model."
136
+ },
137
+ "code": {
138
+ "bashTimeoutSeconds": 300,
139
+ "fullStackBuildTimeoutMs": 300000,
140
+ "previewPort": 3000,
141
+ "previewUrl": "http://127.0.0.1:3000"
142
+ },
143
+ "documents": {
144
+ "sofficePath": "/path/to/soffice"
145
+ }
146
+ }
147
+ }
148
+ }
149
+ ```
150
+
151
+ Only configure fields required by the tools you enable. Defaults are applied when optional fields are absent. Unknown `harnesses` fields fail at startup instead of being silently ignored. A missing service credential produces a tool error only when that service-backed tool is called.
152
+
153
+ Execution capabilities reuse Pi's native settings instead of defining harness-specific
154
+ duplicates: `npmCommand` controls npm invocation, `shellPath` selects the command shell,
155
+ and Pi resolves that shell with its normal cross-platform fallback behavior. Routify,
156
+ DashScope, and Pexels HTTP requests use `retry.provider.maxRetries` and
157
+ `retry.provider.maxRetryDelayMs`; the top-level retry count remains Pi's agent-turn
158
+ policy. The `harnesses` namespace contains only capability-specific settings that Pi
159
+ does not own.
160
+
161
+ Tool service and model configuration does not read the legacy `ARENA_*`, `CODE_HARNESS_*`, `DASHSCOPE_*`, `ROUTIFY_*`, or `PEXELS_*` variables. Subprocess tools still inherit the normal process environment so builds and user programs can access their own environment variables; the runtime also injects workspace-path variables for command compatibility.
162
+
163
+ The settings file can contain plaintext service credentials. Restrict it to the current user:
164
+
165
+ ```bash
166
+ chmod 600 ~/.pi/agent/settings.json
167
+ ```
168
+
169
+ ### Main model versus tool models
170
+
171
+ - `defaultProvider`, `defaultModel`, model selection CLI flags, thinking level, retry, and compaction are handled by Pi.
172
+ - `npmCommand` and the shell resolved from `shellPath` are consumed by execution capabilities. External HTTP clients use `retry.provider.maxRetries` and `retry.provider.maxRetryDelayMs`.
173
+ - `harnesses.tools.webSearch`, `generateImage`, and `generateSpeech` configure the corresponding external tool calls.
174
+ - `harnesses.tools.imageCaption` is optional. When the active Pi model cannot read images, `read_file` sends the image to this Pi-registered side model and returns its caption. The side model uses Pi's model registry and credentials; `provider` and `model` must resolve through the same Pi installation.
175
+
176
+ ## Profile isolation
177
+
178
+ | Profile | Distinct behavior |
179
+ | --- | --- |
180
+ | `agent-arena` | General workspace agent tools, multimodal file reading, search, image and speech generation, and interactive `ask_user` |
181
+ | `code-arena-html` | Single-file HTML tools with a smaller edit/search/media tool set |
182
+ | `code-arena-react` | React/Vite file tools, package installation, build validation, research, media search, and image generation |
183
+ | `code-arena-full-stack` | Next.js/PostgreSQL tools, bash, managed build/start validation, research, media search, and image generation |
184
+ | `long-horizon` | A supervisor session coordinating fresh Manager, Executor, and Auditor child Pi sessions through `pi-subagents` |
185
+
186
+ ### Long-horizon orchestration
187
+
188
+ The `long-horizon` profile gives the parent session only `ask_user` and the explicitly
189
+ loaded `pi-subagents` tools. It runs three namespaced harness-owned agents in order:
190
+
191
+ ```text
192
+ long-horizon.manager → long-horizon.executor → long-horizon.auditor
193
+ ```
194
+
195
+ Each role starts with fresh context. Manager has no workspace tools. Executor receives
196
+ Pi's native `read`, `bash`, `edit`, `write`, `grep`, `find`, and `ls` tools; Auditor
197
+ receives the native `read`, `bash`, `grep`, `find`, and `ls` tools. No custom child tool
198
+ extension is loaded. The parent repeats the cycle until an Auditor independently reports
199
+ complete, clean, contract-aligned evidence.
200
+
201
+ Role definitions ship under `.pi/agents/long-horizon/`. At startup, the profile resolves
202
+ that catalog relative to the installed `@qwen-code/qwen-harness` package, independently of the
203
+ task workspace. Future harnesses can add their own subdirectory and unique `package`
204
+ namespace under `.pi/agents/`. The Long Horizon Supervisor also registers an
205
+ `allowedAgents` capability ceiling, so it cannot launch roles belonging to another harness
206
+ even though Pi discovers the shared packaged agent catalog. Parent and child sessions
207
+ remain separate so Harbor can capture them as related trajectories instead of flattening
208
+ distinct tool contracts into one conversation.
209
+
210
+ The source tree keeps every atomic capability under one `capabilities/` boundary,
211
+ grouped by how it participates in the harness:
212
+
213
+ ```text
214
+ .pi/
215
+ agents/
216
+ long-horizon/ namespaced Manager, Executor, and Auditor definitions
217
+ src/
218
+ capabilities/
219
+ settings.ts loads Pi-owned settings and composes capability-owned settings
220
+ tools/
221
+ settings.ts composes tool-owned settings
222
+ ask-user/ Pi tool adapter for the question workflow
223
+ execution/ tools and their local settings parser
224
+ filesystem/ model-visible workspace file tools
225
+ media/ media tools and their local settings parser
226
+ web/ web tools and their local settings parser
227
+ infrastructure/
228
+ settings.ts composes infrastructure-owned settings
229
+ media/ DashScope and Pexels clients plus their settings parser
230
+ retry.ts provider-style HTTP retry shared by infrastructure clients
231
+ web/ Routify clients and settings parser
232
+ shared/
233
+ capability_settings.ts composes shared capability settings
234
+ ask-user/ interactive question workflow, independent of tool schemas
235
+ filesystem/ document extraction and its settings parser
236
+ image-caption/ side-model perception and its settings parser
237
+ settings.ts shared parsing primitives
238
+ workspace.ts workspace confinement and common result formatting
239
+ harnesses/ each harness system prompt, tool selection, and Pi startup
240
+ entrypoint.ts selects and starts one harness
241
+ ```
242
+
243
+ `capabilities/tools/` contains the Pi-specific exposure layer: tool names, TypeBox
244
+ parameter schemas, descriptions, and result contracts. `capabilities/infrastructure/`
245
+ owns vendor-specific transport and retry behavior. `capabilities/shared/` contains
246
+ reusable implementations that are not independently exposed to the model. For example,
247
+ the `ask_user` tool delegates to the shared interactive-question workflow, while
248
+ `read_file` composes document extraction, image captioning, and workspace confinement.
249
+ Plain-text reads and filesystem search delegate their result limits, truncation, and
250
+ continuation notices to Pi instead of defining harness-specific caps.
251
+ Each capability-owned settings parser lives beside that capability; the root
252
+ `capabilities/settings.ts` only loads Pi settings and composes the three category-level
253
+ settings objects. Adding a capability changes its local parser and category composition,
254
+ not the root loader.
255
+
256
+ Dependencies point inward: harnesses select `capabilities/tools`, tools may compose
257
+ `shared` and `infrastructure`, and those lower layers do not import tool adapters. Both
258
+ `fetch_page` and `web_fetch` use Routify; `fetch_page` adds its own 8,000-character
259
+ chunking and cache.
260
+ Each file under `src/harnesses/` still owns a complete runnable profile: its system prompt,
261
+ selected tool factories, inline-extension registration, and Pi startup.
262
+
263
+ ## Sessions and resume
264
+
265
+ Sessions use Pi's native storage under `~/.pi/agent/sessions/`, organized by working directory. Pi writes its append-only JSONL containing messages, tool calls/results, usage, model changes, and compaction entries.
266
+
267
+ ```bash
268
+ npm run agent-arena -- --resume
269
+ npm run code-arena-react -- --continue
270
+ npm run code-arena-html -- --session /absolute/path/to/session.jsonl
271
+ npm run long-horizon -- --resume
272
+ ```
273
+
274
+ Headless modes use the same session behavior:
275
+
276
+ ```bash
277
+ npm run agent-arena -- -p "First turn"
278
+ npm run agent-arena -- --continue -p "Continue"
279
+ npm run code-arena-full-stack -- --mode json "Build the application"
280
+ ```
281
+
282
+ ## Validate
283
+
284
+ ```bash
285
+ npm run check
286
+ npm test
287
+ ```