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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/ci.yml +23 -0
- package/CHANGELOG.md +54 -0
- package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-a-evid-001.md +123 -0
- package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-b-route-001.md +130 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/README.md +7 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-trace-2026-11-15.jsonl +4 -0
- package/ci/mechanism-2am-observations-session-import.test.js +4 -1
- package/ci/mechanism-2n-opencode-plugin.test.js +1 -1
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +18 -3
- package/ci/mechanism-338-opencode-async.test.js +20 -3
- package/ci/mechanism-34-observations.test.js +127 -23
- package/ci/mechanism-341-opencode-lane.test.js +7 -1
- package/ci/mechanism-349-ci-change-scope.test.js +260 -0
- package/ci/mechanism-397-cycle-import.test.js +399 -0
- package/ci/mechanism-397-host-acceptance.test.js +119 -0
- package/ci/mechanism-397-opencode-observations.test.js +1922 -0
- package/ci/mechanism-handoff-file.test.js +121 -0
- package/ci/mechanism-system-one-contract.test.js +9 -2
- package/ci/mechanism-system-one-curves.test.js +223 -0
- package/ci/mechanism-system-one-cycle.test.js +1204 -0
- package/ci/mechanism-system-one-evaluation.test.js +32 -5
- package/ci/mechanism-system-one-handoff-input.test.js +208 -0
- package/ci/mechanism-system-one-install.test.js +202 -77
- package/ci/mechanism-system-one-live.test.js +361 -0
- package/ci/mechanism-system-one-relevance.test.js +11 -1
- package/ci/mechanism-system-one-train.test.js +136 -53
- package/ci/system-one-adapter-test.py +331 -0
- package/ci/system-one-train-test.py +116 -24
- package/docs/adr/EVID-001.md +123 -0
- package/docs/adr/ROUTE-001-error-lesson-delivery.md +305 -0
- package/docs/governed-index.md +2 -0
- package/docs/platform-capabilities.md +13 -6
- package/docs/routing.md +2 -2
- package/docs/system-one-cycle.md +77 -0
- package/docs/system-one-observations.md +43 -11
- package/docs/system-one-routing.md +163 -115
- package/docs/system-one-suggestion-gates.md +6 -8
- package/docs/system-one-training.md +44 -7
- package/docs/workflow-runtime.md +19 -0
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/kernel-router.js +2 -1
- package/harness-everything/scripts/system-one/contract.js +19 -15
- package/harness-everything/scripts/system-one/cua_adapter.py +211 -17
- package/harness-everything/scripts/system-one/evaluate.js +4 -9
- package/harness-everything/scripts/system-one/handoff-input.js +76 -0
- package/harness-everything/scripts/system-one/install.js +281 -113
- package/harness-everything/scripts/system-one/manifest.js +58 -0
- package/harness-everything/scripts/system-one/provider.js +96 -2
- package/harness-everything/scripts/system-one/resident.js +47 -1
- package/harness-everything/scripts/system-one/router.js +80 -1
- package/harness-everything/scripts/tier-router.js +21 -6
- package/hooks/scripts/lib/observations.js +48 -7
- package/opencode-plugin/README.md +22 -8
- package/opencode-plugin/index.mjs +424 -44
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/observations.js +48 -7
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/scripts/handoff-file.js +223 -0
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +2 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/contract.js +19 -15
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +211 -17
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/evaluate.js +4 -9
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/handoff-input.js +76 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +281 -113
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +58 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +96 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +47 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +80 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +21 -6
- package/sbom.cdx.json +7 -7
- package/scripts/ci-change-scope.js +59 -0
- package/scripts/handoff-file.js +223 -0
- package/scripts/sync-openai-plugin.js +4 -0
- package/scripts/system-one-calibrate.js +108 -41
- package/scripts/system-one-curves.js +472 -0
- package/scripts/system-one-cycle/adjudication-input.js +65 -0
- package/scripts/system-one-cycle/build.js +165 -0
- package/scripts/system-one-cycle/collect.js +67 -0
- package/scripts/system-one-cycle/common.js +175 -0
- package/scripts/system-one-cycle/engines.js +62 -0
- package/scripts/system-one-cycle/evaluate.js +73 -0
- package/scripts/system-one-cycle/judge.js +106 -0
- package/scripts/system-one-cycle/label.js +59 -0
- package/scripts/system-one-cycle/package.js +173 -0
- package/scripts/system-one-cycle/score.py +111 -0
- package/scripts/system-one-cycle/train.js +136 -0
- package/scripts/system-one-cycle.js +136 -0
- package/scripts/system-one-observations-export.js +58 -6
- package/scripts/system-one-observations-import-store.js +128 -0
- package/scripts/system-one-observations-review.js +4 -5
- package/scripts/system-one-train.py +117 -61
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const {
|
|
6
|
+
STEPS, parseFlags, flag, required, markStep, stepComplete, resultSummary,
|
|
7
|
+
} = require('./system-one-cycle/common');
|
|
8
|
+
const { collect } = require('./system-one-cycle/collect');
|
|
9
|
+
const { labelData } = require('./system-one-cycle/label');
|
|
10
|
+
const { judgeRows } = require('./system-one-cycle/judge');
|
|
11
|
+
const { buildDataset } = require('./system-one-cycle/build');
|
|
12
|
+
const { trainCycle } = require('./system-one-cycle/train');
|
|
13
|
+
const { evaluateCycle } = require('./system-one-cycle/evaluate');
|
|
14
|
+
const { buildVersion, publishVersion, validateVersion } = require('./system-one-cycle/package');
|
|
15
|
+
|
|
16
|
+
const USAGE = `Usage:
|
|
17
|
+
node scripts/system-one-cycle.js <collect|label|judge|build|train|evaluate|package|publish> --data-dir <private cycle directory> [options]
|
|
18
|
+
node scripts/system-one-cycle.js all --until <step> --data-dir <private cycle directory> [options]
|
|
19
|
+
|
|
20
|
+
Steps: ${STEPS.join(', ')}
|
|
21
|
+
Options: --since YYYY-MM-DD --sessions <Codex sessions dir> --version <id> --threads 4 --max-rss-mb 6144 --holdout <file> (repeatable) --history <private-history.jsonl> (evaluate/all)`;
|
|
22
|
+
|
|
23
|
+
function values(flags, name) {
|
|
24
|
+
const value = flags[name];
|
|
25
|
+
return value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function integerFlag(flags, name, fallback) {
|
|
29
|
+
const value = Number(flag(flags, name, fallback));
|
|
30
|
+
if (!Number.isInteger(value) || value < 1) throw new Error(`--${name} must be a positive integer`);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function numberFlag(flags, name, fallback) {
|
|
35
|
+
const value = Number(flag(flags, name, fallback));
|
|
36
|
+
if (!Number.isFinite(value) || value <= 0) throw new Error(`--${name} must be positive`);
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function historyFlag(flags) {
|
|
41
|
+
if (Array.isArray(flags.history)) throw new Error('--history may be supplied only once');
|
|
42
|
+
return flag(flags, 'history');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function outputsFor(step, dataDir, version, versionDir, result) {
|
|
46
|
+
switch (step) {
|
|
47
|
+
case 'collect': return ['training/observed/prompts-observed.jsonl', 'training/observed/labels-observed.jsonl'];
|
|
48
|
+
case 'label': return ['training/relabel-luna/labels.jsonl', 'training/relabel-luna/labels-intent.jsonl'];
|
|
49
|
+
case 'judge': return ['training/adjudication/input.jsonl', 'training/adjudication/consensus.jsonl'];
|
|
50
|
+
case 'build': return ['training/v1/prompts.jsonl', 'training/v1/labels.jsonl', 'training/v1/labels-intent.jsonl',
|
|
51
|
+
'training/v1-validity/prompts.jsonl', 'training/v1-validity/labels.jsonl'];
|
|
52
|
+
case 'train': return result.outputs;
|
|
53
|
+
case 'evaluate': return [`training/candidates/${version}/evaluation/curves.json`, `training/candidates/${version}/evaluation/trend.json`];
|
|
54
|
+
case 'package': {
|
|
55
|
+
const target = versionDir || path.join(dataDir, 'training', 'versions', version);
|
|
56
|
+
const relative = path.relative(dataDir, target);
|
|
57
|
+
return path.isAbsolute(relative) || relative.startsWith('..') ? [] : [path.join(relative, 'manifest.json')];
|
|
58
|
+
}
|
|
59
|
+
case 'publish': return [path.join('models', 'cua-s1', version, 'manifest.json')];
|
|
60
|
+
default: return [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function runStep(step, flags, dataDir) {
|
|
65
|
+
if (!STEPS.includes(step)) throw new Error(`unknown cycle step: ${step}`);
|
|
66
|
+
if (['collect', 'label', 'judge'].includes(step) && stepComplete(dataDir, step)) return resultSummary(step, { skipped: true });
|
|
67
|
+
|
|
68
|
+
let result;
|
|
69
|
+
let version;
|
|
70
|
+
let versionDir;
|
|
71
|
+
switch (step) {
|
|
72
|
+
case 'collect':
|
|
73
|
+
result = collect({ dataDir, since: flag(flags, 'since'), sessionsDir: flag(flags, 'sessions') });
|
|
74
|
+
break;
|
|
75
|
+
case 'label':
|
|
76
|
+
result = await labelData({ dataDir, batchSize: integerFlag(flags, 'batch', 20), concurrency: integerFlag(flags, 'concurrency', 4) });
|
|
77
|
+
break;
|
|
78
|
+
case 'judge':
|
|
79
|
+
result = await judgeRows({ dataDir, batchSize: integerFlag(flags, 'batch', 20) });
|
|
80
|
+
break;
|
|
81
|
+
case 'build':
|
|
82
|
+
result = buildDataset({ dataDir, holdoutFiles: values(flags, 'holdout').length ? values(flags, 'holdout') : undefined });
|
|
83
|
+
break;
|
|
84
|
+
case 'train':
|
|
85
|
+
version = validateVersion(required(flags, 'version'));
|
|
86
|
+
result = await trainCycle({ dataDir, version, threads: integerFlag(flags, 'threads', 4), maxRssMb: numberFlag(flags, 'max-rss-mb', 6144) });
|
|
87
|
+
break;
|
|
88
|
+
case 'evaluate':
|
|
89
|
+
version = validateVersion(required(flags, 'version'));
|
|
90
|
+
result = evaluateCycle({ dataDir, version, history: historyFlag(flags) });
|
|
91
|
+
break;
|
|
92
|
+
case 'package':
|
|
93
|
+
version = validateVersion(required(flags, 'version'));
|
|
94
|
+
versionDir = flag(flags, 'version-dir');
|
|
95
|
+
result = buildVersion({ dataDir, version, versionDir, sourceDir: path.join(dataDir, 'training', 'candidates', version) });
|
|
96
|
+
result = { version, evaluation: result.evaluation };
|
|
97
|
+
break;
|
|
98
|
+
case 'publish':
|
|
99
|
+
version = validateVersion(required(flags, 'version'));
|
|
100
|
+
result = publishVersion({ dataDir, version });
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const completed = step === 'label'
|
|
104
|
+
? Object.values(result).every(stage => stage.failed === 0)
|
|
105
|
+
: step === 'judge' ? result.failed === 0 : true;
|
|
106
|
+
if (completed) markStep(dataDir, step, outputsFor(step, dataDir, version, versionDir, result));
|
|
107
|
+
return resultSummary(step, { ...result, completed });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function main(argv) {
|
|
111
|
+
const [command, ...rawFlags] = argv;
|
|
112
|
+
if (command === '--help' || command === 'help' || !command) { process.stdout.write(`${USAGE}\n`); return; }
|
|
113
|
+
const flags = parseFlags(rawFlags);
|
|
114
|
+
if (flag(flags, 'help') === true) { process.stdout.write(`${USAGE}\n`); return; }
|
|
115
|
+
const dataDir = path.resolve(required(flags, 'data-dir'));
|
|
116
|
+
let results;
|
|
117
|
+
if (command === 'all') {
|
|
118
|
+
const until = required(flags, 'until');
|
|
119
|
+
const end = STEPS.indexOf(until);
|
|
120
|
+
if (end < 0) throw new Error('--until must name a cycle step');
|
|
121
|
+
results = [];
|
|
122
|
+
for (const step of STEPS.slice(0, end + 1)) {
|
|
123
|
+
const result = await runStep(step, flags, dataDir);
|
|
124
|
+
results.push(result);
|
|
125
|
+
if (result.completed === false) break;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
results = [await runStep(command, flags, dataDir)];
|
|
129
|
+
}
|
|
130
|
+
process.stdout.write(`${JSON.stringify({ steps: results })}\n`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
main(process.argv.slice(2)).catch(error => {
|
|
134
|
+
process.stderr.write(`system-one-cycle: ${error.message}\n`);
|
|
135
|
+
process.exitCode = 1;
|
|
136
|
+
});
|
|
@@ -30,8 +30,7 @@ function family(text) {
|
|
|
30
30
|
function validDecision(d) {
|
|
31
31
|
return d && typeof d.id === 'string'
|
|
32
32
|
&& [undefined, null, 'actionable', 'invalid', 'unsure'].includes(d.validity)
|
|
33
|
-
&& [undefined, null, ...obs.TIERS].includes(d.tier)
|
|
34
|
-
&& [undefined, null, true, false].includes(d.contextDependent);
|
|
33
|
+
&& [undefined, null, ...obs.TIERS].includes(d.tier);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
function loadReview(file) {
|
|
@@ -47,15 +46,13 @@ function derive(record, owner) {
|
|
|
47
46
|
const self = record.selfReport;
|
|
48
47
|
const behavior = record.captureMethod === 'session-backfill' ? null : record.behavior;
|
|
49
48
|
let validity = self ? self.validity : null;
|
|
50
|
-
let contextDependent = self ? self.contextDependent : null;
|
|
51
49
|
if (owner && owner.validity && owner.validity !== 'unsure') validity = owner.validity;
|
|
52
|
-
if (owner && typeof owner.contextDependent === 'boolean') contextDependent = owner.contextDependent;
|
|
53
50
|
let { tier, source: tierSource } = obs.labelTier(self, owner);
|
|
54
51
|
if (validity === 'invalid' && !(owner && obs.TIERS.includes(owner.tier))) { tier = null; tierSource = tierSource && 'self-report'; }
|
|
55
52
|
const skills = record.behavior && record.behavior.skills && record.behavior.skills.length
|
|
56
53
|
? record.behavior.skills : (self ? self.skills : []);
|
|
57
54
|
return {
|
|
58
|
-
id: record.id, validity,
|
|
55
|
+
id: record.id, validity, tier, tierSource,
|
|
59
56
|
intents: self ? self.intents : [], workflow: (self && self.workflow) || (record.router && record.router.strategy) || null,
|
|
60
57
|
skills,
|
|
61
58
|
behaviorEvidence: behavior ? 'observed' : 'unobserved',
|
|
@@ -68,6 +65,11 @@ function rate(pairs) {
|
|
|
68
65
|
return pairs.length ? pairs.filter(([a, b]) => a === b).length / pairs.length : null;
|
|
69
66
|
}
|
|
70
67
|
|
|
68
|
+
function exportSystemOne(record) {
|
|
69
|
+
const systemOne = obs.normalizeSystemOne(record && record.router && record.router.systemOne);
|
|
70
|
+
return systemOne ? { version: systemOne.version, sha256: systemOne.sha256, mode: systemOne.mode, decision: systemOne.decision } : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
71
73
|
function run(args) {
|
|
72
74
|
const store = path.resolve(option(args, '--store', obs.storeRoot()));
|
|
73
75
|
const out = option(args, '--out');
|
|
@@ -80,6 +82,33 @@ function run(args) {
|
|
|
80
82
|
obs.sweep(store);
|
|
81
83
|
const index = obs.readJson(path.join(store, 'observations-index.json'), null);
|
|
82
84
|
if (!index || index.schemaVersion !== 1 || !Array.isArray(index.records)) throw new Error(`no observation index in ${store}`);
|
|
85
|
+
const malformedLabelReasons = new Set(['label-invalid', 'label-unparseable']);
|
|
86
|
+
const acceptanceByHost = {};
|
|
87
|
+
const seenTurns = new Set();
|
|
88
|
+
for (const record of index.records) {
|
|
89
|
+
const host = String(record.host || 'unknown');
|
|
90
|
+
const counts = acceptanceByHost[host] || (acceptanceByHost[host] = { valid: 0, invalid: 0, missing: 0 });
|
|
91
|
+
if (since !== null && (!Number.isFinite(Date.parse(record.observedAt || '')) || Date.parse(record.observedAt) < since)) continue;
|
|
92
|
+
const writer = record.writer || {};
|
|
93
|
+
const sessionId = String(writer.sessionId || '');
|
|
94
|
+
const turnId = String(writer.turnId || '');
|
|
95
|
+
const turn = Number.isInteger(record.turn) ? String(record.turn) : '';
|
|
96
|
+
const uniqueTurn = sessionId && turnId ? `${host}\0${sessionId}\0id:${turnId}`
|
|
97
|
+
: sessionId && turn ? `${host}\0${sessionId}\0ordinal:${turn}` : record.id ? `${host}\0record:${record.id}` : '';
|
|
98
|
+
if (uniqueTurn && seenTurns.has(uniqueTurn)) continue;
|
|
99
|
+
if (uniqueTurn) seenTurns.add(uniqueTurn);
|
|
100
|
+
if (record.selfReport) counts.valid++;
|
|
101
|
+
else if (malformedLabelReasons.has(record.selfReportReason)) counts.invalid++;
|
|
102
|
+
else counts.missing++;
|
|
103
|
+
}
|
|
104
|
+
const hostAcceptanceByHost = Object.fromEntries(Object.entries(acceptanceByHost).sort(([left], [right]) => left.localeCompare(right))
|
|
105
|
+
.map(([host, counts]) => {
|
|
106
|
+
const eligible = counts.valid + counts.invalid + counts.missing;
|
|
107
|
+
return [host, { eligible, ...counts, acceptanceRate: eligible ? counts.valid / eligible : null }];
|
|
108
|
+
}));
|
|
109
|
+
const malformedLabelsByHost = Object.fromEntries(Object.entries(hostAcceptanceByHost)
|
|
110
|
+
.filter(([, counts]) => counts.invalid)
|
|
111
|
+
.map(([host, counts]) => [host, counts.invalid]));
|
|
83
112
|
const rows = [];
|
|
84
113
|
let skippedNoText = 0;
|
|
85
114
|
let skippedBeforeSince = 0;
|
|
@@ -102,7 +131,9 @@ function run(args) {
|
|
|
102
131
|
const prompts = rows.map((r, i) => JSON.stringify({ id: r.record.id, family: family(r.text.prompt), source: 'observation',
|
|
103
132
|
split: i >= rows.length - validation ? 'validation' : 'train', text: r.text.prompt, previous: r.text.previous || '' }));
|
|
104
133
|
fs.writeFileSync(path.join(out, 'prompts-observed.jsonl'), prompts.join('\n') + (prompts.length ? '\n' : ''));
|
|
105
|
-
fs.writeFileSync(path.join(out, 'labels-observed.jsonl'), rows.map(r => JSON.stringify(
|
|
134
|
+
fs.writeFileSync(path.join(out, 'labels-observed.jsonl'), rows.map(r => JSON.stringify({
|
|
135
|
+
...r.label, systemOne: exportSystemOne(r.record),
|
|
136
|
+
})).join('\n') + (rows.length ? '\n' : ''));
|
|
106
137
|
const withSelf = rows.filter(r => r.record.selfReport);
|
|
107
138
|
// Only turns where the router chose a tier; 'unclassified' is not one.
|
|
108
139
|
const routerSelf = withSelf.filter(r => r.record.router && obs.TIERS.includes(r.record.router.tier)).map(r => [r.record.router.tier, r.record.selfReport.tier]);
|
|
@@ -110,11 +141,31 @@ function run(args) {
|
|
|
110
141
|
const contradictions = {};
|
|
111
142
|
for (const r of rows) for (const c of r.label.contradictions) contradictions[c] = (contradictions[c] || 0) + 1;
|
|
112
143
|
const count = key => rows.reduce((acc, r) => { const k = String(key(r)); acc[k] = (acc[k] || 0) + 1; return acc; }, {});
|
|
144
|
+
const systemOneVersions = new Map();
|
|
145
|
+
for (const r of rows) {
|
|
146
|
+
const systemOne = obs.normalizeSystemOne(r.record.router && r.record.router.systemOne);
|
|
147
|
+
if (!systemOne) continue;
|
|
148
|
+
const version = systemOneVersions.get(systemOne.version) || { rows: 0, matches: 0, comparisons: 0 };
|
|
149
|
+
version.rows++;
|
|
150
|
+
const selfTier = r.record.selfReport && r.record.selfReport.tier;
|
|
151
|
+
if (obs.TIERS.includes(systemOne.decision.tier) && obs.TIERS.includes(selfTier)) {
|
|
152
|
+
version.comparisons++;
|
|
153
|
+
if (systemOne.decision.tier === selfTier) version.matches++;
|
|
154
|
+
}
|
|
155
|
+
systemOneVersions.set(systemOne.version, version);
|
|
156
|
+
}
|
|
157
|
+
const systemOneReport = Object.fromEntries([...systemOneVersions].map(([version, counts]) => [version, {
|
|
158
|
+
rows: counts.rows,
|
|
159
|
+
tierAgreement: { matches: counts.matches, comparisons: counts.comparisons,
|
|
160
|
+
rate: counts.comparisons ? counts.matches / counts.comparisons : null },
|
|
161
|
+
}]));
|
|
113
162
|
const report = {
|
|
114
163
|
schemaVersion: 1, exportedAt: new Date().toISOString(), records: index.records.length, exported: rows.length,
|
|
115
164
|
since: sinceText, selfReportOnly, skippedBeforeSince, skippedUnlabeled,
|
|
116
165
|
skippedNoText, validationRows: validation, withSelfReport: withSelf.length,
|
|
117
166
|
selfReportReasons: count(r => r.record.selfReportReason || 'ok'), hosts: count(r => r.record.host),
|
|
167
|
+
malformedLabelsByHost: Object.fromEntries(Object.entries(malformedLabelsByHost).sort(([left], [right]) => left.localeCompare(right))),
|
|
168
|
+
hostAcceptance: { population: 'stored-observations', byHost: hostAcceptanceByHost },
|
|
118
169
|
validity: count(r => r.label.validity), tiers: count(r => r.label.tier), tierSources: count(r => r.label.tierSource),
|
|
119
170
|
behaviorEvidence: {
|
|
120
171
|
observed: rows.filter(r => r.label.behaviorEvidence === 'observed').length,
|
|
@@ -122,6 +173,7 @@ function run(args) {
|
|
|
122
173
|
},
|
|
123
174
|
contradictionEvidence: 'observed-behavior-only',
|
|
124
175
|
ownerDecisions: Object.keys(owner).length, agreement, contradictions,
|
|
176
|
+
systemOne: { versions: systemOneReport },
|
|
125
177
|
};
|
|
126
178
|
fs.writeFileSync(path.join(out, 'export-report.json'), JSON.stringify(report, null, 2) + '\n');
|
|
127
179
|
return report;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const obs = require('../hooks/scripts/lib/observations');
|
|
6
|
+
const { assertPrivateDataDir } = require('./system-one-cycle/common');
|
|
7
|
+
|
|
8
|
+
function parseSince(value) {
|
|
9
|
+
if (typeof value !== 'string') throw new Error('invalid-since');
|
|
10
|
+
const text = value;
|
|
11
|
+
const timestamp = Date.parse(/^\d{4}-\d{2}-\d{2}$/.test(text) ? `${text}T00:00:00.000Z` : text);
|
|
12
|
+
if (!Number.isFinite(timestamp)) throw new Error('invalid-since');
|
|
13
|
+
return timestamp;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function bucket(byHost, host) {
|
|
17
|
+
if (!Object.hasOwn(byHost, host)) {
|
|
18
|
+
Object.defineProperty(byHost, host, {
|
|
19
|
+
value: { persisted: 0, duplicate: 0, ambiguous: 0, importFailure: 0 }, enumerable: true, configurable: true, writable: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return byHost[host];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function importStore({ sourceRoot = obs.storeRoot(), store, since, lockTimeoutMs } = {}) {
|
|
26
|
+
const report = {
|
|
27
|
+
source: { root: 'configured-private-store', status: 'absent' },
|
|
28
|
+
byHost: {},
|
|
29
|
+
};
|
|
30
|
+
const fail = (host, code) => {
|
|
31
|
+
bucket(report.byHost, host).importFailure++;
|
|
32
|
+
report.source.status = 'error';
|
|
33
|
+
report.source.error ||= code;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let cutoff;
|
|
37
|
+
try { cutoff = parseSince(since); }
|
|
38
|
+
catch { fail('unknown', 'invalid-since'); return report; }
|
|
39
|
+
|
|
40
|
+
if (typeof store !== 'string' || !store.trim() || !path.isAbsolute(store)
|
|
41
|
+
|| typeof sourceRoot !== 'string' || !sourceRoot.trim()) {
|
|
42
|
+
fail('unknown', typeof store !== 'string' || !store.trim() || !path.isAbsolute(store) ? 'invalid-destination' : 'invalid-source-root');
|
|
43
|
+
return report;
|
|
44
|
+
}
|
|
45
|
+
let destination;
|
|
46
|
+
let source;
|
|
47
|
+
try { destination = assertPrivateDataDir(store); }
|
|
48
|
+
catch { fail('unknown', 'destination-unavailable'); return report; }
|
|
49
|
+
try { source = assertPrivateDataDir(sourceRoot, { create: false }); }
|
|
50
|
+
catch { fail('unknown', 'source-unavailable'); return report; }
|
|
51
|
+
|
|
52
|
+
const destinationIndex = path.join(destination, 'observations-index.json');
|
|
53
|
+
try {
|
|
54
|
+
fs.mkdirSync(destination, { recursive: true, mode: 0o700 });
|
|
55
|
+
try { fs.writeFileSync(destinationIndex, '{"schemaVersion":1,"kind":"system-one-observations","records":[]}\n', { flag: 'wx', mode: 0o600 }); }
|
|
56
|
+
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
57
|
+
const existing = JSON.parse(fs.readFileSync(destinationIndex, 'utf8'));
|
|
58
|
+
if (existing.schemaVersion !== 1 || !Array.isArray(existing.records)) throw new Error('invalid destination index');
|
|
59
|
+
} catch { fail('unknown', 'destination-unavailable'); return report; }
|
|
60
|
+
|
|
61
|
+
const sourceIndex = path.join(source, 'observations-index.json');
|
|
62
|
+
if (!fs.existsSync(sourceIndex)) return report;
|
|
63
|
+
|
|
64
|
+
let index;
|
|
65
|
+
try { index = JSON.parse(fs.readFileSync(sourceIndex, 'utf8')); }
|
|
66
|
+
catch { fail('unknown', 'source-index-invalid'); return report; }
|
|
67
|
+
if (!index || index.schemaVersion !== 1 || !Array.isArray(index.records)) {
|
|
68
|
+
fail('unknown', 'source-index-invalid');
|
|
69
|
+
return report;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
report.source.status = 'ok';
|
|
73
|
+
for (const record of index.records) {
|
|
74
|
+
if (!record || typeof record !== 'object' || Array.isArray(record)) {
|
|
75
|
+
fail('unknown', 'source-record-invalid');
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const host = typeof record.host === 'string' && record.host.trim() ? record.host : 'unknown';
|
|
79
|
+
const observedAt = typeof record.observedAt === 'string' ? Date.parse(record.observedAt) : NaN;
|
|
80
|
+
if (!Number.isFinite(observedAt)) { fail(host, 'source-record-invalid'); continue; }
|
|
81
|
+
if (observedAt < cutoff) continue;
|
|
82
|
+
const result = bucket(report.byHost, host);
|
|
83
|
+
const writer = record.writer && typeof record.writer === 'object' ? record.writer : {};
|
|
84
|
+
const sessionId = typeof writer.sessionId === 'string' ? writer.sessionId : '';
|
|
85
|
+
if (typeof record.id !== 'string' || !record.id || typeof record.contentSha256 !== 'string'
|
|
86
|
+
|| !/^[a-f\d]{64}$/i.test(record.contentSha256)) {
|
|
87
|
+
fail(host, 'source-record-invalid');
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (host === 'unknown' || !sessionId || (writer.turnId !== undefined && typeof writer.turnId !== 'string')) {
|
|
91
|
+
result.ambiguous++;
|
|
92
|
+
report.source.status = 'error';
|
|
93
|
+
report.source.error ||= 'ambiguous-records';
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const retained = Number.isFinite(Date.parse(record.validUntil || ''));
|
|
98
|
+
const text = retained ? obs.recordText(source, record) : null;
|
|
99
|
+
if (text !== null && (!text || typeof text.prompt !== 'string'
|
|
100
|
+
|| !(text.previous === undefined || typeof text.previous === 'string'))) {
|
|
101
|
+
fail(host, 'source-text-invalid');
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let appended;
|
|
105
|
+
try {
|
|
106
|
+
appended = obs.appendRecordDetailed(destination, record, text, {
|
|
107
|
+
dedupeByTurn: true,
|
|
108
|
+
...(lockTimeoutMs === undefined ? {} : { lockTimeoutMs }),
|
|
109
|
+
});
|
|
110
|
+
} catch {
|
|
111
|
+
fail(host, 'append-failed');
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (appended.status === 'appended') result.persisted++;
|
|
115
|
+
else if (appended.status === 'duplicate') result.duplicate++;
|
|
116
|
+
else if (appended.status === 'ambiguous') {
|
|
117
|
+
result.ambiguous++;
|
|
118
|
+
report.source.status = 'error';
|
|
119
|
+
report.source.error ||= 'ambiguous-records';
|
|
120
|
+
} else {
|
|
121
|
+
fail(host, 'append-failed');
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return report;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = { importStore };
|
|
@@ -37,13 +37,12 @@ body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.6 system-ui,-appl
|
|
|
37
37
|
main{max-width:860px;margin:0 auto;padding:16px}.box{white-space:pre-wrap;word-break:break-word;background:var(--card);border:1px solid var(--bd);border-radius:10px;padding:14px;max-height:40vh;overflow:auto}
|
|
38
38
|
.prev{font-size:14px;color:var(--mut)}label{margin-right:16px}select,button{font:inherit;padding:6px 10px;border-radius:8px;border:1px solid var(--bd);background:var(--card);color:var(--fg)}
|
|
39
39
|
.row{display:flex;gap:12px;flex-wrap:wrap;align-items:center;margin:12px 0}</style></head><body><main>
|
|
40
|
-
<p class="prev">
|
|
40
|
+
<p class="prev">Decide whether the prompt can be understood from its own text and the tier of the work it asks for. Agent-written dispatches and worker instructions are ordinary prompts.</p>
|
|
41
41
|
<div class="row"><span id="pos"></span><button id="prev">←</button><button id="next">→</button><button id="exp">Export JSON</button><span id="stat" class="prev"></span></div>
|
|
42
42
|
<h3>Previous assistant message</h3><div class="box prev" id="previous"></div>
|
|
43
43
|
<h3>Prompt</h3><div class="box" id="prompt"></div>
|
|
44
44
|
<h3>Behavior evidence</h3><div class="box" id="behavior"></div>
|
|
45
45
|
<div class="row"><label>Validity <select id="validity"><option value="">—</option><option>actionable</option><option>invalid</option><option>unsure</option></select></label>
|
|
46
|
-
<label>Needs context <select id="contextDependent"><option value="">—</option><option value="true">yes</option><option value="false">no</option></select></label>
|
|
47
46
|
<label>Tier <select id="tier"><option value="">—</option><option>tier1</option><option>tier2</option><option>tier3</option></select></label></div>
|
|
48
47
|
</main><script>
|
|
49
48
|
const ITEMS=${data};const KEY='harness-observation-review';
|
|
@@ -53,9 +52,9 @@ function save(){try{localStorage.setItem(KEY,JSON.stringify(st))}catch(e){}}
|
|
|
53
52
|
function render(){if(!ITEMS.length){$('prompt').textContent='Nothing to review.';return}const it=ITEMS[i],d=st[it.id]||{};
|
|
54
53
|
$('pos').textContent=(i+1)+' / '+ITEMS.length;$('prompt').textContent=it.prompt;$('previous').textContent=it.previous||'(none)';
|
|
55
54
|
$('behavior').textContent=it.behaviorEvidence==='observed'?'Observed by local hook collection.':'Behavior evidence is unobserved; session backfill did not record tool events or file writes.';
|
|
56
|
-
$('validity').value=d.validity||'';$('tier').value=d.tier||'';$('
|
|
57
|
-
function set(){const it=ITEMS[i];
|
|
58
|
-
$('validity').onchange=set;$('
|
|
55
|
+
$('validity').value=d.validity||'';$('tier').value=d.tier||'';$('stat').textContent='decided '+Object.keys(st).length}
|
|
56
|
+
function set(){const it=ITEMS[i];st[it.id]={id:it.id,validity:$('validity').value||null,tier:$('tier').value||null,decidedAt:new Date().toISOString()};save();render()}
|
|
57
|
+
$('validity').onchange=set;$('tier').onchange=set;$('prev').onclick=()=>{if(i>0)i--;render()};$('next').onclick=()=>{if(i<ITEMS.length-1)i++;render()};
|
|
59
58
|
$('exp').onclick=()=>{const b=new Blob([JSON.stringify({schemaVersion:1,review:KEY,decisions:Object.values(st)},null,1)],{type:'application/json'});const a=document.createElement('a');a.href=URL.createObjectURL(b);a.download='observation-review-decisions.json';a.click()};
|
|
60
59
|
render();
|
|
61
60
|
</script></body></html>`;
|