smart-commit-copilot-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +392 -0
- package/docs/configuration.md +262 -0
- package/docs/contracts.md +134 -0
- package/docs/getting-started.md +177 -0
- package/docs/integrations.md +85 -0
- package/docs/publish.md +135 -0
- package/docs/release-checklist.md +39 -0
- package/docs/releases/0.1.0-draft.md +52 -0
- package/docs/roadmap.md +94 -0
- package/examples/agent/bridge-agent.mjs +51 -0
- package/examples/agent/report-agent.mjs +48 -0
- package/examples/config/smart-commit.json +60 -0
- package/examples/hooks/cursor-bridge-wrapper.sh +12 -0
- package/examples/hooks/husky-pre-commit.sh +6 -0
- package/examples/hooks/smart-commit-bridge.sh +11 -0
- package/out/cli.js +19 -0
- package/out/cli.js.map +1 -0
- package/out/cliApp.js +239 -0
- package/out/cliApp.js.map +1 -0
- package/out/commands/bridge.js +607 -0
- package/out/commands/bridge.js.map +1 -0
- package/out/commands/report.js +266 -0
- package/out/commands/report.js.map +1 -0
- package/out/commands/types.js +3 -0
- package/out/commands/types.js.map +1 -0
- package/out/commitMessage/index.js +110 -0
- package/out/commitMessage/index.js.map +1 -0
- package/out/commitMessage/mockProvider.js +27 -0
- package/out/commitMessage/mockProvider.js.map +1 -0
- package/out/commitMessage/openaiProvider.js +44 -0
- package/out/commitMessage/openaiProvider.js.map +1 -0
- package/out/commitMessage/prompt.js +65 -0
- package/out/commitMessage/prompt.js.map +1 -0
- package/out/commitMessage/protocol.js +126 -0
- package/out/commitMessage/protocol.js.map +1 -0
- package/out/commitMessage/provider.js +3 -0
- package/out/commitMessage/provider.js.map +1 -0
- package/out/config/cliArgs.js +249 -0
- package/out/config/cliArgs.js.map +1 -0
- package/out/config/constants.js +47 -0
- package/out/config/constants.js.map +1 -0
- package/out/config/env.js +183 -0
- package/out/config/env.js.map +1 -0
- package/out/config/file.js +245 -0
- package/out/config/file.js.map +1 -0
- package/out/config/index.js +46 -0
- package/out/config/index.js.map +1 -0
- package/out/config/legacySmartCommit.js +200 -0
- package/out/config/legacySmartCommit.js.map +1 -0
- package/out/config/merge.js +70 -0
- package/out/config/merge.js.map +1 -0
- package/out/config/runtime.js +36 -0
- package/out/config/runtime.js.map +1 -0
- package/out/config/schema.js +204 -0
- package/out/config/schema.js.map +1 -0
- package/out/contracts.js +311 -0
- package/out/contracts.js.map +1 -0
- package/out/git.js +119 -0
- package/out/git.js.map +1 -0
- package/out/logger.js +17 -0
- package/out/logger.js.map +1 -0
- package/out/openaiCompatible.js +67 -0
- package/out/openaiCompatible.js.map +1 -0
- package/out/output.js +23 -0
- package/out/output.js.map +1 -0
- package/out/passHistory/index.js +119 -0
- package/out/passHistory/index.js.map +1 -0
- package/out/passHistory/store.js +252 -0
- package/out/passHistory/store.js.map +1 -0
- package/out/passHistory/types.js +6 -0
- package/out/passHistory/types.js.map +1 -0
- package/out/promptContext.js +72 -0
- package/out/promptContext.js.map +1 -0
- package/out/renderOutput.js +89 -0
- package/out/renderOutput.js.map +1 -0
- package/out/reporting/aggregate.js +113 -0
- package/out/reporting/aggregate.js.map +1 -0
- package/out/reporting/index.js +72 -0
- package/out/reporting/index.js.map +1 -0
- package/out/reporting/mockProvider.js +25 -0
- package/out/reporting/mockProvider.js.map +1 -0
- package/out/reporting/openaiProvider.js +19 -0
- package/out/reporting/openaiProvider.js.map +1 -0
- package/out/reporting/prompt.js +28 -0
- package/out/reporting/prompt.js.map +1 -0
- package/out/reporting/provider.js +3 -0
- package/out/reporting/provider.js.map +1 -0
- package/out/reporting/render.js +151 -0
- package/out/reporting/render.js.map +1 -0
- package/out/reporting/timeWindow.js +79 -0
- package/out/reporting/timeWindow.js.map +1 -0
- package/out/reporting/types.js +11 -0
- package/out/reporting/types.js.map +1 -0
- package/out/review/index.js +64 -0
- package/out/review/index.js.map +1 -0
- package/out/review/mockProvider.js +57 -0
- package/out/review/mockProvider.js.map +1 -0
- package/out/review/openaiProvider.js +40 -0
- package/out/review/openaiProvider.js.map +1 -0
- package/out/review/parser.js +92 -0
- package/out/review/parser.js.map +1 -0
- package/out/review/prompt.js +61 -0
- package/out/review/prompt.js.map +1 -0
- package/out/review/provider.js +3 -0
- package/out/review/provider.js.map +1 -0
- package/out/review/types.js +3 -0
- package/out/review/types.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRequestedOutputFormat = resolveRequestedOutputFormat;
|
|
4
|
+
exports.renderConfigResolveOutput = renderConfigResolveOutput;
|
|
5
|
+
exports.renderBridgeOutput = renderBridgeOutput;
|
|
6
|
+
exports.renderReportOutput = renderReportOutput;
|
|
7
|
+
function resolveRequestedOutputFormat(argv, env, fallback = "json") {
|
|
8
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
9
|
+
const token = argv[index];
|
|
10
|
+
if (token === "--output") {
|
|
11
|
+
return normalizeOutputFormat(argv[index + 1], fallback);
|
|
12
|
+
}
|
|
13
|
+
if (token.startsWith("--output=")) {
|
|
14
|
+
return normalizeOutputFormat(token.slice("--output=".length), fallback);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return normalizeOutputFormat(env.SMART_COMMIT_OUTPUT_FORMAT, fallback);
|
|
18
|
+
}
|
|
19
|
+
function renderConfigResolveOutput(payload, format) {
|
|
20
|
+
if (format === "json") {
|
|
21
|
+
return `${JSON.stringify(payload, null, 2)}\n`;
|
|
22
|
+
}
|
|
23
|
+
return toText([
|
|
24
|
+
"smart-commit config resolve",
|
|
25
|
+
`Schema Version: ${payload.schemaVersion}`,
|
|
26
|
+
`Status: ${payload.status}`,
|
|
27
|
+
`Repository Path: ${payload.runtime.repositoryPath ?? "(none)"}`,
|
|
28
|
+
`Config Path: ${payload.runtime.configPath ?? "(none)"}`,
|
|
29
|
+
`Output Format: ${payload.config.output.format}`,
|
|
30
|
+
`Base URL: ${payload.config.connection.baseUrl || "(unset)"}`,
|
|
31
|
+
`Model: ${payload.config.connection.model || "(unset)"}`,
|
|
32
|
+
`Review Threshold: ${payload.config.review.threshold}`,
|
|
33
|
+
`Review Language: ${payload.config.review.language}`,
|
|
34
|
+
`Commit Language: ${payload.config.commitMessage.language}`,
|
|
35
|
+
`Auto Commit: ${String(payload.config.git.autoCommit)}`,
|
|
36
|
+
`Auto Push: ${String(payload.config.git.autoPush)}`
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
function renderBridgeOutput(payload, format) {
|
|
40
|
+
if (format === "json") {
|
|
41
|
+
return `${JSON.stringify(payload, null, 2)}\n`;
|
|
42
|
+
}
|
|
43
|
+
return toText([
|
|
44
|
+
"smart-commit bridge",
|
|
45
|
+
`Schema Version: ${payload.schemaVersion}`,
|
|
46
|
+
`Status: ${payload.status}`,
|
|
47
|
+
`Phase: ${payload.phase}`,
|
|
48
|
+
`Repository Path: ${payload.repositoryPath ?? "(none)"}`,
|
|
49
|
+
`Summary: ${payload.summary ?? "(none)"}`,
|
|
50
|
+
`Score: ${payload.score ?? "(none)"}`,
|
|
51
|
+
`Threshold: ${payload.threshold ?? "(none)"}`,
|
|
52
|
+
`Review Decision: ${payload.reviewDecision ?? "(none)"}`,
|
|
53
|
+
`Review Provider: ${payload.reviewProvider ?? "(none)"}`,
|
|
54
|
+
`Commit Message: ${payload.commitMessage ?? "(none)"}`,
|
|
55
|
+
`Commit Message Source: ${payload.commitMessageSource}`,
|
|
56
|
+
`Did Commit: ${String(payload.didCommit)}`,
|
|
57
|
+
`Did Push: ${String(payload.didPush)}`,
|
|
58
|
+
`Pass History Wrote: ${String(payload.passHistory.wrote)}`,
|
|
59
|
+
payload.error ? `Error Code: ${payload.error.code}` : "",
|
|
60
|
+
payload.error ? `Error Message: ${payload.error.message}` : ""
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
function renderReportOutput(payload, format) {
|
|
64
|
+
if (format === "json") {
|
|
65
|
+
return `${JSON.stringify(payload, null, 2)}\n`;
|
|
66
|
+
}
|
|
67
|
+
return toText([
|
|
68
|
+
"smart-commit report generate",
|
|
69
|
+
`Schema Version: ${payload.schemaVersion}`,
|
|
70
|
+
`Status: ${payload.status}`,
|
|
71
|
+
`Repository Path: ${payload.repositoryPath ?? "(none)"}`,
|
|
72
|
+
`Period: ${payload.periodType ?? "(none)"}`,
|
|
73
|
+
`Render Mode: ${payload.renderMode}`,
|
|
74
|
+
`Report Provider: ${payload.reportProvider ?? "(none)"}`,
|
|
75
|
+
`Output File: ${payload.outputFilePath ?? "(none)"}`,
|
|
76
|
+
`Pass History File: ${payload.passHistoryFilePath ?? "(none)"}`,
|
|
77
|
+
`Summary: ${payload.summary}`,
|
|
78
|
+
payload.error ? `Error Code: ${payload.error.code}` : "",
|
|
79
|
+
payload.error ? `Error Message: ${payload.error.message}` : ""
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
function normalizeOutputFormat(value, fallback) {
|
|
83
|
+
const normalized = value?.trim().toLowerCase();
|
|
84
|
+
return normalized === "text" ? "text" : normalized === "json" ? "json" : fallback;
|
|
85
|
+
}
|
|
86
|
+
function toText(lines) {
|
|
87
|
+
return `${lines.filter((line) => line !== "").join("\n")}\n`;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=renderOutput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderOutput.js","sourceRoot":"","sources":["../src/renderOutput.ts"],"names":[],"mappings":";;AAeA,oEAiBC;AAED,8DAoBC;AAED,gDAwBC;AAED,gDAmBC;AAtFD,SAAgB,4BAA4B,CAC1C,IAAuB,EACvB,GAAsB,EACtB,WAA4B,MAAM;IAElC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,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AC,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AACpF,CAAC;AAED,SAAS,MAAM,CAAC,KAAe;IAC7B,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildReportFacts = buildReportFacts;
|
|
4
|
+
const timeWindow_1 = require("./timeWindow");
|
|
5
|
+
function buildReportFacts(input) {
|
|
6
|
+
const window = (0, timeWindow_1.resolveReportTimeWindow)(input.periodType, input.weekStartsOn, input.now);
|
|
7
|
+
const records = input.records
|
|
8
|
+
.filter((record) => (0, timeWindow_1.isRecordInReportTimeWindow)(record.timestampMs, window))
|
|
9
|
+
.sort((left, right) => right.timestampMs - left.timestampMs);
|
|
10
|
+
const scoredRecords = records.filter((record) => typeof record.score === "number");
|
|
11
|
+
const fullDiffCharsTotal = records.reduce((sum, record) => sum + record.fullDiffChars, 0);
|
|
12
|
+
return {
|
|
13
|
+
period: window,
|
|
14
|
+
language: input.language,
|
|
15
|
+
recordCount: records.length,
|
|
16
|
+
repositoryNames: buildRepositoryNames(records),
|
|
17
|
+
totals: {
|
|
18
|
+
reviewPassed: countBy(records, (record) => record.eventType === "review_passed"),
|
|
19
|
+
commitPushCompleted: countBy(records, (record) => record.eventType === "commit_push_completed"),
|
|
20
|
+
averageScore: scoredRecords.length > 0
|
|
21
|
+
? roundToTwoDecimals(scoredRecords.reduce((sum, record) => sum + (record.score ?? 0), 0) / scoredRecords.length)
|
|
22
|
+
: null,
|
|
23
|
+
highestScore: scoredRecords.length > 0 ? Math.max(...scoredRecords.map((record) => record.score)) : null,
|
|
24
|
+
lowestScore: scoredRecords.length > 0 ? Math.min(...scoredRecords.map((record) => record.score)) : null,
|
|
25
|
+
noScoreCount: records.length - scoredRecords.length,
|
|
26
|
+
fullDiffCharsTotal,
|
|
27
|
+
fullDiffCharsAverage: records.length > 0 ? roundToTwoDecimals(fullDiffCharsTotal / records.length) : 0
|
|
28
|
+
},
|
|
29
|
+
branches: buildTopCounts(records.map((record) => record.branchName), 8),
|
|
30
|
+
commitMessageSources: buildTopCounts(records.map((record) => record.commitMessageSource), 8),
|
|
31
|
+
models: buildTopCounts(records.map((record) => record.model), 8),
|
|
32
|
+
codeReviewSkills: buildTopCounts(records.map((record) => record.codeReviewSkillId), 8),
|
|
33
|
+
gitCommitMessageSkills: buildTopCounts(records.map((record) => record.gitCommitMessageSkillId), 8),
|
|
34
|
+
highlights: buildHighlights(records),
|
|
35
|
+
summaryThemes: buildSummaryThemes(records),
|
|
36
|
+
risks: buildRisks(records)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function buildRepositoryNames(records) {
|
|
40
|
+
return Array.from(new Set(records.map((record) => record.repositoryName))).sort((left, right) => left.localeCompare(right, "en"));
|
|
41
|
+
}
|
|
42
|
+
function buildHighlights(records) {
|
|
43
|
+
return records.slice(0, 8).map((record) => ({
|
|
44
|
+
timestamp: record.timestamp,
|
|
45
|
+
timestampMs: record.timestampMs,
|
|
46
|
+
repositoryName: record.repositoryName,
|
|
47
|
+
branchName: record.branchName,
|
|
48
|
+
commitMessage: record.commitMessage,
|
|
49
|
+
reviewSummary: record.reviewSummary,
|
|
50
|
+
score: record.score,
|
|
51
|
+
eventType: record.eventType,
|
|
52
|
+
fullDiffChars: record.fullDiffChars,
|
|
53
|
+
commitSHA: record.commitSHA
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
function buildSummaryThemes(records) {
|
|
57
|
+
const counts = new Map();
|
|
58
|
+
for (const record of records) {
|
|
59
|
+
const summary = normalizeSummary(record.reviewSummary);
|
|
60
|
+
if (!summary) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
counts.set(summary, (counts.get(summary) ?? 0) + 1);
|
|
64
|
+
}
|
|
65
|
+
return [...counts.entries()]
|
|
66
|
+
.sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0], "en"))
|
|
67
|
+
.slice(0, 8)
|
|
68
|
+
.map(([summary, count]) => ({ summary, count }));
|
|
69
|
+
}
|
|
70
|
+
function buildRisks(records) {
|
|
71
|
+
return records
|
|
72
|
+
.filter((record) => typeof record.score === "number" && record.score <= Math.min(record.threshold + 1, 10))
|
|
73
|
+
.slice(0, 8)
|
|
74
|
+
.map((record) => ({
|
|
75
|
+
timestamp: record.timestamp,
|
|
76
|
+
repositoryName: record.repositoryName,
|
|
77
|
+
branchName: record.branchName,
|
|
78
|
+
commitMessage: record.commitMessage,
|
|
79
|
+
reviewSummary: record.reviewSummary,
|
|
80
|
+
score: record.score,
|
|
81
|
+
threshold: record.threshold,
|
|
82
|
+
reason: record.score !== null && record.score <= record.threshold
|
|
83
|
+
? "Score is at or below the configured review threshold."
|
|
84
|
+
: "Score is only one point above the configured review threshold."
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
function buildTopCounts(values, limit) {
|
|
88
|
+
const counts = new Map();
|
|
89
|
+
for (const value of values) {
|
|
90
|
+
const normalized = value.trim() || "(empty)";
|
|
91
|
+
counts.set(normalized, (counts.get(normalized) ?? 0) + 1);
|
|
92
|
+
}
|
|
93
|
+
return [...counts.entries()]
|
|
94
|
+
.sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0], "en"))
|
|
95
|
+
.slice(0, limit)
|
|
96
|
+
.map(([name, count]) => ({ name, count }));
|
|
97
|
+
}
|
|
98
|
+
function countBy(items, predicate) {
|
|
99
|
+
let count = 0;
|
|
100
|
+
for (const item of items) {
|
|
101
|
+
if (predicate(item)) {
|
|
102
|
+
count += 1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return count;
|
|
106
|
+
}
|
|
107
|
+
function normalizeSummary(value) {
|
|
108
|
+
return value.replace(/\s+/g, " ").trim();
|
|
109
|
+
}
|
|
110
|
+
function roundToTwoDecimals(value) {
|
|
111
|
+
return Math.round(value * 100) / 100;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=aggregate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../src/reporting/aggregate.ts"],"names":[],"mappings":";;AAIA,4CAmCC;AArCD,6CAAmF;AAEnF,SAAgB,gBAAgB,CAAC,KAAoD;IACnF,MAAM,MAAM,GAAG,IAAA,oCAAuB,EAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACxF,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO;SAC1B,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,uCAA0B,EAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;SAC1E,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/D,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;IACnF,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAE1F,OAAO;QACL,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,WAAW,EAAE,OAAO,CAAC,MAAM;QAC3B,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC;QAC9C,MAAM,EAAE;YACN,YAAY,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM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,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;SAClF,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,OAAO,CAAI,KAAU,EAAE,SAA+B;IAC7D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YACpB,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.generateLocalWorkReport = generateLocalWorkReport;
|
|
18
|
+
exports.generateAiWorkReport = generateAiWorkReport;
|
|
19
|
+
const aggregate_1 = require("./aggregate");
|
|
20
|
+
const mockProvider_1 = require("./mockProvider");
|
|
21
|
+
const openaiProvider_1 = require("./openaiProvider");
|
|
22
|
+
const render_1 = require("./render");
|
|
23
|
+
__exportStar(require("./aggregate"), exports);
|
|
24
|
+
__exportStar(require("./provider"), exports);
|
|
25
|
+
__exportStar(require("./render"), exports);
|
|
26
|
+
__exportStar(require("./timeWindow"), exports);
|
|
27
|
+
__exportStar(require("./types"), exports);
|
|
28
|
+
function generateLocalWorkReport(input) {
|
|
29
|
+
const facts = (0, aggregate_1.buildReportFacts)({
|
|
30
|
+
records: input.records,
|
|
31
|
+
periodType: input.periodType,
|
|
32
|
+
weekStartsOn: input.weekStartsOn,
|
|
33
|
+
language: input.language,
|
|
34
|
+
now: input.now
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
facts,
|
|
38
|
+
markdown: (0, render_1.renderWorkReportMarkdown)({ facts, markdown: "" }, input.customPrompt)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function generateAiWorkReport(input, options) {
|
|
42
|
+
const facts = (0, aggregate_1.buildReportFacts)({
|
|
43
|
+
records: input.records,
|
|
44
|
+
periodType: input.periodType,
|
|
45
|
+
weekStartsOn: input.weekStartsOn,
|
|
46
|
+
language: input.language,
|
|
47
|
+
now: input.now
|
|
48
|
+
});
|
|
49
|
+
const provider = options.provider ?? createProvider(options.config, options.providerMode ?? resolveProviderMode(), options.mockMode);
|
|
50
|
+
const markdown = await provider.generateReport({
|
|
51
|
+
...input,
|
|
52
|
+
facts
|
|
53
|
+
});
|
|
54
|
+
const normalized = markdown.trim();
|
|
55
|
+
if (!normalized) {
|
|
56
|
+
throw new Error("AI report provider returned empty Markdown.");
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
facts,
|
|
60
|
+
markdown: normalized,
|
|
61
|
+
provider: provider.name
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function resolveProviderMode() {
|
|
65
|
+
return process.env.SMART_COMMIT_REPORT_PROVIDER?.trim().toLowerCase() === "mock"
|
|
66
|
+
? "mock"
|
|
67
|
+
: "openai-compatible";
|
|
68
|
+
}
|
|
69
|
+
function createProvider(config, mode, mockMode) {
|
|
70
|
+
return mode === "mock" ? (0, mockProvider_1.createMockReportProvider)({ mode: mockMode }) : (0, openaiProvider_1.createOpenAICompatibleReportProvider)(config);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporting/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAcA,0DAaC;AAED,oDA+BC;AA5DD,2CAA+C;AAC/C,iDAA0D;AAC1D,qDAAwE;AAExE,qCAAoD;AAIpD,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,+CAA6B;AAC7B,0CAAwB;AAExB,SAAgB,uBAAuB,CAAC,KAA8B;IACpE,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;QAC7B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,GAAG,EAAE,KAAK,CAAC,GAAG;KACf,CAAC,CAAC;IAEH,OAAO;QACL,KAAK;QACL,QAAQ,EAAE,IAAA,iCAAwB,EAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,YAAY,CAAC;KAChF,CAAC;AACJ,CAAC;AAEM,KAAK,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|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMockReportProvider = createMockReportProvider;
|
|
4
|
+
function createMockReportProvider(config = {}) {
|
|
5
|
+
return {
|
|
6
|
+
name: "mock",
|
|
7
|
+
async generateReport(input) {
|
|
8
|
+
const mode = config.mode?.trim().toLowerCase() ?? process.env.SMART_COMMIT_REPORT_MODE?.trim().toLowerCase();
|
|
9
|
+
if (mode === "invalid") {
|
|
10
|
+
return " ";
|
|
11
|
+
}
|
|
12
|
+
const headline = input.language === "zh" ? "# AI 增强工作报告" : "# AI Enhanced Work Report";
|
|
13
|
+
return [
|
|
14
|
+
headline,
|
|
15
|
+
"",
|
|
16
|
+
`Period: ${input.facts.period.displayRangeLabel}`,
|
|
17
|
+
"",
|
|
18
|
+
`Records: ${input.facts.recordCount}`,
|
|
19
|
+
"",
|
|
20
|
+
input.facts.highlights.slice(0, 3).map((item) => `- ${item.commitMessage}`).join("\n")
|
|
21
|
+
].join("\n").trim();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=mockProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockProvider.js","sourceRoot":"","sources":["../../src/reporting/mockProvider.ts"],"names":[],"mappings":";;AAEA,4DAsBC;AAtBD,SAAgB,wBAAwB,CAAC,SAA4B,EAAE;IACrE,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,KAAK,CAAC,cAAc,CAAC,KAA4B;YAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YAE7G,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,2BAA2B,CAAC;YACvF,OAAO;gBACL,QAAQ;gBACR,EAAE;gBACF,WAAW,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAAE;gBACjD,EAAE;gBACF,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE;gBACrC,EAAE;gBACF,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;aACvF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOpenAICompatibleReportProvider = createOpenAICompatibleReportProvider;
|
|
4
|
+
const openaiCompatible_1 = require("../openaiCompatible");
|
|
5
|
+
const prompt_1 = require("./prompt");
|
|
6
|
+
function createOpenAICompatibleReportProvider(config) {
|
|
7
|
+
return {
|
|
8
|
+
name: "openai-compatible",
|
|
9
|
+
async generateReport(input) {
|
|
10
|
+
return (0, openaiCompatible_1.requestOpenAICompatibleText)({
|
|
11
|
+
config,
|
|
12
|
+
messages: (0, prompt_1.buildReportMessages)(input),
|
|
13
|
+
temperature: 0.2,
|
|
14
|
+
taskLabel: "report"
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=openaiProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openaiProvider.js","sourceRoot":"","sources":["../../src/reporting/openaiProvider.ts"],"names":[],"mappings":";;AAKA,oFAYC;AAhBD,0DAAkE;AAClE,qCAA+C;AAG/C,SAAgB,oCAAoC,CAAC,MAAiB;IACpE,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,KAAK,CAAC,cAAc,CAAC,KAA4B;YAC/C,OAAO,IAAA,8CAA2B,EAAC;gBACjC,MAAM;gBACN,QAAQ,EAAE,IAAA,4BAAmB,EAAC,KAAK,CAAC;gBACpC,WAAW,EAAE,GAAG;gBAChB,SAAS,EAAE,QAAQ;aACpB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildReportMessages = buildReportMessages;
|
|
4
|
+
function buildReportMessages(input) {
|
|
5
|
+
return [
|
|
6
|
+
{
|
|
7
|
+
role: "system",
|
|
8
|
+
content: [
|
|
9
|
+
"You are generating a polished work report in Markdown.",
|
|
10
|
+
"Use the provided report facts as the source of truth.",
|
|
11
|
+
"Do not invent repositories, commits, scores, or events.",
|
|
12
|
+
"Keep the report concrete, scannable, and useful for engineering workflow reviews.",
|
|
13
|
+
"Return Markdown only."
|
|
14
|
+
].join("\n")
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
role: "user",
|
|
18
|
+
content: [
|
|
19
|
+
`Language: ${input.language}`,
|
|
20
|
+
`Period: ${input.facts.period.displayRangeLabel}`,
|
|
21
|
+
input.customPrompt.trim() ? `Custom focus:\n${input.customPrompt.trim()}` : "Custom focus: none",
|
|
22
|
+
"Report facts JSON:",
|
|
23
|
+
JSON.stringify(input.facts, null, 2)
|
|
24
|
+
].join("\n\n")
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/reporting/prompt.ts"],"names":[],"mappings":";;AAEA,kDAuBC;AAvBD,SAAgB,mBAAmB,CAAC,KAA4B;IAC9D,OAAO;QACL;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,wDAAwD;gBACxD,uDAAuD;gBACvD,yDAAyD;gBACzD,mFAAmF;gBACnF,uBAAuB;aACxB,CAAC,IAAI,CAAC,IAAI,CAAC;SACb;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE;gBACP,aAAa,KAAK,CAAC,QAAQ,EAAE;gBAC7B,WAAW,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAAE;gBACjD,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,kBAAkB,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,oBAAoB;gBAChG,oBAAoB;gBACpB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;aACrC,CAAC,IAAI,CAAC,MAAM,CAAC;SACf;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/reporting/provider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DEFAULT_REPORT_DIRECTORY_NAME = void 0;
|
|
37
|
+
exports.resolveReportOutputDirectoryPath = resolveReportOutputDirectoryPath;
|
|
38
|
+
exports.buildReportFileName = buildReportFileName;
|
|
39
|
+
exports.writeReportFile = writeReportFile;
|
|
40
|
+
exports.renderWorkReportMarkdown = renderWorkReportMarkdown;
|
|
41
|
+
exports.normalizeMarkdown = normalizeMarkdown;
|
|
42
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
exports.DEFAULT_REPORT_DIRECTORY_NAME = "reports";
|
|
45
|
+
function resolveReportOutputDirectoryPath(input) {
|
|
46
|
+
const configuredDirPath = input.configuredDirPath.trim();
|
|
47
|
+
const defaultDirectoryPath = path.join(path.normalize(input.repositoryPath), ".smart-commit-cli", exports.DEFAULT_REPORT_DIRECTORY_NAME);
|
|
48
|
+
if (!configuredDirPath) {
|
|
49
|
+
return defaultDirectoryPath;
|
|
50
|
+
}
|
|
51
|
+
return path.isAbsolute(configuredDirPath)
|
|
52
|
+
? path.normalize(configuredDirPath)
|
|
53
|
+
: path.resolve(input.repositoryPath, configuredDirPath);
|
|
54
|
+
}
|
|
55
|
+
function buildReportFileName(periodType, now = new Date()) {
|
|
56
|
+
const stamp = [
|
|
57
|
+
now.getFullYear(),
|
|
58
|
+
String(now.getMonth() + 1).padStart(2, "0"),
|
|
59
|
+
String(now.getDate()).padStart(2, "0"),
|
|
60
|
+
"-",
|
|
61
|
+
String(now.getHours()).padStart(2, "0"),
|
|
62
|
+
String(now.getMinutes()).padStart(2, "0"),
|
|
63
|
+
String(now.getSeconds()).padStart(2, "0")
|
|
64
|
+
].join("");
|
|
65
|
+
return `smart-commit-${periodType}-report-${stamp}.md`;
|
|
66
|
+
}
|
|
67
|
+
async function writeReportFile(directoryPath, fileName, markdown) {
|
|
68
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
|
69
|
+
const filePath = path.join(directoryPath, fileName);
|
|
70
|
+
await fs.writeFile(filePath, normalizeMarkdown(markdown), "utf8");
|
|
71
|
+
return filePath;
|
|
72
|
+
}
|
|
73
|
+
function renderWorkReportMarkdown(result, customPrompt) {
|
|
74
|
+
const zh = result.facts.language === "zh";
|
|
75
|
+
const lines = [];
|
|
76
|
+
lines.push(zh ? "# 工作报告" : "# Work Report");
|
|
77
|
+
lines.push("");
|
|
78
|
+
lines.push(zh ? `- 周期: ${result.facts.period.displayRangeLabel}` : `- Period: ${result.facts.period.displayRangeLabel}`);
|
|
79
|
+
lines.push(zh ? `- 记录数: ${result.facts.recordCount}` : `- Records: ${result.facts.recordCount}`);
|
|
80
|
+
lines.push(zh
|
|
81
|
+
? `- 仓库: ${result.facts.repositoryNames.length > 0 ? result.facts.repositoryNames.join(", ") : "无"}`
|
|
82
|
+
: `- Repositories: ${result.facts.repositoryNames.length > 0 ? result.facts.repositoryNames.join(", ") : "None"}`);
|
|
83
|
+
lines.push("");
|
|
84
|
+
if (customPrompt.trim()) {
|
|
85
|
+
lines.push(zh ? "## 关注点" : "## Requested Focus");
|
|
86
|
+
lines.push("");
|
|
87
|
+
lines.push(customPrompt.trim());
|
|
88
|
+
lines.push("");
|
|
89
|
+
}
|
|
90
|
+
lines.push(zh ? "## 汇总" : "## Summary");
|
|
91
|
+
lines.push("");
|
|
92
|
+
lines.push(zh
|
|
93
|
+
? `- 通过评审: ${result.facts.totals.reviewPassed}`
|
|
94
|
+
: `- Review passed: ${result.facts.totals.reviewPassed}`);
|
|
95
|
+
lines.push(zh
|
|
96
|
+
? `- 完成 commit + push: ${result.facts.totals.commitPushCompleted}`
|
|
97
|
+
: `- Commit + push completed: ${result.facts.totals.commitPushCompleted}`);
|
|
98
|
+
lines.push(zh
|
|
99
|
+
? `- 平均分: ${result.facts.totals.averageScore ?? "N/A"}`
|
|
100
|
+
: `- Average score: ${result.facts.totals.averageScore ?? "N/A"}`);
|
|
101
|
+
lines.push(zh
|
|
102
|
+
? `- Diff 总字符数: ${result.facts.totals.fullDiffCharsTotal}`
|
|
103
|
+
: `- Total diff chars: ${result.facts.totals.fullDiffCharsTotal}`);
|
|
104
|
+
lines.push("");
|
|
105
|
+
if (result.facts.highlights.length > 0) {
|
|
106
|
+
lines.push(zh ? "## 亮点记录" : "## Highlights");
|
|
107
|
+
lines.push("");
|
|
108
|
+
for (const item of result.facts.highlights) {
|
|
109
|
+
lines.push(`- [${item.timestamp}] ${item.repositoryName} / ${item.branchName} / ${item.commitMessage} / ${item.score ?? "N/A"}`);
|
|
110
|
+
lines.push(` ${item.reviewSummary}`);
|
|
111
|
+
}
|
|
112
|
+
lines.push("");
|
|
113
|
+
}
|
|
114
|
+
if (result.facts.summaryThemes.length > 0) {
|
|
115
|
+
lines.push(zh ? "## 常见主题" : "## Common Themes");
|
|
116
|
+
lines.push("");
|
|
117
|
+
for (const item of result.facts.summaryThemes) {
|
|
118
|
+
lines.push(`- ${item.summary} (${item.count})`);
|
|
119
|
+
}
|
|
120
|
+
lines.push("");
|
|
121
|
+
}
|
|
122
|
+
if (result.facts.risks.length > 0) {
|
|
123
|
+
lines.push(zh ? "## 风险提醒" : "## Risks");
|
|
124
|
+
lines.push("");
|
|
125
|
+
for (const item of result.facts.risks) {
|
|
126
|
+
lines.push(`- ${item.repositoryName} / ${item.branchName} / ${item.commitMessage}`);
|
|
127
|
+
lines.push(` ${item.reason} ${item.reviewSummary}`);
|
|
128
|
+
}
|
|
129
|
+
lines.push("");
|
|
130
|
+
}
|
|
131
|
+
appendCountSection(lines, zh ? "分支分布" : "Branches", result.facts.branches);
|
|
132
|
+
appendCountSection(lines, zh ? "提交消息来源" : "Commit Message Sources", result.facts.commitMessageSources);
|
|
133
|
+
appendCountSection(lines, zh ? "模型分布" : "Models", result.facts.models);
|
|
134
|
+
return normalizeMarkdown(lines.join("\n"));
|
|
135
|
+
}
|
|
136
|
+
function normalizeMarkdown(markdown) {
|
|
137
|
+
const trimmed = markdown.trim();
|
|
138
|
+
return trimmed ? `${trimmed}\n` : "# Report\n";
|
|
139
|
+
}
|
|
140
|
+
function appendCountSection(lines, title, items) {
|
|
141
|
+
if (items.length === 0) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
lines.push(`## ${title}`);
|
|
145
|
+
lines.push("");
|
|
146
|
+
for (const item of items) {
|
|
147
|
+
lines.push(`- ${item.name}: ${item.count}`);
|
|
148
|
+
}
|
|
149
|
+
lines.push("");
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/reporting/render.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,4EAaC;AAED,kDAYC;AAED,0CAKC;AAED,4DAiFC;AAED,8CAGC;AAhID,qD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E,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEvE,OAAO,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAgB,iBAAiB,CAAC,QAAgB;IAChD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChC,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC;AACjD,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAe,EAAE,KAAa,EAAE,KAA6C;IACvG,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC;IAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveReportTimeWindow = resolveReportTimeWindow;
|
|
4
|
+
exports.isRecordInReportTimeWindow = isRecordInReportTimeWindow;
|
|
5
|
+
const passHistory_1 = require("../passHistory");
|
|
6
|
+
function resolveReportTimeWindow(periodType, weekStartsOn, now = new Date()) {
|
|
7
|
+
switch (periodType) {
|
|
8
|
+
case "daily":
|
|
9
|
+
return buildDailyWindow(now);
|
|
10
|
+
case "weekly":
|
|
11
|
+
return buildWeeklyWindow(now, weekStartsOn);
|
|
12
|
+
case "monthly":
|
|
13
|
+
return buildMonthlyWindow(now);
|
|
14
|
+
case "quarterly":
|
|
15
|
+
return buildQuarterlyWindow(now);
|
|
16
|
+
case "yearly":
|
|
17
|
+
return buildYearlyWindow(now);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function isRecordInReportTimeWindow(timestampMs, window) {
|
|
21
|
+
return timestampMs >= window.startedAtMs && timestampMs < window.endedAtMs;
|
|
22
|
+
}
|
|
23
|
+
function buildDailyWindow(now) {
|
|
24
|
+
const startedAt = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
25
|
+
const endedAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
|
26
|
+
return buildWindow("daily", "Daily", startedAt, endedAt);
|
|
27
|
+
}
|
|
28
|
+
function buildWeeklyWindow(now, weekStartsOn) {
|
|
29
|
+
const currentDay = now.getDay();
|
|
30
|
+
const offset = weekStartsOn === "monday" ? (currentDay + 6) % 7 : currentDay;
|
|
31
|
+
const startedAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() - offset);
|
|
32
|
+
const endedAt = new Date(startedAt.getFullYear(), startedAt.getMonth(), startedAt.getDate() + 7);
|
|
33
|
+
return buildWindow("weekly", "Weekly", startedAt, endedAt);
|
|
34
|
+
}
|
|
35
|
+
function buildMonthlyWindow(now) {
|
|
36
|
+
const startedAt = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
37
|
+
const endedAt = new Date(now.getFullYear(), now.getMonth() + 1, 1);
|
|
38
|
+
return buildWindow("monthly", "Monthly", startedAt, endedAt);
|
|
39
|
+
}
|
|
40
|
+
function buildQuarterlyWindow(now) {
|
|
41
|
+
const quarterStartMonth = Math.floor(now.getMonth() / 3) * 3;
|
|
42
|
+
const startedAt = new Date(now.getFullYear(), quarterStartMonth, 1);
|
|
43
|
+
const endedAt = new Date(now.getFullYear(), quarterStartMonth + 3, 1);
|
|
44
|
+
return buildWindow("quarterly", "Quarterly", startedAt, endedAt);
|
|
45
|
+
}
|
|
46
|
+
function buildYearlyWindow(now) {
|
|
47
|
+
const startedAt = new Date(now.getFullYear(), 0, 1);
|
|
48
|
+
const endedAt = new Date(now.getFullYear() + 1, 0, 1);
|
|
49
|
+
return buildWindow("yearly", "Yearly", startedAt, endedAt);
|
|
50
|
+
}
|
|
51
|
+
function buildWindow(type, label, startedAt, endedAt) {
|
|
52
|
+
const displayEnd = new Date(endedAt.getTime() - 1);
|
|
53
|
+
return {
|
|
54
|
+
type,
|
|
55
|
+
label,
|
|
56
|
+
startedAtMs: startedAt.getTime(),
|
|
57
|
+
endedAtMs: endedAt.getTime(),
|
|
58
|
+
displayStart: formatDisplayDate(startedAt),
|
|
59
|
+
displayEndInclusive: formatDisplayDate(displayEnd),
|
|
60
|
+
displayRangeLabel: buildDisplayRangeLabel(label, startedAt, displayEnd)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function formatDisplayDate(value) {
|
|
64
|
+
return (0, passHistory_1.formatLocalTimestamp)(value).slice(0, 10);
|
|
65
|
+
}
|
|
66
|
+
function buildDisplayRangeLabel(label, startedAt, displayEnd) {
|
|
67
|
+
if (label === "Monthly") {
|
|
68
|
+
return `${startedAt.getFullYear()}-${String(startedAt.getMonth() + 1).padStart(2, "0")} (${formatDisplayDate(startedAt)} to ${formatDisplayDate(displayEnd)})`;
|
|
69
|
+
}
|
|
70
|
+
if (label === "Quarterly") {
|
|
71
|
+
const quarter = Math.floor(startedAt.getMonth() / 3) + 1;
|
|
72
|
+
return `${startedAt.getFullYear()} Q${quarter} (${formatDisplayDate(startedAt)} to ${formatDisplayDate(displayEnd)})`;
|
|
73
|
+
}
|
|
74
|
+
if (label === "Yearly") {
|
|
75
|
+
return `${startedAt.getFullYear()} (${formatDisplayDate(startedAt)} to ${formatDisplayDate(displayEnd)})`;
|
|
76
|
+
}
|
|
77
|
+
return `${label} (${formatDisplayDate(startedAt)} to ${formatDisplayDate(displayEnd)})`;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=timeWindow.js.map
|