@gobing-ai/knowledge-kit 0.1.15 → 0.1.17
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/index.js +1765 -40
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +58 -52
- package/plugins/generations/content-gen/src/storm.ts +94 -61
- package/plugins/generations/core-facts-gen/dist/index.js +1 -1
- package/plugins/generations/daily-article-gen/dist/index.js +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +1 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +1 -1
- package/plugins/generations/gemini-tts/dist/index.js +1 -1
- package/plugins/generations/image-gen/README.md +31 -10
- package/plugins/generations/image-gen/assets/sample/cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__clean-webapp-ui.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__cute.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__daily-news.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__editorial.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__fresh.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__minimalist.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__photorealistic.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__sketch.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__technical-diagram.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__vibrant.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__warm.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__xhs-knowledge.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/free__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/illustration__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/xhs-card__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/dist/index.js +1 -1
- package/plugins/generations/image-gen/presets/formats/daily-news-podcast-cover.yaml +18 -0
- package/plugins/generations/image-gen/presets/styles/quasi-news-podcast.yaml +9 -0
- package/plugins/generations/news-report-gen/dist/index.js +1 -1
- package/plugins/generations/voice-gen/dist/index.js +1 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +1 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +1 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +1 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +1 -1
- package/plugins/ingestions/web-search/dist/index.js +1 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice-migration.json +12 -3
- package/plugins/kk/publish-presets/daily-ai-voice.json +17 -9
- package/plugins/kk/publish-presets/itc-main.json +42 -0
- package/plugins/kk/scripts/cover-compositor.ts +198 -0
- package/plugins/kk/scripts/daily-cover-mock.ts +164 -0
- package/plugins/kk/scripts/daily-scheduled-run.ts +188 -3
- package/plugins/kk/scripts/daily-stages.ts +134 -26
- package/plugins/kk/scripts/daily-triage-core.ts +451 -0
- package/plugins/kk/scripts/daily-triage.ts +74 -0
- package/plugins/kk/scripts/itc-stages.ts +3 -2
- package/plugins/kk/scripts/kk-workflow-stages.ts +31 -2
- package/plugins/kk/scripts/voice3-publish-window.ts +5 -1
- package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +16 -10
- package/plugins/kk/skills/news-editorial/SKILL.md +3 -3
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +2 -1
- package/plugins/kk/skills/publish/SKILL.md +1 -1
- package/plugins/kk/skills/wiki-authoring/SKILL.md +53 -0
- package/plugins/kk/skills/wiki-authoring/references/page-shapes.md +44 -0
- package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +3 -3
- package/plugins/kk/workflows/kk-daily-publish3.yaml +10 -3
- package/plugins/kk/workflows/kk-daily-safety.yaml +32 -7
- package/plugins/publishings/bilibili-pub/dist/index.js +90 -17
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/cnblogs-pub/dist/index.js +90 -17
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/csdn-pub/dist/index.js +90 -17
- package/plugins/publishings/csdn-pub/dist/profile-check.js +91 -17
- package/plugins/publishings/emdash-pub/dist/index.js +1 -1
- package/plugins/publishings/infoq-pub/dist/index.js +120 -19
- package/plugins/publishings/infoq-pub/dist/profile-check.js +95 -18
- package/plugins/publishings/infoq-pub/src/index.ts +40 -1
- package/plugins/publishings/jike-pub/dist/index.js +90 -17
- package/plugins/publishings/jike-pub/dist/profile-check.js +91 -17
- package/plugins/publishings/juejin-pub/dist/index.js +117 -20
- package/plugins/publishings/juejin-pub/dist/profile-check.js +94 -18
- package/plugins/publishings/juejin-pub/src/index.ts +41 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +90 -17
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +91 -17
- package/plugins/publishings/medium-pub/dist/index.js +1 -1
- package/plugins/publishings/podcast-pub/dist/index.js +1 -1
- package/plugins/publishings/qiita-pub/dist/index.js +1 -1
- package/plugins/publishings/shipinhao-pub/dist/index.js +311 -66
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +138 -17
- package/plugins/publishings/shipinhao-pub/plugin.json +2 -2
- package/plugins/publishings/shipinhao-pub/src/flow.ts +335 -79
- package/plugins/publishings/shipinhao-pub/src/index.ts +16 -8
- package/plugins/publishings/shipinhao-pub/src/profile-check.ts +1 -1
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +103 -5
- package/plugins/publishings/sspai-pub/dist/index.js +90 -17
- package/plugins/publishings/sspai-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/substack-pub/dist/index.js +90 -17
- package/plugins/publishings/substack-pub/dist/profile-check.js +91 -17
- package/plugins/publishings/surfdash-pub/dist/index.js +244 -13
- package/plugins/publishings/surfdash-pub/src/index.ts +144 -8
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +189 -0
- package/plugins/publishings/threads-pub/dist/index.js +1 -1
- package/plugins/publishings/wechatmp-pub/dist/index.js +186 -39
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +96 -19
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +14 -2
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +10 -3
- package/plugins/publishings/wechatmp-pub/src/flow.ts +158 -25
- package/plugins/publishings/wechatmp-pub/src/page.ts +14 -0
- package/plugins/publishings/wechatmp-pub/src/profile-check.ts +8 -1
- package/plugins/publishings/weibo-pub/dist/index.js +90 -17
- package/plugins/publishings/weibo-pub/dist/profile-check.js +91 -17
- package/plugins/publishings/x-pub/dist/index.js +90 -17
- package/plugins/publishings/x-pub/dist/profile-check.js +91 -17
- package/plugins/publishings/xhs-pub/dist/index.js +646 -47
- package/plugins/publishings/xhs-pub/dist/profile-check.js +109 -17
- package/plugins/publishings/xhs-pub/src/errors.ts +45 -0
- package/plugins/publishings/xhs-pub/src/flow.ts +773 -45
- package/plugins/publishings/xhs-pub/src/page.ts +33 -0
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +90 -17
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +90 -16
- package/plugins/publishings/zenn-pub/dist/index.js +94 -2
- package/plugins/publishings/zenn-pub/src/index.ts +134 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* 0349 R2: standalone mock cover runner — end-to-end cover verification without a daily cron
|
|
4
|
+
* run. `--mock-bg` renders a local 1344×576 gradient background via SVG→sips (zero tokens,
|
|
5
|
+
* fully offline); otherwise the background is generated through `kk executor run image-gen`
|
|
6
|
+
* with the pinned daily-news-podcast presets. Either way the headline is composited through
|
|
7
|
+
* the same `compositeCover` the daily pipeline uses, then the output is dimension-verified.
|
|
8
|
+
*/
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
13
|
+
import { parseArgs } from 'node:util';
|
|
14
|
+
import { COVER_HEIGHT, COVER_WIDTH, compositeCover } from './cover-compositor';
|
|
15
|
+
|
|
16
|
+
interface MockOptions {
|
|
17
|
+
headline: string;
|
|
18
|
+
scene: string;
|
|
19
|
+
out: string;
|
|
20
|
+
provider: string;
|
|
21
|
+
mockBg: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const MOCK_BG_SVG = `<?xml version="1.0" encoding="UTF-8"?>
|
|
25
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${COVER_WIDTH}" height="${COVER_HEIGHT}" viewBox="0 0 ${COVER_WIDTH} ${COVER_HEIGHT}">
|
|
26
|
+
<defs>
|
|
27
|
+
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
|
|
28
|
+
<stop offset="0" stop-color="#0d1e33"/>
|
|
29
|
+
<stop offset="0.55" stop-color="#123252"/>
|
|
30
|
+
<stop offset="1" stop-color="#0a1424"/>
|
|
31
|
+
</linearGradient>
|
|
32
|
+
<radialGradient id="glow" cx="0.72" cy="0.35" r="0.5">
|
|
33
|
+
<stop offset="0" stop-color="#2f6da8" stop-opacity="0.55"/>
|
|
34
|
+
<stop offset="1" stop-color="#2f6da8" stop-opacity="0"/>
|
|
35
|
+
</radialGradient>
|
|
36
|
+
</defs>
|
|
37
|
+
<rect width="100%" height="100%" fill="url(#bg)"/>
|
|
38
|
+
<rect width="100%" height="100%" fill="url(#glow)"/>
|
|
39
|
+
<!-- scene placeholder: the live path puts diffusion imagery here -->
|
|
40
|
+
<text x="24" y="${COVER_HEIGHT - 24}" font-family="Helvetica, Arial, sans-serif" font-size="15" fill="#5a7ea6">MOCK BACKGROUND — ${COVER_WIDTH}x${COVER_HEIGHT}</text>
|
|
41
|
+
</svg>`;
|
|
42
|
+
|
|
43
|
+
function parseMockArgs(args: string[]): MockOptions {
|
|
44
|
+
const { values } = parseArgs({
|
|
45
|
+
args,
|
|
46
|
+
options: {
|
|
47
|
+
headline: { type: 'string', default: '重大突破:下一代AI深度推理时代正式开启' },
|
|
48
|
+
scene: { type: 'string', default: 'an illuminated advanced semiconductor wafer glowing in dark cleanroom' },
|
|
49
|
+
out: { type: 'string', default: '/tmp/kk-cover-mock.png' },
|
|
50
|
+
provider: { type: 'string', default: '' },
|
|
51
|
+
'mock-bg': { type: 'boolean', default: false },
|
|
52
|
+
},
|
|
53
|
+
strict: true,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
headline: values.headline ?? '',
|
|
57
|
+
scene: values.scene ?? '',
|
|
58
|
+
out: resolve(values.out ?? ''),
|
|
59
|
+
provider: values.provider ?? '',
|
|
60
|
+
mockBg: values['mock-bg'] ?? false,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Render the mock background SVG to PNG via sips (mac-only, ADR-046). */
|
|
65
|
+
function renderMockBg(svgPath: string, pngPath: string): void {
|
|
66
|
+
const sips = spawnSync('sips', ['-s', 'format', 'png', svgPath, '--out', pngPath], { encoding: 'utf-8' });
|
|
67
|
+
if (sips.error || sips.status !== 0 || !existsSync(pngPath)) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`daily-cover-mock: mock background render failed (sips status ${sips.status ?? 'n/a'}); stderr: ${(sips.stderr || '').trim()}`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Live path: same envelope shape dailyCover writes, through the pinned presets. */
|
|
75
|
+
function generateLiveBg(options: MockOptions, envPath: string, contentOut: string): string {
|
|
76
|
+
const kkBin = process.env.KK_BIN || 'kk';
|
|
77
|
+
const envelope = [
|
|
78
|
+
{
|
|
79
|
+
id: 'daily-cover-mock',
|
|
80
|
+
title: basename(options.out),
|
|
81
|
+
body: '',
|
|
82
|
+
metadata: {
|
|
83
|
+
imageGen: {
|
|
84
|
+
job: 'cover',
|
|
85
|
+
format: 'daily-news-podcast-cover',
|
|
86
|
+
style: 'quasi-news-podcast',
|
|
87
|
+
vars: { subject: options.scene },
|
|
88
|
+
maxImages: 1,
|
|
89
|
+
...(options.provider !== '' ? { provider: options.provider } : {}),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
writeFileSync(envPath, JSON.stringify(envelope, null, 4));
|
|
95
|
+
const run = spawnSync(kkBin, ['executor', 'run', 'image-gen', '--in', envPath, '--out', contentOut], {
|
|
96
|
+
encoding: 'utf-8',
|
|
97
|
+
});
|
|
98
|
+
if (run.error || run.status !== 0) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`daily-cover-mock: image-gen failed (status ${run.status ?? 'n/a'}); stderr: ${(run.stderr || '').trim().slice(-400)}`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
const content = JSON.parse(readFileSync(contentOut, 'utf-8')) as Array<{ metadata?: { image_path?: string } }>;
|
|
104
|
+
const imagePath = content[0]?.metadata?.image_path;
|
|
105
|
+
if (imagePath === undefined || !existsSync(imagePath)) {
|
|
106
|
+
throw new Error('daily-cover-mock: image-gen produced no usable image_path');
|
|
107
|
+
}
|
|
108
|
+
return imagePath;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Verify the composited output is a real COVER_WIDTH×COVER_HEIGHT PNG. */
|
|
112
|
+
function verifyOutput(outPath: string): { width: number; height: number } {
|
|
113
|
+
const probe = spawnSync('sips', ['-g', 'pixelWidth', '-g', 'pixelHeight', outPath], { encoding: 'utf-8' });
|
|
114
|
+
const text = probe.stdout || '';
|
|
115
|
+
const width = Number(/pixelWidth:\s*(\d+)/.exec(text)?.[1]);
|
|
116
|
+
const height = Number(/pixelHeight:\s*(\d+)/.exec(text)?.[1]);
|
|
117
|
+
if (!Number.isFinite(width) || !Number.isFinite(height)) {
|
|
118
|
+
throw new Error(`daily-cover-mock: output verification failed — sips cannot read dimensions from ${outPath}`);
|
|
119
|
+
}
|
|
120
|
+
if (width !== COVER_WIDTH || height !== COVER_HEIGHT) {
|
|
121
|
+
throw new Error(`daily-cover-mock: output is ${width}x${height}, expected ${COVER_WIDTH}x${COVER_HEIGHT}`);
|
|
122
|
+
}
|
|
123
|
+
return { width, height };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function runMock(args: string[]): { out: string; width: number; height: number; background: string } {
|
|
127
|
+
const options = parseMockArgs(args);
|
|
128
|
+
const parent = dirname(options.out);
|
|
129
|
+
if (!existsSync(parent)) {
|
|
130
|
+
// sips would silently no-op on a missing parent (0348 finding) — fail before compositing.
|
|
131
|
+
throw new Error(`daily-cover-mock: output directory does not exist: ${parent}`);
|
|
132
|
+
}
|
|
133
|
+
const tmp = mkdtempSync(join(tmpdir(), 'kk-cover-mock-'));
|
|
134
|
+
try {
|
|
135
|
+
const envPath = join(tmp, 'mock-image-gen-in.json');
|
|
136
|
+
const contentOut = join(tmp, 'content.json');
|
|
137
|
+
const background = options.mockBg
|
|
138
|
+
? (() => {
|
|
139
|
+
const svgPath = join(tmp, 'mock-bg.svg');
|
|
140
|
+
const pngPath = join(tmp, 'mock-bg.png');
|
|
141
|
+
writeFileSync(svgPath, MOCK_BG_SVG);
|
|
142
|
+
renderMockBg(svgPath, pngPath);
|
|
143
|
+
return pngPath;
|
|
144
|
+
})()
|
|
145
|
+
: generateLiveBg(options, envPath, contentOut);
|
|
146
|
+
compositeCover({
|
|
147
|
+
backgroundImagePath: background,
|
|
148
|
+
headline: options.headline,
|
|
149
|
+
outputPath: options.out,
|
|
150
|
+
});
|
|
151
|
+
const { width, height } = verifyOutput(options.out);
|
|
152
|
+
console.error(
|
|
153
|
+
`daily-cover-mock: composited ${options.out} (${width}x${height}, background=${options.mockBg ? 'mock' : options.provider || 'default'})`,
|
|
154
|
+
);
|
|
155
|
+
return { out: options.out, width, height, background: options.mockBg ? 'mock' : 'live' };
|
|
156
|
+
} finally {
|
|
157
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const invokedDirectly = process.argv[1] !== undefined && basename(process.argv[1]) === 'daily-cover-mock.ts';
|
|
162
|
+
if (invokedDirectly) {
|
|
163
|
+
runMock(process.argv.slice(2));
|
|
164
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/** Supervise one scheduled daily run and persist its terminal outcome even after a deadline. */
|
|
3
3
|
import { spawn, spawnSync } from 'node:child_process';
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
5
6
|
import { dirname, join, resolve } from 'node:path';
|
|
6
7
|
import { parseArgs } from 'node:util';
|
|
8
|
+
import type { TriageReceipt, TriageReport } from './daily-triage-core';
|
|
9
|
+
import { collectTriage, summarizeTriage } from './daily-triage-core';
|
|
7
10
|
|
|
8
11
|
const { values } = parseArgs({
|
|
9
12
|
options: {
|
|
@@ -21,6 +24,8 @@ const { values } = parseArgs({
|
|
|
21
24
|
window: { type: 'string' },
|
|
22
25
|
'publish-preset': { type: 'string' },
|
|
23
26
|
'publish-live-channels': { type: 'string' },
|
|
27
|
+
'allow-dirty': { type: 'boolean', default: false },
|
|
28
|
+
'skip-probe': { type: 'boolean', default: false },
|
|
24
29
|
},
|
|
25
30
|
});
|
|
26
31
|
const timeoutMs = Number(values['timeout-ms']);
|
|
@@ -67,7 +72,159 @@ const vars = isVoice3
|
|
|
67
72
|
work_dir: workDir,
|
|
68
73
|
run_date: stamp,
|
|
69
74
|
};
|
|
70
|
-
|
|
75
|
+
// ------------------------------------------------------------------
|
|
76
|
+
// Preflight (0347 F1, 2026-11-10). Fail fast at minute one with named
|
|
77
|
+
// reasons instead of burning the window on a doomed run (2026-11-09: 80
|
|
78
|
+
// minutes died on a quota-dead executor chain a probe would have refused,
|
|
79
|
+
// on workflow bytes that had already diverged from the installed kk).
|
|
80
|
+
// ------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
interface Preflight {
|
|
83
|
+
ok: boolean;
|
|
84
|
+
reasons: string[];
|
|
85
|
+
warnings: string[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const ANSI_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[A-Za-z]`, 'g');
|
|
89
|
+
|
|
90
|
+
function harnessDirtyPaths(): string[] {
|
|
91
|
+
const git = spawnSync('git', ['status', '--porcelain', '--', 'plugins/kk', '.spur/workflows'], {
|
|
92
|
+
cwd: repo,
|
|
93
|
+
encoding: 'utf-8',
|
|
94
|
+
timeout: 10_000,
|
|
95
|
+
});
|
|
96
|
+
if (git.status !== 0) return [];
|
|
97
|
+
// Keep the full porcelain line (XY + path): the refusal must show whether a byte is staged,
|
|
98
|
+
// unstaged or untracked — 20261111 a16 spent a fix loop guessing that from bare paths.
|
|
99
|
+
return git.stdout
|
|
100
|
+
.split('\n')
|
|
101
|
+
.map((line) => line.trimEnd())
|
|
102
|
+
.filter(Boolean);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Package root of the kk binary this machine resolves `kk` to, or null. */
|
|
106
|
+
function kkPackageRoot(): string | null {
|
|
107
|
+
const which = spawnSync('sh', ['-c', 'command -v kk'], { encoding: 'utf-8', timeout: 5_000 });
|
|
108
|
+
const bin = which.stdout.trim();
|
|
109
|
+
if (which.status !== 0 || bin === '') return null;
|
|
110
|
+
try {
|
|
111
|
+
const real = realpathSync(bin);
|
|
112
|
+
// <pkg>/dist/index.js -> <pkg>
|
|
113
|
+
return dirname(dirname(real));
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function diffDirs(a: string, b: string): string[] {
|
|
120
|
+
if (!existsSync(a) || !existsSync(b)) return [];
|
|
121
|
+
const diff = spawnSync('diff', ['-rq', a, b], { encoding: 'utf-8', timeout: 20_000 });
|
|
122
|
+
if (diff.status === 0) return [];
|
|
123
|
+
if (diff.error || (diff.status !== 1 && diff.status !== null)) return []; // unavailable: warn elsewhere, never false-refuse
|
|
124
|
+
return diff.stdout
|
|
125
|
+
.split('\n')
|
|
126
|
+
.filter((line) => line.trim() !== '')
|
|
127
|
+
.map((line) => line.replace(a, 'checkout').replace(b, 'install'))
|
|
128
|
+
.slice(0, 5);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* One minimal real agent round-trip. `spur agent doctor` reports usable:true for accounts whose
|
|
133
|
+
* quota is exhausted (2026-11-09 R3), so executor health must be proven with traffic, not probes.
|
|
134
|
+
*/
|
|
135
|
+
function executorProbe(agentName: string): { ok: boolean; detail: string } {
|
|
136
|
+
const probeCwd = mkdtempSync(join(tmpdir(), 'kk-preflight-'));
|
|
137
|
+
try {
|
|
138
|
+
const probe = spawnSync(
|
|
139
|
+
'spur',
|
|
140
|
+
['agent', 'run', '--agent', agentName, '--mode', 'text', '--json', 'Reply with exactly: OK'],
|
|
141
|
+
{ cwd: probeCwd, encoding: 'utf-8', timeout: 120_000 },
|
|
142
|
+
);
|
|
143
|
+
if (probe.status === 0) return { ok: true, detail: 'ok' };
|
|
144
|
+
const text = `${probe.stderr ?? ''}${probe.stdout ?? ''}`.replace(ANSI_RE, '').trim();
|
|
145
|
+
const named = text
|
|
146
|
+
.split('\n')
|
|
147
|
+
.filter((line) => line.trim() !== '')
|
|
148
|
+
.slice(-2)
|
|
149
|
+
.join(' | ')
|
|
150
|
+
.slice(-240);
|
|
151
|
+
return { ok: false, detail: named !== '' ? named : `exit ${probe.status ?? '?'}` };
|
|
152
|
+
} finally {
|
|
153
|
+
rmSync(probeCwd, { recursive: true, force: true });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function runPreflight(): Preflight {
|
|
158
|
+
const reasons: string[] = [];
|
|
159
|
+
const warnings: string[] = [];
|
|
160
|
+
const dirty = harnessDirtyPaths();
|
|
161
|
+
if (dirty.length > 0 && values['allow-dirty'] !== true) {
|
|
162
|
+
reasons.push(
|
|
163
|
+
`working tree dirty on harness paths (git status --porcelain):\n ${dirty.slice(0, 10).join('\n ')}`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
const install = kkPackageRoot();
|
|
167
|
+
if (install === null) {
|
|
168
|
+
warnings.push('kk binary not found on PATH; executed-vs-installed sync not checked');
|
|
169
|
+
} else {
|
|
170
|
+
const diffs = [
|
|
171
|
+
...diffDirs(join(repo, 'plugins', 'kk', 'workflows'), join(install, 'plugins', 'kk', 'workflows')),
|
|
172
|
+
...diffDirs(join(repo, 'plugins', 'kk', 'scripts'), join(install, 'plugins', 'kk', 'scripts')),
|
|
173
|
+
];
|
|
174
|
+
if (diffs.length > 0) {
|
|
175
|
+
reasons.push(`checkout diverges from installed kk (${install}): ${diffs.join('; ')}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (values['skip-probe'] !== true) {
|
|
179
|
+
if (values.agent !== 'inline') {
|
|
180
|
+
const probe = executorProbe(values.agent);
|
|
181
|
+
if (!probe.ok) reasons.push(`executor probe failed for primary '${values.agent}': ${probe.detail}`);
|
|
182
|
+
}
|
|
183
|
+
const retry = values['retry-agent'];
|
|
184
|
+
if (retry !== undefined && retry !== 'inline') {
|
|
185
|
+
const retryProbe = executorProbe(retry);
|
|
186
|
+
if (!retryProbe.ok) {
|
|
187
|
+
warnings.push(`executor probe failed for retry '${retry}': ${retryProbe.detail}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { ok: reasons.length === 0, reasons, warnings };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const preflight = runPreflight();
|
|
195
|
+
if (!preflight.ok) {
|
|
196
|
+
const refused = {
|
|
197
|
+
runId,
|
|
198
|
+
startedAt,
|
|
199
|
+
completedAt: new Date().toISOString(),
|
|
200
|
+
status: 'preflight-refused',
|
|
201
|
+
exitCode: 5,
|
|
202
|
+
agent: values.agent,
|
|
203
|
+
retryAgent: values['retry-agent'],
|
|
204
|
+
workDir,
|
|
205
|
+
preflight: { reasons: preflight.reasons, warnings: preflight.warnings },
|
|
206
|
+
error: preflight.reasons[0] ?? 'preflight refused',
|
|
207
|
+
};
|
|
208
|
+
writeFileSync(receiptPath, `${JSON.stringify(refused, null, 2)}\n`);
|
|
209
|
+
console.error(`daily-scheduled-run: preflight refused run ${runId}`);
|
|
210
|
+
for (const reason of preflight.reasons) console.error(` ! ${reason}`);
|
|
211
|
+
for (const warning of preflight.warnings) console.error(` ~ ${warning}`);
|
|
212
|
+
process.exit(5);
|
|
213
|
+
}
|
|
214
|
+
writeFileSync(
|
|
215
|
+
receiptPath,
|
|
216
|
+
JSON.stringify(
|
|
217
|
+
{
|
|
218
|
+
runId,
|
|
219
|
+
startedAt,
|
|
220
|
+
status: 'running',
|
|
221
|
+
workDir,
|
|
222
|
+
preflight: { warnings: preflight.warnings, probes: values['skip-probe'] === true ? 'skipped' : 'passed' },
|
|
223
|
+
},
|
|
224
|
+
null,
|
|
225
|
+
2,
|
|
226
|
+
),
|
|
227
|
+
);
|
|
71
228
|
let interrupted = false;
|
|
72
229
|
let timedOut = false;
|
|
73
230
|
let spawnError = '';
|
|
@@ -369,6 +526,33 @@ const status =
|
|
|
369
526
|
: primaryPublishStatus === 'full' && !(!isVoice3 && missingRequiredChannels.length > 0)
|
|
370
527
|
? 'done'
|
|
371
528
|
: 'incomplete';
|
|
529
|
+
function buildTriage(finalStatus: string, exitCode: number): TriageReport | null {
|
|
530
|
+
try {
|
|
531
|
+
const inlineReceipt: TriageReceipt = {
|
|
532
|
+
status: finalStatus,
|
|
533
|
+
startedAt,
|
|
534
|
+
completedAt: new Date().toISOString(),
|
|
535
|
+
workDir,
|
|
536
|
+
agent: values.agent,
|
|
537
|
+
retryAgent: values['retry-agent'],
|
|
538
|
+
exitCode,
|
|
539
|
+
error: spawnError || null,
|
|
540
|
+
};
|
|
541
|
+
const report = collectTriage(repo, runId, { receipt: inlineReceipt, workflow: values.workflow });
|
|
542
|
+
console.error('daily-scheduled-run: triage summary');
|
|
543
|
+
for (const line of summarizeTriage(report)) console.error(` ${line}`);
|
|
544
|
+
return report;
|
|
545
|
+
} catch (error) {
|
|
546
|
+
console.error(`daily-scheduled-run: triage collection failed: ${String(error)}`);
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const terminalExitCode = timedOut ? 124 : interrupted ? 143 : exitCode !== 0 ? exitCode : status === 'done' ? 0 : 4;
|
|
552
|
+
const triage =
|
|
553
|
+
status === 'failed' || status === 'timed-out' || status === 'interrupted' || status === 'incomplete'
|
|
554
|
+
? buildTriage(status, terminalExitCode)
|
|
555
|
+
: null;
|
|
372
556
|
const receipt = {
|
|
373
557
|
runId,
|
|
374
558
|
startedAt,
|
|
@@ -376,7 +560,7 @@ const receipt = {
|
|
|
376
560
|
status,
|
|
377
561
|
generateOnly,
|
|
378
562
|
generationInspection,
|
|
379
|
-
exitCode:
|
|
563
|
+
exitCode: terminalExitCode,
|
|
380
564
|
workDir,
|
|
381
565
|
timeoutMs,
|
|
382
566
|
agent: values.agent,
|
|
@@ -388,6 +572,7 @@ const receipt = {
|
|
|
388
572
|
runSummary,
|
|
389
573
|
reservationRecovery,
|
|
390
574
|
cleanup,
|
|
575
|
+
triage,
|
|
391
576
|
};
|
|
392
577
|
writeFileSync(receiptPath, `${JSON.stringify(receipt, null, 2)}\n`);
|
|
393
578
|
console.log(JSON.stringify(receipt));
|