@gobing-ai/knowledge-kit 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/daily-voice/index.js +40 -7
- package/dist/index.js +1379 -378
- package/package.json +1 -1
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/kk/config.example.yaml +3 -0
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
- package/plugins/kk/scripts/daily-stages.ts +238 -14
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/publish/SKILL.md +11 -0
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +32 -5
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/shipinhao-pub/dist/index.js +385 -31
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
- package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
- package/plugins/publishings/threads-pub/dist/index.js +9196 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +7 -0
- package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
- package/plugins/publishings/weibo-pub/dist/index.js +46 -2
- package/plugins/publishings/weibo-pub/src/index.ts +74 -2
- package/plugins/publishings/x-pub/dist/index.js +263 -43
- package/plugins/publishings/x-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
package/dist/index.js
CHANGED
|
@@ -37353,13 +37353,25 @@ function tokenCells(row) {
|
|
|
37353
37353
|
}
|
|
37354
37354
|
return `${row.inputTokens}/${row.outputTokens}`;
|
|
37355
37355
|
}
|
|
37356
|
+
function shortRunId(runId) {
|
|
37357
|
+
const epoch = /-(\d{13})$/.exec(runId);
|
|
37358
|
+
return epoch === null ? runId.slice(0, 8) : `\u2026${(epoch[1] ?? "").slice(-8)}`;
|
|
37359
|
+
}
|
|
37356
37360
|
function renderLedgerSection(trace, options = {}) {
|
|
37357
37361
|
const rows = stepGroups(trace).map((group) => stepRow(group, options.summaries));
|
|
37358
37362
|
const unknownSteps = rows.filter((row) => row.unknownTokens).length;
|
|
37359
37363
|
const inputTokens = rows.reduce((total, row) => total + (row.hasAgentAction ? row.inputTokens : 0), 0);
|
|
37360
37364
|
const outputTokens = rows.reduce((total, row) => total + (row.hasAgentAction ? row.outputTokens : 0), 0);
|
|
37365
|
+
const heading = [
|
|
37366
|
+
utcMinute(trace.run.startedAt),
|
|
37367
|
+
`run ${shortRunId(trace.run.runId)}`,
|
|
37368
|
+
trace.run.status,
|
|
37369
|
+
formatDuration(trace.run.durationMs),
|
|
37370
|
+
`tokens: ${inputTokens}/${outputTokens} (+${unknownSteps} unknown)`,
|
|
37371
|
+
...options.noContent === true ? ["no-content"] : []
|
|
37372
|
+
].join(" \xB7 ");
|
|
37361
37373
|
return [
|
|
37362
|
-
`## ${
|
|
37374
|
+
`## ${heading}`,
|
|
37363
37375
|
`<!-- run:${trace.run.runId} -->`,
|
|
37364
37376
|
"",
|
|
37365
37377
|
"| Step | Status | Duration | Tokens in/out | Result |",
|
|
@@ -37570,6 +37582,18 @@ async function readSummaries(fs, workDir, trace) {
|
|
|
37570
37582
|
}
|
|
37571
37583
|
return summaries;
|
|
37572
37584
|
}
|
|
37585
|
+
async function readNoContent(fs, workDir) {
|
|
37586
|
+
if (workDir === undefined)
|
|
37587
|
+
return false;
|
|
37588
|
+
const path = resolve7(workDir, "run-report.summary.txt");
|
|
37589
|
+
if (!await fs.exists(path))
|
|
37590
|
+
return false;
|
|
37591
|
+
try {
|
|
37592
|
+
return (await fs.readFile(path)).startsWith("no-content:");
|
|
37593
|
+
} catch {
|
|
37594
|
+
return false;
|
|
37595
|
+
}
|
|
37596
|
+
}
|
|
37573
37597
|
function ledgerFilePath(worksDir, workflow) {
|
|
37574
37598
|
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(workflow)) {
|
|
37575
37599
|
throw new LedgerError("workflow.invalid", `'${workflow}' is not a workflow name (letters, digits, . _ -)`);
|
|
@@ -37597,7 +37621,10 @@ async function appendAction(options) {
|
|
|
37597
37621
|
return;
|
|
37598
37622
|
}
|
|
37599
37623
|
const summaries = await readSummaries(fs, options.workDir, trace);
|
|
37600
|
-
const section = renderLedgerSection(trace, {
|
|
37624
|
+
const section = renderLedgerSection(trace, {
|
|
37625
|
+
summaries,
|
|
37626
|
+
noContent: await readNoContent(fs, options.workDir)
|
|
37627
|
+
});
|
|
37601
37628
|
await writeLedger(fs, ledgerPath, appendLedgerSection(existing, options.workflow, section));
|
|
37602
37629
|
report(options.workflow, ledgerPath, [options.run]);
|
|
37603
37630
|
} catch (error) {
|
|
@@ -37615,7 +37642,8 @@ async function syncLedger(options) {
|
|
|
37615
37642
|
const trace = readTrace(runId);
|
|
37616
37643
|
const workDir = index === missing.length - 1 ? options.workDir : undefined;
|
|
37617
37644
|
const summaries = await readSummaries(fs, workDir, trace);
|
|
37618
|
-
|
|
37645
|
+
const noContent = await readNoContent(fs, workDir);
|
|
37646
|
+
content = appendLedgerSection(content, options.workflow, renderLedgerSection(trace, { summaries, noContent }));
|
|
37619
37647
|
}
|
|
37620
37648
|
if (missing.length > 0) {
|
|
37621
37649
|
await writeLedger(fs, ledgerPath, content ?? "");
|
|
@@ -40365,6 +40393,716 @@ var init_bot_collection = __esm(() => {
|
|
|
40365
40393
|
};
|
|
40366
40394
|
});
|
|
40367
40395
|
|
|
40396
|
+
// ../../packages/publish-harness/src/bot-record-normalize.ts
|
|
40397
|
+
function quoteValue(value) {
|
|
40398
|
+
return value.replaceAll("\\", "\\\\").replaceAll('"', "\\\"");
|
|
40399
|
+
}
|
|
40400
|
+
function normalizeTarget(snapshot) {
|
|
40401
|
+
const target = snapshot.nodes[snapshot.targetIndex];
|
|
40402
|
+
if (target === undefined || !target.visible)
|
|
40403
|
+
return null;
|
|
40404
|
+
const visible = snapshot.nodes.filter((candidate) => candidate.visible);
|
|
40405
|
+
for (const tier of TIERS) {
|
|
40406
|
+
const candidate = tier.build(target);
|
|
40407
|
+
if (candidate === undefined)
|
|
40408
|
+
continue;
|
|
40409
|
+
const hits = visible.filter(candidate.matches);
|
|
40410
|
+
if (hits.length === 0)
|
|
40411
|
+
continue;
|
|
40412
|
+
if (hits.length === 1)
|
|
40413
|
+
return { selector: candidate.selector, rank: tier.rank };
|
|
40414
|
+
return {
|
|
40415
|
+
ambiguous: true,
|
|
40416
|
+
candidates: hits.slice(0, MAX_AMBIGUOUS_CANDIDATES).map((hit) => hit.path)
|
|
40417
|
+
};
|
|
40418
|
+
}
|
|
40419
|
+
return { selector: target.path, rank: "path" };
|
|
40420
|
+
}
|
|
40421
|
+
var MAX_AMBIGUOUS_CANDIDATES = 5, TIERS;
|
|
40422
|
+
var init_bot_record_normalize = __esm(() => {
|
|
40423
|
+
TIERS = [
|
|
40424
|
+
{
|
|
40425
|
+
rank: "testid",
|
|
40426
|
+
build: (node) => node.testid === undefined || node.testid === "" ? undefined : {
|
|
40427
|
+
selector: `[data-testid="${quoteValue(node.testid)}"]`,
|
|
40428
|
+
matches: (candidate) => candidate.testid === node.testid
|
|
40429
|
+
}
|
|
40430
|
+
},
|
|
40431
|
+
{
|
|
40432
|
+
rank: "name",
|
|
40433
|
+
build: (node) => node.name === undefined || node.name === "" ? undefined : {
|
|
40434
|
+
selector: `[name="${quoteValue(node.name)}"]`,
|
|
40435
|
+
matches: (candidate) => candidate.name === node.name
|
|
40436
|
+
}
|
|
40437
|
+
},
|
|
40438
|
+
{
|
|
40439
|
+
rank: "aria",
|
|
40440
|
+
build: (node) => node.ariaLabel === undefined || node.ariaLabel === "" ? undefined : {
|
|
40441
|
+
selector: `[aria-label="${quoteValue(node.ariaLabel)}"]`,
|
|
40442
|
+
matches: (candidate) => candidate.ariaLabel === node.ariaLabel
|
|
40443
|
+
}
|
|
40444
|
+
},
|
|
40445
|
+
{
|
|
40446
|
+
rank: "role-text",
|
|
40447
|
+
build: (node) => node.role === undefined || node.role === "" || node.text === undefined || node.text === "" ? undefined : {
|
|
40448
|
+
selector: `role=${node.role}[name="${quoteValue(node.text)}" s]`,
|
|
40449
|
+
matches: (candidate) => candidate.role === node.role && candidate.text === node.text
|
|
40450
|
+
}
|
|
40451
|
+
},
|
|
40452
|
+
{
|
|
40453
|
+
rank: "text",
|
|
40454
|
+
build: (node) => node.text === undefined || node.text === "" ? undefined : {
|
|
40455
|
+
selector: `text="${quoteValue(node.text)}"`,
|
|
40456
|
+
matches: (candidate) => candidate.text === node.text
|
|
40457
|
+
}
|
|
40458
|
+
}
|
|
40459
|
+
];
|
|
40460
|
+
});
|
|
40461
|
+
|
|
40462
|
+
// ../../packages/publish-harness/src/bot-record.ts
|
|
40463
|
+
var exports_bot_record = {};
|
|
40464
|
+
__export(exports_bot_record, {
|
|
40465
|
+
RECORDER_INIT_SCRIPT: () => RECORDER_INIT_SCRIPT,
|
|
40466
|
+
applyRecordedEvent: () => applyRecordedEvent,
|
|
40467
|
+
attachTranscriptRecorder: () => attachTranscriptRecorder,
|
|
40468
|
+
defaultTranscriptPath: () => defaultTranscriptPath,
|
|
40469
|
+
emptyTranscript: () => emptyTranscript,
|
|
40470
|
+
parkSigintListenersSince: () => parkSigintListenersSince,
|
|
40471
|
+
readTranscript: () => readTranscript,
|
|
40472
|
+
recordBotSession: () => recordBotSession,
|
|
40473
|
+
redactJson: () => redactJson,
|
|
40474
|
+
redactUrl: () => redactUrl,
|
|
40475
|
+
writeTranscript: () => writeTranscript
|
|
40476
|
+
});
|
|
40477
|
+
import { basename as basename3, join as join14 } from "path";
|
|
40478
|
+
function redactUrl(url) {
|
|
40479
|
+
try {
|
|
40480
|
+
const parsed = new URL(url);
|
|
40481
|
+
return `${parsed.origin}${parsed.pathname}`;
|
|
40482
|
+
} catch {
|
|
40483
|
+
return url.split(/[?#]/)[0] ?? url;
|
|
40484
|
+
}
|
|
40485
|
+
}
|
|
40486
|
+
function redactJson(value) {
|
|
40487
|
+
if (Array.isArray(value))
|
|
40488
|
+
return value.map((entry) => redactJson(entry));
|
|
40489
|
+
if (value === null || typeof value !== "object")
|
|
40490
|
+
return value;
|
|
40491
|
+
const redacted = {};
|
|
40492
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
40493
|
+
redacted[key] = SECRET_KEY_PATTERN.test(key) ? "<redacted>" : redactJson(entry);
|
|
40494
|
+
}
|
|
40495
|
+
return redacted;
|
|
40496
|
+
}
|
|
40497
|
+
function emptyTranscript(input) {
|
|
40498
|
+
return {
|
|
40499
|
+
schemaVersion: 1,
|
|
40500
|
+
bot: input.bot,
|
|
40501
|
+
startUrl: redactUrl(input.startUrl),
|
|
40502
|
+
recordedAt: new Date().toISOString(),
|
|
40503
|
+
redacted: input.redacted,
|
|
40504
|
+
steps: []
|
|
40505
|
+
};
|
|
40506
|
+
}
|
|
40507
|
+
function append(transcript, step) {
|
|
40508
|
+
const recorded = { ...step, i: transcript.steps.length };
|
|
40509
|
+
transcript.steps.push(recorded);
|
|
40510
|
+
return recorded;
|
|
40511
|
+
}
|
|
40512
|
+
function recordedText(text, includeText) {
|
|
40513
|
+
return { text: includeText ? text : { redacted: true, length: text.length } };
|
|
40514
|
+
}
|
|
40515
|
+
function typeLength(text) {
|
|
40516
|
+
return typeof text === "string" ? text.length : text.length;
|
|
40517
|
+
}
|
|
40518
|
+
function applyRecordedEvent(transcript, event, options = {}) {
|
|
40519
|
+
const includeText = options.includeText === true;
|
|
40520
|
+
if (event.kind === "navigate") {
|
|
40521
|
+
return append(transcript, { t: event.t, kind: "navigate", url: redactUrl(event.url) });
|
|
40522
|
+
}
|
|
40523
|
+
const target = normalizeTarget(event.snapshot);
|
|
40524
|
+
if (target === null)
|
|
40525
|
+
return null;
|
|
40526
|
+
const url = redactUrl(event.url);
|
|
40527
|
+
if (event.kind === "click") {
|
|
40528
|
+
return append(transcript, {
|
|
40529
|
+
t: event.t,
|
|
40530
|
+
kind: "click",
|
|
40531
|
+
url,
|
|
40532
|
+
target,
|
|
40533
|
+
...event.text === undefined || event.text === "" ? {} : { text: event.text }
|
|
40534
|
+
});
|
|
40535
|
+
}
|
|
40536
|
+
if (event.kind === "key") {
|
|
40537
|
+
return append(transcript, { t: event.t, kind: "key", url, target, key: event.key });
|
|
40538
|
+
}
|
|
40539
|
+
if (event.kind === "file") {
|
|
40540
|
+
return append(transcript, { t: event.t, kind: "file", url, target, fileName: basename3(event.fileName) });
|
|
40541
|
+
}
|
|
40542
|
+
const last = transcript.steps.at(-1);
|
|
40543
|
+
if (last !== undefined && last.kind === "type" && JSON.stringify(last.target) === JSON.stringify(target)) {
|
|
40544
|
+
const merged = typeLength(last.text) + event.text.length;
|
|
40545
|
+
last.text = includeText ? `${typeof last.text === "string" ? last.text : ""}${event.text}` : { redacted: true, length: merged };
|
|
40546
|
+
return last;
|
|
40547
|
+
}
|
|
40548
|
+
return append(transcript, { t: event.t, kind: "type", url, target, ...recordedText(event.text, includeText) });
|
|
40549
|
+
}
|
|
40550
|
+
async function writeTranscript(path, transcript, options = {}) {
|
|
40551
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
40552
|
+
const temp = `${path}.tmp-${process.pid}`;
|
|
40553
|
+
await fileSystem.writeFile(temp, `${JSON.stringify(transcript, null, 2)}
|
|
40554
|
+
`);
|
|
40555
|
+
chmod(temp, 384);
|
|
40556
|
+
await fileSystem.rename(temp, path);
|
|
40557
|
+
}
|
|
40558
|
+
async function readTranscript(path, options = {}) {
|
|
40559
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
40560
|
+
const raw = await fileSystem.readFile(path);
|
|
40561
|
+
const parsed = JSON.parse(typeof raw === "string" ? raw : new TextDecoder().decode(raw));
|
|
40562
|
+
if (parsed.schemaVersion !== 1) {
|
|
40563
|
+
throw new Error(`transcript ${path} has schemaVersion ${String(parsed.schemaVersion)}; this kk reads 1`);
|
|
40564
|
+
}
|
|
40565
|
+
if (parsed.redacted !== true && options.allowUnredacted !== true)
|
|
40566
|
+
throw new UnredactedTranscriptError(path);
|
|
40567
|
+
return parsed;
|
|
40568
|
+
}
|
|
40569
|
+
function defaultTranscriptPath(bot, now = new Date) {
|
|
40570
|
+
const stamp = now.toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
40571
|
+
return join14(".spur", "run", `bot-record-${bot}-${stamp}.json`);
|
|
40572
|
+
}
|
|
40573
|
+
async function readResponseBody(response) {
|
|
40574
|
+
try {
|
|
40575
|
+
const length = Number.parseInt(await response.headerValue("content-length") ?? "", 10);
|
|
40576
|
+
const truncated = Number.isFinite(length) && length > MAX_RESPONSE_BODY_BYTES;
|
|
40577
|
+
if (truncated)
|
|
40578
|
+
return { truncated: true };
|
|
40579
|
+
const body = await response.json();
|
|
40580
|
+
if (Buffer.byteLength(JSON.stringify(body)) > MAX_RESPONSE_BODY_BYTES)
|
|
40581
|
+
return { truncated: true };
|
|
40582
|
+
return { body: redactJson(body) };
|
|
40583
|
+
} catch {
|
|
40584
|
+
return {};
|
|
40585
|
+
}
|
|
40586
|
+
}
|
|
40587
|
+
function attachTranscriptRecorder(options) {
|
|
40588
|
+
const { context, transcript } = options;
|
|
40589
|
+
context.on("response", (response) => {
|
|
40590
|
+
const method = response.request().method().toUpperCase();
|
|
40591
|
+
if (!MUTATING_METHODS.has(method))
|
|
40592
|
+
return;
|
|
40593
|
+
(async () => {
|
|
40594
|
+
const contentType = await response.headerValue("content-type") ?? "";
|
|
40595
|
+
if (!contentType.includes("application/json"))
|
|
40596
|
+
return;
|
|
40597
|
+
const { body, truncated } = await readResponseBody(response);
|
|
40598
|
+
append(transcript, {
|
|
40599
|
+
t: Date.now(),
|
|
40600
|
+
kind: "response",
|
|
40601
|
+
method,
|
|
40602
|
+
url: redactUrl(response.url()),
|
|
40603
|
+
status: response.status(),
|
|
40604
|
+
...body === undefined ? {} : { body },
|
|
40605
|
+
...truncated === true ? { truncated: true } : {}
|
|
40606
|
+
});
|
|
40607
|
+
await options.persist?.();
|
|
40608
|
+
})().catch(() => {});
|
|
40609
|
+
});
|
|
40610
|
+
}
|
|
40611
|
+
function parkSigintListenersSince(before) {
|
|
40612
|
+
const parked = process.listeners("SIGINT").filter((listener) => !before.has(listener));
|
|
40613
|
+
for (const listener of parked)
|
|
40614
|
+
process.off("SIGINT", listener);
|
|
40615
|
+
return () => {
|
|
40616
|
+
for (const listener of parked)
|
|
40617
|
+
process.on("SIGINT", listener);
|
|
40618
|
+
};
|
|
40619
|
+
}
|
|
40620
|
+
async function recordBotSession(name, options = {}) {
|
|
40621
|
+
await Promise.resolve().then(() => init_browser());
|
|
40622
|
+
await Promise.resolve().then(() => init_browser());
|
|
40623
|
+
const fileSystem = options.fileSystem ?? createNodeFileSystem();
|
|
40624
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(name)) {
|
|
40625
|
+
throw new Error(`bot name '${name}' does not match [A-Za-z0-9][A-Za-z0-9_-]{0,63}`);
|
|
40626
|
+
}
|
|
40627
|
+
const profileDir = resolveBotProfileDir(name, { root: options.root });
|
|
40628
|
+
const saved = await readBotSavedMetadata(name, { root: options.root, fileSystem });
|
|
40629
|
+
const startUrl = saved?.defaultUrl ?? options.defaultUrl;
|
|
40630
|
+
if (startUrl === undefined)
|
|
40631
|
+
throw missingBotProfile(name, true);
|
|
40632
|
+
const out = options.out ?? defaultTranscriptPath(name);
|
|
40633
|
+
const transcript = emptyTranscript({ bot: name, startUrl, redacted: options.includeText !== true });
|
|
40634
|
+
const persist = () => writeTranscript(out, transcript, { fileSystem });
|
|
40635
|
+
const lease = await acquireProfileLease(profileDir, { leaseRoot: options.leaseRoot, fileSystem });
|
|
40636
|
+
let context;
|
|
40637
|
+
let flushing;
|
|
40638
|
+
let interrupted;
|
|
40639
|
+
const flushAndRelease = (signal) => {
|
|
40640
|
+
flushing ??= (async () => {
|
|
40641
|
+
interrupted = signal;
|
|
40642
|
+
if (signal === "SIGINT")
|
|
40643
|
+
process.exitCode = 130;
|
|
40644
|
+
if (signal === "SIGTERM")
|
|
40645
|
+
process.exitCode = 143;
|
|
40646
|
+
await closeBotContext(context);
|
|
40647
|
+
await persist();
|
|
40648
|
+
await lease.release();
|
|
40649
|
+
})();
|
|
40650
|
+
return flushing;
|
|
40651
|
+
};
|
|
40652
|
+
const onSigint = () => void flushAndRelease("SIGINT");
|
|
40653
|
+
const onSigterm = () => void flushAndRelease("SIGTERM");
|
|
40654
|
+
const sigintBefore = new Set(process.listeners("SIGINT"));
|
|
40655
|
+
let unpark;
|
|
40656
|
+
try {
|
|
40657
|
+
const launcher = options.launcher ?? createKkBrowserLauncher(undefined, { lease, physicalProfileDir: profileDir }, { leaseRoot: options.leaseRoot, fileSystem });
|
|
40658
|
+
context = await launcher.launch({ profileDir, headless: false });
|
|
40659
|
+
unpark = parkSigintListenersSince(sigintBefore);
|
|
40660
|
+
const closed = new Promise((resolve) => context?.once("close", () => resolve()));
|
|
40661
|
+
await context.exposeBinding("__kkRecord", (_source, event) => {
|
|
40662
|
+
const step = applyRecordedEvent(transcript, event, { includeText: options.includeText === true });
|
|
40663
|
+
if (step !== null)
|
|
40664
|
+
persist();
|
|
40665
|
+
return step !== null;
|
|
40666
|
+
});
|
|
40667
|
+
await context.addInitScript(RECORDER_INIT_SCRIPT);
|
|
40668
|
+
attachTranscriptRecorder({ context, transcript, fileSystem, persist, includeText: options.includeText });
|
|
40669
|
+
process.once("SIGINT", onSigint);
|
|
40670
|
+
process.once("SIGTERM", onSigterm);
|
|
40671
|
+
const page = await openBotPage(context);
|
|
40672
|
+
applyRecordedEvent(transcript, { kind: "navigate", url: startUrl, t: Date.now() });
|
|
40673
|
+
await persist();
|
|
40674
|
+
await page.goto(startUrl);
|
|
40675
|
+
applyRecordedEvent(transcript, { kind: "navigate", url: page.url(), t: Date.now() });
|
|
40676
|
+
await persist();
|
|
40677
|
+
await closed;
|
|
40678
|
+
return {
|
|
40679
|
+
name,
|
|
40680
|
+
out,
|
|
40681
|
+
startUrl: transcript.startUrl,
|
|
40682
|
+
stepCount: transcript.steps.length,
|
|
40683
|
+
redacted: transcript.redacted,
|
|
40684
|
+
...interrupted === undefined ? {} : { signal: interrupted }
|
|
40685
|
+
};
|
|
40686
|
+
} finally {
|
|
40687
|
+
process.off("SIGINT", onSigint);
|
|
40688
|
+
process.off("SIGTERM", onSigterm);
|
|
40689
|
+
await flushAndRelease();
|
|
40690
|
+
unpark?.();
|
|
40691
|
+
}
|
|
40692
|
+
}
|
|
40693
|
+
var MAX_RESPONSE_BODY_BYTES, SECRET_KEY_PATTERN, MUTATING_METHODS, UnredactedTranscriptError, RECORDER_INIT_SCRIPT = `(() => {
|
|
40694
|
+
if (globalThis.__kkRecorderInstalled) return;
|
|
40695
|
+
globalThis.__kkRecorderInstalled = true;
|
|
40696
|
+
const INTERACTIVE = 'button, a, input, textarea, select, [role=button], [role=link], [role=textbox], [role=menuitem], [contenteditable=true]';
|
|
40697
|
+
const attr = (el, name) => el.getAttribute(name) ?? undefined;
|
|
40698
|
+
function pathOf(el) {
|
|
40699
|
+
const parts = [];
|
|
40700
|
+
for (let node = el; node && node.nodeType === 1 && parts.length < 12; node = node.parentElement) {
|
|
40701
|
+
let part = node.tagName.toLowerCase();
|
|
40702
|
+
for (const name of ['data-testid', 'name', 'aria-label', 'role']) {
|
|
40703
|
+
const value = node.getAttribute(name);
|
|
40704
|
+
if (value) part += '[' + name + '="' + value.replace(/"/g, '\\\\"') + '"]';
|
|
40705
|
+
}
|
|
40706
|
+
const siblings = node.parentElement ? [...node.parentElement.children].filter((s) => s.tagName === node.tagName) : [];
|
|
40707
|
+
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
40708
|
+
parts.unshift(part);
|
|
40709
|
+
}
|
|
40710
|
+
return parts.join(' > ');
|
|
40711
|
+
}
|
|
40712
|
+
const describe = (el) => ({
|
|
40713
|
+
tag: el.tagName.toLowerCase(),
|
|
40714
|
+
...(attr(el, 'data-testid') ? { testid: attr(el, 'data-testid') } : {}),
|
|
40715
|
+
...(attr(el, 'name') ? { name: attr(el, 'name') } : {}),
|
|
40716
|
+
...(attr(el, 'aria-label') ? { ariaLabel: attr(el, 'aria-label') } : {}),
|
|
40717
|
+
...(attr(el, 'role') ? { role: attr(el, 'role') } : {}),
|
|
40718
|
+
text: (el.textContent ?? '').trim().replace(/\\s+/g, ' ').slice(0, 120),
|
|
40719
|
+
// Rendered under aria-hidden or inert is unreachable (X's background composer behind its modal).
|
|
40720
|
+
visible: (el.checkVisibility ? el.checkVisibility() : el.offsetParent !== null) && !el.closest('[aria-hidden="true"], [inert]'),
|
|
40721
|
+
path: pathOf(el),
|
|
40722
|
+
});
|
|
40723
|
+
function snapshot(el) {
|
|
40724
|
+
const nodes = [...document.querySelectorAll(INTERACTIVE)].map(describe);
|
|
40725
|
+
const index = nodes.findIndex((node) => node.path === pathOf(el));
|
|
40726
|
+
return { nodes, targetIndex: index };
|
|
40727
|
+
}
|
|
40728
|
+
const post = (event) => globalThis.__kkRecord?.({ ...event, url: location.href, t: Date.now() });
|
|
40729
|
+
document.addEventListener('click', (e) => {
|
|
40730
|
+
const el = e.target instanceof Element ? e.target.closest(INTERACTIVE) : null;
|
|
40731
|
+
if (el) post({ kind: 'click', snapshot: snapshot(el), text: (el.textContent ?? '').trim().slice(0, 120) });
|
|
40732
|
+
}, true);
|
|
40733
|
+
document.addEventListener('keydown', (e) => {
|
|
40734
|
+
if (e.key.length === 1) return;
|
|
40735
|
+
const el = document.activeElement instanceof Element ? document.activeElement.closest(INTERACTIVE) : null;
|
|
40736
|
+
if (el) post({ kind: 'key', snapshot: snapshot(el), key: e.key });
|
|
40737
|
+
}, true);
|
|
40738
|
+
document.addEventListener('input', (e) => {
|
|
40739
|
+
const el = e.target instanceof Element ? e.target.closest(INTERACTIVE) : null;
|
|
40740
|
+
if (!el) return;
|
|
40741
|
+
const inserted = typeof e.data === 'string' ? e.data : '';
|
|
40742
|
+
if (inserted !== '') post({ kind: 'type', snapshot: snapshot(el), text: inserted });
|
|
40743
|
+
}, true);
|
|
40744
|
+
document.addEventListener('change', (e) => {
|
|
40745
|
+
const el = e.target;
|
|
40746
|
+
if (!(el instanceof HTMLInputElement) || el.type !== 'file') return;
|
|
40747
|
+
const name = el.files && el.files[0] ? el.files[0].name : '';
|
|
40748
|
+
if (name !== '') post({ kind: 'file', snapshot: snapshot(el), fileName: name });
|
|
40749
|
+
}, true);
|
|
40750
|
+
})();`;
|
|
40751
|
+
var init_bot_record = __esm(() => {
|
|
40752
|
+
init_dist3();
|
|
40753
|
+
init_bot_fs();
|
|
40754
|
+
init_bot_record_normalize();
|
|
40755
|
+
MAX_RESPONSE_BODY_BYTES = 64 * 1024;
|
|
40756
|
+
SECRET_KEY_PATTERN = /token|secret|password|cookie|session|auth/i;
|
|
40757
|
+
MUTATING_METHODS = new Set(["POST", "PUT", "PATCH"]);
|
|
40758
|
+
UnredactedTranscriptError = class UnredactedTranscriptError extends Error {
|
|
40759
|
+
constructor(path) {
|
|
40760
|
+
super(`transcript ${path} was recorded unredacted \u2014 replay/codegen refuse it unless --allow-unredacted is given`);
|
|
40761
|
+
this.name = "UnredactedTranscriptError";
|
|
40762
|
+
}
|
|
40763
|
+
};
|
|
40764
|
+
});
|
|
40765
|
+
|
|
40766
|
+
// ../../packages/publish-harness/src/bot-codegen.ts
|
|
40767
|
+
var exports_bot_codegen = {};
|
|
40768
|
+
__export(exports_bot_codegen, {
|
|
40769
|
+
generateRail: () => generateRail
|
|
40770
|
+
});
|
|
40771
|
+
function isReceiptField(name) {
|
|
40772
|
+
return name === "rest_id" || name === "id" || name.endsWith("_id") || name === "url";
|
|
40773
|
+
}
|
|
40774
|
+
function pickReceiptPath(value, prefix = []) {
|
|
40775
|
+
if (value === null || typeof value !== "object")
|
|
40776
|
+
return;
|
|
40777
|
+
const entries = Object.entries(value);
|
|
40778
|
+
const ranked = [...entries].sort(([a], [b]) => {
|
|
40779
|
+
const rank = (name) => {
|
|
40780
|
+
const index = RECEIPT_FIELDS.indexOf(name);
|
|
40781
|
+
return index === -1 ? RECEIPT_FIELDS.length : index;
|
|
40782
|
+
};
|
|
40783
|
+
return rank(a) - rank(b);
|
|
40784
|
+
});
|
|
40785
|
+
for (const [key, entry] of ranked) {
|
|
40786
|
+
if (typeof entry === "string" && isReceiptField(key) && entry !== "")
|
|
40787
|
+
return [...prefix, key].join(".");
|
|
40788
|
+
}
|
|
40789
|
+
for (const [key, entry] of ranked) {
|
|
40790
|
+
const nested = pickReceiptPath(entry, [...prefix, key]);
|
|
40791
|
+
if (nested !== undefined)
|
|
40792
|
+
return nested;
|
|
40793
|
+
}
|
|
40794
|
+
return;
|
|
40795
|
+
}
|
|
40796
|
+
function receiptResponse(transcript) {
|
|
40797
|
+
const lastClick = transcript.steps.filter((step) => step.kind === "click").at(-1)?.i ?? -1;
|
|
40798
|
+
const responses = transcript.steps.filter((step) => step.kind === "response");
|
|
40799
|
+
const polled = new Set(responses.filter((step) => step.i < lastClick).map(endpoint));
|
|
40800
|
+
const after = responses.filter((step) => step.i > lastClick);
|
|
40801
|
+
return after.findLast((step) => !polled.has(endpoint(step))) ?? after.at(-1);
|
|
40802
|
+
}
|
|
40803
|
+
function pascalCase(value) {
|
|
40804
|
+
return value.split(/[^A-Za-z0-9]+/).filter((part) => part !== "").map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
40805
|
+
}
|
|
40806
|
+
function stepSelector(step, index) {
|
|
40807
|
+
if (!("target" in step))
|
|
40808
|
+
return { abort: `step ${index} carries no target` };
|
|
40809
|
+
if ("ambiguous" in step.target) {
|
|
40810
|
+
return { abort: `step ${index} is ambiguous (${step.target.candidates.join(" | ")}) \u2014 resolve it by hand` };
|
|
40811
|
+
}
|
|
40812
|
+
if (step.target.rank === "path") {
|
|
40813
|
+
return { abort: `step ${index} has a structural-only selector (${step.target.selector}) \u2014 re-record it` };
|
|
40814
|
+
}
|
|
40815
|
+
return step.target.selector;
|
|
40816
|
+
}
|
|
40817
|
+
function renderStep(step, key) {
|
|
40818
|
+
if (step.kind === "response")
|
|
40819
|
+
return [];
|
|
40820
|
+
if (step.kind === "navigate")
|
|
40821
|
+
return [` await page.goto('${step.url}');`];
|
|
40822
|
+
const selector = key === undefined ? undefined : `SELECTORS.${key} as string`;
|
|
40823
|
+
const lines = [];
|
|
40824
|
+
if (selector !== undefined)
|
|
40825
|
+
lines.push(` const ${key} = await resolveSelector(page, [${selector}]);`);
|
|
40826
|
+
switch (step.kind) {
|
|
40827
|
+
case "click":
|
|
40828
|
+
lines.push(` await page.click(${key});`);
|
|
40829
|
+
break;
|
|
40830
|
+
case "key":
|
|
40831
|
+
lines.push(` await page.keyboard.press('${step.key}');`);
|
|
40832
|
+
break;
|
|
40833
|
+
case "type":
|
|
40834
|
+
lines.push(` await page.click(${key});`);
|
|
40835
|
+
lines.push(" await page.keyboard.type(input.text);");
|
|
40836
|
+
break;
|
|
40837
|
+
case "file":
|
|
40838
|
+
lines.push(` await uploadFile(page, ${key}, input.filePath);`);
|
|
40839
|
+
break;
|
|
40840
|
+
}
|
|
40841
|
+
return lines;
|
|
40842
|
+
}
|
|
40843
|
+
function node(step) {
|
|
40844
|
+
return step.kind === "navigate" || step.kind === "response";
|
|
40845
|
+
}
|
|
40846
|
+
function generateRail(transcript, options) {
|
|
40847
|
+
const warnings = [];
|
|
40848
|
+
const selectorLines = [];
|
|
40849
|
+
const bodyLines = [];
|
|
40850
|
+
const receipt = receiptResponse(transcript);
|
|
40851
|
+
const keys = new Map;
|
|
40852
|
+
for (const step of transcript.steps) {
|
|
40853
|
+
if (node(step))
|
|
40854
|
+
continue;
|
|
40855
|
+
const selector = stepSelector(step, step.i);
|
|
40856
|
+
if (typeof selector !== "string")
|
|
40857
|
+
throw new Error(selector.abort);
|
|
40858
|
+
const key = `step${step.i}`;
|
|
40859
|
+
keys.set(step.i, key);
|
|
40860
|
+
selectorLines.push(` ${key}: '${selector.replaceAll("'", "\\'")}',`);
|
|
40861
|
+
}
|
|
40862
|
+
if (receipt !== undefined) {
|
|
40863
|
+
const path = options.receiptPath ?? pickReceiptPath(receipt.body);
|
|
40864
|
+
const pathname = new URL(receipt.url).pathname;
|
|
40865
|
+
if (path === undefined) {
|
|
40866
|
+
warnings.push(`receipt: the ${receipt.method} ${pathname} response carries no id/url field \u2014 pass --receipt-path`);
|
|
40867
|
+
bodyLines.push(" // TODO receipt: name the id path inside the captured response (see --receipt-path)");
|
|
40868
|
+
} else {
|
|
40869
|
+
bodyLines.push(" // receipt");
|
|
40870
|
+
bodyLines.push(" // Armed before the submit click: the response can land before the click returns.");
|
|
40871
|
+
bodyLines.push(" const pending = page.waitForResponse(");
|
|
40872
|
+
bodyLines.push(` (candidate) => candidate.request().method() === '${receipt.method}' && new URL(candidate.url()).pathname === '${pathname}',`);
|
|
40873
|
+
bodyLines.push(" );");
|
|
40874
|
+
}
|
|
40875
|
+
if (path !== undefined)
|
|
40876
|
+
bodyLines.push(` const receiptPath = '${path}';`);
|
|
40877
|
+
} else {
|
|
40878
|
+
warnings.push("receipt: the transcript holds no mutating response after the submit click \u2014 emitting a TODO");
|
|
40879
|
+
bodyLines.push(" // TODO receipt: re-record the submit so codegen can emit a response matcher");
|
|
40880
|
+
}
|
|
40881
|
+
bodyLines.push("");
|
|
40882
|
+
for (const step of transcript.steps) {
|
|
40883
|
+
for (const line of renderStep(step, keys.get(step.i)))
|
|
40884
|
+
bodyLines.push(line);
|
|
40885
|
+
}
|
|
40886
|
+
const picksReceipt = receipt !== undefined && (options.receiptPath ?? pickReceiptPath(receipt.body)) !== undefined;
|
|
40887
|
+
if (picksReceipt) {
|
|
40888
|
+
bodyLines.push("");
|
|
40889
|
+
bodyLines.push(" // receipt");
|
|
40890
|
+
bodyLines.push(" const response = await pending;");
|
|
40891
|
+
bodyLines.push(" const evidence = pick(await response.json(), receiptPath);");
|
|
40892
|
+
bodyLines.push(" return expectOutcome(async () => evidence ?? null, {");
|
|
40893
|
+
bodyLines.push(" timeoutMs: 15000,");
|
|
40894
|
+
bodyLines.push(` label: '${options.plugin} ${options.operation} receipt',`);
|
|
40895
|
+
bodyLines.push(" });");
|
|
40896
|
+
}
|
|
40897
|
+
const runner = pascalCase(options.operation);
|
|
40898
|
+
const source = [
|
|
40899
|
+
...options.transcriptPath === undefined ? [] : [`// transcript: ${options.transcriptPath}`],
|
|
40900
|
+
"// generated by kk bot codegen \u2014 promote by hand; this file is a diffable draft, not a live rail",
|
|
40901
|
+
"import type { Page } from 'playwright';",
|
|
40902
|
+
`import { ${["expectOutcome", "resolveSelector", ...bodyLines.some((line) => line.includes("uploadFile(")) ? ["uploadFile"] : []].join(", ")} } from '@gobing-ai/publish-harness/browser';`,
|
|
40903
|
+
"",
|
|
40904
|
+
"/** Selectors measured from the recorded session, keyed by the transcript step they replay. */",
|
|
40905
|
+
"export const SELECTORS = {",
|
|
40906
|
+
...selectorLines,
|
|
40907
|
+
"} as const;",
|
|
40908
|
+
"",
|
|
40909
|
+
"/** Read a dot path out of the captured response body. */",
|
|
40910
|
+
"function pick(body: unknown, path: string): string | undefined {",
|
|
40911
|
+
" let cursor: unknown = body;",
|
|
40912
|
+
" for (const key of path.split('.')) {",
|
|
40913
|
+
" if (cursor === null || typeof cursor !== 'object') return undefined;",
|
|
40914
|
+
" cursor = (cursor as Record<string, unknown>)[key];",
|
|
40915
|
+
" }",
|
|
40916
|
+
" return typeof cursor === 'string' ? cursor : undefined;",
|
|
40917
|
+
"}",
|
|
40918
|
+
"",
|
|
40919
|
+
`/** Replay the recorded ${options.operation} steps for ${options.plugin}. */`,
|
|
40920
|
+
`export async function run${runner}(`,
|
|
40921
|
+
" page: Page,",
|
|
40922
|
+
" input: { text: string; filePath: string },",
|
|
40923
|
+
"): ReturnType<typeof expectOutcome> {",
|
|
40924
|
+
...bodyLines,
|
|
40925
|
+
"}",
|
|
40926
|
+
""
|
|
40927
|
+
].join(`
|
|
40928
|
+
`);
|
|
40929
|
+
return { source, warnings };
|
|
40930
|
+
}
|
|
40931
|
+
var RECEIPT_FIELDS, endpoint = (step) => `${step.method} ${new URL(step.url).pathname}`;
|
|
40932
|
+
var init_bot_codegen = __esm(() => {
|
|
40933
|
+
RECEIPT_FIELDS = ["rest_id", "id", "url"];
|
|
40934
|
+
});
|
|
40935
|
+
|
|
40936
|
+
// ../../packages/publish-harness/src/bot-replay.ts
|
|
40937
|
+
var exports_bot_replay = {};
|
|
40938
|
+
__export(exports_bot_replay, {
|
|
40939
|
+
replayBot: () => replayBot,
|
|
40940
|
+
replayBotSession: () => replayBotSession,
|
|
40941
|
+
submitStepIndex: () => submitStepIndex
|
|
40942
|
+
});
|
|
40943
|
+
function submitStepIndex(transcript, submitText) {
|
|
40944
|
+
if (submitText !== undefined) {
|
|
40945
|
+
const named = transcript.steps.findLastIndex((step) => step.kind === "click" && step.text === submitText);
|
|
40946
|
+
if (named !== -1)
|
|
40947
|
+
return named;
|
|
40948
|
+
}
|
|
40949
|
+
return transcript.steps.findLastIndex((step) => step.kind === "click");
|
|
40950
|
+
}
|
|
40951
|
+
function selectorOf(step) {
|
|
40952
|
+
if (!("target" in step))
|
|
40953
|
+
return null;
|
|
40954
|
+
if ("ambiguous" in step.target) {
|
|
40955
|
+
return { blocked: `step ${step.i} is ambiguous (${step.target.candidates.join(" | ")})` };
|
|
40956
|
+
}
|
|
40957
|
+
return { selector: step.target.selector };
|
|
40958
|
+
}
|
|
40959
|
+
function visibleOnly(selector) {
|
|
40960
|
+
return `${selector} >> visible=true`;
|
|
40961
|
+
}
|
|
40962
|
+
async function reachableTargets(page, selector, timeoutMs) {
|
|
40963
|
+
const narrowed = visibleOnly(selector);
|
|
40964
|
+
const locator = page.locator(narrowed);
|
|
40965
|
+
const deadline = Date.now() + timeoutMs;
|
|
40966
|
+
try {
|
|
40967
|
+
for (;; ) {
|
|
40968
|
+
const reachable = await locator.evaluateAll((nodes, unreachable) => nodes.map((node) => node.closest(unreachable) === null), UNREACHABLE);
|
|
40969
|
+
if (reachable.includes(true) || Date.now() >= deadline) {
|
|
40970
|
+
return reachable.flatMap((ok, index) => ok ? [`${narrowed} >> nth=${index}`] : []);
|
|
40971
|
+
}
|
|
40972
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
40973
|
+
}
|
|
40974
|
+
} catch {
|
|
40975
|
+
return [];
|
|
40976
|
+
}
|
|
40977
|
+
}
|
|
40978
|
+
async function replayBotSession(bot, transcript, options) {
|
|
40979
|
+
const marker = options.redactionMarker ?? "\u2022";
|
|
40980
|
+
const stopAt = options.submit === true ? -1 : submitStepIndex(transcript, options.submitText);
|
|
40981
|
+
const timeoutMs = options.stepTimeoutMs ?? 15000;
|
|
40982
|
+
const rows = [];
|
|
40983
|
+
const opensWithNavigate = transcript.steps.find((step) => step.kind !== "response")?.kind === "navigate";
|
|
40984
|
+
if (!opensWithNavigate && options.page.url() !== transcript.startUrl) {
|
|
40985
|
+
await options.page.goto(transcript.startUrl);
|
|
40986
|
+
}
|
|
40987
|
+
for (const step of transcript.steps) {
|
|
40988
|
+
if (step.kind === "response")
|
|
40989
|
+
continue;
|
|
40990
|
+
if (step.i === stopAt) {
|
|
40991
|
+
rows.push({
|
|
40992
|
+
step: step.i,
|
|
40993
|
+
kind: step.kind,
|
|
40994
|
+
url: step.url,
|
|
40995
|
+
ok: false,
|
|
40996
|
+
skipped: "submit",
|
|
40997
|
+
detail: "stopped before the submit step (pass --submit to replay it)"
|
|
40998
|
+
});
|
|
40999
|
+
return { bot, rows, stoppedBeforeSubmit: true };
|
|
41000
|
+
}
|
|
41001
|
+
if (step.kind === "navigate") {
|
|
41002
|
+
await options.page.goto(step.url);
|
|
41003
|
+
rows.push({ step: step.i, kind: step.kind, url: step.url, ok: true });
|
|
41004
|
+
await options.screenshot?.(step.i);
|
|
41005
|
+
continue;
|
|
41006
|
+
}
|
|
41007
|
+
const target = selectorOf(step);
|
|
41008
|
+
if (target === null) {
|
|
41009
|
+
rows.push({ step: step.i, kind: step.kind, url: step.url, ok: false, detail: "step carries no selector" });
|
|
41010
|
+
await options.screenshot?.(step.i);
|
|
41011
|
+
return { bot, rows, stoppedBeforeSubmit: false };
|
|
41012
|
+
}
|
|
41013
|
+
if ("blocked" in target) {
|
|
41014
|
+
rows.push({ step: step.i, kind: step.kind, url: step.url, ok: false, detail: target.blocked });
|
|
41015
|
+
await options.screenshot?.(step.i);
|
|
41016
|
+
return { bot, rows, stoppedBeforeSubmit: false };
|
|
41017
|
+
}
|
|
41018
|
+
const selector = target.selector;
|
|
41019
|
+
const targets = await reachableTargets(options.page, selector, timeoutMs);
|
|
41020
|
+
const count = targets.length;
|
|
41021
|
+
if (count !== 1) {
|
|
41022
|
+
rows.push({
|
|
41023
|
+
step: step.i,
|
|
41024
|
+
kind: step.kind,
|
|
41025
|
+
url: step.url,
|
|
41026
|
+
selectorCount: count,
|
|
41027
|
+
ok: false,
|
|
41028
|
+
detail: `selector ${selector} resolved ${count} visible, reachable nodes (expected exactly 1)`
|
|
41029
|
+
});
|
|
41030
|
+
await options.screenshot?.(step.i);
|
|
41031
|
+
return { bot, rows, stoppedBeforeSubmit: false };
|
|
41032
|
+
}
|
|
41033
|
+
const resolved = targets[0];
|
|
41034
|
+
if (step.kind === "click") {
|
|
41035
|
+
await options.page.click(resolved);
|
|
41036
|
+
rows.push({ step: step.i, kind: step.kind, url: step.url, selectorCount: count, ok: true });
|
|
41037
|
+
await options.screenshot?.(step.i);
|
|
41038
|
+
continue;
|
|
41039
|
+
}
|
|
41040
|
+
if (step.kind === "key") {
|
|
41041
|
+
await options.page.keyboard.press(step.key);
|
|
41042
|
+
rows.push({ step: step.i, kind: step.kind, url: step.url, selectorCount: count, ok: true });
|
|
41043
|
+
await options.screenshot?.(step.i);
|
|
41044
|
+
continue;
|
|
41045
|
+
}
|
|
41046
|
+
if (step.kind === "file") {
|
|
41047
|
+
await options.page.setInputFiles(resolved, options.filePath ?? step.fileName);
|
|
41048
|
+
rows.push({ step: step.i, kind: step.kind, url: step.url, selectorCount: count, ok: true });
|
|
41049
|
+
await options.screenshot?.(step.i);
|
|
41050
|
+
continue;
|
|
41051
|
+
}
|
|
41052
|
+
await options.page.click(resolved);
|
|
41053
|
+
const typed = typeof step.text === "string" ? step.text : marker.repeat(step.text.length);
|
|
41054
|
+
await options.page.keyboard.type(typed);
|
|
41055
|
+
rows.push({
|
|
41056
|
+
step: step.i,
|
|
41057
|
+
kind: step.kind,
|
|
41058
|
+
url: step.url,
|
|
41059
|
+
selectorCount: count,
|
|
41060
|
+
editorTextLength: typed.length,
|
|
41061
|
+
ok: true
|
|
41062
|
+
});
|
|
41063
|
+
await options.screenshot?.(step.i);
|
|
41064
|
+
}
|
|
41065
|
+
return { bot, rows, stoppedBeforeSubmit: false };
|
|
41066
|
+
}
|
|
41067
|
+
async function replayBot(bot, transcript, options = {}) {
|
|
41068
|
+
await Promise.resolve().then(() => init_browser());
|
|
41069
|
+
const { mkdirSync } = await import("fs");
|
|
41070
|
+
const { join } = await import("path");
|
|
41071
|
+
await Promise.resolve().then(() => init_dist3());
|
|
41072
|
+
const fileSystem = createNodeFileSystem();
|
|
41073
|
+
const profileDir = resolveBotProfileDir(bot, { root: options.root });
|
|
41074
|
+
const outDir = options.outDir ?? join(".spur", "run", `bot-replay-${bot}`);
|
|
41075
|
+
mkdirSync(outDir, { recursive: true });
|
|
41076
|
+
const lease = await acquireProfileLease(profileDir, { leaseRoot: options.leaseRoot, fileSystem });
|
|
41077
|
+
let context;
|
|
41078
|
+
try {
|
|
41079
|
+
const launcher = options.launcher ?? createKkBrowserLauncher(undefined, { lease, physicalProfileDir: profileDir }, { leaseRoot: options.leaseRoot, fileSystem });
|
|
41080
|
+
context = await launcher.launch({ profileDir, headless: false });
|
|
41081
|
+
const page = await openBotPage(context);
|
|
41082
|
+
const shots = [];
|
|
41083
|
+
const result = await replayBotSession(bot, transcript, {
|
|
41084
|
+
page,
|
|
41085
|
+
submit: options.submit === true,
|
|
41086
|
+
...options.submitText === undefined ? {} : { submitText: options.submitText },
|
|
41087
|
+
...options.filePath === undefined ? {} : { filePath: options.filePath },
|
|
41088
|
+
...options.stepTimeoutMs === undefined ? {} : { stepTimeoutMs: options.stepTimeoutMs },
|
|
41089
|
+
screenshot: async (step) => {
|
|
41090
|
+
const path = join(outDir, `${String(step).padStart(2, "0")}.png`);
|
|
41091
|
+
await page.screenshot({ path });
|
|
41092
|
+
shots.push(path);
|
|
41093
|
+
}
|
|
41094
|
+
});
|
|
41095
|
+
const replayPath = join(outDir, "replay.json");
|
|
41096
|
+
await fileSystem.writeFile(replayPath, `${JSON.stringify({ ...result, screenshots: shots }, null, 2)}
|
|
41097
|
+
`);
|
|
41098
|
+
return { result, outDir, replayPath };
|
|
41099
|
+
} finally {
|
|
41100
|
+
await closeBotContext(context);
|
|
41101
|
+
await lease.release();
|
|
41102
|
+
}
|
|
41103
|
+
}
|
|
41104
|
+
var UNREACHABLE = '[aria-hidden="true"], [inert]';
|
|
41105
|
+
|
|
40368
41106
|
// ../../node_modules/.bun/@logtape+logtape@2.3.1/node_modules/@logtape/logtape/dist/util.node.js
|
|
40369
41107
|
var exports_util_node = {};
|
|
40370
41108
|
__export(exports_util_node, {
|
|
@@ -43271,16 +44009,25 @@ async function spawnPluginSession(opts) {
|
|
|
43271
44009
|
await proc.exited;
|
|
43272
44010
|
return { exitCode: proc.exitCode ?? 1, stdout: stdout.trim() };
|
|
43273
44011
|
}
|
|
44012
|
+
var VERDICT_SCAN_LINES = 20;
|
|
43274
44013
|
function probeVerdict(exitCode, stdout) {
|
|
43275
|
-
const
|
|
43276
|
-
`).map((line) => line.trim()).filter((line) => line !== "").
|
|
43277
|
-
let
|
|
43278
|
-
|
|
43279
|
-
|
|
43280
|
-
|
|
43281
|
-
parsed
|
|
44014
|
+
const lines = stdout.split(`
|
|
44015
|
+
`).map((line) => line.trim()).filter((line) => line !== "").slice(-VERDICT_SCAN_LINES);
|
|
44016
|
+
let fields;
|
|
44017
|
+
for (const line of [...lines].reverse()) {
|
|
44018
|
+
if (!line.startsWith("{"))
|
|
44019
|
+
continue;
|
|
44020
|
+
let parsed;
|
|
44021
|
+
try {
|
|
44022
|
+
parsed = JSON.parse(line);
|
|
44023
|
+
} catch {
|
|
44024
|
+
continue;
|
|
44025
|
+
}
|
|
44026
|
+
if (typeof parsed === "object" && parsed !== null && typeof parsed.status === "string") {
|
|
44027
|
+
fields = parsed;
|
|
44028
|
+
break;
|
|
44029
|
+
}
|
|
43282
44030
|
}
|
|
43283
|
-
const fields = typeof parsed === "object" && parsed !== null ? parsed : undefined;
|
|
43284
44031
|
const status = typeof fields?.status === "string" ? fields.status : undefined;
|
|
43285
44032
|
if (status === "verified" && exitCode === 0 || status === "refused" && exitCode === 1) {
|
|
43286
44033
|
return {
|
|
@@ -49149,6 +49896,41 @@ async function runReportAction(options) {
|
|
|
49149
49896
|
failLoud2("kk.daily.run-report.failed", error);
|
|
49150
49897
|
}
|
|
49151
49898
|
}
|
|
49899
|
+
function appendLadderReport(body, workDir) {
|
|
49900
|
+
const path = join7(workDir, "10-collect", "ladder.json");
|
|
49901
|
+
if (!existsSync5(path))
|
|
49902
|
+
return body;
|
|
49903
|
+
try {
|
|
49904
|
+
const ladder = parseJson3(readFileSync7(path, "utf-8"));
|
|
49905
|
+
const rungs = Array.isArray(ladder.rungs) ? ladder.rungs : [];
|
|
49906
|
+
const rows = rungs.flatMap((value) => {
|
|
49907
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
49908
|
+
return [];
|
|
49909
|
+
const rung = value;
|
|
49910
|
+
const cell = (key) => String(rung[key] ?? "").replaceAll("|", "\\|");
|
|
49911
|
+
return [
|
|
49912
|
+
`| ${cell("window")} | ${cell("items")} | ${cell("chars")} | ${cell("minutes")} | ${cell("clears")} |`
|
|
49913
|
+
];
|
|
49914
|
+
});
|
|
49915
|
+
const section = [
|
|
49916
|
+
"## Pool ladder",
|
|
49917
|
+
"",
|
|
49918
|
+
`- Driving measure: ${String(ladder.ratioUsed ?? "unknown")} spoken/raw ratio (${String(ladder.ratioSource ?? "unknown source")})`,
|
|
49919
|
+
`- Chosen window: ${String(ladder.chosen ?? "unknown")}`,
|
|
49920
|
+
"",
|
|
49921
|
+
"| Window | Items | Characters | Estimated minutes | Clears floor |",
|
|
49922
|
+
"| --- | ---: | ---: | ---: | --- |",
|
|
49923
|
+
...rows
|
|
49924
|
+
].join(`
|
|
49925
|
+
`);
|
|
49926
|
+
return `${body.trimEnd()}
|
|
49927
|
+
|
|
49928
|
+
${section}
|
|
49929
|
+
`;
|
|
49930
|
+
} catch {
|
|
49931
|
+
return body;
|
|
49932
|
+
}
|
|
49933
|
+
}
|
|
49152
49934
|
async function generateRunReport(options) {
|
|
49153
49935
|
const { workDir, runDate } = options;
|
|
49154
49936
|
const reportMd = join7(workDir, `${runDate}_19_run-report_report.md`);
|
|
@@ -49158,13 +49940,13 @@ async function generateRunReport(options) {
|
|
|
49158
49940
|
mkdirSync3(workDir, { recursive: true });
|
|
49159
49941
|
if (poolCount === 0 || candidateCount === 0) {
|
|
49160
49942
|
const reason = noContentReason(workDir, runDate, poolCount);
|
|
49161
|
-
const body = `# Daily run ${runDate} \u2014 no content
|
|
49943
|
+
const body = appendLadderReport(`# Daily run ${runDate} \u2014 no content
|
|
49162
49944
|
|
|
49163
49945
|
${reason}
|
|
49164
49946
|
|
|
49165
49947
|
No article, audio or publish
|
|
49166
49948
|
artifact was produced; nothing was marked used.
|
|
49167
|
-
|
|
49949
|
+
`, workDir);
|
|
49168
49950
|
writeFileSync4(reportMd, body);
|
|
49169
49951
|
writeFileSync4(summary, `${reason}
|
|
49170
49952
|
`);
|
|
@@ -49225,7 +50007,7 @@ artifact was produced; nothing was marked used.
|
|
|
49225
50007
|
const parsedReport = parseJson3(readFileSync7(reportJson, "utf-8"));
|
|
49226
50008
|
if (typeof parsedReport.body !== "string")
|
|
49227
50009
|
throw new Error(`${reportJson} has no string body`);
|
|
49228
|
-
writeFileSync4(reportMd, parsedReport.body);
|
|
50010
|
+
writeFileSync4(reportMd, appendLadderReport(parsedReport.body, workDir));
|
|
49229
50011
|
writeFileSync4(summary, `${candidateCount} items planned
|
|
49230
50012
|
`);
|
|
49231
50013
|
return { noContent: false, report: reportMd };
|
|
@@ -49307,7 +50089,7 @@ function collectSetting2(value, previous) {
|
|
|
49307
50089
|
}
|
|
49308
50090
|
|
|
49309
50091
|
// src/commands/bot.ts
|
|
49310
|
-
import { join as
|
|
50092
|
+
import { join as join15 } from "path";
|
|
49311
50093
|
init_dist3();
|
|
49312
50094
|
init_commander();
|
|
49313
50095
|
|
|
@@ -49419,8 +50201,17 @@ var botHarness;
|
|
|
49419
50201
|
function loadBotHarness() {
|
|
49420
50202
|
botHarness ??= Promise.all([
|
|
49421
50203
|
Promise.resolve().then(() => (init_browser(), exports_browser)),
|
|
49422
|
-
Promise.resolve().then(() => (init_bot_collection(), exports_bot_collection))
|
|
49423
|
-
|
|
50204
|
+
Promise.resolve().then(() => (init_bot_collection(), exports_bot_collection)),
|
|
50205
|
+
Promise.resolve().then(() => (init_bot_record(), exports_bot_record)),
|
|
50206
|
+
Promise.resolve().then(() => (init_bot_codegen(), exports_bot_codegen)),
|
|
50207
|
+
Promise.resolve().then(() => exports_bot_replay)
|
|
50208
|
+
]).then(([browser, collection, record, codegen, replay]) => ({
|
|
50209
|
+
...browser,
|
|
50210
|
+
...collection,
|
|
50211
|
+
...record,
|
|
50212
|
+
...codegen,
|
|
50213
|
+
...replay
|
|
50214
|
+
}));
|
|
49424
50215
|
return botHarness;
|
|
49425
50216
|
}
|
|
49426
50217
|
async function runBotAction(load, action) {
|
|
@@ -49489,6 +50280,72 @@ async function botOpenAction(load, name, options) {
|
|
|
49489
50280
|
consoleOutput.write(`${result.name} closed`);
|
|
49490
50281
|
});
|
|
49491
50282
|
}
|
|
50283
|
+
async function botRecordAction(load, name, options) {
|
|
50284
|
+
let signal;
|
|
50285
|
+
await runBotAction(load, async (harness) => {
|
|
50286
|
+
const result = await harness.recordBotSession(name, {
|
|
50287
|
+
...options.out === undefined ? {} : { out: options.out },
|
|
50288
|
+
...options.includeText === true ? { includeText: true } : {},
|
|
50289
|
+
...options.url === undefined ? {} : { defaultUrl: options.url }
|
|
50290
|
+
});
|
|
50291
|
+
signal = result.signal;
|
|
50292
|
+
consoleOutput.write(`${result.out} ${result.stepCount} steps ${result.redacted ? "redacted" : "verbatim"}`);
|
|
50293
|
+
});
|
|
50294
|
+
if (signal !== undefined) {
|
|
50295
|
+
throw new CommanderError(signal === "SIGINT" ? 130 : 143, "kk.bot.interrupted", `recording ended by ${signal}`);
|
|
50296
|
+
}
|
|
50297
|
+
}
|
|
50298
|
+
async function botCodegenAction(load, transcriptPath, options) {
|
|
50299
|
+
await runBotAction(load, async (harness) => {
|
|
50300
|
+
const transcript = await harness.readTranscript(transcriptPath, {
|
|
50301
|
+
...options.allowUnredacted === true ? { allowUnredacted: true } : {}
|
|
50302
|
+
});
|
|
50303
|
+
const { source, warnings } = harness.generateRail(transcript, {
|
|
50304
|
+
plugin: options.plugin,
|
|
50305
|
+
operation: options.operation,
|
|
50306
|
+
transcriptPath,
|
|
50307
|
+
...options.receiptPath === undefined ? {} : { receiptPath: options.receiptPath }
|
|
50308
|
+
});
|
|
50309
|
+
for (const warning of warnings)
|
|
50310
|
+
consoleOutput.error(`kk.bot.codegen: ${warning}`);
|
|
50311
|
+
if (options.apply !== true) {
|
|
50312
|
+
consoleOutput.write(source);
|
|
50313
|
+
return;
|
|
50314
|
+
}
|
|
50315
|
+
const slug = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
50316
|
+
if (!slug.test(options.plugin) || !slug.test(options.operation)) {
|
|
50317
|
+
throw new harness.BotError("usage", "--plugin and --operation must each be a lowercase slug");
|
|
50318
|
+
}
|
|
50319
|
+
const pluginDir = join15("plugins", "publishings", options.plugin);
|
|
50320
|
+
if (!await createNodeFileSystem().exists(join15(pluginDir, "plugin.json"))) {
|
|
50321
|
+
throw new harness.BotError("usage", `no publish plugin at ${pluginDir} \u2014 run --apply from the repo root`);
|
|
50322
|
+
}
|
|
50323
|
+
const target = join15(pluginDir, "src", `${options.operation}-rail.generated.ts`);
|
|
50324
|
+
if (await createNodeFileSystem().exists(target)) {
|
|
50325
|
+
throw new harness.BotError("usage", `${target} already exists \u2014 promoting a generated rail is a by-hand edit`);
|
|
50326
|
+
}
|
|
50327
|
+
writeFileBytes(target, new TextEncoder().encode(source));
|
|
50328
|
+
consoleOutput.write(`${target} written`);
|
|
50329
|
+
});
|
|
50330
|
+
}
|
|
50331
|
+
async function botReplayAction(load, name, transcriptPath, options) {
|
|
50332
|
+
await runBotAction(load, async (harness) => {
|
|
50333
|
+
const transcript = await harness.readTranscript(transcriptPath, {
|
|
50334
|
+
...options.allowUnredacted === true ? { allowUnredacted: true } : {}
|
|
50335
|
+
});
|
|
50336
|
+
const { result, replayPath } = await harness.replayBot(name, transcript, {
|
|
50337
|
+
...options.submit === true ? { submit: true } : {},
|
|
50338
|
+
...options.submitText === undefined ? {} : { submitText: options.submitText },
|
|
50339
|
+
...options.output === undefined ? {} : { outDir: options.output },
|
|
50340
|
+
...options.file === undefined ? {} : { filePath: options.file }
|
|
50341
|
+
});
|
|
50342
|
+
consoleOutput.write(JSON.stringify({ ...result, replayPath }, null, 2));
|
|
50343
|
+
const failed = result.rows.find((row) => !row.ok && row.skipped !== "submit");
|
|
50344
|
+
if (failed !== undefined) {
|
|
50345
|
+
throw new harness.BotError("browser", `replay stopped at step ${failed.step}: ${failed.detail ?? "unresolved"}`);
|
|
50346
|
+
}
|
|
50347
|
+
});
|
|
50348
|
+
}
|
|
49492
50349
|
function collectHeader(value, previous) {
|
|
49493
50350
|
return [...previous ?? [], value];
|
|
49494
50351
|
}
|
|
@@ -49598,7 +50455,7 @@ async function botPlanAction(load, name, planPath, options) {
|
|
|
49598
50455
|
const sanitizedArtifacts = [];
|
|
49599
50456
|
for (const [index, artifact] of result.artifacts.entries()) {
|
|
49600
50457
|
const safeName = `${String(index).padStart(2, "0")}-${artifact.id.replace(/[^A-Za-z0-9_-]/g, "-")}.txt`;
|
|
49601
|
-
const filePath =
|
|
50458
|
+
const filePath = join15(options.output, safeName);
|
|
49602
50459
|
await fs.writeFile(filePath, artifact.body);
|
|
49603
50460
|
harness.chmod(filePath, 384);
|
|
49604
50461
|
sanitizedArtifacts.push({
|
|
@@ -49615,7 +50472,7 @@ async function botPlanAction(load, name, planPath, options) {
|
|
|
49615
50472
|
steps: result.steps,
|
|
49616
50473
|
artifacts: sanitizedArtifacts
|
|
49617
50474
|
};
|
|
49618
|
-
const resultPath =
|
|
50475
|
+
const resultPath = join15(options.output, "result.json");
|
|
49619
50476
|
await fs.writeFile(resultPath, JSON.stringify(summary, null, 2));
|
|
49620
50477
|
harness.chmod(resultPath, 384);
|
|
49621
50478
|
consoleOutput.write(JSON.stringify(summary, null, 2));
|
|
@@ -49633,8 +50490,11 @@ function registerBotCommand(program, deps = {}) {
|
|
|
49633
50490
|
bot.command("open").description("Open a named bot's saved page headed until the browser closes").argument("<name>", "Bot name").option("--login", "Reauthenticate first, then reopen the saved page for interaction").action((name, options) => botOpenAction(load, name, options));
|
|
49634
50491
|
const exec = bot.command("exec").description("Send one request with a named bot's cached cookie session (curl option subset)").argument("<name>", "Bot name").argument("<url>", "Request URL (http/https, no credentials; sent as given, query kept)").option("-X, --request <method>", "HTTP method (default GET, or POST when -d is given)").option("-H, --header <header>", 'Request header "Name: value" (repeatable)', collectHeader).option("-d, --data <data>", "Request body: a literal, or @file read raw").option("-o, --output <file>", "Write the response body to a file instead of stdout").option("-i, --include", "Include the status line and response headers before the body (stdout or the -o file)").option("-L, --location", "Follow redirects (default: return the 3xx response as-is)").option("-f, --fail", "Exit 1 without the body when the status is 400 or above").option("-m, --max-time <seconds>", "Whole-request timeout in seconds (default: Playwright 30s)").action((name, url, options) => botExecAction(load, name, url, options));
|
|
49635
50492
|
const plan = bot.command("plan").description("Execute a declarative collection plan with a named bot session").argument("<name>", "Bot name").argument("<plan>", "Path to plan JSON file").option("-o, --output <dir>", "Directory to write captured artifact bodies (0600 mode)").option("-m, --max-time <seconds>", "Whole-run timeout in seconds (default: 120s, max: 600s)").action((name, planPath, options) => botPlanAction(load, name, planPath, options));
|
|
50493
|
+
const record = bot.command("record").description("Record an operator session with a named bot into a transcript").argument("<name>", "Bot name").option("-o, --out <file>", "Transcript path (default .spur/run/bot-record-<bot>-<stamp>.json)").option("--include-text", "Keep typed text verbatim instead of a length marker").option("--url <url>", "Start page when the bot has no saved default page").action((name, options) => botRecordAction(load, name, options));
|
|
50494
|
+
const codegen = bot.command("codegen").description("Emit a rail skeleton from a recorded transcript").argument("<transcript>", "Transcript JSON path").requiredOption("--plugin <name>", "Target publish plugin name under plugins/publishings/").requiredOption("--operation <op>", "Rail operation slug (the runner is run<Operation>)").option("--apply", "Write <operation>-rail.generated.ts beside the plugin instead of stdout").option("--receipt-path <path>", "Dot path of the publish id inside the receipt body").option("--allow-unredacted", "Accept a transcript recorded with --include-text").action((transcriptPath, options) => botCodegenAction(load, transcriptPath, options));
|
|
50495
|
+
const replay = bot.command("replay").description("Replay a transcript headed, stopping before the submit step by default").argument("<name>", "Bot name").argument("<transcript>", "Transcript JSON path").option("--submit", "Execute the submit step instead of stopping before it").option("--submit-text <text>", "Text of the click that submits (default: the last click)").option("-o, --output <dir>", "Evidence directory (default .spur/run/bot-replay-<bot>)").option("--file <path>", "Local file a recorded file step re-selects").option("--allow-unredacted", "Accept a transcript recorded with --include-text").action((name, transcriptPath, options) => botReplayAction(load, name, transcriptPath, options));
|
|
49636
50496
|
bot.hook("preSubcommand", (_parent, subcommand) => {
|
|
49637
|
-
if (subcommand === exec || subcommand === plan) {
|
|
50497
|
+
if (subcommand === exec || subcommand === plan || subcommand === record || subcommand === codegen || subcommand === replay) {
|
|
49638
50498
|
subcommand.exitOverride((error) => {
|
|
49639
50499
|
throw error.exitCode === 1 ? new CommanderError(2, error.code, error.message) : error;
|
|
49640
50500
|
});
|
|
@@ -49647,22 +50507,22 @@ init_dist3();
|
|
|
49647
50507
|
init_dist();
|
|
49648
50508
|
init_commander();
|
|
49649
50509
|
import { homedir as homedir11 } from "os";
|
|
49650
|
-
import { basename as
|
|
50510
|
+
import { basename as basename5, dirname as dirname17, extname, isAbsolute as isAbsolute8, join as join32, resolve as resolve26 } from "path";
|
|
49651
50511
|
|
|
49652
50512
|
// src/content-types.ts
|
|
49653
50513
|
init_dist3();
|
|
49654
50514
|
init_zod();
|
|
49655
50515
|
import { createHash as createHash3 } from "crypto";
|
|
49656
|
-
import { join as
|
|
50516
|
+
import { join as join19, relative as relative3, resolve as resolve17, sep as sep2 } from "path";
|
|
49657
50517
|
|
|
49658
50518
|
// src/package-root.ts
|
|
49659
50519
|
init_dist3();
|
|
49660
|
-
import { dirname as dirname10, join as
|
|
50520
|
+
import { dirname as dirname10, join as join16, resolve as resolve14 } from "path";
|
|
49661
50521
|
var SHIPPED_DIR = "plugins/kk";
|
|
49662
50522
|
async function findPackageRoot(fs, start) {
|
|
49663
50523
|
let dir = resolve14(start);
|
|
49664
50524
|
for (;; ) {
|
|
49665
|
-
if (await fs.exists(
|
|
50525
|
+
if (await fs.exists(join16(dir, SHIPPED_DIR)))
|
|
49666
50526
|
return dir;
|
|
49667
50527
|
const parent = resolve14(dir, "..");
|
|
49668
50528
|
if (parent === dir)
|
|
@@ -49685,11 +50545,11 @@ init_dist3();
|
|
|
49685
50545
|
init_dist();
|
|
49686
50546
|
init_zod();
|
|
49687
50547
|
import { createHash as createHash2 } from "crypto";
|
|
49688
|
-
import { join as
|
|
50548
|
+
import { join as join18, resolve as resolve16 } from "path";
|
|
49689
50549
|
|
|
49690
50550
|
// src/fanout.ts
|
|
49691
50551
|
import { tmpdir } from "os";
|
|
49692
|
-
import { isAbsolute as isAbsolute6, join as
|
|
50552
|
+
import { isAbsolute as isAbsolute6, join as join17, resolve as resolve15 } from "path";
|
|
49693
50553
|
init_dist3();
|
|
49694
50554
|
init_dist();
|
|
49695
50555
|
var EXIT_FAILURE = 1;
|
|
@@ -49977,7 +50837,7 @@ async function pluginDispatch(target, contentPath, discovery, targetTimeoutMs) {
|
|
|
49977
50837
|
if (!await fs.exists(entryPath)) {
|
|
49978
50838
|
throw new Error(`Plugin entry script does not exist: ${entryPath}`);
|
|
49979
50839
|
}
|
|
49980
|
-
const outTmp =
|
|
50840
|
+
const outTmp = join17(tmpdir(), `kk-fanout-${target}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
|
|
49981
50841
|
try {
|
|
49982
50842
|
const proc = await spawnPluginEntryAsync({
|
|
49983
50843
|
entryPath,
|
|
@@ -50169,10 +51029,18 @@ var PublishPresetTargetSchema = object2({
|
|
|
50169
51029
|
modeSource: _enum2(["flag", "config", "preset"]).optional(),
|
|
50170
51030
|
options: record(string2(), unknown()).optional()
|
|
50171
51031
|
}).strict();
|
|
51032
|
+
var PublishPresetOverrideSchema = object2({
|
|
51033
|
+
plugin: string2().min(1),
|
|
51034
|
+
operation: string2().min(1).optional(),
|
|
51035
|
+
mode: _enum2(["off", "dummy", "draft", "live"]),
|
|
51036
|
+
reason: string2().min(1),
|
|
51037
|
+
until: string2().min(1).optional()
|
|
51038
|
+
}).strict();
|
|
50172
51039
|
var PublishPresetSchema = object2({
|
|
50173
51040
|
schemaVersion: literal(1).default(1),
|
|
50174
51041
|
name: string2().min(1),
|
|
50175
|
-
targets: array(PublishPresetTargetSchema).min(1)
|
|
51042
|
+
targets: array(PublishPresetTargetSchema).min(1),
|
|
51043
|
+
overrides: array(PublishPresetOverrideSchema).optional()
|
|
50176
51044
|
}).strict();
|
|
50177
51045
|
var SLUG_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
50178
51046
|
async function resolveDefaultPackageRoot(fs) {
|
|
@@ -50224,16 +51092,16 @@ function expandHome3(value, homeDir) {
|
|
|
50224
51092
|
if (value === "~" || value === "$HOME")
|
|
50225
51093
|
return homeDir;
|
|
50226
51094
|
if (value.startsWith("~/"))
|
|
50227
|
-
return
|
|
51095
|
+
return join18(homeDir, value.slice(2));
|
|
50228
51096
|
if (value.startsWith("$HOME/"))
|
|
50229
|
-
return
|
|
51097
|
+
return join18(homeDir, value.slice("$HOME/".length));
|
|
50230
51098
|
return value;
|
|
50231
51099
|
}
|
|
50232
51100
|
function resolveConfigPath(env, homeDir) {
|
|
50233
51101
|
const explicit = env.KK_CONFIG;
|
|
50234
51102
|
if (explicit !== undefined && explicit.trim() !== "")
|
|
50235
51103
|
return expandHome3(explicit.trim(), homeDir);
|
|
50236
|
-
return
|
|
51104
|
+
return join18(homeDir, ".config", "kk", "config.yaml");
|
|
50237
51105
|
}
|
|
50238
51106
|
async function sendRows(options) {
|
|
50239
51107
|
const fs = options.fs ?? createNodeFileSystem();
|
|
@@ -50243,7 +51111,7 @@ async function sendRows(options) {
|
|
|
50243
51111
|
const sameDigest = (priorDigest, digest) => priorDigest !== undefined && digest !== undefined && priorDigest === digest;
|
|
50244
51112
|
for (const row of rows) {
|
|
50245
51113
|
const startedAt = new Date().toISOString();
|
|
50246
|
-
const targetReceiptPath =
|
|
51114
|
+
const targetReceiptPath = join18(receiptsDir, `${row.key}.json`);
|
|
50247
51115
|
let reattempt = false;
|
|
50248
51116
|
let payloadPath = row.payloadPath;
|
|
50249
51117
|
let preparedError;
|
|
@@ -50304,11 +51172,14 @@ async function sendRows(options) {
|
|
|
50304
51172
|
reattempt = true;
|
|
50305
51173
|
} else {
|
|
50306
51174
|
const mayAlreadyBeLive = (prior.status === "uncertain" || prior.effect === "unknown") && (row.mode === "live" || prior.mode === "live");
|
|
50307
|
-
if (mayAlreadyBeLive) {
|
|
51175
|
+
if (mayAlreadyBeLive && options.confirmNone !== true) {
|
|
50308
51176
|
echoError(`${label}: ${row.key} has an unknown-effect live receipt (may already be published) \u2014 resolve it before resending; skipped`);
|
|
50309
51177
|
result.skipped.push(row.key);
|
|
50310
51178
|
continue;
|
|
50311
51179
|
}
|
|
51180
|
+
if (mayAlreadyBeLive) {
|
|
51181
|
+
echoError(`${label}: ${row.key} re-attempted on the operator's confirmation that the unknown-effect attempt published nothing (--confirm-none)`);
|
|
51182
|
+
}
|
|
50312
51183
|
reattempt = true;
|
|
50313
51184
|
}
|
|
50314
51185
|
}
|
|
@@ -50351,7 +51222,7 @@ async function sendRows(options) {
|
|
|
50351
51222
|
await options.onReceipt(receipt);
|
|
50352
51223
|
continue;
|
|
50353
51224
|
}
|
|
50354
|
-
const outPath =
|
|
51225
|
+
const outPath = join18(publishDir, `fanout-result.${row.key}${retry ? ".retry" : ""}.json`);
|
|
50355
51226
|
if (await fs.exists(outPath)) {
|
|
50356
51227
|
let staleFailure = false;
|
|
50357
51228
|
if (!reattempt) {
|
|
@@ -50489,11 +51360,11 @@ function mergeType(base, override) {
|
|
|
50489
51360
|
return ContentTypeSchema.parse(candidate);
|
|
50490
51361
|
}
|
|
50491
51362
|
async function hashSkill(skillDir, fs) {
|
|
50492
|
-
const skillFile =
|
|
51363
|
+
const skillFile = join19(skillDir, "SKILL.md");
|
|
50493
51364
|
if (!await fs.exists(skillFile))
|
|
50494
51365
|
throw new ContentTypeSkillMissingError(skillFile);
|
|
50495
51366
|
const hash = createHash3("sha256");
|
|
50496
|
-
const referencesDir =
|
|
51367
|
+
const referencesDir = join19(skillDir, "references");
|
|
50497
51368
|
const allFiles = await walkDir(skillDir, fs);
|
|
50498
51369
|
const paths = [
|
|
50499
51370
|
skillFile,
|
|
@@ -50562,19 +51433,19 @@ function resolveRun(input) {
|
|
|
50562
51433
|
throw new Error("--slug is required for article content and must be a lowercase slug");
|
|
50563
51434
|
}
|
|
50564
51435
|
const run = input.type === "news" ? runDate : dated ? `${runDate ?? laDate(input.now ?? new Date)}-${input.slug}` : input.slug;
|
|
50565
|
-
return { workDir: resolve17(input.workDir ??
|
|
51436
|
+
return { workDir: resolve17(input.workDir ?? join19(input.worksDir, workflow, run)), run, workflow };
|
|
50566
51437
|
}
|
|
50567
51438
|
|
|
50568
51439
|
// src/itc-stage.ts
|
|
50569
51440
|
import { createHash as createHash8 } from "crypto";
|
|
50570
|
-
import { join as
|
|
51441
|
+
import { join as join24 } from "path";
|
|
50571
51442
|
init_dist3();
|
|
50572
51443
|
init_dist();
|
|
50573
51444
|
|
|
50574
51445
|
// src/itc-config.ts
|
|
50575
51446
|
init_dist3();
|
|
50576
51447
|
import { createHash as createHash4 } from "crypto";
|
|
50577
|
-
import { dirname as dirname11, isAbsolute as isAbsolute7, join as
|
|
51448
|
+
import { dirname as dirname11, isAbsolute as isAbsolute7, join as join20, resolve as resolve18 } from "path";
|
|
50578
51449
|
var ARTICLE_WORKFLOW_BLOCK = "kk-article-generate";
|
|
50579
51450
|
var ITC_WORKFLOW_BLOCK = "kk-itc";
|
|
50580
51451
|
|
|
@@ -50996,18 +51867,18 @@ function resolveItcWorkspace(options, topic, input = {}) {
|
|
|
50996
51867
|
dated: input.runDate !== undefined
|
|
50997
51868
|
};
|
|
50998
51869
|
}
|
|
50999
|
-
const leaf = options.runDate !== null ?
|
|
51000
|
-
return { workDir:
|
|
51870
|
+
const leaf = options.runDate !== null ? join20(slug, options.runDate) : slug;
|
|
51871
|
+
return { workDir: join20(options.worksRoot, "kk-itc", leaf), topicName: slug, dated: options.runDate !== null };
|
|
51001
51872
|
}
|
|
51002
51873
|
async function writeItcOptionsSnapshot(workDir, options, fs = createNodeFileSystem()) {
|
|
51003
|
-
const path =
|
|
51874
|
+
const path = join20(workDir, "itc-options.json");
|
|
51004
51875
|
await fs.ensureDir(workDir);
|
|
51005
51876
|
await fs.writeFile(path, `${JSON.stringify(options, null, 2)}
|
|
51006
51877
|
`);
|
|
51007
51878
|
return path;
|
|
51008
51879
|
}
|
|
51009
51880
|
async function verifyItcOptionsSnapshot(workDir, options, fs = createNodeFileSystem()) {
|
|
51010
|
-
const path =
|
|
51881
|
+
const path = join20(workDir, "itc-options.json");
|
|
51011
51882
|
if (!await fs.exists(path))
|
|
51012
51883
|
return { ok: true };
|
|
51013
51884
|
let saved;
|
|
@@ -51207,7 +52078,7 @@ async function itcDecision(request, fs = createNodeFileSystem(), executor = new
|
|
|
51207
52078
|
}
|
|
51208
52079
|
|
|
51209
52080
|
// src/itc-plan.ts
|
|
51210
|
-
import { join as
|
|
52081
|
+
import { join as join21, resolve as resolve19 } from "path";
|
|
51211
52082
|
init_dist3();
|
|
51212
52083
|
init_zod();
|
|
51213
52084
|
var ItcTargetsOriginSchema = _enum2([
|
|
@@ -51341,7 +52212,7 @@ async function resolveItcTargets(input, fs = createNodeFileSystem()) {
|
|
|
51341
52212
|
};
|
|
51342
52213
|
}
|
|
51343
52214
|
async function hasCoverImage(fs, workDir) {
|
|
51344
|
-
const dir =
|
|
52215
|
+
const dir = join21(workDir, "4-illustrations");
|
|
51345
52216
|
if (!await fs.exists(dir))
|
|
51346
52217
|
return false;
|
|
51347
52218
|
try {
|
|
@@ -51352,7 +52223,7 @@ async function hasCoverImage(fs, workDir) {
|
|
|
51352
52223
|
}
|
|
51353
52224
|
}
|
|
51354
52225
|
async function hasOrderedImages(fs, workDir) {
|
|
51355
|
-
const path =
|
|
52226
|
+
const path = join21(workDir, "4-publish", "content.json");
|
|
51356
52227
|
if (!await fs.exists(path))
|
|
51357
52228
|
return false;
|
|
51358
52229
|
try {
|
|
@@ -51469,13 +52340,13 @@ async function buildItcPublishPlan(request, plugins, fs = createNodeFileSystem()
|
|
|
51469
52340
|
|
|
51470
52341
|
// src/itc-publish.ts
|
|
51471
52342
|
import { createHash as createHash7 } from "crypto";
|
|
51472
|
-
import { join as
|
|
52343
|
+
import { join as join23 } from "path";
|
|
51473
52344
|
init_dist3();
|
|
51474
52345
|
init_dist();
|
|
51475
52346
|
|
|
51476
52347
|
// src/itc-topic.ts
|
|
51477
52348
|
import { createHash as createHash6 } from "crypto";
|
|
51478
|
-
import { join as
|
|
52349
|
+
import { join as join22, resolve as resolve20 } from "path";
|
|
51479
52350
|
init_dist3();
|
|
51480
52351
|
init_dist();
|
|
51481
52352
|
init_zod();
|
|
@@ -51516,7 +52387,7 @@ async function resolveTopicProfilePath(fs, topic, customPath) {
|
|
|
51516
52387
|
if (customPath !== undefined && await fs.exists(customPath)) {
|
|
51517
52388
|
return customPath;
|
|
51518
52389
|
}
|
|
51519
|
-
const candidate =
|
|
52390
|
+
const candidate = join22(await resolvePackageRoot(fs), "plugins/kk/decisions/extract", `${topic}.yaml`);
|
|
51520
52391
|
if (await fs.exists(candidate))
|
|
51521
52392
|
return candidate;
|
|
51522
52393
|
throw new Error(`no profile for topic '${topic}': expected plugins/kk/decisions/extract/${topic}.yaml under the package root (cwd or script tree)`);
|
|
@@ -51586,9 +52457,9 @@ async function itcTopicExtract(request, fs = createNodeFileSystem()) {
|
|
|
51586
52457
|
poolDigest,
|
|
51587
52458
|
...request.refreshRun?.runId ? { collectRunId: request.refreshRun.runId } : {}
|
|
51588
52459
|
};
|
|
51589
|
-
await fs.writeFile(
|
|
52460
|
+
await fs.writeFile(join22(request.intakeDir, "topic-pool.json"), `${JSON.stringify(docs, null, 2)}
|
|
51590
52461
|
`);
|
|
51591
|
-
await fs.writeFile(
|
|
52462
|
+
await fs.writeFile(join22(request.intakeDir, "topic-pool-manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
51592
52463
|
`);
|
|
51593
52464
|
return { count: docs.length, poolDigest };
|
|
51594
52465
|
}
|
|
@@ -51611,9 +52482,9 @@ var ItcTopicValidateRequestSchema = object2({
|
|
|
51611
52482
|
parentRunId: string2().min(1)
|
|
51612
52483
|
});
|
|
51613
52484
|
async function itcTopicValidate(request, fs = createNodeFileSystem()) {
|
|
51614
|
-
const manifestPath =
|
|
51615
|
-
const poolPath =
|
|
51616
|
-
const candidatesPath =
|
|
52485
|
+
const manifestPath = join22(request.intakeDir, "topic-pool-manifest.json");
|
|
52486
|
+
const poolPath = join22(request.intakeDir, "topic-pool.json");
|
|
52487
|
+
const candidatesPath = join22(request.intakeDir, "topic-candidates.json");
|
|
51617
52488
|
if (!await fs.exists(manifestPath) || !await fs.exists(poolPath)) {
|
|
51618
52489
|
throw new Error(`topic pool artifacts not found in ${request.intakeDir}`);
|
|
51619
52490
|
}
|
|
@@ -51657,7 +52528,7 @@ async function itcTopicValidate(request, fs = createNodeFileSystem()) {
|
|
|
51657
52528
|
}
|
|
51658
52529
|
}
|
|
51659
52530
|
}
|
|
51660
|
-
await fs.writeFile(
|
|
52531
|
+
await fs.writeFile(join22(request.intakeDir, ".topic-candidates-valid"), `${new Date().toISOString()}
|
|
51661
52532
|
`);
|
|
51662
52533
|
return { valid: true };
|
|
51663
52534
|
}
|
|
@@ -51670,9 +52541,9 @@ var ItcTopicSelectRequestSchema = object2({
|
|
|
51670
52541
|
});
|
|
51671
52542
|
async function itcTopicSelect(request, fs = createNodeFileSystem()) {
|
|
51672
52543
|
await itcTopicValidate(request, fs);
|
|
51673
|
-
const manifestPath =
|
|
51674
|
-
const poolPath =
|
|
51675
|
-
const candidatesPath =
|
|
52544
|
+
const manifestPath = join22(request.intakeDir, "topic-pool-manifest.json");
|
|
52545
|
+
const poolPath = join22(request.intakeDir, "topic-pool.json");
|
|
52546
|
+
const candidatesPath = join22(request.intakeDir, "topic-candidates.json");
|
|
51676
52547
|
if (!await fs.exists(manifestPath) || !await fs.exists(poolPath) || !await fs.exists(candidatesPath)) {
|
|
51677
52548
|
throw new Error(`intake artifacts missing in ${request.intakeDir}`);
|
|
51678
52549
|
}
|
|
@@ -51685,7 +52556,7 @@ async function itcTopicSelect(request, fs = createNodeFileSystem()) {
|
|
|
51685
52556
|
}
|
|
51686
52557
|
const selectedDocSet = new Set(candidate.itemIds);
|
|
51687
52558
|
const selectedDocs = poolDocs.filter((d) => selectedDocSet.has(d.id));
|
|
51688
|
-
const selectedDocsPath =
|
|
52559
|
+
const selectedDocsPath = join22(request.intakeDir, "selected-docs.json");
|
|
51689
52560
|
await fs.writeFile(selectedDocsPath, `${JSON.stringify(selectedDocs, null, 2)}
|
|
51690
52561
|
`);
|
|
51691
52562
|
const chosenSource = {
|
|
@@ -51699,7 +52570,7 @@ async function itcTopicSelect(request, fs = createNodeFileSystem()) {
|
|
|
51699
52570
|
itemIds: candidate.itemIds,
|
|
51700
52571
|
selectedDocsPath
|
|
51701
52572
|
};
|
|
51702
|
-
await fs.writeFile(
|
|
52573
|
+
await fs.writeFile(join22(request.intakeDir, "chosen-source.json"), `${JSON.stringify(chosenSource, null, 2)}
|
|
51703
52574
|
`);
|
|
51704
52575
|
const storePath = await resolveStorePath(resolveKkConfigPath2(), request.dbPath);
|
|
51705
52576
|
const store = await openStore({ path: storePath });
|
|
@@ -51738,7 +52609,7 @@ async function itcSelectionSettle(request, fs = createNodeFileSystem()) {
|
|
|
51738
52609
|
const storePath = await resolveStorePath(resolveKkConfigPath2(), request.dbPath);
|
|
51739
52610
|
if (request.outcome === "published") {
|
|
51740
52611
|
let itemIds;
|
|
51741
|
-
const chosenSourcePath =
|
|
52612
|
+
const chosenSourcePath = join22(request.intakeDir, "chosen-source.json");
|
|
51742
52613
|
if (await fs.exists(chosenSourcePath)) {
|
|
51743
52614
|
try {
|
|
51744
52615
|
const chosen = JSON.parse(await fs.readFile(chosenSourcePath));
|
|
@@ -51768,7 +52639,7 @@ async function itcSelectionSettle(request, fs = createNodeFileSystem()) {
|
|
|
51768
52639
|
guidance: "reconcile status manually via kk store mark-published or kk store release"
|
|
51769
52640
|
};
|
|
51770
52641
|
await fs.ensureDir(request.intakeDir);
|
|
51771
|
-
await fs.writeFile(
|
|
52642
|
+
await fs.writeFile(join22(request.intakeDir, ".selection-reconcile.json"), `${JSON.stringify(reconcileInfo, null, 2)}
|
|
51772
52643
|
`);
|
|
51773
52644
|
return { settled: "retained", action: "reconcile_retained" };
|
|
51774
52645
|
}
|
|
@@ -51832,11 +52703,11 @@ async function runItcTopicStage(stageName, args, fs = createNodeFileSystem()) {
|
|
|
51832
52703
|
|
|
51833
52704
|
// src/itc-publish.ts
|
|
51834
52705
|
async function findCover(fs, workDir) {
|
|
51835
|
-
const dir =
|
|
52706
|
+
const dir = join23(workDir, "4-illustrations");
|
|
51836
52707
|
if (!await fs.exists(dir))
|
|
51837
52708
|
return;
|
|
51838
52709
|
const cover = (await fs.readDir(dir)).find((file) => file.startsWith("cover."));
|
|
51839
|
-
return cover ?
|
|
52710
|
+
return cover ? join23(dir, cover) : undefined;
|
|
51840
52711
|
}
|
|
51841
52712
|
async function readFrontmatter(fs, path) {
|
|
51842
52713
|
if (!await fs.exists(path))
|
|
@@ -51869,7 +52740,7 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51869
52740
|
const snapshot = await readOptionsSnapshot(fs, workDir);
|
|
51870
52741
|
const [targetsArg = "", sourceLocale = "", liveArg = "", presetArg = ""] = snapshot ? [snapshot.publishTargets, snapshot.sourceLocale, String(snapshot.publishLive), ""] : positional;
|
|
51871
52742
|
const live = liveArg === "true";
|
|
51872
|
-
const draftPath =
|
|
52743
|
+
const draftPath = join23(workDir, "3-draft-draft-article.md");
|
|
51873
52744
|
if (!await fs.exists(draftPath)) {
|
|
51874
52745
|
echoError(`final draft not found: ${draftPath}`);
|
|
51875
52746
|
return 1;
|
|
@@ -51889,10 +52760,10 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51889
52760
|
return 1;
|
|
51890
52761
|
}
|
|
51891
52762
|
const content = { title, format: "markdown", body };
|
|
51892
|
-
const outlinePath =
|
|
52763
|
+
const outlinePath = join23(workDir, "2-outline", "outline-approved.md");
|
|
51893
52764
|
if (await fs.exists(outlinePath))
|
|
51894
52765
|
content.outline = (await fs.readFile(outlinePath)).trim();
|
|
51895
|
-
const docsPath =
|
|
52766
|
+
const docsPath = join23(workDir, "docs.json");
|
|
51896
52767
|
if (await fs.exists(docsPath)) {
|
|
51897
52768
|
try {
|
|
51898
52769
|
const docs = JSON.parse(await fs.readFile(docsPath));
|
|
@@ -51909,7 +52780,7 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51909
52780
|
const cover = await findCover(fs, workDir);
|
|
51910
52781
|
if (cover)
|
|
51911
52782
|
metadata.coverImage = cover;
|
|
51912
|
-
const brief = await readFrontmatter(fs,
|
|
52783
|
+
const brief = await readFrontmatter(fs, join23(workDir, "brief.md"));
|
|
51913
52784
|
if (brief.tags)
|
|
51914
52785
|
metadata.tags = splitList(brief.tags);
|
|
51915
52786
|
if (brief.keywords)
|
|
@@ -51917,9 +52788,9 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51917
52788
|
if (brief.description)
|
|
51918
52789
|
metadata.description = brief.description;
|
|
51919
52790
|
content.metadata = metadata;
|
|
51920
|
-
const publishDir =
|
|
52791
|
+
const publishDir = join23(workDir, "4-publish");
|
|
51921
52792
|
await fs.ensureDir(publishDir);
|
|
51922
|
-
await fs.writeFile(
|
|
52793
|
+
await fs.writeFile(join23(publishDir, "content.json"), `${JSON.stringify(content, null, 2)}
|
|
51923
52794
|
`);
|
|
51924
52795
|
const fromLaunch = snapshot?.publishPresetSource === "launch" ? snapshot.publishPreset : null;
|
|
51925
52796
|
const fromConfig = snapshot?.publishPresetSource === "config" ? snapshot.publishPreset : null;
|
|
@@ -51946,7 +52817,7 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51946
52817
|
title: `${resolvedTargets.presetName}: ${resolvedTargets.targets.map((t) => t.plugin).join(", ")}`
|
|
51947
52818
|
}
|
|
51948
52819
|
],
|
|
51949
|
-
outPath:
|
|
52820
|
+
outPath: join23(workDir, "4-publish", "preset-decision.json")
|
|
51950
52821
|
}, fs);
|
|
51951
52822
|
if (decision.value !== "suggested")
|
|
51952
52823
|
resolvedTargets = { targets: [], origin: "none" };
|
|
@@ -51962,7 +52833,7 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51962
52833
|
browser: [],
|
|
51963
52834
|
targets: []
|
|
51964
52835
|
};
|
|
51965
|
-
await fs.writeFile(
|
|
52836
|
+
await fs.writeFile(join23(publishDir, "publish-plan.json"), `${JSON.stringify(emptyPlan, null, 2)}
|
|
51966
52837
|
`);
|
|
51967
52838
|
return 0;
|
|
51968
52839
|
}
|
|
@@ -51979,7 +52850,7 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51979
52850
|
};
|
|
51980
52851
|
try {
|
|
51981
52852
|
const plan = await buildItcPublishPlan(req, plugins, fs);
|
|
51982
|
-
const planPath =
|
|
52853
|
+
const planPath = join23(publishDir, "publish-plan.json");
|
|
51983
52854
|
await fs.writeFile(planPath, `${JSON.stringify(plan, null, 2)}
|
|
51984
52855
|
`);
|
|
51985
52856
|
for (const warning of plan.warnings ?? [])
|
|
@@ -51992,13 +52863,13 @@ async function itcMaterializePlan(args, fs = createNodeFileSystem()) {
|
|
|
51992
52863
|
}
|
|
51993
52864
|
}
|
|
51994
52865
|
async function readOptionsSnapshot(fs, workDir) {
|
|
51995
|
-
const path =
|
|
52866
|
+
const path = join23(workDir, "itc-options.json");
|
|
51996
52867
|
if (!await fs.exists(path))
|
|
51997
52868
|
return;
|
|
51998
52869
|
return JSON.parse(await fs.readFile(path));
|
|
51999
52870
|
}
|
|
52000
52871
|
async function prepareTargetPayloads(fs, workDir, plan, plugins) {
|
|
52001
|
-
const publishDir =
|
|
52872
|
+
const publishDir = join23(workDir, "4-publish");
|
|
52002
52873
|
if (!plan.targets || plan.targets.length === 0)
|
|
52003
52874
|
return plan;
|
|
52004
52875
|
const planned = new Set(plan.targets.map((t) => t.plugin));
|
|
@@ -52018,9 +52889,9 @@ async function prepareTargetPayloads(fs, workDir, plan, plugins) {
|
|
|
52018
52889
|
for (const target of plan.targets) {
|
|
52019
52890
|
const variantEntry = variants[target.variant];
|
|
52020
52891
|
const baseFile = variantEntry?.file ?? "content.json";
|
|
52021
|
-
let basePath =
|
|
52892
|
+
let basePath = join23(publishDir, baseFile);
|
|
52022
52893
|
if (!await fs.exists(basePath)) {
|
|
52023
|
-
basePath =
|
|
52894
|
+
basePath = join23(publishDir, "content.json");
|
|
52024
52895
|
}
|
|
52025
52896
|
if (!await fs.exists(basePath))
|
|
52026
52897
|
continue;
|
|
@@ -52037,7 +52908,7 @@ async function prepareTargetPayloads(fs, workDir, plan, plugins) {
|
|
|
52037
52908
|
}
|
|
52038
52909
|
};
|
|
52039
52910
|
const targetFileName = `content.${target.plugin}.json`;
|
|
52040
|
-
const targetFilePath =
|
|
52911
|
+
const targetFilePath = join23(publishDir, targetFileName);
|
|
52041
52912
|
const contentStr = `${JSON.stringify(isolatedContent, null, 2)}
|
|
52042
52913
|
`;
|
|
52043
52914
|
await fs.writeFile(targetFilePath, contentStr);
|
|
@@ -52047,7 +52918,7 @@ async function prepareTargetPayloads(fs, workDir, plan, plugins) {
|
|
|
52047
52918
|
written = true;
|
|
52048
52919
|
}
|
|
52049
52920
|
if (written) {
|
|
52050
|
-
await fs.writeFile(
|
|
52921
|
+
await fs.writeFile(join23(publishDir, "publish-plan.json"), `${JSON.stringify(plan, null, 2)}
|
|
52051
52922
|
`);
|
|
52052
52923
|
}
|
|
52053
52924
|
return plan;
|
|
@@ -52058,7 +52929,7 @@ async function itcCheckTargets(args, fs = createNodeFileSystem(), executor = new
|
|
|
52058
52929
|
echoError("usage: itc-check-targets <work_dir>");
|
|
52059
52930
|
return 1;
|
|
52060
52931
|
}
|
|
52061
|
-
const planPath =
|
|
52932
|
+
const planPath = join23(workDir, "4-publish/publish-plan.json");
|
|
52062
52933
|
if (!await fs.exists(planPath))
|
|
52063
52934
|
return 0;
|
|
52064
52935
|
let plan;
|
|
@@ -52091,8 +52962,8 @@ async function itcCheckTargets(args, fs = createNodeFileSystem(), executor = new
|
|
|
52091
52962
|
}
|
|
52092
52963
|
}
|
|
52093
52964
|
try {
|
|
52094
|
-
await fs.ensureDir(
|
|
52095
|
-
await fs.writeFile(
|
|
52965
|
+
await fs.ensureDir(join23(workDir, "4-publish"));
|
|
52966
|
+
await fs.writeFile(join23(workDir, "4-publish/check-targets.json"), `${JSON.stringify({ schemaVersion: 1, plugins: probes }, null, 2)}
|
|
52096
52967
|
`);
|
|
52097
52968
|
} catch (error) {
|
|
52098
52969
|
echoError(`itc-check-targets: cannot write probes: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -52107,8 +52978,8 @@ async function itcSendTargets(args, fs = createNodeFileSystem(), dispatch = runF
|
|
|
52107
52978
|
echoError("usage: itc-send-targets <work_dir> [--retry]");
|
|
52108
52979
|
return 1;
|
|
52109
52980
|
}
|
|
52110
|
-
const publishDir =
|
|
52111
|
-
const planPath =
|
|
52981
|
+
const publishDir = join23(workDir, "4-publish");
|
|
52982
|
+
const planPath = join23(publishDir, "publish-plan.json");
|
|
52112
52983
|
if (!await fs.exists(planPath))
|
|
52113
52984
|
return 0;
|
|
52114
52985
|
let plan = JSON.parse(await fs.readFile(planPath));
|
|
@@ -52116,7 +52987,7 @@ async function itcSendTargets(args, fs = createNodeFileSystem(), dispatch = runF
|
|
|
52116
52987
|
return 0;
|
|
52117
52988
|
const parentRunId = (await readOptionsSnapshot(fs, workDir))?.parentRunId;
|
|
52118
52989
|
if (!parentRunId) {
|
|
52119
|
-
echoError(`itc-send-targets: ${
|
|
52990
|
+
echoError(`itc-send-targets: ${join23(workDir, "itc-options.json")} has no parentRunId`);
|
|
52120
52991
|
return 1;
|
|
52121
52992
|
}
|
|
52122
52993
|
const { plugins } = discoverAllPlugins();
|
|
@@ -52126,11 +52997,11 @@ async function itcSendTargets(args, fs = createNodeFileSystem(), dispatch = runF
|
|
|
52126
52997
|
const entry = plan.variants?.[target.variant];
|
|
52127
52998
|
if (entry?.adapt !== true)
|
|
52128
52999
|
continue;
|
|
52129
|
-
if (await fs.exists(
|
|
53000
|
+
if (await fs.exists(join23(publishDir, entry.file)))
|
|
52130
53001
|
continue;
|
|
52131
53002
|
echoError(`itc-send-targets: variant ${target.variant} has no ${entry.file}; '${target.plugin}' receives the ${plan.sourceLocale} source article`);
|
|
52132
53003
|
}
|
|
52133
|
-
const receiptsDir =
|
|
53004
|
+
const receiptsDir = join23(publishDir, "receipts");
|
|
52134
53005
|
await fs.ensureDir(receiptsDir);
|
|
52135
53006
|
const planRaw = await fs.readFile(planPath);
|
|
52136
53007
|
const planDigest = createHash7("sha256").update(planRaw).digest("hex");
|
|
@@ -52139,7 +53010,7 @@ async function itcSendTargets(args, fs = createNodeFileSystem(), dispatch = runF
|
|
|
52139
53010
|
plugin: target.plugin,
|
|
52140
53011
|
profile: target.profile,
|
|
52141
53012
|
mode: target.mode,
|
|
52142
|
-
payloadPath:
|
|
53013
|
+
payloadPath: join23(workDir, target.payloadPath ?? `4-publish/content.${target.plugin}.json`),
|
|
52143
53014
|
transport: target.transport
|
|
52144
53015
|
}));
|
|
52145
53016
|
const outcome = await sendRows({
|
|
@@ -52163,12 +53034,12 @@ async function itcReconcileReceipts(args, fs = createNodeFileSystem()) {
|
|
|
52163
53034
|
echoError("usage: itc-reconcile-receipts <work_dir>");
|
|
52164
53035
|
return 1;
|
|
52165
53036
|
}
|
|
52166
|
-
const publishDir =
|
|
52167
|
-
const planPath =
|
|
53037
|
+
const publishDir = join23(workDir, "4-publish");
|
|
53038
|
+
const planPath = join23(publishDir, "publish-plan.json");
|
|
52168
53039
|
if (!await fs.exists(planPath))
|
|
52169
53040
|
return 0;
|
|
52170
53041
|
const plan = JSON.parse(await fs.readFile(planPath));
|
|
52171
|
-
const chosenPath =
|
|
53042
|
+
const chosenPath = join23(workDir, "chosen-source.json");
|
|
52172
53043
|
const chosen = await fs.exists(chosenPath) ? JSON.parse(await fs.readFile(chosenPath)) : undefined;
|
|
52173
53044
|
const settle = async (outcome) => {
|
|
52174
53045
|
if (chosen === undefined)
|
|
@@ -52185,10 +53056,10 @@ async function itcReconcileReceipts(args, fs = createNodeFileSystem()) {
|
|
|
52185
53056
|
await settle("author_only");
|
|
52186
53057
|
return 0;
|
|
52187
53058
|
}
|
|
52188
|
-
const receiptsDir =
|
|
53059
|
+
const receiptsDir = join23(publishDir, "receipts");
|
|
52189
53060
|
const receipts = [];
|
|
52190
53061
|
for (const target of plan.targets) {
|
|
52191
|
-
const rPath =
|
|
53062
|
+
const rPath = join23(receiptsDir, `${target.plugin}.json`);
|
|
52192
53063
|
if (!await fs.exists(rPath)) {
|
|
52193
53064
|
echoError(`itc-reconcile-receipts: missing receipt for target '${target.plugin}'`);
|
|
52194
53065
|
return 1;
|
|
@@ -52213,12 +53084,12 @@ async function itcExportSeo(args, fs = createNodeFileSystem()) {
|
|
|
52213
53084
|
echoError("usage: itc-export-seo <work_dir> [mode]");
|
|
52214
53085
|
return 1;
|
|
52215
53086
|
}
|
|
52216
|
-
const seoDir =
|
|
53087
|
+
const seoDir = join23(workDir, "seo");
|
|
52217
53088
|
await fs.ensureDir(seoDir);
|
|
52218
53089
|
if (mode === "off") {
|
|
52219
|
-
await fs.writeFile(
|
|
53090
|
+
await fs.writeFile(join23(seoDir, "prepublish-request.json"), `${JSON.stringify({ schemaVersion: 1, mode: "off", status: "not-assessed" }, null, 2)}
|
|
52220
53091
|
`);
|
|
52221
|
-
await fs.writeFile(
|
|
53092
|
+
await fs.writeFile(join23(seoDir, "published-pages.json"), `${JSON.stringify({ schemaVersion: 1, mode: "off", pages: [], status: "not-assessed" }, null, 2)}
|
|
52222
53093
|
`);
|
|
52223
53094
|
return 0;
|
|
52224
53095
|
}
|
|
@@ -52228,14 +53099,14 @@ async function itcExportSeo(args, fs = createNodeFileSystem()) {
|
|
|
52228
53099
|
status: "ready",
|
|
52229
53100
|
draftFile: "3-draft-draft-article.md"
|
|
52230
53101
|
};
|
|
52231
|
-
await fs.writeFile(
|
|
53102
|
+
await fs.writeFile(join23(seoDir, "prepublish-request.json"), `${JSON.stringify(prepublish, null, 2)}
|
|
52232
53103
|
`);
|
|
52233
|
-
const receiptsDir =
|
|
53104
|
+
const receiptsDir = join23(workDir, "4-publish/receipts");
|
|
52234
53105
|
const verifiedPages = [];
|
|
52235
53106
|
if (await fs.exists(receiptsDir)) {
|
|
52236
53107
|
for (const file of (await fs.readDir(receiptsDir)).filter((f) => f.endsWith(".json"))) {
|
|
52237
53108
|
try {
|
|
52238
|
-
const r = JSON.parse(await fs.readFile(
|
|
53109
|
+
const r = JSON.parse(await fs.readFile(join23(receiptsDir, file)));
|
|
52239
53110
|
if (r.mode === "live" && r.effect === "confirmed" && r.publicUrlVerified === true && r.url) {
|
|
52240
53111
|
verifiedPages.push({ plugin: r.plugin, url: r.url });
|
|
52241
53112
|
}
|
|
@@ -52249,7 +53120,7 @@ async function itcExportSeo(args, fs = createNodeFileSystem()) {
|
|
|
52249
53120
|
pages: verifiedPages,
|
|
52250
53121
|
...verifiedPages.length === 0 ? { reason: "no verified public live URLs available" } : {}
|
|
52251
53122
|
};
|
|
52252
|
-
await fs.writeFile(
|
|
53123
|
+
await fs.writeFile(join23(seoDir, "published-pages.json"), `${JSON.stringify(publishedPages, null, 2)}
|
|
52253
53124
|
`);
|
|
52254
53125
|
return 0;
|
|
52255
53126
|
}
|
|
@@ -52259,12 +53130,12 @@ async function itcReportSummary(args, fs = createNodeFileSystem()) {
|
|
|
52259
53130
|
echoError("usage: itc-report-summary <work_dir> [max_revisions]");
|
|
52260
53131
|
return 1;
|
|
52261
53132
|
}
|
|
52262
|
-
const reportDir =
|
|
53133
|
+
const reportDir = join23(workDir, "5-report");
|
|
52263
53134
|
await fs.ensureDir(reportDir);
|
|
52264
53135
|
let verdict = "PASS";
|
|
52265
53136
|
let confidence = null;
|
|
52266
53137
|
let outcome = "done";
|
|
52267
|
-
const verdictPath =
|
|
53138
|
+
const verdictPath = join23(workDir, ".itc-verdict.json");
|
|
52268
53139
|
const hasVerdict = await fs.exists(verdictPath);
|
|
52269
53140
|
if (hasVerdict) {
|
|
52270
53141
|
try {
|
|
@@ -52278,7 +53149,7 @@ async function itcReportSummary(args, fs = createNodeFileSystem()) {
|
|
|
52278
53149
|
}
|
|
52279
53150
|
}
|
|
52280
53151
|
let revisions = 0;
|
|
52281
|
-
const revPath =
|
|
53152
|
+
const revPath = join23(workDir, ".auto-revise-count");
|
|
52282
53153
|
if (await fs.exists(revPath)) {
|
|
52283
53154
|
try {
|
|
52284
53155
|
revisions = Number((await fs.readFile(revPath)).trim()) || 0;
|
|
@@ -52286,12 +53157,12 @@ async function itcReportSummary(args, fs = createNodeFileSystem()) {
|
|
|
52286
53157
|
revisions = 0;
|
|
52287
53158
|
}
|
|
52288
53159
|
}
|
|
52289
|
-
const receiptsDir =
|
|
53160
|
+
const receiptsDir = join23(workDir, "4-publish/receipts");
|
|
52290
53161
|
const receipts = [];
|
|
52291
53162
|
if (await fs.exists(receiptsDir)) {
|
|
52292
53163
|
for (const file of (await fs.readDir(receiptsDir)).filter((f) => f.endsWith(".json"))) {
|
|
52293
53164
|
try {
|
|
52294
|
-
const r = JSON.parse(await fs.readFile(
|
|
53165
|
+
const r = JSON.parse(await fs.readFile(join23(receiptsDir, file)));
|
|
52295
53166
|
receipts.push(r);
|
|
52296
53167
|
} catch {}
|
|
52297
53168
|
}
|
|
@@ -52299,7 +53170,7 @@ async function itcReportSummary(args, fs = createNodeFileSystem()) {
|
|
|
52299
53170
|
if (receipts.some((r) => r.status !== "succeeded")) {
|
|
52300
53171
|
outcome = "failed";
|
|
52301
53172
|
}
|
|
52302
|
-
const planPath =
|
|
53173
|
+
const planPath = join23(workDir, "4-publish/publish-plan.json");
|
|
52303
53174
|
let targetContract;
|
|
52304
53175
|
if (await fs.exists(planPath)) {
|
|
52305
53176
|
const planRaw = await fs.readFile(planPath);
|
|
@@ -52323,7 +53194,7 @@ async function itcReportSummary(args, fs = createNodeFileSystem()) {
|
|
|
52323
53194
|
...targetContract ? { targetContractFailure: targetContract } : {},
|
|
52324
53195
|
maxRevisions: Number(maxRevisions) || 2
|
|
52325
53196
|
};
|
|
52326
|
-
await fs.writeFile(
|
|
53197
|
+
await fs.writeFile(join23(reportDir, "report.json"), `${JSON.stringify(reportJson, null, 2)}
|
|
52327
53198
|
`);
|
|
52328
53199
|
const md = [
|
|
52329
53200
|
"# ITC Publication Run Report",
|
|
@@ -52341,7 +53212,7 @@ async function itcReportSummary(args, fs = createNodeFileSystem()) {
|
|
|
52341
53212
|
...receipts.map((r) => `- ${r.plugin} (${r.profile}): status=${r.status}, effect=${r.effect}`)
|
|
52342
53213
|
].join(`
|
|
52343
53214
|
`);
|
|
52344
|
-
await fs.writeFile(
|
|
53215
|
+
await fs.writeFile(join23(reportDir, "report.md"), `${md}
|
|
52345
53216
|
`);
|
|
52346
53217
|
return 0;
|
|
52347
53218
|
}
|
|
@@ -52354,13 +53225,13 @@ async function itcAuthorVerdict(args, fs = createNodeFileSystem()) {
|
|
|
52354
53225
|
const auto = process.env.KK_ITC_AUTO === "true";
|
|
52355
53226
|
const maxRevisions = Number(process.env.KK_ITC_MAX_REVISIONS ?? "2") || 2;
|
|
52356
53227
|
const readCount = async (name) => {
|
|
52357
|
-
const p =
|
|
53228
|
+
const p = join23(workDir, name);
|
|
52358
53229
|
if (!await fs.exists(p))
|
|
52359
53230
|
return 0;
|
|
52360
53231
|
const n = Number((await fs.readFile(p)).trim());
|
|
52361
53232
|
return Number.isFinite(n) ? n : 0;
|
|
52362
53233
|
};
|
|
52363
|
-
const verdictPath =
|
|
53234
|
+
const verdictPath = join23(workDir, ".itc-verdict.json");
|
|
52364
53235
|
let verdict = "";
|
|
52365
53236
|
let confidence = "";
|
|
52366
53237
|
if (await fs.exists(verdictPath)) {
|
|
@@ -52386,8 +53257,8 @@ async function itcAuthorVerdict(args, fs = createNodeFileSystem()) {
|
|
|
52386
53257
|
} else {
|
|
52387
53258
|
disposition = "fail";
|
|
52388
53259
|
}
|
|
52389
|
-
await fs.ensureDir(
|
|
52390
|
-
await fs.writeFile(
|
|
53260
|
+
await fs.ensureDir(join23(workDir, ".itc"));
|
|
53261
|
+
await fs.writeFile(join23(workDir, ".itc/disposition.txt"), `${disposition}
|
|
52391
53262
|
`);
|
|
52392
53263
|
return 0;
|
|
52393
53264
|
}
|
|
@@ -52484,9 +53355,9 @@ async function runItcPublishPlan(args, fs) {
|
|
|
52484
53355
|
try {
|
|
52485
53356
|
const { plugins } = discoverAllPlugins();
|
|
52486
53357
|
const plan = await buildItcPublishPlan(request, plugins, fs);
|
|
52487
|
-
const outDir =
|
|
53358
|
+
const outDir = join24(request.workDir, "4-publish");
|
|
52488
53359
|
await fs.ensureDir(outDir);
|
|
52489
|
-
await fs.writeFile(
|
|
53360
|
+
await fs.writeFile(join24(outDir, "publish-plan.json"), `${JSON.stringify(plan, null, 4)}
|
|
52490
53361
|
`);
|
|
52491
53362
|
for (const warning of plan.warnings ?? [])
|
|
52492
53363
|
echoError(`itc-publish-plan: ${warning}`);
|
|
@@ -52528,23 +53399,23 @@ async function runSlotDecision(args, fs) {
|
|
|
52528
53399
|
}
|
|
52529
53400
|
try {
|
|
52530
53401
|
if (mode === "--topic") {
|
|
52531
|
-
const candidatesPath =
|
|
53402
|
+
const candidatesPath = join24(dir, "topic-candidates.json");
|
|
52532
53403
|
const artifact = JSON.parse(await fs.readFile(candidatesPath));
|
|
52533
53404
|
const result = await itcDecision({
|
|
52534
53405
|
parentRunId,
|
|
52535
53406
|
decisionId: "kk-itc-topic-choice",
|
|
52536
53407
|
candidates: artifact.candidates.map((c) => ({ id: c.id, title: c.title, description: c.reason })),
|
|
52537
53408
|
evidenceFiles: [candidatesPath],
|
|
52538
|
-
outPath:
|
|
53409
|
+
outPath: join24(dir, "topic-decision.json")
|
|
52539
53410
|
}, fs);
|
|
52540
53411
|
echo(result.value);
|
|
52541
53412
|
return 0;
|
|
52542
53413
|
}
|
|
52543
|
-
const outlineDir =
|
|
53414
|
+
const outlineDir = join24(dir, "2-outline");
|
|
52544
53415
|
const candidates = [];
|
|
52545
53416
|
const evidenceFiles = [];
|
|
52546
53417
|
for (const id of ["a", "b", "c"]) {
|
|
52547
|
-
const file =
|
|
53418
|
+
const file = join24(outlineDir, `outline-option-${id}.md`);
|
|
52548
53419
|
if (!await fs.exists(file))
|
|
52549
53420
|
continue;
|
|
52550
53421
|
const heading = (await fs.readFile(file)).split(`
|
|
@@ -52554,18 +53425,18 @@ async function runSlotDecision(args, fs) {
|
|
|
52554
53425
|
}
|
|
52555
53426
|
if (candidates.length === 0)
|
|
52556
53427
|
throw new Error(`no outline options in ${outlineDir}`);
|
|
52557
|
-
evidenceFiles.push(
|
|
53428
|
+
evidenceFiles.push(join24(outlineDir, "outline-recommendation.json"));
|
|
52558
53429
|
const result = await itcDecision({
|
|
52559
53430
|
parentRunId,
|
|
52560
53431
|
decisionId: "kk-itc-outline-choice",
|
|
52561
53432
|
candidates,
|
|
52562
53433
|
evidenceFiles,
|
|
52563
|
-
outPath:
|
|
53434
|
+
outPath: join24(outlineDir, "outline-decision.json")
|
|
52564
53435
|
}, fs);
|
|
52565
53436
|
const pick = result.value === "defer" ? "" : result.value;
|
|
52566
53437
|
if (pick === "")
|
|
52567
53438
|
echoError(`itc-decision: outline choice deferred to the operator: ${result.reason}`);
|
|
52568
|
-
await fs.writeFile(
|
|
53439
|
+
await fs.writeFile(join24(outlineDir, ".auto-pick"), pick);
|
|
52569
53440
|
return 0;
|
|
52570
53441
|
} catch (err) {
|
|
52571
53442
|
echoError(`itc-decision: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -52578,7 +53449,7 @@ async function runItcAuthorComplete(args, fs) {
|
|
|
52578
53449
|
echoError("usage: itc-author-complete <work_dir> <parentRunId> [reviewMode]");
|
|
52579
53450
|
return 1;
|
|
52580
53451
|
}
|
|
52581
|
-
const draftPath =
|
|
53452
|
+
const draftPath = join24(workDir, "3-draft-draft-article.md");
|
|
52582
53453
|
if (!await fs.exists(draftPath)) {
|
|
52583
53454
|
echoError(`itc-author-complete: draft not found: ${draftPath}`);
|
|
52584
53455
|
return 1;
|
|
@@ -52589,7 +53460,7 @@ async function runItcAuthorComplete(args, fs) {
|
|
|
52589
53460
|
return 1;
|
|
52590
53461
|
}
|
|
52591
53462
|
const draftDigest = createHash8("sha256").update(draftText).digest("hex");
|
|
52592
|
-
const outlinePath =
|
|
53463
|
+
const outlinePath = join24(workDir, "2-outline/outline-approved.md");
|
|
52593
53464
|
if (!await fs.exists(outlinePath)) {
|
|
52594
53465
|
echoError(`itc-author-complete: approved outline not found: ${outlinePath}`);
|
|
52595
53466
|
return 1;
|
|
@@ -52600,7 +53471,7 @@ async function runItcAuthorComplete(args, fs) {
|
|
|
52600
53471
|
return 1;
|
|
52601
53472
|
}
|
|
52602
53473
|
const outlineDigest = createHash8("sha256").update(outlineText).digest("hex");
|
|
52603
|
-
const verdictPath =
|
|
53474
|
+
const verdictPath = join24(workDir, ".itc-verdict.json");
|
|
52604
53475
|
let judgeDigest = null;
|
|
52605
53476
|
let reviewMode = reviewModeArg === "manual" ? "manual" : "judged";
|
|
52606
53477
|
if (await fs.exists(verdictPath)) {
|
|
@@ -52625,7 +53496,7 @@ async function runItcAuthorComplete(args, fs) {
|
|
|
52625
53496
|
} else {
|
|
52626
53497
|
reviewMode = "manual";
|
|
52627
53498
|
}
|
|
52628
|
-
const runPath =
|
|
53499
|
+
const runPath = join24(workDir, ".itc/author-run.json");
|
|
52629
53500
|
let childRunId = `${parentRunId}-author`;
|
|
52630
53501
|
if (await fs.exists(runPath)) {
|
|
52631
53502
|
try {
|
|
@@ -52644,9 +53515,9 @@ async function runItcAuthorComplete(args, fs) {
|
|
|
52644
53515
|
reviewMode,
|
|
52645
53516
|
status: "complete"
|
|
52646
53517
|
};
|
|
52647
|
-
const itcDir =
|
|
53518
|
+
const itcDir = join24(workDir, ".itc");
|
|
52648
53519
|
await fs.ensureDir(itcDir);
|
|
52649
|
-
await fs.writeFile(
|
|
53520
|
+
await fs.writeFile(join24(itcDir, "author-complete.json"), `${JSON.stringify(completeReceipt, null, 2)}
|
|
52650
53521
|
`);
|
|
52651
53522
|
return 0;
|
|
52652
53523
|
}
|
|
@@ -52684,7 +53555,7 @@ async function runItcPrepare(args, fs) {
|
|
|
52684
53555
|
echoError("itc-prepare: --chosen applies only to a --from-collect launch");
|
|
52685
53556
|
return 1;
|
|
52686
53557
|
}
|
|
52687
|
-
const chosenPath =
|
|
53558
|
+
const chosenPath = join24(intakeDir, "chosen-source.json");
|
|
52688
53559
|
if (!await fs.exists(chosenPath)) {
|
|
52689
53560
|
echoError(`itc-prepare: chosen source not found: ${chosenPath}`);
|
|
52690
53561
|
return 1;
|
|
@@ -52720,9 +53591,9 @@ async function runItcPrepare(args, fs) {
|
|
|
52720
53591
|
["topic-pool-manifest.json", "topic-pool-manifest.json"]
|
|
52721
53592
|
];
|
|
52722
53593
|
for (const [from, to] of copies) {
|
|
52723
|
-
const src =
|
|
53594
|
+
const src = join24(intakeDir, from);
|
|
52724
53595
|
if (await fs.exists(src))
|
|
52725
|
-
await fs.writeFile(
|
|
53596
|
+
await fs.writeFile(join24(workDir, to), await fs.readFile(src));
|
|
52726
53597
|
}
|
|
52727
53598
|
}
|
|
52728
53599
|
} catch (err) {
|
|
@@ -52736,16 +53607,99 @@ async function runItcPrepare(args, fs) {
|
|
|
52736
53607
|
// src/commands/content.ts
|
|
52737
53608
|
init_output2();
|
|
52738
53609
|
|
|
53610
|
+
// src/status-progress.ts
|
|
53611
|
+
import { join as join25 } from "path";
|
|
53612
|
+
var parseJson4 = JSON.parse.bind(JSON);
|
|
53613
|
+
function optionalString2(value) {
|
|
53614
|
+
return typeof value === "string" ? value : null;
|
|
53615
|
+
}
|
|
53616
|
+
async function readJson2(fs, path) {
|
|
53617
|
+
if (!await fs.exists(path))
|
|
53618
|
+
return null;
|
|
53619
|
+
try {
|
|
53620
|
+
const value = parseJson4(await fs.readFile(path));
|
|
53621
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
53622
|
+
} catch {
|
|
53623
|
+
return null;
|
|
53624
|
+
}
|
|
53625
|
+
}
|
|
53626
|
+
async function recordedSteps(fs, workDir) {
|
|
53627
|
+
const path = join25(workDir, "step-timing.json");
|
|
53628
|
+
if (!await fs.exists(path))
|
|
53629
|
+
return [];
|
|
53630
|
+
const text = await fs.readFile(path);
|
|
53631
|
+
return text.split(`
|
|
53632
|
+
`).flatMap((line) => {
|
|
53633
|
+
const trimmed = line.trim();
|
|
53634
|
+
if (trimmed === "")
|
|
53635
|
+
return [];
|
|
53636
|
+
try {
|
|
53637
|
+
const parsed = JSON.parse(trimmed);
|
|
53638
|
+
return typeof parsed.step === "string" ? [parsed] : [];
|
|
53639
|
+
} catch {
|
|
53640
|
+
return [];
|
|
53641
|
+
}
|
|
53642
|
+
});
|
|
53643
|
+
}
|
|
53644
|
+
async function progressPayload(fs, workDir) {
|
|
53645
|
+
const steps = await recordedSteps(fs, workDir);
|
|
53646
|
+
if (steps.length === 0)
|
|
53647
|
+
return { stages: 0, current: null, state: "not-started", elapsedMs: null };
|
|
53648
|
+
const last = steps[steps.length - 1];
|
|
53649
|
+
const first = steps[0];
|
|
53650
|
+
const startedAt = first.startedAt ?? null;
|
|
53651
|
+
const lastEndedAt = last.endedAt ?? null;
|
|
53652
|
+
const endMs = lastEndedAt === null ? Date.now() : Date.parse(lastEndedAt);
|
|
53653
|
+
const startMs = startedAt === null ? Number.NaN : Date.parse(startedAt);
|
|
53654
|
+
return {
|
|
53655
|
+
stages: steps.length,
|
|
53656
|
+
completed: steps.filter((step) => typeof step.endedAt === "string").length,
|
|
53657
|
+
current: last.step,
|
|
53658
|
+
state: lastEndedAt === null ? "running" : "settled",
|
|
53659
|
+
startedAt,
|
|
53660
|
+
lastEndedAt,
|
|
53661
|
+
elapsedMs: Number.isFinite(startMs) && Number.isFinite(endMs) ? Math.max(0, endMs - startMs) : null
|
|
53662
|
+
};
|
|
53663
|
+
}
|
|
53664
|
+
async function gatePayload(fs, workDir) {
|
|
53665
|
+
const pool = await readJson2(fs, join25(workDir, "pool-gate.json"));
|
|
53666
|
+
const ladder = await readJson2(fs, join25(workDir, "10-collect", "ladder.json"));
|
|
53667
|
+
const planDir = join25(workDir, "21-plan");
|
|
53668
|
+
let refusal = null;
|
|
53669
|
+
if (await fs.exists(planDir)) {
|
|
53670
|
+
const refusalFile = (await fs.readDir(planDir)).filter((entry) => entry.endsWith("_04_quality-control-content_floor-refusal.json")).sort().at(-1);
|
|
53671
|
+
if (refusalFile !== undefined) {
|
|
53672
|
+
const raw = await readJson2(fs, join25(planDir, refusalFile));
|
|
53673
|
+
refusal = raw === null ? null : {
|
|
53674
|
+
estimatedMinutes: raw.estimatedMinutes ?? null,
|
|
53675
|
+
minMinutes: raw.minMinutes ?? null,
|
|
53676
|
+
expansion: raw.expansion ?? null,
|
|
53677
|
+
reason: optionalString2(raw.reason)
|
|
53678
|
+
};
|
|
53679
|
+
}
|
|
53680
|
+
}
|
|
53681
|
+
return {
|
|
53682
|
+
pool: pool === null ? null : optionalString2(pool.status) ?? null,
|
|
53683
|
+
floorRefusal: refusal,
|
|
53684
|
+
ladder: ladder === null ? null : {
|
|
53685
|
+
chosen: optionalString2(ladder.chosen),
|
|
53686
|
+
ratioUsed: typeof ladder.ratioUsed === "number" ? ladder.ratioUsed : null,
|
|
53687
|
+
ratioSource: optionalString2(ladder.ratioSource),
|
|
53688
|
+
rungs: Array.isArray(ladder.rungs) ? ladder.rungs : []
|
|
53689
|
+
}
|
|
53690
|
+
};
|
|
53691
|
+
}
|
|
53692
|
+
|
|
52739
53693
|
// src/commands/content-generate.ts
|
|
52740
53694
|
init_dist3();
|
|
52741
53695
|
init_dist();
|
|
52742
53696
|
init_commander();
|
|
52743
|
-
import { join as
|
|
53697
|
+
import { join as join28, resolve as resolve22 } from "path";
|
|
52744
53698
|
init_output2();
|
|
52745
53699
|
|
|
52746
53700
|
// src/publish-matrix.ts
|
|
52747
53701
|
import { createHash as createHash9 } from "crypto";
|
|
52748
|
-
import { dirname as dirname13, join as
|
|
53702
|
+
import { dirname as dirname13, join as join26, relative as relative4, resolve as resolve21 } from "path";
|
|
52749
53703
|
init_dist3();
|
|
52750
53704
|
init_dist();
|
|
52751
53705
|
init_zod();
|
|
@@ -52808,10 +53762,10 @@ var PublishPlanSchema = object2({
|
|
|
52808
53762
|
rows: array(PublishPlanRowSchema)
|
|
52809
53763
|
}).strict();
|
|
52810
53764
|
async function resolveBundlePath(fs, workDir) {
|
|
52811
|
-
const
|
|
52812
|
-
if (await fs.exists(
|
|
52813
|
-
return
|
|
52814
|
-
return
|
|
53765
|
+
const root = join26(workDir, "bundle.json");
|
|
53766
|
+
if (await fs.exists(root))
|
|
53767
|
+
return root;
|
|
53768
|
+
return join26(workDir, "4-publish", "bundle.json");
|
|
52815
53769
|
}
|
|
52816
53770
|
var PublishOutcomeRowSchema = object2({
|
|
52817
53771
|
id: string2().min(1),
|
|
@@ -52929,7 +53883,7 @@ function listValue(args, flag) {
|
|
|
52929
53883
|
}
|
|
52930
53884
|
async function appendEvent(fs, publishDir, event) {
|
|
52931
53885
|
await fs.ensureDir(publishDir);
|
|
52932
|
-
const path =
|
|
53886
|
+
const path = join26(publishDir, "publish-events.jsonl");
|
|
52933
53887
|
const prior = await fs.exists(path) ? await fs.readFile(path) : "";
|
|
52934
53888
|
await fs.writeFile(path, `${prior}${JSON.stringify({ at: new Date().toISOString(), ...event })}
|
|
52935
53889
|
`);
|
|
@@ -52978,8 +53932,8 @@ async function runPublishMatrixValidate(args, deps = {}) {
|
|
|
52978
53932
|
echoError(`publish-matrix-validate: run date '${candidate}' (from ${source}) is not a valid calendar day (YYYY-MM-DD or YYYYMMDD)`);
|
|
52979
53933
|
return 1;
|
|
52980
53934
|
}
|
|
52981
|
-
await fs.ensureDir(
|
|
52982
|
-
await fs.writeFile(
|
|
53935
|
+
await fs.ensureDir(join26(workDir, "4-publish"));
|
|
53936
|
+
await fs.writeFile(join26(workDir, "4-publish", "run-date.txt"), `${normalized}
|
|
52983
53937
|
`);
|
|
52984
53938
|
echo(`run date ${normalized} (from ${source})`);
|
|
52985
53939
|
return 0;
|
|
@@ -52989,7 +53943,7 @@ var LINK_SOURCES = [
|
|
|
52989
53943
|
{ placeholder: "{{podcast_url}}", plugin: "podcast-pub", receipt: "podcast" }
|
|
52990
53944
|
];
|
|
52991
53945
|
async function readPlan(fs, workDir, window) {
|
|
52992
|
-
const planPath =
|
|
53946
|
+
const planPath = join26(workDir, "4-publish", `plan.${window}.json`);
|
|
52993
53947
|
if (!await fs.exists(planPath)) {
|
|
52994
53948
|
throw new Error(`no plan at ${planPath}; run publish-matrix-plan first`);
|
|
52995
53949
|
}
|
|
@@ -53182,8 +54136,8 @@ async function composePlan(fs, input) {
|
|
|
53182
54136
|
variantPath: relative4(input.workDir, resolve21(bundleDir, entry.path)),
|
|
53183
54137
|
variantDigest: entry.sha256
|
|
53184
54138
|
});
|
|
53185
|
-
await fs.ensureDir(
|
|
53186
|
-
await fs.writeFile(
|
|
54139
|
+
await fs.ensureDir(join26(input.workDir, "4-publish", "payloads"));
|
|
54140
|
+
await fs.writeFile(join26(input.workDir, payloadRelative), payloadText);
|
|
53187
54141
|
}
|
|
53188
54142
|
return {
|
|
53189
54143
|
plan: {
|
|
@@ -53235,11 +54189,11 @@ async function planPublishMatrix(args, deps = {}) {
|
|
|
53235
54189
|
...deps.projectRoot ? { projectRoot: deps.projectRoot } : {},
|
|
53236
54190
|
...deps.presetOverride ? { presetOverride: deps.presetOverride } : {}
|
|
53237
54191
|
});
|
|
53238
|
-
const publishDir =
|
|
54192
|
+
const publishDir = join26(workDir, "4-publish");
|
|
53239
54193
|
await fs.ensureDir(publishDir);
|
|
53240
54194
|
const planText = `${JSON.stringify(plan, null, 2)}
|
|
53241
54195
|
`;
|
|
53242
|
-
await fs.writeFile(
|
|
54196
|
+
await fs.writeFile(join26(publishDir, `plan.${plan.window}.json`), planText);
|
|
53243
54197
|
const planDigest = createHash9("sha256").update(planText).digest("hex");
|
|
53244
54198
|
for (const target of omitted) {
|
|
53245
54199
|
const receipt = {
|
|
@@ -53257,8 +54211,8 @@ async function planPublishMatrix(args, deps = {}) {
|
|
|
53257
54211
|
window: plan.window,
|
|
53258
54212
|
...target.mode === "dummy" ? { dummy: true } : {}
|
|
53259
54213
|
};
|
|
53260
|
-
await fs.ensureDir(
|
|
53261
|
-
await fs.writeFile(
|
|
54214
|
+
await fs.ensureDir(join26(publishDir, "receipts"));
|
|
54215
|
+
await fs.writeFile(join26(publishDir, "receipts", `${target.id}.json`), `${JSON.stringify(receipt, null, 2)}
|
|
53262
54216
|
`);
|
|
53263
54217
|
await appendEvent(fs, publishDir, {
|
|
53264
54218
|
event: "omitted",
|
|
@@ -53340,9 +54294,9 @@ async function checkPublishMatrix(args, deps = {}) {
|
|
|
53340
54294
|
echoError(`publish-matrix-check: channel probe for '${name}' refused: ${probe.detail ?? "unknown"}`);
|
|
53341
54295
|
}
|
|
53342
54296
|
}
|
|
53343
|
-
const publishDir =
|
|
54297
|
+
const publishDir = join26(workDir, "4-publish");
|
|
53344
54298
|
await fs.ensureDir(publishDir);
|
|
53345
|
-
await fs.writeFile(
|
|
54299
|
+
await fs.writeFile(join26(publishDir, outFile), `${JSON.stringify({ schemaVersion: 1, window: label, plugins: probes }, null, 2)}
|
|
53346
54300
|
`);
|
|
53347
54301
|
echo(names.length === 0 ? "no probes" : `${probes.length} probe(s) recorded for ${label}`);
|
|
53348
54302
|
return 0;
|
|
@@ -53370,7 +54324,7 @@ async function runPublishMatrixClassify(args, deps = {}) {
|
|
|
53370
54324
|
echoError(`publish-matrix-classify: unknown window '${windowArg}'`);
|
|
53371
54325
|
return 1;
|
|
53372
54326
|
}
|
|
53373
|
-
const publishDir =
|
|
54327
|
+
const publishDir = join26(workDir, "4-publish");
|
|
53374
54328
|
let plan;
|
|
53375
54329
|
try {
|
|
53376
54330
|
plan = await readPlan(fs, workDir, parsedWindow.data);
|
|
@@ -53385,7 +54339,7 @@ async function runPublishMatrixClassify(args, deps = {}) {
|
|
|
53385
54339
|
echoError(`publish-matrix-classify: ${err instanceof Error ? err.message : String(err)}`);
|
|
53386
54340
|
await fs.ensureDir(publishDir);
|
|
53387
54341
|
const noneDate = runDate ?? await (async () => {
|
|
53388
|
-
const stampPath =
|
|
54342
|
+
const stampPath = join26(publishDir, "run-date.txt");
|
|
53389
54343
|
if (!await fs.exists(stampPath))
|
|
53390
54344
|
return;
|
|
53391
54345
|
return normalizeRunDate((await fs.readFile(stampPath)).trim());
|
|
@@ -53400,16 +54354,16 @@ async function runPublishMatrixClassify(args, deps = {}) {
|
|
|
53400
54354
|
excluded: [],
|
|
53401
54355
|
rows: []
|
|
53402
54356
|
};
|
|
53403
|
-
await fs.writeFile(
|
|
54357
|
+
await fs.writeFile(join26(publishDir, `outcome.${parsedWindow.data}.json`), `${JSON.stringify(none, null, 2)}
|
|
53404
54358
|
`);
|
|
53405
|
-
await fs.writeFile(
|
|
54359
|
+
await fs.writeFile(join26(publishDir, `publish-status.${parsedWindow.data}.txt`), `none
|
|
53406
54360
|
`);
|
|
53407
|
-
await fs.writeFile(
|
|
54361
|
+
await fs.writeFile(join26(workDir, "publish-classify.summary.txt"), `${JSON.stringify({ status: "none", published: 0, targets: 0 })}
|
|
53408
54362
|
`);
|
|
53409
54363
|
return 0;
|
|
53410
54364
|
}
|
|
53411
54365
|
if (runDate === undefined) {
|
|
53412
|
-
const stampPath =
|
|
54366
|
+
const stampPath = join26(publishDir, "run-date.txt");
|
|
53413
54367
|
const stamp = await fs.exists(stampPath) ? normalizeRunDate((await fs.readFile(stampPath)).trim()) : undefined;
|
|
53414
54368
|
if (stamp === undefined) {
|
|
53415
54369
|
echoError("publish-matrix-classify: plan has no runDate and no usable --run-date/run-date.txt was provided");
|
|
@@ -53417,27 +54371,27 @@ async function runPublishMatrixClassify(args, deps = {}) {
|
|
|
53417
54371
|
}
|
|
53418
54372
|
runDate = stamp;
|
|
53419
54373
|
}
|
|
53420
|
-
const receiptsDir =
|
|
54374
|
+
const receiptsDir = join26(publishDir, "receipts");
|
|
53421
54375
|
const receipts = [];
|
|
53422
54376
|
if (await fs.exists(receiptsDir)) {
|
|
53423
54377
|
for (const name of await fs.readDir(receiptsDir)) {
|
|
53424
54378
|
if (!name.endsWith(".json"))
|
|
53425
54379
|
continue;
|
|
53426
54380
|
try {
|
|
53427
|
-
receipts.push(JSON.parse(await fs.readFile(
|
|
54381
|
+
receipts.push(JSON.parse(await fs.readFile(join26(receiptsDir, name))));
|
|
53428
54382
|
} catch {}
|
|
53429
54383
|
}
|
|
53430
54384
|
}
|
|
53431
54385
|
const outcome = classifyPublishMatrix(plan, receipts, runDate);
|
|
53432
54386
|
await fs.ensureDir(publishDir);
|
|
53433
|
-
await fs.writeFile(
|
|
54387
|
+
await fs.writeFile(join26(publishDir, `outcome.${outcome.window}.json`), `${JSON.stringify(outcome, null, 2)}
|
|
53434
54388
|
`);
|
|
53435
|
-
await fs.writeFile(
|
|
54389
|
+
await fs.writeFile(join26(publishDir, `publish-status.${outcome.window}.txt`), `${outcome.status}
|
|
53436
54390
|
`);
|
|
53437
|
-
await fs.writeFile(
|
|
54391
|
+
await fs.writeFile(join26(workDir, "publish-classify.summary.txt"), `${JSON.stringify({ status: outcome.status, published: outcome.published, targets: outcome.targets })}
|
|
53438
54392
|
`);
|
|
53439
54393
|
if (outcome.window === "after-generate") {
|
|
53440
|
-
const legacyDir =
|
|
54394
|
+
const legacyDir = join26(workDir, "31-publish");
|
|
53441
54395
|
for (const source of LEGACY_RESULT_FILES) {
|
|
53442
54396
|
const row = plan.rows.find((candidate) => candidate.plugin === source.plugin && candidate.tier === 0);
|
|
53443
54397
|
if (row === undefined || row.mode === "dummy")
|
|
@@ -53449,7 +54403,7 @@ async function runPublishMatrixClassify(args, deps = {}) {
|
|
|
53449
54403
|
if (!await fs.exists(aggregate))
|
|
53450
54404
|
continue;
|
|
53451
54405
|
await fs.ensureDir(legacyDir);
|
|
53452
|
-
await fs.writeFile(
|
|
54406
|
+
await fs.writeFile(join26(legacyDir, `${runDate.replaceAll("-", "")}${source.file}`), await fs.readFile(aggregate));
|
|
53453
54407
|
}
|
|
53454
54408
|
}
|
|
53455
54409
|
echo(outcome.status);
|
|
@@ -53471,7 +54425,7 @@ async function runPublishMatrixSettle(args, deps = {}) {
|
|
|
53471
54425
|
echoError(`publish-matrix-settle: unknown window '${windowArg}'`);
|
|
53472
54426
|
return 1;
|
|
53473
54427
|
}
|
|
53474
|
-
const publishDir =
|
|
54428
|
+
const publishDir = join26(workDir, "4-publish");
|
|
53475
54429
|
let plan;
|
|
53476
54430
|
try {
|
|
53477
54431
|
plan = await readPlan(fs, workDir, parsedWindow.data);
|
|
@@ -53480,9 +54434,9 @@ async function runPublishMatrixSettle(args, deps = {}) {
|
|
|
53480
54434
|
return 1;
|
|
53481
54435
|
}
|
|
53482
54436
|
const parentRunId = plan.parentRunId;
|
|
53483
|
-
const receiptsDir =
|
|
54437
|
+
const receiptsDir = join26(publishDir, "receipts");
|
|
53484
54438
|
const receiptFor = async (id) => {
|
|
53485
|
-
const path =
|
|
54439
|
+
const path = join26(receiptsDir, `${id}.json`);
|
|
53486
54440
|
if (!await fs.exists(path))
|
|
53487
54441
|
return;
|
|
53488
54442
|
try {
|
|
@@ -53534,7 +54488,7 @@ async function runPublishMatrixSettle(args, deps = {}) {
|
|
|
53534
54488
|
unresolved
|
|
53535
54489
|
};
|
|
53536
54490
|
await fs.ensureDir(publishDir);
|
|
53537
|
-
const settlementPath =
|
|
54491
|
+
const settlementPath = join26(publishDir, `settlement.${parsedWindow.data}.json`);
|
|
53538
54492
|
if (unresolved.length > 0) {
|
|
53539
54493
|
await fs.writeFile(settlementPath, `${JSON.stringify(settlement, null, 2)}
|
|
53540
54494
|
`);
|
|
@@ -53607,7 +54561,7 @@ async function readLinkMap(fs, publishDir, plan) {
|
|
|
53607
54561
|
const planPaths = (await fs.exists(publishDir) ? await fs.readDir(publishDir) : []).filter((name) => /^plan\..*\.json$/.test(name));
|
|
53608
54562
|
for (const name of planPaths) {
|
|
53609
54563
|
try {
|
|
53610
|
-
const candidate = JSON.parse(await fs.readFile(
|
|
54564
|
+
const candidate = JSON.parse(await fs.readFile(join26(publishDir, name)));
|
|
53611
54565
|
if (candidate.parentRunId !== plan.parentRunId)
|
|
53612
54566
|
continue;
|
|
53613
54567
|
for (const row of candidate.rows) {
|
|
@@ -53620,7 +54574,7 @@ async function readLinkMap(fs, publishDir, plan) {
|
|
|
53620
54574
|
const entry = tierZero.find((candidate) => candidate.plugin === source.plugin);
|
|
53621
54575
|
if (entry === undefined)
|
|
53622
54576
|
continue;
|
|
53623
|
-
const path =
|
|
54577
|
+
const path = join26(publishDir, "receipts", `${entry.rowId}.json`);
|
|
53624
54578
|
if (!await fs.exists(path))
|
|
53625
54579
|
continue;
|
|
53626
54580
|
try {
|
|
@@ -53644,8 +54598,9 @@ async function sendPublishMatrix(args, deps = {}) {
|
|
|
53644
54598
|
const windowArg = flagValue(args, "--window");
|
|
53645
54599
|
const tierArg = flagValue(args, "--tier");
|
|
53646
54600
|
const retry = args.includes("--retry");
|
|
54601
|
+
const confirmNone = args.includes("--confirm-none");
|
|
53647
54602
|
if (!workDir || windowArg === undefined) {
|
|
53648
|
-
echoError("usage: publish-matrix-send <work_dir> --window <w> [--retry] [--tier <n>]");
|
|
54603
|
+
echoError("usage: publish-matrix-send <work_dir> --window <w> [--retry] [--tier <n>] [--confirm-none]");
|
|
53649
54604
|
return 1;
|
|
53650
54605
|
}
|
|
53651
54606
|
const parsedWindow = PublishWindowSchema.safeParse(windowArg);
|
|
@@ -53662,21 +54617,21 @@ async function sendPublishMatrix(args, deps = {}) {
|
|
|
53662
54617
|
}
|
|
53663
54618
|
}
|
|
53664
54619
|
try {
|
|
53665
|
-
if (retry && !await fs.exists(
|
|
54620
|
+
if (retry && !await fs.exists(join26(workDir, "4-publish", `plan.${parsedWindow.data}.json`))) {
|
|
53666
54621
|
echo(`publish-matrix-send: no plan for window '${parsedWindow.data}' \u2014 nothing was planned, nothing to resend`);
|
|
53667
54622
|
return 0;
|
|
53668
54623
|
}
|
|
53669
54624
|
const plan = await readPlan(fs, workDir, parsedWindow.data);
|
|
53670
|
-
const publishDir =
|
|
53671
|
-
const receiptsDir =
|
|
54625
|
+
const publishDir = join26(workDir, "4-publish");
|
|
54626
|
+
const receiptsDir = join26(publishDir, "receipts");
|
|
53672
54627
|
await fs.ensureDir(receiptsDir);
|
|
53673
|
-
const planDigest = createHash9("sha256").update(await fs.readFile(
|
|
54628
|
+
const planDigest = createHash9("sha256").update(await fs.readFile(join26(publishDir, `plan.${plan.window}.json`))).digest("hex");
|
|
53674
54629
|
const tiers = [...new Set(plan.rows.map((row) => row.tier))].sort((a, b) => a - b);
|
|
53675
54630
|
const pending = onlyTier === undefined ? plan.rows : plan.rows.filter((row) => row.tier === onlyTier);
|
|
53676
54631
|
for (const row of pending) {
|
|
53677
54632
|
if (row.mode === "dummy")
|
|
53678
54633
|
continue;
|
|
53679
|
-
const payloadPath =
|
|
54634
|
+
const payloadPath = join26(workDir, row.payloadPath);
|
|
53680
54635
|
const payloadRaw = await fs.exists(payloadPath) ? await fs.readFile(payloadPath) : null;
|
|
53681
54636
|
if (payloadRaw === null) {
|
|
53682
54637
|
throw new Error(`payload missing for '${row.id}': ${payloadPath}; re-run publish-matrix-plan`);
|
|
@@ -53686,7 +54641,7 @@ async function sendPublishMatrix(args, deps = {}) {
|
|
|
53686
54641
|
throw new Error(`payload for '${row.id}' changed after the plan was frozen (reviewed ${row.payloadDigest}, on disk ${payloadActual}); re-run publish-matrix-plan`);
|
|
53687
54642
|
}
|
|
53688
54643
|
if (row.variantPath !== undefined && row.variantDigest !== undefined) {
|
|
53689
|
-
const variantPath =
|
|
54644
|
+
const variantPath = join26(workDir, row.variantPath);
|
|
53690
54645
|
const variantRaw = await fs.exists(variantPath) ? await fs.readFile(variantPath) : null;
|
|
53691
54646
|
if (variantRaw === null) {
|
|
53692
54647
|
throw new Error(`variant source missing for '${row.id}': ${variantPath}; re-run publish-matrix-plan`);
|
|
@@ -53707,7 +54662,7 @@ async function sendPublishMatrix(args, deps = {}) {
|
|
|
53707
54662
|
plugin: row.plugin,
|
|
53708
54663
|
profile: row.profile ?? "article",
|
|
53709
54664
|
mode: row.mode,
|
|
53710
|
-
payloadPath:
|
|
54665
|
+
payloadPath: join26(workDir, row.payloadPath),
|
|
53711
54666
|
transport: row.transport ?? "fanout",
|
|
53712
54667
|
...row.metadata !== undefined ? { metadata: row.metadata } : {},
|
|
53713
54668
|
receiptExtras: { target: row.id, window: plan.window }
|
|
@@ -53719,6 +54674,7 @@ async function sendPublishMatrix(args, deps = {}) {
|
|
|
53719
54674
|
parentRunId: plan.parentRunId,
|
|
53720
54675
|
planDigest,
|
|
53721
54676
|
retry,
|
|
54677
|
+
...confirmNone ? { confirmNone } : {},
|
|
53722
54678
|
label: "publish-matrix-send",
|
|
53723
54679
|
fs,
|
|
53724
54680
|
...deps.dispatch ? { dispatch: deps.dispatch } : {},
|
|
@@ -53735,10 +54691,18 @@ async function sendPublishMatrix(args, deps = {}) {
|
|
|
53735
54691
|
continue;
|
|
53736
54692
|
resolved = resolved.split(source.placeholder).join(JSON.stringify(url).slice(1, -1));
|
|
53737
54693
|
}
|
|
54694
|
+
if (LINK_SOURCES.some((source) => resolved.includes(source.placeholder))) {
|
|
54695
|
+
const unresolved = LINK_SOURCES.filter((source) => resolved.includes(source.placeholder)).map((source) => source.placeholder);
|
|
54696
|
+
const draftMayDropLink = row.mode === "draft" && unresolved.every((placeholder) => placeholder === "{{article_url}}");
|
|
54697
|
+
if (draftMayDropLink) {
|
|
54698
|
+
resolved = resolved.replace(/"originalUrl"\s*:\s*"\{\{article_url\}\}"/, '"originalUrl": ""');
|
|
54699
|
+
echo(`publish-matrix-send: ${row.key} is a draft \u2014 dropped the unresolved {{article_url}} cross-link`);
|
|
54700
|
+
}
|
|
54701
|
+
}
|
|
53738
54702
|
if (LINK_SOURCES.some((source) => resolved.includes(source.placeholder))) {
|
|
53739
54703
|
return { error: "unresolved-link" };
|
|
53740
54704
|
}
|
|
53741
|
-
const resolvedPath =
|
|
54705
|
+
const resolvedPath = join26(workDir, "4-publish", "payloads", `content.${row.key}.resolved.json`);
|
|
53742
54706
|
await fs.writeFile(resolvedPath, resolved);
|
|
53743
54707
|
return { payloadPath: resolvedPath };
|
|
53744
54708
|
},
|
|
@@ -53799,7 +54763,7 @@ async function runPublishMatrixRssGate(args, deps = {}) {
|
|
|
53799
54763
|
echoError("usage: publish-matrix-rss-gate <work_dir> [--date <YYYY-MM-DD|YYYYMMDD>] [--feed <url>]");
|
|
53800
54764
|
return 1;
|
|
53801
54765
|
}
|
|
53802
|
-
const publishDir =
|
|
54766
|
+
const publishDir = join26(workDir, "4-publish");
|
|
53803
54767
|
const bundlePath = await resolveBundlePath(fs, workDir);
|
|
53804
54768
|
const hasBundle = await fs.exists(bundlePath);
|
|
53805
54769
|
if (hasBundle) {
|
|
@@ -53821,9 +54785,9 @@ async function runPublishMatrixRssGate(args, deps = {}) {
|
|
|
53821
54785
|
return 1;
|
|
53822
54786
|
}
|
|
53823
54787
|
let guid = "";
|
|
53824
|
-
const receiptsDir =
|
|
54788
|
+
const receiptsDir = join26(publishDir, "receipts");
|
|
53825
54789
|
for (const planWindow of ["after-generate", "cn-peak"]) {
|
|
53826
|
-
const planPath =
|
|
54790
|
+
const planPath = join26(publishDir, `plan.${planWindow}.json`);
|
|
53827
54791
|
if (!await fs.exists(planPath))
|
|
53828
54792
|
continue;
|
|
53829
54793
|
const plan = JSON.parse(await fs.readFile(planPath));
|
|
@@ -53839,7 +54803,7 @@ async function runPublishMatrixRssGate(args, deps = {}) {
|
|
|
53839
54803
|
for (const row of plan.rows) {
|
|
53840
54804
|
if (row.plugin !== "podcast-pub")
|
|
53841
54805
|
continue;
|
|
53842
|
-
const receiptPath =
|
|
54806
|
+
const receiptPath = join26(receiptsDir, `${row.id}.json`);
|
|
53843
54807
|
if (!await fs.exists(receiptPath))
|
|
53844
54808
|
continue;
|
|
53845
54809
|
const receipt = JSON.parse(await fs.readFile(receiptPath));
|
|
@@ -53848,7 +54812,7 @@ async function runPublishMatrixRssGate(args, deps = {}) {
|
|
|
53848
54812
|
}
|
|
53849
54813
|
}
|
|
53850
54814
|
if (date === undefined) {
|
|
53851
|
-
const stampPath =
|
|
54815
|
+
const stampPath = join26(publishDir, "run-date.txt");
|
|
53852
54816
|
const stamp = await fs.exists(stampPath) ? normalizeRunDate((await fs.readFile(stampPath)).trim()) : undefined;
|
|
53853
54817
|
if (stamp === undefined) {
|
|
53854
54818
|
echoError("publish-matrix-rss-gate: no usable --date and no run-date.txt/plan.runDate to derive one from");
|
|
@@ -53858,7 +54822,7 @@ async function runPublishMatrixRssGate(args, deps = {}) {
|
|
|
53858
54822
|
}
|
|
53859
54823
|
const write = async (result) => {
|
|
53860
54824
|
await fs.ensureDir(publishDir);
|
|
53861
|
-
await fs.writeFile(
|
|
54825
|
+
await fs.writeFile(join26(publishDir, "rss-gate.json"), `${JSON.stringify(result, null, 2)}
|
|
53862
54826
|
`);
|
|
53863
54827
|
await appendEvent(fs, publishDir, {
|
|
53864
54828
|
event: result.hit ? "gate-hit" : "gate-miss",
|
|
@@ -53874,9 +54838,9 @@ async function runPublishMatrixRssGate(args, deps = {}) {
|
|
|
53874
54838
|
reason: `feed ${result.feedUrl} has no episode for ${result.date} (${result.reason})`,
|
|
53875
54839
|
evidence: ["4-publish/rss-gate.json", ...result.detail === undefined ? [] : [result.detail]]
|
|
53876
54840
|
};
|
|
53877
|
-
await fs.writeFile(
|
|
54841
|
+
await fs.writeFile(join26(publishDir, "incident.json"), `${JSON.stringify(incident, null, 2)}
|
|
53878
54842
|
`);
|
|
53879
|
-
await fs.writeFile(
|
|
54843
|
+
await fs.writeFile(join26(publishDir, "incident.md"), [
|
|
53880
54844
|
`# Overseas window missed \u2014 ${result.date}`,
|
|
53881
54845
|
"",
|
|
53882
54846
|
`The podcast feed \`${result.feedUrl}\` does not carry the ${result.date} episode (${result.reason}).`,
|
|
@@ -54029,7 +54993,7 @@ async function runPublishMatrixBundle(args, deps = {}) {
|
|
|
54029
54993
|
echoError("usage: publish-matrix-bundle <work_dir> --run-date <YYYY-MM-DD> --run-id <voice3 run id> [--preset <slug>]");
|
|
54030
54994
|
return 1;
|
|
54031
54995
|
}
|
|
54032
|
-
const variantsDir =
|
|
54996
|
+
const variantsDir = join26(workDir, "30-variants");
|
|
54033
54997
|
if (!await fs.exists(variantsDir)) {
|
|
54034
54998
|
echoError(`publish-matrix-bundle: no variants at ${variantsDir}; run daily-bundle-variants first`);
|
|
54035
54999
|
return 1;
|
|
@@ -54041,7 +55005,7 @@ async function runPublishMatrixBundle(args, deps = {}) {
|
|
|
54041
55005
|
const variants = {};
|
|
54042
55006
|
for (const file of entries) {
|
|
54043
55007
|
const key = file.replace(/\.content\.json$/, "").replaceAll("_", ":");
|
|
54044
|
-
const raw = await fs.readFile(
|
|
55008
|
+
const raw = await fs.readFile(join26(variantsDir, file));
|
|
54045
55009
|
const parsed = ContentSchema.safeParse(JSON.parse(raw));
|
|
54046
55010
|
if (!parsed.success) {
|
|
54047
55011
|
throw new Error(`variant '${key}' is not valid Content: ${parsed.error.message}`);
|
|
@@ -54065,7 +55029,7 @@ async function runPublishMatrixBundle(args, deps = {}) {
|
|
|
54065
55029
|
}
|
|
54066
55030
|
}
|
|
54067
55031
|
const articleTitle = await readVariantTitle(fs, workDir, variants);
|
|
54068
|
-
const safetyPath =
|
|
55032
|
+
const safetyPath = join26(workDir, "4-safety-variants", "safety.json");
|
|
54069
55033
|
let safety;
|
|
54070
55034
|
if (await fs.exists(safetyPath)) {
|
|
54071
55035
|
const safetyParsed = BundleSafetySchema.safeParse(JSON.parse(await fs.readFile(safetyPath)));
|
|
@@ -54074,6 +55038,14 @@ async function runPublishMatrixBundle(args, deps = {}) {
|
|
|
54074
55038
|
return 1;
|
|
54075
55039
|
}
|
|
54076
55040
|
safety = safetyParsed.data;
|
|
55041
|
+
const disagreed = Object.entries(safety.variants).filter(([key, reviewed]) => {
|
|
55042
|
+
const frozen = variants[key]?.sha256;
|
|
55043
|
+
return frozen !== undefined && frozen !== reviewed;
|
|
55044
|
+
}).map(([key]) => key);
|
|
55045
|
+
if (disagreed.length > 0) {
|
|
55046
|
+
echoError(`publish-matrix-bundle: final-variant safety evidence is stale for ${disagreed.join(", ")} \u2014 the reviewed digest differs from the variant being frozen; re-run the variants safety gate (kk-daily-safety scope=variants) and freeze again`);
|
|
55047
|
+
return 1;
|
|
55048
|
+
}
|
|
54077
55049
|
}
|
|
54078
55050
|
const bundle = {
|
|
54079
55051
|
schemaVersion: 1,
|
|
@@ -54086,7 +55058,7 @@ async function runPublishMatrixBundle(args, deps = {}) {
|
|
|
54086
55058
|
...safety !== undefined ? { safety } : {}
|
|
54087
55059
|
};
|
|
54088
55060
|
const validated = BundleSchema.parse(bundle);
|
|
54089
|
-
const bundlePath =
|
|
55061
|
+
const bundlePath = join26(workDir, "bundle.json");
|
|
54090
55062
|
if (await fs.exists(bundlePath)) {
|
|
54091
55063
|
try {
|
|
54092
55064
|
const prior = BundleSchema.parse(JSON.parse(await fs.readFile(bundlePath)));
|
|
@@ -54113,7 +55085,7 @@ async function readVariantTitle(fs, workDir, variants) {
|
|
|
54113
55085
|
if (entry === undefined)
|
|
54114
55086
|
continue;
|
|
54115
55087
|
try {
|
|
54116
|
-
const parsed = ContentSchema.parse(JSON.parse(await fs.readFile(
|
|
55088
|
+
const parsed = ContentSchema.parse(JSON.parse(await fs.readFile(join26(workDir, entry.path))));
|
|
54117
55089
|
if (parsed.title !== undefined && parsed.title.trim() !== "")
|
|
54118
55090
|
return parsed.title.trim();
|
|
54119
55091
|
} catch {}
|
|
@@ -54125,7 +55097,7 @@ async function readVariantTitle(fs, workDir, variants) {
|
|
|
54125
55097
|
init_dist3();
|
|
54126
55098
|
init_dist();
|
|
54127
55099
|
import { createHash as createHash10 } from "crypto";
|
|
54128
|
-
import { dirname as dirname14, join as
|
|
55100
|
+
import { dirname as dirname14, join as join27 } from "path";
|
|
54129
55101
|
var PARSE_JSON = JSON.parse.bind(JSON);
|
|
54130
55102
|
var ARTICLE_CHECK_STEPS = ["outline", "judge", "adapt"];
|
|
54131
55103
|
var OUTLINE_DIR = "2-outline";
|
|
@@ -54150,7 +55122,7 @@ var DEFAULT_DEPS = {
|
|
|
54150
55122
|
runStage: async (argv) => runStage(argv)
|
|
54151
55123
|
};
|
|
54152
55124
|
var deps = DEFAULT_DEPS;
|
|
54153
|
-
async function
|
|
55125
|
+
async function readJson3(fs, path) {
|
|
54154
55126
|
if (!await fs.exists(path))
|
|
54155
55127
|
return null;
|
|
54156
55128
|
try {
|
|
@@ -54183,16 +55155,16 @@ async function resolveArticleMaxRevisions(configFile, fs) {
|
|
|
54183
55155
|
return block.max_revisions ?? DEFAULT_MAX_REVISIONS;
|
|
54184
55156
|
}
|
|
54185
55157
|
async function parentRunIdOf(fs, workDir) {
|
|
54186
|
-
const snapshot = await
|
|
55158
|
+
const snapshot = await readJson3(fs, join27(workDir, OPTIONS_SNAPSHOT));
|
|
54187
55159
|
const recorded = snapshot?.parentRunId;
|
|
54188
55160
|
if (typeof recorded === "string" && recorded.trim() !== "")
|
|
54189
55161
|
return recorded.trim();
|
|
54190
|
-
const request = await
|
|
55162
|
+
const request = await readJson3(fs, join27(workDir, REQUEST_FILE));
|
|
54191
55163
|
const run = request?.run;
|
|
54192
55164
|
return typeof run === "string" && run.trim() !== "" ? `kk-content-${run.trim()}` : "kk-content-run";
|
|
54193
55165
|
}
|
|
54194
55166
|
async function runOutlineStep(input, fs) {
|
|
54195
|
-
const recommendation =
|
|
55167
|
+
const recommendation = join27(input.workDir, OUTLINE_DIR, "outline-recommendation.json");
|
|
54196
55168
|
if (!await fs.exists(recommendation)) {
|
|
54197
55169
|
return missingInput(input.step, recommendation);
|
|
54198
55170
|
}
|
|
@@ -54211,25 +55183,25 @@ async function runOutlineStep(input, fs) {
|
|
|
54211
55183
|
echoError(`kk generate-check: itc-decision --outline failed (exit ${decided}) for ${input.workDir}`);
|
|
54212
55184
|
return 1;
|
|
54213
55185
|
}
|
|
54214
|
-
const chosen = (await readText(fs,
|
|
55186
|
+
const chosen = (await readText(fs, join27(input.workDir, OUTLINE_DIR, AUTO_PICK))).trim();
|
|
54215
55187
|
if (chosen === "")
|
|
54216
55188
|
return { verdict: "fix" };
|
|
54217
|
-
const option =
|
|
55189
|
+
const option = join27(input.workDir, OUTLINE_DIR, `outline-option-${chosen}.md`);
|
|
54218
55190
|
if (!await fs.exists(option)) {
|
|
54219
55191
|
echoError(`kk generate-check: the picked outline option is missing: ${option}`);
|
|
54220
55192
|
return 1;
|
|
54221
55193
|
}
|
|
54222
|
-
await fs.copy(option,
|
|
55194
|
+
await fs.copy(option, join27(input.workDir, OUTLINE_DIR, OUTLINE_APPROVED));
|
|
54223
55195
|
return { verdict: "pass" };
|
|
54224
55196
|
}
|
|
54225
55197
|
async function runJudgeStep(input, fs) {
|
|
54226
|
-
const verdictPath =
|
|
55198
|
+
const verdictPath = join27(input.workDir, VERDICT_FILE);
|
|
54227
55199
|
if (!await fs.exists(verdictPath)) {
|
|
54228
55200
|
return missingInput(input.step, verdictPath);
|
|
54229
55201
|
}
|
|
54230
|
-
const drafts = await countOf(fs,
|
|
55202
|
+
const drafts = await countOf(fs, join27(input.workDir, DRAFT_COUNT));
|
|
54231
55203
|
const rewrites = Math.max(0, drafts - 1);
|
|
54232
|
-
await fs.writeFile(
|
|
55204
|
+
await fs.writeFile(join27(input.workDir, AUTO_REVISE_COUNT), `${rewrites}
|
|
54233
55205
|
`);
|
|
54234
55206
|
const previousAuto = process.env.KK_ITC_AUTO;
|
|
54235
55207
|
const previousMax = process.env.KK_ITC_MAX_REVISIONS;
|
|
@@ -54246,7 +55218,7 @@ async function runJudgeStep(input, fs) {
|
|
|
54246
55218
|
echoError(`kk generate-check: itc-author-verdict failed (exit ${code}) for ${input.workDir}`);
|
|
54247
55219
|
return 1;
|
|
54248
55220
|
}
|
|
54249
|
-
const disposition = (await readText(fs,
|
|
55221
|
+
const disposition = (await readText(fs, join27(input.workDir, DISPOSITION_FILE))).trim();
|
|
54250
55222
|
if (disposition === "finish" && !await verdictCarriesConfidence(fs, verdictPath)) {
|
|
54251
55223
|
echoError(`kk generate-check: ${verdictPath} reports PASS without a HIGH|MEDIUM|LOW confidence`);
|
|
54252
55224
|
return { verdict: "fix", errors: verdictPath };
|
|
@@ -54255,7 +55227,7 @@ async function runJudgeStep(input, fs) {
|
|
|
54255
55227
|
}
|
|
54256
55228
|
var CONFIDENCE_LEVELS2 = new Set(["HIGH", "MEDIUM", "LOW"]);
|
|
54257
55229
|
async function verdictCarriesConfidence(fs, path) {
|
|
54258
|
-
const value = await
|
|
55230
|
+
const value = await readJson3(fs, path);
|
|
54259
55231
|
if (value === null)
|
|
54260
55232
|
return false;
|
|
54261
55233
|
if (value.verdict !== "PASS")
|
|
@@ -54271,7 +55243,7 @@ function restoreEnv(name, previous) {
|
|
|
54271
55243
|
process.env[name] = previous;
|
|
54272
55244
|
}
|
|
54273
55245
|
async function runAdaptStep(input, fs) {
|
|
54274
|
-
const planPath =
|
|
55246
|
+
const planPath = join27(input.workDir, PUBLISH_DIR, PLAN_FILE);
|
|
54275
55247
|
if (!await fs.exists(planPath)) {
|
|
54276
55248
|
return missingInput(input.step, planPath);
|
|
54277
55249
|
}
|
|
@@ -54309,10 +55281,10 @@ function generationVariants(plan) {
|
|
|
54309
55281
|
return out;
|
|
54310
55282
|
}
|
|
54311
55283
|
async function readSnapshot(fs, workDir) {
|
|
54312
|
-
return await
|
|
55284
|
+
return await readJson3(fs, join27(workDir, OPTIONS_SNAPSHOT)) ?? {};
|
|
54313
55285
|
}
|
|
54314
55286
|
async function runVariantsStage(input, fs) {
|
|
54315
|
-
const draft =
|
|
55287
|
+
const draft = join27(input.workDir, DRAFT_FILE);
|
|
54316
55288
|
if (!await fs.exists(draft)) {
|
|
54317
55289
|
echoError(`kk generate-bundle: final draft not found: ${draft}; run the authoring states first`);
|
|
54318
55290
|
return 1;
|
|
@@ -54328,11 +55300,11 @@ async function runVariantsStage(input, fs) {
|
|
|
54328
55300
|
echoError(`kk generate-bundle: itc-materialize-plan failed (exit ${materialized}) for ${input.workDir}`);
|
|
54329
55301
|
return 1;
|
|
54330
55302
|
}
|
|
54331
|
-
const planPath =
|
|
54332
|
-
const plan = await
|
|
55303
|
+
const planPath = join27(input.workDir, PUBLISH_DIR, PLAN_FILE);
|
|
55304
|
+
const plan = await readJson3(fs, planPath);
|
|
54333
55305
|
const variants = generationVariants(plan);
|
|
54334
|
-
const contentPath =
|
|
54335
|
-
const content = await
|
|
55306
|
+
const contentPath = join27(input.workDir, PUBLISH_DIR, CONTENT_FILE);
|
|
55307
|
+
const content = await readJson3(fs, contentPath) ?? {};
|
|
54336
55308
|
const warnings = Array.isArray(plan?.warnings) ? plan.warnings : [];
|
|
54337
55309
|
await writeJson(fs, contentPath, {
|
|
54338
55310
|
...content,
|
|
@@ -54341,14 +55313,14 @@ async function runVariantsStage(input, fs) {
|
|
|
54341
55313
|
...warnings.length === 0 ? {} : { warnings }
|
|
54342
55314
|
});
|
|
54343
55315
|
return {
|
|
54344
|
-
bundle:
|
|
55316
|
+
bundle: join27(input.workDir, PUBLISH_DIR, "bundle.json"),
|
|
54345
55317
|
variants: Object.keys(variants).sort(),
|
|
54346
55318
|
safety: null,
|
|
54347
55319
|
runId: input.runId
|
|
54348
55320
|
};
|
|
54349
55321
|
}
|
|
54350
55322
|
async function variantEntry(fs, workDir, file) {
|
|
54351
|
-
const path =
|
|
55323
|
+
const path = join27(workDir, PUBLISH_DIR, file);
|
|
54352
55324
|
let raw;
|
|
54353
55325
|
try {
|
|
54354
55326
|
raw = await fs.readFile(path);
|
|
@@ -54367,7 +55339,7 @@ class ArticleStepFailure extends Error {
|
|
|
54367
55339
|
}
|
|
54368
55340
|
}
|
|
54369
55341
|
async function runDateOf(fs, workDir) {
|
|
54370
|
-
const request = await
|
|
55342
|
+
const request = await readJson3(fs, join27(workDir, REQUEST_FILE));
|
|
54371
55343
|
const snapshot = await readSnapshot(fs, workDir);
|
|
54372
55344
|
const candidates = [request?.runDate, snapshot.runDate, workDir.replace(/\/+$/, "").split("/").at(-1)];
|
|
54373
55345
|
for (const candidate of candidates) {
|
|
@@ -54392,20 +55364,20 @@ async function validatePreset(fs, presetName, variants) {
|
|
|
54392
55364
|
return missing.length === 0 ? null : `preset '${preset.name}' requires variant(s) the run never produced: ${missing.join(", ")}`;
|
|
54393
55365
|
}
|
|
54394
55366
|
async function runFreezeStage(input, fs) {
|
|
54395
|
-
const bundlePath =
|
|
55367
|
+
const bundlePath = join27(input.workDir, PUBLISH_DIR, "bundle.json");
|
|
54396
55368
|
const completed = await deps.runItc(["itc-author-complete", input.workDir, input.runId]);
|
|
54397
55369
|
if (completed !== 0) {
|
|
54398
55370
|
echoError(`kk generate-bundle: itc-author-complete failed (exit ${completed}) for ${input.workDir}`);
|
|
54399
55371
|
return 1;
|
|
54400
55372
|
}
|
|
54401
|
-
const content = await
|
|
55373
|
+
const content = await readJson3(fs, join27(input.workDir, PUBLISH_DIR, CONTENT_FILE));
|
|
54402
55374
|
if (content === null) {
|
|
54403
|
-
echoError(`kk generate-bundle: ${
|
|
55375
|
+
echoError(`kk generate-bundle: ${join27(input.workDir, PUBLISH_DIR, CONTENT_FILE)} is missing; run --stage variants first`);
|
|
54404
55376
|
return 1;
|
|
54405
55377
|
}
|
|
54406
55378
|
const title = typeof content.title === "string" ? content.title.trim() : "";
|
|
54407
55379
|
if (title === "") {
|
|
54408
|
-
echoError(`kk generate-bundle: ${
|
|
55380
|
+
echoError(`kk generate-bundle: ${join27(input.workDir, PUBLISH_DIR, CONTENT_FILE)} has no title; the draft's H1 is the bundle title`);
|
|
54409
55381
|
return 1;
|
|
54410
55382
|
}
|
|
54411
55383
|
const sourceLocale = typeof content.sourceLocale === "string" ? content.sourceLocale : "en";
|
|
@@ -54441,7 +55413,7 @@ async function runFreezeStage(input, fs) {
|
|
|
54441
55413
|
return 1;
|
|
54442
55414
|
}
|
|
54443
55415
|
await writeJson(fs, bundlePath, parsed.data);
|
|
54444
|
-
const planPath =
|
|
55416
|
+
const planPath = join27(input.workDir, PUBLISH_DIR, PLAN_FILE);
|
|
54445
55417
|
if (await fs.exists(planPath))
|
|
54446
55418
|
await fs.deleteFile(planPath);
|
|
54447
55419
|
return { bundle: bundlePath, variants: Object.keys(variants).sort(), safety: null, runId: input.runId };
|
|
@@ -54554,7 +55526,7 @@ async function resolveRunDate(fs, workDir, explicit) {
|
|
|
54554
55526
|
const fromFlag = explicit?.replaceAll("-", "");
|
|
54555
55527
|
if (fromFlag !== undefined && /^\d{8}$/.test(fromFlag))
|
|
54556
55528
|
return fromFlag;
|
|
54557
|
-
const marker =
|
|
55529
|
+
const marker = join28(workDir, "run-date.txt");
|
|
54558
55530
|
if (await fs.exists(marker)) {
|
|
54559
55531
|
const text = (await fs.readFile(marker)).trim().replaceAll("-", "");
|
|
54560
55532
|
if (/^\d{8}$/.test(text))
|
|
@@ -54566,7 +55538,7 @@ async function resolveRunDate(fs, workDir, explicit) {
|
|
|
54566
55538
|
async function resolveRunId(fs, workDir, runDate, explicit) {
|
|
54567
55539
|
if (explicit !== undefined && explicit.trim() !== "")
|
|
54568
55540
|
return explicit.trim();
|
|
54569
|
-
const receipt = await readJsonFile3(fs,
|
|
55541
|
+
const receipt = await readJsonFile3(fs, join28(workDir, "schedule-receipt.json"));
|
|
54570
55542
|
const recorded = receipt?.runId;
|
|
54571
55543
|
if (typeof recorded === "string" && recorded.trim() !== "")
|
|
54572
55544
|
return recorded.trim();
|
|
@@ -54575,26 +55547,26 @@ async function resolveRunId(fs, workDir, runDate, explicit) {
|
|
|
54575
55547
|
return `news-generate-${runDate}`;
|
|
54576
55548
|
}
|
|
54577
55549
|
function candidatesPath(ctx) {
|
|
54578
|
-
return
|
|
55550
|
+
return join28(ctx.workDir, "21-plan", `${ctx.runDate}_04_quality-control-content_candidates.json`);
|
|
54579
55551
|
}
|
|
54580
55552
|
function curatedPlanPath(ctx) {
|
|
54581
|
-
return
|
|
55553
|
+
return join28(ctx.workDir, "21-plan", `${ctx.runDate}_03_plan_plan.json`);
|
|
54582
55554
|
}
|
|
54583
55555
|
function curateErrorsPath(ctx) {
|
|
54584
|
-
return
|
|
55556
|
+
return join28(ctx.workDir, "21-plan", `${ctx.runDate}_03_curate_errors.json`);
|
|
54585
55557
|
}
|
|
54586
55558
|
function scriptErrorsPath(ctx) {
|
|
54587
|
-
return
|
|
55559
|
+
return join28(ctx.workDir, "24-script", `${ctx.runDate}_08_script-write_errors.json`);
|
|
54588
55560
|
}
|
|
54589
55561
|
function poolGatePath(workDir) {
|
|
54590
|
-
return
|
|
55562
|
+
return join28(workDir, "pool-gate.json");
|
|
54591
55563
|
}
|
|
54592
55564
|
var AUDIO_CONTENT_REL = ["30-audio", "_11_generate_content.json"];
|
|
54593
55565
|
var SCRIPT_CONTENT_REL = ["24-script", "_08_script_content.json"];
|
|
54594
55566
|
var ARTICLE_CONTENT_REL = ["22-article", "_06_article_content.json"];
|
|
54595
55567
|
var COVER_REL = ["23-cover", "_07_cover_cover.png"];
|
|
54596
55568
|
function dated(ctx, [dir, suffix]) {
|
|
54597
|
-
return
|
|
55569
|
+
return join28(ctx.workDir, dir, `${ctx.runDate}${suffix}`);
|
|
54598
55570
|
}
|
|
54599
55571
|
async function audioMetadata(ctx) {
|
|
54600
55572
|
const content = await readJsonFile3(ctx.fs, dated(ctx, AUDIO_CONTENT_REL));
|
|
@@ -54621,17 +55593,16 @@ async function stampContentType(ctx) {
|
|
|
54621
55593
|
return 0;
|
|
54622
55594
|
}
|
|
54623
55595
|
async function writePoolGate(ctx) {
|
|
54624
|
-
const pooled = itemCount(await
|
|
54625
|
-
const items = itemCount(await
|
|
55596
|
+
const pooled = itemCount(await readJsonValue(ctx.fs, join28(ctx.workDir, "10-collect", "pool.json")));
|
|
55597
|
+
const items = itemCount(await readJsonValue(ctx.fs, candidatesPath(ctx)));
|
|
54626
55598
|
const status = items > 0 ? "PASS" : "EMPTY";
|
|
54627
55599
|
await ctx.fs.writeFile(poolGatePath(ctx.workDir), `${JSON.stringify({ status }, null, 2)}
|
|
54628
55600
|
`);
|
|
54629
|
-
const summary =
|
|
55601
|
+
const summary = join28(ctx.workDir, "run-report.summary.txt");
|
|
54630
55602
|
if (status === "EMPTY") {
|
|
54631
|
-
|
|
54632
|
-
await ctx.fs.writeFile(summary, `${reason}
|
|
55603
|
+
await ctx.fs.writeFile(summary, `${noContentReason(ctx.workDir, ctx.runDate, pooled)}
|
|
54633
55604
|
`);
|
|
54634
|
-
for (const stale of [
|
|
55605
|
+
for (const stale of [join28(ctx.workDir, "bundle.json"), join28(ctx.workDir, "4-publish", "bundle.json")]) {
|
|
54635
55606
|
if (await ctx.fs.exists(stale))
|
|
54636
55607
|
await ctx.fs.deleteFile(stale);
|
|
54637
55608
|
}
|
|
@@ -54690,8 +55661,8 @@ async function runGenerationReport(ctx) {
|
|
|
54690
55661
|
}
|
|
54691
55662
|
if (result.report === "")
|
|
54692
55663
|
return 1;
|
|
54693
|
-
const target =
|
|
54694
|
-
await ctx.fs.ensureDir(
|
|
55664
|
+
const target = join28(ctx.workDir, "5-report", "generation.md");
|
|
55665
|
+
await ctx.fs.ensureDir(join28(ctx.workDir, "5-report"));
|
|
54695
55666
|
await ctx.fs.writeFile(target, await ctx.fs.readFile(result.report));
|
|
54696
55667
|
try {
|
|
54697
55668
|
await quietStdout(() => syncLedger({ workflow: ctx.workflow, worksDir: ctx.worksDir, workDir: ctx.workDir }));
|
|
@@ -54753,7 +55724,7 @@ function reportOptions(ctx) {
|
|
|
54753
55724
|
return {
|
|
54754
55725
|
workDir: ctx.workDir,
|
|
54755
55726
|
runDate: ctx.runDate,
|
|
54756
|
-
pool:
|
|
55727
|
+
pool: join28(ctx.workDir, "10-collect", "pool.json"),
|
|
54757
55728
|
candidates: candidatesPath(ctx),
|
|
54758
55729
|
...ctx.settings.plugins_path === "" ? {} : { pluginsPath: ctx.settings.plugins_path },
|
|
54759
55730
|
qcMinQuality: ctx.settings.qc_min_quality,
|
|
@@ -54765,7 +55736,7 @@ function reportOptions(ctx) {
|
|
|
54765
55736
|
var ARGS = {
|
|
54766
55737
|
preflight: async (ctx) => {
|
|
54767
55738
|
const root = await resolvePackageRoot(ctx.fs);
|
|
54768
|
-
return ["kk-news-generate", "kk-publish", "kk-daily-safety"].map((name) =>
|
|
55739
|
+
return ["kk-news-generate", "kk-publish", "kk-daily-safety"].map((name) => join28(root, "plugins", "kk", "workflows", `${name}.yaml`));
|
|
54769
55740
|
},
|
|
54770
55741
|
extract: (ctx) => [
|
|
54771
55742
|
ctx.workDir,
|
|
@@ -54898,15 +55869,15 @@ var ARGS = {
|
|
|
54898
55869
|
report: () => []
|
|
54899
55870
|
};
|
|
54900
55871
|
async function poolNonEmpty(ctx) {
|
|
54901
|
-
return itemCount(await
|
|
55872
|
+
return itemCount(await readJsonValue(ctx.fs, join28(ctx.workDir, "10-collect", "pool.json"))) > 0;
|
|
54902
55873
|
}
|
|
54903
55874
|
async function sessionWarnings(ctx) {
|
|
54904
|
-
const check = await readJsonFile3(ctx.fs,
|
|
55875
|
+
const check = await readJsonFile3(ctx.fs, join28(ctx.workDir, "4-publish", "check.preflight.json"));
|
|
54905
55876
|
const plugins = Array.isArray(check?.plugins) ? check.plugins : [];
|
|
54906
55877
|
return plugins.filter(isObject4).filter((plugin) => plugin.ok !== true).map((plugin) => `${String(plugin.plugin ?? "unknown")}: ${String(plugin.detail ?? "not ready")}`);
|
|
54907
55878
|
}
|
|
54908
55879
|
async function candidatesNonEmpty(ctx) {
|
|
54909
|
-
return itemCount(await
|
|
55880
|
+
return itemCount(await readJsonValue(ctx.fs, candidatesPath(ctx))) > 0;
|
|
54910
55881
|
}
|
|
54911
55882
|
var STEP = {
|
|
54912
55883
|
preflight: () => ({ name: "daily-preflight", args: ARGS.preflight }),
|
|
@@ -54962,14 +55933,14 @@ async function bundleSummary(ctx) {
|
|
|
54962
55933
|
safety: safety === undefined ? "none" : safety.status
|
|
54963
55934
|
};
|
|
54964
55935
|
}
|
|
54965
|
-
const variantsDir =
|
|
55936
|
+
const variantsDir = join28(ctx.workDir, "30-variants");
|
|
54966
55937
|
const written = await ctx.fs.exists(variantsDir) ? (await ctx.fs.readDir(variantsDir)).filter((entry) => entry.endsWith(".content.json")).map((entry) => entry.replace(/\.content\.json$/, "").replaceAll("_", ":")) : [];
|
|
54967
|
-
const safety = await readJsonFile3(ctx.fs,
|
|
55938
|
+
const safety = await readJsonFile3(ctx.fs, join28(ctx.workDir, "4-safety-variants", "safety.json"));
|
|
54968
55939
|
const status = safety?.status;
|
|
54969
55940
|
return { path, variants: written.sort(), safety: typeof status === "string" ? status : "none" };
|
|
54970
55941
|
}
|
|
54971
55942
|
async function countFiles(ctx, dir, suffix) {
|
|
54972
|
-
const path =
|
|
55943
|
+
const path = join28(ctx.workDir, dir);
|
|
54973
55944
|
if (!await ctx.fs.exists(path))
|
|
54974
55945
|
return 0;
|
|
54975
55946
|
return (await ctx.fs.readDir(path)).filter((entry) => entry.endsWith(suffix)).length;
|
|
@@ -54988,7 +55959,7 @@ var GENERATE_ROWS = [
|
|
|
54988
55959
|
],
|
|
54989
55960
|
summary: async (ctx) => {
|
|
54990
55961
|
const gate = await readJsonFile3(ctx.fs, poolGatePath(ctx.workDir));
|
|
54991
|
-
const candidates = itemCount(await
|
|
55962
|
+
const candidates = itemCount(await readJsonValue(ctx.fs, candidatesPath(ctx)));
|
|
54992
55963
|
const pass = gate?.status === "PASS";
|
|
54993
55964
|
return {
|
|
54994
55965
|
pool: pass ? "ok" : "empty",
|
|
@@ -55070,7 +56041,7 @@ var GENERATE_ROWS = [
|
|
|
55070
56041
|
stages: [STEP.cards()],
|
|
55071
56042
|
summary: async (ctx) => ({
|
|
55072
56043
|
cards: await countFiles(ctx, "25-xhs", ".png"),
|
|
55073
|
-
dir:
|
|
56044
|
+
dir: join28(ctx.workDir, "25-xhs")
|
|
55074
56045
|
})
|
|
55075
56046
|
},
|
|
55076
56047
|
{
|
|
@@ -55106,7 +56077,7 @@ var GENERATE_ROWS = [
|
|
|
55106
56077
|
{
|
|
55107
56078
|
verb: "report",
|
|
55108
56079
|
stages: [STEP.report()],
|
|
55109
|
-
summary: async (ctx) => ({ report:
|
|
56080
|
+
summary: async (ctx) => ({ report: join28(ctx.workDir, "5-report", "generation.md") })
|
|
55110
56081
|
}
|
|
55111
56082
|
];
|
|
55112
56083
|
function articleOutcome(ctx, verb) {
|
|
@@ -55119,7 +56090,7 @@ function articleOutcome(ctx, verb) {
|
|
|
55119
56090
|
};
|
|
55120
56091
|
}
|
|
55121
56092
|
return {
|
|
55122
|
-
bundle: outcome.bundle ??
|
|
56093
|
+
bundle: outcome.bundle ?? join28(ctx.workDir, "4-publish", "bundle.json"),
|
|
55123
56094
|
runId: outcome.runId ?? ctx.runId,
|
|
55124
56095
|
variants: outcome.variants ?? [],
|
|
55125
56096
|
safety: outcome.safety ?? null
|
|
@@ -55161,6 +56132,7 @@ var NEWS_PHASE_DIRS = [
|
|
|
55161
56132
|
"4-publish",
|
|
55162
56133
|
"5-report"
|
|
55163
56134
|
];
|
|
56135
|
+
var REFRESH_PHASE_DIRS = [...NEWS_PHASE_DIRS, "4-publish", "5-report"];
|
|
55164
56136
|
function requireWorkDir(options, verb) {
|
|
55165
56137
|
if (options.workDir === undefined || options.workDir.trim() === "") {
|
|
55166
56138
|
return fail(2, `kk.content.${verb}`, `kk ${verb}: --work-dir is required`);
|
|
@@ -55238,7 +56210,7 @@ async function buildContext(noun, type, verb, options) {
|
|
|
55238
56210
|
if (runDate === undefined && noun === "news") {
|
|
55239
56211
|
return fail(2, `kk.content.${verb}`, `kk ${verb}: cannot resolve the run date for ${run.workDir}`);
|
|
55240
56212
|
}
|
|
55241
|
-
const priorErrors = await fs.exists(options.step === "script" ?
|
|
56213
|
+
const priorErrors = await fs.exists(options.step === "script" ? join28(run.workDir, "24-script", `${runDate}_08_script-write_errors.json`) : join28(run.workDir, "21-plan", `${runDate}_03_curate_errors.json`));
|
|
55242
56214
|
let maxRevisions = 0;
|
|
55243
56215
|
if (noun === "article" && (verb === "generate-check" || verb === "generate-bundle")) {
|
|
55244
56216
|
try {
|
|
@@ -55269,12 +56241,24 @@ async function buildContext(noun, type, verb, options) {
|
|
|
55269
56241
|
}
|
|
55270
56242
|
async function composeWorkspace(ctx) {
|
|
55271
56243
|
for (const dir of NEWS_PHASE_DIRS)
|
|
55272
|
-
await ctx.fs.ensureDir(
|
|
55273
|
-
await ctx.fs.writeFile(
|
|
56244
|
+
await ctx.fs.ensureDir(join28(ctx.workDir, dir));
|
|
56245
|
+
await ctx.fs.writeFile(join28(ctx.workDir, "run-date.txt"), `${ctx.runDate}
|
|
55274
56246
|
`);
|
|
55275
|
-
await ctx.fs.writeFile(
|
|
56247
|
+
await ctx.fs.writeFile(join28(ctx.workDir, ".safety-revise-count"), `0
|
|
55276
56248
|
`);
|
|
55277
56249
|
}
|
|
56250
|
+
async function unfreezeRun(ctx) {
|
|
56251
|
+
for (const name of REFRESH_PHASE_DIRS) {
|
|
56252
|
+
const path = join28(ctx.workDir, name);
|
|
56253
|
+
if (await ctx.fs.exists(path))
|
|
56254
|
+
await ctx.fs.deleteFile(path);
|
|
56255
|
+
}
|
|
56256
|
+
for (const stale of ["pool-gate.json", "bundle.json", "run-report.summary.txt"]) {
|
|
56257
|
+
const path = join28(ctx.workDir, stale);
|
|
56258
|
+
if (await ctx.fs.exists(path))
|
|
56259
|
+
await ctx.fs.deleteFile(path);
|
|
56260
|
+
}
|
|
56261
|
+
}
|
|
55278
56262
|
async function ledgerSync(ctx) {
|
|
55279
56263
|
try {
|
|
55280
56264
|
await quietStdout(() => syncLedger({ workflow: ctx.workflow, worksDir: ctx.worksDir, workDir: ctx.workDir }));
|
|
@@ -55288,6 +56272,8 @@ async function runAction(noun, defaultType, verb, options) {
|
|
|
55288
56272
|
requireWorkDir(options, verb);
|
|
55289
56273
|
const ctx = await buildContext(noun, type, verb, options);
|
|
55290
56274
|
if (verb === "prepare") {
|
|
56275
|
+
if (options.refresh === true)
|
|
56276
|
+
await unfreezeRun(ctx);
|
|
55291
56277
|
await composeWorkspace(ctx);
|
|
55292
56278
|
const summary = await runGenerateRow(rowFor(verb), ctx);
|
|
55293
56279
|
if (options.ledgerSync === true)
|
|
@@ -55335,7 +56321,7 @@ function verbCommand(group, noun, type, name, description, configure) {
|
|
|
55335
56321
|
var NEWS_ONLY_VERBS = new Set(["prepare", "generate-render", "generate-voice", "generate-cards", "report"]);
|
|
55336
56322
|
function registerContentGenerateVerbs(group, noun, defaultType) {
|
|
55337
56323
|
const workDir = (command) => command.option("--work-dir <dir>", "content run directory");
|
|
55338
|
-
verbCommand(group, noun, defaultType, "prepare", "compose the run workspace and gate the pool", (command) => workDir(command).option("--run-date <YYYYMMDD>", "news run date").option("--ledger-sync", "backfill the run ledger before the run starts"));
|
|
56324
|
+
verbCommand(group, noun, defaultType, "prepare", "compose the run workspace and gate the pool", (command) => workDir(command).option("--run-date <YYYYMMDD>", "news run date").option("--refresh", "drop the frozen pool and plan, then re-extract from the store").option("--ledger-sync", "backfill the run ledger before the run starts"));
|
|
55339
56325
|
verbCommand(group, noun, defaultType, "generate-check", "validate one agent step output", (command) => workDir(command).option("--step <step>", noun === "news" ? NEWS_CHECK_STEPS.join("|") : ARTICLE_CHECK_STEPS.join("|")).option("--final", "apply the step fallback when the fix pass left errors"));
|
|
55340
56326
|
verbCommand(group, noun, defaultType, "generate-render", "render script, article, cover and TTS input", (command) => workDir(command));
|
|
55341
56327
|
verbCommand(group, noun, defaultType, "generate-voice", "synthesize the episode with exactly one engine", (command) => workDir(command).option("--engine <engine>", VOICE_ENGINES.join("|"), "voxcpm"));
|
|
@@ -55347,11 +56333,11 @@ function registerContentGenerateVerbs(group, noun, defaultType) {
|
|
|
55347
56333
|
// src/commands/content-launch.ts
|
|
55348
56334
|
init_dist3();
|
|
55349
56335
|
init_commander();
|
|
55350
|
-
import { basename as
|
|
56336
|
+
import { basename as basename4, join as join30, resolve as resolve24 } from "path";
|
|
55351
56337
|
|
|
55352
56338
|
// src/launch.ts
|
|
55353
56339
|
import { tmpdir as tmpdir2 } from "os";
|
|
55354
|
-
import { dirname as dirname15, join as
|
|
56340
|
+
import { dirname as dirname15, join as join29, resolve as resolve23 } from "path";
|
|
55355
56341
|
init_dist3();
|
|
55356
56342
|
init_dist();
|
|
55357
56343
|
init_ledger2();
|
|
@@ -55421,7 +56407,7 @@ async function diffDirs(deps, checkout, install) {
|
|
|
55421
56407
|
`).filter((line) => line.trim() !== "").map((line) => line.split(checkout).join("checkout").split(install).join("install")).slice(0, 5);
|
|
55422
56408
|
}
|
|
55423
56409
|
async function executorProbe(deps, spurBin, target) {
|
|
55424
|
-
const probeCwd =
|
|
56410
|
+
const probeCwd = join29(tmpdir2(), `kk-preflight-${process.pid}-${deps.now().getTime()}`);
|
|
55425
56411
|
await deps.fs.ensureDir(probeCwd);
|
|
55426
56412
|
try {
|
|
55427
56413
|
const probe = await deps.spawn.run({
|
|
@@ -55455,8 +56441,8 @@ async function runPreflight(deps, context) {
|
|
|
55455
56441
|
warnings.push("running package root not found; executed-vs-installed sync not checked");
|
|
55456
56442
|
} else {
|
|
55457
56443
|
const diffs = [
|
|
55458
|
-
...await diffDirs(deps,
|
|
55459
|
-
...await diffDirs(deps,
|
|
56444
|
+
...await diffDirs(deps, join29(context.harnessRoot, "plugins", "kk", "workflows"), join29(install, "plugins", "kk", "workflows")),
|
|
56445
|
+
...await diffDirs(deps, join29(context.harnessRoot, "plugins", "kk", "scripts"), join29(install, "plugins", "kk", "scripts"))
|
|
55460
56446
|
];
|
|
55461
56447
|
if (diffs.length > 0) {
|
|
55462
56448
|
reasons.push(`checkout diverges from installed kk (${install}): ${diffs.join("; ")}`);
|
|
@@ -55564,7 +56550,7 @@ async function launchWorkflow(options) {
|
|
|
55564
56550
|
const executor = agent ?? "inline";
|
|
55565
56551
|
const harnessRoot = options.harnessRoot ?? process.cwd();
|
|
55566
56552
|
const spurBin = options.spurBin ?? process.env.KK_SPUR_BIN ?? "spur";
|
|
55567
|
-
const receiptPath = options.receiptPath ??
|
|
56553
|
+
const receiptPath = options.receiptPath ?? join29(options.workDir, "schedule-receipt.json");
|
|
55568
56554
|
const identityVar = options.identityVar === undefined ? options.type === "news" ? "run_date" : "slug" : options.identityVar;
|
|
55569
56555
|
const vars = launchVars(options, runId, agent, identityVar);
|
|
55570
56556
|
const argv = workflowArgv(options.workflowPath, runId, vars);
|
|
@@ -55662,7 +56648,7 @@ async function launchWorkflow(options) {
|
|
|
55662
56648
|
const spawnFailed = result.outcome === "error";
|
|
55663
56649
|
let status = interrupted || spawnFailed ? "failed" : timedOut ? "timeout" : "failed";
|
|
55664
56650
|
if (!interrupted && !timedOut && !spawnFailed && result.exitCode === 0) {
|
|
55665
|
-
const summary = await readOptional(deps.fs,
|
|
56651
|
+
const summary = await readOptional(deps.fs, join29(options.workDir, "run-report.summary.txt"));
|
|
55666
56652
|
status = summary?.startsWith("no-content:") === true ? "no-content" : "done";
|
|
55667
56653
|
}
|
|
55668
56654
|
const exitCode = status === "done" || status === "no-content" ? 0 : interrupted ? 143 : timedOut ? 124 : result.exitCode === null || result.exitCode === 0 ? 1 : result.exitCode;
|
|
@@ -55679,7 +56665,8 @@ async function launchWorkflow(options) {
|
|
|
55679
56665
|
}
|
|
55680
56666
|
}
|
|
55681
56667
|
}
|
|
55682
|
-
|
|
56668
|
+
const greenWithBundle = status === "done" && await deps.fs.exists(await resolveBundlePath(deps.fs, options.workDir));
|
|
56669
|
+
if (status !== "no-content" && options.workflow !== PUBLISH_WORKFLOW && !greenWithBundle) {
|
|
55683
56670
|
try {
|
|
55684
56671
|
await deps.recycleRun(runId);
|
|
55685
56672
|
} catch (error) {
|
|
@@ -55709,7 +56696,7 @@ async function launchWorkflow(options) {
|
|
|
55709
56696
|
// src/commands/content-launch.ts
|
|
55710
56697
|
init_output2();
|
|
55711
56698
|
var PUBLISH_WINDOWS = PublishWindowSchema.options;
|
|
55712
|
-
var
|
|
56699
|
+
var parseJson5 = JSON.parse.bind(JSON);
|
|
55713
56700
|
function isObject5(value) {
|
|
55714
56701
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
55715
56702
|
}
|
|
@@ -55740,13 +56727,13 @@ async function resolveWorkflowPath(workflow, config, fs) {
|
|
|
55740
56727
|
return candidate;
|
|
55741
56728
|
}
|
|
55742
56729
|
const root = await resolvePackageRoot(fs);
|
|
55743
|
-
return
|
|
56730
|
+
return join30(root, "plugins", "kk", "workflows", `${workflow}.yaml`);
|
|
55744
56731
|
}
|
|
55745
|
-
async function
|
|
56732
|
+
async function readJson4(fs, path) {
|
|
55746
56733
|
if (!await fs.exists(path))
|
|
55747
56734
|
return null;
|
|
55748
56735
|
try {
|
|
55749
|
-
const parsed =
|
|
56736
|
+
const parsed = parseJson5(await fs.readFile(path));
|
|
55750
56737
|
return isObject5(parsed) ? parsed : null;
|
|
55751
56738
|
} catch {
|
|
55752
56739
|
return null;
|
|
@@ -55793,7 +56780,7 @@ function runSelector(type, options, verb) {
|
|
|
55793
56780
|
fail2(2, `kk.content.${verb}`, "--slug is required for article content and must be a lowercase slug");
|
|
55794
56781
|
}
|
|
55795
56782
|
return {
|
|
55796
|
-
slug: options.slug ?? (suppliedWorkDir === undefined ? undefined :
|
|
56783
|
+
slug: options.slug ?? (suppliedWorkDir === undefined ? undefined : basename4(suppliedWorkDir)),
|
|
55797
56784
|
runDate: options.runDate === undefined ? undefined : normalizeRunDate2(options.runDate),
|
|
55798
56785
|
workDir: suppliedWorkDir
|
|
55799
56786
|
};
|
|
@@ -55825,8 +56812,8 @@ function validateLiveTokens(preset, window, tokens, presetName) {
|
|
|
55825
56812
|
}
|
|
55826
56813
|
async function readPreset(presetName, fs) {
|
|
55827
56814
|
const root = await resolvePackageRoot(fs);
|
|
55828
|
-
const path =
|
|
55829
|
-
return await
|
|
56815
|
+
const path = join30(root, "plugins", "kk", "publish-presets", `${presetName}.json`);
|
|
56816
|
+
return await readJson4(fs, path);
|
|
55830
56817
|
}
|
|
55831
56818
|
async function generateAction(noun, defaultType, options) {
|
|
55832
56819
|
const fs = createNodeFileSystem();
|
|
@@ -55850,8 +56837,12 @@ async function generateAction(noun, defaultType, options) {
|
|
|
55850
56837
|
const vars = { skill_dir: resolved.skillDir, preset: resolved.publish_preset };
|
|
55851
56838
|
if (options.skipReview === true)
|
|
55852
56839
|
vars.skip_review = "true";
|
|
55853
|
-
if (options.auto === true)
|
|
56840
|
+
if (options.auto === true) {
|
|
56841
|
+
if (type !== "itc") {
|
|
56842
|
+
fail2(2, "kk.content.generate", `--auto is article-only: the '${type}' workflow declares no 'auto' var`);
|
|
56843
|
+
}
|
|
55854
56844
|
vars.auto = "true";
|
|
56845
|
+
}
|
|
55855
56846
|
const receipt = await launchWorkflow({
|
|
55856
56847
|
type,
|
|
55857
56848
|
workflow: resolved.workflow,
|
|
@@ -55869,7 +56860,14 @@ async function generateAction(noun, defaultType, options) {
|
|
|
55869
56860
|
...options.dryRun === undefined ? {} : { dryRun: options.dryRun }
|
|
55870
56861
|
});
|
|
55871
56862
|
if (receipt.status !== "done" || options.publish !== true) {
|
|
55872
|
-
const
|
|
56863
|
+
const reported = options.publish === true && receipt.status !== "done" ? {
|
|
56864
|
+
...receipt,
|
|
56865
|
+
publish: {
|
|
56866
|
+
status: "skipped",
|
|
56867
|
+
reason: `generation status '${receipt.status}' \u2014 the after-generate publish window did not launch`
|
|
56868
|
+
}
|
|
56869
|
+
} : receipt;
|
|
56870
|
+
const code = reportReceipt(reported);
|
|
55873
56871
|
if (code !== 0)
|
|
55874
56872
|
fail2(code, "kk.content.generate", receipt.reason ?? `${resolved.workflow} exited ${code}`);
|
|
55875
56873
|
return;
|
|
@@ -55903,12 +56901,12 @@ function nounForType(type) {
|
|
|
55903
56901
|
}
|
|
55904
56902
|
async function publishRun(settings) {
|
|
55905
56903
|
const { fs, type, resolved, worksDir, run } = settings;
|
|
55906
|
-
const publishDir =
|
|
55907
|
-
const bundlePath =
|
|
55908
|
-
const receiptPath =
|
|
55909
|
-
const generateReceipt = await
|
|
56904
|
+
const publishDir = join30(run.workDir, "4-publish");
|
|
56905
|
+
const bundlePath = await resolveBundlePath(fs, run.workDir);
|
|
56906
|
+
const receiptPath = join30(publishDir, `schedule-receipt.${settings.window}.json`);
|
|
56907
|
+
const generateReceipt = await readJson4(fs, join30(run.workDir, "schedule-receipt.json"));
|
|
55910
56908
|
const running = typeof generateReceipt?.status === "string" && generateReceipt.status === "running";
|
|
55911
|
-
let bundle = await
|
|
56909
|
+
let bundle = await readJson4(fs, bundlePath);
|
|
55912
56910
|
if (running) {
|
|
55913
56911
|
fail2(5, "kk.content.publish", `generation for ${run.run} is still running (${run.workDir})`);
|
|
55914
56912
|
}
|
|
@@ -55939,7 +56937,7 @@ async function publishRun(settings) {
|
|
|
55939
56937
|
fail2(generated.exitCode, "kk.content.generate", generated.reason ?? `generation for ${run.run} exited ${generated.exitCode}`);
|
|
55940
56938
|
}
|
|
55941
56939
|
if (generated.dryRun === undefined) {
|
|
55942
|
-
bundle = await
|
|
56940
|
+
bundle = await readJson4(fs, bundlePath);
|
|
55943
56941
|
} else {
|
|
55944
56942
|
planned.push({ workflow: generated.workflow, ...generated.dryRun });
|
|
55945
56943
|
}
|
|
@@ -56008,7 +57006,7 @@ async function publishAction(noun, defaultType, options) {
|
|
|
56008
57006
|
const worksDir = resolveWorksDir2(config, configFile);
|
|
56009
57007
|
let runDate = selector.runDate ?? (type === "news" ? losAngelesDate(window === "overseas-rss" ? -1 : 0) : undefined);
|
|
56010
57008
|
if (type === "news" && selector.runDate === undefined && selector.workDir !== undefined) {
|
|
56011
|
-
const archived = await
|
|
57009
|
+
const archived = await readJson4(fs, join30(selector.workDir, "4-publish", "bundle.json"));
|
|
56012
57010
|
const bundleDay = typeof archived?.runDate === "string" ? normalizeRunDate2(archived.runDate) : undefined;
|
|
56013
57011
|
if (bundleDay !== undefined)
|
|
56014
57012
|
runDate = bundleDay;
|
|
@@ -56074,10 +57072,10 @@ init_dist3();
|
|
|
56074
57072
|
init_dist();
|
|
56075
57073
|
init_commander();
|
|
56076
57074
|
import { homedir as homedir10 } from "os";
|
|
56077
|
-
import { dirname as dirname16, join as
|
|
57075
|
+
import { dirname as dirname16, join as join31, resolve as resolve25 } from "path";
|
|
56078
57076
|
init_output2();
|
|
56079
57077
|
init_ledger2();
|
|
56080
|
-
var
|
|
57078
|
+
var parseJson6 = JSON.parse.bind(JSON);
|
|
56081
57079
|
function isObject6(value) {
|
|
56082
57080
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
56083
57081
|
}
|
|
@@ -56091,9 +57089,9 @@ function expandHome5(value) {
|
|
|
56091
57089
|
if (value === "~" || value === "$HOME")
|
|
56092
57090
|
return homedir10();
|
|
56093
57091
|
if (value.startsWith("~/"))
|
|
56094
|
-
return
|
|
57092
|
+
return join31(homedir10(), value.slice(2));
|
|
56095
57093
|
if (value.startsWith("$HOME/"))
|
|
56096
|
-
return
|
|
57094
|
+
return join31(homedir10(), value.slice("$HOME/".length));
|
|
56097
57095
|
return value;
|
|
56098
57096
|
}
|
|
56099
57097
|
function requireWorkDir2(options, command) {
|
|
@@ -56113,11 +57111,11 @@ function quietStdout2(action) {
|
|
|
56113
57111
|
const restore = setDefaultOutputTargets({ stdout: { write() {} } });
|
|
56114
57112
|
return action().finally(restore);
|
|
56115
57113
|
}
|
|
56116
|
-
async function
|
|
57114
|
+
async function readJson5(fs, path) {
|
|
56117
57115
|
if (!await fs.exists(path))
|
|
56118
57116
|
return null;
|
|
56119
57117
|
try {
|
|
56120
|
-
const parsed =
|
|
57118
|
+
const parsed = parseJson6(await fs.readFile(path));
|
|
56121
57119
|
return isObject6(parsed) ? parsed : null;
|
|
56122
57120
|
} catch {
|
|
56123
57121
|
return null;
|
|
@@ -56206,7 +57204,7 @@ async function planAction(type, options) {
|
|
|
56206
57204
|
...options.feed ? ["--feed", options.feed] : []
|
|
56207
57205
|
];
|
|
56208
57206
|
const code = await quietStdout2(() => runPublishMatrixRssGate(gateArgs));
|
|
56209
|
-
const result = await
|
|
57207
|
+
const result = await readJson5(fs, join31(workDir, "4-publish", "rss-gate.json"));
|
|
56210
57208
|
gate = { rss: result?.hit === true ? "hit" : "miss" };
|
|
56211
57209
|
if (code !== 0)
|
|
56212
57210
|
return commandFailure(command, 1, `publish-plan: RSS gate ${gate.rss}`);
|
|
@@ -56233,8 +57231,8 @@ async function planAction(type, options) {
|
|
|
56233
57231
|
}));
|
|
56234
57232
|
if (code !== 0)
|
|
56235
57233
|
return commandFailure(command, 1, "publish-plan: matrix planning failed");
|
|
56236
|
-
const path =
|
|
56237
|
-
const plan = PublishPlanSchema.parse.bind(PublishPlanSchema)(
|
|
57234
|
+
const path = join31(workDir, "4-publish", `plan.${context.window}.json`);
|
|
57235
|
+
const plan = PublishPlanSchema.parse.bind(PublishPlanSchema)(parseJson6(await fs.readFile(path)));
|
|
56238
57236
|
consoleOutput.write(JSON.stringify({
|
|
56239
57237
|
plan: path,
|
|
56240
57238
|
rows: plan.rows.length,
|
|
@@ -56255,8 +57253,8 @@ async function checkAction(type, options) {
|
|
|
56255
57253
|
const code = await quietStdout2(() => checkPublishMatrix(args));
|
|
56256
57254
|
if (code !== 0)
|
|
56257
57255
|
return commandFailure(command, 1, "publish-check failed");
|
|
56258
|
-
const path =
|
|
56259
|
-
const check = await
|
|
57256
|
+
const path = join31(context.workDir, "4-publish", options.allWindows ? "check.preflight.json" : `check.${context.window}.json`);
|
|
57257
|
+
const check = await readJson5(fs, path) ?? { plugins: [] };
|
|
56260
57258
|
const plugins = Array.isArray(check.plugins) ? check.plugins : [];
|
|
56261
57259
|
const warnings = plugins.filter((plugin) => isObject6(plugin) && plugin.ok !== true).map((plugin) => `${String(plugin.plugin ?? "unknown")}: ${String(plugin.detail ?? "not ready")}`);
|
|
56262
57260
|
consoleOutput.write(JSON.stringify({
|
|
@@ -56266,12 +57264,12 @@ async function checkAction(type, options) {
|
|
|
56266
57264
|
}));
|
|
56267
57265
|
}
|
|
56268
57266
|
async function receiptFiles(fs, workDir) {
|
|
56269
|
-
const dir =
|
|
57267
|
+
const dir = join31(workDir, "4-publish", "receipts");
|
|
56270
57268
|
if (!await fs.exists(dir))
|
|
56271
57269
|
return [];
|
|
56272
57270
|
const names = (await fs.readDir(dir)).filter((name) => name.endsWith(".json"));
|
|
56273
57271
|
return (await Promise.all(names.map(async (name) => {
|
|
56274
|
-
const value = await
|
|
57272
|
+
const value = await readJson5(fs, join31(dir, name));
|
|
56275
57273
|
return value === null ? undefined : ReceiptSchema.safeParse(value).data;
|
|
56276
57274
|
}))).filter((value) => value !== undefined);
|
|
56277
57275
|
}
|
|
@@ -56284,7 +57282,8 @@ async function sendAction(type, options) {
|
|
|
56284
57282
|
"--window",
|
|
56285
57283
|
context.window,
|
|
56286
57284
|
...options.retry ? ["--retry"] : [],
|
|
56287
|
-
...options.tier ? ["--tier", options.tier] : []
|
|
57285
|
+
...options.tier ? ["--tier", options.tier] : [],
|
|
57286
|
+
...options.confirmNone ? ["--confirm-none"] : []
|
|
56288
57287
|
];
|
|
56289
57288
|
const code = await quietStdout2(() => sendPublishMatrix(args));
|
|
56290
57289
|
if (code !== 0)
|
|
@@ -56294,14 +57293,14 @@ async function sendAction(type, options) {
|
|
|
56294
57293
|
sent: receipts.filter((receipt) => receipt.status === "succeeded").length,
|
|
56295
57294
|
failed: receipts.filter((receipt) => receipt.status === "failed").length,
|
|
56296
57295
|
uncertain: receipts.filter((receipt) => receipt.status === "uncertain").length,
|
|
56297
|
-
receipts:
|
|
57296
|
+
receipts: join31(context.workDir, "4-publish", "receipts")
|
|
56298
57297
|
}));
|
|
56299
57298
|
}
|
|
56300
57299
|
async function appendBundleRun(fs, workDir) {
|
|
56301
57300
|
const path = await resolveBundlePath(fs, workDir);
|
|
56302
57301
|
if (!await fs.exists(path))
|
|
56303
57302
|
throw new Error(`bundle.json not found at ${path}`);
|
|
56304
|
-
const parsed = BundleSchema.parse.bind(BundleSchema)(
|
|
57303
|
+
const parsed = BundleSchema.parse.bind(BundleSchema)(parseJson6(await fs.readFile(path)));
|
|
56305
57304
|
const runId = parsed.runId;
|
|
56306
57305
|
if (!parsed.runs.includes(runId))
|
|
56307
57306
|
parsed.runs.push(runId);
|
|
@@ -56318,7 +57317,7 @@ async function settleAction(type, options) {
|
|
|
56318
57317
|
if (context.window === "after-generate") {
|
|
56319
57318
|
await quietStdout2(() => runStageCancellable(["publish-matrix-patch-surfdash", context.workDir, "--window", context.window]));
|
|
56320
57319
|
}
|
|
56321
|
-
const statusPath =
|
|
57320
|
+
const statusPath = join31(context.workDir, "4-publish", `publish-status.${context.window}.txt`);
|
|
56322
57321
|
if (await fs.exists(statusPath) && /^(full|partial|none)$/.test((await fs.readFile(statusPath)).trim())) {
|
|
56323
57322
|
await quietStdout2(() => runStageCancellable(["publish-matrix-partial", context.workDir, "--window", context.window]));
|
|
56324
57323
|
}
|
|
@@ -56338,17 +57337,17 @@ async function settleAction(type, options) {
|
|
|
56338
57337
|
} catch (error) {
|
|
56339
57338
|
return commandFailure(command, 1, `publish-settle: ${error instanceof Error ? error.message : String(error)}`);
|
|
56340
57339
|
}
|
|
56341
|
-
const outcomePath =
|
|
56342
|
-
const outcome = PublishOutcomeSchema.parse.bind(PublishOutcomeSchema)(
|
|
57340
|
+
const outcomePath = join31(context.workDir, "4-publish", `outcome.${context.window}.json`);
|
|
57341
|
+
const outcome = PublishOutcomeSchema.parse.bind(PublishOutcomeSchema)(parseJson6(await fs.readFile(outcomePath)));
|
|
56343
57342
|
const failedRequired = outcome.rows.some((row) => row.required && !row.dummy && row.status !== "succeeded");
|
|
56344
57343
|
consoleOutput.write(JSON.stringify(outcome));
|
|
56345
57344
|
if (settleCode !== 0 || failedRequired)
|
|
56346
57345
|
throw new CommanderError(1, command, "publish-settle: required targets failed");
|
|
56347
57346
|
}
|
|
56348
57347
|
async function renderReport(fs, workDir, window) {
|
|
56349
|
-
const statusPath =
|
|
57348
|
+
const statusPath = join31(workDir, "4-publish", `publish-status.${window}.txt`);
|
|
56350
57349
|
const status = await fs.exists(statusPath) ? (await fs.readFile(statusPath)).trim() : "unknown";
|
|
56351
|
-
const outcome = await
|
|
57350
|
+
const outcome = await readJson5(fs, join31(workDir, "4-publish", `outcome.${window}.json`));
|
|
56352
57351
|
const runDate = typeof outcome?.runDate === "string" ? outcome.runDate : "";
|
|
56353
57352
|
const rows = Array.isArray(outcome?.rows) ? outcome.rows : [];
|
|
56354
57353
|
const excluded = Array.isArray(outcome?.excluded) ? outcome.excluded : [];
|
|
@@ -56370,7 +57369,7 @@ async function reportAction(type, options) {
|
|
|
56370
57369
|
const command = "kk.content.publish-report";
|
|
56371
57370
|
const fs = createNodeFileSystem();
|
|
56372
57371
|
const context = await loadContext(type, options, command, fs);
|
|
56373
|
-
const reportPath =
|
|
57372
|
+
const reportPath = join31(context.workDir, "5-report", `publish-${context.window}.md`);
|
|
56374
57373
|
await fs.ensureDir(dirname16(reportPath));
|
|
56375
57374
|
await fs.writeFile(reportPath, await renderReport(fs, context.workDir, context.window));
|
|
56376
57375
|
try {
|
|
@@ -56383,11 +57382,11 @@ async function reportAction(type, options) {
|
|
|
56383
57382
|
consoleOutput.error(`publish-report: ledger sync warning: ${error instanceof Error ? error.message : String(error)}`);
|
|
56384
57383
|
}
|
|
56385
57384
|
consoleOutput.write(JSON.stringify({ report: reportPath }));
|
|
56386
|
-
const outcomePath =
|
|
57385
|
+
const outcomePath = join31(context.workDir, "4-publish", `outcome.${context.window}.json`);
|
|
56387
57386
|
if (await fs.exists(outcomePath)) {
|
|
56388
57387
|
let rows;
|
|
56389
57388
|
try {
|
|
56390
|
-
const parsed =
|
|
57389
|
+
const parsed = parseJson6(await fs.readFile(outcomePath));
|
|
56391
57390
|
rows = isOutcomeRows(parsed) ? parsed.rows : [];
|
|
56392
57391
|
} catch {
|
|
56393
57392
|
return commandFailure(command, 1, `publish-report: ${outcomePath} is unreadable or malformed`);
|
|
@@ -56420,7 +57419,7 @@ function registerContentPublishVerbs(parent, type) {
|
|
|
56420
57419
|
base(command).option("--preset <name>", "publish preset").option("--all-windows", "probe every preset window");
|
|
56421
57420
|
}, checkAction, type);
|
|
56422
57421
|
publishCommand(parent, "publish-send", "dispatch a frozen publish plan", (command) => {
|
|
56423
|
-
base(command).option("--retry", "retry effect-none failures").option("--tier <n>", "send one tier");
|
|
57422
|
+
base(command).option("--retry", "retry effect-none failures").option("--tier <n>", "send one tier").option("--confirm-none", "re-attempt a live row whose effect is unknown, after verifying it published nothing");
|
|
56424
57423
|
}, sendAction, type);
|
|
56425
57424
|
publishCommand(parent, "publish-settle", "classify and settle a publish window", (command) => {
|
|
56426
57425
|
base(command).option("--topic <topic>", "store topic").option("--db <path>", "store database path");
|
|
@@ -56429,7 +57428,7 @@ function registerContentPublishVerbs(parent, type) {
|
|
|
56429
57428
|
}
|
|
56430
57429
|
|
|
56431
57430
|
// src/commands/content.ts
|
|
56432
|
-
var
|
|
57431
|
+
var parseJson7 = JSON.parse.bind(JSON);
|
|
56433
57432
|
var parseYaml2 = Bun.YAML.parse.bind(Bun.YAML);
|
|
56434
57433
|
function isObject7(value) {
|
|
56435
57434
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -56453,11 +57452,11 @@ function expandHome4(value) {
|
|
|
56453
57452
|
if (value === "~")
|
|
56454
57453
|
return homedir11();
|
|
56455
57454
|
if (value.startsWith("~/"))
|
|
56456
|
-
return
|
|
57455
|
+
return join32(homedir11(), value.slice(2));
|
|
56457
57456
|
if (value === "$HOME")
|
|
56458
57457
|
return homedir11();
|
|
56459
57458
|
if (value.startsWith("$HOME/"))
|
|
56460
|
-
return
|
|
57459
|
+
return join32(homedir11(), value.slice("$HOME/".length));
|
|
56461
57460
|
return value;
|
|
56462
57461
|
}
|
|
56463
57462
|
function resolveWorksDir2(config, path) {
|
|
@@ -56551,9 +57550,9 @@ function splitMarkdown(markdown, fallbackTitle, titleOverride) {
|
|
|
56551
57550
|
return { title, body };
|
|
56552
57551
|
}
|
|
56553
57552
|
async function writeSeededContent(fs, workDir, locale, markdown, options) {
|
|
56554
|
-
const contentDir =
|
|
57553
|
+
const contentDir = join32(workDir, "content", locale);
|
|
56555
57554
|
await fs.ensureDir(contentDir);
|
|
56556
|
-
await fs.writeFile(
|
|
57555
|
+
await fs.writeFile(join32(contentDir, "article.md"), markdown);
|
|
56557
57556
|
const fallbackTitle = options.slug?.replaceAll("-", " ") ?? "article";
|
|
56558
57557
|
const article = splitMarkdown(markdown, fallbackTitle, options.title);
|
|
56559
57558
|
if (article.body === "")
|
|
@@ -56568,13 +57567,13 @@ async function writeSeededContent(fs, workDir, locale, markdown, options) {
|
|
|
56568
57567
|
...options.description !== undefined ? { description: options.description } : {}
|
|
56569
57568
|
}
|
|
56570
57569
|
};
|
|
56571
|
-
const publishDir =
|
|
57570
|
+
const publishDir = join32(workDir, "4-publish");
|
|
56572
57571
|
await fs.ensureDir(publishDir);
|
|
56573
|
-
await fs.writeFile(
|
|
57572
|
+
await fs.writeFile(join32(publishDir, "content.json"), `${JSON.stringify(content, null, 2)}
|
|
56574
57573
|
`);
|
|
56575
57574
|
}
|
|
56576
57575
|
async function seedItcPreparation(fs, workDir, run, options, preset) {
|
|
56577
|
-
const launchPath =
|
|
57576
|
+
const launchPath = join32(workDir, ".content-itc-prepare.json");
|
|
56578
57577
|
const launch = {
|
|
56579
57578
|
topic: options.slug ?? run.run,
|
|
56580
57579
|
sourceLocale: options.locale ?? "en",
|
|
@@ -56631,7 +57630,7 @@ async function newAction(defaultType, options, article) {
|
|
|
56631
57630
|
workflow: resolved.workflow,
|
|
56632
57631
|
config
|
|
56633
57632
|
});
|
|
56634
|
-
const requestPath =
|
|
57633
|
+
const requestPath = join32(run.workDir, "request.json");
|
|
56635
57634
|
if (await fs.exists(requestPath)) {
|
|
56636
57635
|
consoleOutput.write(JSON.stringify({ workDir: run.workDir, run: run.run, type, created: false }));
|
|
56637
57636
|
return;
|
|
@@ -56650,54 +57649,54 @@ async function newAction(defaultType, options, article) {
|
|
|
56650
57649
|
await writeSeededContent(fs, run.workDir, locale, await fs.readFile(fromPath), options);
|
|
56651
57650
|
if (options.cover !== undefined) {
|
|
56652
57651
|
const coverPath = resolve26(expandHome4(options.cover));
|
|
56653
|
-
const coverDir =
|
|
57652
|
+
const coverDir = join32(run.workDir, "4-illustrations");
|
|
56654
57653
|
await fs.ensureDir(coverDir);
|
|
56655
|
-
await fs.copy(coverPath,
|
|
57654
|
+
await fs.copy(coverPath, join32(coverDir, `cover${extname(coverPath) || ".png"}`));
|
|
56656
57655
|
}
|
|
56657
57656
|
const request = requestObject(type, resolved, run, options, locale, variants, run.workDir);
|
|
56658
57657
|
await fs.writeFile(requestPath, `${JSON.stringify(request, null, 2)}
|
|
56659
57658
|
`);
|
|
56660
57659
|
consoleOutput.write(JSON.stringify({ workDir: run.workDir, run: run.run, type, created: true }));
|
|
56661
57660
|
}
|
|
56662
|
-
function
|
|
57661
|
+
function optionalString3(value) {
|
|
56663
57662
|
return typeof value === "string" ? value : null;
|
|
56664
57663
|
}
|
|
56665
|
-
async function
|
|
57664
|
+
async function readJson6(fs, path) {
|
|
56666
57665
|
if (!await fs.exists(path))
|
|
56667
57666
|
return null;
|
|
56668
57667
|
try {
|
|
56669
|
-
const value =
|
|
57668
|
+
const value = parseJson7(await fs.readFile(path));
|
|
56670
57669
|
return isObject7(value) ? value : null;
|
|
56671
57670
|
} catch {
|
|
56672
57671
|
return null;
|
|
56673
57672
|
}
|
|
56674
57673
|
}
|
|
56675
57674
|
async function statusPayload(fs, workDir, type, selectedWindow) {
|
|
56676
|
-
const receipt = await
|
|
57675
|
+
const receipt = await readJson6(fs, join32(workDir, "schedule-receipt.json"));
|
|
56677
57676
|
const generate = receipt === null ? null : {
|
|
56678
|
-
status:
|
|
56679
|
-
runId:
|
|
56680
|
-
executor:
|
|
56681
|
-
checkoutCommit:
|
|
57677
|
+
status: optionalString3(receipt.status),
|
|
57678
|
+
runId: optionalString3(receipt.runId),
|
|
57679
|
+
executor: optionalString3(receipt.executor),
|
|
57680
|
+
checkoutCommit: optionalString3(receipt.checkoutCommit)
|
|
56682
57681
|
};
|
|
56683
|
-
const bundle = await
|
|
57682
|
+
const bundle = await readJson6(fs, join32(workDir, "4-publish", "bundle.json"));
|
|
56684
57683
|
const bundleSummary = bundle === null ? null : {
|
|
56685
57684
|
frozen: typeof bundle.frozen === "boolean" ? bundle.frozen : null,
|
|
56686
|
-
runId:
|
|
57685
|
+
runId: optionalString3(bundle.runId),
|
|
56687
57686
|
variants: bundle.variants ?? null
|
|
56688
57687
|
};
|
|
56689
57688
|
const windows = {};
|
|
56690
|
-
const publishDir =
|
|
57689
|
+
const publishDir = join32(workDir, "4-publish");
|
|
56691
57690
|
if (await fs.exists(publishDir)) {
|
|
56692
57691
|
for (const name of (await fs.readDir(publishDir)).filter((entry) => /^outcome\.[^.]+\.json$/.test(entry)).sort()) {
|
|
56693
|
-
const outcome = await
|
|
57692
|
+
const outcome = await readJson6(fs, join32(publishDir, name));
|
|
56694
57693
|
if (outcome === null)
|
|
56695
57694
|
continue;
|
|
56696
|
-
const window =
|
|
57695
|
+
const window = optionalString3(outcome.window) ?? name.slice("outcome.".length, -".json".length);
|
|
56697
57696
|
if (selectedWindow !== undefined && selectedWindow !== window)
|
|
56698
57697
|
continue;
|
|
56699
57698
|
windows[window] = {
|
|
56700
|
-
status:
|
|
57699
|
+
status: optionalString3(outcome.status),
|
|
56701
57700
|
published: outcome.published ?? null,
|
|
56702
57701
|
targets: outcome.targets ?? null
|
|
56703
57702
|
};
|
|
@@ -56708,7 +57707,9 @@ async function statusPayload(fs, workDir, type, selectedWindow) {
|
|
|
56708
57707
|
type,
|
|
56709
57708
|
generate,
|
|
56710
57709
|
bundle: bundleSummary,
|
|
56711
|
-
windows: Object.keys(windows).length === 0 ? null : windows
|
|
57710
|
+
windows: Object.keys(windows).length === 0 ? null : windows,
|
|
57711
|
+
progress: await progressPayload(fs, workDir),
|
|
57712
|
+
gate: await gatePayload(fs, workDir)
|
|
56712
57713
|
};
|
|
56713
57714
|
}
|
|
56714
57715
|
async function statusAction(defaultType, options) {
|
|
@@ -56724,7 +57725,7 @@ async function statusAction(defaultType, options) {
|
|
|
56724
57725
|
const resolved = await resolveType(type, config, configFile);
|
|
56725
57726
|
const worksDir = resolveWorksDir2(config, configFile);
|
|
56726
57727
|
const suppliedWorkDir = options.workDir === undefined ? undefined : resolve26(expandHome4(options.workDir));
|
|
56727
|
-
const slug = options.slug ?? (suppliedWorkDir === undefined ? undefined :
|
|
57728
|
+
const slug = options.slug ?? (suppliedWorkDir === undefined ? undefined : basename5(suppliedWorkDir));
|
|
56728
57729
|
const runDate = options.runDate;
|
|
56729
57730
|
if (runDate !== undefined && !validCalendarDate(runDate)) {
|
|
56730
57731
|
fail3(2, "kk.content.status", "--run-date must be a real calendar date as YYYYMMDD");
|
|
@@ -56776,7 +57777,7 @@ init_commander();
|
|
|
56776
57777
|
|
|
56777
57778
|
// src/fanin.ts
|
|
56778
57779
|
import { tmpdir as tmpdir3 } from "os";
|
|
56779
|
-
import { isAbsolute as isAbsolute9, join as
|
|
57780
|
+
import { isAbsolute as isAbsolute9, join as join33, resolve as resolve27 } from "path";
|
|
56780
57781
|
init_dist3();
|
|
56781
57782
|
init_dist();
|
|
56782
57783
|
var DEFAULT_SOURCE_TIMEOUT_MS = 30 * 60 * 1000;
|
|
@@ -56972,7 +57973,7 @@ async function collectSourceDocs(discovery, source, timeoutMs) {
|
|
|
56972
57973
|
if (!await fs.exists(entryPath)) {
|
|
56973
57974
|
throw new Error(`Plugin entry script does not exist: ${entryPath}`);
|
|
56974
57975
|
}
|
|
56975
|
-
const outTmp =
|
|
57976
|
+
const outTmp = join33(tmpdir3(), `kk-fanin-${source.plugin}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
|
|
56976
57977
|
try {
|
|
56977
57978
|
const proc = await spawnPluginEntryAsync({
|
|
56978
57979
|
entryPath,
|
|
@@ -57178,7 +58179,7 @@ function registerExecutorCommand(program) {
|
|
|
57178
58179
|
init_commander();
|
|
57179
58180
|
|
|
57180
58181
|
// src/itc-candidates.ts
|
|
57181
|
-
import { join as
|
|
58182
|
+
import { join as join34 } from "path";
|
|
57182
58183
|
init_dist3();
|
|
57183
58184
|
init_dist();
|
|
57184
58185
|
init_zod();
|
|
@@ -57204,7 +58205,7 @@ function buildTopicCandidates(pool) {
|
|
|
57204
58205
|
return candidates;
|
|
57205
58206
|
}
|
|
57206
58207
|
async function runItcCandidates(options, fs = createNodeFileSystem(), executor) {
|
|
57207
|
-
const intakeDir = options.intakeDir ??
|
|
58208
|
+
const intakeDir = options.intakeDir ?? join34(process.cwd(), ".itc-intake", options.parentRunId);
|
|
57208
58209
|
const { count: poolCount } = await itcTopicExtract({
|
|
57209
58210
|
schemaVersion: 1,
|
|
57210
58211
|
parentRunId: options.parentRunId,
|
|
@@ -57215,13 +58216,13 @@ async function runItcCandidates(options, fs = createNodeFileSystem(), executor)
|
|
|
57215
58216
|
...options.limit ? { limit: options.limit } : {},
|
|
57216
58217
|
...options.dbPath ? { dbPath: options.dbPath } : {}
|
|
57217
58218
|
}, fs);
|
|
57218
|
-
const pool = array(DocSchema).parse(JSON.parse(await fs.readFile(
|
|
57219
|
-
const manifest = JSON.parse(await fs.readFile(
|
|
58219
|
+
const pool = array(DocSchema).parse(JSON.parse(await fs.readFile(join34(intakeDir, "topic-pool.json"))));
|
|
58220
|
+
const manifest = JSON.parse(await fs.readFile(join34(intakeDir, "topic-pool-manifest.json")));
|
|
57220
58221
|
const candidates = buildTopicCandidates(pool);
|
|
57221
58222
|
if (candidates.length === 0) {
|
|
57222
58223
|
throw new Error(`no citable pool item carries a source URI: cannot build topic candidates from ${poolCount} items`);
|
|
57223
58224
|
}
|
|
57224
|
-
await fs.writeFile(
|
|
58225
|
+
await fs.writeFile(join34(intakeDir, "topic-candidates.json"), `${JSON.stringify({
|
|
57225
58226
|
schemaVersion: 1,
|
|
57226
58227
|
parentRunId: options.parentRunId,
|
|
57227
58228
|
poolDigest: manifest.poolDigest,
|
|
@@ -57233,8 +58234,8 @@ async function runItcCandidates(options, fs = createNodeFileSystem(), executor)
|
|
|
57233
58234
|
parentRunId: options.parentRunId,
|
|
57234
58235
|
decisionId: "kk-itc-topic-choice",
|
|
57235
58236
|
candidates: candidates.map((c) => ({ id: c.id, title: c.title, description: c.reason })),
|
|
57236
|
-
evidenceFiles: [
|
|
57237
|
-
outPath:
|
|
58237
|
+
evidenceFiles: [join34(intakeDir, "topic-candidates.json")],
|
|
58238
|
+
outPath: join34(intakeDir, "topic-decision.json")
|
|
57238
58239
|
}, fs, executor);
|
|
57239
58240
|
for (const c of candidates) {
|
|
57240
58241
|
echo(`${c.id} \u2014 ${c.title}`);
|
|
@@ -57741,7 +58742,7 @@ function registerStageCommand(program) {
|
|
|
57741
58742
|
}
|
|
57742
58743
|
|
|
57743
58744
|
// src/commands/store.ts
|
|
57744
|
-
import { dirname as dirname18, join as
|
|
58745
|
+
import { dirname as dirname18, join as join36, resolve as resolve31 } from "path";
|
|
57745
58746
|
init_dist3();
|
|
57746
58747
|
init_commander();
|
|
57747
58748
|
|
|
@@ -57749,7 +58750,7 @@ init_commander();
|
|
|
57749
58750
|
init_dist3();
|
|
57750
58751
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
57751
58752
|
import { tmpdir as tmpdir4 } from "os";
|
|
57752
|
-
import { join as
|
|
58753
|
+
import { join as join35, resolve as resolve30 } from "path";
|
|
57753
58754
|
var STORE_CATALOG_PATH_REL = "plugins/kk/decisions/kk-items.yaml";
|
|
57754
58755
|
var SPUR_CONFIG_PATH_REL = ".spur/config.yaml";
|
|
57755
58756
|
var EVIDENCE_MAX_CHARS = 2000;
|
|
@@ -57778,7 +58779,7 @@ async function loadInjectedHub() {
|
|
|
57778
58779
|
}
|
|
57779
58780
|
async function readDecisionRouting(projectRoot, fs = createNodeFileSystem()) {
|
|
57780
58781
|
const catalogPath = await resolveCatalogPath(projectRoot, fs);
|
|
57781
|
-
const configPath =
|
|
58782
|
+
const configPath = join35(projectRoot, SPUR_CONFIG_PATH_REL);
|
|
57782
58783
|
if (!await fs.exists(configPath))
|
|
57783
58784
|
return { catalogPath, routing: { makers: {} } };
|
|
57784
58785
|
let parsed;
|
|
@@ -57862,8 +58863,8 @@ function createBufferedDecisionFetch(inner = fetch) {
|
|
|
57862
58863
|
var bufferedDecisionFetch = createBufferedDecisionFetch();
|
|
57863
58864
|
function runDecisionSubprocess(decisionId, input, maker, fs = createNodeFileSystem()) {
|
|
57864
58865
|
const command = process.env.KK_SPUR_BIN ?? "spur";
|
|
57865
|
-
const scratch =
|
|
57866
|
-
const evidencePath =
|
|
58866
|
+
const scratch = join35(tmpdir4(), `kk-decision-${randomUUID2()}`);
|
|
58867
|
+
const evidencePath = join35(scratch, "evidence.md");
|
|
57867
58868
|
try {
|
|
57868
58869
|
fs.writeFile(evidencePath, input.body);
|
|
57869
58870
|
const args = [
|
|
@@ -58011,7 +59012,7 @@ async function ingestAction(options) {
|
|
|
58011
59012
|
failLoud6("kk.store.ingest.failed", error);
|
|
58012
59013
|
}
|
|
58013
59014
|
}
|
|
58014
|
-
var
|
|
59015
|
+
var parseJson8 = JSON.parse;
|
|
58015
59016
|
var parseYaml3 = Bun.YAML.parse;
|
|
58016
59017
|
function parseLabelMode(raw) {
|
|
58017
59018
|
if (raw !== "heuristic" && raw !== "decision") {
|
|
@@ -58025,7 +59026,7 @@ async function readNewIds(fs, path) {
|
|
|
58025
59026
|
}
|
|
58026
59027
|
let parsed;
|
|
58027
59028
|
try {
|
|
58028
|
-
parsed =
|
|
59029
|
+
parsed = parseJson8(await fs.readFile(path));
|
|
58029
59030
|
} catch {
|
|
58030
59031
|
throw new Error(`new-ids file is not valid JSON: ${path}`);
|
|
58031
59032
|
}
|
|
@@ -58036,7 +59037,7 @@ async function readNewIds(fs, path) {
|
|
|
58036
59037
|
}
|
|
58037
59038
|
function parseMetadata(raw) {
|
|
58038
59039
|
try {
|
|
58039
|
-
const parsed =
|
|
59040
|
+
const parsed = parseJson8(raw);
|
|
58040
59041
|
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
58041
59042
|
} catch {
|
|
58042
59043
|
return {};
|
|
@@ -58099,8 +59100,8 @@ async function readAnnotations(fs, outputPath) {
|
|
|
58099
59100
|
async function heuristicAnnotations(fs, scratch, runId, items) {
|
|
58100
59101
|
if (items.length === 0)
|
|
58101
59102
|
return new Map;
|
|
58102
|
-
const inputPath =
|
|
58103
|
-
const outputPath =
|
|
59103
|
+
const inputPath = join36(scratch, "label-input.json");
|
|
59104
|
+
const outputPath = join36(scratch, "label-out.json");
|
|
58104
59105
|
await fs.ensureDir(scratch);
|
|
58105
59106
|
const docs = items.map((item) => ({
|
|
58106
59107
|
id: item.id,
|
|
@@ -58451,7 +59452,7 @@ async function labelAction(options) {
|
|
|
58451
59452
|
const mode = parseLabelMode(options.mode);
|
|
58452
59453
|
const configPath = resolveKkConfigPath();
|
|
58453
59454
|
const dbPath = await resolveStorePath(configPath, options.db);
|
|
58454
|
-
const scratch =
|
|
59455
|
+
const scratch = join36(dirname18(plan.kind === "new-ids" ? plan.newIds : dbPath), LABEL_SCRATCH_DIR);
|
|
58455
59456
|
const store = await openStore({ path: dbPath });
|
|
58456
59457
|
const catalogVersion = await readCatalogVersion(fs);
|
|
58457
59458
|
const labels = (await readStoreConfig(configPath)).labels;
|
|
@@ -58551,7 +59552,7 @@ async function readPoolDocs(fs, path) {
|
|
|
58551
59552
|
}
|
|
58552
59553
|
let parsed;
|
|
58553
59554
|
try {
|
|
58554
|
-
parsed =
|
|
59555
|
+
parsed = parseJson8(await fs.readFile(path));
|
|
58555
59556
|
} catch {
|
|
58556
59557
|
throw new Error(`input file is not valid JSON: ${path}`);
|
|
58557
59558
|
}
|
|
@@ -58758,7 +59759,7 @@ init_commander();
|
|
|
58758
59759
|
init_output2();
|
|
58759
59760
|
|
|
58760
59761
|
// src/wiki/ingest.ts
|
|
58761
|
-
import { extname as extname2, isAbsolute as isAbsolute14, join as
|
|
59762
|
+
import { extname as extname2, isAbsolute as isAbsolute14, join as join43 } from "path";
|
|
58762
59763
|
|
|
58763
59764
|
// ../../packages/kk-wiki/src/compile.ts
|
|
58764
59765
|
function oneLineSummary(body) {
|
|
@@ -58960,11 +59961,11 @@ ${page.body.trim()}
|
|
|
58960
59961
|
`, pages: included.map((page) => page.path) };
|
|
58961
59962
|
}
|
|
58962
59963
|
// ../../packages/kk-wiki/src/gc.ts
|
|
58963
|
-
import { dirname as dirname19, isAbsolute as isAbsolute10, join as
|
|
59964
|
+
import { dirname as dirname19, isAbsolute as isAbsolute10, join as join37 } from "path";
|
|
58964
59965
|
async function planGc(index, options) {
|
|
58965
59966
|
const fs = options.fileSystem;
|
|
58966
59967
|
const root = dirname19(options.rawDir);
|
|
58967
|
-
const mirrorPaths = (options.mirrors ?? []).map((mirror) => isAbsolute10(mirror) ? mirror :
|
|
59968
|
+
const mirrorPaths = (options.mirrors ?? []).map((mirror) => isAbsolute10(mirror) ? mirror : join37(root, mirror));
|
|
58968
59969
|
const referenced = new Set;
|
|
58969
59970
|
for (const page of index.pages) {
|
|
58970
59971
|
for (const source of page.frontmatter.sources)
|
|
@@ -58972,16 +59973,16 @@ async function planGc(index, options) {
|
|
|
58972
59973
|
}
|
|
58973
59974
|
const candidates = [];
|
|
58974
59975
|
for (const type of ["url", "pdf", "html", "rss"]) {
|
|
58975
|
-
const dir =
|
|
59976
|
+
const dir = join37(options.rawDir, type);
|
|
58976
59977
|
if (!await fs.exists(dir))
|
|
58977
59978
|
continue;
|
|
58978
59979
|
for (const name of await fs.readDir(dir))
|
|
58979
|
-
candidates.push(
|
|
59980
|
+
candidates.push(join37(dir, name));
|
|
58980
59981
|
}
|
|
58981
|
-
const tmpDir =
|
|
59982
|
+
const tmpDir = join37(options.rawDir, "tmp");
|
|
58982
59983
|
if (await fs.exists(tmpDir)) {
|
|
58983
59984
|
for (const name of await fs.readDir(tmpDir))
|
|
58984
|
-
candidates.push(
|
|
59985
|
+
candidates.push(join37(tmpDir, name));
|
|
58985
59986
|
}
|
|
58986
59987
|
const skippedMirrors = (options.mirrors ?? []).filter((_, index) => {
|
|
58987
59988
|
const path = mirrorPaths[index];
|
|
@@ -59117,7 +60118,7 @@ function resolveLink(index, link) {
|
|
|
59117
60118
|
}
|
|
59118
60119
|
// ../../packages/kk-wiki/src/link.ts
|
|
59119
60120
|
init_dist3();
|
|
59120
|
-
import { join as
|
|
60121
|
+
import { join as join38 } from "path";
|
|
59121
60122
|
|
|
59122
60123
|
// ../../packages/kk-wiki/src/write.ts
|
|
59123
60124
|
function guardHeading(date) {
|
|
@@ -59228,7 +60229,7 @@ async function fixLinks(index, options = { date: "" }) {
|
|
|
59228
60229
|
const changed = [];
|
|
59229
60230
|
const refused = [];
|
|
59230
60231
|
for (const [path, pageMentions] of grouped) {
|
|
59231
|
-
const raw = await fs.readFile(
|
|
60232
|
+
const raw = await fs.readFile(join38(contentDir, path));
|
|
59232
60233
|
const page = parsePage(raw, path);
|
|
59233
60234
|
const rewritten = rewriteBody(page.body, pageMentions, parseFrontmatter(raw).bodyStartLine);
|
|
59234
60235
|
const { text, guard } = applyWriteToPage(page, rewritten, {
|
|
@@ -59239,7 +60240,7 @@ async function fixLinks(index, options = { date: "" }) {
|
|
|
59239
60240
|
changed.push(path);
|
|
59240
60241
|
continue;
|
|
59241
60242
|
}
|
|
59242
|
-
await fs.writeFile(
|
|
60243
|
+
await fs.writeFile(join38(contentDir, path), text);
|
|
59243
60244
|
if (guard === "appended")
|
|
59244
60245
|
refused.push(path);
|
|
59245
60246
|
else
|
|
@@ -59290,7 +60291,7 @@ function lintExitCode(findings) {
|
|
|
59290
60291
|
init_dist3();
|
|
59291
60292
|
import { createHash as createHash11 } from "crypto";
|
|
59292
60293
|
import { tmpdir as tmpdir5 } from "os";
|
|
59293
|
-
import { isAbsolute as isAbsolute11, join as
|
|
60294
|
+
import { isAbsolute as isAbsolute11, join as join39 } from "path";
|
|
59294
60295
|
|
|
59295
60296
|
class MissingNormalizerError extends Error {
|
|
59296
60297
|
binary;
|
|
@@ -59319,7 +60320,7 @@ function createMarkitdownRunner(options = {}) {
|
|
|
59319
60320
|
let target = input.target;
|
|
59320
60321
|
if (input.kind === "html") {
|
|
59321
60322
|
const id = createHash11("sha256").update(input.body ?? "").digest("hex").slice(0, 12);
|
|
59322
|
-
tempPath =
|
|
60323
|
+
tempPath = join39(tmpdir5(), `kk-wiki-${id}.html`);
|
|
59323
60324
|
await fs.writeFile(tempPath, input.body ?? "");
|
|
59324
60325
|
target = tempPath;
|
|
59325
60326
|
}
|
|
@@ -59413,7 +60414,7 @@ ${source.body.replace(/^\s+/, "")}`;
|
|
|
59413
60414
|
};
|
|
59414
60415
|
}
|
|
59415
60416
|
// ../../packages/kk-wiki/src/publish.ts
|
|
59416
|
-
import { dirname as dirname20, isAbsolute as isAbsolute12, join as
|
|
60417
|
+
import { dirname as dirname20, isAbsolute as isAbsolute12, join as join40, relative as relative6, resolve as resolve32 } from "path";
|
|
59417
60418
|
function isInside(parent, child) {
|
|
59418
60419
|
const rel = relative6(parent, child);
|
|
59419
60420
|
return rel === "" || !rel.startsWith("..") && !isAbsolute12(rel);
|
|
@@ -59425,11 +60426,11 @@ async function publishVault(index, options) {
|
|
|
59425
60426
|
const fs = options.fileSystem;
|
|
59426
60427
|
const files = [];
|
|
59427
60428
|
for (const page of index.pages) {
|
|
59428
|
-
const source =
|
|
59429
|
-
const destination =
|
|
60429
|
+
const source = join40(index.contentDir, page.path);
|
|
60430
|
+
const destination = join40(targetRoot, "content", page.path);
|
|
59430
60431
|
await fs.ensureDir(dirname20(destination));
|
|
59431
60432
|
await fs.writeFile(destination, await fs.readFile(source));
|
|
59432
|
-
files.push(
|
|
60433
|
+
files.push(join40("content", page.path));
|
|
59433
60434
|
}
|
|
59434
60435
|
return { files: files.sort() };
|
|
59435
60436
|
}
|
|
@@ -59481,7 +60482,7 @@ function rankPages(index, prompt, options = {}) {
|
|
|
59481
60482
|
// ../../packages/kk-wiki/src/raw.ts
|
|
59482
60483
|
init_dist3();
|
|
59483
60484
|
import { createHash as createHash12 } from "crypto";
|
|
59484
|
-
import { dirname as dirname21, join as
|
|
60485
|
+
import { dirname as dirname21, join as join41 } from "path";
|
|
59485
60486
|
var RAW_SOURCE_TYPES = ["url", "pdf", "html", "rss"];
|
|
59486
60487
|
function rawSnapshotId(sourceUri, body) {
|
|
59487
60488
|
return createHash12("sha256").update(`${sourceUri}
|
|
@@ -59510,7 +60511,7 @@ async function writeRawSnapshot(input, fileSystem = createNodeFileSystem()) {
|
|
|
59510
60511
|
const id = rawSnapshotId(input.sourceUri, input.body);
|
|
59511
60512
|
const snapshot = {
|
|
59512
60513
|
id,
|
|
59513
|
-
path:
|
|
60514
|
+
path: join41(input.dir, input.type, `${id}.md`),
|
|
59514
60515
|
type: input.type,
|
|
59515
60516
|
title: input.title,
|
|
59516
60517
|
sourceUri: input.sourceUri,
|
|
@@ -59638,7 +60639,7 @@ function synthesizePage(index, input) {
|
|
|
59638
60639
|
init_dist3();
|
|
59639
60640
|
|
|
59640
60641
|
// src/wiki/config.ts
|
|
59641
|
-
import { isAbsolute as isAbsolute13, join as
|
|
60642
|
+
import { isAbsolute as isAbsolute13, join as join42, resolve as resolve33 } from "path";
|
|
59642
60643
|
init_dist3();
|
|
59643
60644
|
var WIKI_CONFIG_FILE = "kk.config.json";
|
|
59644
60645
|
|
|
@@ -59725,7 +60726,7 @@ function parseBlock(raw) {
|
|
|
59725
60726
|
return block;
|
|
59726
60727
|
}
|
|
59727
60728
|
async function readConfigFile(cwd, fileSystem) {
|
|
59728
|
-
const path =
|
|
60729
|
+
const path = join42(cwd, WIKI_CONFIG_FILE);
|
|
59729
60730
|
if (!await fileSystem.exists(path))
|
|
59730
60731
|
return {};
|
|
59731
60732
|
let text;
|
|
@@ -59767,7 +60768,7 @@ async function resolveWikiConfig(options = {}) {
|
|
|
59767
60768
|
merged.root = resolve33(cwd, merged.root);
|
|
59768
60769
|
for (const key of ["raw", "content"]) {
|
|
59769
60770
|
if (!isAbsolute13(merged[key]))
|
|
59770
|
-
merged[key] =
|
|
60771
|
+
merged[key] = join42(merged.root, merged[key]);
|
|
59771
60772
|
}
|
|
59772
60773
|
return merged;
|
|
59773
60774
|
}
|
|
@@ -59818,7 +60819,7 @@ async function runIngest(args, deps = {}) {
|
|
|
59818
60819
|
const fs = deps.fileSystem ?? createNodeFileSystem();
|
|
59819
60820
|
const readStdinFn = deps.readStdin ?? readStdin;
|
|
59820
60821
|
const normalise = deps.markitdown ?? createMarkitdownRunner();
|
|
59821
|
-
const sourcePath = isAbsolute14(args.source) ? args.source :
|
|
60822
|
+
const sourcePath = isAbsolute14(args.source) ? args.source : join43(deps.cwd ?? process.cwd(), args.source);
|
|
59822
60823
|
let sourceText;
|
|
59823
60824
|
try {
|
|
59824
60825
|
if (fromStdin) {
|
|
@@ -59938,7 +60939,7 @@ function printLintOutcome(outcome, json) {
|
|
|
59938
60939
|
}
|
|
59939
60940
|
|
|
59940
60941
|
// src/wiki/maintenance.ts
|
|
59941
|
-
import { join as
|
|
60942
|
+
import { join as join44 } from "path";
|
|
59942
60943
|
init_dist3();
|
|
59943
60944
|
init_output2();
|
|
59944
60945
|
async function withConfig2(options, run) {
|
|
@@ -59960,12 +60961,12 @@ async function runMerge(options) {
|
|
|
59960
60961
|
if (merge.guard === "refused")
|
|
59961
60962
|
return { refused: true, path: merge.written };
|
|
59962
60963
|
const fs = createNodeFileSystem();
|
|
59963
|
-
await fs.writeFile(
|
|
60964
|
+
await fs.writeFile(join44(contentDir, merge.written), merge.targetText);
|
|
59964
60965
|
const sourcePage = index.pages.find((page) => page.slug === merge.sourceSlug);
|
|
59965
60966
|
if (sourcePage !== undefined)
|
|
59966
|
-
await fs.writeFile(
|
|
60967
|
+
await fs.writeFile(join44(contentDir, sourcePage.path), merge.sourceText);
|
|
59967
60968
|
for (const page of merge.rewrittenPages)
|
|
59968
|
-
await fs.writeFile(
|
|
60969
|
+
await fs.writeFile(join44(contentDir, page.path), page.text);
|
|
59969
60970
|
return {
|
|
59970
60971
|
refused: false,
|
|
59971
60972
|
path: merge.written,
|
|
@@ -59993,7 +60994,7 @@ async function runCompile(options) {
|
|
|
59993
60994
|
["index.md", compiled.index],
|
|
59994
60995
|
["MAP.md", compiled.map]
|
|
59995
60996
|
]) {
|
|
59996
|
-
const path =
|
|
60997
|
+
const path = join44(contentDir, name);
|
|
59997
60998
|
const current = await fs.exists(path) ? await fs.readFile(path) : null;
|
|
59998
60999
|
if (!needsWrite(current, rendered))
|
|
59999
61000
|
continue;
|
|
@@ -60133,7 +61134,7 @@ function printRetrievalOutcome(outcome, json) {
|
|
|
60133
61134
|
}
|
|
60134
61135
|
|
|
60135
61136
|
// src/wiki/write-verbs.ts
|
|
60136
|
-
import { isAbsolute as isAbsolute15, join as
|
|
61137
|
+
import { isAbsolute as isAbsolute15, join as join45 } from "path";
|
|
60137
61138
|
init_dist3();
|
|
60138
61139
|
init_output2();
|
|
60139
61140
|
async function readMaterial(options) {
|
|
@@ -60145,7 +61146,7 @@ async function readMaterial(options) {
|
|
|
60145
61146
|
chunks.push(chunk);
|
|
60146
61147
|
return Buffer.concat(chunks).toString("utf8");
|
|
60147
61148
|
}
|
|
60148
|
-
const path = isAbsolute15(options.from) ? options.from :
|
|
61149
|
+
const path = isAbsolute15(options.from) ? options.from : join45(options.cwd ?? process.cwd(), options.from);
|
|
60149
61150
|
return createNodeFileSystem().readFile(path);
|
|
60150
61151
|
}
|
|
60151
61152
|
async function resolveContext(options) {
|
|
@@ -60170,7 +61171,7 @@ async function runSummarize(options) {
|
|
|
60170
61171
|
const material = await readMaterial(options);
|
|
60171
61172
|
const date = options.date ?? new Date().toISOString().slice(0, 10);
|
|
60172
61173
|
const result = summarizePage(context.index, target, material, { date });
|
|
60173
|
-
await createNodeFileSystem().writeFile(
|
|
61174
|
+
await createNodeFileSystem().writeFile(join45(context.contentDir, result.path), result.text);
|
|
60174
61175
|
return { ok: true, code: 0, payload: { ok: true, path: result.path, guard: result.guard, links: result.links } };
|
|
60175
61176
|
}
|
|
60176
61177
|
async function runSynthesize(options) {
|
|
@@ -60181,7 +61182,7 @@ async function runSynthesize(options) {
|
|
|
60181
61182
|
const date = options.date ?? new Date().toISOString().slice(0, 10);
|
|
60182
61183
|
const type = options.type;
|
|
60183
61184
|
const result = synthesizePage(context.index, { target: options.target, material, type, date });
|
|
60184
|
-
await createNodeFileSystem().writeFile(
|
|
61185
|
+
await createNodeFileSystem().writeFile(join45(context.contentDir, result.path), result.text);
|
|
60185
61186
|
return {
|
|
60186
61187
|
ok: true,
|
|
60187
61188
|
code: 0,
|