@monoes/monodesign 1.2.18 → 1.2.22
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/README.md +3 -3
- package/cli/engine/design-system-checks.mjs +381 -0
- package/cli/engine/design-system-parse.mjs +433 -0
- package/cli/engine/design-system.mjs +20 -736
- package/cli/engine/detect-antipatterns-browser.js +12 -1
- package/cli/engine/engines/regex/detect-text-matchers.mjs +371 -0
- package/cli/engine/engines/regex/detect-text-run.mjs +186 -0
- package/cli/engine/engines/regex/detect-text.mjs +11 -523
- package/cli/engine/engines/static-html/css-cascade-color.mjs +219 -0
- package/cli/engine/engines/static-html/css-cascade-static-data.mjs +138 -0
- package/cli/engine/engines/static-html/css-cascade-static-dom.mjs +132 -0
- package/cli/engine/engines/static-html/css-cascade-static-parse.mjs +393 -0
- package/cli/engine/engines/static-html/css-cascade.mjs +24 -837
- package/cli/engine/registry/antipatterns-provider.mjs +60 -0
- package/cli/engine/registry/antipatterns-quality.mjs +218 -0
- package/cli/engine/registry/antipatterns-slop.mjs +226 -0
- package/cli/engine/registry/antipatterns.mjs +7 -494
- package/cli/engine/rules/checks-background.mjs +155 -0
- package/cli/engine/rules/checks-css-values.mjs +137 -0
- package/cli/engine/rules/checks-dom-effects.mjs +243 -0
- package/cli/engine/rules/checks-dom.mjs +148 -0
- package/cli/engine/rules/checks-element.mjs +286 -0
- package/cli/engine/rules/checks-html.mjs +204 -0
- package/cli/engine/rules/checks-overflow.mjs +263 -0
- package/cli/engine/rules/checks-page.mjs +465 -0
- package/cli/engine/rules/checks-pure.mjs +453 -0
- package/cli/engine/rules/checks-quality.mjs +447 -0
- package/cli/engine/rules/checks-stylesheet.mjs +324 -0
- package/cli/engine/rules/checks.mjs +98 -2939
- package/cli/lib/monodesign-config-consent.mjs +93 -0
- package/cli/lib/monodesign-config-core.mjs +37 -0
- package/cli/lib/monodesign-config-detection.mjs +133 -0
- package/cli/lib/monodesign-config-filter.mjs +198 -0
- package/cli/lib/monodesign-config-ignore-value.mjs +212 -0
- package/cli/lib/monodesign-config.mjs +21 -623
- package/package.json +2 -2
- package/skill/scripts/context-fields.mjs +65 -0
- package/skill/scripts/context-resolve.mjs +425 -0
- package/skill/scripts/context-update.mjs +151 -0
- package/skill/scripts/context-utils.mjs +68 -0
- package/skill/scripts/context-workspace.mjs +245 -0
- package/skill/scripts/context.mjs +17 -891
- package/skill/scripts/hook-admin-config.mjs +152 -0
- package/skill/scripts/hook-admin-ignore.mjs +131 -0
- package/skill/scripts/hook-admin-manifest.mjs +292 -0
- package/skill/scripts/hook-admin.mjs +8 -541
- package/skill/scripts/hook-before-edit-shell.mjs +184 -0
- package/skill/scripts/hook-before-edit.mjs +9 -165
- package/skill/scripts/hook-lib-cache.mjs +145 -0
- package/skill/scripts/hook-lib-config.mjs +292 -0
- package/skill/scripts/hook-lib-detector.mjs +72 -0
- package/skill/scripts/hook-lib-events.mjs +182 -0
- package/skill/scripts/hook-lib-findings.mjs +201 -0
- package/skill/scripts/hook-lib-ignore.mjs +205 -0
- package/skill/scripts/hook-lib-render.mjs +273 -0
- package/skill/scripts/hook-lib-run.mjs +281 -0
- package/skill/scripts/hook-lib-scan-targets.mjs +128 -0
- package/skill/scripts/hook-lib.mjs +71 -1747
- package/skill/scripts/lib/design-parser-colors.mjs +182 -0
- package/skill/scripts/lib/design-parser-extract.mjs +333 -0
- package/skill/scripts/lib/design-parser-sections.mjs +214 -0
- package/skill/scripts/lib/design-parser-yaml.mjs +135 -0
- package/skill/scripts/lib/design-parser.mjs +10 -783
- package/skill/scripts/live/manual-apply-chunk.mjs +151 -0
- package/skill/scripts/live/manual-apply-compact.mjs +122 -0
- package/skill/scripts/live/manual-apply-evidence.mjs +115 -0
- package/skill/scripts/live/manual-apply-log.mjs +179 -0
- package/skill/scripts/live/manual-apply-transaction.mjs +122 -0
- package/skill/scripts/live/manual-apply.mjs +65 -640
- package/skill/scripts/live/svelte-component-accept.mjs +248 -0
- package/skill/scripts/live/svelte-component-css.mjs +230 -0
- package/skill/scripts/live/svelte-component-markup.mjs +104 -0
- package/skill/scripts/live/svelte-component-scaffold.mjs +118 -0
- package/skill/scripts/live/svelte-component-session.mjs +158 -0
- package/skill/scripts/live/svelte-component.mjs +32 -792
- package/skill/scripts/live-accept-mutate.mjs +152 -0
- package/skill/scripts/live-accept-parse.mjs +370 -0
- package/skill/scripts/live-accept-scrub.mjs +59 -0
- package/skill/scripts/live-accept-search.mjs +58 -0
- package/skill/scripts/live-accept.mjs +15 -631
- package/skill/scripts/live-commit-manual-edits-paths.mjs +27 -0
- package/skill/scripts/live-commit-manual-edits-repair.mjs +166 -0
- package/skill/scripts/live-commit-manual-edits-rollback.mjs +231 -0
- package/skill/scripts/live-commit-manual-edits-utils.mjs +167 -0
- package/skill/scripts/live-commit-manual-edits-verify.mjs +356 -0
- package/skill/scripts/live-commit-manual-edits.mjs +24 -881
- package/skill/scripts/live-copy-edit-agent.mjs +16 -551
- package/skill/scripts/live-copy-edit-compact.mjs +137 -0
- package/skill/scripts/live-copy-edit-post-apply.mjs +175 -0
- package/skill/scripts/live-copy-edit-runners.mjs +297 -0
- package/skill/scripts/live-inject-csp.mjs +132 -0
- package/skill/scripts/live-inject-files.mjs +229 -0
- package/skill/scripts/live-inject-tag.mjs +114 -0
- package/skill/scripts/live-inject.mjs +13 -440
- package/skill/scripts/live-server-poll.mjs +232 -0
- package/skill/scripts/live-server-routes.mjs +449 -0
- package/skill/scripts/live-server-state.mjs +361 -0
- package/skill/scripts/live-server.mjs +10 -946
- package/skill/scripts/live-wrap-css.mjs +132 -0
- package/skill/scripts/live-wrap-manual-edit.mjs +153 -0
- package/skill/scripts/live-wrap-search.mjs +247 -0
- package/skill/scripts/live-wrap.mjs +21 -484
- package/skill/scripts/palette-seeds.mjs +401 -0
- package/skill/scripts/palette.mjs +1 -395
|
@@ -1,16 +1,73 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { getLiveDir } from '../lib/monodesign-paths.mjs';
|
|
5
|
-
import { readBuffer as readManualEditsBuffer } from './manual-edits-buffer.mjs';
|
|
6
|
-
|
|
7
4
|
const APPLY_EVENT_HARD_TIMEOUT_MS = Number(process.env.MONODESIGN_LIVE_APPLY_EVENT_HARD_TIMEOUT_MS || 150_000);
|
|
8
5
|
const APPLY_EVENT_SOFT_DEADLINE_MS = Number(process.env.MONODESIGN_LIVE_APPLY_EVENT_SOFT_DEADLINE_MS || 120_000);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
collectManualApplyFiles,
|
|
9
|
+
manualApplyEvidenceDir,
|
|
10
|
+
normalizeManualApplyEvidencePath,
|
|
11
|
+
removeManualApplyEvidence,
|
|
12
|
+
rollbackApplySnapshot,
|
|
13
|
+
snapshotApplyEventFiles,
|
|
14
|
+
writeManualApplyEvidence,
|
|
15
|
+
} from './manual-apply-evidence.mjs';
|
|
16
|
+
import { compactManualApplyBatch } from './manual-apply-compact.mjs';
|
|
17
|
+
import {
|
|
18
|
+
countManualApplyOps,
|
|
19
|
+
firstFailureReason,
|
|
20
|
+
manualEditApplyChunkSize,
|
|
21
|
+
markChunkEntriesFailed,
|
|
22
|
+
normalizeApplyChunkResult,
|
|
23
|
+
splitManualApplyBatch,
|
|
24
|
+
} from './manual-apply-chunk.mjs';
|
|
25
|
+
import {
|
|
26
|
+
buildManualApplyAgentAction,
|
|
27
|
+
summarizeManualApplyEvent,
|
|
28
|
+
validateManualApplyResultMessage,
|
|
29
|
+
} from './manual-apply-log.mjs';
|
|
30
|
+
import {
|
|
31
|
+
clearManualApplyTransaction,
|
|
32
|
+
readManualApplyTransaction,
|
|
33
|
+
rollbackManualApplyTransaction,
|
|
34
|
+
writeManualApplyTransaction,
|
|
35
|
+
} from './manual-apply-transaction.mjs';
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
collectManualApplyFiles,
|
|
39
|
+
manualApplyEvidenceDir,
|
|
40
|
+
normalizeManualApplyEvidencePath,
|
|
41
|
+
removeManualApplyEvidence,
|
|
42
|
+
rollbackApplySnapshot,
|
|
43
|
+
snapshotApplyEventFiles,
|
|
44
|
+
writeManualApplyEvidence,
|
|
45
|
+
} from './manual-apply-evidence.mjs';
|
|
46
|
+
export {
|
|
47
|
+
compactManualApplyBatch,
|
|
48
|
+
compactManualApplyCandidates,
|
|
49
|
+
} from './manual-apply-compact.mjs';
|
|
50
|
+
export {
|
|
51
|
+
countManualApplyOps,
|
|
52
|
+
manualEditApplyChunkSize,
|
|
53
|
+
splitManualApplyBatch,
|
|
54
|
+
} from './manual-apply-chunk.mjs';
|
|
55
|
+
export {
|
|
56
|
+
buildManualApplyAgentAction,
|
|
57
|
+
compactManualLogText,
|
|
58
|
+
summarizeManualApplyEvent,
|
|
59
|
+
summarizeManualApplyFailures,
|
|
60
|
+
summarizeManualDiagnostics,
|
|
61
|
+
summarizeManualLogFile,
|
|
62
|
+
validateManualApplyResultMessage,
|
|
63
|
+
} from './manual-apply-log.mjs';
|
|
64
|
+
export {
|
|
65
|
+
clearManualApplyTransaction,
|
|
66
|
+
manualApplyTransactionPath,
|
|
67
|
+
readManualApplyTransaction,
|
|
68
|
+
rollbackManualApplyTransaction,
|
|
69
|
+
writeManualApplyTransaction,
|
|
70
|
+
} from './manual-apply-transaction.mjs';
|
|
14
71
|
|
|
15
72
|
export function createManualApplyController({
|
|
16
73
|
pendingEvents,
|
|
@@ -305,635 +362,3 @@ export function createManualApplyController({
|
|
|
305
362
|
writeTransaction: (opts = {}) => writeManualApplyTransaction({ cwd: projectCwd(), ...opts }),
|
|
306
363
|
};
|
|
307
364
|
}
|
|
308
|
-
|
|
309
|
-
export function manualEditApplyChunkSize(env = process.env) {
|
|
310
|
-
const raw = Number(env.MONODESIGN_LIVE_MANUAL_EDIT_CHUNK_SIZE);
|
|
311
|
-
if (!Number.isFinite(raw)) return DEFAULT_MANUAL_EDIT_APPLY_CHUNK_SIZE;
|
|
312
|
-
const size = Math.trunc(raw);
|
|
313
|
-
return Math.max(MIN_MANUAL_EDIT_APPLY_CHUNK_SIZE, Math.min(MAX_MANUAL_EDIT_APPLY_CHUNK_SIZE, size));
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export function countManualApplyOps(entriesOrBatch) {
|
|
317
|
-
const entries = Array.isArray(entriesOrBatch)
|
|
318
|
-
? entriesOrBatch
|
|
319
|
-
: Array.isArray(entriesOrBatch?.entries) ? entriesOrBatch.entries : [];
|
|
320
|
-
let count = 0;
|
|
321
|
-
for (const entry of entries) count += Array.isArray(entry.ops) ? entry.ops.length : 0;
|
|
322
|
-
return count;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export function writeManualApplyEvidence(eventId, batch, cwd = process.cwd()) {
|
|
326
|
-
const dir = manualApplyEvidenceDir(cwd);
|
|
327
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
328
|
-
const evidencePath = path.join(dir, `${eventId}.json`);
|
|
329
|
-
fs.writeFileSync(evidencePath, `${JSON.stringify(batch, null, 2)}\n`, 'utf-8');
|
|
330
|
-
return evidencePath;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export function manualApplyEvidenceDir(cwd = process.cwd()) {
|
|
334
|
-
return path.join(getLiveDir(cwd), 'manual-edit-evidence');
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export function normalizeManualApplyEvidencePath(evidencePath, cwd = process.cwd()) {
|
|
338
|
-
if (!evidencePath || typeof evidencePath !== 'string') return null;
|
|
339
|
-
const fullPath = path.isAbsolute(evidencePath) ? evidencePath : path.resolve(cwd, evidencePath);
|
|
340
|
-
const evidenceDir = manualApplyEvidenceDir(cwd);
|
|
341
|
-
const relative = path.relative(evidenceDir, fullPath).split(path.sep).join('/');
|
|
342
|
-
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) return null;
|
|
343
|
-
if (path.extname(relative) !== '.json') return null;
|
|
344
|
-
return fullPath;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export function removeManualApplyEvidence(evidencePath, cwd = process.cwd()) {
|
|
348
|
-
const fullPath = normalizeManualApplyEvidencePath(evidencePath, cwd);
|
|
349
|
-
if (!fullPath) return false;
|
|
350
|
-
try {
|
|
351
|
-
fs.unlinkSync(fullPath);
|
|
352
|
-
return true;
|
|
353
|
-
} catch {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export function compactManualApplyBatch(batch = {}, cwd = process.cwd()) {
|
|
359
|
-
const entries = (batch.entries || []).map(compactManualApplyEntry);
|
|
360
|
-
const candidates = compactManualApplyCandidates(batch.candidates || [], cwd);
|
|
361
|
-
return {
|
|
362
|
-
version: batch.version,
|
|
363
|
-
pageUrl: batch.pageUrl || null,
|
|
364
|
-
count: batch.count,
|
|
365
|
-
entries,
|
|
366
|
-
ops: entries.flatMap((entry) => entry.ops.map((op) => ({ ...op, entryId: entry.id }))),
|
|
367
|
-
candidates: candidates.length > 0 ? candidates : undefined,
|
|
368
|
-
context: batch.context ? {
|
|
369
|
-
bufferPath: batch.context.bufferPath,
|
|
370
|
-
totalEntries: batch.context.totalEntries,
|
|
371
|
-
totalOps: batch.context.totalOps,
|
|
372
|
-
chunkIndex: batch.context.chunkIndex,
|
|
373
|
-
chunkTotal: batch.context.chunkTotal,
|
|
374
|
-
totalApplyOps: batch.context.totalApplyOps,
|
|
375
|
-
} : undefined,
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export function compactManualApplyCandidates(candidates, cwd = process.cwd()) {
|
|
380
|
-
return (Array.isArray(candidates) ? candidates : [])
|
|
381
|
-
.slice(0, 24)
|
|
382
|
-
.map((candidate) => ({
|
|
383
|
-
entryId: candidate.entryId,
|
|
384
|
-
ref: candidate.ref,
|
|
385
|
-
sourceHint: compactManualApplySourceMatch(candidate.sourceHint, cwd),
|
|
386
|
-
textMatches: compactManualApplySourceMatches(candidate.textMatches, 8, cwd),
|
|
387
|
-
objectKeyMatches: compactManualApplySourceMatches(candidate.objectKeyMatches, 8, cwd),
|
|
388
|
-
contextTextMatches: compactManualApplySourceMatches(candidate.contextTextMatches, 8, cwd),
|
|
389
|
-
locatorMatches: compactManualApplySourceMatches(candidate.locatorMatches, 6, cwd),
|
|
390
|
-
}));
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function compactManualApplySourceMatches(matches, limit, cwd) {
|
|
394
|
-
return (Array.isArray(matches) ? matches : [])
|
|
395
|
-
.slice(0, limit)
|
|
396
|
-
.map((match) => compactManualApplySourceMatch(match, cwd))
|
|
397
|
-
.filter(Boolean);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function compactManualApplySourceMatch(match, cwd) {
|
|
401
|
-
if (!match || typeof match !== 'object') return null;
|
|
402
|
-
const file = match.relativeFile || match.file;
|
|
403
|
-
if (!file && !match.line) return null;
|
|
404
|
-
return {
|
|
405
|
-
file: summarizeManualLogFile(file, cwd),
|
|
406
|
-
line: match.line || null,
|
|
407
|
-
column: match.column || null,
|
|
408
|
-
reason: match.reason || match.kind || undefined,
|
|
409
|
-
status: match.status || undefined,
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function compactManualApplyEntry(entry = {}) {
|
|
414
|
-
return {
|
|
415
|
-
id: entry.id,
|
|
416
|
-
pageUrl: entry.pageUrl,
|
|
417
|
-
stagedAt: entry.stagedAt || null,
|
|
418
|
-
element: compactManualApplyContext(entry.element),
|
|
419
|
-
ops: (entry.ops || []).map(compactManualApplyOp),
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function compactManualApplyOp(op = {}) {
|
|
424
|
-
return {
|
|
425
|
-
entryId: op.entryId,
|
|
426
|
-
ref: op.ref,
|
|
427
|
-
contextRef: op.contextRef,
|
|
428
|
-
tag: op.tag,
|
|
429
|
-
elementId: op.elementId,
|
|
430
|
-
classes: Array.isArray(op.classes) ? op.classes : [],
|
|
431
|
-
originalText: op.originalText,
|
|
432
|
-
newText: op.newText,
|
|
433
|
-
deleted: op.deleted === true || undefined,
|
|
434
|
-
sourceHint: op.sourceHint || null,
|
|
435
|
-
leaf: compactManualApplyContext(op.leaf),
|
|
436
|
-
nearbyEditableTexts: compactNearbyManualEditTexts(op.nearbyEditableTexts),
|
|
437
|
-
container: compactManualApplyContext(op.container),
|
|
438
|
-
contextHints: Array.isArray(op.contextHints) ? op.contextHints.slice(0, 8) : undefined,
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function compactManualApplyContext(value) {
|
|
443
|
-
if (!value || typeof value !== 'object') return null;
|
|
444
|
-
return {
|
|
445
|
-
ref: value.ref,
|
|
446
|
-
tagName: value.tagName || value.tag || null,
|
|
447
|
-
id: value.id || null,
|
|
448
|
-
classes: Array.isArray(value.classes) ? value.classes : [],
|
|
449
|
-
textContent: truncateManualApplyText(value.textContent, MANUAL_APPLY_COMPACT_TEXT_LIMIT),
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function compactNearbyManualEditTexts(items) {
|
|
454
|
-
return (Array.isArray(items) ? items : [])
|
|
455
|
-
.slice(0, MANUAL_APPLY_COMPACT_NEARBY_LIMIT)
|
|
456
|
-
.map((item) => typeof item === 'string' ? { text: truncateManualApplyText(item, MANUAL_APPLY_COMPACT_TEXT_LIMIT) } : {
|
|
457
|
-
ref: item?.ref,
|
|
458
|
-
tag: item?.tag,
|
|
459
|
-
classes: Array.isArray(item?.classes) ? item.classes : [],
|
|
460
|
-
text: truncateManualApplyText(item?.text, MANUAL_APPLY_COMPACT_TEXT_LIMIT),
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
function truncateManualApplyText(value, max) {
|
|
465
|
-
if (typeof value !== 'string') return value || null;
|
|
466
|
-
return value.length > max ? value.slice(0, max) : value;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function normalizeApplyChunkResult(result) {
|
|
470
|
-
const status = result?.status === 'partial' ? 'partial' : result?.status === 'error' ? 'error' : 'done';
|
|
471
|
-
return {
|
|
472
|
-
status,
|
|
473
|
-
message: typeof result?.message === 'string' ? result.message : null,
|
|
474
|
-
appliedEntryIds: Array.isArray(result?.appliedEntryIds) ? result.appliedEntryIds.filter((id) => typeof id === 'string') : [],
|
|
475
|
-
failed: Array.isArray(result?.failed) ? result.failed.filter(Boolean) : [],
|
|
476
|
-
files: Array.isArray(result?.files) ? result.files.filter((file) => typeof file === 'string') : [],
|
|
477
|
-
notes: Array.isArray(result?.notes) ? result.notes.filter((note) => typeof note === 'string') : [],
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function manualApplyResultShapeHint(eventId = 'EVENT_ID') {
|
|
482
|
-
return `Use live-poll.mjs --reply ${eventId} done --data '{"status":"done","appliedEntryIds":["ENTRY_ID"],"failed":[],"files":["src/page.html"],"notes":[]}'`;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function invalidManualApplyResult(reason, eventId, extra = {}) {
|
|
486
|
-
return {
|
|
487
|
-
ok: false,
|
|
488
|
-
body: {
|
|
489
|
-
error: 'invalid_manual_apply_result',
|
|
490
|
-
reason,
|
|
491
|
-
hint: manualApplyResultShapeHint(eventId),
|
|
492
|
-
...extra,
|
|
493
|
-
},
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
export function validateManualApplyResultMessage(msg, deferred) {
|
|
498
|
-
const data = msg?.data;
|
|
499
|
-
const eventId = msg?.id || deferred?.event?.id || 'EVENT_ID';
|
|
500
|
-
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
501
|
-
return invalidManualApplyResult('missing_result_data', eventId);
|
|
502
|
-
}
|
|
503
|
-
if ('entries' in data || 'ops' in data) {
|
|
504
|
-
return invalidManualApplyResult('summary_result_not_allowed', eventId);
|
|
505
|
-
}
|
|
506
|
-
if (!['done', 'partial', 'error'].includes(data.status)) {
|
|
507
|
-
return invalidManualApplyResult('invalid_status', eventId, { status: data.status ?? null });
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
for (const key of ['appliedEntryIds', 'failed', 'files', 'notes']) {
|
|
511
|
-
if (!Array.isArray(data[key])) {
|
|
512
|
-
return invalidManualApplyResult(`${key}_must_be_array`, eventId);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
for (const [index, value] of data.appliedEntryIds.entries()) {
|
|
517
|
-
if (typeof value !== 'string' || !value) {
|
|
518
|
-
return invalidManualApplyResult('appliedEntryIds_must_contain_strings', eventId, { index });
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
for (const [index, value] of data.files.entries()) {
|
|
522
|
-
if (typeof value !== 'string' || !value) {
|
|
523
|
-
return invalidManualApplyResult('files_must_contain_strings', eventId, { index });
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
for (const [index, value] of data.notes.entries()) {
|
|
527
|
-
if (typeof value !== 'string') {
|
|
528
|
-
return invalidManualApplyResult('notes_must_contain_strings', eventId, { index });
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
for (const [index, item] of data.failed.entries()) {
|
|
532
|
-
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
533
|
-
return invalidManualApplyResult('failed_must_contain_objects', eventId, { index });
|
|
534
|
-
}
|
|
535
|
-
if (typeof item.entryId !== 'string' || !item.entryId) {
|
|
536
|
-
return invalidManualApplyResult('failed_entryId_required', eventId, { index });
|
|
537
|
-
}
|
|
538
|
-
if (typeof item.reason !== 'string' || !item.reason) {
|
|
539
|
-
return invalidManualApplyResult('failed_reason_required', eventId, { index });
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const eventEntryIds = new Set((deferred?.batch?.entries || []).map((entry) => entry.id).filter(Boolean));
|
|
544
|
-
for (const entryId of data.appliedEntryIds) {
|
|
545
|
-
if (eventEntryIds.size > 0 && !eventEntryIds.has(entryId)) {
|
|
546
|
-
return invalidManualApplyResult('applied_entry_id_not_in_event', eventId, { entryId });
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
for (const item of data.failed) {
|
|
550
|
-
if (eventEntryIds.size > 0 && !eventEntryIds.has(item.entryId)) {
|
|
551
|
-
return invalidManualApplyResult('failed_entry_id_not_in_event', eventId, { entryId: item.entryId });
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (data.status === 'done') {
|
|
556
|
-
if (data.failed.length > 0) {
|
|
557
|
-
return invalidManualApplyResult('done_result_has_failed_entries', eventId);
|
|
558
|
-
}
|
|
559
|
-
if (countManualApplyOps(deferred?.batch) > 0 && data.appliedEntryIds.length === 0) {
|
|
560
|
-
return invalidManualApplyResult('done_result_missing_applied_entry_ids', eventId);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
if (data.status === 'partial' && data.appliedEntryIds.length === 0 && data.failed.length === 0) {
|
|
564
|
-
return invalidManualApplyResult('partial_result_has_no_entries', eventId);
|
|
565
|
-
}
|
|
566
|
-
if (data.status === 'error' && data.appliedEntryIds.length > 0) {
|
|
567
|
-
return invalidManualApplyResult('error_result_has_applied_entries', eventId);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
return {
|
|
571
|
-
ok: true,
|
|
572
|
-
result: {
|
|
573
|
-
status: data.status,
|
|
574
|
-
message: typeof data.message === 'string' ? data.message : undefined,
|
|
575
|
-
appliedEntryIds: data.appliedEntryIds,
|
|
576
|
-
failed: data.failed,
|
|
577
|
-
files: data.files,
|
|
578
|
-
notes: data.notes,
|
|
579
|
-
},
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function firstFailureReason(result) {
|
|
584
|
-
const first = Array.isArray(result?.failed) ? result.failed.find(Boolean) : null;
|
|
585
|
-
return first?.reason || first?.message || null;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
function markChunkEntriesFailed(failedByEntry, chunk, reason) {
|
|
589
|
-
for (const entryId of chunk.entryIds) {
|
|
590
|
-
if (failedByEntry.has(entryId)) continue;
|
|
591
|
-
failedByEntry.set(entryId, { entryId, reason, candidates: [] });
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
export function splitManualApplyBatch(batch, maxOps) {
|
|
596
|
-
const totalOpCount = countManualApplyOps(batch);
|
|
597
|
-
if (totalOpCount <= maxOps) {
|
|
598
|
-
return [{
|
|
599
|
-
batch,
|
|
600
|
-
meta: null,
|
|
601
|
-
entryIds: new Set((batch?.entries || []).map((entry) => entry.id).filter(Boolean)),
|
|
602
|
-
opCountsByEntry: new Map((batch?.entries || []).map((entry) => [entry.id, Array.isArray(entry.ops) ? entry.ops.length : 0])),
|
|
603
|
-
}];
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
const rawChunks = [];
|
|
607
|
-
let current = createManualApplyChunkBuilder();
|
|
608
|
-
for (const entry of batch?.entries || []) {
|
|
609
|
-
const ops = entry.ops || [];
|
|
610
|
-
if (ops.length <= maxOps) {
|
|
611
|
-
if (current.opCount > 0 && current.opCount + ops.length > maxOps) {
|
|
612
|
-
rawChunks.push(current);
|
|
613
|
-
current = createManualApplyChunkBuilder();
|
|
614
|
-
}
|
|
615
|
-
for (const op of ops) addOpToManualApplyChunk(current, entry, op);
|
|
616
|
-
continue;
|
|
617
|
-
}
|
|
618
|
-
if (current.opCount > 0) {
|
|
619
|
-
rawChunks.push(current);
|
|
620
|
-
current = createManualApplyChunkBuilder();
|
|
621
|
-
}
|
|
622
|
-
for (const op of ops) {
|
|
623
|
-
if (current.opCount >= maxOps) {
|
|
624
|
-
rawChunks.push(current);
|
|
625
|
-
current = createManualApplyChunkBuilder();
|
|
626
|
-
}
|
|
627
|
-
addOpToManualApplyChunk(current, entry, op);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
if (current.opCount > 0) rawChunks.push(current);
|
|
631
|
-
|
|
632
|
-
return rawChunks.map((chunk, index) => ({
|
|
633
|
-
batch: {
|
|
634
|
-
...batch,
|
|
635
|
-
count: chunk.opCount,
|
|
636
|
-
entries: chunk.entries,
|
|
637
|
-
ops: chunk.ops,
|
|
638
|
-
candidates: filterManualApplyChunkCandidates(batch, chunk.refsByEntry),
|
|
639
|
-
context: {
|
|
640
|
-
...(batch?.context || {}),
|
|
641
|
-
totalEntries: chunk.entries.length,
|
|
642
|
-
totalOps: chunk.opCount,
|
|
643
|
-
chunkIndex: index + 1,
|
|
644
|
-
chunkTotal: rawChunks.length,
|
|
645
|
-
totalApplyOps: totalOpCount,
|
|
646
|
-
},
|
|
647
|
-
},
|
|
648
|
-
meta: {
|
|
649
|
-
index: index + 1,
|
|
650
|
-
total: rawChunks.length,
|
|
651
|
-
opCount: chunk.opCount,
|
|
652
|
-
totalOpCount,
|
|
653
|
-
},
|
|
654
|
-
entryIds: new Set(chunk.entries.map((entry) => entry.id).filter(Boolean)),
|
|
655
|
-
opCountsByEntry: chunk.opCountsByEntry,
|
|
656
|
-
}));
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
function createManualApplyChunkBuilder() {
|
|
660
|
-
return {
|
|
661
|
-
entries: [],
|
|
662
|
-
entryById: new Map(),
|
|
663
|
-
entryIds: new Set(),
|
|
664
|
-
ops: [],
|
|
665
|
-
refsByEntry: new Map(),
|
|
666
|
-
opCountsByEntry: new Map(),
|
|
667
|
-
opCount: 0,
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
function addOpToManualApplyChunk(chunk, entry, op) {
|
|
672
|
-
let chunkEntry = chunk.entryById.get(entry.id);
|
|
673
|
-
if (!chunkEntry) {
|
|
674
|
-
chunkEntry = { ...entry, ops: [] };
|
|
675
|
-
chunk.entryById.set(entry.id, chunkEntry);
|
|
676
|
-
chunk.entryIds.add(entry.id);
|
|
677
|
-
chunk.entries.push(chunkEntry);
|
|
678
|
-
}
|
|
679
|
-
chunkEntry.ops.push(op);
|
|
680
|
-
chunk.ops.push({ ...op, entryId: op.entryId || entry.id });
|
|
681
|
-
if (!chunk.refsByEntry.has(entry.id)) chunk.refsByEntry.set(entry.id, new Set());
|
|
682
|
-
if (op.ref) chunk.refsByEntry.get(entry.id).add(op.ref);
|
|
683
|
-
chunk.opCountsByEntry.set(entry.id, (chunk.opCountsByEntry.get(entry.id) || 0) + 1);
|
|
684
|
-
chunk.opCount += 1;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
function filterManualApplyChunkCandidates(batch, refsByEntry) {
|
|
688
|
-
return (batch?.candidates || []).filter((candidate) => {
|
|
689
|
-
const refs = refsByEntry.get(candidate.entryId);
|
|
690
|
-
if (!refs) return false;
|
|
691
|
-
if (!candidate.ref) return true;
|
|
692
|
-
return refs.has(candidate.ref);
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
export function snapshotApplyEventFiles(batch, cwd = process.cwd()) {
|
|
697
|
-
const snapshot = new Map();
|
|
698
|
-
for (const relativeFile of collectManualApplyFiles(batch, [], cwd)) {
|
|
699
|
-
const absolute = path.resolve(cwd, relativeFile);
|
|
700
|
-
try {
|
|
701
|
-
snapshot.set(relativeFile, {
|
|
702
|
-
exists: fs.existsSync(absolute),
|
|
703
|
-
content: fs.existsSync(absolute) ? fs.readFileSync(absolute, 'utf-8') : '',
|
|
704
|
-
});
|
|
705
|
-
} catch {
|
|
706
|
-
// If a file cannot be read before dispatch, do not attempt late rollback.
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
return snapshot;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
export function manualApplyTransactionPath(cwd = process.cwd()) {
|
|
713
|
-
return path.join(getLiveDir(cwd), 'manual-edit-apply-transaction.json');
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
export function readManualApplyTransaction(cwd = process.cwd()) {
|
|
717
|
-
const file = manualApplyTransactionPath(cwd);
|
|
718
|
-
if (!fs.existsSync(file)) return null;
|
|
719
|
-
try {
|
|
720
|
-
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
721
|
-
} catch {
|
|
722
|
-
return null;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
export function writeManualApplyTransaction({ cwd = process.cwd(), pageUrl = null, batch }) {
|
|
727
|
-
const file = manualApplyTransactionPath(cwd);
|
|
728
|
-
const files = collectManualApplyFiles(batch, [], cwd);
|
|
729
|
-
const transaction = {
|
|
730
|
-
version: 1,
|
|
731
|
-
id: randomUUID().replace(/-/g, '').slice(0, 8),
|
|
732
|
-
createdAt: new Date().toISOString(),
|
|
733
|
-
pageUrl,
|
|
734
|
-
entryIds: (batch?.entries || []).map((entry) => entry.id).filter(Boolean),
|
|
735
|
-
files: files.map((relativeFile) => {
|
|
736
|
-
const absolute = path.resolve(cwd, relativeFile);
|
|
737
|
-
const exists = fs.existsSync(absolute);
|
|
738
|
-
return {
|
|
739
|
-
file: relativeFile,
|
|
740
|
-
exists,
|
|
741
|
-
content: exists ? fs.readFileSync(absolute, 'utf-8') : '',
|
|
742
|
-
};
|
|
743
|
-
}),
|
|
744
|
-
};
|
|
745
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
746
|
-
fs.writeFileSync(`${file}.tmp`, `${JSON.stringify(transaction, null, 2)}\n`, 'utf-8');
|
|
747
|
-
fs.renameSync(`${file}.tmp`, file);
|
|
748
|
-
return transaction;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
export function clearManualApplyTransaction(cwd = process.cwd(), transactionId = null) {
|
|
752
|
-
const file = manualApplyTransactionPath(cwd);
|
|
753
|
-
if (!fs.existsSync(file)) return false;
|
|
754
|
-
if (transactionId) {
|
|
755
|
-
const existing = readManualApplyTransaction(cwd);
|
|
756
|
-
if (existing?.id && existing.id !== transactionId) return false;
|
|
757
|
-
}
|
|
758
|
-
try {
|
|
759
|
-
fs.unlinkSync(file);
|
|
760
|
-
return true;
|
|
761
|
-
} catch {
|
|
762
|
-
return false;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
export function rollbackManualApplyTransaction({
|
|
767
|
-
cwd = process.cwd(),
|
|
768
|
-
pageUrl = null,
|
|
769
|
-
reason = 'manual_edit_transaction_rollback',
|
|
770
|
-
recordManualEditActivity = null,
|
|
771
|
-
} = {}) {
|
|
772
|
-
const transaction = readManualApplyTransaction(cwd);
|
|
773
|
-
if (!transaction) return null;
|
|
774
|
-
if (pageUrl && transaction.pageUrl && transaction.pageUrl !== pageUrl) return null;
|
|
775
|
-
|
|
776
|
-
let pendingIds = new Set();
|
|
777
|
-
try {
|
|
778
|
-
const buffer = readManualEditsBuffer(cwd);
|
|
779
|
-
pendingIds = new Set((buffer.entries || []).map((entry) => entry.id).filter(Boolean));
|
|
780
|
-
} catch {
|
|
781
|
-
pendingIds = new Set(transaction.entryIds || []);
|
|
782
|
-
}
|
|
783
|
-
const shouldRollback = (transaction.entryIds || []).some((id) => pendingIds.has(id));
|
|
784
|
-
if (!shouldRollback) {
|
|
785
|
-
clearManualApplyTransaction(cwd, transaction.id);
|
|
786
|
-
return { id: transaction.id, reason, rolledBackFiles: [], rollbackFailures: [], skipped: 'entries_not_pending' };
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
const rolledBackFiles = [];
|
|
790
|
-
const rollbackFailures = [];
|
|
791
|
-
for (const item of transaction.files || []) {
|
|
792
|
-
const relativeFile = normalizeProjectFile(item.file, cwd);
|
|
793
|
-
if (!relativeFile) continue;
|
|
794
|
-
const absolute = path.resolve(cwd, relativeFile);
|
|
795
|
-
try {
|
|
796
|
-
if (item.exists) {
|
|
797
|
-
fs.mkdirSync(path.dirname(absolute), { recursive: true });
|
|
798
|
-
fs.writeFileSync(absolute, item.content || '', 'utf-8');
|
|
799
|
-
} else if (fs.existsSync(absolute)) {
|
|
800
|
-
fs.rmSync(absolute);
|
|
801
|
-
}
|
|
802
|
-
rolledBackFiles.push(relativeFile);
|
|
803
|
-
} catch (err) {
|
|
804
|
-
rollbackFailures.push({ file: relativeFile, reason: 'restore_failed', message: err.message || String(err) });
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
clearManualApplyTransaction(cwd, transaction.id);
|
|
808
|
-
recordManualEditActivity?.('manual_edit_transaction_rolled_back', {
|
|
809
|
-
id: transaction.id,
|
|
810
|
-
pageUrl: transaction.pageUrl || null,
|
|
811
|
-
reason,
|
|
812
|
-
entryIds: transaction.entryIds || [],
|
|
813
|
-
rolledBackFiles: rolledBackFiles.map((file) => summarizeManualLogFile(file, cwd)).filter(Boolean),
|
|
814
|
-
rollbackFailures: summarizeManualDiagnostics(rollbackFailures, cwd),
|
|
815
|
-
});
|
|
816
|
-
return { id: transaction.id, reason, rolledBackFiles, rollbackFailures };
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
export function collectManualApplyFiles(batch, extraFiles = [], cwd = process.cwd()) {
|
|
820
|
-
const files = [];
|
|
821
|
-
for (const entry of batch?.entries || []) {
|
|
822
|
-
for (const op of entry.ops || []) files.push(op.sourceHint?.file);
|
|
823
|
-
}
|
|
824
|
-
for (const candidate of batch?.candidates || []) {
|
|
825
|
-
files.push(candidate.sourceHint?.relativeFile, candidate.sourceHint?.file);
|
|
826
|
-
for (const item of candidate.textMatches || []) files.push(item.file);
|
|
827
|
-
for (const item of candidate.objectKeyMatches || []) files.push(item.file);
|
|
828
|
-
for (const item of candidate.locatorMatches || []) files.push(item.file);
|
|
829
|
-
for (const item of candidate.contextTextMatches || []) files.push(item.file);
|
|
830
|
-
}
|
|
831
|
-
files.push(...(extraFiles || []));
|
|
832
|
-
return [...new Set(files)]
|
|
833
|
-
.map((file) => normalizeProjectFile(file, cwd))
|
|
834
|
-
.filter(Boolean);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
function normalizeProjectFile(file, cwd = process.cwd()) {
|
|
838
|
-
if (!file || typeof file !== 'string') return null;
|
|
839
|
-
const absolute = path.isAbsolute(file) ? file : path.resolve(cwd, file);
|
|
840
|
-
const relative = path.relative(cwd, absolute).split(path.sep).join('/');
|
|
841
|
-
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) return null;
|
|
842
|
-
return relative;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
export function rollbackApplySnapshot(
|
|
846
|
-
batch,
|
|
847
|
-
rollbackSnapshot,
|
|
848
|
-
extraFiles = [],
|
|
849
|
-
_reason = 'manual_edit_apply_snapshot_rollback',
|
|
850
|
-
cwd = process.cwd(),
|
|
851
|
-
) {
|
|
852
|
-
const scope = collectManualApplyFiles(batch, extraFiles, cwd);
|
|
853
|
-
const rolledBackFiles = [];
|
|
854
|
-
const rollbackFailures = [];
|
|
855
|
-
for (const relativeFile of scope) {
|
|
856
|
-
const before = rollbackSnapshot?.get(relativeFile);
|
|
857
|
-
if (!before) continue;
|
|
858
|
-
const absolute = path.resolve(cwd, relativeFile);
|
|
859
|
-
try {
|
|
860
|
-
if (before.exists) {
|
|
861
|
-
fs.mkdirSync(path.dirname(absolute), { recursive: true });
|
|
862
|
-
fs.writeFileSync(absolute, before.content, 'utf-8');
|
|
863
|
-
} else if (fs.existsSync(absolute)) {
|
|
864
|
-
fs.rmSync(absolute);
|
|
865
|
-
}
|
|
866
|
-
rolledBackFiles.push(relativeFile);
|
|
867
|
-
} catch (err) {
|
|
868
|
-
rollbackFailures.push({ file: relativeFile, reason: 'restore_failed', message: err.message || String(err) });
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
return { rolledBackFiles, rollbackFailures };
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
function manualApplyReplyCommand(eventOrId = 'EVENT_ID') {
|
|
875
|
-
const id = typeof eventOrId === 'string' ? eventOrId : eventOrId?.id || 'EVENT_ID';
|
|
876
|
-
return `live-poll.mjs --reply ${id} done --data '<json>'`;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
export function buildManualApplyAgentAction(eventOrId = 'EVENT_ID') {
|
|
880
|
-
return {
|
|
881
|
-
kind: 'manual_edit_apply',
|
|
882
|
-
required: 'apply_source_edits_then_reply',
|
|
883
|
-
replyCommand: manualApplyReplyCommand(eventOrId),
|
|
884
|
-
warning: 'Polling only leases this work item; it does not commit source edits.',
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
export function summarizeManualApplyEvent(event = {}, batch = event.batch, cwd = process.cwd()) {
|
|
889
|
-
const entries = Array.isArray(batch?.entries) ? batch.entries : [];
|
|
890
|
-
const opCount = entries.reduce((sum, entry) => sum + (Array.isArray(entry.ops) ? entry.ops.length : 0), 0);
|
|
891
|
-
return {
|
|
892
|
-
pageUrl: event.pageUrl || null,
|
|
893
|
-
chunk: event.chunk || null,
|
|
894
|
-
entryCount: entries.length,
|
|
895
|
-
opCount,
|
|
896
|
-
files: collectManualApplyFiles(batch, [], cwd),
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
export function summarizeManualApplyFailures(failed, cwd = process.cwd()) {
|
|
901
|
-
if (!Array.isArray(failed)) return [];
|
|
902
|
-
return failed.slice(0, 20).map((item) => ({
|
|
903
|
-
id: item.id || item.entryId || null,
|
|
904
|
-
reason: item.reason || item.message || 'failed',
|
|
905
|
-
message: compactManualLogText(item.message, 300),
|
|
906
|
-
files: Array.isArray(item.files) ? item.files.slice(0, 12).map((file) => summarizeManualLogFile(file, cwd)).filter(Boolean) : undefined,
|
|
907
|
-
checks: summarizeManualDiagnostics(item.checks, cwd),
|
|
908
|
-
failures: summarizeManualDiagnostics(item.failures, cwd),
|
|
909
|
-
candidates: summarizeManualDiagnostics(item.candidates, cwd),
|
|
910
|
-
}));
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
export function summarizeManualDiagnostics(items, cwd = process.cwd()) {
|
|
914
|
-
if (!Array.isArray(items) || items.length === 0) return undefined;
|
|
915
|
-
return items.slice(0, 12).map((item) => ({
|
|
916
|
-
reason: item.reason || item.kind || undefined,
|
|
917
|
-
detail: compactManualLogText(item.detail, 220),
|
|
918
|
-
message: compactManualLogText(item.message, 300),
|
|
919
|
-
file: summarizeManualLogFile(item.file || item.relativeFile, cwd),
|
|
920
|
-
line: item.line || undefined,
|
|
921
|
-
ref: compactManualLogText(item.ref, 180),
|
|
922
|
-
marker: compactManualLogText(item.marker, 120),
|
|
923
|
-
files: Array.isArray(item.files) ? item.files.slice(0, 8).map((file) => summarizeManualLogFile(file, cwd)).filter(Boolean) : undefined,
|
|
924
|
-
}));
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
export function summarizeManualLogFile(file, cwd = process.cwd()) {
|
|
928
|
-
if (!file || typeof file !== 'string') return undefined;
|
|
929
|
-
if (!path.isAbsolute(file)) return file;
|
|
930
|
-
const relative = path.relative(cwd, file).split(path.sep).join('/');
|
|
931
|
-
return relative && !relative.startsWith('..') && !path.isAbsolute(relative) ? relative : file;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
export function compactManualLogText(value, max = 200) {
|
|
935
|
-
if (typeof value !== 'string') return undefined;
|
|
936
|
-
const normalized = value.replace(/\s+/g, ' ').trim();
|
|
937
|
-
if (normalized.length <= max) return normalized;
|
|
938
|
-
return `${normalized.slice(0, max)}... [truncated ${normalized.length - max} chars]`;
|
|
939
|
-
}
|