@gobing-ai/knowledge-kit 0.0.12 → 0.0.14

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.
Files changed (152) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +120 -26
  3. package/package.json +1 -1
  4. package/plugins/generations/content-gen/dist/index.js +22187 -0
  5. package/plugins/generations/content-gen/plugin.json +1 -1
  6. package/plugins/generations/core-facts-gen/dist/index.js +22068 -0
  7. package/plugins/generations/core-facts-gen/plugin.json +1 -1
  8. package/plugins/generations/daily-article-gen/dist/index.js +22050 -0
  9. package/plugins/generations/daily-article-gen/plugin.json +1 -1
  10. package/plugins/generations/daily-article-gen/src/index.ts +13 -1
  11. package/plugins/generations/dailynews-gen/dist/index.js +22344 -0
  12. package/plugins/generations/dailynews-gen/plugin.json +1 -1
  13. package/plugins/generations/episode-plan-gen/dist/index.js +22503 -0
  14. package/plugins/generations/episode-plan-gen/plugin.json +1 -1
  15. package/plugins/generations/episode-plan-gen/src/index.ts +11 -0
  16. package/plugins/generations/image-gen/config.example.yaml +75 -0
  17. package/plugins/generations/image-gen/dist/index.js +24862 -0
  18. package/plugins/generations/image-gen/package.json +17 -0
  19. package/plugins/generations/image-gen/plugin.json +7 -0
  20. package/plugins/generations/image-gen/presets/formats/cover.yaml +57 -0
  21. package/plugins/generations/image-gen/presets/formats/free.yaml +46 -0
  22. package/plugins/generations/image-gen/presets/formats/illustration.yaml +48 -0
  23. package/plugins/generations/image-gen/presets/styles/clean-webapp-ui.yaml +28 -0
  24. package/plugins/generations/image-gen/presets/styles/cute.yaml +3 -0
  25. package/plugins/generations/image-gen/presets/styles/editorial.yaml +3 -0
  26. package/plugins/generations/image-gen/presets/styles/fresh.yaml +3 -0
  27. package/plugins/generations/image-gen/presets/styles/minimalist.yaml +3 -0
  28. package/plugins/generations/image-gen/presets/styles/photorealistic.yaml +3 -0
  29. package/plugins/generations/image-gen/presets/styles/sketch.yaml +3 -0
  30. package/plugins/generations/image-gen/presets/styles/technical-diagram.yaml +3 -0
  31. package/plugins/generations/image-gen/presets/styles/vibrant.yaml +3 -0
  32. package/plugins/generations/image-gen/presets/styles/warm.yaml +3 -0
  33. package/plugins/generations/image-gen/src/bytes.ts +19 -0
  34. package/plugins/generations/image-gen/src/index.ts +319 -0
  35. package/plugins/generations/image-gen/src/job.ts +143 -0
  36. package/plugins/generations/image-gen/src/paths.ts +31 -0
  37. package/plugins/generations/image-gen/src/presets.ts +344 -0
  38. package/plugins/generations/image-gen/src/providers/agnes.ts +110 -0
  39. package/plugins/generations/image-gen/src/providers/azure.ts +153 -0
  40. package/plugins/generations/image-gen/src/providers/codex-cli.ts +170 -0
  41. package/plugins/generations/image-gen/src/providers/dashscope.ts +485 -0
  42. package/plugins/generations/image-gen/src/providers/google.ts +268 -0
  43. package/plugins/generations/image-gen/src/providers/huggingface.ts +59 -0
  44. package/plugins/generations/image-gen/src/providers/jimeng.ts +259 -0
  45. package/plugins/generations/image-gen/src/providers/minimax.ts +171 -0
  46. package/plugins/generations/image-gen/src/providers/openai.ts +319 -0
  47. package/plugins/generations/image-gen/src/providers/openrouter.ts +257 -0
  48. package/plugins/generations/image-gen/src/providers/refs.ts +24 -0
  49. package/plugins/generations/image-gen/src/providers/replicate.ts +279 -0
  50. package/plugins/generations/image-gen/src/providers/seedream.ts +128 -0
  51. package/plugins/generations/image-gen/src/providers/types.ts +286 -0
  52. package/plugins/generations/image-gen/src/providers/zai.ts +237 -0
  53. package/plugins/generations/image-gen/tsconfig.json +8 -0
  54. package/plugins/generations/news-report-gen/dist/index.js +22193 -0
  55. package/plugins/generations/news-report-gen/package.json +17 -0
  56. package/plugins/generations/news-report-gen/plugin.json +7 -0
  57. package/plugins/generations/news-report-gen/src/index.ts +308 -0
  58. package/plugins/generations/news-report-gen/tsconfig.json +4 -0
  59. package/plugins/generations/omni-voice-gen/Makefile +14 -0
  60. package/plugins/generations/omni-voice-gen/README.md +112 -0
  61. package/plugins/generations/omni-voice-gen/bin/omni-voice-gen +2 -0
  62. package/plugins/generations/omni-voice-gen/dist/omni-voice-gen-prr8skpb. +2 -0
  63. package/plugins/generations/omni-voice-gen/dist/omni-voice-gen.js +6 -0
  64. package/plugins/generations/omni-voice-gen/plugin.json +6 -0
  65. package/plugins/generations/omni-voice-gen/profiles.json +12 -0
  66. package/plugins/generations/omni-voice-gen/pyproject.toml +25 -0
  67. package/plugins/generations/omni-voice-gen/scripts/coverage_gate.py +74 -0
  68. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/__init__.py +1 -0
  69. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/__main__.py +39 -0
  70. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/audio.py +190 -0
  71. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/backend.py +150 -0
  72. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/contract.py +76 -0
  73. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/mp3.py +60 -0
  74. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/pipeline.py +289 -0
  75. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/profiles.py +100 -0
  76. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/qc.py +234 -0
  77. package/plugins/generations/omni-voice-gen/src/omni_voice_gen/voicescript.py +352 -0
  78. package/plugins/generations/omni-voice-gen/uv.lock +3510 -0
  79. package/plugins/generations/voice-gen/dist/index.js +23055 -0
  80. package/plugins/generations/voice-gen/plugin.json +1 -1
  81. package/plugins/generations/voice-gen/src/index.ts +16 -1
  82. package/plugins/generations/voice-gen/src/voicebox-client.ts +3 -1
  83. package/plugins/ingestions/aihot-ingest/dist/index.js +22378 -0
  84. package/plugins/ingestions/aihot-ingest/plugin.json +1 -1
  85. package/plugins/ingestions/horizon-ingest/dist/index.js +22125 -0
  86. package/plugins/ingestions/horizon-ingest/plugin.json +1 -1
  87. package/plugins/ingestions/karakeep-local/dist/index.js +24204 -0
  88. package/plugins/ingestions/karakeep-local/plugin.json +1 -1
  89. package/plugins/ingestions/last30days-ingest/dist/index.js +22070 -0
  90. package/plugins/ingestions/last30days-ingest/plugin.json +1 -1
  91. package/plugins/ingestions/web-search/dist/index.js +24399 -0
  92. package/plugins/ingestions/web-search/plugin.json +1 -1
  93. package/plugins/kk/commands/image-extract.md +40 -0
  94. package/plugins/kk/commands/image-generate.md +32 -0
  95. package/plugins/kk/config.example.yaml +80 -0
  96. package/plugins/kk/plugin.json +1 -1
  97. package/plugins/kk/skills/image-authoring/SKILL.md +257 -0
  98. package/plugins/kk/skills/image-authoring/references/format-drafting.md +57 -0
  99. package/plugins/kk/skills/image-authoring/references/illustration-positions.md +87 -0
  100. package/plugins/kk/skills/image-authoring/references/migrating-from-wt.md +31 -0
  101. package/plugins/kk/skills/image-authoring/references/providers.md +52 -0
  102. package/plugins/kk/skills/image-authoring/references/style-extraction.md +139 -0
  103. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +130 -30
  104. package/plugins/publishings/emdash-pub/dist/index.js +22263 -0
  105. package/plugins/publishings/emdash-pub/plugin.json +1 -1
  106. package/plugins/publishings/podcast-pub/dist/index.js +22650 -0
  107. package/plugins/publishings/podcast-pub/plugin.json +8 -2
  108. package/plugins/publishings/podcast-pub/src/index.ts +18 -2
  109. package/plugins/publishings/podcast-pub/src/show-notes.ts +56 -9
  110. package/plugins/publishings/qiita-pub/dist/index.js +22101 -0
  111. package/plugins/publishings/qiita-pub/plugin.json +1 -1
  112. package/plugins/publishings/surfdash-pub/dist/index.js +22323 -0
  113. package/plugins/publishings/surfdash-pub/plugin.json +1 -1
  114. package/plugins/publishings/surfdash-pub/src/index.ts +109 -9
  115. package/plugins/publishings/zenn-pub/dist/index.js +22142 -0
  116. package/plugins/publishings/zenn-pub/plugin.json +1 -1
  117. package/plugins/sp/scripts/batch-preflight.mjs +346 -0
  118. package/plugins/sp/scripts/batch-preflight.ts +459 -0
  119. package/plugins/sp/scripts/daily-summary/daily-summary.mjs +615 -0
  120. package/plugins/sp/scripts/daily-summary/daily-summary.ts +846 -0
  121. package/plugins/sp/scripts/daily-summary/logger.ts +28 -0
  122. package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.mjs +223 -0
  123. package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.ts +367 -0
  124. package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +132 -0
  125. package/plugins/sp/scripts/dogfood-testing/validate-report.ts +169 -0
  126. package/plugins/sp/scripts/feature-dev-precheck.mjs +171 -0
  127. package/plugins/sp/scripts/feature-dev-precheck.ts +238 -0
  128. package/plugins/sp/scripts/feature-sync-bounded.mjs +285 -0
  129. package/plugins/sp/scripts/feature-sync-bounded.ts +478 -0
  130. package/plugins/sp/scripts/history-anatomy-cache.mjs +902 -0
  131. package/plugins/sp/scripts/history-anatomy-cache.ts +1028 -0
  132. package/plugins/sp/scripts/idea-handoff.mjs +22 -0
  133. package/plugins/sp/scripts/idea-handoff.ts +44 -0
  134. package/plugins/sp/scripts/inline-pipeline-parity-check.ts +185 -0
  135. package/plugins/sp/scripts/inline-run-setup.ts +198 -0
  136. package/plugins/sp/scripts/pr-reviewing.mjs +769 -0
  137. package/plugins/sp/scripts/pr-reviewing.ts +925 -0
  138. package/plugins/sp/scripts/quality-gate.mjs +179 -0
  139. package/plugins/sp/scripts/quality-gate.ts +217 -0
  140. package/plugins/sp/scripts/script-contract-check.ts +319 -0
  141. package/plugins/sp/scripts/stage-registry-adapter.ts +1533 -0
  142. package/plugins/sp/scripts/surface-drift-inventory.ts +929 -0
  143. package/plugins/sp/scripts/task-evidence-precheck.ts +181 -0
  144. package/plugins/sp/scripts/task-size-precheck.ts +175 -0
  145. package/plugins/sp/scripts/transition-shim-check.ts +238 -0
  146. package/plugins/sp/scripts/validate-commands.ts +689 -0
  147. package/plugins/sp/scripts/validate-flag-contracts.ts +878 -0
  148. package/plugins/sp/scripts/verify-answer-lint.ts +530 -0
  149. package/plugins/sp/scripts/workflow-step-profile.mjs +316 -0
  150. package/plugins/sp/scripts/workflow-step-profile.ts +456 -0
  151. package/plugins/sp/scripts/wrapup-steps.mjs +373 -0
  152. package/plugins/sp/scripts/wrapup-steps.ts +466 -0
@@ -0,0 +1,615 @@
1
+ #!/usr/bin/env node
2
+ // @bun
3
+ import { createRequire } from 'node:module';
4
+
5
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
6
+
7
+ // plugins/sp/scripts/daily-summary/daily-summary.ts
8
+ import { spawn, spawnSync } from 'node:child_process';
9
+ import { existsSync, mkdirSync, readlinkSync, writeFileSync } from 'node:fs';
10
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
11
+
12
+ // plugins/sp/scripts/daily-summary/logger.ts
13
+ var state = { console: true, file: false };
14
+ function emit(stream, message) {
15
+ if (!state.console) return;
16
+ console[stream](message);
17
+ }
18
+ var logger = {
19
+ info: (message) => emit('log', message),
20
+ warn: (message) => emit('warn', message),
21
+ error: (message) => emit('error', message),
22
+ };
23
+
24
+ // plugins/sp/scripts/daily-summary/daily-summary.ts
25
+ var DAILY_DIR = 'docs/daily';
26
+ var DEFAULT_DATE = 'today';
27
+ function parseArgs(argv = process.argv.slice(2)) {
28
+ const args = argv;
29
+ const options = {
30
+ date: DEFAULT_DATE,
31
+ dryRun: false,
32
+ skipGit: false,
33
+ skipCcusage: false,
34
+ };
35
+ for (let i = 0; i < args.length; i++) {
36
+ const arg = args[i];
37
+ if (arg === '--date' && i + 1 < args.length) {
38
+ options.date = args[++i];
39
+ } else if (arg === '--dry-run') {
40
+ options.dryRun = true;
41
+ } else if (arg === '--output' && i + 1 < args.length) {
42
+ options.outputPath = args[++i];
43
+ } else if (arg === '--no-git') {
44
+ options.skipGit = true;
45
+ } else if (arg === '--no-ccusage') {
46
+ options.skipCcusage = true;
47
+ } else if (arg === '--help' || arg === '-h') {
48
+ printUsage();
49
+ process.exit(0);
50
+ }
51
+ }
52
+ if (options.date === 'today') {
53
+ options.date = todayLocal();
54
+ } else if (options.date === 'yesterday') {
55
+ options.date = yesterdayLocal();
56
+ }
57
+ return options;
58
+ }
59
+ function printUsage() {
60
+ console.log(`
61
+ sp:daily-summary \u2014 Generate daily summary reports
62
+
63
+ Usage: daily-summary.ts [options]
64
+
65
+ Options:
66
+ --date YYYY-MM-DD Date for summary (default: today, also: yesterday)
67
+ --dry-run Show summary without writing file
68
+ --output <path> Write to custom path
69
+ --no-git Skip git history collection
70
+ --no-ccusage Skip token usage collection
71
+ --help, -h Show this help
72
+
73
+ Examples:
74
+ daily-summary.ts # Today's summary
75
+ daily-summary.ts --date yesterday # Yesterday's summary
76
+ daily-summary.ts --dry-run # Preview without writing
77
+ `);
78
+ }
79
+ function todayLocal() {
80
+ const proc = spawnSync('date', ['+%Y-%m-%d'], { encoding: 'utf8' });
81
+ return (proc.stdout ?? '').trim();
82
+ }
83
+ function yesterdayLocal() {
84
+ const epochProc = spawnSync('date', ['+%s'], { encoding: 'utf8' });
85
+ const epoch = parseInt((epochProc.stdout ?? '').trim(), 10);
86
+ const yesterdayEpoch = epoch - 86400;
87
+ let proc = spawnSync('date', ['-r', String(yesterdayEpoch), '+%Y-%m-%d'], { encoding: 'utf8' });
88
+ if ((proc.status ?? 1) !== 0) {
89
+ proc = spawnSync('date', ['-d', `@${yesterdayEpoch}`, '+%Y-%m-%d'], { encoding: 'utf8' });
90
+ }
91
+ return (proc.stdout ?? '').trim();
92
+ }
93
+ function getDateRange(dateStr) {
94
+ const date = new Date(`${dateStr}T00:00:00`);
95
+ const start = `${dateStr} 00:00:00`;
96
+ const endDate = new Date(date);
97
+ endDate.setDate(endDate.getDate() + 1);
98
+ const end = `${endDate.toISOString().slice(0, 10)} 00:00:00`;
99
+ return { start, end };
100
+ }
101
+ var defaultProcessSpawner = (cmd, args, env) => {
102
+ return new Promise((resolve2, reject) => {
103
+ try {
104
+ const proc = spawn(cmd, args, {
105
+ stdio: ['ignore', 'pipe', 'pipe'],
106
+ env: env ?? process.env,
107
+ });
108
+ const stdoutChunks = [];
109
+ const stderrChunks = [];
110
+ proc.stdout.on('data', (chunk) => stdoutChunks.push(Buffer.from(chunk)));
111
+ proc.stderr.on('data', (chunk) => stderrChunks.push(Buffer.from(chunk)));
112
+ proc.on('close', (exitCode) => {
113
+ resolve2({
114
+ stdout: Buffer.concat(stdoutChunks).toString('utf8'),
115
+ stderr: Buffer.concat(stderrChunks).toString('utf8'),
116
+ exitCode: exitCode ?? 0,
117
+ });
118
+ });
119
+ proc.on('error', (err) => {
120
+ reject(err);
121
+ });
122
+ } catch (err) {
123
+ reject(err);
124
+ }
125
+ });
126
+ };
127
+ var processSpawner = defaultProcessSpawner;
128
+ function setProcessSpawner(next) {
129
+ processSpawner = next ?? defaultProcessSpawner;
130
+ }
131
+ async function getCcusageData(date) {
132
+ try {
133
+ const env = { ...process.env };
134
+ const ccusageCheck = await processSpawner('ccusage', ['--version'], env);
135
+ if (ccusageCheck.exitCode !== 0) {
136
+ return null;
137
+ }
138
+ const since = `${date}T00:00:00`;
139
+ const until = `${date}T23:59:59`;
140
+ const proc = await processSpawner('ccusage', ['daily', '--since', since, '--until', until, '--json'], env);
141
+ if (proc.exitCode !== 0) {
142
+ logger.warn(`ccusage error: ${proc.stderr}`);
143
+ return null;
144
+ }
145
+ const data = JSON.parse(proc.stdout);
146
+ return data;
147
+ } catch (error) {
148
+ logger.warn(`Failed to get ccusage data: ${error}`);
149
+ return null;
150
+ }
151
+ }
152
+ async function getSpurHistoryHealth(date, dbPath = '.spur/spur.db') {
153
+ try {
154
+ const resolvedPath = resolve(process.cwd(), dbPath);
155
+ if (!existsSync(resolvedPath)) {
156
+ return null;
157
+ }
158
+ const { Database } = await import('bun:sqlite');
159
+ const db = new Database(resolvedPath, { readonly: true });
160
+ try {
161
+ const loopTable = db
162
+ .query("SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?")
163
+ .get('history_board_loop_findings');
164
+ let loops = [];
165
+ if (loopTable) {
166
+ const rows = db
167
+ .query(`SELECT tool_name, args_digest, repeats, session_id, first_seq, last_seq, started_at
168
+ FROM history_board_loop_findings
169
+ WHERE started_at IS NULL OR started_at LIKE ?
170
+ ORDER BY repeats DESC
171
+ LIMIT 20`)
172
+ .all(`${date}%`);
173
+ loops = rows.map((r) => ({
174
+ toolName: r.tool_name,
175
+ argsDigest: r.args_digest || 'repeated execution',
176
+ repeats: r.repeats,
177
+ sessionId: r.session_id,
178
+ fromSeq: r.first_seq,
179
+ toSeq: r.last_seq,
180
+ wastedTokens: r.repeats * 250,
181
+ }));
182
+ }
183
+ let toolCalls = 0;
184
+ let toolErrors = 0;
185
+ const toolTable = db
186
+ .query("SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?")
187
+ .get('history_board_tool_5m');
188
+ if (toolTable) {
189
+ const stats = db
190
+ .query(`SELECT SUM(calls) AS calls, SUM(errors) AS errors
191
+ FROM history_board_tool_5m
192
+ WHERE bucket_start LIKE ?`)
193
+ .get(`${date}%`);
194
+ toolCalls = stats?.calls ?? 0;
195
+ toolErrors = stats?.errors ?? 0;
196
+ }
197
+ const redundantCalls = loops.reduce((acc, l) => acc + Math.max(0, l.repeats - 1), 0);
198
+ const wastedTokens = loops.reduce((acc, l) => acc + l.wastedTokens, 0);
199
+ const errorRatePct = toolCalls > 0 ? (toolErrors / toolCalls) * 100 : 0;
200
+ const remediationProposals = [];
201
+ for (const lp of loops.slice(0, 5)) {
202
+ const cleanTool = lp.toolName.replace(/[^a-zA-Z0-9_-]/g, '_');
203
+ const key = `repetition:${cleanTool}:${lp.argsDigest.slice(0, 16)}`;
204
+ const title = `Break execution loop in ${lp.toolName} (${lp.repeats} repeats)`;
205
+ const command = `spur task create "<title>" --feature <id> && spur task update <wbs> --section Plan --from-file <path>`;
206
+ remediationProposals.push({ key, title, command });
207
+ }
208
+ if (toolCalls > 0 && errorRatePct > 10) {
209
+ const key = 'reliability:tooling:high-error-rate';
210
+ const title = `Investigate high tool error rate (${errorRatePct.toFixed(1)}%)`;
211
+ const command = `spur task create "<title>" --feature <id> && spur task update <wbs> --section Plan --from-file <path>`;
212
+ remediationProposals.push({ key, title, command });
213
+ }
214
+ return {
215
+ toolCalls,
216
+ toolErrors,
217
+ errorRatePct,
218
+ loops,
219
+ redundantCalls,
220
+ wastedTokens,
221
+ remediationProposals,
222
+ };
223
+ } finally {
224
+ db.close();
225
+ }
226
+ } catch {
227
+ return null;
228
+ }
229
+ }
230
+ async function getGitCommits(date) {
231
+ try {
232
+ const { start, end } = getDateRange(date);
233
+ const proc = await processSpawner('git', [
234
+ 'log',
235
+ '--since',
236
+ start,
237
+ '--until',
238
+ end,
239
+ '--pretty=format:%H|%ad|%s',
240
+ '--date=iso',
241
+ '--numstat',
242
+ ]);
243
+ if (proc.exitCode !== 0) {
244
+ logger.warn('Failed to get git commits');
245
+ return [];
246
+ }
247
+ const commits = [];
248
+ const lines = proc.stdout.trim().split(`
249
+ `);
250
+ let currentCommit = null;
251
+ for (const line of lines) {
252
+ if (!line.trim()) continue;
253
+ if (line.includes('|')) {
254
+ const parts = line.split('|');
255
+ if (parts.length >= 3) {
256
+ if (currentCommit?.hash) {
257
+ commits.push(currentCommit);
258
+ }
259
+ currentCommit = {
260
+ hash: parts[0],
261
+ date: parts[1],
262
+ message: parts[2],
263
+ filesChanged: 0,
264
+ insertions: 0,
265
+ deletions: 0,
266
+ };
267
+ }
268
+ } else if (currentCommit && line.includes('\t')) {
269
+ const parts = line.split('\t');
270
+ if (parts.length >= 3) {
271
+ const insertions = parseInt(parts[0], 10) || 0;
272
+ const deletions = parseInt(parts[1], 10) || 0;
273
+ currentCommit.filesChanged = (currentCommit.filesChanged ?? 0) + 1;
274
+ currentCommit.insertions = (currentCommit.insertions ?? 0) + insertions;
275
+ currentCommit.deletions = (currentCommit.deletions ?? 0) + deletions;
276
+ }
277
+ }
278
+ }
279
+ if (currentCommit?.hash) {
280
+ commits.push(currentCommit);
281
+ }
282
+ return commits;
283
+ } catch (error) {
284
+ logger.warn(`Failed to get git commits: ${error}`);
285
+ return [];
286
+ }
287
+ }
288
+ async function promptUser() {
289
+ if (process.env.SP_DAILY_SUMMARY_NO_PROMPT === '1') {
290
+ return { learnings: '', issuesFixed: '', pending: '' };
291
+ }
292
+ if (process.env.RD3_DAILY_SUMMARY_NO_PROMPT === '1') {
293
+ logger.warn('[deprecate] RD3_DAILY_SUMMARY_NO_PROMPT is deprecated; use SP_DAILY_SUMMARY_NO_PROMPT');
294
+ return { learnings: '', issuesFixed: '', pending: '' };
295
+ }
296
+ console.log(`
297
+ \uD83D\uDCCA Daily Summary \u2014 ${todayLocal()}`);
298
+ console.log('\u2550'.repeat(50));
299
+ console.log(`
300
+ Please provide the following (press Enter to skip):
301
+ `);
302
+ if (!process.stdin.isTTY) {
303
+ const chunks = [];
304
+ for await (const chunk of process.stdin) {
305
+ chunks.push(chunk);
306
+ }
307
+ const buffered = Buffer.concat(chunks).toString('utf-8');
308
+ const [learnings2 = '', issuesFixed2 = '', pending2 = ''] = buffered.split(`
309
+ `);
310
+ return {
311
+ learnings: learnings2.trim(),
312
+ issuesFixed: issuesFixed2.trim(),
313
+ pending: pending2.trim(),
314
+ };
315
+ }
316
+ const readline = await import('node:readline');
317
+ const rl = readline.createInterface({
318
+ input: process.stdin,
319
+ output: process.stdout,
320
+ });
321
+ const question = (prompt) =>
322
+ new Promise((resolve2) => {
323
+ rl.question(prompt, (answer) => {
324
+ resolve2(answer.trim());
325
+ });
326
+ });
327
+ const learnings = await question(`1. What did you learn today? (optional)
328
+ > `);
329
+ const issuesFixed = await question(`
330
+ 2. What issues did you fix? (optional)
331
+ > `);
332
+ const pending = await question(`
333
+ 3. What's pending for tomorrow? (optional)
334
+ > `);
335
+ rl.close();
336
+ return {
337
+ learnings,
338
+ issuesFixed,
339
+ pending,
340
+ };
341
+ }
342
+ function generateMarkdown(summary) {
343
+ const lines = [];
344
+ lines.push(`# Daily Summary \u2014 ${summary.date}`);
345
+ lines.push('');
346
+ lines.push(`**Generated:** ${summary.generatedAt}`);
347
+ lines.push('');
348
+ lines.push('## Meta');
349
+ lines.push('');
350
+ lines.push(`- **Date:** ${summary.date}`);
351
+ lines.push(`- **Platforms:** ${summary.platforms.join(', ') || 'unknown'}`);
352
+ lines.push('');
353
+ if (summary.tokenUsage) {
354
+ const tu = summary.tokenUsage;
355
+ lines.push('## Token Usage');
356
+ lines.push('');
357
+ lines.push(`| Metric | Value |`);
358
+ lines.push(`|--------|-------|`);
359
+ lines.push(`| Input Tokens | ${tu.inputTokens.toLocaleString()} |`);
360
+ lines.push(`| Output Tokens | ${tu.outputTokens.toLocaleString()} |`);
361
+ lines.push(`| Cache Tokens | ${tu.cacheTokens.toLocaleString()} |`);
362
+ lines.push(`| Total Tokens | ${tu.totalTokens.toLocaleString()} |`);
363
+ lines.push(`| Estimated Cost | $${tu.costUsd.toFixed(4)} |`);
364
+ lines.push('');
365
+ if (tu.inputTokens > 0) {
366
+ const cacheHitRate = (tu.cacheTokens / (tu.inputTokens + tu.cacheTokens)) * 100;
367
+ lines.push(`**Cache Hit Rate:** ${cacheHitRate.toFixed(1)}%`);
368
+ lines.push('');
369
+ }
370
+ }
371
+ if (summary.gitActivity) {
372
+ const ga = summary.gitActivity;
373
+ lines.push('## Git Activity');
374
+ lines.push('');
375
+ lines.push(`| Metric | Value |`);
376
+ lines.push(`|--------|-------|`);
377
+ lines.push(`| Commits | ${ga.commitCount} |`);
378
+ lines.push(`| Files Changed | ${ga.filesChanged} |`);
379
+ lines.push(`| Insertions | +${ga.insertions} |`);
380
+ lines.push(`| Deletions | -${ga.deletions} |`);
381
+ lines.push('');
382
+ }
383
+ if (summary.commits.length > 0) {
384
+ lines.push('## Commits');
385
+ lines.push('');
386
+ for (const commit of summary.commits.slice(0, 10)) {
387
+ const shortHash = commit.hash.slice(0, 7);
388
+ lines.push(`- \`${shortHash}\` ${commit.message}`);
389
+ }
390
+ if (summary.commits.length > 10) {
391
+ lines.push(`- ... and ${summary.commits.length - 10} more commits`);
392
+ }
393
+ lines.push('');
394
+ }
395
+ const { learnings, issuesFixed, pending } = summary.annotations;
396
+ if (learnings) {
397
+ lines.push('## Learnings');
398
+ lines.push('');
399
+ lines.push(learnings);
400
+ lines.push('');
401
+ }
402
+ if (issuesFixed) {
403
+ lines.push('## Issues Fixed');
404
+ lines.push('');
405
+ lines.push(issuesFixed);
406
+ lines.push('');
407
+ }
408
+ if (pending) {
409
+ lines.push('## Pending');
410
+ lines.push('');
411
+ lines.push(pending);
412
+ lines.push('');
413
+ }
414
+ if (summary.historyHealth) {
415
+ const hh = summary.historyHealth;
416
+ lines.push('## Execution Loops & Health Findings');
417
+ lines.push('');
418
+ if (hh.loops.length === 0 && hh.toolCalls === 0) {
419
+ lines.push('- **Status:** \u2705 Clean \u2014 No execution loops or tool calls recorded for this date.');
420
+ lines.push('');
421
+ } else {
422
+ lines.push('| Metric | Value |');
423
+ lines.push('|--------|-------|');
424
+ lines.push(`| Tool Invocations | ${hh.toolCalls.toLocaleString()} |`);
425
+ lines.push(`| Tool Errors | ${hh.toolErrors.toLocaleString()} (${hh.errorRatePct.toFixed(1)}%) |`);
426
+ lines.push(`| Detected Loops (Repeats \u2265 3) | ${hh.loops.length} |`);
427
+ lines.push(`| Redundant Invocations | ${hh.redundantCalls.toLocaleString()} |`);
428
+ lines.push(`| Estimated Wasted Tokens | ${hh.wastedTokens.toLocaleString()} |`);
429
+ lines.push('');
430
+ if (hh.loops.length > 0) {
431
+ lines.push('### Detected Execution Loops');
432
+ lines.push('');
433
+ for (const lp of hh.loops.slice(0, 10)) {
434
+ const seqInfo = lp.fromSeq && lp.toSeq ? ` (steps #${lp.fromSeq} \u2192 #${lp.toSeq})` : '';
435
+ const argsHint =
436
+ lp.argsDigest === '74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b'
437
+ ? 'empty/unrecorded arguments'
438
+ : lp.argsDigest.length > 28
439
+ ? `${lp.argsDigest.slice(0, 24)}...`
440
+ : lp.argsDigest;
441
+ lines.push(
442
+ `- \`${lp.toolName || 'unknown'}\` \xD7 **${lp.repeats} repeats** in session \`${lp.sessionId}\`${seqInfo}`,
443
+ );
444
+ lines.push(` - *Args hint:* \`${argsHint}\` (~${lp.wastedTokens.toLocaleString()} wasted tokens)`);
445
+ }
446
+ lines.push('');
447
+ }
448
+ if (hh.remediationProposals.length > 0) {
449
+ lines.push('### Auto-Healing Remediation Proposals');
450
+ lines.push('');
451
+ lines.push('To remediate root causes and prevent recurring token waste, execute:');
452
+ lines.push('');
453
+ lines.push('```bash');
454
+ for (const prop of hh.remediationProposals) {
455
+ lines.push(`# ${prop.title} [${prop.key}]`);
456
+ lines.push(prop.command);
457
+ lines.push('');
458
+ }
459
+ lines.push('```');
460
+ lines.push('');
461
+ }
462
+ }
463
+ }
464
+ if (summary.historyReportPath) {
465
+ lines.push('## History Report');
466
+ lines.push('');
467
+ lines.push(`- **Newest artifact:** ${summary.historyReportPath}`);
468
+ lines.push('');
469
+ }
470
+ lines.push('---');
471
+ lines.push('');
472
+ lines.push(`*Generated by sp:daily-summary at ${summary.generatedAt}*`);
473
+ return lines.join(`
474
+ `);
475
+ }
476
+ function ensureDir(path) {
477
+ if (!existsSync(path)) {
478
+ mkdirSync(path, { recursive: true });
479
+ }
480
+ }
481
+ function writeSummary(markdown, options) {
482
+ const filename = `summary_${options.date.replace(/-/g, '')}.md`;
483
+ const outputPath = options.outputPath || join(DAILY_DIR, filename);
484
+ ensureDir(join(outputPath, '..'));
485
+ writeFileSync(outputPath, markdown, 'utf-8');
486
+ return outputPath;
487
+ }
488
+ function resolveHistoryReportPath() {
489
+ const pointer = resolve(process.cwd(), '.spur', 'reports', 'history', 'latest.json');
490
+ if (!existsSync(pointer)) {
491
+ return;
492
+ }
493
+ try {
494
+ const target = readlinkSync(pointer);
495
+ const resolved = isAbsolute(target) ? target : resolve(dirname(pointer), target);
496
+ return existsSync(resolved) ? resolved : undefined;
497
+ } catch {
498
+ return;
499
+ }
500
+ }
501
+ async function buildDailySummary(options) {
502
+ const platforms = [];
503
+ let tokenUsage;
504
+ if (!options.skipCcusage) {
505
+ const ccusageData = await getCcusageData(options.date);
506
+ if (ccusageData?.totals) {
507
+ const totals = ccusageData.totals;
508
+ tokenUsage = {
509
+ inputTokens: totals.inputTokens,
510
+ outputTokens: totals.outputTokens,
511
+ cacheTokens: totals.cacheCreationTokens + totals.cacheReadTokens,
512
+ totalTokens: totals.totalTokens,
513
+ costUsd: totals.totalCost,
514
+ };
515
+ platforms.push('Claude Code');
516
+ }
517
+ }
518
+ let gitActivity;
519
+ let commits = [];
520
+ if (!options.skipGit) {
521
+ commits = await getGitCommits(options.date);
522
+ if (commits.length > 0) {
523
+ gitActivity = commits.reduce(
524
+ (acc, commit) => ({
525
+ commitCount: acc.commitCount + 1,
526
+ filesChanged: acc.filesChanged + (commit.filesChanged || 0),
527
+ insertions: acc.insertions + (commit.insertions || 0),
528
+ deletions: acc.deletions + (commit.deletions || 0),
529
+ }),
530
+ { commitCount: 0, filesChanged: 0, insertions: 0, deletions: 0 },
531
+ );
532
+ platforms.push('Git');
533
+ }
534
+ }
535
+ const historyReportPath = resolveHistoryReportPath();
536
+ const annotations = await promptUser();
537
+ const result = {
538
+ date: options.date,
539
+ platforms,
540
+ commits,
541
+ annotations,
542
+ historyReportPath,
543
+ generatedAt: new Date().toISOString().replace('T', ' ').slice(0, 19),
544
+ };
545
+ if (tokenUsage !== undefined) {
546
+ result.tokenUsage = tokenUsage;
547
+ }
548
+ if (gitActivity !== undefined) {
549
+ result.gitActivity = gitActivity;
550
+ }
551
+ const historyHealth = await getSpurHistoryHealth(options.date);
552
+ if (historyHealth && (historyHealth.loops.length > 0 || historyHealth.toolCalls > 0)) {
553
+ result.historyHealth = historyHealth;
554
+ platforms.push('Spur History');
555
+ }
556
+ return result;
557
+ }
558
+ async function main() {
559
+ const options = parseArgs();
560
+ logger.info(`Generating daily summary for ${options.date}...`);
561
+ try {
562
+ const summary = await buildDailySummary(options);
563
+ const markdown = generateMarkdown(summary);
564
+ if (options.dryRun) {
565
+ console.log(`
566
+ ${markdown}
567
+ `);
568
+ logger.info('(dry-run) Summary not written to file');
569
+ } else {
570
+ const outputPath = writeSummary(markdown, options);
571
+ console.log(`
572
+ ${markdown}
573
+ `);
574
+ console.log(`
575
+ \u2705 Summary written to: ${outputPath}`);
576
+ }
577
+ console.log(`
578
+ \uD83D\uDCCA Summary Statistics:`);
579
+ console.log(` Date: ${summary.date}`);
580
+ console.log(` Platforms: ${summary.platforms.join(', ') || 'none'}`);
581
+ if (summary.tokenUsage) {
582
+ console.log(` Tokens: ${summary.tokenUsage.totalTokens.toLocaleString()}`);
583
+ console.log(` Cost: $${summary.tokenUsage.costUsd.toFixed(4)}`);
584
+ }
585
+ if (summary.gitActivity) {
586
+ console.log(` Commits: ${summary.gitActivity.commitCount}`);
587
+ }
588
+ } catch (error) {
589
+ logger.error(`Failed to generate summary: ${error}`);
590
+ process.exit(1);
591
+ }
592
+ }
593
+ main().catch((error) => {
594
+ logger.error(`Daily summary failed: ${error}`);
595
+ process.exit(1);
596
+ });
597
+
598
+ export {
599
+ buildDailySummary,
600
+ defaultProcessSpawner,
601
+ ensureDir,
602
+ generateMarkdown,
603
+ getCcusageData,
604
+ getDateRange,
605
+ getGitCommits,
606
+ getSpurHistoryHealth,
607
+ main,
608
+ parseArgs,
609
+ printUsage,
610
+ promptUser,
611
+ setProcessSpawner,
612
+ todayLocal,
613
+ writeSummary,
614
+ yesterdayLocal,
615
+ };