@lmzhen/dsh-evolution-merge 0.45.0 → 0.47.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.
@@ -1,77 +0,0 @@
1
- import { countsOf, toRunView } from "./facts.js";
2
- const queueOf = (row) => row.state === 'approved' ? 'fuse' : row.queue;
3
- const expiredOf = (row) => row.expired !== undefined;
4
- /** Host-owned row actions; client only renders/copies them. */
5
- export function actionRefs(row) {
6
- const base = '/evolution merge ';
7
- const disabled = row.expired === undefined ? undefined : 'expired';
8
- const action = (id, confirm = false, enabled = true) => ({ id, command: base + id + ' ' + row.id, confirm, enabled, ...(enabled ? {} : { disabledReason: disabled ?? 'invalid' }) });
9
- if (row.state === 'pending' && row.expired !== undefined)
10
- return [{ id: 'discard', command: base + 'discard ' + row.id, confirm: true, enabled: true }, { id: 'pair', command: base + 'pair ' + row.a + ' ' + row.b, confirm: true, enabled: true }];
11
- if (row.state === 'pending')
12
- return [action('approve'), action('reject', true), action('discard', true)];
13
- if (row.state === 'approved' || row.state === 'fuse') {
14
- if (row.failure !== undefined && row.failure.retryable === false)
15
- return [{ id: 'pair', command: base + 'pair ' + row.a + ' ' + row.b, confirm: true, enabled: true }, action('discard', true)];
16
- return [{ id: 'retry-resume', command: base + 'resume --retry ' + row.id, confirm: true, enabled: true }, action('discard', true), action('status')];
17
- }
18
- if (row.state === 'skipped')
19
- return [action('restore', true)];
20
- if (row.state === 'verify')
21
- return [{ id: 'retry-candidates', command: base + 'candidates --retry ' + row.id, confirm: false, enabled: true }];
22
- return [action('pair')];
23
- }
24
- export function toRowFact(row, actions = actionRefs(row)) {
25
- return {
26
- id: row.id,
27
- state: row.state,
28
- queue: queueOf(row),
29
- ...(row.state === 'verify' ? { verifySubState: 'queued' } : {}),
30
- a: row.a,
31
- b: row.b,
32
- ...(row.target === undefined ? {} : { target: { requested: row.target.requested, ...(row.target.actual === undefined ? {} : { actual: row.target.actual }), ...(row.target.created === undefined ? {} : { created: row.target.created }) } }),
33
- ...(row.state === 'pending' ? { summary: { a: null, b: null, rationale: row.decision?.rationale ?? null } } : {}),
34
- ...(row.reason === undefined ? {} : { reason: row.reason }),
35
- ...(row.state === 'skipped' ? { origin: row.origin ?? 'system' } : {}),
36
- ...(row.failure === undefined ? {} : { failure: { stage: row.failure.stage === 'screening' ? 'screening' : row.failure.stage === 'decide' ? 'decide' : row.failure.stage === 'author' ? 'author' : row.failure.stage === 'validate' ? 'validate' : 'commit', code: row.failure.code, retryable: row.failure.retryable, retryFrom: row.failure.retryFrom } }),
37
- ...(row.stagingRef === undefined ? {} : { staging: { state: 'kept', ...(row.stagingExpiresAt === undefined ? {} : { expiresAt: row.stagingExpiresAt }) } }),
38
- ...(row.expired === undefined ? {} : { expired: { kind: row.expired, at: Date.parse(row.updatedAt) } }),
39
- ...(row.attempts === undefined ? {} : { attempts: row.attempts }),
40
- ...(row.decision?.confidence === undefined ? {} : { confidence: row.decision.confidence }),
41
- ...(row.state === 'skipped' && row.stagingExpiresAt !== undefined ? { expiresAt: row.stagingExpiresAt } : {}),
42
- createdAt: Date.parse(row.createdAt),
43
- updatedAt: Date.parse(row.updatedAt),
44
- actions,
45
- };
46
- }
47
- export function toQueuePage(rows, queue, expiredOnly, readAt, limit = 50) {
48
- const filtered = rows.filter(row => queueOf(row) === queue && (expiredOnly ? expiredOf(row) : !expiredOf(row)));
49
- const page = filtered.slice(0, Math.max(0, Math.min(200, limit)));
50
- const counts = countsOf(rows);
51
- return { wireVersion: 1, readAt, queue, expiredOnly, counts, rows: page.map(row => toRowFact(row)), ...(filtered.length > page.length ? { nextCursor: String(page.length) } : {}), notes: [] };
52
- }
53
- export function toRunsView(runs, readAt) {
54
- const ordered = [...runs].sort((a, b) => b.startedAt - a.startedAt).slice(0, 50);
55
- return { wireVersion: 1, readAt, runs: ordered.map(run => toRunView(run, readAt)) };
56
- }
57
- export function toDoctorView(input) {
58
- return {
59
- wireVersion: 1,
60
- readAt: input.readAt,
61
- counts: input.counts,
62
- ...(input.latestRun === undefined ? {} : { latestRun: input.latestRun }),
63
- staging: input.staging,
64
- approval: input.approval,
65
- rows: input.rows.map(row => ({ key: row.key, status: row.status, ...(row.count === undefined ? {} : { count: row.count }), ...(row.detail === undefined ? {} : { detail: row.detail }) })),
66
- };
67
- }
68
- export function toBodyView(name, side, text, readAt) {
69
- return { wireVersion: 1, readAt, name, side, text, markdown: true, truncated: false, totalBytes: Buffer.byteLength(text, 'utf8') };
70
- }
71
- export function toHistoryView(items, readAt) {
72
- return { wireVersion: 1, readAt, items: items.map(item => {
73
- const parsed = item.archivedAt === null ? null : typeof item.archivedAt === 'number' ? item.archivedAt : Date.parse(item.archivedAt);
74
- return { name: item.name, kind: item.kind, reason: item.reason, lastVersion: item.lastVersion, archivedAt: parsed === null || Number.isFinite(parsed) ? parsed : null, ...(item.sourceRunId === undefined ? {} : { sourceRunId: item.sourceRunId }) };
75
- }) };
76
- }
77
- //# sourceMappingURL=wire-projection.js.map