goals-cli 0.0.0-stage → 1.3.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 +25 -0
- package/README.md +130 -2
- package/dist/args.js +96 -0
- package/dist/auth/command.js +16 -0
- package/dist/auth/help.js +82 -0
- package/dist/auth/list.js +41 -0
- package/dist/auth/login.js +203 -0
- package/dist/auth/logout.js +25 -0
- package/dist/auth/select.js +30 -0
- package/dist/auth/status.js +43 -0
- package/dist/auth/use.js +10 -0
- package/dist/cli.js +112 -0
- package/dist/commands/export-help.js +49 -0
- package/dist/commands/export.js +194 -0
- package/dist/commands/goal-flags.js +111 -0
- package/dist/commands/goal-format.js +95 -0
- package/dist/commands/goal-help.js +214 -0
- package/dist/commands/goal-read.js +80 -0
- package/dist/commands/goal-write.js +186 -0
- package/dist/commands/goal.js +15 -0
- package/dist/commands/initiative-help.js +38 -0
- package/dist/commands/initiative.js +81 -0
- package/dist/commands/list-output.js +13 -0
- package/dist/commands/skill-help.js +18 -0
- package/dist/commands/skill.js +36 -0
- package/dist/credentials.js +270 -0
- package/dist/deps.js +46 -0
- package/dist/dispatch.js +16 -0
- package/dist/endpoints.js +82 -0
- package/dist/errors.js +29 -0
- package/dist/help.js +105 -0
- package/dist/http.js +199 -0
- package/dist/iso-week.js +18 -0
- package/dist/open-browser.js +47 -0
- package/dist/output.js +29 -0
- package/dist/vendor/cli-contract/index.js +26 -0
- package/dist/vendor/quarterly-markdown/dateFormat.js +101 -0
- package/dist/vendor/quarterly-markdown/generate.js +450 -0
- package/dist/vendor/quarterly-markdown/htmlToPlainText.js +101 -0
- package/dist/vendor/quarterly-markdown/index.js +4 -0
- package/dist/vendor/quarterly-markdown/types.js +1 -0
- package/dist/vendor/quarterly-markdown/year.js +45 -0
- package/dist/version.js +9 -0
- package/package.json +37 -4
- package/skills/goals-cli/REFERENCE.md +212 -0
- package/skills/goals-cli/SKILL.md +12 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
// GENERATED by packages/cli/scripts/vendor-shared.mjs from packages/shared — do not edit.
|
|
2
|
+
import { formatDateKey, formatDay, formatDayFromKey, formatGeneratedAt } from './dateFormat.js';
|
|
3
|
+
import { htmlToPlainText } from './htmlToPlainText.js';
|
|
4
|
+
/**
|
|
5
|
+
* Formats goal log entries as markdown.
|
|
6
|
+
* Groups logs by date and renders content.
|
|
7
|
+
*
|
|
8
|
+
* @param logs - goal log entries
|
|
9
|
+
* @param timeZone - IANA zone for grouping keys; undefined = system zone
|
|
10
|
+
* @param indent - indentation level for nested lists (default: '')
|
|
11
|
+
* @returns formatted markdown string for logs
|
|
12
|
+
*/
|
|
13
|
+
function formatGoalLogsAsMarkdown(logs, timeZone, indent = '') {
|
|
14
|
+
if (!logs || logs.length === 0) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
const lines = [];
|
|
18
|
+
lines.push(`${indent}**Log:**`);
|
|
19
|
+
// Group logs by date
|
|
20
|
+
const logsByDate = new Map();
|
|
21
|
+
for (const log of logs) {
|
|
22
|
+
const dateKey = formatDateKey(log.logDate, timeZone);
|
|
23
|
+
if (!logsByDate.has(dateKey)) {
|
|
24
|
+
logsByDate.set(dateKey, []);
|
|
25
|
+
}
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- moved verbatim from the legacy generator; cleanup is out of scope
|
|
27
|
+
logsByDate.get(dateKey).push(log);
|
|
28
|
+
}
|
|
29
|
+
// Sort dates in descending order (most recent first)
|
|
30
|
+
const sortedDates = [...logsByDate.keys()].sort((a, b) => b.localeCompare(a));
|
|
31
|
+
for (const dateKey of sortedDates) {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- moved verbatim from the legacy generator; cleanup is out of scope
|
|
33
|
+
const dateLogs = logsByDate.get(dateKey);
|
|
34
|
+
const formattedDate = formatDayFromKey(dateKey);
|
|
35
|
+
lines.push(`${indent}- **${formattedDate}:**`);
|
|
36
|
+
for (const log of dateLogs) {
|
|
37
|
+
// Convert HTML to plain text
|
|
38
|
+
const plainContent = htmlToPlainText(log.content);
|
|
39
|
+
if (plainContent) {
|
|
40
|
+
lines.push(`${indent} - ${plainContent}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generates a markdown representation of a quarterly goal summary.
|
|
48
|
+
*
|
|
49
|
+
* @param summaryData - The quarterly goal summary data
|
|
50
|
+
* @param options - Options for customizing the markdown output
|
|
51
|
+
* @returns A formatted markdown string
|
|
52
|
+
*/
|
|
53
|
+
export function generateQuarterlySummaryMarkdown(summaryData, options = {}) {
|
|
54
|
+
const { quarterlyGoal, weeklyGoalsByWeek, quarter, year, weekRange } = summaryData;
|
|
55
|
+
const { omitIncomplete = false, timeZone } = options;
|
|
56
|
+
// Build the markdown content
|
|
57
|
+
const lines = [];
|
|
58
|
+
// Header with quarterly goal - always show quarterly goal regardless of completion status
|
|
59
|
+
const completionStatus = quarterlyGoal.isComplete ? '[x]' : '[ ]';
|
|
60
|
+
lines.push(`# ${completionStatus} Q${quarter} ${year}: ${quarterlyGoal.title}`);
|
|
61
|
+
lines.push('');
|
|
62
|
+
// Add details if available
|
|
63
|
+
if (quarterlyGoal.details?.trim()) {
|
|
64
|
+
lines.push(quarterlyGoal.details.trim());
|
|
65
|
+
lines.push('');
|
|
66
|
+
}
|
|
67
|
+
// Add completion date if completed
|
|
68
|
+
if (quarterlyGoal.isComplete && quarterlyGoal.completedAt) {
|
|
69
|
+
const completedDate = formatDay(quarterlyGoal.completedAt, timeZone);
|
|
70
|
+
lines.push(`**Completed:** ${completedDate}`);
|
|
71
|
+
lines.push('');
|
|
72
|
+
}
|
|
73
|
+
// Add quarterly goal logs if available
|
|
74
|
+
if (quarterlyGoal.logs && quarterlyGoal.logs.length > 0) {
|
|
75
|
+
lines.push(formatGoalLogsAsMarkdown(quarterlyGoal.logs, timeZone));
|
|
76
|
+
lines.push('');
|
|
77
|
+
}
|
|
78
|
+
// Add quarter info
|
|
79
|
+
lines.push(`**Quarter:** Q${quarter} ${year} (Weeks ${weekRange.startWeek}-${weekRange.endWeek})`);
|
|
80
|
+
if (omitIncomplete) {
|
|
81
|
+
lines.push('**Note:** Only completed goals are shown');
|
|
82
|
+
}
|
|
83
|
+
lines.push('');
|
|
84
|
+
// Calculate and add summary statistics
|
|
85
|
+
const allWeeklyGoals = Object.values(weeklyGoalsByWeek).flat();
|
|
86
|
+
const completedWeeklyGoals = allWeeklyGoals.filter((goal) => goal.isComplete).length;
|
|
87
|
+
const totalDailyGoals = allWeeklyGoals.reduce((sum, weeklyGoal) => sum + (weeklyGoal.children?.length || 0), 0);
|
|
88
|
+
const completedDailyGoals = allWeeklyGoals.reduce((sum, weeklyGoal) => {
|
|
89
|
+
return sum + (weeklyGoal.children?.filter((daily) => daily.isComplete).length || 0);
|
|
90
|
+
}, 0);
|
|
91
|
+
lines.push('## Summary');
|
|
92
|
+
lines.push(`- **Weekly Goals:** ${completedWeeklyGoals}/${allWeeklyGoals.length} completed`);
|
|
93
|
+
lines.push(`- **Daily Goals:** ${completedDailyGoals}/${totalDailyGoals} completed`);
|
|
94
|
+
lines.push('');
|
|
95
|
+
// Group weekly goals by week number and sort, applying filtering if needed
|
|
96
|
+
const weekNumbers = Object.keys(weeklyGoalsByWeek)
|
|
97
|
+
.map(Number)
|
|
98
|
+
.filter((weekNum) => {
|
|
99
|
+
const weeklyGoals = weeklyGoalsByWeek[weekNum];
|
|
100
|
+
if (!weeklyGoals || weeklyGoals.length === 0)
|
|
101
|
+
return false;
|
|
102
|
+
// If omitting incomplete goals, only include weeks that have at least one completed goal
|
|
103
|
+
if (omitIncomplete) {
|
|
104
|
+
return weeklyGoals.some((goal) => goal.isComplete || goal.children?.some((child) => child.isComplete));
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
})
|
|
108
|
+
.sort((a, b) => a - b);
|
|
109
|
+
// Add weekly goals sections
|
|
110
|
+
if (weekNumbers.length > 0) {
|
|
111
|
+
lines.push('## Weekly Goals');
|
|
112
|
+
lines.push('');
|
|
113
|
+
weekNumbers.forEach((weekNumber) => {
|
|
114
|
+
const allWeeklyGoals = weeklyGoalsByWeek[weekNumber];
|
|
115
|
+
if (!allWeeklyGoals || allWeeklyGoals.length === 0)
|
|
116
|
+
return;
|
|
117
|
+
// Filter weekly goals based on completion status if needed
|
|
118
|
+
const weeklyGoals = omitIncomplete
|
|
119
|
+
? allWeeklyGoals.filter((goal) => goal.isComplete || goal.children?.some((child) => child.isComplete))
|
|
120
|
+
: allWeeklyGoals;
|
|
121
|
+
if (weeklyGoals.length === 0)
|
|
122
|
+
return;
|
|
123
|
+
lines.push(`### Week ${weekNumber}`);
|
|
124
|
+
lines.push('');
|
|
125
|
+
weeklyGoals.forEach((weeklyGoal) => {
|
|
126
|
+
// Skip incomplete weekly goals if omitting incomplete
|
|
127
|
+
if (omitIncomplete &&
|
|
128
|
+
!weeklyGoal.isComplete &&
|
|
129
|
+
(!weeklyGoal.children || !weeklyGoal.children.some((child) => child.isComplete))) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const weeklyStatus = weeklyGoal.isComplete ? '[x]' : '[ ]';
|
|
133
|
+
lines.push(`#### ${weeklyStatus} ${weeklyGoal.title}`);
|
|
134
|
+
// Add weekly goal details if available
|
|
135
|
+
if (weeklyGoal.details?.trim()) {
|
|
136
|
+
lines.push('');
|
|
137
|
+
lines.push(weeklyGoal.details.trim());
|
|
138
|
+
}
|
|
139
|
+
// Add weekly goal logs if available
|
|
140
|
+
if (weeklyGoal.logs && weeklyGoal.logs.length > 0) {
|
|
141
|
+
lines.push('');
|
|
142
|
+
lines.push(formatGoalLogsAsMarkdown(weeklyGoal.logs, timeZone));
|
|
143
|
+
}
|
|
144
|
+
// Add daily goals as bullet points
|
|
145
|
+
if (weeklyGoal.children && weeklyGoal.children.length > 0) {
|
|
146
|
+
// Filter daily goals if omitting incomplete
|
|
147
|
+
const dailyGoals = omitIncomplete
|
|
148
|
+
? weeklyGoal.children.filter((daily) => daily.isComplete)
|
|
149
|
+
: weeklyGoal.children;
|
|
150
|
+
if (dailyGoals.length > 0) {
|
|
151
|
+
lines.push('');
|
|
152
|
+
lines.push('**Daily Goals:**');
|
|
153
|
+
dailyGoals.forEach((dailyGoal) => {
|
|
154
|
+
const dailyStatus = dailyGoal.isComplete ? '[x]' : '[ ]';
|
|
155
|
+
lines.push(`- ${dailyStatus} ${dailyGoal.title}`);
|
|
156
|
+
// Add daily goal details as sub-bullets if available
|
|
157
|
+
if (dailyGoal.details?.trim()) {
|
|
158
|
+
const detailLines = dailyGoal.details.trim().split('\n');
|
|
159
|
+
detailLines.forEach((line) => {
|
|
160
|
+
lines.push(` - ${line.trim()}`);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// Add daily goal logs if available
|
|
164
|
+
if (dailyGoal.logs && dailyGoal.logs.length > 0) {
|
|
165
|
+
lines.push(formatGoalLogsAsMarkdown(dailyGoal.logs, timeZone, ' '));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
lines.push('');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
lines.push('## Weekly Goals');
|
|
176
|
+
lines.push('');
|
|
177
|
+
const noGoalsMessage = omitIncomplete
|
|
178
|
+
? '*No completed goals found for this quarter.*'
|
|
179
|
+
: '*No weekly goals found for this quarter.*';
|
|
180
|
+
lines.push(noGoalsMessage);
|
|
181
|
+
lines.push('');
|
|
182
|
+
}
|
|
183
|
+
// Add generation timestamp
|
|
184
|
+
lines.push('---');
|
|
185
|
+
lines.push(`*Generated on ${formatGeneratedAt(options.now ?? Date.now(), timeZone)}*`);
|
|
186
|
+
return lines.join('\n');
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Generates a markdown representation of multiple quarterly goals summary.
|
|
190
|
+
*
|
|
191
|
+
* @param summaryData - The multiple quarterly goals summary data
|
|
192
|
+
* @param options - Options for customizing the markdown output
|
|
193
|
+
* @returns A formatted markdown string
|
|
194
|
+
*/
|
|
195
|
+
export function generateMultipleQuarterlyGoalsMarkdown(summaryData, options = {}) {
|
|
196
|
+
const { quarterlyGoals, adhocGoals, quarter, year, weekRange } = summaryData;
|
|
197
|
+
const { omitIncomplete = false, timeZone } = options;
|
|
198
|
+
// Build the markdown content
|
|
199
|
+
const lines = [];
|
|
200
|
+
// Main header
|
|
201
|
+
lines.push(`# Q${quarter} ${year} Multi-Goal Summary`);
|
|
202
|
+
lines.push('');
|
|
203
|
+
lines.push(`**Quarter:** Q${quarter} ${year} (Weeks ${weekRange.startWeek}-${weekRange.endWeek})`);
|
|
204
|
+
lines.push(`**Goals Included:** ${quarterlyGoals.length}`);
|
|
205
|
+
if (adhocGoals && adhocGoals.length > 0) {
|
|
206
|
+
lines.push(`**Adhoc Goals Included:** ${adhocGoals.length}`);
|
|
207
|
+
}
|
|
208
|
+
if (omitIncomplete) {
|
|
209
|
+
lines.push('**Note:** Only completed goals are shown');
|
|
210
|
+
}
|
|
211
|
+
lines.push('');
|
|
212
|
+
// Calculate overall statistics
|
|
213
|
+
let totalWeeklyGoals = 0;
|
|
214
|
+
let completedWeeklyGoals = 0;
|
|
215
|
+
let totalDailyGoals = 0;
|
|
216
|
+
let completedDailyGoals = 0;
|
|
217
|
+
let completedQuarterlyGoals = 0;
|
|
218
|
+
quarterlyGoals.forEach((summary) => {
|
|
219
|
+
if (summary.quarterlyGoal.isComplete) {
|
|
220
|
+
completedQuarterlyGoals++;
|
|
221
|
+
}
|
|
222
|
+
const weeklyGoals = Object.values(summary.weeklyGoalsByWeek).flat();
|
|
223
|
+
totalWeeklyGoals += weeklyGoals.length;
|
|
224
|
+
completedWeeklyGoals += weeklyGoals.filter((goal) => goal.isComplete).length;
|
|
225
|
+
weeklyGoals.forEach((weeklyGoal) => {
|
|
226
|
+
const dailyGoals = weeklyGoal.children || [];
|
|
227
|
+
totalDailyGoals += dailyGoals.length;
|
|
228
|
+
completedDailyGoals += dailyGoals.filter((daily) => daily.isComplete).length;
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
// Calculate adhoc goal statistics
|
|
232
|
+
let totalAdhocGoals = 0;
|
|
233
|
+
let completedAdhocGoals = 0;
|
|
234
|
+
if (adhocGoals && adhocGoals.length > 0) {
|
|
235
|
+
// Filter adhoc goals based on omitIncomplete option
|
|
236
|
+
const filteredAdhocGoals = omitIncomplete
|
|
237
|
+
? adhocGoals.filter((goal) => goal.isComplete)
|
|
238
|
+
: adhocGoals;
|
|
239
|
+
totalAdhocGoals = filteredAdhocGoals.length;
|
|
240
|
+
completedAdhocGoals = filteredAdhocGoals.filter((goal) => goal.isComplete).length;
|
|
241
|
+
}
|
|
242
|
+
// Overall summary statistics
|
|
243
|
+
lines.push('## Overall Summary');
|
|
244
|
+
lines.push(`- **Quarterly Goals:** ${completedQuarterlyGoals}/${quarterlyGoals.length} completed`);
|
|
245
|
+
lines.push(`- **Weekly Goals:** ${completedWeeklyGoals}/${totalWeeklyGoals} completed`);
|
|
246
|
+
lines.push(`- **Daily Goals:** ${completedDailyGoals}/${totalDailyGoals} completed`);
|
|
247
|
+
if (adhocGoals && adhocGoals.length > 0) {
|
|
248
|
+
lines.push(`- **Adhoc Goals:** ${completedAdhocGoals}/${totalAdhocGoals} completed`);
|
|
249
|
+
}
|
|
250
|
+
lines.push('');
|
|
251
|
+
// Table of contents
|
|
252
|
+
lines.push('## Table of Contents');
|
|
253
|
+
quarterlyGoals.forEach((summary, index) => {
|
|
254
|
+
const status = summary.quarterlyGoal.isComplete ? '✓' : '○';
|
|
255
|
+
lines.push(`${index + 1}. [${status} ${summary.quarterlyGoal.title}](#goal-${index + 1})`);
|
|
256
|
+
});
|
|
257
|
+
if (adhocGoals && adhocGoals.length > 0) {
|
|
258
|
+
lines.push(`${quarterlyGoals.length + 1}. [Adhoc Goals](#adhoc-goals)`);
|
|
259
|
+
}
|
|
260
|
+
lines.push('');
|
|
261
|
+
// Individual goal sections
|
|
262
|
+
lines.push('## Goals');
|
|
263
|
+
lines.push('');
|
|
264
|
+
quarterlyGoals.forEach((summary, index) => {
|
|
265
|
+
const { quarterlyGoal, weeklyGoalsByWeek } = summary;
|
|
266
|
+
// Skip incomplete quarterly goals if omitting incomplete
|
|
267
|
+
if (omitIncomplete && !quarterlyGoal.isComplete) {
|
|
268
|
+
const hasCompletedSubGoals = Object.values(weeklyGoalsByWeek)
|
|
269
|
+
.flat()
|
|
270
|
+
.some((weekly) => weekly.isComplete || weekly.children?.some((daily) => daily.isComplete));
|
|
271
|
+
if (!hasCompletedSubGoals) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const completionStatus = quarterlyGoal.isComplete ? '[x]' : '[ ]';
|
|
276
|
+
lines.push(`### Goal ${index + 1}: ${completionStatus} ${quarterlyGoal.title}`);
|
|
277
|
+
lines.push('');
|
|
278
|
+
// Add details if available
|
|
279
|
+
if (quarterlyGoal.details?.trim()) {
|
|
280
|
+
lines.push(quarterlyGoal.details.trim());
|
|
281
|
+
lines.push('');
|
|
282
|
+
}
|
|
283
|
+
// Add completion date if completed
|
|
284
|
+
if (quarterlyGoal.isComplete && quarterlyGoal.completedAt) {
|
|
285
|
+
const completedDate = formatDay(quarterlyGoal.completedAt, timeZone);
|
|
286
|
+
lines.push(`**Completed:** ${completedDate}`);
|
|
287
|
+
lines.push('');
|
|
288
|
+
}
|
|
289
|
+
// Add quarterly goal logs if available
|
|
290
|
+
if (quarterlyGoal.logs && quarterlyGoal.logs.length > 0) {
|
|
291
|
+
lines.push(formatGoalLogsAsMarkdown(quarterlyGoal.logs, timeZone));
|
|
292
|
+
lines.push('');
|
|
293
|
+
}
|
|
294
|
+
// Calculate goal-specific statistics
|
|
295
|
+
const allWeeklyGoals = Object.values(weeklyGoalsByWeek).flat();
|
|
296
|
+
const goalCompletedWeeklyGoals = allWeeklyGoals.filter((goal) => goal.isComplete).length;
|
|
297
|
+
const goalTotalDailyGoals = allWeeklyGoals.reduce((sum, weeklyGoal) => sum + (weeklyGoal.children?.length || 0), 0);
|
|
298
|
+
const goalCompletedDailyGoals = allWeeklyGoals.reduce((sum, weeklyGoal) => {
|
|
299
|
+
return sum + (weeklyGoal.children?.filter((daily) => daily.isComplete).length || 0);
|
|
300
|
+
}, 0);
|
|
301
|
+
lines.push('**Goal Statistics:**');
|
|
302
|
+
lines.push(`- Weekly Goals: ${goalCompletedWeeklyGoals}/${allWeeklyGoals.length} completed`);
|
|
303
|
+
lines.push(`- Daily Goals: ${goalCompletedDailyGoals}/${goalTotalDailyGoals} completed`);
|
|
304
|
+
lines.push('');
|
|
305
|
+
// Group weekly goals by week number and sort, applying filtering if needed
|
|
306
|
+
const weekNumbers = Object.keys(weeklyGoalsByWeek)
|
|
307
|
+
.map(Number)
|
|
308
|
+
.filter((weekNum) => {
|
|
309
|
+
const weeklyGoals = weeklyGoalsByWeek[weekNum];
|
|
310
|
+
if (!weeklyGoals || weeklyGoals.length === 0)
|
|
311
|
+
return false;
|
|
312
|
+
// If omitting incomplete goals, only include weeks that have at least one completed goal
|
|
313
|
+
if (omitIncomplete) {
|
|
314
|
+
return weeklyGoals.some((goal) => goal.isComplete || goal.children?.some((child) => child.isComplete));
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
317
|
+
})
|
|
318
|
+
.sort((a, b) => a - b);
|
|
319
|
+
// Add weekly goals sections for this quarterly goal
|
|
320
|
+
if (weekNumbers.length > 0) {
|
|
321
|
+
lines.push(`#### Weekly Goals for Goal ${index + 1}`);
|
|
322
|
+
lines.push('');
|
|
323
|
+
weekNumbers.forEach((weekNumber) => {
|
|
324
|
+
const allWeeklyGoals = weeklyGoalsByWeek[weekNumber];
|
|
325
|
+
if (!allWeeklyGoals || allWeeklyGoals.length === 0)
|
|
326
|
+
return;
|
|
327
|
+
// Filter weekly goals based on completion status if needed
|
|
328
|
+
const weeklyGoals = omitIncomplete
|
|
329
|
+
? allWeeklyGoals.filter((goal) => goal.isComplete || goal.children?.some((child) => child.isComplete))
|
|
330
|
+
: allWeeklyGoals;
|
|
331
|
+
if (weeklyGoals.length === 0)
|
|
332
|
+
return;
|
|
333
|
+
lines.push(`**Week ${weekNumber}**`);
|
|
334
|
+
lines.push('');
|
|
335
|
+
weeklyGoals.forEach((weeklyGoal) => {
|
|
336
|
+
// Skip incomplete weekly goals if omitting incomplete
|
|
337
|
+
if (omitIncomplete &&
|
|
338
|
+
!weeklyGoal.isComplete &&
|
|
339
|
+
(!weeklyGoal.children || !weeklyGoal.children.some((child) => child.isComplete))) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const weeklyStatus = weeklyGoal.isComplete ? '[x]' : '[ ]';
|
|
343
|
+
lines.push(`- ${weeklyStatus} **${weeklyGoal.title}**`);
|
|
344
|
+
// Add weekly goal details if available
|
|
345
|
+
if (weeklyGoal.details?.trim()) {
|
|
346
|
+
const detailLines = weeklyGoal.details.trim().split('\n');
|
|
347
|
+
detailLines.forEach((line) => {
|
|
348
|
+
lines.push(` - ${line.trim()}`);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
// Add weekly goal logs if available
|
|
352
|
+
if (weeklyGoal.logs && weeklyGoal.logs.length > 0) {
|
|
353
|
+
lines.push(formatGoalLogsAsMarkdown(weeklyGoal.logs, timeZone, ' '));
|
|
354
|
+
}
|
|
355
|
+
// Add daily goals as sub-bullets
|
|
356
|
+
if (weeklyGoal.children && weeklyGoal.children.length > 0) {
|
|
357
|
+
// Filter daily goals if omitting incomplete
|
|
358
|
+
const dailyGoals = omitIncomplete
|
|
359
|
+
? weeklyGoal.children.filter((daily) => daily.isComplete)
|
|
360
|
+
: weeklyGoal.children;
|
|
361
|
+
if (dailyGoals.length > 0) {
|
|
362
|
+
dailyGoals.forEach((dailyGoal) => {
|
|
363
|
+
const dailyStatus = dailyGoal.isComplete ? '[x]' : '[ ]';
|
|
364
|
+
lines.push(` - ${dailyStatus} ${dailyGoal.title}`);
|
|
365
|
+
// Add daily goal details as sub-sub-bullets if available
|
|
366
|
+
if (dailyGoal.details?.trim()) {
|
|
367
|
+
const detailLines = dailyGoal.details.trim().split('\n');
|
|
368
|
+
detailLines.forEach((line) => {
|
|
369
|
+
lines.push(` - ${line.trim()}`);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
// Add daily goal logs if available
|
|
373
|
+
if (dailyGoal.logs && dailyGoal.logs.length > 0) {
|
|
374
|
+
lines.push(formatGoalLogsAsMarkdown(dailyGoal.logs, timeZone, ' '));
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
lines.push('');
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
lines.push(`#### Weekly Goals for Goal ${index + 1}`);
|
|
385
|
+
lines.push('');
|
|
386
|
+
const noGoalsMessage = omitIncomplete
|
|
387
|
+
? '*No completed goals found for this quarterly goal.*'
|
|
388
|
+
: '*No weekly goals found for this quarterly goal.*';
|
|
389
|
+
lines.push(noGoalsMessage);
|
|
390
|
+
lines.push('');
|
|
391
|
+
}
|
|
392
|
+
// Add separator between goals (except for the last one or if there are adhoc goals to add)
|
|
393
|
+
if (index < quarterlyGoals.length - 1 || (adhocGoals && adhocGoals.length > 0)) {
|
|
394
|
+
lines.push('---');
|
|
395
|
+
lines.push('');
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
// Add Adhoc Goals section if applicable
|
|
399
|
+
if (adhocGoals && adhocGoals.length > 0) {
|
|
400
|
+
const filteredAdhocGoals = omitIncomplete
|
|
401
|
+
? adhocGoals.filter((goal) => goal.isComplete)
|
|
402
|
+
: adhocGoals;
|
|
403
|
+
if (filteredAdhocGoals.length > 0) {
|
|
404
|
+
lines.push('### Adhoc Goals');
|
|
405
|
+
lines.push('');
|
|
406
|
+
lines.push('Tactical tasks and smaller wins achieved during the quarter.');
|
|
407
|
+
lines.push('');
|
|
408
|
+
// Group adhoc goals by week
|
|
409
|
+
const adhocGoalsByWeek = {};
|
|
410
|
+
filteredAdhocGoals.forEach((goal) => {
|
|
411
|
+
if (goal.adhoc?.weekNumber) {
|
|
412
|
+
const weekNumber = goal.adhoc.weekNumber;
|
|
413
|
+
if (!adhocGoalsByWeek[weekNumber]) {
|
|
414
|
+
adhocGoalsByWeek[weekNumber] = [];
|
|
415
|
+
}
|
|
416
|
+
adhocGoalsByWeek[weekNumber].push(goal);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
// Sort weeks
|
|
420
|
+
const sortedWeeks = Object.keys(adhocGoalsByWeek)
|
|
421
|
+
.map(Number)
|
|
422
|
+
.sort((a, b) => a - b);
|
|
423
|
+
sortedWeeks.forEach((weekNumber) => {
|
|
424
|
+
const weekGoals = adhocGoalsByWeek[weekNumber];
|
|
425
|
+
lines.push(`**Week ${weekNumber}**`);
|
|
426
|
+
lines.push('');
|
|
427
|
+
weekGoals.forEach((goal) => {
|
|
428
|
+
const status = goal.isComplete ? '[x]' : '[ ]';
|
|
429
|
+
lines.push(`- ${status} ${goal.title}`);
|
|
430
|
+
// Add goal details if available
|
|
431
|
+
if (goal.details?.trim()) {
|
|
432
|
+
const detailLines = goal.details.trim().split('\n');
|
|
433
|
+
detailLines.forEach((line) => {
|
|
434
|
+
lines.push(` - ${line.trim()}`);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
// Add adhoc goal logs if available
|
|
438
|
+
if (goal.logs && goal.logs.length > 0) {
|
|
439
|
+
lines.push(formatGoalLogsAsMarkdown(goal.logs, timeZone, ' '));
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
lines.push('');
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// Add generation timestamp
|
|
447
|
+
lines.push('---');
|
|
448
|
+
lines.push(`*Generated on ${formatGeneratedAt(options.now ?? Date.now(), timeZone)}*`);
|
|
449
|
+
return lines.join('\n');
|
|
450
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// GENERATED by packages/cli/scripts/vendor-shared.mjs from packages/shared — do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Converts stored goal-log HTML into plain text, mirroring the legacy
|
|
4
|
+
* sanitize-then-textContent pipeline byte-for-byte without a DOM.
|
|
5
|
+
*
|
|
6
|
+
* Constraint: this file must stay DOM-free and dependency-free (the CLI
|
|
7
|
+
* vendors this directory by copy), so it carries its own small entity table.
|
|
8
|
+
* Constraint: block tags add NO separator between their text, reproducing the
|
|
9
|
+
* legacy quirk where `<p>a</p><p>b</p>` becomes `ab`.
|
|
10
|
+
*/
|
|
11
|
+
const DROP_WITH_CONTENT = 'script|style|iframe|noscript|template|title|xmp|noembed|noframes|audio|video|desc|foreignobject';
|
|
12
|
+
// An open tag body that tolerates quoted '>' inside attributes.
|
|
13
|
+
const TAG_BODY = `[^>"']*(?:(?:"[^"]*"|'[^']*')[^>"']*)*`;
|
|
14
|
+
// Dropped elements remove themselves AND their content; unterminated -> drop to end.
|
|
15
|
+
const DROP_RE = new RegExp(`<(${DROP_WITH_CONTENT})(?![\\w:-])${TAG_BODY}>[\\s\\S]*?(?:<\\/\\1\\s*>|$)`, 'gi');
|
|
16
|
+
const PLAINTEXT_RE = /<plaintext(?![\w:-])[\s\S]*$/gi;
|
|
17
|
+
const COMMENT_RE = /<!--[\s\S]*?(?:-->|$)/g;
|
|
18
|
+
// BOGUS: <!DOCTYPE …>, <?php … ?>
|
|
19
|
+
const BOGUS_RE = /<[!?][^>]*>/g;
|
|
20
|
+
const TAG_RE = /<\/?[a-zA-Z][^>"']*(?:(?:"[^"]*"|'[^']*')[^>"']*)*>/g;
|
|
21
|
+
const ENTITY_RE = /&(#[xX][0-9a-fA-F]+|#\d+|[a-zA-Z][a-zA-Z0-9]*);/g;
|
|
22
|
+
const NAMED_ENTITIES = {
|
|
23
|
+
amp: '&',
|
|
24
|
+
lt: '<',
|
|
25
|
+
gt: '>',
|
|
26
|
+
quot: '"',
|
|
27
|
+
apos: "'",
|
|
28
|
+
nbsp: '\u00A0',
|
|
29
|
+
copy: '©',
|
|
30
|
+
reg: '®',
|
|
31
|
+
trade: '™',
|
|
32
|
+
hellip: '…',
|
|
33
|
+
mdash: '—',
|
|
34
|
+
ndash: '–',
|
|
35
|
+
lsquo: '‘',
|
|
36
|
+
rsquo: '’',
|
|
37
|
+
ldquo: '“',
|
|
38
|
+
rdquo: '”',
|
|
39
|
+
bull: '•',
|
|
40
|
+
middot: '·',
|
|
41
|
+
laquo: '«',
|
|
42
|
+
raquo: '»',
|
|
43
|
+
times: '×',
|
|
44
|
+
divide: '÷',
|
|
45
|
+
euro: '€',
|
|
46
|
+
pound: '£',
|
|
47
|
+
yen: '¥',
|
|
48
|
+
cent: '¢',
|
|
49
|
+
deg: '°',
|
|
50
|
+
plusmn: '±',
|
|
51
|
+
para: '¶',
|
|
52
|
+
sect: '§',
|
|
53
|
+
};
|
|
54
|
+
const REPLACEMENT_CHARACTER = '\uFFFD';
|
|
55
|
+
const MAX_CODE_POINT = 0x10ffff;
|
|
56
|
+
const SURROGATE_START = 0xd800;
|
|
57
|
+
const SURROGATE_END = 0xdfff;
|
|
58
|
+
const HEX_ENTITY_PREFIX_RE = /^#[xX]/;
|
|
59
|
+
const isInUnicodeRange = (cp) => cp >= 1 && cp <= MAX_CODE_POINT;
|
|
60
|
+
const isSurrogateCodePoint = (cp) => cp >= SURROGATE_START && cp <= SURROGATE_END;
|
|
61
|
+
function toCodePointOrReplacement(cp) {
|
|
62
|
+
if (Number.isNaN(cp) || !isInUnicodeRange(cp))
|
|
63
|
+
return REPLACEMENT_CHARACTER;
|
|
64
|
+
if (isSurrogateCodePoint(cp))
|
|
65
|
+
return REPLACEMENT_CHARACTER;
|
|
66
|
+
return String.fromCodePoint(cp);
|
|
67
|
+
}
|
|
68
|
+
function decodeNumericEntity(body) {
|
|
69
|
+
const hex = HEX_ENTITY_PREFIX_RE.test(body);
|
|
70
|
+
const digits = hex ? body.slice(2) : body.slice(1);
|
|
71
|
+
return toCodePointOrReplacement(parseInt(digits, hex ? 16 : 10));
|
|
72
|
+
}
|
|
73
|
+
function decodeEntity(match, body) {
|
|
74
|
+
if (body[0] !== '#') {
|
|
75
|
+
return NAMED_ENTITIES[body] ?? match;
|
|
76
|
+
}
|
|
77
|
+
return decodeNumericEntity(body);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Extracts display text from log HTML.
|
|
81
|
+
*
|
|
82
|
+
* @param html - stored log content, possibly untrusted HTML
|
|
83
|
+
* @returns whitespace-collapsed plain text; empty logs return an empty string
|
|
84
|
+
*/
|
|
85
|
+
export function htmlToPlainText(html) {
|
|
86
|
+
if (!html)
|
|
87
|
+
return '';
|
|
88
|
+
const text = html
|
|
89
|
+
.replace(DROP_RE, '')
|
|
90
|
+
.replace(PLAINTEXT_RE, '')
|
|
91
|
+
.replace(COMMENT_RE, '')
|
|
92
|
+
.replace(BOGUS_RE, '')
|
|
93
|
+
.replace(TAG_RE, '') // strip tags, NO separator inserted
|
|
94
|
+
.replace(ENTITY_RE, decodeEntity); // exactly one decoding pass, AFTER tag stripping
|
|
95
|
+
return text
|
|
96
|
+
.split(/\n+/)
|
|
97
|
+
.map((line) => line.trim())
|
|
98
|
+
.filter((line) => line.length > 0)
|
|
99
|
+
.join(' ')
|
|
100
|
+
.trim();
|
|
101
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// GENERATED by packages/cli/scripts/vendor-shared.mjs from packages/shared — do not edit.
|
|
2
|
+
export { generateMultipleQuarterlyGoalsMarkdown, generateQuarterlySummaryMarkdown, } from './generate.js';
|
|
3
|
+
export { generateYearMarkdown } from './year.js';
|
|
4
|
+
export { htmlToPlainText } from './htmlToPlainText.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// GENERATED by packages/cli/scripts/vendor-shared.mjs from packages/shared — do not edit.
|
|
2
|
+
import { generateMultipleQuarterlyGoalsMarkdown } from './generate.js';
|
|
3
|
+
const isEmptyQuarter = (summary) => summary.quarterlyGoals.length === 0 && (summary.adhocGoals?.length ?? 0) === 0;
|
|
4
|
+
const quarterLabel = (entry) => `Q${entry.quarter}`;
|
|
5
|
+
function buildHeader(year, withGoals, empty, omitIncomplete) {
|
|
6
|
+
const lines = [`# ${year} Goals Summary`, '', `**Year:** ${year}`];
|
|
7
|
+
if (withGoals.length > 0) {
|
|
8
|
+
lines.push(`**Quarters with goals:** ${withGoals.map(quarterLabel).join(', ')}`);
|
|
9
|
+
}
|
|
10
|
+
if (empty.length > 0) {
|
|
11
|
+
lines.push(`**No goals:** ${empty.map(quarterLabel).join(', ')}`);
|
|
12
|
+
}
|
|
13
|
+
if (omitIncomplete) {
|
|
14
|
+
lines.push('**Note:** Only completed goals are shown');
|
|
15
|
+
}
|
|
16
|
+
return lines;
|
|
17
|
+
}
|
|
18
|
+
function renderQuarterBodies(year, withGoals, options) {
|
|
19
|
+
if (withGoals.length === 0) {
|
|
20
|
+
return `*No goals found for ${year}.*`;
|
|
21
|
+
}
|
|
22
|
+
return withGoals
|
|
23
|
+
.map((entry) => generateMultipleQuarterlyGoalsMarkdown(entry.summary, options))
|
|
24
|
+
.join('\n\n');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates a full-year markdown output from up to four quarter summaries.
|
|
28
|
+
*
|
|
29
|
+
* Emptiness is decided on the raw summary (before `omitIncomplete` filtering),
|
|
30
|
+
* and `now` is resolved once and reused for every quarter footer.
|
|
31
|
+
*
|
|
32
|
+
* @param year - the calendar year being summarised
|
|
33
|
+
* @param quarters - quarter summaries in any order; rendered ascending
|
|
34
|
+
* @param options - options forwarded to each quarter generator
|
|
35
|
+
* @returns markdown text with one section per quarter that has goals
|
|
36
|
+
*/
|
|
37
|
+
export function generateYearMarkdown(year, quarters, options = {}) {
|
|
38
|
+
const now = options.now ?? Date.now();
|
|
39
|
+
const sorted = [...quarters].sort((a, b) => a.quarter - b.quarter);
|
|
40
|
+
const withGoals = sorted.filter((entry) => !isEmptyQuarter(entry.summary));
|
|
41
|
+
const empty = sorted.filter((entry) => isEmptyQuarter(entry.summary));
|
|
42
|
+
const quarterOptions = { ...options, now };
|
|
43
|
+
const header = buildHeader(year, withGoals, empty, options.omitIncomplete === true);
|
|
44
|
+
return [...header, '', '---', '', renderQuarterBodies(year, withGoals, quarterOptions)].join('\n');
|
|
45
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
/** The package version, read from `../package.json` relative to this module (works from `src/` and `dist/`). */
|
|
3
|
+
export function readCliVersion() {
|
|
4
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
5
|
+
if (typeof manifest.version !== 'string' || manifest.version === '') {
|
|
6
|
+
throw new Error('goals-cli package.json is missing a version');
|
|
7
|
+
}
|
|
8
|
+
return manifest.version;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goals-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Command-line access to your Goals app data",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"goals": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"skills",
|
|
12
|
+
"README.md",
|
|
13
|
+
"CHANGELOG.md"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/conradkoh/goals.git",
|
|
24
|
+
"directory": "packages/cli"
|
|
25
|
+
},
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"vendor": "node scripts/vendor-shared.mjs",
|
|
29
|
+
"build": "node scripts/vendor-shared.mjs && tsc -p tsconfig.json",
|
|
30
|
+
"typecheck": "node scripts/vendor-shared.mjs && tsc -p tsconfig.spec.json --noEmit",
|
|
31
|
+
"test": "node scripts/vendor-shared.mjs && vitest run",
|
|
32
|
+
"prepack": "pnpm build"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^20.17.24",
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vitest": "^4.1.10"
|
|
38
|
+
}
|
|
39
|
+
}
|