@ngockhoale/ckit 0.0.0-stage → 0.1.1
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/.env.example +21 -0
- package/README.md +70 -2
- package/dist/src/adapters/agent/claude/errors.d.ts +13 -0
- package/dist/src/adapters/agent/claude/errors.js +16 -0
- package/dist/src/adapters/agent/claude/normalize.d.ts +11 -0
- package/dist/src/adapters/agent/claude/normalize.js +83 -0
- package/dist/src/adapters/agent/errors.d.ts +13 -0
- package/dist/src/adapters/agent/errors.js +19 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.d.ts +70 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.js +15 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.d.ts +60 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.js +14 -0
- package/dist/src/adapters/agent/normalize.d.ts +18 -0
- package/dist/src/adapters/agent/normalize.js +77 -0
- package/dist/src/adapters/agent/transport.d.ts +35 -0
- package/dist/src/adapters/agent/transport.js +39 -0
- package/dist/src/adapters/agent/worker-service.d.ts +49 -0
- package/dist/src/adapters/agent/worker-service.js +77 -0
- package/dist/src/adapters/fake/fake-advisor.d.ts +15 -0
- package/dist/src/adapters/fake/fake-advisor.js +29 -0
- package/dist/src/adapters/fake/fake-agent.d.ts +12 -0
- package/dist/src/adapters/fake/fake-agent.js +21 -0
- package/dist/src/adapters/fake/fake-store.d.ts +13 -0
- package/dist/src/adapters/fake/fake-store.js +23 -0
- package/dist/src/adapters/fake/fake-web.d.ts +12 -0
- package/dist/src/adapters/fake/fake-web.js +21 -0
- package/dist/src/adapters/fake/fault-injector.d.ts +18 -0
- package/dist/src/adapters/fake/fault-injector.js +64 -0
- package/dist/src/adapters/fake/virtual-clock.d.ts +12 -0
- package/dist/src/adapters/fake/virtual-clock.js +35 -0
- package/dist/src/adapters/launch/discover.d.ts +18 -0
- package/dist/src/adapters/launch/discover.js +55 -0
- package/dist/src/adapters/launch/executor.d.ts +117 -0
- package/dist/src/adapters/launch/executor.js +383 -0
- package/dist/src/adapters/launch/profile.d.ts +35 -0
- package/dist/src/adapters/launch/profile.js +73 -0
- package/dist/src/adapters/launch/spawn.d.ts +29 -0
- package/dist/src/adapters/launch/spawn.js +18 -0
- package/dist/src/adapters/openai/openai-advisor.d.ts +56 -0
- package/dist/src/adapters/openai/openai-advisor.js +146 -0
- package/dist/src/cli/ckit.d.ts +5 -0
- package/dist/src/cli/ckit.js +384 -0
- package/dist/src/cli/demo.d.ts +1 -0
- package/dist/src/cli/demo.js +30 -0
- package/dist/src/cli/lifecycle.d.ts +19 -0
- package/dist/src/cli/lifecycle.js +90 -0
- package/dist/src/cli/sessions.d.ts +10 -0
- package/dist/src/cli/sessions.js +381 -0
- package/dist/src/cli/setup.d.ts +11 -0
- package/dist/src/cli/setup.js +115 -0
- package/dist/src/committee/decision.d.ts +84 -0
- package/dist/src/committee/decision.js +167 -0
- package/dist/src/committee/handover.d.ts +115 -0
- package/dist/src/committee/handover.js +191 -0
- package/dist/src/committee/no-progress.d.ts +44 -0
- package/dist/src/committee/no-progress.js +64 -0
- package/dist/src/committee/primary-registry.d.ts +15 -0
- package/dist/src/committee/primary-registry.js +60 -0
- package/dist/src/committee/reply-parser.d.ts +28 -0
- package/dist/src/committee/reply-parser.js +53 -0
- package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
- package/dist/src/committee/reviewer-scheduler.js +163 -0
- package/dist/src/committee/role-epoch.d.ts +91 -0
- package/dist/src/committee/role-epoch.js +154 -0
- package/dist/src/core/control.d.ts +18 -0
- package/dist/src/core/control.js +29 -0
- package/dist/src/core/entities.d.ts +166 -0
- package/dist/src/core/entities.js +119 -0
- package/dist/src/core/errors.d.ts +9 -0
- package/dist/src/core/errors.js +17 -0
- package/dist/src/core/events.d.ts +72 -0
- package/dist/src/core/events.js +125 -0
- package/dist/src/core/ids.d.ts +47 -0
- package/dist/src/core/ids.js +32 -0
- package/dist/src/core/machine.d.ts +55 -0
- package/dist/src/core/machine.js +110 -0
- package/dist/src/core/policy.d.ts +34 -0
- package/dist/src/core/policy.js +59 -0
- package/dist/src/core/provenance.d.ts +20 -0
- package/dist/src/core/provenance.js +21 -0
- package/dist/src/core/record.d.ts +35 -0
- package/dist/src/core/record.js +67 -0
- package/dist/src/core/replay.d.ts +10 -0
- package/dist/src/core/replay.js +36 -0
- package/dist/src/core/run-task.d.ts +20 -0
- package/dist/src/core/run-task.js +48 -0
- package/dist/src/diagnostics/doctor.d.ts +78 -0
- package/dist/src/diagnostics/doctor.js +365 -0
- package/dist/src/diagnostics/journal-lock.d.ts +38 -0
- package/dist/src/diagnostics/journal-lock.js +181 -0
- package/dist/src/evidence/linker.d.ts +44 -0
- package/dist/src/evidence/linker.js +75 -0
- package/dist/src/evidence/report-parser.d.ts +27 -0
- package/dist/src/evidence/report-parser.js +17 -0
- package/dist/src/evidence/store.d.ts +36 -0
- package/dist/src/evidence/store.js +57 -0
- package/dist/src/gui/server.d.ts +27 -0
- package/dist/src/gui/server.js +497 -0
- package/dist/src/host/checkpoint.d.ts +22 -0
- package/dist/src/host/checkpoint.js +74 -0
- package/dist/src/host/export.d.ts +52 -0
- package/dist/src/host/export.js +45 -0
- package/dist/src/host/ipc.d.ts +57 -0
- package/dist/src/host/ipc.js +124 -0
- package/dist/src/host/leases.d.ts +27 -0
- package/dist/src/host/leases.js +40 -0
- package/dist/src/host/retention.d.ts +47 -0
- package/dist/src/host/retention.js +130 -0
- package/dist/src/host/supervisor.d.ts +59 -0
- package/dist/src/host/supervisor.js +64 -0
- package/dist/src/intake/owner-intake.d.ts +31 -0
- package/dist/src/intake/owner-intake.js +97 -0
- package/dist/src/intake/types.d.ts +46 -0
- package/dist/src/intake/types.js +2 -0
- package/dist/src/intent/context-packet.d.ts +68 -0
- package/dist/src/intent/context-packet.js +76 -0
- package/dist/src/intent/idea-ledger.d.ts +50 -0
- package/dist/src/intent/idea-ledger.js +136 -0
- package/dist/src/intent/ledger.d.ts +35 -0
- package/dist/src/intent/ledger.js +40 -0
- package/dist/src/intent/registry.d.ts +51 -0
- package/dist/src/intent/registry.js +44 -0
- package/dist/src/intent/revision.d.ts +37 -0
- package/dist/src/intent/revision.js +48 -0
- package/dist/src/orchestration/dispatcher.d.ts +32 -0
- package/dist/src/orchestration/dispatcher.js +136 -0
- package/dist/src/orchestration/milestone-loop.d.ts +149 -0
- package/dist/src/orchestration/milestone-loop.js +132 -0
- package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
- package/dist/src/orchestration/recovery-coordinator.js +180 -0
- package/dist/src/orchestration/work-order-contract.d.ts +44 -0
- package/dist/src/orchestration/work-order-contract.js +85 -0
- package/dist/src/orchestration/work-queue.d.ts +56 -0
- package/dist/src/orchestration/work-queue.js +95 -0
- package/dist/src/ports/advisor.d.ts +33 -0
- package/dist/src/ports/advisor.js +2 -0
- package/dist/src/ports/agent.d.ts +31 -0
- package/dist/src/ports/agent.js +2 -0
- package/dist/src/ports/capabilities.d.ts +3 -0
- package/dist/src/ports/capabilities.js +5 -0
- package/dist/src/ports/clock.d.ts +5 -0
- package/dist/src/ports/clock.js +5 -0
- package/dist/src/ports/store.d.ts +13 -0
- package/dist/src/ports/store.js +2 -0
- package/dist/src/ports/web.d.ts +29 -0
- package/dist/src/ports/web.js +2 -0
- package/dist/src/run/api-run.d.ts +49 -0
- package/dist/src/run/api-run.js +173 -0
- package/dist/src/run/plan-run.d.ts +22 -0
- package/dist/src/run/plan-run.js +233 -0
- package/dist/src/run/plan.d.ts +36 -0
- package/dist/src/run/plan.js +119 -0
- package/dist/src/run/verify.d.ts +25 -0
- package/dist/src/run/verify.js +81 -0
- package/dist/src/security/redact.d.ts +7 -0
- package/dist/src/security/redact.js +21 -0
- package/dist/src/settings/env-config.d.ts +64 -0
- package/dist/src/settings/env-config.js +232 -0
- package/dist/src/storage/artifacts.d.ts +30 -0
- package/dist/src/storage/artifacts.js +105 -0
- package/dist/src/storage/audit.d.ts +6 -0
- package/dist/src/storage/audit.js +6 -0
- package/dist/src/storage/db.d.ts +9 -0
- package/dist/src/storage/db.js +43 -0
- package/dist/src/storage/events.d.ts +20 -0
- package/dist/src/storage/events.js +69 -0
- package/dist/src/storage/migrations.d.ts +8 -0
- package/dist/src/storage/migrations.js +48 -0
- package/dist/src/storage/outbox.d.ts +25 -0
- package/dist/src/storage/outbox.js +40 -0
- package/dist/src/storage/projections.d.ts +18 -0
- package/dist/src/storage/projections.js +40 -0
- package/dist/src/storage/reconcile.d.ts +14 -0
- package/dist/src/storage/reconcile.js +93 -0
- package/dist/src/storage/reservations.d.ts +12 -0
- package/dist/src/storage/reservations.js +80 -0
- package/dist/src/storage/store.d.ts +34 -0
- package/dist/src/storage/store.js +105 -0
- package/dist/src/team/attachments.d.ts +22 -0
- package/dist/src/team/attachments.js +211 -0
- package/dist/src/team/cli-models.d.ts +24 -0
- package/dist/src/team/cli-models.js +72 -0
- package/dist/src/team/config.d.ts +20 -0
- package/dist/src/team/config.js +113 -0
- package/dist/src/team/engine.d.ts +28 -0
- package/dist/src/team/engine.js +443 -0
- package/dist/src/team/journal.d.ts +30 -0
- package/dist/src/team/journal.js +70 -0
- package/dist/src/team/runners.d.ts +79 -0
- package/dist/src/team/runners.js +436 -0
- package/dist/src/team/secrets.d.ts +10 -0
- package/dist/src/team/secrets.js +68 -0
- package/dist/src/team/types.d.ts +157 -0
- package/dist/src/team/types.js +5 -0
- package/dist/src/tui/app.d.ts +29 -0
- package/dist/src/tui/app.js +96 -0
- package/dist/src/tui/control-model.d.ts +101 -0
- package/dist/src/tui/control-model.js +109 -0
- package/dist/src/tui/control-screens.d.ts +27 -0
- package/dist/src/tui/control-screens.js +85 -0
- package/dist/src/tui/graph-model.d.ts +34 -0
- package/dist/src/tui/graph-model.js +29 -0
- package/dist/src/tui/graph-screens.d.ts +13 -0
- package/dist/src/tui/graph-screens.js +4 -0
- package/dist/src/tui/inspector-model.d.ts +150 -0
- package/dist/src/tui/inspector-model.js +15 -0
- package/dist/src/tui/inspector-screens.d.ts +14 -0
- package/dist/src/tui/inspector-screens.js +61 -0
- package/dist/src/tui/live.d.ts +16 -0
- package/dist/src/tui/live.js +39 -0
- package/dist/src/tui/mission-action-screens.d.ts +15 -0
- package/dist/src/tui/mission-action-screens.js +105 -0
- package/dist/src/tui/mission-actions.d.ts +46 -0
- package/dist/src/tui/mission-actions.js +53 -0
- package/dist/src/tui/mission-model.d.ts +120 -0
- package/dist/src/tui/mission-model.js +164 -0
- package/dist/src/tui/mission-nav.d.ts +82 -0
- package/dist/src/tui/mission-nav.js +131 -0
- package/dist/src/tui/mission-plan-screens.d.ts +11 -0
- package/dist/src/tui/mission-plan-screens.js +40 -0
- package/dist/src/tui/mission-plan.d.ts +45 -0
- package/dist/src/tui/mission-plan.js +166 -0
- package/dist/src/tui/mission-screens.d.ts +7 -0
- package/dist/src/tui/mission-screens.js +263 -0
- package/dist/src/tui/provenance-label.d.ts +11 -0
- package/dist/src/tui/provenance-label.js +16 -0
- package/dist/src/tui/screens.d.ts +10 -0
- package/dist/src/tui/screens.js +34 -0
- package/dist/src/tui/session-outcome.d.ts +14 -0
- package/dist/src/tui/session-outcome.js +57 -0
- package/dist/src/tui/setup-model.d.ts +159 -0
- package/dist/src/tui/setup-model.js +234 -0
- package/dist/src/tui/setup-screens.d.ts +66 -0
- package/dist/src/tui/setup-screens.js +72 -0
- package/dist/src/tui/team/app.d.ts +24 -0
- package/dist/src/tui/team/app.js +228 -0
- package/dist/src/tui/team/demo-handle.d.ts +22 -0
- package/dist/src/tui/team/demo-handle.js +42 -0
- package/dist/src/tui/team/model.d.ts +81 -0
- package/dist/src/tui/team/model.js +133 -0
- package/gui/app.css +177 -0
- package/gui/app.js +677 -0
- package/gui/index.html +51 -0
- package/gui/network.js +413 -0
- package/package.json +44 -4
- package/src/storage/schema.sql +42 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstat, readFile } from 'node:fs/promises';
|
|
3
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { redactSecretText } from '../security/redact.js';
|
|
6
|
+
export const PLAN_INDEX_PATH = 'docs/AI_HANDOFF/INDEX.md';
|
|
7
|
+
/** Strip OSC/CSI sequences and remaining control bytes, then redact secret-shaped text. */
|
|
8
|
+
export function sanitizePlanText(value) {
|
|
9
|
+
return redactSecretText(value.replace(/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?/g, '').replace(/\u001b\[[0-?]*[ -/]*[@-~]?/g, '').replace(/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, ' ')).trim();
|
|
10
|
+
}
|
|
11
|
+
const DONE_STATUSES = new Set(['approved', 'approved_minor', 'done']);
|
|
12
|
+
const cells = (line) => line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map(c => c.trim());
|
|
13
|
+
function parseIndex(text) {
|
|
14
|
+
const lines = text.split(/\r?\n/);
|
|
15
|
+
const rows = [];
|
|
16
|
+
let found = false;
|
|
17
|
+
for (let h = 0; h < lines.length; h++) {
|
|
18
|
+
const l = lines[h];
|
|
19
|
+
if (!(l.trim().startsWith('|') && /^\|?[\s:-]+(\|[\s:-]+)+\|?$/.test(lines[h + 1]?.trim() ?? '')))
|
|
20
|
+
continue;
|
|
21
|
+
const head = cells(l).map(c => c.toLowerCase());
|
|
22
|
+
const col = (n) => head.indexOf(n);
|
|
23
|
+
if (col('id') < 0 || col('status') < 0 || col('file') < 0)
|
|
24
|
+
continue;
|
|
25
|
+
found = true;
|
|
26
|
+
let i = h + 2;
|
|
27
|
+
for (; i < lines.length && (lines[i].trim() === '' || lines[i].trim().startsWith('|')); i++) {
|
|
28
|
+
if (lines[i].trim() === '')
|
|
29
|
+
continue;
|
|
30
|
+
if (/^\|?[\s:-]+(\|[\s:-]+)+\|?$/.test(lines[i + 1]?.trim() ?? ''))
|
|
31
|
+
break; // next table's header
|
|
32
|
+
// a blank line does not end the table; prose does
|
|
33
|
+
const c = cells(lines[i]);
|
|
34
|
+
const id = c[col('id')] ?? '';
|
|
35
|
+
if (!id)
|
|
36
|
+
continue;
|
|
37
|
+
const statusCell = c[col('status')] ?? '';
|
|
38
|
+
rows.push({ id, title: c[col('title')] ?? '', status: statusCell.replace(/`/g, '').split(/\s+/)[0] ?? '', statusCell, file: (c[col('file')] ?? '').replace(/`/g, '').trim() });
|
|
39
|
+
}
|
|
40
|
+
h = i - 1;
|
|
41
|
+
}
|
|
42
|
+
return found ? rows : null;
|
|
43
|
+
}
|
|
44
|
+
function sections(text) {
|
|
45
|
+
return text.split(/^#{2,4} /m).slice(1).map(s => { const i = s.indexOf('\n'); return { name: (i < 0 ? s : s.slice(0, i)).trim(), body: i < 0 ? '' : s.slice(i + 1) }; });
|
|
46
|
+
}
|
|
47
|
+
const sectionOf = (text, prefix) => sections(text).filter(s => prefix.test(s.name));
|
|
48
|
+
function parseTask(row, text) {
|
|
49
|
+
const ac = sectionOf(text, /^Acceptance Criteria\b/)[0]?.body ?? '';
|
|
50
|
+
const boxes = [...ac.matchAll(/^\s*- \[( |x|X)\]/gm)];
|
|
51
|
+
const deps = sectionOf(text, /^Dependencies\b/)[0]?.body ?? '';
|
|
52
|
+
const dependencies = [...new Set([...deps.matchAll(/TASK-([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)/g)].map(m => m[1]))];
|
|
53
|
+
const tf = sectionOf(text, /^Target Files\b/)[0]?.body ?? '';
|
|
54
|
+
const targetFiles = [...tf.matchAll(/^\s*- `([^`]+)`/gm)].map(m => sanitizePlanText(m[1]));
|
|
55
|
+
return Object.freeze({ id: sanitizePlanText(row.id), title: sanitizePlanText(row.title), status: sanitizePlanText(row.status), file: row.file, dependencies: Object.freeze(dependencies), acceptance: Object.freeze({ checked: boxes.filter(b => b[1] !== ' ').length, total: boxes.length }), targetFiles: Object.freeze(targetFiles) });
|
|
56
|
+
}
|
|
57
|
+
const sha = (h, b) => h.update(b);
|
|
58
|
+
const texts = new WeakMap();
|
|
59
|
+
const rowsOf = new WeakMap();
|
|
60
|
+
/** Read-only snapshot of `<root>/docs/AI_HANDOFF/INDEX.md` + referenced task files. Never writes. */
|
|
61
|
+
export async function readMissionPlan(projectRoot, now = () => new Date().toISOString()) {
|
|
62
|
+
const capturedAt = now();
|
|
63
|
+
const empty = (status, diagnostics, digest = null, sources = []) => Object.freeze({ status, root: projectRoot, sources: Object.freeze(sources), digest, capturedAt, tasks: Object.freeze([]), diagnostics: Object.freeze(diagnostics) });
|
|
64
|
+
let indexBytes;
|
|
65
|
+
try {
|
|
66
|
+
indexBytes = await readFile(join(projectRoot, PLAN_INDEX_PATH));
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
return empty('missing', [`Plan source not found: ${PLAN_INDEX_PATH}` + (e.code === 'ENOENT' ? '' : ` (${e.code ?? 'read error'})`)]);
|
|
70
|
+
}
|
|
71
|
+
const rows = parseIndex(indexBytes.toString('utf8'));
|
|
72
|
+
if (!rows)
|
|
73
|
+
return empty('malformed', [`Plan index malformed: no task table header in ${PLAN_INDEX_PATH}`], sha(createHash('sha256'), indexBytes).digest('hex'), [PLAN_INDEX_PATH]);
|
|
74
|
+
const diagnostics = [];
|
|
75
|
+
const loaded = [];
|
|
76
|
+
const rowTasks = [];
|
|
77
|
+
const base = join(projectRoot, 'docs/AI_HANDOFF');
|
|
78
|
+
for (const row of rows) {
|
|
79
|
+
const rel = row.file;
|
|
80
|
+
const ok = rel !== '' && !rel.startsWith('/') && !rel.split('/').includes('..');
|
|
81
|
+
if (!ok) {
|
|
82
|
+
diagnostics.push(`missing-task-file:${sanitizePlanText(row.id)}`);
|
|
83
|
+
rowTasks.push({ row, text: null });
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
if (!(await lstat(join(base, rel))).isFile()) {
|
|
88
|
+
diagnostics.push(`unsafe-task-file:${sanitizePlanText(row.id)}`);
|
|
89
|
+
rowTasks.push({ row, text: null });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const bytes = await readFile(join(base, rel));
|
|
93
|
+
loaded.push({ row, bytes });
|
|
94
|
+
rowTasks.push({ row, text: bytes.toString('utf8') });
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
diagnostics.push(`missing-task-file:${sanitizePlanText(row.id)}`);
|
|
98
|
+
rowTasks.push({ row, text: null });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const hash = createHash('sha256');
|
|
102
|
+
sha(hash, indexBytes);
|
|
103
|
+
const sorted = [...loaded].sort((a, b) => a.row.file < b.row.file ? -1 : a.row.file > b.row.file ? 1 : 0);
|
|
104
|
+
for (const l of sorted)
|
|
105
|
+
sha(hash, l.bytes);
|
|
106
|
+
const tasks = rowTasks.map(({ row, text }) => Object.freeze(text === null ? { id: sanitizePlanText(row.id), title: sanitizePlanText(row.title), status: sanitizePlanText(row.status), file: row.file, dependencies: Object.freeze([]), acceptance: Object.freeze({ checked: 0, total: 0 }), targetFiles: Object.freeze([]) } : parseTask(row, text)));
|
|
107
|
+
const snap = Object.freeze({ status: 'ok', root: projectRoot, sources: Object.freeze([PLAN_INDEX_PATH, ...sorted.map(l => `docs/AI_HANDOFF/${l.row.file}`)]), digest: hash.digest('hex'), capturedAt, tasks: Object.freeze(tasks), diagnostics: Object.freeze(diagnostics) });
|
|
108
|
+
texts.set(snap, new Map(rowTasks.flatMap(({ row, text }) => text === null ? [] : [[row.id, text]])));
|
|
109
|
+
rowsOf.set(snap, new Map(rows.map(r => [r.id, r])));
|
|
110
|
+
return snap;
|
|
111
|
+
}
|
|
112
|
+
/** Five independent facets. `check` comes only from the Reviewer Verdict VERIFICATION_RERUN line; executor claims never feed it. */
|
|
113
|
+
export function planTaskFacets(snapshot, taskId) {
|
|
114
|
+
const task = snapshot.tasks.find(t => t.id === taskId);
|
|
115
|
+
const text = texts.get(snapshot)?.get(taskId) ?? '';
|
|
116
|
+
const row = rowsOf.get(snapshot)?.get(taskId);
|
|
117
|
+
const exec = sectionOf(text, /\bExecutor Report\b/).at(-1);
|
|
118
|
+
const execStatus = exec ? /^STATUS:\s*([A-Za-z_-]+)/m.exec(exec.body)?.[1]?.toUpperCase() : undefined;
|
|
119
|
+
const agentReport = exec === undefined ? 'absent' : execStatus === 'DONE' ? 'complete' : 'partial';
|
|
120
|
+
const verdict = sectionOf(text, /\bReviewer Verdict\b/).at(-1)?.body;
|
|
121
|
+
const v = verdict ? /^VERDICT:\s*([A-Za-z_-]+)/m.exec(verdict)?.[1]?.toUpperCase() : undefined;
|
|
122
|
+
const rerun = verdict ? /^VERIFICATION_RERUN:\s*([A-Za-z_]+)/m.exec(verdict)?.[1]?.toUpperCase() : undefined;
|
|
123
|
+
const check = rerun === 'PASS' ? 'pass' : rerun === 'FAIL' ? 'fail' : 'absent';
|
|
124
|
+
const approved = v === 'APPROVED' || v === 'APPROVED-WITH-MINOR';
|
|
125
|
+
const review = approved ? 'approved' : v !== undefined && /^CHANGES[-_]REQUESTED$/.test(v) ? 'changes-requested' : 'pending';
|
|
126
|
+
const acOk = task !== undefined && task.acceptance.total > 0 && task.acceptance.checked === task.acceptance.total;
|
|
127
|
+
const acceptance = acOk && approved && check === 'pass' ? 'verified' : 'not-verified';
|
|
128
|
+
const ownerGate = task?.status === 'blocked' && row !== undefined && (/owner/i.test(row.statusCell) || /^-\s*Status:.*owner/im.test(text)) ? 'pending' : 'none';
|
|
129
|
+
const byId = new Map(snapshot.tasks.map(t => [t.id, t]));
|
|
130
|
+
const blockedBy = (task?.dependencies ?? []).filter(d => { const s = byId.get(d)?.status; return s === undefined || !DONE_STATUSES.has(s); });
|
|
131
|
+
return { agentReport, check, acceptance, review, ownerGate, blockedBy };
|
|
132
|
+
}
|
|
133
|
+
/** Workspace facts. Assigned scope (Target Files) is never presented as observed activity. */
|
|
134
|
+
export function workspaceFacts(projectRoot, view, agentId, task) {
|
|
135
|
+
let root = projectRoot, rootGone = false;
|
|
136
|
+
try {
|
|
137
|
+
root = realpathSync(projectRoot);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
rootGone = true;
|
|
141
|
+
} // root deleted/unmounted after the snapshot: render must not throw
|
|
142
|
+
const agent = view.agents.find(a => a.id === agentId);
|
|
143
|
+
const cwd = { status: 'unavailable', reason: agent?.kind === 'advisor' ? 'web advisor: no local filesystem' : agent ? 'cwd not recorded in v1 events' : 'unknown agent' };
|
|
144
|
+
return { projectRoot: root, cwd, branch: rootGone ? { status: 'unavailable', reason: 'project root unavailable (not accessible now)' } : readBranch(root), assignedFiles: task?.targetFiles ?? [], observedEdits: { status: 'unavailable', reason: 'no v1 event records file edits' } };
|
|
145
|
+
}
|
|
146
|
+
function readBranch(root) {
|
|
147
|
+
const git = join(root, '.git');
|
|
148
|
+
if (!existsSync(git))
|
|
149
|
+
return { status: 'unavailable', reason: 'no .git in project root' };
|
|
150
|
+
try {
|
|
151
|
+
let dir = git;
|
|
152
|
+
if (statSync(git).isFile()) {
|
|
153
|
+
const m = /^gitdir:\s*(.+)$/m.exec(readFileSync(git, 'utf8'));
|
|
154
|
+
if (!m)
|
|
155
|
+
return { status: 'unavailable', reason: '.git file unreadable' };
|
|
156
|
+
dir = resolve(root, m[1].trim());
|
|
157
|
+
}
|
|
158
|
+
const head = readFileSync(join(dir, 'HEAD'), 'utf8').trim();
|
|
159
|
+
const ref = /^ref:\s*refs\/heads\/(.+)$/.exec(head);
|
|
160
|
+
return { status: 'available', value: sanitizePlanText(ref ? ref[1] : `detached ${head.slice(0, 8)}`), source: '.git/HEAD' };
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return { status: 'unavailable', reason: '.git/HEAD unreadable' };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=mission-plan.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type MissionView, type MissionViewOptions } from './mission-model.js';
|
|
3
|
+
export declare function MissionScreen({ view, width, options }: {
|
|
4
|
+
view: MissionView;
|
|
5
|
+
width: number;
|
|
6
|
+
options?: MissionViewOptions;
|
|
7
|
+
}): ReactElement;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text, useInput, useStdout } from 'ink';
|
|
3
|
+
import stringWidth from 'string-width';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { redactSecretText } from '../security/redact.js';
|
|
6
|
+
import { InspectorBudgetContext, bindingLabel } from './mission-model.js';
|
|
7
|
+
import { activityEntries, agentRows, filteredConversation, initialMissionNav, missionRowBudget, missionWindow, reduceMissionNav, resolveTerminalProfile, searchMission } from './mission-nav.js';
|
|
8
|
+
const clean = (s) => redactSecretText(s).replace(/\s+/g, ' ').trim();
|
|
9
|
+
const clamp = (n, lo, hi) => Math.max(lo, Math.min(hi, n));
|
|
10
|
+
/** Word-wrap one paragraph to `width` terminal columns (display width, so CJK/emoji count 2); over-long words are hard-split. */
|
|
11
|
+
function wrapText(text, width) {
|
|
12
|
+
const w = Math.max(8, width);
|
|
13
|
+
const out = [];
|
|
14
|
+
for (const para of text.split('\n')) {
|
|
15
|
+
let cur = '';
|
|
16
|
+
for (const word of para.split(' ')) {
|
|
17
|
+
let rest = word;
|
|
18
|
+
while (stringWidth(rest) > w) {
|
|
19
|
+
if (cur) {
|
|
20
|
+
out.push(cur);
|
|
21
|
+
cur = '';
|
|
22
|
+
}
|
|
23
|
+
let head = '';
|
|
24
|
+
for (const ch of Array.from(rest)) {
|
|
25
|
+
if (stringWidth(head + ch) > w)
|
|
26
|
+
break;
|
|
27
|
+
head += ch;
|
|
28
|
+
}
|
|
29
|
+
if (head === '')
|
|
30
|
+
head = Array.from(rest)[0];
|
|
31
|
+
out.push(head);
|
|
32
|
+
rest = rest.slice(head.length);
|
|
33
|
+
}
|
|
34
|
+
if (cur === '') {
|
|
35
|
+
cur = rest;
|
|
36
|
+
}
|
|
37
|
+
else if (stringWidth(cur) + 1 + stringWidth(rest) <= w) {
|
|
38
|
+
cur += ` ${rest}`;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
out.push(cur);
|
|
42
|
+
cur = rest;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
out.push(cur);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
const FOCUS = ['agents', 'conversation', 'inspector', 'activity'];
|
|
50
|
+
const Line = ({ plain, color, bold, dim, children }) => plain ? _jsx(Text, { wrap: "truncate-end", children: children }) : _jsx(Text, { wrap: "truncate-end", ...color ? { color } : {}, ...bold ? { bold: true } : {}, ...dim ? { dimColor: true } : {}, children: children });
|
|
51
|
+
export function MissionScreen({ view, width, options }) {
|
|
52
|
+
const { stdout } = useStdout();
|
|
53
|
+
const rows = stdout.rows;
|
|
54
|
+
const profile = resolveTerminalProfile(process.env);
|
|
55
|
+
const ascii = (options?.charset ?? profile.charset) === 'ascii';
|
|
56
|
+
const plain = !(options?.color ?? profile.color);
|
|
57
|
+
const mode = options?.mode ?? 'REPLAY';
|
|
58
|
+
const [nav, setNav] = useState(initialMissionNav);
|
|
59
|
+
const [typing, setTyping] = useState(false);
|
|
60
|
+
const typingRef = useRef(false);
|
|
61
|
+
const setTypingNow = (on) => { typingRef.current = on; setTyping(on); };
|
|
62
|
+
const [scroll, setScroll] = useState({ k: '', n: 0 });
|
|
63
|
+
const dispatch = (a) => setNav(s => reduceMissionNav(s, a, view));
|
|
64
|
+
const capture = options?.onInputCapture;
|
|
65
|
+
useEffect(() => () => { capture?.(false); }, [capture]);
|
|
66
|
+
const SEP = ascii ? ' | ' : ' · ', ARROW = ascii ? '->' : '→', UPM = ascii ? '^' : '↑', DOWNM = ascii ? 'v' : '↓', BRANCH = ascii ? '+- ' : '└ ';
|
|
67
|
+
const narrow = width < 90;
|
|
68
|
+
const label = (id) => id === null ? 'unknown' : redactSecretText(bindingLabel(id));
|
|
69
|
+
const aRows = agentRows(view, nav.layout);
|
|
70
|
+
const effSel = nav.selection ?? (aRows[0] ? { kind: 'agent', id: aRows[0].agent.id } : null);
|
|
71
|
+
const conv = filteredConversation(view, nav.filter);
|
|
72
|
+
const w = missionWindow(view, nav, undefined, conv);
|
|
73
|
+
const acts = activityEntries(view);
|
|
74
|
+
const query = nav.query;
|
|
75
|
+
const hits = query !== null && query !== '' ? (() => { const c = searchMission(conv, query), a = searchMission(acts, query); return { ids: [...c.ids, ...a.ids], scanned: c.scanned + a.scanned }; })() : null;
|
|
76
|
+
const hitSet = hits ? new Set(hits.ids) : null;
|
|
77
|
+
const convList = hitSet ? w.entries.filter(e => hitSet.has(e.id)) : w.entries;
|
|
78
|
+
const actList = hitSet ? acts.filter(e => hitSet.has(e.id)) : acts;
|
|
79
|
+
const prov = [...new Set(view.entries.map(e => e.provenance))];
|
|
80
|
+
const goal = view.entries.map(e => e.kind === 'system' && e.content.status === 'available' ? /^Task created: (.*)$/s.exec(e.content.value)?.[1] : undefined).find(g => g !== undefined);
|
|
81
|
+
const cursors = [...view.cursors];
|
|
82
|
+
const cursorText = cursors.length === 0 ? 'none' : cursors.length === 1 ? `#${cursors[0][1]}` : cursors.map(([s, n]) => `${s.slice(-8)} #${n}`).join(', ');
|
|
83
|
+
const primary = view.committee.primary.status === 'available' ? view.committee.primary.value : 'unknown';
|
|
84
|
+
const cfgLine = options?.configSummary;
|
|
85
|
+
const stripLines = 2 + (query !== null ? 1 : 0) + (cfgLine ? 1 : 0);
|
|
86
|
+
// ---- selection helpers
|
|
87
|
+
const entryById = (id) => view.entries.find(e => e.id === id);
|
|
88
|
+
const selEntry = effSel?.kind === 'entry' ? entryById(effSel.id) : undefined;
|
|
89
|
+
const selAgent = effSel?.kind === 'agent' ? view.agents.find(a => a.id === effSel.id) : undefined;
|
|
90
|
+
const scrollKey = `${effSel?.kind}:${effSel?.id}:${nav.tab}`;
|
|
91
|
+
const scrollAt = scroll.k === scrollKey ? scroll.n : 0;
|
|
92
|
+
// The Actions panel owns its keys only while it is the focused Inspector tab and no prompt is capturing input.
|
|
93
|
+
const actionsActive = nav.focus === 'inspector' && nav.tab === 'actions' && !typing;
|
|
94
|
+
// ---- keys
|
|
95
|
+
useInput((input, key) => {
|
|
96
|
+
if (typingRef.current) {
|
|
97
|
+
if (key.return) {
|
|
98
|
+
setTypingNow(false);
|
|
99
|
+
capture?.(false);
|
|
100
|
+
}
|
|
101
|
+
else if (key.escape) {
|
|
102
|
+
dispatch({ type: 'search-clear' });
|
|
103
|
+
setTypingNow(false);
|
|
104
|
+
capture?.(false);
|
|
105
|
+
}
|
|
106
|
+
else if (key.backspace || key.delete)
|
|
107
|
+
dispatch({ type: 'search-back' });
|
|
108
|
+
else if (!key.ctrl && !key.meta && !key.tab) {
|
|
109
|
+
const text = input.replace(/[\u0000-\u001f\u007f]/g, '');
|
|
110
|
+
if (text !== '')
|
|
111
|
+
dispatch({ type: 'search-input', text });
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (key.ctrl || key.meta)
|
|
116
|
+
return;
|
|
117
|
+
if (input.length > 1 && input[0] === '/' && !key.escape) {
|
|
118
|
+
capture?.(true);
|
|
119
|
+
dispatch({ type: 'search-open' });
|
|
120
|
+
setTypingNow(true);
|
|
121
|
+
const rest = input.slice(1).replace(/[\u0000-\u001f\u007f]/g, '');
|
|
122
|
+
if (rest !== '')
|
|
123
|
+
dispatch({ type: 'search-input', text: rest });
|
|
124
|
+
return;
|
|
125
|
+
} // chunked input: `/` and the next keys arrived in one write
|
|
126
|
+
if (key.tab)
|
|
127
|
+
dispatch({ type: 'focus' });
|
|
128
|
+
else if (key.upArrow || key.downArrow || key.pageUp || key.pageDown) {
|
|
129
|
+
const dir = key.upArrow || key.pageUp ? -1 : 1;
|
|
130
|
+
const count = key.pageUp || key.pageDown ? 10 : 1;
|
|
131
|
+
if (nav.focus === 'inspector')
|
|
132
|
+
setScroll({ k: scrollKey, n: Math.max(0, scrollAt + dir * count) });
|
|
133
|
+
else
|
|
134
|
+
dispatch({ type: 'move', dir, count });
|
|
135
|
+
}
|
|
136
|
+
else if (key.return) {
|
|
137
|
+
if (!actionsActive)
|
|
138
|
+
dispatch({ type: 'open', narrow });
|
|
139
|
+
} // the active Actions panel owns Enter (one Enter = one effect)
|
|
140
|
+
else if (input === 't')
|
|
141
|
+
dispatch({ type: 'layout' });
|
|
142
|
+
else if (input === 'f')
|
|
143
|
+
dispatch({ type: 'kind' });
|
|
144
|
+
else if (input === 'a')
|
|
145
|
+
dispatch({ type: 'agent-filter' });
|
|
146
|
+
else if (input === 'h')
|
|
147
|
+
dispatch({ type: 'thread' });
|
|
148
|
+
else if (input === 'l')
|
|
149
|
+
dispatch({ type: 'follow' });
|
|
150
|
+
else if (input === '/') {
|
|
151
|
+
capture?.(true);
|
|
152
|
+
dispatch({ type: 'search-open' });
|
|
153
|
+
setTypingNow(true);
|
|
154
|
+
}
|
|
155
|
+
else if (input === '1' || input === '2' || input === '3')
|
|
156
|
+
dispatch({ type: 'tab', tab: ['detail', 'plan', 'actions'][Number(input) - 1] });
|
|
157
|
+
}, { isActive: true });
|
|
158
|
+
// ---- row builders
|
|
159
|
+
const entryText = (e) => e.kind === 'message' ? `#${e.seq} [MESSAGE] ${label(e.sender)} ${ARROW} ${e.recipients.map(label).join(', ')}${e.facets.length ? `${SEP}${e.facets.map(f => f.facet).join(', ')}` : ''}${e.content.status === 'available' ? `${SEP}${clean(e.content.value)}` : ''}` : `#${e.seq} [${e.kind.toUpperCase()}] ${e.content.status === 'available' ? clean(e.content.value) : `content unavailable (${clean(e.content.reason)})`}`;
|
|
160
|
+
const kindColor = (e) => e.kind === 'message' ? 'cyan' : e.kind === 'tool' ? 'yellow' : 'gray';
|
|
161
|
+
const isSel = (e) => effSel?.kind === 'entry' && effSel.id === e.id;
|
|
162
|
+
const heading = (name, f, extra = '') => _jsxs(Line, { plain: plain, bold: nav.focus === f, children: [nav.focus === f ? '> ' : ' ', name, extra] }, `h-${name}`);
|
|
163
|
+
const convPane = (budget) => {
|
|
164
|
+
if (convList.length === 0)
|
|
165
|
+
return [_jsx(Line, { plain: plain, dim: true, children: w.total === 0 && !hitSet ? 'No messages observed' : hitSet ? 'No matching messages' : 'No messages match the filter' }, "e")];
|
|
166
|
+
const cap0 = budget;
|
|
167
|
+
const cap = convList.length > cap0 || w.above > 0 ? Math.max(1, cap0 - 1) : cap0;
|
|
168
|
+
const vis = convList.slice(-cap);
|
|
169
|
+
const hidden = w.above + convList.length - vis.length;
|
|
170
|
+
return [...(hidden > 0 ? [_jsxs(Line, { plain: plain, dim: true, children: [UPM, " ", hidden, " more"] }, "more")] : []), ...vis.map(e => _jsxs(Line, { plain: plain, color: kindColor(e), bold: isSel(e), children: [isSel(e) ? '> ' : ' ', entryText(e)] }, e.id))];
|
|
171
|
+
};
|
|
172
|
+
// State is always text plus a glyph (never colour alone); ASCII profile swaps the glyph for a bracketed word.
|
|
173
|
+
const reasonText = (i) => {
|
|
174
|
+
const code = i.reasonCode ?? (i.outcome === null ? 'running' : i.outcome);
|
|
175
|
+
const OK = ['acceptance-verified', 'goal-met'], SKIP = ['dependency-blocked', 'cancelled'];
|
|
176
|
+
const kind = i.outcome === null && i.reasonCode === null ? 'run' : i.reasonCode !== null && OK.includes(i.reasonCode) ? 'ok' : i.reasonCode !== null && SKIP.includes(i.reasonCode) ? 'skip' : i.outcome === 'success' ? 'ok' : i.outcome === 'unknown' ? 'unk' : 'fail';
|
|
177
|
+
const g = ascii ? { run: '[..]', ok: '[ok]', skip: '[-]', unk: '[?]', fail: '[x]' }[kind] : { run: '⧖', ok: '✓', skip: '⊘', unk: '?', fail: '✗' }[kind];
|
|
178
|
+
return `${g} ${code}`;
|
|
179
|
+
};
|
|
180
|
+
const agentPane = (budget) => {
|
|
181
|
+
if (aRows.length === 0)
|
|
182
|
+
return [_jsx(Line, { plain: plain, dim: true, children: "No agents observed" }, "e")];
|
|
183
|
+
const lines = [];
|
|
184
|
+
let session = '';
|
|
185
|
+
let run = '';
|
|
186
|
+
for (const { agent, depth } of aRows) {
|
|
187
|
+
if (depth === 0 && agent.sessionId !== session) { // nested children inherit the visible header of their root, so the parent's session line is never repeated after them
|
|
188
|
+
session = agent.sessionId;
|
|
189
|
+
const info = view.sessions?.get(session);
|
|
190
|
+
if (info && info.runId !== null && info.runId !== run) {
|
|
191
|
+
run = info.runId;
|
|
192
|
+
const n = [...view.sessions.values()].filter(x => x.runId === run).length;
|
|
193
|
+
lines.push({ key: `s-run-${run}-${lines.length}`, text: `run ${run.replace(/^run-/, '').slice(0, 8)}${SEP}${n} ${n === 1 ? 'session' : 'sessions'}`, sel: false });
|
|
194
|
+
}
|
|
195
|
+
lines.push({ key: `s-${session}-${lines.length}`, text: `session ${session.slice(-8)}${info && info.runId !== null ? ` ${reasonText(info)}` : ''}`, sel: false });
|
|
196
|
+
}
|
|
197
|
+
lines.push({ key: agent.id, text: `${depth > 0 ? `${' '.repeat(depth - 1)}${BRANCH}` : ''}${label(agent.id)} [${agent.kind.toUpperCase()}]`, sel: effSel?.kind === 'agent' && effSel.id === agent.id });
|
|
198
|
+
}
|
|
199
|
+
const idx = Math.max(0, lines.findIndex(l => l.sel));
|
|
200
|
+
const start = clamp(idx - Math.floor(budget / 2), 0, Math.max(0, lines.length - budget));
|
|
201
|
+
return lines.slice(start, start + budget).map(l => _jsxs(Line, { plain: plain, bold: l.sel, dim: l.key.startsWith('s-'), children: [l.sel ? '> ' : ' ', l.text] }, l.key));
|
|
202
|
+
};
|
|
203
|
+
const detailLines = (textWidth) => {
|
|
204
|
+
if (selAgent)
|
|
205
|
+
return agentDetail(selAgent, textWidth);
|
|
206
|
+
if (selEntry)
|
|
207
|
+
return entryDetail(selEntry, textWidth);
|
|
208
|
+
return ['Nothing selected'];
|
|
209
|
+
};
|
|
210
|
+
const agentDetail = (a, tw) => [
|
|
211
|
+
`Agent ${label(a.id)}`, `kind ${a.kind}`, `session ${a.sessionId.slice(-8)}`, ...(a.parentId ? [`parent ${label(a.parentId)}`] : []),
|
|
212
|
+
...wrapText(a.identity.status === 'available' ? `identity ${clean(a.identity.value)} (source ${clean(a.identity.source)})` : `identity unavailable (${clean(a.identity.reason)})`, tw),
|
|
213
|
+
...(a.conversation.status === 'available' ? ['transcript', ...a.conversation.value.flatMap(l => wrapText(redactSecretText(l), tw))] : wrapText(`transcript unavailable: ${clean(a.conversation.reason)}`, tw))
|
|
214
|
+
];
|
|
215
|
+
const entryDetail = (e, tw) => [
|
|
216
|
+
`Entry #${e.seq} [${e.kind.toUpperCase()}]`,
|
|
217
|
+
...(e.kind === 'message' ? wrapText(`from ${label(e.sender)} ${ARROW} ${e.recipients.map(label).join(', ')}`, tw) : []),
|
|
218
|
+
`provenance ${e.provenance}`, `session ${e.sessionId.slice(-8)}`, `thread ${e.threadId.slice(-8)}`, `parent ${e.parent.state}`,
|
|
219
|
+
...e.facets.flatMap(f => wrapText(`facet ${f.facet}${f.reason ? ` (${redactSecretText(f.reason)})` : ''}${f.source ? ` source ${clean(f.source)}` : ''}`, tw)),
|
|
220
|
+
...(e.content.status === 'available' ? ['content', ...wrapText(redactSecretText(e.content.value), tw)] : wrapText(e.content.ref ? `content unavailable (v1 envelope carries promptRef only)${SEP}ref ${clean(e.content.ref)}` : `content unavailable (${clean(e.content.reason)})`, tw))
|
|
221
|
+
];
|
|
222
|
+
const tabBar = `${nav.tab === 'detail' ? '[1 Detail]' : '1 Detail'} ${nav.tab === 'plan' ? '[2 Plan]' : '2 Plan'} ${nav.tab === 'actions' ? '[3 Actions]' : '3 Actions'}`;
|
|
223
|
+
const inspectorPane = (budget, textWidth) => {
|
|
224
|
+
const bar = _jsx(Line, { plain: plain, bold: true, children: tabBar }, "tabs");
|
|
225
|
+
const room = Math.max(1, budget - 1);
|
|
226
|
+
if (nav.tab !== 'detail') {
|
|
227
|
+
const slot = options?.panels?.[nav.tab];
|
|
228
|
+
return [bar, slot ? _jsx(Box, { flexDirection: "column", maxHeight: room, overflow: "hidden", children: _jsx(InspectorBudgetContext.Provider, { value: room, children: slot(effSel, { active: actionsActive, mode, view }) }) }, "slot") : _jsxs(Line, { plain: plain, dim: true, children: [nav.tab === 'plan' ? 'Plan' : 'Actions', " panel not provided"] }, "slot")];
|
|
229
|
+
}
|
|
230
|
+
const all = detailLines(textWidth);
|
|
231
|
+
const top = clamp(scrollAt, 0, Math.max(0, all.length - room));
|
|
232
|
+
const above = top > 0, below = top + room < all.length;
|
|
233
|
+
const body = all.slice(top + (above ? 1 : 0), top + room - (below ? 1 : 0));
|
|
234
|
+
return [bar, ...(above ? [_jsxs(Line, { plain: plain, dim: true, children: [UPM, " ", top, " above"] }, "up")] : []), ...body.map((l, i) => _jsx(Line, { plain: plain, children: l }, `d${i}`)), ...(below ? [_jsxs(Line, { plain: plain, dim: true, children: [DOWNM, " ", all.length - top - room + (above ? 1 : 0), " below"] }, "dn")] : [])];
|
|
235
|
+
};
|
|
236
|
+
const actRow = (e) => _jsxs(Line, { plain: plain, color: kindColor(e), bold: isSel(e), children: [isSel(e) ? '> ' : ' ', entryText(e)] }, e.id);
|
|
237
|
+
const actEmpty = _jsx(Line, { plain: plain, dim: true, children: hitSet ? 'No matching activity' : 'No activity observed' }, "e");
|
|
238
|
+
const searchText = query === null ? '' : `search "${query}"${hits ? `${SEP}${hits.ids.length} ${hits.ids.length === 1 ? 'match' : 'matches'}${SEP}searched ${hits.scanned} of ${conv.length + acts.length} retained` : typing ? `${SEP}type to search, Enter to apply` : ''}`;
|
|
239
|
+
const strip = _jsxs(_Fragment, { children: [_jsxs(Line, { plain: plain, bold: true, children: [mode, SEP, prov.length === 0 ? 'UNKNOWN' : prov.length === 1 ? prov[0] : 'MIXED', SEP, "Primary: ", primary, SEP, "cursor ", cursorText, SEP, "goal ", goal === undefined ? 'unavailable' : clean(goal), SEP, "project unavailable"] }), _jsxs(Line, { plain: plain, children: [nav.following ? 'following' : 'scrolled back', SEP, w.unseen, " new", SEP, "showing ", w.entries.length, " of ", w.total, SEP, "filter ", nav.filter.kind, nav.filter.threadId ? `${SEP}thread ${nav.filter.threadId.slice(-8)}` : '', nav.filter.agentId ? `${SEP}agent ${label(nav.filter.agentId)}` : ''] }), cfgLine ? _jsx(Line, { plain: plain, dim: true, children: clean(cfgLine) }) : null, query !== null ? _jsx(Line, { plain: plain, children: searchText }) : null] });
|
|
240
|
+
if (narrow) {
|
|
241
|
+
const budget = missionRowBudget(rows, 1 + stripLines + 1 + (view.diagnostics.length > 0 ? 1 : 0)) ?? 100;
|
|
242
|
+
const full = FOCUS.map(f => `${nav.focus === f ? '[' : ''}${f[0].toUpperCase()}${f.slice(1)}${nav.focus === f ? ']' : ''}`).join(' ');
|
|
243
|
+
const short = `${nav.focus === 'agents' ? '[Agents]' : 'Agents'} ${nav.focus === 'conversation' ? '[Convo]' : 'Convo'} ${nav.focus === 'inspector' ? '[Inspect]' : 'Inspect'} ${nav.focus === 'activity' ? '[Activity]' : 'Activity'}`;
|
|
244
|
+
const bar = stringWidth(full) <= width ? full : short;
|
|
245
|
+
const pane = nav.focus === 'agents' ? agentPane(budget) : nav.focus === 'conversation' ? convPane(budget) : nav.focus === 'inspector' ? inspectorPane(budget, width - 1) : (() => {
|
|
246
|
+
if (actList.length === 0)
|
|
247
|
+
return [actEmpty];
|
|
248
|
+
const cap = Math.max(1, Math.floor(budget / 2));
|
|
249
|
+
const vis = actList.slice(-cap);
|
|
250
|
+
return [...(vis.length < actList.length ? [_jsxs(Line, { plain: plain, dim: true, children: [UPM, " ", actList.length - vis.length, " more"] }, "more")] : []), ...vis.flatMap(e => wrapText(`${isSel(e) ? '> ' : ' '}${entryText(e)}`, width - 1).slice(0, 2).map((l, i) => _jsx(Line, { plain: plain, color: kindColor(e), bold: isSel(e), children: l }, `${e.id}-${i}`)))];
|
|
251
|
+
})();
|
|
252
|
+
return _jsxs(Box, { flexDirection: "column", width: width, children: [strip, _jsx(Line, { plain: plain, bold: true, children: bar }), pane, view.diagnostics.slice(0, 1).map(d => _jsxs(Line, { plain: plain, dim: true, children: ["[DIAGNOSTIC] ", clean(d)] }, d))] });
|
|
253
|
+
}
|
|
254
|
+
const actCap = rows === undefined ? 5 : 3;
|
|
255
|
+
const actVis = actList.slice(-actCap);
|
|
256
|
+
const actBlock = 1 + Math.max(1, actVis.length);
|
|
257
|
+
const diagLines = view.diagnostics.length > 0 ? 1 : 0;
|
|
258
|
+
const body = missionRowBudget(rows, 1 + stripLines + actBlock + diagLines) ?? 30;
|
|
259
|
+
const aw = Math.floor(width * 0.25), iw = nav.focus === 'inspector' ? Math.floor(width * 0.5) : Math.floor(width * 0.3), cw = width - aw - iw;
|
|
260
|
+
const col = (wd, children) => _jsx(Box, { flexDirection: "column", width: wd, paddingRight: 1, children: children });
|
|
261
|
+
return _jsxs(Box, { flexDirection: "column", width: width, children: [strip, _jsxs(Box, { flexDirection: "row", children: [col(aw, _jsxs(_Fragment, { children: [heading('Agents', 'agents', ` (${nav.layout})`), agentPane(Math.max(1, body - 1))] })), col(cw, _jsxs(_Fragment, { children: [heading('Conversation', 'conversation'), convPane(Math.max(1, body - 1))] })), col(iw, _jsxs(_Fragment, { children: [heading('Inspector', 'inspector'), inspectorPane(Math.max(1, body - 1), iw - 2)] }))] }), heading('Activity', 'activity', actList.length > actVis.length ? ` (showing ${actVis.length} of ${actList.length})` : ''), actVis.length === 0 ? actEmpty : actVis.map(actRow), view.diagnostics.slice(0, 1).map(d => _jsxs(Line, { plain: plain, dim: true, children: ["[DIAGNOSTIC] ", clean(d)] }, d))] });
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=mission-screens.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EventProvenance } from '../core/events.js';
|
|
2
|
+
/**
|
|
3
|
+
* Honest provenance label for a recorded event or session. Derived only from the recorded provenance, never assumed:
|
|
4
|
+
* [SIMULATED] provenance.source === 'simulated'
|
|
5
|
+
* [LOCAL-ENDPOINT] live provenance whose `api-run:<session>@<baseUrl>` ref names a loopback host (localhost, 127.0.0.0/8, ::1);
|
|
6
|
+
* a mock or local server, not a remote provider
|
|
7
|
+
* [API] live provenance whose ref names a non-loopback baseUrl
|
|
8
|
+
* [LIVE] live provenance with no recognisable baseUrl in its ref (kept only when nothing finer can be proven)
|
|
9
|
+
*/
|
|
10
|
+
export type ProvenanceLabel = 'SIMULATED' | 'LOCAL-ENDPOINT' | 'API' | 'LIVE';
|
|
11
|
+
export declare function provenanceLabel(provenance: EventProvenance): ProvenanceLabel;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const LOOPBACK = /^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$/i;
|
|
2
|
+
const PREFIX = /^api-run:[^@]*@/;
|
|
3
|
+
export function provenanceLabel(provenance) {
|
|
4
|
+
if (provenance.source === 'simulated')
|
|
5
|
+
return 'SIMULATED';
|
|
6
|
+
const m = PREFIX.exec(provenance.ref); // split at the FIRST '@' after the session prefix, so userinfo in the URL cannot shift the host
|
|
7
|
+
if (m === null)
|
|
8
|
+
return 'LIVE';
|
|
9
|
+
try {
|
|
10
|
+
return LOOPBACK.test(new URL(provenance.ref.slice(m[0].length)).hostname.replace(/\.$/, '')) ? 'LOCAL-ENDPOINT' : 'API';
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return 'LIVE';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=provenance-label.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Envelope } from '../core/events.js';
|
|
2
|
+
export declare function SessionTaskList({ events }: {
|
|
3
|
+
readonly events: readonly Envelope[];
|
|
4
|
+
}): import("react").JSX.Element;
|
|
5
|
+
export declare function EventFeed({ events }: {
|
|
6
|
+
readonly events: readonly Envelope[];
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
export declare function PhaseState({ events }: {
|
|
9
|
+
readonly events: readonly Envelope[];
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import { provenanceLabel } from './provenance-label.js';
|
|
4
|
+
import { outcomeLines, summarizeSessionOutcome } from './session-outcome.js';
|
|
5
|
+
const SECRET_TEXT = /(?:bearer\s+[\w.-]+|(?:api[_-]?key|token|password|secret)\s*[:=]\s*\S+)/gi;
|
|
6
|
+
function safeText(value) { return value.replace(SECRET_TEXT, '[REDACTED]'); }
|
|
7
|
+
function describe(event) {
|
|
8
|
+
const { payload } = event;
|
|
9
|
+
switch (payload.type) {
|
|
10
|
+
case 'TaskCreated': return `Task created: ${safeText(payload.title)}`;
|
|
11
|
+
case 'AdvisorDispatched': return `Advisor dispatched (${safeText(payload.adapter)})`;
|
|
12
|
+
case 'AdvisorAcked': return `Advisor acknowledged (${safeText(payload.adapter)})`;
|
|
13
|
+
case 'AdvisorCompleted': return `Advisor completed: ${safeText(payload.resultRef)}`;
|
|
14
|
+
case 'AdvisorUnknownOutcome': return `Advisor outcome unknown (${payload.reason})`;
|
|
15
|
+
case 'TaskCompleted': return `Task completed: ${payload.outcome}`;
|
|
16
|
+
case 'ReviewerSelected': return `Reviewer selected: ${safeText(payload.reviewerId)} (evidence revision ${payload.evidenceRevision})`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function SessionTaskList({ events }) {
|
|
20
|
+
const latestTask = [...events].reverse().find(event => event.payload.type === 'TaskCreated');
|
|
21
|
+
return _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Session / task" }), _jsx(Text, { children: latestTask ? describe(latestTask) : 'No recorded task' })] });
|
|
22
|
+
}
|
|
23
|
+
export function EventFeed({ events }) {
|
|
24
|
+
if (events.length === 0)
|
|
25
|
+
return _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Recorded events" }), _jsx(Text, { children: "No recorded events" })] });
|
|
26
|
+
return _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Recorded events" }), events.slice(-12).map(event => _jsxs(Text, { children: ["[", provenanceLabel(event.provenance), "] #", event.sessionSequence, " ", describe(event)] }, event.eventId))] });
|
|
27
|
+
}
|
|
28
|
+
export function PhaseState({ events }) {
|
|
29
|
+
const last = events.at(-1);
|
|
30
|
+
const state = last?.payload.type === 'TaskCompleted' ? `completed (${last.payload.outcome})` : last?.payload.type === 'AdvisorUnknownOutcome' ? 'awaiting reconciliation' : last ? 'active' : 'not started';
|
|
31
|
+
const summary = last ? summarizeSessionOutcome(events.filter(e => e.sessionId === last.sessionId)) : null;
|
|
32
|
+
return _jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { bold: true, children: "Phase / awaiting: " }), _jsx(Text, { children: state })] }), summary ? outcomeLines(summary).map(line => _jsxs(Text, { wrap: "wrap", children: [" ", line] }, line)) : null] });
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=screens.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Envelope } from '../core/events.js';
|
|
2
|
+
/** Three separate facts about a closed session, derived only from its recorded events (never inferred beyond them). */
|
|
3
|
+
export interface SessionOutcomeSummary {
|
|
4
|
+
readonly outcome: 'success' | 'failed' | 'unknown';
|
|
5
|
+
readonly delivery: 'answered' | 'sent' | 'unknown' | 'not run';
|
|
6
|
+
readonly worker: string;
|
|
7
|
+
readonly acceptance: string;
|
|
8
|
+
readonly failure: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function workerAuthLabel(note: string): string | null;
|
|
11
|
+
/** `events` are one session's events in order. Returns null while the session has no TaskCompleted. */
|
|
12
|
+
export declare function summarizeSessionOutcome(events: readonly Envelope[]): SessionOutcomeSummary | null;
|
|
13
|
+
/** Plain-text lines (labels, never colour alone). */
|
|
14
|
+
export declare function outcomeLines(s: SessionOutcomeSummary): string[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { redactSecretText } from '../security/redact.js';
|
|
2
|
+
/** Auth is classified only from the worker's own text; the env-boundary / worker-env hints are product text and never evidence. */
|
|
3
|
+
const BOUNDARY = /env boundary|worker env:/i;
|
|
4
|
+
const AUTH_PHRASE = /Failed to authenticate|Invalid API key|Please run \/login|OAuth token (?:has )?expired|"type"\s*:\s*"authentication_error"|\bauthentication_error\s*:|\b401 Unauthorized|\b403 Forbidden/i;
|
|
5
|
+
/** A status counts only in an API/HTTP context: "API Error: 401", "HTTP/1.1 401", "status code 403", "status: 403", "401 Unauthorized". Bare "status 401" in prose does not. */
|
|
6
|
+
const AUTH_STATUS = /\bAPI Error:?\s*(401|403)\b|\bHTTP\/\d(?:\.\d)?\s+(401|403)\b|\bstatus(?:\s+code)?:\s*(401|403)\b|\bstatus code\s+(401|403)\b|\b(401)\s+Unauthorized|\b(403)\s+Forbidden/i;
|
|
7
|
+
export function workerAuthLabel(note) {
|
|
8
|
+
const cut = BOUNDARY.exec(note), text = cut ? note.slice(0, cut.index) : note;
|
|
9
|
+
const code = AUTH_STATUS.exec(text)?.slice(1).find(g => g !== undefined);
|
|
10
|
+
if (code !== undefined)
|
|
11
|
+
return `worker auth failed (${code})`;
|
|
12
|
+
return AUTH_PHRASE.test(text) ? 'worker auth failed' : null;
|
|
13
|
+
}
|
|
14
|
+
const PLAN_CODES = ['goal-met', 'verdict-not-accept', 'acceptance-unmet', 'plan-invalid', 'cancelled', 'advisor-rejected', 'advisor-unknown'];
|
|
15
|
+
/** Plan sessions that got as far as running task sessions (their worker/acceptance facts live in those sessions). */
|
|
16
|
+
const PLAN_RAN = ['goal-met', 'verdict-not-accept', 'acceptance-unmet'];
|
|
17
|
+
function firstLine(note) { const line = redactSecretText(note).split(/\r?\n/)[0]?.trim() ?? ''; return line.length > 160 ? `${line.slice(0, 157)}...` : line; }
|
|
18
|
+
/** `events` are one session's events in order. Returns null while the session has no TaskCompleted. */
|
|
19
|
+
export function summarizeSessionOutcome(events) {
|
|
20
|
+
const done = events.find(e => e.payload.type === 'TaskCompleted');
|
|
21
|
+
if (done === undefined || done.payload.type !== 'TaskCompleted')
|
|
22
|
+
return null;
|
|
23
|
+
const outcome = done.payload.outcome;
|
|
24
|
+
const by = (role) => events.filter(e => e.actor.role === role && e.payload.type.startsWith('Advisor'));
|
|
25
|
+
const adv = by('advisor'), wrk = by('worker');
|
|
26
|
+
const has = (list, type) => list.some(e => e.payload.type === type);
|
|
27
|
+
const lastTurn = [...adv].reverse().find(e => e.payload.type !== 'AdvisorAcked')?.payload.type;
|
|
28
|
+
const delivery = lastTurn === 'AdvisorCompleted' ? 'answered' : lastTurn === 'AdvisorUnknownOutcome' ? 'unknown' : lastTurn === 'AdvisorDispatched' ? 'sent' : 'not run';
|
|
29
|
+
const planSession = wrk.length === 0 && done.reasonCode !== null && PLAN_CODES.includes(done.reasonCode);
|
|
30
|
+
const wFail = wrk.find(e => e.payload.type === 'AdvisorUnknownOutcome');
|
|
31
|
+
const wNote = wFail?.payload.type === 'AdvisorUnknownOutcome' ? wFail.payload.note : '';
|
|
32
|
+
let worker = planSession && PLAN_RAN.includes(done.reasonCode ?? '') ? 'see task sessions' : 'not run';
|
|
33
|
+
if (has(wrk, 'AdvisorCompleted'))
|
|
34
|
+
worker = 'completed';
|
|
35
|
+
else if (wFail?.payload.type === 'AdvisorUnknownOutcome') {
|
|
36
|
+
const code = /exited with code (\d+)/.exec(wNote)?.[1];
|
|
37
|
+
worker = code !== undefined ? `exit ${code}` : wFail.payload.reason === 'timeout' ? 'timeout' : 'unknown';
|
|
38
|
+
}
|
|
39
|
+
else if (has(wrk, 'AdvisorDispatched'))
|
|
40
|
+
worker = 'unknown (no result recorded)';
|
|
41
|
+
const verified = outcome === 'success' && (done.status === 'verified' || done.reasonCode === 'acceptance-verified');
|
|
42
|
+
const acceptance = verified ? 'verified'
|
|
43
|
+
: planSession && PLAN_RAN.includes(done.reasonCode ?? '') ? 'see task sessions'
|
|
44
|
+
: outcome === 'success' && done.reasonCode === null ? 'accepted by advisor (no checks run)'
|
|
45
|
+
: worker === 'completed' && done.reasonCode !== 'dependency-blocked' ? 'not verified' : 'not reached';
|
|
46
|
+
const unknownEv = [...events].reverse().find(e => e.payload.type === 'AdvisorUnknownOutcome');
|
|
47
|
+
let failure = null;
|
|
48
|
+
if (unknownEv?.payload.type === 'AdvisorUnknownOutcome') {
|
|
49
|
+
failure = (unknownEv.actor.role === 'worker' ? workerAuthLabel(unknownEv.payload.note) : null) ?? firstLine(unknownEv.payload.note);
|
|
50
|
+
}
|
|
51
|
+
return { outcome, delivery, worker, acceptance, failure };
|
|
52
|
+
}
|
|
53
|
+
/** Plain-text lines (labels, never colour alone). */
|
|
54
|
+
export function outcomeLines(s) {
|
|
55
|
+
return [`outcome: ${s.outcome}`, `advisor delivery: ${s.delivery}`, `worker execution: ${s.worker}`, `acceptance: ${s.acceptance}`, ...(s.failure !== null ? [`failure: ${s.failure}`] : [])];
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=session-outcome.js.map
|