@apet97/clockify-cli-115 5.0.4 → 7.0.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/README.md +255 -39
- package/dist/client.js +43 -17
- package/dist/closed-pipe.js +3 -0
- package/dist/commands/api.js +192 -103
- package/dist/commands/approvals.js +9 -10
- package/dist/commands/auditlog.js +11 -8
- package/dist/commands/auth.js +229 -0
- package/dist/commands/balanceAssignment.js +10 -8
- package/dist/commands/batch.js +226 -0
- package/dist/commands/clients.js +27 -72
- package/dist/commands/doctor.js +98 -82
- package/dist/commands/entries.js +29 -14
- package/dist/commands/expenses.js +75 -36
- package/dist/commands/helpers.js +74 -9
- package/dist/commands/invoices.js +12 -16
- package/dist/commands/leaf-command.js +15 -0
- package/dist/commands/log.js +4 -2
- package/dist/commands/manifest.js +63 -0
- package/dist/commands/operations.js +271 -0
- package/dist/commands/projects.js +28 -32
- package/dist/commands/reports.js +54 -21
- package/dist/commands/resolve-refs.js +30 -53
- package/dist/commands/scheduling.js +94 -40
- package/dist/commands/shared-report-body.js +127 -0
- package/dist/commands/sharedReports.js +19 -235
- package/dist/commands/skill.js +85 -0
- package/dist/commands/start.js +6 -4
- package/dist/commands/status.js +69 -27
- package/dist/commands/stop.js +7 -18
- package/dist/commands/tags.js +11 -11
- package/dist/commands/tasks.js +27 -133
- package/dist/commands/timeoff.js +23 -16
- package/dist/commands/users.js +11 -19
- package/dist/commands/webhook-delivery.js +331 -0
- package/dist/commands/webhooks.js +40 -104
- package/dist/completions.js +291 -55
- package/dist/config.js +168 -61
- package/dist/credentials.js +164 -0
- package/dist/duration.js +5 -4
- package/dist/failure.js +82 -0
- package/dist/flags.js +84 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +68 -108
- package/dist/interrupts.js +28 -0
- package/dist/output.js +189 -66
- package/dist/receipt.js +2 -10
- package/dist/stdin.js +6 -0
- package/dist/stdout.js +38 -0
- package/dist/write-outcome.js +84 -0
- package/package.json +6 -4
- package/plugin/.claude-plugin/plugin.json +16 -0
- package/plugin/skills/clockify-cli/SKILL.md +88 -0
- package/plugin/skills/clockify-mcp/SKILL.md +48 -0
- package/plugin/skills/clockify-sdk/SKILL.md +85 -0
- package/dist/error-codes.js +0 -272
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SHARED_REPORT_TYPES } from "clockify-sdk-ts-115/requests";
|
|
2
|
+
import { UsageError } from "../failure.js";
|
|
2
3
|
import { printObject, printRecords } from "../output.js";
|
|
3
4
|
import { printReceipt } from "../receipt.js";
|
|
4
|
-
import {
|
|
5
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
6
|
+
import { parseTimeViewMode, resolveBaseContext, resolveContext, TIME_VIEW_MODE_HELP } from "./helpers.js";
|
|
5
7
|
import { leafCommand } from "./leaf-command.js";
|
|
6
8
|
async function readReportBody(response) {
|
|
7
9
|
const buffer = await response.arrayBuffer();
|
|
@@ -19,30 +21,9 @@ async function readReportBody(response) {
|
|
|
19
21
|
return { body: text };
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
|
-
const
|
|
23
|
-
"SUMMARY",
|
|
24
|
-
"DETAILED",
|
|
25
|
-
"WEEKLY",
|
|
26
|
-
"EXPENSE_DETAILED",
|
|
27
|
-
"INVOICE_TIME",
|
|
28
|
-
"KIOSK_PIN_LIST",
|
|
29
|
-
"ATTENDANCE_DETAILED",
|
|
30
|
-
"ATTENDANCE_SUMMARY",
|
|
31
|
-
"ASSIGNMENT_LIST",
|
|
32
|
-
"ASSIGNMENT_SCHEDULE",
|
|
33
|
-
"APPROVAL_DETAILED",
|
|
34
|
-
"APPROVAL_SUMMARY",
|
|
35
|
-
"BALANCE_LIST",
|
|
36
|
-
"INVOICE_AMOUNT_LIST",
|
|
37
|
-
"INVOICE_DETAILED",
|
|
38
|
-
"TIMEOFF_DETAILED",
|
|
39
|
-
"TIMEOFF_HOLIDAY",
|
|
40
|
-
"TIMEOFF_BALANCE",
|
|
41
|
-
"EXPENSE_SUMMARY",
|
|
42
|
-
];
|
|
43
|
-
const SHARED_REPORT_FILTER_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
|
|
24
|
+
export const SHARED_REPORT_FILTER_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
|
|
44
25
|
const SHARED_REPORT_VIEW_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV"];
|
|
45
|
-
const SUMMARY_GROUPS = [
|
|
26
|
+
export const SUMMARY_GROUPS = [
|
|
46
27
|
"CLIENT",
|
|
47
28
|
"PROJECT",
|
|
48
29
|
"TASK",
|
|
@@ -53,208 +34,6 @@ const SUMMARY_GROUPS = [
|
|
|
53
34
|
"USER",
|
|
54
35
|
"TAG",
|
|
55
36
|
];
|
|
56
|
-
const nonEmptyStringSchema = z
|
|
57
|
-
.string()
|
|
58
|
-
.refine((value) => value.trim() !== "", "must be a non-empty string.");
|
|
59
|
-
const dateStringSchema = nonEmptyStringSchema.refine((value) => !Number.isNaN(Date.parse(value)), "must be a valid date string.");
|
|
60
|
-
const upperCaseString = (value) => typeof value === "string" ? value.toUpperCase() : value;
|
|
61
|
-
const sharedReportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_TYPES));
|
|
62
|
-
const sharedReportExportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_FILTER_EXPORT_TYPES));
|
|
63
|
-
const openObjectSchema = z.record(z.string(), z.unknown());
|
|
64
|
-
const INT_MESSAGE = { error: "provide a whole integer" };
|
|
65
|
-
const sharedUsersFilterSchema = z
|
|
66
|
-
.object({
|
|
67
|
-
contains: z.enum(["CONTAINS", "DOES_NOT_CONTAIN", "CONTAINS_ONLY"]).optional(),
|
|
68
|
-
ids: z.array(z.string()).optional(),
|
|
69
|
-
status: z.enum(["ALL", "ACTIVE", "INACTIVE"]).optional(),
|
|
70
|
-
})
|
|
71
|
-
.strict();
|
|
72
|
-
const sharedAttendanceFilterSchema = z
|
|
73
|
-
.object({
|
|
74
|
-
page: z.number().int(INT_MESSAGE).optional(),
|
|
75
|
-
pageSize: z.number().int(INT_MESSAGE).optional(),
|
|
76
|
-
users: sharedUsersFilterSchema.optional(),
|
|
77
|
-
})
|
|
78
|
-
.strict();
|
|
79
|
-
const sharedDetailedFilterSchema = z
|
|
80
|
-
.object({
|
|
81
|
-
auditFilter: openObjectSchema.optional(),
|
|
82
|
-
options: openObjectSchema.optional(),
|
|
83
|
-
page: z.number().int(INT_MESSAGE).optional(),
|
|
84
|
-
pageSize: z.number().int(INT_MESSAGE).optional(),
|
|
85
|
-
sortColumn: nonEmptyStringSchema.optional(),
|
|
86
|
-
sortOrder: z.enum(["ASCENDING", "DESCENDING"]).optional(),
|
|
87
|
-
})
|
|
88
|
-
.strict();
|
|
89
|
-
const sharedSummaryFilterSchema = z
|
|
90
|
-
.object({
|
|
91
|
-
groups: z
|
|
92
|
-
.array(z.enum(SUMMARY_GROUPS))
|
|
93
|
-
.min(1, { error: `provide 1-3 of: ${SUMMARY_GROUPS.join(", ")}` })
|
|
94
|
-
.max(3, { error: `provide at most 3 of: ${SUMMARY_GROUPS.join(", ")}` }),
|
|
95
|
-
sortColumn: nonEmptyStringSchema.optional(),
|
|
96
|
-
})
|
|
97
|
-
.strict();
|
|
98
|
-
const sharedWeeklyFilterSchema = z
|
|
99
|
-
.object({
|
|
100
|
-
group: z.enum(["PROJECT", "USER"]),
|
|
101
|
-
subgroup: z.literal("TIME"),
|
|
102
|
-
})
|
|
103
|
-
.strict();
|
|
104
|
-
const sharedReportFilterSchema = z
|
|
105
|
-
.object({
|
|
106
|
-
attendanceFilter: sharedAttendanceFilterSchema.optional(),
|
|
107
|
-
dateRangeEnd: dateStringSchema,
|
|
108
|
-
dateRangeStart: dateStringSchema,
|
|
109
|
-
detailedFilter: sharedDetailedFilterSchema.optional(),
|
|
110
|
-
exportType: sharedReportExportTypeSchema,
|
|
111
|
-
summaryFilter: sharedSummaryFilterSchema.optional(),
|
|
112
|
-
weeklyFilter: sharedWeeklyFilterSchema.optional(),
|
|
113
|
-
})
|
|
114
|
-
.strict();
|
|
115
|
-
const sharedReportBodyShape = {
|
|
116
|
-
filter: sharedReportFilterSchema,
|
|
117
|
-
isPublic: z.boolean().optional(),
|
|
118
|
-
name: nonEmptyStringSchema,
|
|
119
|
-
type: sharedReportTypeSchema,
|
|
120
|
-
};
|
|
121
|
-
const sharedReportCreateBodySchema = z.object(sharedReportBodyShape).strict();
|
|
122
|
-
const sharedReportUpdateBodySchema = z.object(sharedReportBodyShape).strict();
|
|
123
|
-
function toSharedUsersFilter(value) {
|
|
124
|
-
return {
|
|
125
|
-
...(value.contains !== undefined ? { contains: value.contains } : {}),
|
|
126
|
-
...(value.ids !== undefined ? { ids: value.ids } : {}),
|
|
127
|
-
...(value.status !== undefined ? { status: value.status } : {}),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function toSharedReportFilter(value) {
|
|
131
|
-
return {
|
|
132
|
-
dateRangeEnd: value.dateRangeEnd,
|
|
133
|
-
dateRangeStart: value.dateRangeStart,
|
|
134
|
-
exportType: value.exportType,
|
|
135
|
-
...(value.attendanceFilter !== undefined
|
|
136
|
-
? {
|
|
137
|
-
attendanceFilter: {
|
|
138
|
-
...(value.attendanceFilter.page !== undefined
|
|
139
|
-
? { page: value.attendanceFilter.page }
|
|
140
|
-
: {}),
|
|
141
|
-
...(value.attendanceFilter.pageSize !== undefined
|
|
142
|
-
? { pageSize: value.attendanceFilter.pageSize }
|
|
143
|
-
: {}),
|
|
144
|
-
...(value.attendanceFilter.users !== undefined
|
|
145
|
-
? { users: toSharedUsersFilter(value.attendanceFilter.users) }
|
|
146
|
-
: {}),
|
|
147
|
-
},
|
|
148
|
-
}
|
|
149
|
-
: {}),
|
|
150
|
-
...(value.detailedFilter !== undefined
|
|
151
|
-
? {
|
|
152
|
-
detailedFilter: {
|
|
153
|
-
...(value.detailedFilter.auditFilter !== undefined
|
|
154
|
-
? { auditFilter: value.detailedFilter.auditFilter }
|
|
155
|
-
: {}),
|
|
156
|
-
...(value.detailedFilter.options !== undefined
|
|
157
|
-
? { options: value.detailedFilter.options }
|
|
158
|
-
: {}),
|
|
159
|
-
...(value.detailedFilter.page !== undefined
|
|
160
|
-
? { page: value.detailedFilter.page }
|
|
161
|
-
: {}),
|
|
162
|
-
...(value.detailedFilter.pageSize !== undefined
|
|
163
|
-
? { pageSize: value.detailedFilter.pageSize }
|
|
164
|
-
: {}),
|
|
165
|
-
...(value.detailedFilter.sortColumn !== undefined
|
|
166
|
-
? { sortColumn: value.detailedFilter.sortColumn }
|
|
167
|
-
: {}),
|
|
168
|
-
...(value.detailedFilter.sortOrder !== undefined
|
|
169
|
-
? { sortOrder: value.detailedFilter.sortOrder }
|
|
170
|
-
: {}),
|
|
171
|
-
},
|
|
172
|
-
}
|
|
173
|
-
: {}),
|
|
174
|
-
...(value.summaryFilter !== undefined
|
|
175
|
-
? {
|
|
176
|
-
summaryFilter: {
|
|
177
|
-
groups: value.summaryFilter.groups,
|
|
178
|
-
...(value.summaryFilter.sortColumn !== undefined
|
|
179
|
-
? { sortColumn: value.summaryFilter.sortColumn }
|
|
180
|
-
: {}),
|
|
181
|
-
},
|
|
182
|
-
}
|
|
183
|
-
: {}),
|
|
184
|
-
...(value.weeklyFilter !== undefined
|
|
185
|
-
? {
|
|
186
|
-
weeklyFilter: {
|
|
187
|
-
group: value.weeklyFilter.group,
|
|
188
|
-
subgroup: value.weeklyFilter.subgroup,
|
|
189
|
-
},
|
|
190
|
-
}
|
|
191
|
-
: {}),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function toSharedReportBody(value) {
|
|
195
|
-
return {
|
|
196
|
-
filter: toSharedReportFilter(value.filter),
|
|
197
|
-
name: value.name,
|
|
198
|
-
type: value.type,
|
|
199
|
-
...(value.isPublic !== undefined ? { isPublic: value.isPublic } : {}),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function parseFilterJson(raw) {
|
|
203
|
-
if (typeof raw !== "string") {
|
|
204
|
-
throw new Error("--filter must be a JSON object.");
|
|
205
|
-
}
|
|
206
|
-
try {
|
|
207
|
-
return JSON.parse(raw);
|
|
208
|
-
}
|
|
209
|
-
catch {
|
|
210
|
-
throw new Error(`--filter must be a JSON object, e.g. '{"dateRangeStart":"…","dateRangeEnd":"…"}'`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function schemaIssueLabel(issue, operation) {
|
|
214
|
-
const [root, ...path] = issue.path;
|
|
215
|
-
if (root === "filter") {
|
|
216
|
-
return path.length > 0 ? `--filter ${path.join(".")}` : "--filter";
|
|
217
|
-
}
|
|
218
|
-
if (root === "name")
|
|
219
|
-
return "--name";
|
|
220
|
-
if (root === "type")
|
|
221
|
-
return "--type";
|
|
222
|
-
return operation;
|
|
223
|
-
}
|
|
224
|
-
function sharedReportValidationError(error, operation, rawType) {
|
|
225
|
-
const invalidTypeIssue = error.issues.find((issue) => issue.path[0] === "type" && issue.code === "invalid_value");
|
|
226
|
-
if (invalidTypeIssue !== undefined) {
|
|
227
|
-
return new Error(`Unknown --type "${String(rawType)}". Provide one of: ${SHARED_REPORT_TYPES.join(", ")}.`);
|
|
228
|
-
}
|
|
229
|
-
const issue = error.issues[0];
|
|
230
|
-
if (issue === undefined)
|
|
231
|
-
return new Error(`${operation}: invalid request.`);
|
|
232
|
-
if (issue.path.length === 1 &&
|
|
233
|
-
issue.path[0] === "filter" &&
|
|
234
|
-
issue.code === "invalid_type" &&
|
|
235
|
-
issue.expected === "object") {
|
|
236
|
-
return new Error("--filter must be a JSON object.");
|
|
237
|
-
}
|
|
238
|
-
const label = schemaIssueLabel(issue, operation);
|
|
239
|
-
if (issue.code === "unrecognized_keys") {
|
|
240
|
-
const fieldKind = issue.path[0] === "filter" ? "filter field(s)" : "field(s)";
|
|
241
|
-
return new Error(`${label} has unknown ${fieldKind}: ${issue.keys.join(", ")}.`);
|
|
242
|
-
}
|
|
243
|
-
return new Error(`${label}: ${issue.message}`);
|
|
244
|
-
}
|
|
245
|
-
function parseSharedReportBody(schema, opts, operation) {
|
|
246
|
-
const candidate = {
|
|
247
|
-
name: opts.name,
|
|
248
|
-
type: opts.type,
|
|
249
|
-
filter: parseFilterJson(opts.filter),
|
|
250
|
-
...(opts.public !== undefined ? { isPublic: opts.public } : {}),
|
|
251
|
-
};
|
|
252
|
-
const result = schema.safeParse(candidate);
|
|
253
|
-
if (!result.success) {
|
|
254
|
-
throw sharedReportValidationError(result.error, operation, opts.type);
|
|
255
|
-
}
|
|
256
|
-
return toSharedReportBody(result.data);
|
|
257
|
-
}
|
|
258
37
|
export const registerSharedReportsCommand = (program, services) => {
|
|
259
38
|
const shared = program
|
|
260
39
|
.command("shared-reports")
|
|
@@ -277,6 +56,7 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
277
56
|
leafCommand(shared, "view", "read")
|
|
278
57
|
.argument("<id>", "Shared-report ID.")
|
|
279
58
|
.option("--export-type <type>", "Text-safe export type: JSON_V1, JSON, or CSV (default JSON_V1).")
|
|
59
|
+
.option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
|
|
280
60
|
.description("View a shared report's rendered data by ID (reports host; not workspace-scoped).")
|
|
281
61
|
.addHelpText("after", "\nExamples:\n" +
|
|
282
62
|
" $ clk115 shared-reports view report_123\n" +
|
|
@@ -284,16 +64,18 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
284
64
|
.action(async function (id, opts) {
|
|
285
65
|
const candidate = opts.exportType ? String(opts.exportType).toUpperCase() : "JSON_V1";
|
|
286
66
|
if (candidate === "XLSX" || candidate === "PDF") {
|
|
287
|
-
throw new
|
|
67
|
+
throw new UsageError(`--export-type ${candidate} is unavailable because the CLI cannot stream binary output to a file yet. Provide one of: ${SHARED_REPORT_VIEW_EXPORT_TYPES.join(", ")}. Run \`clk115 shared-reports list\` and open the report link for binary downloads.`);
|
|
288
68
|
}
|
|
289
69
|
if (!SHARED_REPORT_VIEW_EXPORT_TYPES.includes(candidate)) {
|
|
290
|
-
throw new
|
|
70
|
+
throw new UsageError(`Unknown --export-type "${String(opts.exportType)}". Provide one of: ${SHARED_REPORT_VIEW_EXPORT_TYPES.join(", ")}.`);
|
|
291
71
|
}
|
|
72
|
+
const timeViewMode = opts.timeViewMode === undefined ? undefined : parseTimeViewMode(opts.timeViewMode);
|
|
292
73
|
const { client, output } = await resolveBaseContext(this, services);
|
|
293
74
|
const exportType = candidate;
|
|
294
75
|
const response = await client.sharedReports.view({
|
|
295
76
|
sharedReportId: id,
|
|
296
77
|
exportType,
|
|
78
|
+
...(timeViewMode !== undefined ? { timeViewMode } : {}),
|
|
297
79
|
});
|
|
298
80
|
printObject(await readReportBody(response), output);
|
|
299
81
|
});
|
|
@@ -308,10 +90,11 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
308
90
|
" $ clk115 shared-reports create --name \"Q3 Summary\" --type SUMMARY \\\n" +
|
|
309
91
|
" --filter '{\"dateRangeStart\":\"2026-07-01\",\"dateRangeEnd\":\"2026-09-30\",\"exportType\":\"JSON_V1\"}' --public\n")
|
|
310
92
|
.action(async function (opts) {
|
|
93
|
+
const { parseSharedReportBody } = await import("./shared-report-body.js");
|
|
94
|
+
const body = parseSharedReportBody(opts, "shared-reports.create");
|
|
311
95
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
312
|
-
const body = parseSharedReportBody(sharedReportCreateBodySchema, opts, "shared-reports.create");
|
|
313
96
|
const request = { workspaceId, body };
|
|
314
|
-
const created = (await client.sharedReports.create(request));
|
|
97
|
+
const created = (await dispatchedWrite(this, client.sharedReports.create(request)));
|
|
315
98
|
const data = { id: created.id ?? "", name: created.name ?? opts.name };
|
|
316
99
|
printReceipt({
|
|
317
100
|
ok: true,
|
|
@@ -338,16 +121,17 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
338
121
|
.description("Replace a shared report by ID (full replace of name, type, and filter).")
|
|
339
122
|
.addHelpText("after", "\nExamples:\n" +
|
|
340
123
|
" $ clk115 shared-reports update report_123 --name \"Q3 Summary\" \\\n" +
|
|
341
|
-
" --type SUMMARY --filter '{}'\n")
|
|
124
|
+
" --type SUMMARY --filter '{\"dateRangeStart\":\"2026-07-01\",\"dateRangeEnd\":\"2026-09-30\",\"exportType\":\"JSON_V1\"}'\n")
|
|
342
125
|
.action(async function (id, opts) {
|
|
126
|
+
const { parseSharedReportBody } = await import("./shared-report-body.js");
|
|
127
|
+
const body = parseSharedReportBody(opts, "shared-reports.update");
|
|
343
128
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
344
|
-
const body = parseSharedReportBody(sharedReportUpdateBodySchema, opts, "shared-reports.update");
|
|
345
129
|
const request = {
|
|
346
130
|
workspaceId,
|
|
347
131
|
sharedReportId: id,
|
|
348
132
|
body,
|
|
349
133
|
};
|
|
350
|
-
const updated = (await client.sharedReports.update(request));
|
|
134
|
+
const updated = (await dispatchedWrite(this, client.sharedReports.update(request)));
|
|
351
135
|
const data = { id: updated.id ?? id, name: updated.name ?? opts.name };
|
|
352
136
|
printReceipt({
|
|
353
137
|
ok: true,
|
|
@@ -370,7 +154,7 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
370
154
|
.addHelpText("after", "\nExamples:\n" + " $ clk115 shared-reports delete report_123\n")
|
|
371
155
|
.action(async function (id) {
|
|
372
156
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
373
|
-
await client.sharedReports.delete({ workspaceId, sharedReportId: id });
|
|
157
|
+
await dispatchedWrite(this, client.sharedReports.delete({ workspaceId, sharedReportId: id }));
|
|
374
158
|
printReceipt({
|
|
375
159
|
ok: true,
|
|
376
160
|
action: "shared-reports.delete",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { lstatSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { UsageError } from "../failure.js";
|
|
6
|
+
import { resolveFlags } from "../flags.js";
|
|
7
|
+
import { fixedColumns, printObject, printRecords } from "../output.js";
|
|
8
|
+
import { rootProgram } from "./helpers.js";
|
|
9
|
+
import { leafCommand } from "./leaf-command.js";
|
|
10
|
+
const SKILLS = fileURLToPath(new URL("../../plugin/skills/", import.meta.url));
|
|
11
|
+
const skillNames = () => readdirSync(SKILLS).sort();
|
|
12
|
+
function readSkill(name) {
|
|
13
|
+
if (!skillNames().includes(name))
|
|
14
|
+
throw new UsageError(`Unknown skill "${name}". Provide one of: ${skillNames().join(", ")}.`);
|
|
15
|
+
return readFileSync(path.join(SKILLS, name, "SKILL.md"), "utf8");
|
|
16
|
+
}
|
|
17
|
+
function installedText(file) {
|
|
18
|
+
try {
|
|
19
|
+
for (const target of [path.dirname(file), file]) {
|
|
20
|
+
if (lstatSync(target, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
21
|
+
throw new Error(`${target} is a symbolic link; remove it, or pass another --dir.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return readFileSync(file, "utf8");
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err.code === "ENOENT")
|
|
28
|
+
return undefined;
|
|
29
|
+
throw new UsageError(`Nothing was written. ${err.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const description = (text) => /^description: (.*)$/m.exec(text)?.[1] ?? "";
|
|
33
|
+
export const registerSkillCommand = (program) => {
|
|
34
|
+
const skill = program.command("skill").description("Agent skills that come with this command line.");
|
|
35
|
+
leafCommand(skill, "list", "read")
|
|
36
|
+
.description("List the skills.")
|
|
37
|
+
.addHelpText("after", "\nExamples:\n $ clk115 skill list\n")
|
|
38
|
+
.action(function () {
|
|
39
|
+
const output = fixedColumns(["name", "description"], resolveFlags(rootProgram(this)));
|
|
40
|
+
printRecords(skillNames().map((name) => ({ name, description: description(readSkill(name)) })), output);
|
|
41
|
+
});
|
|
42
|
+
leafCommand(skill, "show <name>", "read")
|
|
43
|
+
.description("Print a skill.")
|
|
44
|
+
.addHelpText("after", "\nExamples:\n $ clk115 skill show clockify-cli\n")
|
|
45
|
+
.action(function (name) {
|
|
46
|
+
const output = fixedColumns(["name", "description", "text"], resolveFlags(rootProgram(this)));
|
|
47
|
+
const text = readSkill(name);
|
|
48
|
+
if (output.mode === "table")
|
|
49
|
+
process.stdout.write(text);
|
|
50
|
+
else
|
|
51
|
+
printObject({ name, description: description(text), text }, output);
|
|
52
|
+
});
|
|
53
|
+
leafCommand(skill, "install [names...]", "local")
|
|
54
|
+
.description("Copy skills into a directory an agent reads. Without names, all of them.")
|
|
55
|
+
.option("--dir <path>", "Target directory.", path.join(".claude", "skills"))
|
|
56
|
+
.option("--personal", "Install for every project of yours, in ~/.claude/skills.", false)
|
|
57
|
+
.option("--force", "Replace a skill that differs from the one that comes with this version.", false)
|
|
58
|
+
.addHelpText("after", "\nExamples:\n" +
|
|
59
|
+
" $ clk115 skill install\n" +
|
|
60
|
+
" $ clk115 skill install clockify-cli --personal\n" +
|
|
61
|
+
" $ clk115 skill install --dir .agents/skills --force\n")
|
|
62
|
+
.action(function (names, opts) {
|
|
63
|
+
const output = fixedColumns(["name", "state", "file"], resolveFlags(rootProgram(this)));
|
|
64
|
+
if (opts.personal && this.getOptionValueSource("dir") !== "default")
|
|
65
|
+
throw new UsageError("Provide only one of --personal and --dir.");
|
|
66
|
+
const root = opts.personal ? path.join(homedir(), ".claude", "skills") : opts.dir;
|
|
67
|
+
const planned = (names.length > 0 ? names : skillNames()).map((name) => {
|
|
68
|
+
const text = readSkill(name);
|
|
69
|
+
const file = path.resolve(root, name, "SKILL.md");
|
|
70
|
+
const before = installedText(file);
|
|
71
|
+
return { name, text, file, state: before === undefined ? "created" : before === text ? "unchanged" : "replaced" };
|
|
72
|
+
});
|
|
73
|
+
const differing = planned.filter(({ state }) => state === "replaced");
|
|
74
|
+
if (differing.length > 0 && !opts.force) {
|
|
75
|
+
throw new UsageError(`Nothing was written. ${differing.map(({ file }) => file).join(", ")} differs; pass --force to replace it.`);
|
|
76
|
+
}
|
|
77
|
+
for (const { file, text, state } of planned) {
|
|
78
|
+
if (state === "unchanged")
|
|
79
|
+
continue;
|
|
80
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
81
|
+
writeFileSync(file, text);
|
|
82
|
+
}
|
|
83
|
+
printRecords(planned.map(({ name, state, file }) => ({ name, state, file })), output);
|
|
84
|
+
});
|
|
85
|
+
};
|
package/dist/commands/start.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { UsageError } from "../failure.js";
|
|
1
2
|
import { printReceipt } from "../receipt.js";
|
|
3
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
2
4
|
import { resolveContext } from "./helpers.js";
|
|
3
5
|
import { leafCommand } from "./leaf-command.js";
|
|
4
6
|
import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.js";
|
|
@@ -14,13 +16,13 @@ export const registerStartCommand = (program, services) => {
|
|
|
14
16
|
.option("--tag <name...>", "Tag name(s) or ID(s). Repeat the flag for multiple tags.")
|
|
15
17
|
.option("--billable", "Mark the entry as billable.", false)
|
|
16
18
|
.action(async function (description, opts) {
|
|
19
|
+
if (opts.task && !opts.project) {
|
|
20
|
+
throw new UsageError("--task requires --project: a task can only be resolved within a project.");
|
|
21
|
+
}
|
|
17
22
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
18
23
|
const projectId = opts.project
|
|
19
24
|
? await resolveProjectId(client, workspaceId, opts.project)
|
|
20
25
|
: undefined;
|
|
21
|
-
if (opts.task && !projectId) {
|
|
22
|
-
throw new Error("--task requires --project: a task can only be resolved within a project.");
|
|
23
|
-
}
|
|
24
26
|
const taskId = opts.task && projectId
|
|
25
27
|
? await resolveTaskId(client, workspaceId, projectId, opts.task)
|
|
26
28
|
: undefined;
|
|
@@ -41,7 +43,7 @@ export const registerStartCommand = (program, services) => {
|
|
|
41
43
|
if (opts.billable)
|
|
42
44
|
body.billable = true;
|
|
43
45
|
const req = { workspaceId, body };
|
|
44
|
-
const created = await client.timeEntries.create(req);
|
|
46
|
+
const created = await dispatchedWrite(this, client.timeEntries.create(req));
|
|
45
47
|
const entry = created;
|
|
46
48
|
const data = {
|
|
47
49
|
id: entry.id ?? "",
|
package/dist/commands/status.js
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import { iterAll } from "clockify-sdk-ts-115/iter";
|
|
2
1
|
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
|
+
import { runningEntryOf } from "clockify-sdk-ts-115/timer";
|
|
3
3
|
import { formatIsoDuration } from "../duration.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { resolveFlags } from "../flags.js";
|
|
5
|
+
import { fixedColumns, printObject } from "../output.js";
|
|
6
|
+
import { resolveBaseContext, rootProgram } from "./helpers.js";
|
|
6
7
|
import { leafCommand } from "./leaf-command.js";
|
|
8
|
+
const TIMER_UNAVAILABLE = {
|
|
9
|
+
user_id_missing: "(timer lookup skipped: current user ID unavailable)",
|
|
10
|
+
response_unrecognized: "(timer state unknown: unrecognized response to the timer lookup)",
|
|
11
|
+
};
|
|
12
|
+
const STATUS_KEYS = [
|
|
13
|
+
"workspaceId",
|
|
14
|
+
"userId",
|
|
15
|
+
"email",
|
|
16
|
+
"name",
|
|
17
|
+
"timerState",
|
|
18
|
+
"timerStateReason",
|
|
19
|
+
"runningEntry",
|
|
20
|
+
"availableWorkspaces",
|
|
21
|
+
"hint",
|
|
22
|
+
];
|
|
7
23
|
export const registerStatusCommand = (program, services) => {
|
|
8
24
|
leafCommand(program, "status", "read")
|
|
9
25
|
.description("Show the configured workspace, current user, and running timer.")
|
|
@@ -11,41 +27,72 @@ export const registerStatusCommand = (program, services) => {
|
|
|
11
27
|
" $ clk115 status\n" +
|
|
12
28
|
" $ clk115 status --json\n")
|
|
13
29
|
.action(async function () {
|
|
14
|
-
const
|
|
30
|
+
const output = fixedColumns(STATUS_KEYS, resolveFlags(rootProgram(this)));
|
|
31
|
+
const { client, config } = await resolveBaseContext(this, services, output);
|
|
15
32
|
const user = await client.users.getCurrentUser();
|
|
33
|
+
let statusState;
|
|
16
34
|
if (!config.workspaceId) {
|
|
17
35
|
const workspaces = (await client.workspaces.list());
|
|
36
|
+
statusState = {
|
|
37
|
+
kind: "workspace_unconfigured",
|
|
38
|
+
availableWorkspaces: workspaces.map((w) => ({
|
|
39
|
+
id: w.id ?? "",
|
|
40
|
+
name: w.name ?? "",
|
|
41
|
+
})),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const workspaceId = config.workspaceId;
|
|
46
|
+
const userId = entityId(user);
|
|
47
|
+
if (userId?.trim()) {
|
|
48
|
+
const entries = normaliseEntries(await client.timeEntries.listForUser({
|
|
49
|
+
workspaceId,
|
|
50
|
+
userId,
|
|
51
|
+
"in-progress": true,
|
|
52
|
+
"page-size": 1,
|
|
53
|
+
}));
|
|
54
|
+
const entry = entries && runningEntryOf(entries, userId);
|
|
55
|
+
if (entries === undefined) {
|
|
56
|
+
statusState = { kind: "unavailable", workspaceId, reason: "response_unrecognized" };
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
statusState = entry === undefined ? { kind: "idle", workspaceId } : { kind: "timer_running", workspaceId, entry };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
statusState = { kind: "unavailable", workspaceId, reason: "user_id_missing" };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (statusState.kind === "workspace_unconfigured") {
|
|
18
67
|
printObject({
|
|
19
68
|
userId: entityId(user) ?? "",
|
|
20
69
|
email: user.email ?? "",
|
|
21
70
|
workspaceId: "(not set)",
|
|
22
|
-
|
|
71
|
+
timerState: "unavailable",
|
|
72
|
+
timerStateReason: "workspace_not_set",
|
|
73
|
+
availableWorkspaces: statusState.availableWorkspaces,
|
|
23
74
|
hint: "Set CLOCKIFY_WORKSPACE_ID (or pass --workspace, or add workspaceId to ~/.clockifyrc.json) to one of the ids above.",
|
|
24
75
|
}, output);
|
|
25
76
|
return;
|
|
26
77
|
}
|
|
27
|
-
const workspaceId = config.workspaceId;
|
|
28
|
-
let running = null;
|
|
29
|
-
for await (const entry of iterAll(async (req) => normaliseEntries(await client.timeEntries.listInProgress(req)), { workspaceId }, { pageSize: 200, maxPages: 1000 })) {
|
|
30
|
-
if (isOwn(entry, user)) {
|
|
31
|
-
running = entry;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
78
|
printObject({
|
|
36
|
-
workspaceId,
|
|
79
|
+
workspaceId: statusState.workspaceId,
|
|
37
80
|
userId: entityId(user) ?? "",
|
|
38
81
|
email: user.email ?? "",
|
|
39
82
|
name: user.name ?? "",
|
|
40
|
-
|
|
83
|
+
timerState: statusState.kind,
|
|
84
|
+
...(statusState.kind === "unavailable" && { timerStateReason: statusState.reason }),
|
|
85
|
+
runningEntry: statusState.kind === "timer_running"
|
|
41
86
|
? {
|
|
42
|
-
id: entityId(
|
|
43
|
-
description:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
87
|
+
id: entityId(statusState.entry),
|
|
88
|
+
description: statusState.entry.description ??
|
|
89
|
+
"",
|
|
90
|
+
projectId: statusState.entry
|
|
91
|
+
.projectId ?? "",
|
|
92
|
+
startedAt: extractStart(statusState.entry),
|
|
93
|
+
elapsed: formatRunningElapsed(statusState.entry),
|
|
47
94
|
}
|
|
48
|
-
: "(no timer running)",
|
|
95
|
+
: statusState.kind === "idle" ? "(no timer running)" : TIMER_UNAVAILABLE[statusState.reason],
|
|
49
96
|
}, output);
|
|
50
97
|
});
|
|
51
98
|
};
|
|
@@ -57,12 +104,7 @@ function normaliseEntries(resp) {
|
|
|
57
104
|
if (Array.isArray(candidate))
|
|
58
105
|
return candidate;
|
|
59
106
|
}
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
function isOwn(entry, user) {
|
|
63
|
-
const entryUserId = entry.userId;
|
|
64
|
-
const userId = entityId(user);
|
|
65
|
-
return entryUserId !== undefined && userId !== undefined && entryUserId === userId;
|
|
107
|
+
return undefined;
|
|
66
108
|
}
|
|
67
109
|
function extractStart(entry) {
|
|
68
110
|
const interval = entry.timeInterval;
|
package/dist/commands/stop.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
1
|
+
import { findRunningEntry } from "clockify-sdk-ts-115/timer";
|
|
3
2
|
import { printReceipt } from "../receipt.js";
|
|
4
|
-
import {
|
|
3
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
4
|
+
import { requireCurrentUserId, resolveContext } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
6
|
export const registerStopCommand = (program, services) => {
|
|
7
7
|
leafCommand(program, "stop", "write")
|
|
@@ -11,20 +11,9 @@ export const registerStopCommand = (program, services) => {
|
|
|
11
11
|
" $ clk115 stop --json\n")
|
|
12
12
|
.action(async function () {
|
|
13
13
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
throw new Error("could not determine user ID from getCurrentUser response");
|
|
18
|
-
}
|
|
19
|
-
let running;
|
|
20
|
-
for await (const item of iterAll((req) => client.timeEntries.listInProgress(req), { workspaceId }, { pageSize: 200, maxPages: 1000 })) {
|
|
21
|
-
const entry = item;
|
|
22
|
-
if (entry.userId === userId && entry.id) {
|
|
23
|
-
running = entry;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!running) {
|
|
14
|
+
const userId = await requireCurrentUserId(client);
|
|
15
|
+
const running = await findRunningEntry(client, { workspaceId, userId });
|
|
16
|
+
if (running === undefined) {
|
|
28
17
|
printReceipt({
|
|
29
18
|
ok: true,
|
|
30
19
|
action: "timer.stop",
|
|
@@ -37,7 +26,7 @@ export const registerStopCommand = (program, services) => {
|
|
|
37
26
|
return;
|
|
38
27
|
}
|
|
39
28
|
const end = new Date().toISOString();
|
|
40
|
-
const stopped = await client.timeEntries.updateForUser({ workspaceId, userId, end });
|
|
29
|
+
const stopped = await dispatchedWrite(this, client.timeEntries.updateForUser({ workspaceId, userId, end }));
|
|
41
30
|
const entry = stopped;
|
|
42
31
|
const data = {
|
|
43
32
|
...entry,
|