teimmo 0.0.0-stage → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +30 -0
- package/README.md +292 -2
- package/artifacts.mjs +232 -0
- package/cli.mjs +757 -0
- package/context.mjs +45 -0
- package/dashboard-state.mjs +220 -0
- package/dashboard-ui.mjs +128 -0
- package/dashboard.mjs +133 -0
- package/domain.mjs +80 -0
- package/evidence.mjs +58 -0
- package/native-workspace.mjs +49 -0
- package/obligations.mjs +35 -0
- package/package.json +62 -4
- package/regression-supersession.mjs +65 -0
- package/replan.mjs +48 -0
- package/runners/unittest_evidence.py +59 -0
- package/runtime.mjs +181 -0
- package/skillpack.mjs +112 -0
- package/workspace-layout.mjs +39 -0
package/context.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {assert,inventory,relativeFile,digest} from './artifacts.mjs';
|
|
4
|
+
const instruction=name=>/^(AGENTS|CLAUDE|GEMINI)\.md$/.test(path.basename(name));
|
|
5
|
+
const excluded=name=>/(^|\/)(node_modules|\.git|\.harness|\.agents|\.codex|\.cache)(\/|$)/.test(name)||/(^|\/)(\.env(?:\..*)?|id_rsa|id_ed25519)$/.test(name)||/\.(pem|key|p12|pfx)$/i.test(name);
|
|
6
|
+
function textFile(root,name,maxBytes=4*1024*1024){
|
|
7
|
+
assert(!excluded(name),'Context path excluded: '+name);
|
|
8
|
+
const file=relativeFile(root,name),stat=fs.statSync(file);assert(stat.isFile(),'Context must be a file');
|
|
9
|
+
assert(stat.size<=maxBytes,'File exceeds context read limit; split or provide a smaller reference: '+name);
|
|
10
|
+
const buffer=fs.readFileSync(file);assert(!buffer.includes(0),'Binary file omitted: '+name);
|
|
11
|
+
return new TextDecoder('utf-8',{fatal:true}).decode(buffer);
|
|
12
|
+
}
|
|
13
|
+
export function readSource(root,name,start=1,count=120,{allowAbsent=false}={}){
|
|
14
|
+
assert(Number.isInteger(start)&&start>0&&Number.isInteger(count)&&count>0&&count<=400,'Source range must be positive; maximum 400 lines');
|
|
15
|
+
assert(!excluded(name),'Context path excluded: '+name);
|
|
16
|
+
const requested=relativeFile(root,name);
|
|
17
|
+
if(allowAbsent&&!fs.existsSync(requested))return {path:name,status:'not-created',instruction:'No existing file at this path. During new-project planning choose and document its future interface; write tests now, implementation comes after approval. Do not invent missing user/business decisions.'};
|
|
18
|
+
assert(inventory(root).includes(name),'Source must be a Git-visible project file');
|
|
19
|
+
const text=textFile(root,name),lines=text.split(/\r?\n/),end=Math.min(lines.length,start+count-1);
|
|
20
|
+
assert(start<=lines.length,'Start exceeds file length');
|
|
21
|
+
const content=lines.slice(start-1,end).join('\n');assert(content.length<=40000,'Requested range too large; request fewer lines');
|
|
22
|
+
return {path:name,startLine:start,endLine:end,totalLines:lines.length,sha256:digest(text),content};
|
|
23
|
+
}
|
|
24
|
+
export function buildContext(root,{focus=[],budget=90000,chunk=12000,focusChunk=chunk}={}){
|
|
25
|
+
assert(Number.isInteger(budget)&&budget>=1000&&budget<=150000,'Context budget must be 1000..150000');
|
|
26
|
+
assert(Array.isArray(focus)&&focus.every(x=>typeof x==='string'),'Context focus must contain paths');
|
|
27
|
+
assert(Number.isInteger(focusChunk)&&focusChunk>0&&focusChunk<=60000,'Focused context chunk must be 1..60000');
|
|
28
|
+
const names=inventory(root).filter(n=>!n.startsWith('harness-spec/'));
|
|
29
|
+
const priority=n=>instruction(n)?0:focus.includes(n)?1:focus.some(f=>n.startsWith(path.posix.dirname(f)+'/'))?2:3;
|
|
30
|
+
names.sort((a,b)=>priority(a)-priority(b)||a.localeCompare(b));
|
|
31
|
+
const entries=[],pieces=[];let remaining=budget;
|
|
32
|
+
for(const name of names){
|
|
33
|
+
const entry={path:name,status:'omitted',reason:null};entries.push(entry);
|
|
34
|
+
if(excluded(name)){entry.reason='excluded-sensitive-or-managed';continue;}
|
|
35
|
+
if(remaining<=100){entry.reason='budget';continue;}
|
|
36
|
+
let text;try{text=textFile(root,name);}catch(error){entry.reason=error.message;continue;}
|
|
37
|
+
const limit=Math.min(instruction(name)?40000:focus.includes(name)?focusChunk:chunk,remaining-100);
|
|
38
|
+
const content=text.slice(0,limit);remaining-=content.length+100;
|
|
39
|
+
Object.assign(entry,{status:content.length===text.length?'included':'partial',reason:content.length===text.length?null:'chunk-limit',characters:text.length,includedCharacters:content.length,totalLines:text.split(/\r?\n/).length,sha256:digest(text)});
|
|
40
|
+
pieces.push((instruction(name)?'SCOPED INSTRUCTIONS ':'SOURCE ')+name+'\n'+content+(entry.status==='partial'?'\n[PARTIAL: request further lines through contextRequests]':''));
|
|
41
|
+
}
|
|
42
|
+
const manifest={version:1,focus,budget,entries,notice:'Partial and omitted files have NOT been fully read; request source ranges before editing them.'};
|
|
43
|
+
const summary=entries.map(e=>e.path+' '+e.status+(e.totalLines?' [total lines: '+e.totalLines+']':'')+(e.reason?' ('+e.reason+')':'')).join('\n');
|
|
44
|
+
return {manifest,text:'CONTEXT MANIFEST\n'+summary.slice(0,18000)+(summary.length>18000?'\n[Inventory abbreviated; full manifest in .harness/context-manifest.json]':'')+'\n\n'+pieces.join('\n\n')};
|
|
45
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import {snapshot, relativeFile} from './artifacts.mjs';
|
|
3
|
+
import {environmentFingerprint} from './evidence.mjs';
|
|
4
|
+
|
|
5
|
+
const MAX_JSON_BYTES = 2 * 1024 * 1024;
|
|
6
|
+
|
|
7
|
+
function isRecord(value) {
|
|
8
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isOrdinaryDirectory(stat) {
|
|
12
|
+
return Boolean(stat) && !stat.isSymbolicLink() && stat.isDirectory();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function requireOrdinaryDirectory(file, label) {
|
|
16
|
+
const first = fs.lstatSync(file, {bigint: true, throwIfNoEntry: false});
|
|
17
|
+
if (!isOrdinaryDirectory(first)) {
|
|
18
|
+
throw new Error(label + ' must be an ordinary directory');
|
|
19
|
+
}
|
|
20
|
+
const confirmed = fs.lstatSync(file, {bigint: true, throwIfNoEntry: false});
|
|
21
|
+
if (!isOrdinaryDirectory(confirmed) || !sameDirectoryIdentity(first, confirmed)) {
|
|
22
|
+
throw new Error(label + ' changed while being acquired');
|
|
23
|
+
}
|
|
24
|
+
return confirmed;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sameIdentity(left, right) {
|
|
28
|
+
return left.dev === right.dev &&
|
|
29
|
+
left.ino === right.ino &&
|
|
30
|
+
left.mode === right.mode &&
|
|
31
|
+
left.size === right.size &&
|
|
32
|
+
left.mtimeNs === right.mtimeNs &&
|
|
33
|
+
left.ctimeNs === right.ctimeNs;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function sameDirectoryIdentity(left, right) {
|
|
37
|
+
return left.dev === right.dev && left.ino === right.ino &&
|
|
38
|
+
left.mode === right.mode && left.birthtimeNs === right.birthtimeNs;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function assertHarnessIdentity(harness, expected) {
|
|
42
|
+
const current = fs.lstatSync(harness, {bigint: true, throwIfNoEntry: false});
|
|
43
|
+
if (!isOrdinaryDirectory(current) || !sameDirectoryIdentity(expected, current)) {
|
|
44
|
+
throw new Error('.harness changed while being read; file changed before reading');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readBoundedJson(root, name, harnessIdentity) {
|
|
49
|
+
const harness = relativeFile(root, '.harness');
|
|
50
|
+
assertHarnessIdentity(harness, harnessIdentity);
|
|
51
|
+
const file = relativeFile(root, name);
|
|
52
|
+
const before = fs.lstatSync(file, {bigint: true, throwIfNoEntry: false});
|
|
53
|
+
if (!before || before.isSymbolicLink() || !before.isFile()) {
|
|
54
|
+
throw new Error(name + ' must be an ordinary file');
|
|
55
|
+
}
|
|
56
|
+
if (before.size > BigInt(MAX_JSON_BYTES)) throw new Error(name + ' exceeds the read limit');
|
|
57
|
+
|
|
58
|
+
const flags = fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0);
|
|
59
|
+
let descriptor;
|
|
60
|
+
try {
|
|
61
|
+
descriptor = fs.openSync(file, flags);
|
|
62
|
+
} catch {
|
|
63
|
+
throw new Error(name + ' could not be opened as an ordinary file');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
assertHarnessIdentity(harness, harnessIdentity);
|
|
68
|
+
const opened = fs.fstatSync(descriptor, {bigint: true});
|
|
69
|
+
if (!opened.isFile()) throw new Error(name + ' must be an ordinary file');
|
|
70
|
+
if (!sameIdentity(before, opened)) throw new Error(name + ' changed before reading');
|
|
71
|
+
if (opened.size > BigInt(MAX_JSON_BYTES)) throw new Error(name + ' exceeds the read limit');
|
|
72
|
+
|
|
73
|
+
const buffer = Buffer.allocUnsafe(MAX_JSON_BYTES + 1);
|
|
74
|
+
let length = 0;
|
|
75
|
+
while (length < buffer.length) {
|
|
76
|
+
const count = fs.readSync(descriptor, buffer, length, buffer.length - length, null);
|
|
77
|
+
if (count === 0) break;
|
|
78
|
+
length += count;
|
|
79
|
+
}
|
|
80
|
+
if (length > MAX_JSON_BYTES) throw new Error(name + ' exceeds the read limit');
|
|
81
|
+
|
|
82
|
+
const finished = fs.fstatSync(descriptor, {bigint: true});
|
|
83
|
+
const after = fs.lstatSync(file, {bigint: true, throwIfNoEntry: false});
|
|
84
|
+
assertHarnessIdentity(harness, harnessIdentity);
|
|
85
|
+
if (!finished.isFile() || !after || after.isSymbolicLink() || !after.isFile() ||
|
|
86
|
+
!sameIdentity(opened, finished) || !sameIdentity(finished, after)) {
|
|
87
|
+
throw new Error(name + ' changed while being read');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const text = new TextDecoder('utf-8', {fatal: true})
|
|
91
|
+
.decode(buffer.subarray(0, length))
|
|
92
|
+
.replace(/^\uFEFF/, '');
|
|
93
|
+
return JSON.parse(text);
|
|
94
|
+
} finally {
|
|
95
|
+
fs.closeSync(descriptor);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function strings(value) {
|
|
100
|
+
return Array.isArray(value) ? value.filter(item => typeof item === 'string') : [];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function sanitizeRouting(state, config) {
|
|
104
|
+
const overrides = Object.fromEntries(
|
|
105
|
+
Object.entries(isRecord(config.routes) ? config.routes : {}).flatMap(([name, route]) => {
|
|
106
|
+
if (!isRecord(route)) return [];
|
|
107
|
+
const value = {};
|
|
108
|
+
if (typeof route.agent === 'string') value.agent = route.agent;
|
|
109
|
+
if (typeof route.model === 'string') value.model = route.model;
|
|
110
|
+
return [[name, value]];
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
default: {
|
|
116
|
+
agent: typeof state.agent === 'string' ? state.agent : null,
|
|
117
|
+
model: typeof state.model === 'string' ? state.model : null
|
|
118
|
+
},
|
|
119
|
+
overrides
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function sanitizeTasks(taskRuns) {
|
|
124
|
+
return taskRuns.filter(isRecord).map(task => ({
|
|
125
|
+
id: typeof task.id === 'string' ? task.id : '',
|
|
126
|
+
status: typeof task.status === 'string' ? task.status : '',
|
|
127
|
+
criteria: strings(task.criteria)
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function sanitizeChecks(checks) {
|
|
132
|
+
return checks.filter(isRecord).map(check => ({
|
|
133
|
+
id: typeof check.id === 'string' ? check.id : '',
|
|
134
|
+
code: typeof check.code === 'number' || check.code === null ? check.code : null,
|
|
135
|
+
evidenceValid: check.evidence?.valid === true,
|
|
136
|
+
tests: (Array.isArray(check.evidence?.tests) ? check.evidence.tests : [])
|
|
137
|
+
.filter(isRecord)
|
|
138
|
+
.map(test => ({
|
|
139
|
+
id: typeof test.id === 'string' ? test.id : '',
|
|
140
|
+
name: typeof test.name === 'string' ? test.name : '',
|
|
141
|
+
status: typeof test.status === 'string' ? test.status : ''
|
|
142
|
+
}))
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function sanitizeCoverage(coverage) {
|
|
147
|
+
return (Array.isArray(coverage) ? coverage : []).filter(isRecord).map(row => ({
|
|
148
|
+
criterion: typeof row.criterion === 'string' ? row.criterion : '',
|
|
149
|
+
tasks: strings(row.tasks),
|
|
150
|
+
checks: strings(row.checks)
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function sanitizeEvents(history) {
|
|
155
|
+
return history.slice(-100).filter(isRecord).map(event => ({
|
|
156
|
+
at: typeof event.at === 'string' ? event.at : '',
|
|
157
|
+
stage: typeof event.stage === 'string' ? event.stage : '',
|
|
158
|
+
status: typeof event.status === 'string' ? event.status : '',
|
|
159
|
+
agent: typeof event.agent === 'string' ? event.agent : '',
|
|
160
|
+
model: typeof event.model === 'string' ? event.model : ''
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function validateState(state) {
|
|
165
|
+
if (!isRecord(state)) throw new Error('Persisted state must be an object');
|
|
166
|
+
for (const field of ['title', 'phase', 'status']) {
|
|
167
|
+
if (typeof state[field] !== 'string') throw new Error('Persisted state needs string ' + field);
|
|
168
|
+
}
|
|
169
|
+
for (const field of ['history', 'taskRuns', 'checks']) {
|
|
170
|
+
if (field === 'taskRuns' && state[field] === null) continue;
|
|
171
|
+
if (state[field] !== undefined && !Array.isArray(state[field])) {
|
|
172
|
+
throw new Error('Persisted state ' + field + ' must be an array');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function lockExists(root) {
|
|
178
|
+
const lock = relativeFile(root, '.harness/lock');
|
|
179
|
+
const stat = fs.lstatSync(lock, {throwIfNoEntry: false});
|
|
180
|
+
if (stat?.isSymbolicLink()) throw new Error('Symlinked lock refused');
|
|
181
|
+
return stat !== undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function buildStatus(root) {
|
|
185
|
+
const harness = relativeFile(root, '.harness');
|
|
186
|
+
const harnessIdentity = requireOrdinaryDirectory(harness, '.harness');
|
|
187
|
+
|
|
188
|
+
const state = readBoundedJson(root, '.harness/state.json', harnessIdentity);
|
|
189
|
+
const config = readBoundedJson(root, '.harness/config.json', harnessIdentity);
|
|
190
|
+
assertHarnessIdentity(harness, harnessIdentity);
|
|
191
|
+
validateState(state);
|
|
192
|
+
if (!isRecord(config)) throw new Error('Persisted configuration must be an object');
|
|
193
|
+
|
|
194
|
+
let status = state.status;
|
|
195
|
+
if (state.phase === 'complete') {
|
|
196
|
+
const completeAndFresh = state.evidenceVersion === 1 &&
|
|
197
|
+
state.sourceHash === snapshot(root) &&
|
|
198
|
+
state.environmentHash === environmentFingerprint(root, config);
|
|
199
|
+
status = completeAndFresh ? 'PASS' : 'STALE';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const metrics = isRecord(state.metrics) ? state.metrics : {};
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
schemaVersion: 1,
|
|
206
|
+
title: state.title,
|
|
207
|
+
phase: state.phase,
|
|
208
|
+
status,
|
|
209
|
+
busy: lockExists(root),
|
|
210
|
+
routing: sanitizeRouting(state, config),
|
|
211
|
+
metrics: {
|
|
212
|
+
calls: Number.isFinite(metrics.calls) ? metrics.calls : 0,
|
|
213
|
+
agentMs: Number.isFinite(metrics.agentMs) ? metrics.agentMs : 0
|
|
214
|
+
},
|
|
215
|
+
tasks: sanitizeTasks(state.taskRuns || []),
|
|
216
|
+
checks: sanitizeChecks(state.checks || []),
|
|
217
|
+
coverage: sanitizeCoverage(state.coverage),
|
|
218
|
+
events: sanitizeEvents(state.history || [])
|
|
219
|
+
};
|
|
220
|
+
}
|
package/dashboard-ui.mjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
function escapeHtml(value) {
|
|
2
|
+
return String(value ?? '').replace(/[&<>"']/g, character => ({
|
|
3
|
+
'&': '&',
|
|
4
|
+
'<': '<',
|
|
5
|
+
'>': '>',
|
|
6
|
+
'"': '"',
|
|
7
|
+
"'": '''
|
|
8
|
+
}[character]));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function list(values) {
|
|
12
|
+
return Array.isArray(values) ? values : [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function taskMatches(task, filter) {
|
|
16
|
+
return filter === 'all' || task.status === filter;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizedFilter(filter) {
|
|
20
|
+
return ['all', 'pending', 'running', 'accepted'].includes(filter) ? filter : 'all';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function renderTasks(tasks, filter) {
|
|
24
|
+
const visible = list(tasks).filter(task => taskMatches(task, filter));
|
|
25
|
+
if (!visible.length) return '<p class="empty">No task checkpoints match this filter.</p>';
|
|
26
|
+
|
|
27
|
+
return '<div class="task-list">' + visible.map(task => {
|
|
28
|
+
const criteria = list(task.criteria).map(item => '<code>' + escapeHtml(item) + '</code>').join(' ');
|
|
29
|
+
return '<article class="task">' +
|
|
30
|
+
'<div class="task-heading"><strong>' + escapeHtml(task.id) + '</strong>' +
|
|
31
|
+
'<span class="status">' + escapeHtml(task.status) + '</span></div>' +
|
|
32
|
+
'<div class="criteria">Criteria: ' + (criteria || 'none') + '</div>' +
|
|
33
|
+
'</article>';
|
|
34
|
+
}).join('') + '</div>';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function renderChecks(checks) {
|
|
38
|
+
if (!checks.length) return '<p class="empty">No named evidence checks recorded.</p>';
|
|
39
|
+
return '<div class="checks">' + checks.map(check => {
|
|
40
|
+
const tests = list(check.tests);
|
|
41
|
+
return '<article class="check">' +
|
|
42
|
+
'<h3>' + escapeHtml(check.id) + '</h3>' +
|
|
43
|
+
'<p>Exit code: ' + escapeHtml(check.code) + ' · Evidence: ' +
|
|
44
|
+
'<strong>' + (check.evidenceValid ? 'valid' : 'invalid') + '</strong></p>' +
|
|
45
|
+
(tests.length ? '<ul>' + tests.map(test => '<li><code>' + escapeHtml(test.id) + '</code> ' +
|
|
46
|
+
escapeHtml(test.name) + ' <span class="status">' + escapeHtml(test.status) + '</span></li>').join('') +
|
|
47
|
+
'</ul>' : '<p class="empty">No named tests.</p>') +
|
|
48
|
+
'</article>';
|
|
49
|
+
}).join('') + '</div>';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function renderRoutes(routing) {
|
|
53
|
+
const value = routing && typeof routing === 'object' ? routing : {};
|
|
54
|
+
const defaultRoute = value.default && typeof value.default === 'object' ? value.default : {};
|
|
55
|
+
const overrides = value.overrides && typeof value.overrides === 'object' ? value.overrides : {};
|
|
56
|
+
const rows = [['default', defaultRoute], ...Object.entries(overrides)];
|
|
57
|
+
return '<table><thead><tr><th>Route</th><th>Agent</th><th>Model</th></tr></thead><tbody>' +
|
|
58
|
+
rows.map(([name, route]) => '<tr><td>' + escapeHtml(name) + '</td><td>' +
|
|
59
|
+
escapeHtml(route?.agent) + '</td><td>' + escapeHtml(route?.model) + '</td></tr>').join('') +
|
|
60
|
+
'</tbody></table>';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function renderEvents(events) {
|
|
64
|
+
if (!events.length) return '<p class="empty">No events recorded.</p>';
|
|
65
|
+
return '<table><thead><tr><th>At</th><th>Stage</th><th>Status</th><th>Agent</th><th>Model</th></tr></thead><tbody>' +
|
|
66
|
+
events.map(event => '<tr><td>' + escapeHtml(event.at) + '</td><td>' +
|
|
67
|
+
escapeHtml(event.stage) + '</td><td>' + escapeHtml(event.status) + '</td><td>' +
|
|
68
|
+
escapeHtml(event.agent) + '</td><td>' + escapeHtml(event.model) + '</td></tr>').join('') +
|
|
69
|
+
'</tbody></table>';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function renderDashboard(view, {filter = 'all'} = {}) {
|
|
73
|
+
const currentFilter = normalizedFilter(filter);
|
|
74
|
+
const status = typeof view?.status === 'string' ? view.status : 'UNKNOWN';
|
|
75
|
+
const stale = status === 'STALE';
|
|
76
|
+
const metrics = view?.metrics && typeof view.metrics === 'object' ? view.metrics : {};
|
|
77
|
+
const tasks = list(view?.tasks);
|
|
78
|
+
const checks = list(view?.checks);
|
|
79
|
+
const events = list(view?.events);
|
|
80
|
+
const title = escapeHtml(view?.title || 'TeImMo dashboard');
|
|
81
|
+
const phase = escapeHtml(view?.phase);
|
|
82
|
+
const busy = view?.busy ? 'busy' : 'idle';
|
|
83
|
+
|
|
84
|
+
return '<!doctype html>\n' +
|
|
85
|
+
'<html lang="en"><head><meta charset="utf-8">' +
|
|
86
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">' +
|
|
87
|
+
'<meta http-equiv="refresh" content="5">' +
|
|
88
|
+
'<title>' + title + ' · dashboard</title>' +
|
|
89
|
+
'<style>' +
|
|
90
|
+
':root{font-family:system-ui,sans-serif;color:#18202b;background:#f6f8fb}' +
|
|
91
|
+
'body{margin:0;padding:1rem;line-height:1.45}' +
|
|
92
|
+
'main{max-width:1100px;margin:0 auto}' +
|
|
93
|
+
'section{background:#fff;border:1px solid #dce2ea;border-radius:.6rem;padding:1rem;margin:1rem 0;overflow:auto}' +
|
|
94
|
+
'h1{margin:.25rem 0}h2{margin-top:0}h3{margin:.25rem 0}' +
|
|
95
|
+
'.summary{display:flex;flex-wrap:wrap;gap:.6rem 1rem;align-items:center}' +
|
|
96
|
+
'.badge,.status{display:inline-block;border-radius:999px;padding:.15rem .55rem;background:#e8edf5;font-size:.9em}' +
|
|
97
|
+
'.stale{color:#8a3b00;background:#fff0d6;font-weight:700}' +
|
|
98
|
+
'.busy{color:#8a3b00}.idle{color:#24613b}' +
|
|
99
|
+
'.task-list,.checks{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:.75rem}' +
|
|
100
|
+
'.task,.check{border:1px solid #dce2ea;border-radius:.45rem;padding:.75rem}' +
|
|
101
|
+
'.task-heading{display:flex;justify-content:space-between;gap:1rem}' +
|
|
102
|
+
'.criteria{margin-top:.5rem;color:#526070}code{background:#eef2f7;padding:.1rem .3rem;border-radius:.25rem}' +
|
|
103
|
+
'table{border-collapse:collapse;width:100%;min-width:30rem}th,td{border:1px solid #dce2ea;padding:.5rem;text-align:left;vertical-align:top;overflow-wrap:anywhere}' +
|
|
104
|
+
'th{background:#f0f3f7}.empty{color:#526070}' +
|
|
105
|
+
'form{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center}select,button,.button{font:inherit;padding:.4rem .6rem}' +
|
|
106
|
+
'.button{color:inherit;text-decoration:none;border:1px solid #767676;border-radius:2px;background:#efefef}' +
|
|
107
|
+
'@media(max-width:600px){body{padding:.5rem}section{padding:.75rem}table{min-width:0;font-size:.9rem}}' +
|
|
108
|
+
'</style></head><body><main>' +
|
|
109
|
+
'<header><h1>' + title + '</h1>' +
|
|
110
|
+
'<div class="summary"><span class="badge ' + (stale ? 'stale' : '') + '">Verdict: ' +
|
|
111
|
+
escapeHtml(status) + (stale ? ' — stale evidence' : '') + '</span>' +
|
|
112
|
+
'<span>Phase: ' + phase + '</span><span class="' + busy + '">Run: ' +
|
|
113
|
+
escapeHtml(busy) + '</span></div></header>' +
|
|
114
|
+
'<section><h2>Refresh and task filter</h2><form method="get" action="/">' +
|
|
115
|
+
'<label for="filter">Tasks</label><select id="filter" name="filter">' +
|
|
116
|
+
['all', 'pending', 'running', 'accepted'].map(option => '<option value="' + option + '"' +
|
|
117
|
+
(option === currentFilter ? ' selected' : '') + '>' + option + '</option>').join('') +
|
|
118
|
+
'</select><button type="submit">Apply filter</button>' +
|
|
119
|
+
'<a class="button" href="/?filter=' + currentFilter + '">Refresh now</a>' +
|
|
120
|
+
'</form></section>' +
|
|
121
|
+
'<section><h2>Run metrics</h2><p>Agent calls: ' + escapeHtml(metrics.calls) +
|
|
122
|
+
' · Agent time: ' + escapeHtml(metrics.agentMs) + ' ms</p></section>' +
|
|
123
|
+
'<section><h2>Task checkpoints</h2>' + renderTasks(tasks, currentFilter) + '</section>' +
|
|
124
|
+
'<section><h2>Agent routes</h2>' + renderRoutes(view?.routing) + '</section>' +
|
|
125
|
+
'<section><h2>Named evidence</h2>' + renderChecks(checks) + '</section>' +
|
|
126
|
+
'<section><h2>Events</h2>' + renderEvents(events) + '</section>' +
|
|
127
|
+
'</main></body></html>';
|
|
128
|
+
}
|
package/dashboard.mjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import {buildStatus} from './dashboard-state.mjs';
|
|
3
|
+
import {renderDashboard} from './dashboard-ui.mjs';
|
|
4
|
+
|
|
5
|
+
const SECURITY_HEADERS = {
|
|
6
|
+
'Cache-Control': 'no-store',
|
|
7
|
+
'X-Content-Type-Options': 'nosniff',
|
|
8
|
+
'Content-Security-Policy': "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function write(response, status, contentType, body, extraHeaders = {}) {
|
|
12
|
+
response.writeHead(status, {
|
|
13
|
+
...SECURITY_HEADERS,
|
|
14
|
+
'Content-Type': contentType,
|
|
15
|
+
...extraHeaders
|
|
16
|
+
});
|
|
17
|
+
response.end(body);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function json(response, status, value, extraHeaders) {
|
|
21
|
+
write(response, status, 'application/json; charset=utf-8', JSON.stringify(value), extraHeaders);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function unavailable(response) {
|
|
25
|
+
json(response, 503, {error: 'Service unavailable'});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function validateOptions(options) {
|
|
29
|
+
if (options === null || typeof options !== 'object' || Array.isArray(options)) {
|
|
30
|
+
throw new TypeError('Dashboard options must be an object');
|
|
31
|
+
}
|
|
32
|
+
const port = options.port ?? 0;
|
|
33
|
+
const host = options.host ?? '127.0.0.1';
|
|
34
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
35
|
+
throw new RangeError('Dashboard port must be an integer from 0 through 65535');
|
|
36
|
+
}
|
|
37
|
+
if (host !== '127.0.0.1') {
|
|
38
|
+
throw new Error('Dashboard host must be 127.0.0.1');
|
|
39
|
+
}
|
|
40
|
+
return {port, host};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function startDashboard(root, options = {}) {
|
|
44
|
+
const {port, host} = validateOptions(options);
|
|
45
|
+
let publicUrl = null;
|
|
46
|
+
|
|
47
|
+
const server = http.createServer((request, response) => {
|
|
48
|
+
try {
|
|
49
|
+
const expectedHost = publicUrl && new URL(publicUrl).host;
|
|
50
|
+
if (!expectedHost || request.headers.host !== expectedHost) {
|
|
51
|
+
json(response, 403, {error: 'Forbidden'});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const origin = request.headers.origin;
|
|
56
|
+
if (origin !== undefined && origin !== publicUrl) {
|
|
57
|
+
json(response, 403, {error: 'Forbidden'});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const target = new URL(request.url || '/', publicUrl);
|
|
62
|
+
if (target.origin !== publicUrl) {
|
|
63
|
+
json(response, 403, {error: 'Forbidden'});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (request.method !== 'GET') {
|
|
68
|
+
json(response, 405, {error: 'Method not allowed'}, {Allow: 'GET'});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (target.pathname === '/api/status' && target.search === '') {
|
|
73
|
+
try {
|
|
74
|
+
json(response, 200, buildStatus(root));
|
|
75
|
+
} catch {
|
|
76
|
+
unavailable(response);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (target.pathname === '/') {
|
|
82
|
+
try {
|
|
83
|
+
const view = buildStatus(root);
|
|
84
|
+
write(
|
|
85
|
+
response,
|
|
86
|
+
200,
|
|
87
|
+
'text/html; charset=utf-8',
|
|
88
|
+
renderDashboard(view, {filter: target.searchParams.get('filter') || 'all'})
|
|
89
|
+
);
|
|
90
|
+
} catch {
|
|
91
|
+
unavailable(response);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
json(response, 404, {error: 'Not found'});
|
|
97
|
+
} catch {
|
|
98
|
+
unavailable(response);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
await new Promise((resolve, reject) => {
|
|
103
|
+
const onError = error => {
|
|
104
|
+
server.off('listening', onListening);
|
|
105
|
+
reject(error);
|
|
106
|
+
};
|
|
107
|
+
const onListening = () => {
|
|
108
|
+
server.off('error', onError);
|
|
109
|
+
resolve();
|
|
110
|
+
};
|
|
111
|
+
server.once('error', onError);
|
|
112
|
+
server.once('listening', onListening);
|
|
113
|
+
server.listen(port, host);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const address = server.address();
|
|
117
|
+
if (!address || typeof address === 'string') {
|
|
118
|
+
await new Promise(resolve => server.close(resolve));
|
|
119
|
+
throw new Error('Dashboard did not acquire a TCP address');
|
|
120
|
+
}
|
|
121
|
+
publicUrl = `http://${host}:${address.port}`;
|
|
122
|
+
|
|
123
|
+
let closePromise = null;
|
|
124
|
+
const close = () => {
|
|
125
|
+
if (closePromise) return closePromise;
|
|
126
|
+
closePromise = new Promise((resolve, reject) => {
|
|
127
|
+
server.close(error => error ? reject(error) : resolve());
|
|
128
|
+
});
|
|
129
|
+
return closePromise;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return {server, url: publicUrl, close};
|
|
133
|
+
}
|
package/domain.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {assert,readJson} from './artifacts.mjs';
|
|
4
|
+
|
|
5
|
+
export const dimensions=['happy','error','boundary','permission','state','concurrency','retry','integration','data','performance','compatibility'];
|
|
6
|
+
export function domainTemplate() {
|
|
7
|
+
return {version:1,purpose:'',actors:[],scope:{in:[],out:[]},terms:[],facts:[],decisions:[],questions:[],rules:[],cases:[],dimensions:dimensions.map(id=>({id,status:'unreviewed',rationale:''}))};
|
|
8
|
+
}
|
|
9
|
+
export function domainProposals(stage,response){
|
|
10
|
+
assert(!response.files.some(file=>file.path.toLowerCase()==='harness-spec/domain.json'),'Use validated top-level domain field for business records');
|
|
11
|
+
if(response.domain===undefined)return response.files;
|
|
12
|
+
assert(['discussion','requirements','design','tasks','analysis'].includes(stage),'Domain updates belong to planning only; reopen planning for business changes');
|
|
13
|
+
validateDomain(response.domain);
|
|
14
|
+
return [...response.files,{path:'harness-spec/domain.json',content:JSON.stringify(response.domain,null,2)}];
|
|
15
|
+
}
|
|
16
|
+
export function validateDomain(value) {
|
|
17
|
+
assert(value && value.version===1,'Domain version must be 1');
|
|
18
|
+
const string=(x,label)=>assert(typeof x==='string',label+' must be a string');
|
|
19
|
+
const list=(x,label)=>assert(Array.isArray(x),label+' must be an array');
|
|
20
|
+
string(value.purpose,'purpose');
|
|
21
|
+
assert(value.scope && typeof value.scope==='object','scope required');
|
|
22
|
+
for(const name of ['in','out']) {list(value.scope[name],'scope.'+name);value.scope[name].forEach(x=>string(x,'scope item'));}
|
|
23
|
+
for(const name of ['actors','terms','facts','decisions','questions','rules','cases','dimensions']) list(value[name],name);
|
|
24
|
+
for(const name of ['actors','facts','decisions','questions','rules','cases','dimensions']) {
|
|
25
|
+
const ids=new Set();
|
|
26
|
+
for(const item of value[name]) {assert(item && typeof item.id==='string' && /^[A-Za-z][\w-]*$/.test(item.id) && !ids.has(item.id),'Invalid/duplicate '+name+' ID');ids.add(item.id);}
|
|
27
|
+
}
|
|
28
|
+
value.actors.forEach(x=>string(x.description,'actor description'));
|
|
29
|
+
value.terms.forEach(x=>{string(x.term,'term');string(x.meaning,'meaning');});
|
|
30
|
+
for(const name of ['facts','decisions','rules']) for(const item of value[name]) {string(item.statement,'statement');string(item.source,'source');}
|
|
31
|
+
value.decisions.forEach(x=>assert(['proposed','confirmed'].includes(x.status),'Decision status invalid'));
|
|
32
|
+
value.questions.forEach(x=>{string(x.question,'question');assert(typeof x.blocking==='boolean','blocking must be boolean');string(x.resolution,'resolution');string(x.source,'source');});
|
|
33
|
+
value.rules.forEach(x=>{list(x.actors,'rule actors');assert(x.actors.every(id=>value.actors.some(a=>a.id===id)),'Unknown actor');});
|
|
34
|
+
for(const item of value.cases) {
|
|
35
|
+
for(const key of ['given','when','then'])string(item[key],key);
|
|
36
|
+
for(const key of ['rules','kinds','criteria','checks'])list(item[key],key);
|
|
37
|
+
assert(item.rules.every(id=>value.rules.some(r=>r.id===id)),'Unknown rule');
|
|
38
|
+
assert(item.kinds.every(id=>dimensions.includes(id)),'Unknown case dimension');
|
|
39
|
+
assert(item.criteria.every(id=>typeof id==='string'&&/^AC-\d+$/.test(id)),'Invalid case criterion');
|
|
40
|
+
assert(item.checks.every(id=>typeof id==='string'&&/^[\w-]+$/.test(id)),'Invalid case check');
|
|
41
|
+
}
|
|
42
|
+
value.dimensions.forEach(x=>{assert(dimensions.includes(x.id)&&['unreviewed','covered','na'].includes(x.status),'Invalid dimension');string(x.rationale,'dimension rationale');});
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
export function inspectDomain(root,plan=null,required=false) {
|
|
46
|
+
const file=path.join(root,'harness-spec/domain.json');
|
|
47
|
+
if(!fs.existsSync(file))return {enabled:required,ready:!required,gaps:required?['Domain record missing']:[],cases:[],notice:'No claim of exhaustive business coverage'};
|
|
48
|
+
const value=validateDomain(readJson(file)),gaps=[];
|
|
49
|
+
const need=(ok,message)=>{if(!ok)gaps.push(message);};
|
|
50
|
+
need(value.purpose.trim(),'Project purpose missing');
|
|
51
|
+
need(value.actors.length,'Actors missing');
|
|
52
|
+
need(value.scope.in.length,'In-scope behavior missing');
|
|
53
|
+
need(value.scope.out.length,'Out-of-scope boundary missing');
|
|
54
|
+
need(value.rules.length,'Business rules missing');
|
|
55
|
+
for(const group of ['facts','decisions','rules'])for(const item of value[group]) {
|
|
56
|
+
need(item.statement.trim(),group+' '+item.id+' empty');need(item.source.trim(),group+' '+item.id+' has no source');
|
|
57
|
+
if(group==='decisions')need(item.status==='confirmed','Unconfirmed decision '+item.id);
|
|
58
|
+
}
|
|
59
|
+
for(const q of value.questions) if(q.blocking) {need(q.resolution.trim(),'Unresolved question '+q.id);if(q.resolution.trim())need(q.source.trim(),'Resolution has no source '+q.id);}
|
|
60
|
+
for(const id of dimensions) {
|
|
61
|
+
const item=value.dimensions.find(x=>x.id===id);
|
|
62
|
+
need(item && item.status!=='unreviewed','Dimension not reviewed: '+id);
|
|
63
|
+
if(item?.status==='na') {need(item.rationale.trim(),'N/A needs rationale: '+id);need(!value.cases.some(c=>c.kinds.includes(id)),'Dimension marked N/A but has cases: '+id);}
|
|
64
|
+
if(item?.status==='covered')need(value.cases.some(c=>c.kinds.includes(id)),'Dimension has no case: '+id);
|
|
65
|
+
}
|
|
66
|
+
need(value.dimensions.find(x=>x.id==='happy')?.status==='covered','Happy path must be covered');
|
|
67
|
+
for(const rule of value.rules) {need(rule.actors.length,'Rule has no actor: '+rule.id);need(value.cases.some(c=>c.rules.includes(rule.id)),'Rule has no case: '+rule.id);}
|
|
68
|
+
for(const item of value.cases) {
|
|
69
|
+
need(item.rules.length&&item.kinds.length,'Case has no rule/dimension: '+item.id);
|
|
70
|
+
for(const key of ['given','when','then'])need(item[key].trim(),'Case '+item.id+' missing '+key);
|
|
71
|
+
if(plan) {
|
|
72
|
+
need(item.criteria.length&&item.checks.length,'Case has no AC/check mapping: '+item.id);
|
|
73
|
+
need(item.criteria.every(id=>plan.trace.criteria.includes(id)),'Case references unknown AC: '+item.id);
|
|
74
|
+
need(item.checks.every(id=>plan.checks.some(c=>c.id===id)),'Case references unknown check: '+item.id);
|
|
75
|
+
need(item.criteria.every(ac=>item.checks.some(id=>plan.checks.find(c=>c.id===id)?.evidence?.tests.some(t=>t.cases?.includes(item.id)&&t.criteria.includes(ac)))),'Case has no named executable test binding: '+item.id);
|
|
76
|
+
for(const id of item.criteria)need(plan.trace.coverage.some(row=>row.criterion===id&&item.checks.some(check=>row.checks.includes(check))),'Case contradicts AC/check trace: '+item.id+' '+id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {enabled:true,ready:gaps.length===0,phase:plan?'mapped':'discovery',gaps,cases:value.cases,dimensions:value.dimensions,notice:'Structural coverage only; assertions and business completeness still require review'};
|
|
80
|
+
}
|