harness-everything 0.51.0 → 0.53.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.
Files changed (97) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.github/workflows/ci.yml +23 -0
  4. package/CHANGELOG.md +54 -0
  5. package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-a-evid-001.md +123 -0
  6. package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-b-route-001.md +130 -0
  7. package/benchmarks/results/live-host/opencode-2026-11-15-workspace/README.md +7 -0
  8. package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-probe.js +16 -0
  9. package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-trace-2026-11-15.jsonl +4 -0
  10. package/ci/mechanism-2am-observations-session-import.test.js +4 -1
  11. package/ci/mechanism-2n-opencode-plugin.test.js +1 -1
  12. package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +18 -3
  13. package/ci/mechanism-338-opencode-async.test.js +20 -3
  14. package/ci/mechanism-34-observations.test.js +127 -23
  15. package/ci/mechanism-341-opencode-lane.test.js +7 -1
  16. package/ci/mechanism-349-ci-change-scope.test.js +260 -0
  17. package/ci/mechanism-397-cycle-import.test.js +399 -0
  18. package/ci/mechanism-397-host-acceptance.test.js +119 -0
  19. package/ci/mechanism-397-opencode-observations.test.js +1922 -0
  20. package/ci/mechanism-handoff-file.test.js +121 -0
  21. package/ci/mechanism-system-one-contract.test.js +9 -2
  22. package/ci/mechanism-system-one-curves.test.js +223 -0
  23. package/ci/mechanism-system-one-cycle.test.js +1204 -0
  24. package/ci/mechanism-system-one-evaluation.test.js +32 -5
  25. package/ci/mechanism-system-one-handoff-input.test.js +208 -0
  26. package/ci/mechanism-system-one-install.test.js +202 -77
  27. package/ci/mechanism-system-one-live.test.js +361 -0
  28. package/ci/mechanism-system-one-relevance.test.js +11 -1
  29. package/ci/mechanism-system-one-train.test.js +136 -53
  30. package/ci/system-one-adapter-test.py +331 -0
  31. package/ci/system-one-train-test.py +116 -24
  32. package/docs/adr/EVID-001.md +123 -0
  33. package/docs/adr/ROUTE-001-error-lesson-delivery.md +305 -0
  34. package/docs/governed-index.md +2 -0
  35. package/docs/platform-capabilities.md +13 -6
  36. package/docs/routing.md +2 -2
  37. package/docs/system-one-cycle.md +77 -0
  38. package/docs/system-one-observations.md +43 -11
  39. package/docs/system-one-routing.md +163 -115
  40. package/docs/system-one-suggestion-gates.md +6 -8
  41. package/docs/system-one-training.md +44 -7
  42. package/docs/workflow-runtime.md +19 -0
  43. package/harness-everything/SKILL.md +1 -1
  44. package/harness-everything/scripts/kernel-router.js +2 -1
  45. package/harness-everything/scripts/system-one/contract.js +19 -15
  46. package/harness-everything/scripts/system-one/cua_adapter.py +211 -17
  47. package/harness-everything/scripts/system-one/evaluate.js +4 -9
  48. package/harness-everything/scripts/system-one/handoff-input.js +76 -0
  49. package/harness-everything/scripts/system-one/install.js +281 -113
  50. package/harness-everything/scripts/system-one/manifest.js +58 -0
  51. package/harness-everything/scripts/system-one/provider.js +96 -2
  52. package/harness-everything/scripts/system-one/resident.js +47 -1
  53. package/harness-everything/scripts/system-one/router.js +80 -1
  54. package/harness-everything/scripts/tier-router.js +21 -6
  55. package/hooks/scripts/lib/observations.js +48 -7
  56. package/opencode-plugin/README.md +22 -8
  57. package/opencode-plugin/index.mjs +424 -44
  58. package/opencode-plugin/plugin.json +1 -1
  59. package/package.json +1 -1
  60. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  61. package/plugins/harness-everything/hooks/scripts/lib/observations.js +48 -7
  62. package/plugins/harness-everything/plugin.json +1 -1
  63. package/plugins/harness-everything/scripts/handoff-file.js +223 -0
  64. package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
  65. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +2 -1
  66. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/contract.js +19 -15
  67. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +211 -17
  68. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/evaluate.js +4 -9
  69. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/handoff-input.js +76 -0
  70. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +281 -113
  71. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +58 -0
  72. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +96 -2
  73. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +47 -1
  74. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +80 -1
  75. package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +21 -6
  76. package/sbom.cdx.json +7 -7
  77. package/scripts/ci-change-scope.js +59 -0
  78. package/scripts/handoff-file.js +223 -0
  79. package/scripts/sync-openai-plugin.js +4 -0
  80. package/scripts/system-one-calibrate.js +108 -41
  81. package/scripts/system-one-curves.js +472 -0
  82. package/scripts/system-one-cycle/adjudication-input.js +65 -0
  83. package/scripts/system-one-cycle/build.js +165 -0
  84. package/scripts/system-one-cycle/collect.js +67 -0
  85. package/scripts/system-one-cycle/common.js +175 -0
  86. package/scripts/system-one-cycle/engines.js +62 -0
  87. package/scripts/system-one-cycle/evaluate.js +73 -0
  88. package/scripts/system-one-cycle/judge.js +106 -0
  89. package/scripts/system-one-cycle/label.js +59 -0
  90. package/scripts/system-one-cycle/package.js +173 -0
  91. package/scripts/system-one-cycle/score.py +111 -0
  92. package/scripts/system-one-cycle/train.js +136 -0
  93. package/scripts/system-one-cycle.js +136 -0
  94. package/scripts/system-one-observations-export.js +58 -6
  95. package/scripts/system-one-observations-import-store.js +128 -0
  96. package/scripts/system-one-observations-review.js +4 -5
  97. package/scripts/system-one-train.py +117 -61
@@ -0,0 +1,77 @@
1
+ # System One monthly training cycle
2
+
3
+ The owner starts one cycle when ready. The public repository supplies the scripts; prompts, labels, checkpoints, and version packages stay in a private data directory. This runbook has no manual label or spot-check step.
4
+
5
+ ```mermaid
6
+ flowchart LR
7
+ A[collect local observations] --> B[label current text with Luna]
8
+ B --> C[judge self vs Luna disagreements]
9
+ C --> D[build CUA-S1 dataset]
10
+ D --> E[train validity, intent, tier]
11
+ E --> F[score fixed holdouts and compare curves]
12
+ F --> G[package private version directory]
13
+ G --> H[publish to private models/cua-s1 directory]
14
+ ```
15
+
16
+ ## Before the monthly run
17
+
18
+ - Use a fresh, private directory for this cycle, outside the Harness checkout. On POSIX hosts the scripts set directory permissions to `0700` and data files to `0600`; on Windows, use a user-private directory with a restrictive ACL.
19
+ - For cross-month comparisons, choose one absolute private history file outside the checkout and every cycle directory, then pass the same `--history` path to each month's `evaluate` or `all` command. If omitted, history remains at `<private-cycle-dir>/training/history.jsonl` for compatibility and is cycle-local.
20
+ - Set `--since` to the last completed collection boundary. `collect` requires this date and accepts an optional `--sessions` path for a non-default Codex session directory.
21
+ - Pick a version id containing letters, numbers, dots, underscores, or hyphens. Reuse the same data directory and version id to resume; use a new directory for the next month.
22
+ - Replace the placeholders in the commands below with real paths, dates, and a version id.
23
+
24
+ ## Steps
25
+
26
+ | Step | Command | Inputs → outputs | Typical duration and resources¹ | Resume |
27
+ |---|---|---|---|---|
28
+ | Collect | `node scripts/system-one-cycle.js collect --data-dir "<private-cycle-dir>" --since <YYYY-MM-DD>` | Local Codex session observations and the local observation store → `training/observed/prompts-observed.jsonl`, `labels-observed.jsonl`, and a count-only export report. Previous-message text and self `contextDependent` fields are removed. | Minutes for a local session scan; low CPU and local disk. | The completed step is recorded in `cycle-state.json`. Start another month in a new directory. |
29
+ | Label | `node scripts/system-one-cycle.js label --data-dir "<private-cycle-dir>"` | Current text only → Luna tier and intent rows in `training/relabel-luna/`. `null` maps to invalid; every other tier label maps to actionable for the validity stage. | Model latency dominates. Defaults: batches of 20, concurrency 4. | Rows already written are skipped by id. Failed batches are recorded with ids and reason codes, then retried on the next invocation. |
30
+ | Judge | `node scripts/system-one-cycle.js judge --data-dir "<private-cycle-dir>"` | Self tier and text-only Luna tier disagreements → private `training/adjudication/input.jsonl` and `consensus.jsonl`. Two independent votes are collected from Luna and OpenCode using current text and candidate labels. | Two model calls per batch of up to 20 disagreements; low local memory. | Completed majority and no-majority rows are skipped. Failed batches have no consensus row and are retried. A split vote is dropped during build; it does not request human review. |
31
+ | Build | `node scripts/system-one-cycle.js build --data-dir "<private-cycle-dir>"` | Observed text, Luna labels, consensus, behavior contradictions, and the existing frozen holdouts → consensus-adjusted tier/intent rows under `training/v1/`, raw Luna validity labels under `training/v1-validity/`, and a count-only report. | Usually seconds to minutes; memory grows with the dataset. | Safe to rerun; outputs are rebuilt from the current input files. Validation copies win over normalized train duplicates. |
32
+ | Train | `node scripts/system-one-cycle.js train --data-dir "<private-cycle-dir>" --version <version-id>` | The validity task reads raw Luna labels from `training/v1-validity/`; tier and intent read the consensus-adjusted dataset in `training/v1/`. Outputs CUA-S1 checkpoints, catalog-keyed validation scores, a trainer report with the catalog IDs, calibration, and `resource-guard.json` under `training/runs/<version-id>/`. | CPU training with 4 threads by default and a 6144 MB RSS ceiling. Duration depends on row count and epochs. | Completed stages are reused. If interrupted inside a stage, that stage starts again; earlier completed stages are kept. |
33
+ | Evaluate | `node scripts/system-one-cycle.js evaluate --data-dir "<private-cycle-dir>" --version <version-id> [--history "<absolute-private-history.jsonl>"]` | Candidate checkpoints, validation scores, and the existing frozen holdouts → score files, `curves.json`, and `trend.json` in a candidate version directory. The scorer follows the trainer catalog; curves uses the shared manifest validator and requires each score row's keys to match the stage options. It appends one immutable version row to the selected history file. | CPU scoring at one thread plus the curve calculation; typically seconds to minutes after checkpoint loading. | Cached curves and trend are reused. If the selected history lacks that version row, resume validates and appends the saved curves once without rescoring. Conflicting reuse fails. |
34
+ | Package | `node scripts/system-one-cycle.js package --data-dir "<private-cycle-dir>" --version <version-id>` | Trained candidate and evaluation artifacts → `training/versions/<version-id>/manifest.json` with three stage entries, relative artifact paths, thresholds, and weight SHA-256 values. The trainer catalog is the source of truth: intent includes `unclassified`, and catalog IDs, score keys, manifest options, and threshold keys agree. A `null` calibration threshold becomes `1` and the stage lists that option under `referenceOnly`, so its score stays available while it is excluded from automatic decisions. | A local file copy and hashes; usually seconds. | Safe to rerun. Repackaging an older candidate that omitted only intent `unclassified` metadata restores it as reference-only without retraining. Evaluation references carry forward. |
35
+ | Publish | `node scripts/system-one-cycle.js publish --data-dir "<private-cycle-dir>" --version <version-id>` | `training/versions/<version-id>/` → `models/cua-s1/<version-id>/` in the same private data directory. It prints the published path; it does not use Git. The installer reads this model directory. | A local file copy; usually seconds. | Published version ids are immutable. Use a new id for changed weights; an existing destination is not overwritten. |
36
+
37
+ ¹ Durations are planning estimates, not measurements from this checkout. Model latency and dataset size vary.
38
+
39
+ F6 extends per-stage manifest metadata with `referenceOnly`; it does not
40
+ authorize an additional top-level `workflowPlan.systemOne` field. The routing
41
+ guide records the separate H1b output enrichment and the unresolved output
42
+ shape discrepancy.
43
+
44
+ ## Run or resume the ordered path
45
+
46
+ Run the full cycle with one command:
47
+
48
+ ```sh
49
+ node scripts/system-one-cycle.js all --until publish --data-dir "<private-cycle-dir>" --since <YYYY-MM-DD> --version <version-id> --history "<absolute-private-history.jsonl>"
50
+ ```
51
+
52
+ `all` runs each step in order and stops at `--until`; it passes `--history` through to evaluation. Completed collection, label, and judge steps with their outputs are skipped. If a label or judge batch fails, `all` stops at that step without marking it complete; rerun the same command to resume. `build` can be rerun. Training resumes between completed stages; evaluation reuses complete curve artifacts; packaging can be repeated. Publish only after packaging, then use the private data directory as the install source described in the [System One routing guide](system-one-routing.md).
53
+
54
+ ## Cross-cycle history and floor baseline
55
+
56
+ - History is append-only. Reusing a version id is allowed only when its saved curve content matches; duplicate or conflicting version rows fail without overwriting existing history.
57
+ - Cached resume is accepted only when the selected history reproduces its saved baseline, ordered predecessor comparisons, and verdict; incompatible history is rejected without changing history or saved artifacts.
58
+ - Each stage keeps the first compatible historical holdout row as its floor baseline. Later rows record the baseline version and compare against that same row, including after partial recovery.
59
+ - A supplied history path must resolve outside the repository and name a file. Malformed history fails visibly. On POSIX, newly created history directories and files use `0700` and `0600`; existing shared parent permissions are left alone. Windows ACLs remain the operator's responsibility.
60
+ - The two-consecutive-cycle detector uses the latest three evaluation rows as its active-trend proxy. It does not identify the version currently installed; active-version rollback semantics remain with #443.
61
+
62
+ For a synthetic integration check that does not read local session data or invoke model engines, prepare the earlier stage artifacts and completion entries under `.s1-work/`, then run:
63
+
64
+ ```sh
65
+ node scripts/system-one-cycle.js all --until build --data-dir ".s1-work/<synthetic-cycle-dir>"
66
+ ```
67
+
68
+ Repository-local build input is accepted only under `.s1-work/` and only when each fixture text is marked synthetic.
69
+
70
+ ## Label and privacy policy
71
+
72
+ - Luna sees only each current text. Agent-dispatch requests remain valid when their text states the requested work. A `null` tier is reserved for text that requires prior conversation context to understand.
73
+ - The self `contextDependent` flag does not affect labels. Self tier disagreements and primary-intent disagreements with Luna enter the two-judge vote.
74
+ - If a majority exists, build uses that tier; with no majority or no vote, it drops the disagreement. A `tier1-with-writes` behavior contradiction raises the final tier to `tier2`.
75
+ - Validity uses Luna's original text-only tier result: null means invalid and any tier means actionable, even if the adjudicated tier differs. Tier uses consensus; intent uses Luna on agreement or an intent-vote majority, and an unresolved intent is omitted from intent training only.
76
+ - Reports and failure records contain counts, ids, field names, or reason codes only. Current and previous prompt text stays in the private cycle files and is not printed by the cycle commands.
77
+ - The cycle trains only CUA-S1 validity, intent, and tier stages. It does not train ngram or Laya models, create a new owner-reviewed holdout, publish weights to Git, or activate a version. `publish` copies the package inside the private data directory; installation and active-pointer changes are handled by the opt-in runtime workflow.
@@ -2,9 +2,10 @@
2
2
 
3
3
  Status: **accepted**, 2026-09-27. Owner decisions are recorded below.
4
4
  Implementation: `hooks/scripts/observation-hook.js`,
5
- `hooks/scripts/lib/observations.js`, `scripts/system-one-observations-export.js`, `scripts/system-one-observations-import-codex-sessions.js` and
5
+ `hooks/scripts/lib/observations.js`, `scripts/system-one-observations-export.js`, `scripts/system-one-observations-import-codex-sessions.js`,
6
+ `scripts/system-one-observations-import-store.js` and
6
7
  `scripts/system-one-observations-review.js`; tests in
7
- `ci/mechanism-34-observations.test.js`. Issue
8
+ `ci/mechanism-34-observations.test.js` and `ci/mechanism-397-cycle-import.test.js`. Issue
8
9
  [#233](https://github.com/dyphn1/Harness-everything/issues/233).
9
10
 
10
11
  ## Why
@@ -29,7 +30,7 @@ validity, intent, tier, workflow and skills.
29
30
  - Collection is **on by default**, with no environment variable needed to
30
31
  enable it. `HARNESS_OBSERVATIONS=off` turns it off; this opt-out exists
31
32
  because the plugin ships to other users.
32
- - Hosts: **Claude Code** and **Codex** first.
33
+ - Hosts: **Claude Code**, **Codex** and **OpenCode**.
33
34
  - This document is the specification; implementation follows
34
35
  docs → RED → GREEN.
35
36
 
@@ -43,6 +44,7 @@ A turn runs from `UserPromptSubmit` to `Stop`. Its record:
43
44
  | `prompt` | `UserPromptSubmit` | stored in the private text store only (see Storage) |
44
45
  | `previous` | the last assistant message before the prompt | truncated to 2 KB; text store only |
45
46
  | `router` | kernel-router output | lexical tier, strategy, normalized knowledge signals, active step/stage bindings; System One shadow scores when present |
47
+ | `router.systemOne` | `workflow-run.json` → `workflowPlan.systemOne` | bounded version, hash, mode, scores and decision; unknown keys are dropped, scores are clamped to 0..1, and malformed or missing input is stored as `null`. Scores remain in the private store only. |
46
48
  | `behavior` | `PostToolUse`, `PostToolUseFailure` | counts and categories, never arguments: files written, distinct repositories written, files created, commands by class (git, gh, test, build, package, shell), skills loaded or read, subagents started. Failed attempts are counted separately (`toolFailures`, `failedWrites`, `failedSkillLoads`) and never count as a write or a load. `null` means the capture source did not observe tool events; it is not a zero count. |
47
49
  | `workflow` | `workflow-run.json` / `workflow-disposition` | selected and confirmed strategy |
48
50
  | `selfReport` | label line in the final message | see below; `null` if missing or invalid |
@@ -54,13 +56,12 @@ At the end of the final message of each turn the agent writes one line,
54
56
  which is invisible in rendered Markdown:
55
57
 
56
58
  ```
57
- <!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier2","intents":["fix","test"],"workflow":"iterative-single","skills":["tdd"]} -->
59
+ <!-- harness-label {"v":1,"validity":"actionable","tier":"tier2","intents":["fix","test"],"workflow":"iterative-single","skills":["tdd"]} -->
58
60
  ```
59
61
 
60
62
  | Key | Values |
61
63
  | --- | --- |
62
- | `validity` | `actionable` or `invalid` (continuation, feedback on earlier work, pointer to earlier content, paste or chatter) |
63
- | `contextDependent` | `true` when the prompt text alone would not have been enough to know the task |
64
+ | `validity` | `actionable` or `invalid`; invalid means the prompt cannot be understood from its own text and needs conversation context. Agent-written dispatches and worker instructions are ordinary prompts. |
64
65
  | `tier` | `tier1` (no file change), `tier2` (bounded file change: code, config or docs), `tier3` (feature, refactor, redefinition, cross-component) or `null` (only for `invalid`), under tier rules v2 |
65
66
  | `intents` | up to 3 of the 12 intent ids, strongest first |
66
67
  | `workflow` | a router strategy id or `null` |
@@ -76,13 +77,13 @@ accepted when it ends the message.
76
77
 
77
78
  ## Labels and how much to trust them
78
79
 
79
- The label is the host LLM's own judgement. It saw the whole conversation and
80
- did the work, so no fixed rule replaces it (owner decision, 2026-09-27: no
81
- file-count threshold for tier).
80
+ Validity is judged from the prompt text alone, even when the agent saw the
81
+ whole conversation. The other keys are the host LLM's own judgement; no
82
+ fixed rule replaces tier (owner decision, 2026-09-27: no file-count threshold).
82
83
 
83
84
  | Label | Source | Override |
84
85
  | --- | --- | --- |
85
- | validity, contextDependent | self-report | owner review |
86
+ | validity | self-report, judged from prompt text alone | owner review |
86
87
  | intents | self-report | — |
87
88
  | tier | self-report (tier rules v2) | owner review |
88
89
  | workflow | self-report, else the confirmed strategy | — |
@@ -173,6 +174,8 @@ warning sign. The review page samples the turns where they differ.
173
174
  cannot read Codex trust state.
174
175
  - The final message comes from the rollout's `task_complete` event.
175
176
  - Fresh live-host verification on Windows (Codex CLI 0.162.1, 2026-10-13) exercised the user-hook compatibility fallback: only the `UserPromptSubmit` and `Stop` observation hooks were individually reviewed/trusted. Two consecutive real turns produced `host: "codex"` records with distinct current `turn_id` values and their respective valid self-reports. The sanitized record excerpt and scope limits are preserved in [Codex live-host evidence](../benchmarks/results/live-host/codex-2026-10-13/README.md). This does not verify native plugin-bundled hooks, other lifecycle events, or tool behavior capture.
177
+ - **OpenCode 2.x:** the plugin's documented `prompt` hook captures the original user text and runs the canonical kernel router; its `context` hook adds that router output, including the exact label instruction, to primary model requests. OpenCode tool events and `session.idle` feed the shared observation library, which reads the current turn's final assistant text through the session context API. `HARNESS_OBSERVATIONS=off` disables capture while routing injection remains active. Deterministic mechanism tests cover injection, turn recording, malformed labels, and opt-out; there is no retained live-host artifact for these hooks yet.
178
+ - The OpenCode exporter reports malformed `label-invalid` and `label-unparseable` records by host in `malformedLabelsByHost`; missing labels remain a separate reason and count.
176
179
  - The final message must belong to the current turn. A transcript scan
177
180
  stops at the start of the current turn (Codex `task_started` or a user
178
181
  message; a Claude user prompt) and a Codex `task_complete` must carry the
@@ -195,13 +198,42 @@ The importer scans local Codex rollout files and pairs each completed turn with
195
198
 
196
199
  The importer accepts only valid label lines, applies the same email/home-path redaction, and appends idempotently to the private observations store. Backfill and live hook records deduplicate by `(host, writer.sessionId, writer.turnId)`. For older live records without a turn ID, an exact turn-and-text match is skipped; a partial match is counted as ambiguous and skipped to avoid silently duplicating training data. Duplicate and ambiguous legacy live matches are checked atomically under the store lock. A bounded lock timeout is reported as a persistence failure, not as a duplicate, and gives the importer a nonzero exit status; migration lock timeouts are reported the same way. Existing backfill behavior placeholders are migrated to `null`. Reports contain counts and generic error descriptions without printing session text. The cutoff defaults to the date the label contract was accepted. The importer never uploads or writes session content into the repository.
197
200
 
201
+ ## Cycle import boundary
202
+
203
+ The `collect` step writes only to its private cycle directory. It runs Codex
204
+ session backfill, then imports every in-window record from the live store at
205
+ `observations.storeRoot()` (overridable with `HARNESS_OBSERVATIONS_DIR`). The
206
+ store importer preserves unlabeled and malformed-label metadata, including
207
+ its reason code, and deduplicates through `appendRecordDetailed` by host,
208
+ session and turn. It copies text only while the source record's original
209
+ retention deadline permits it; missing or expired text stays unavailable.
210
+
211
+ ```mermaid
212
+ flowchart LR
213
+ OC[OpenCode and other live capture] --> LS[Private live observation store]
214
+ CS[Codex session backfill] --> CY[Private cycle observation store]
215
+ LS --> IM[Cycle store importer]
216
+ IM --> CY
217
+ CY --> EX[Prompt and label exports]
218
+ IM --> IR[Text-free import-report.json]
219
+ ```
220
+
221
+ `import-report.json` records each source's status and per-host persisted,
222
+ duplicate, ambiguous and failed import counts. It contains a stable label for
223
+ the live store rather than its path. Final label rows retain their `host` so
224
+ OpenCode and Codex examples remain attributable after collection.
225
+
198
226
  ## Export
199
227
 
200
228
  `scripts/system-one-observations-export.js` writes to the private data
201
229
  repository:
202
230
 
203
231
  - `prompts-observed.jsonl`: `{id, family, source: "observation", split, text}`
204
- - `labels-observed.jsonl`: `{id, validity, contextDependent, tier, tierSource, intents, workflow, skills, behaviorEvidence, contradictions}`
232
+ - `labels-observed.jsonl`: `{id, validity, tier, tierSource, intents, workflow, skills, behaviorEvidence, contradictions, host, systemOne}`. `systemOne` is `{version, sha256, mode, decision}` or `null`; score maps stay in the private observation store.
233
+ - `export-report.json`: `systemOne.versions[version]` counts exported rows for each version and reports tier agreement (`matches`, `comparisons`, `rate`) between the router decision and self-report. Comparisons include only rows where both tiers are known.
234
+
235
+ The text-free `export-report.json` includes `malformedLabelsByHost` for invalid
236
+ or unparseable self-reports, including those omitted by `--self-report-only`.
205
237
 
206
238
  `family` groups near-duplicate prompts. The split is by time: the newest 15%
207
239
  is validation. The existing holdouts stay frozen and separate. Observed data
@@ -1,12 +1,12 @@
1
1
  # System One routing migration
2
2
 
3
3
  Status: experimental engineering; issue [#233](https://github.com/dyphn1/Harness-everything/issues/233).
4
- The default router stays lexical until a Harness checkpoint passes the rollout gates.
4
+ The default mode stays `off`. `live` is opt-in for machines with an activated private checkpoint; recorded gate values are baselines and do not block that opt-in.
5
5
  Implement each phase in **documentation → failing tests → implementation** order.
6
6
 
7
7
  ## Phase 0: scorer contract
8
8
 
9
- System One scores a complete, caller-owned candidate list in one pass. It cannot
9
+ For each stage, System One scores the complete, caller-owned candidate list in one pass. It cannot
10
10
  generate a workflow, execute actions, authorize tools, or write memory. Policy and
11
11
  contract assembly remain deterministic. This boundary does not add execution locks.
12
12
 
@@ -22,17 +22,18 @@ fingerprint grants permission or authenticates a model.
22
22
  The provider response has exactly `schemaVersion`, `requestHash`, `catalogHash`,
23
23
  `model`, and `scores`. Model has nonempty `id`, `revision`, and `domain` strings.
24
24
  Scores have exactly `{id, probability}` in request order. All candidates occur
25
- exactly once; probabilities are finite numbers in [0, 1], summing to one within
26
- 1e-6. Unknown fields, stale request/catalog hashes, and version mismatches fail.
25
+ exactly once; probabilities are finite values in [0, 1], as a categorical simplex for legacy checkpoints or independent scores for staged checkpoints. Unknown fields, stale request/catalog hashes, and version mismatches fail.
27
26
 
28
27
  `decide(request, response, policy)` returns exactly `status`, `reason`,
29
28
  `selectedId`, `confidence`, `margin`, and `model`. Status is `accepted`, `abstain`,
30
29
  or `invalid-output`; nonaccepted results always have `selectedId: null`.
31
30
  Policy requires a domain (default `harness-routing-v1`), minimum confidence
32
31
  (default 0.9) and minimum margin (default 0.2). Invalid policy is a caller error.
33
- Reject domain mismatch, tied winners, low confidence and low margin. A softmax
34
- score is not calibrated correctness probability. Invalid output returns no raw
35
- response, exception, or prompt. Identical inputs give identical decisions.
32
+ The legacy `decide` path rejects domain mismatch, tied winners, low confidence
33
+ and low margin. Live stages use their own calibrated per-option thresholds.
34
+ Probabilities are reference confidence, not correctness guarantees. Invalid
35
+ output returns no raw response, exception, or prompt. Identical inputs give
36
+ identical decisions.
36
37
 
37
38
  ## Phase 1: local provider
38
39
 
@@ -70,33 +71,42 @@ VCS URL pinned to that commit (not an editable or local-directory install).
70
71
  The status is `pinned` when it matches, `mismatch` otherwise, or `unavailable`
71
72
  when no revision is recorded. Malformed probe output is `provider-json`.
72
73
 
73
- `npm run system-one:install` (or `node harness-everything/scripts/system-one/install.js`)
74
- performs these steps on explicit request; hooks never run it. It selects a
75
- Python 3.11–3.13 interpreter (`--python` overrides; 3.14 is rejected by upstream),
76
- creates `<dir>/venv`, installs CPU-only torch from the PyTorch CPU index, then
77
- installs the pinned `cua_s1` Git URL. It downloads the `cua-ai/cua-s1-forms`
78
- safetensors weights and JSON sidecar at Hugging Face revision
79
- `f54adbf447f4ca6ec259f529ee3f2e3e09f8cc71`, verifies pinned sizes and SHA-256
80
- before an atomic write (the pickle `.pt` is never fetched), and writes
81
- `<dir>/manifest.json` with `timeoutMs: 10000`, `transport: "resident"` and
82
- `idleTimeoutMs: 1800000`. The default `<dir>` is
83
- `~/.agents/harness-everything/system-one`; `--dir` takes an absolute path and
84
- `--dry-run` prints the plan without changes. Acceptance requires a `pinned`
85
- provenance probe and one real warm CPU inference through a resident server that
86
- the installer starts and then stops; otherwise the exit code is 1. Child-process
87
- output goes to stderr; stdout carries only the JSON report.
88
- Torch/numpy/safetensors versions resolve at install time and are recorded by
89
- the probe. The installer does not change the router mode: it prints
90
- `HARNESS_SYSTEM_ONE_MODE=shadow` and the manifest path for the host
91
- environment. This checkpoint declares domain `forms-v1`, so shadow diagnostics
92
- report `domain-mismatch` and prefer never applies it. It also rejects context
93
- above its 224-byte limit (`provider-exit`), so installing it proves the local
94
- inference path only, not Harness routing quality.
74
+ Install a private checkpoint from a local data-repository checkout or its Git
75
+ SSH URL. The checkout must contain
76
+ `models/cua-s1/<id>/manifest.json` with validity, intent and tier stages:
77
+
78
+ ```sh
79
+ node harness-everything/scripts/system-one/install.js install \
80
+ --from /path/to/private-data-repo --version <id>
81
+ node harness-everything/scripts/system-one/install.js install \
82
+ --from git@host:private/data-repo.git --version <id>
83
+ ```
84
+
85
+ The SSH path uses a shallow sparse clone of the requested checkpoint in a
86
+ temporary cache directory; SSH credentials must come from the local SSH
87
+ configuration, not the URL. The installer verifies each stage's `sha256`, then
88
+ copies the manifest, weights, configs and optional evaluation file to
89
+ `~/.agents/harness-everything/system-one/versions/<id>/`. It also creates the
90
+ dedicated Python 3.11–3.13 virtual environment, installs CPU-only torch and the
91
+ pinned `cua_s1` source. `--python` selects the interpreter, `--dir` selects an
92
+ absolute install directory, and `--dry-run` prints the plan without changes.
93
+ The default directory is `~/.agents/harness-everything/system-one`; set
94
+ `HARNESS_SYSTEM_ONE_HOME` to override it.
95
+
96
+ Installation does not activate a checkpoint. Run
97
+ `node harness-everything/scripts/system-one/install.js activate <id>` to switch
98
+ the atomic `active.json` pointer; it records the prior version for
99
+ `rollback`. `status` reports active and previous versions, verifies their
100
+ checkpoint hashes, and prints the `HARNESS_SYSTEM_ONE_MODE=live` opt-in hint.
101
+ The router remains off by default; set `HARNESS_SYSTEM_ONE_MODE=live` only on
102
+ machines where System One is opted in. The public plugin contains the installer
103
+ code but no private weights.
95
104
 
96
105
  The adapter verifies both files before `load_checkpoint(..., 'cpu')`, sets one
97
106
  torch thread and deterministic inference, calls the upstream collator/model,
98
- and returns a probability for every option. It rejects context or option text
99
- that exceeds the loaded byte limits before collation (no silent truncation).
107
+ and applies a sigmoid independently to each option logit. It rejects context
108
+ or option text that exceeds the loaded byte limits before collation (no silent
109
+ truncation).
100
110
  No prompts or model values are written to disk or echoed in error messages.
101
111
 
102
112
  The Node transport has a hard timeout and a 1 MiB stdout/stderr bound; it kills
@@ -234,44 +244,88 @@ it started. Repository tests use a stub scorer behind the real server/protocol
234
244
  code; they prove the mechanism, not host survival of detached processes or model
235
245
  quality. Those require retained evidence.
236
246
 
237
- ## Phase 2: tier integration and rollback
238
-
239
- Set `HARNESS_SYSTEM_ONE_MODE=off|shadow|prefer` in the host environment. Default
240
- is `off`: no provider process, diagnostic, or contract change. Supply an absolute
241
- `HARNESS_SYSTEM_ONE_CONFIG` path to the Phase 1 manifest for the other modes.
242
- An unknown mode reports `invalid-mode` and leaves the lexical result unchanged.
243
- Shadow records the decision but never changes the route. Prefer replaces only
244
- the recommended tier when a valid `harness-routing-v1` result passes Phase 0
245
- thresholds. The full fixed tier catalog (tier1, tier2, tier3, unclassified) is
246
- always scored; it is never filtered using lexical matches. `unclassified` means
247
- abstention and keeps the existing route. Explicit strategy/model requests keep
248
- precedence and prevent model tier replacement. Set mode back to `off` to roll back.
249
-
250
- Prefer can raise a tier but never lower it below the deterministic structural
251
- floor: a macro-scope signal sets floor `tier3`, and multi-task, multi-sentence
252
- structure (other than a trivial docs edit) sets floor `tier2`. An accepted result
253
- below the floor is not applied and reports `structural-floor`, so repository-wide
254
- work keeps its Tier 3 strategy, independent verification and worktree
255
- invariants. Tier-3 keywords are lexical guesses, not structural floors. The
256
- policy assembler still consumes the original structural and risk signals.
257
- Safety, explicit prohibitions, memory ownership, and verification are not model
258
- outputs. This phase does not yet replace guide matching, dynamic
259
- skill triggers, fact-audit reminders, or the structural workflow signals.
260
- The same scorer API can evaluate caller-supplied text options; additional routing
261
- surfaces require their own catalog and held-out evidence before integration.
262
-
263
- When enabled, a single `SYSTEM ONE` JSON diagnostic reports mode, status, reason,
264
- selected candidate, model identity, confidence and margin; it omits prompt text,
265
- score vectors and artifact paths. The existing router contract schema is unchanged.
266
- Kernel/packaged entry points inherit these host environment variables. Prompts
247
+ ## Phase 2: compatibility modes and staged live routing
248
+
249
+ `HARNESS_SYSTEM_ONE_MODE=off` remains the default. Off starts no provider, emits
250
+ no System One text or workflow field, and preserves the lexical route byte for
251
+ byte. The older `shadow` and `prefer` single-tier modes remain for compatibility
252
+ and use an absolute `HARNESS_SYSTEM_ONE_CONFIG` manifest path. `live` reads the
253
+ active version pointer described below; it does not use that legacy manifest.
254
+ Set the mode back to `off` to roll back. Unknown modes keep the lexical result.
255
+
256
+ Live reads `~/.agents/harness-everything/system-one/active.json`; tests can point
257
+ `HARNESS_SYSTEM_ONE_HOME` at another System One home. The pointer has exactly
258
+ `schemaVersion`, `version`, `dir`, `previous`, and `activatedAt`. Its version
259
+ directory contains `manifest.json` with `schemaVersion`, `version`, `createdAt`,
260
+ `stages`, and `evaluation`. `stages` contains `validity`, `intent`, and `tier`;
261
+ each entry names sibling `weights` and `config` files, the weights `sha256`, its
262
+ ordered trainer-catalog `options`, and one per-option `threshold`. The intent
263
+ catalog includes `unclassified`; validity has only `invalid`, and tier has the
264
+ three tier IDs. Calibration, manifest options, and score rows keep the same
265
+ catalog IDs. An optional
266
+ `referenceOnly` list must be a subset of the stage options, and each listed
267
+ option must have threshold `1`. Its score remains visible in the reference
268
+ readout, but it is excluded from automatic decisions. The router verifies the weight
269
+ hash and the CUA-S1 adapter verifies the checkpoint/config pair before loading.
270
+ The workflow hash is the first 16 hex digits of the tier weights hash. A single
271
+ resident process loads all three checkpoints from that version. The public plugin
272
+ contains the loading and training method, not private weights.
273
+
274
+ Live scores the prompt text in order: validity, then intent and tier only when
275
+ validity is actionable. An invalid result stops later scoring. `p(invalid)` at
276
+ or above its threshold marks the prompt invalid. Each option keeps its own
277
+ sigmoid probability. Intent suggestions include options at or above their
278
+ thresholds, sorted by probability and capped at three. The highest-scoring tier
279
+ is returned only when it meets that tier's own threshold; otherwise the tier
280
+ stage abstains. A tie at the top also abstains.
281
+
282
+ Precedence is structural floor and explicit user/workflow choices, then System
283
+ One, then lexical tier when System One abstains, is invalid or unavailable, or
284
+ mode is off. The structural floor can only raise the route. Existing safety,
285
+ explicit prohibitions, memory ownership, and verification remain deterministic.
286
+
287
+ When a valid active version is available, `workflowPlan.systemOne` records the
288
+ fixed version, weight hash, mode, raw stage probabilities, and thresholded
289
+ decision. Unscored stages are `null`. When System One has no active version, the
290
+ field is omitted. User-visible routing text labels the highest stage options
291
+ with their probabilities as reference confidence, never as a verdict; it does
292
+ not print prompt text or artifact paths. Checkpoint activation is opt-in and the
293
+ default mode remains `off`.
294
+
295
+ H1b separately authorized the handoff count enrichment at
296
+ `inputEnrichment.handoffFiles`. F6 authorized `referenceOnly` as optional
297
+ per-stage manifest metadata; it did not explicitly approve a new top-level
298
+ `referenceOnly` output field. The current router includes both fields in
299
+ `workflowPlan.systemOne`, so the top-level `referenceOnly` field remains an
300
+ unresolved discrepancy against shared contract B. The seven-field contract
301
+ shape is:
302
+
303
+ ```json
304
+ {
305
+ "version": "<active version id>",
306
+ "sha256": "<first 16 hex digits of tier weights hash>",
307
+ "mode": "live",
308
+ "validity": { "invalid": 0.12 },
309
+ "intents": {
310
+ "explain": 0.1, "discuss": 0.12, "git": 0.1, "fix": 0.81,
311
+ "edit": 0.2, "feature": 0.54, "refactor": 0.1, "review": 0.1,
312
+ "test": 0.1, "docs": 0.14, "plan": 0.1, "investigate": 0.1
313
+ },
314
+ "tier": { "tier1": 0.1, "tier2": 0.84, "tier3": 0.62 },
315
+ "decision": { "validity": "actionable", "intents": ["fix"], "tier": "tier2" }
316
+ }
317
+ ```
318
+
319
+ `decision.validity` is `actionable`, `invalid`, or `abstain`. `decision.intents`
320
+ contains up to three above-threshold IDs in probability order. `decision.tier` is
321
+ the unique highest above-threshold tier or `null` when the tier stage abstains.
322
+
323
+ Kernel and packaged entry points inherit host environment variables. Prompts
267
324
  and hook payload fields cannot set model configuration or launch executables.
268
325
  Claude Code settings `env` is hot-reloaded and reaches hooks and every command
269
- the agent runs; Codex hooks inherit the `codex` process environment, so a Codex
270
- started from an ordinary terminal needs user/OS-level variables (which then apply
271
- to every program the user starts). The recommended setting is `off` until a
272
- `harness-routing-v1` checkpoint passes the rollout gates.
273
- Repository tests establish mechanism/package evidence only; actual host loading
274
- and semantic quality remain unverified until retained sessions demonstrate them.
326
+ the agent runs; Codex hooks inherit the `codex` process environment. Repository
327
+ tests establish mechanism and package evidence only; live host loading and
328
+ behavioral quality require retained host evidence.
275
329
 
276
330
  ## Phase 3: corpus and paired evaluation
277
331
 
@@ -340,7 +394,7 @@ unversioned download during a prompt hook.
340
394
  | --- | --- | --- |
341
395
  | 0 | Versioned option-scoring boundary | Complete positive/negative contract tests |
342
396
  | 1 | Local CUA-S1 adapter | Bounded subprocess, artifact validation, explicit failures |
343
- | 2 | Router integration | Off/shadow/prefer, existing policy invariants, rollback |
397
+ | 2 | Router integration | Off/shadow/prefer/live, active pointer, precedence, rollback |
344
398
  | 3 | Corpus and paired evaluator | Leakage checks, coverage/error metrics, repeatability |
345
399
  | 4 | Harness training and rollout | Real checkpoint, reviewed holdout, measured host results |
346
400
 
@@ -349,50 +403,44 @@ Phase 4 training data, labeling, calibration and release are defined in
349
403
 
350
404
  ## Staged classification
351
405
 
352
- System One answers three narrow questions in sequence instead of one broad
353
- question. Each stage is its own fixed catalog, scorer request and holdout, so a
354
- small model only has to separate a few options at a time.
355
-
356
- 1. **Tier**: `tier1`, `tier2`, `tier3` or `unclassified`, following
357
- [system-one-corpus.md](system-one-corpus.md).
358
- 2. **Intent**: the kind of work the prompt asks for, drawn from the owner's
359
- fixed catalog in [system-one-intent.md](system-one-intent.md): `explain`,
360
- `discuss`, `git`, `fix`, `edit`, `feature`, `refactor`, `review`, `test`,
361
- `docs`, `plan`, `investigate` or `unclassified`. A prompt has one primary
362
- intent and may have secondary intents.
363
- 3. **Skill relevance**: candidate signals for requirement composition,
364
- scored against canonical skill descriptions. These candidates do not select
365
- paths, trigger loads, or bypass the active-step binding contract.
366
-
367
- Each stage has its own gates, and a stage ships only when it passes them.
368
- The relevance-native plan in
369
- [system-one-suggestion-gates.md](system-one-suggestion-gates.md#readout-per-stage)
370
- adds a validity stage first and runs intent before tier, because tier3 is
371
- composed from the intent scores. Tier was trained first because the
372
- reviewed holdout exists for it. Later stages reuse the
373
- same collector, labeler, trainer and evaluator with a different catalog.
374
- Relevance candidates are advisory inputs to requirement composition: explicit
375
- workflow requests, action gates, memory ownership, the Rule of 3 and
376
- deterministic policy always take precedence. A candidate becomes a skill path
377
- only when a specific ordered requirement declares it as a binding.
378
-
379
- ## Rollout gates
380
-
381
- Model-quality gates for relevance-native candidates are defined in
382
- [system-one-suggestion-gates.md](system-one-suggestion-gates.md), which
383
- supersedes the precision/coverage/latency targets below. The holdout size,
384
- provenance, repeatability and advisory rules below still apply.
385
-
386
- Phase 4 requires a separately reviewed, family-disjoint holdout of at least 200
387
- cases, at least 50 each in English and Traditional Chinese. System One output is
388
- advisory: it informs requirement composition and provides skill-relevance
389
- candidates. It never grants, removes policy, or loads paths. The owner therefore
390
- set the target at accepted precision ≥85% (the
391
- 80–90% band), coverage ≥80%, and macro-F1 at least the lexical baseline. A
392
- probabilistic scorer small enough to ship inside a skills plugin (a few MB, not
393
- hundreds) is not expected to reach 98%.
394
- Policy invariants must remain intact in every case; repeat decisions twice with
395
- 100% agreement. Record checkpoint/source hashes, CPU, OS, runtime, thread count,
396
- cold latency and warm p95 (target ≤100ms). Synthetic fixtures and mock providers
397
- only validate mechanisms. They cannot satisfy these model/behavior gates.
398
- Until measured evidence passes, retain the default, fallback and this open issue.
406
+ Live routing scores three fixed catalogs in order. Validity is `actionable` or
407
+ `invalid`; the intent catalog contains the twelve work intents plus
408
+ `unclassified`; and the tier catalog contains `tier1`, `tier2`, and `tier3`.
409
+ `unclassified` remains in intent score rows and manifest metadata, but is never
410
+ auto-selected or included in the output intent probability map.
411
+
412
+ Invalid prompts receive no intent or tier suggestion. For actionable prompts,
413
+ all intent options are scored independently and up to three above-threshold
414
+ suggestions are reported. Tier uses its own per-option thresholds and abstains
415
+ when no tier meets its threshold. The live tier readout is independent of intent
416
+ scores. System One does not choose workflow strategies or skill paths in this
417
+ contract; explicit workflow requests, action gates, memory ownership, the Rule
418
+ of 3 and the active-step binding contract remain deterministic.
419
+
420
+ In opt-in `live` mode, System One may also read up to three file paths written
421
+ in the prompt: absolute paths, or paths relative to the session working
422
+ directory that stay within it. It considers only existing regular files up to
423
+ 1 MiB and reads at most the first 2 KiB with the shared
424
+ [`handoff-file.js`](../scripts/handoff-file.js) parser. A valid
425
+ `harness-handoff` header adds one `[handoff] kind=... title=... summary=...`
426
+ line per file to the System One scoring input; file bodies are never read.
427
+ The host prompt, lexical routing input and stored prompt observation remain
428
+ unchanged. `workflowPlan.systemOne.inputEnrichment.handoffFiles` records how
429
+ many headers were added. Invalid files and read errors are ignored, and mode
430
+ `off` keeps its existing byte-identical behavior.
431
+
432
+ ## Rollout and evaluation
433
+
434
+ The measurement definitions in
435
+ [system-one-suggestion-gates.md](system-one-suggestion-gates.md) remain useful
436
+ for recording model behavior. For opt-in live routing, their numeric values are
437
+ stored as a baseline and do not block activation. Version comparison and
438
+ rollback follow the long-term optimization curve, not one threshold or metric.
439
+ The default mode stays `off`; private weights are used only by machines with an
440
+ active version pointer, and the public plugin ships the training method rather
441
+ than weights.
442
+
443
+ Evaluation records stage distributions, provenance, repeatability, CPU, OS,
444
+ runtime, thread count, cold latency and warm p95. System One provides reference
445
+ confidence, not absolute answers. Mechanism tests and mock providers establish
446
+ contract behavior only; they do not claim model quality or a live-host result.
@@ -122,14 +122,12 @@ on `actionable` prompts.
122
122
 
123
123
  ### Invalid prompts
124
124
 
125
- Some prompts cannot be judged from their text: a go-ahead (`go`, `好`,
126
- `完成了`), an option pick, a change verb with no object (`修正一下`),
127
- feedback on earlier work (`還是一樣的錯誤`), a pointer to earlier content
128
- (`請依照需求實作`), a paste with no request, or chatter. The small model
129
- does not try to recover the missing context. It marks them `invalid` and
130
- hands them to the host agent (the external LLM), which sees the whole
131
- conversation. Deterministic controls (action gates, scope and memory
132
- ownership, the Rule of 3) apply unchanged. The noise-gate experiment (#265)
125
+ `invalid` means the prompt cannot be understood from its own text and needs
126
+ conversation context. Agent-written dispatch packets and worker instructions
127
+ are ordinary prompts; their audience does not make them invalid. The small
128
+ model judges the prompt text itself, without trying to recover missing
129
+ context. Deterministic controls (action gates, scope and memory ownership,
130
+ the Rule of 3) apply unchanged. The noise-gate experiment (#265)
133
131
  showed that tier labels given to such prompts from session context were
134
132
  what kept a text-only model unsure.
135
133