@apet97/clockify-cli-115 6.0.0 → 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.
Files changed (44) hide show
  1. package/README.md +167 -21
  2. package/dist/client.js +30 -7
  3. package/dist/commands/api.js +44 -76
  4. package/dist/commands/approvals.js +2 -5
  5. package/dist/commands/auth.js +229 -0
  6. package/dist/commands/batch.js +226 -0
  7. package/dist/commands/clients.js +11 -65
  8. package/dist/commands/doctor.js +65 -66
  9. package/dist/commands/expenses.js +21 -24
  10. package/dist/commands/helpers.js +46 -2
  11. package/dist/commands/leaf-command.js +7 -0
  12. package/dist/commands/manifest.js +63 -0
  13. package/dist/commands/operations.js +271 -0
  14. package/dist/commands/projects.js +10 -23
  15. package/dist/commands/reports.js +22 -7
  16. package/dist/commands/shared-report-body.js +3 -81
  17. package/dist/commands/sharedReports.js +1 -21
  18. package/dist/commands/skill.js +85 -0
  19. package/dist/commands/status.js +18 -12
  20. package/dist/commands/stop.js +3 -12
  21. package/dist/commands/tags.js +5 -7
  22. package/dist/commands/tasks.js +19 -120
  23. package/dist/commands/users.js +4 -14
  24. package/dist/commands/webhook-delivery.js +331 -0
  25. package/dist/commands/webhooks.js +31 -97
  26. package/dist/completions.js +2 -1
  27. package/dist/config.js +166 -63
  28. package/dist/credentials.js +164 -0
  29. package/dist/failure.js +4 -9
  30. package/dist/flags.js +14 -4
  31. package/dist/generated/version.js +1 -1
  32. package/dist/index.js +38 -14
  33. package/dist/interrupts.js +28 -0
  34. package/dist/output.js +137 -48
  35. package/dist/receipt.js +2 -10
  36. package/dist/stdin.js +6 -0
  37. package/dist/stdout.js +38 -0
  38. package/dist/write-outcome.js +1 -1
  39. package/package.json +5 -3
  40. package/plugin/.claude-plugin/plugin.json +16 -0
  41. package/plugin/skills/clockify-cli/SKILL.md +88 -0
  42. package/plugin/skills/clockify-mcp/SKILL.md +48 -0
  43. package/plugin/skills/clockify-sdk/SKILL.md +85 -0
  44. package/dist/error-codes.js +0 -300
@@ -0,0 +1,271 @@
1
+ import { closeSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { Option } from "commander";
4
+ import { requireWorkspaceId } from "../config.js";
5
+ import { UsageError } from "../failure.js";
6
+ import { globalFlags, resolveFlags } from "../flags.js";
7
+ import { fixedColumns, printData, printObject, printRecords } from "../output.js";
8
+ import { printReceipt } from "../receipt.js";
9
+ import { dispatchedWrite } from "../write-outcome.js";
10
+ import { collect, parseIntArg, parseJson, parsePair, readTextInput, rootProgram } from "./helpers.js";
11
+ import { declareMutation, leafCommand } from "./leaf-command.js";
12
+ const EFFECTS = [
13
+ "read",
14
+ "business_write",
15
+ "external_side_effect",
16
+ "privileged",
17
+ "destructive",
18
+ ];
19
+ const LIST_KEYS = ["name", "effect", "method", "path", "command", "tool", "summary"];
20
+ const REQUEST_KEYS = ["ok", "dryRun", "operation", "effect", "method", "path", "query", "body"];
21
+ const WRITTEN_KEYS = ["written", "bytes"];
22
+ const OPERATION_KEYS = Object.keys({
23
+ name: true, operationId: true, method: true, path: true, service: true, server: true, tags: true, summary: true, description: true,
24
+ deprecated: true, effect: true, destructiveHint: true, openWorldHint: true, replacedBy: true, mcp: true, cli: true, media: true,
25
+ responseMedia: true, returnsSigningToken: true, input: true,
26
+ });
27
+ export async function requireOperation(reference) {
28
+ const { findOperation, searchOperations } = await import("clockify-sdk-ts-115/operations");
29
+ const operation = findOperation(reference);
30
+ if (operation !== undefined)
31
+ return operation;
32
+ const near = searchOperations(reference.replace(/[._-]/g, " ")).slice(0, 3).map(({ name }) => name);
33
+ throw new UsageError(`Unknown operation "${reference}". ` +
34
+ (near.length > 0 ? `Provide one of: ${near.join(", ")}.` : "Run `clk115 operations list`."));
35
+ }
36
+ export function resolvedRequest(operation, { workspaceId, path: params = {}, query, body }) {
37
+ const values = { ...params, workspaceId };
38
+ return {
39
+ operation: operation.name,
40
+ effect: operation.effect,
41
+ method: operation.method,
42
+ path: operation.path.replace(/\{(\w+)\}/g, (_, name) => encodeURIComponent(String(values[name]))),
43
+ ...(query && Object.keys(query).length > 0 && { query }),
44
+ ...(body !== undefined && { body: describeBody(body) }),
45
+ };
46
+ }
47
+ function describeBody(body) {
48
+ if (body instanceof Blob)
49
+ return `<${body.size} bytes>`;
50
+ if (Array.isArray(body))
51
+ return body.map(describeBody);
52
+ if (body === null || typeof body !== "object")
53
+ return body;
54
+ return Object.fromEntries(Object.entries(body).map(([key, value]) => [key, describeBody(value)]));
55
+ }
56
+ function coerce(schema, values) {
57
+ if (schema?.type === "array")
58
+ return values.map((value) => coerce(schema.items, [value]));
59
+ if (values.length > 1)
60
+ return values;
61
+ const value = values[0];
62
+ if ((schema?.type === "integer" || schema?.type === "number") && value.trim() !== "" && Number.isFinite(Number(value))) {
63
+ return Number(value);
64
+ }
65
+ if (schema?.type === "boolean" && (value === "true" || value === "false"))
66
+ return value === "true";
67
+ return value;
68
+ }
69
+ function parameters(schema, pairs) {
70
+ const values = new Map();
71
+ for (const [key, value] of pairs)
72
+ values.set(key, [...(values.get(key) ?? []), value]);
73
+ return Object.fromEntries([...values].map(([key, value]) => [key, coerce(schema?.properties?.[key], value)]));
74
+ }
75
+ function withFile(operation, body, file) {
76
+ if (file === undefined)
77
+ return body;
78
+ const fields = operation.input.properties?.body?.properties ?? {};
79
+ const field = Object.keys(fields).find((name) => fields[name].format === "binary");
80
+ if (field === undefined)
81
+ throw new UsageError(`--file does not apply: ${operation.name} takes no file.`);
82
+ let bytes;
83
+ try {
84
+ bytes = readFileSync(file);
85
+ }
86
+ catch (err) {
87
+ throw new UsageError(`--file ${JSON.stringify(file)} could not be read: ${err.message}; provide a readable file`);
88
+ }
89
+ return { ...body, [field]: new File([bytes], path.basename(file)) };
90
+ }
91
+ export const registerOperationsCommand = (program, services) => {
92
+ const operations = program
93
+ .command("operations")
94
+ .description("Find, inspect and call any of the API's operations.");
95
+ leafCommand(operations, "list", "read")
96
+ .description("List operations, or search them by what you want to do.")
97
+ .argument("[words...]", "What you want to do, for example: archive a client.")
98
+ .addOption(new Option("--effect <effect>", "Only operations with this effect.").choices(EFFECTS))
99
+ .option("--tag <tag>", "Only operations with this tag.")
100
+ .option("--limit <n>", "Maximum operations to print.", parseIntArg, 25)
101
+ .option("--all", "Print every match.", false)
102
+ .addHelpText("after", "\nExamples:\n" +
103
+ " $ clk115 operations list archive a client\n" +
104
+ " $ clk115 operations list --tag Invoices --effect read\n" +
105
+ " $ clk115 operations list --all --json\n")
106
+ .action(async function (words, opts) {
107
+ const output = fixedColumns(LIST_KEYS, resolveFlags(rootProgram(this)));
108
+ const catalog = await import("clockify-sdk-ts-115/operations");
109
+ const found = words.length > 0 ? catalog.searchOperations(words.join(" ")) : [...catalog.operations().values()];
110
+ const rows = found
111
+ .filter(({ effect }) => opts.effect === undefined || effect === opts.effect)
112
+ .filter(({ tags }) => opts.tag === undefined || tags.some((tag) => tag.toLowerCase() === opts.tag.toLowerCase()))
113
+ .slice(0, opts.all ? undefined : opts.limit)
114
+ .map(({ name, effect, method, path: route, cli, mcp, summary, deprecated }) => ({
115
+ name,
116
+ effect,
117
+ method,
118
+ path: route,
119
+ command: cli ?? null,
120
+ tool: mcp.curated ?? mcp.exact,
121
+ summary: (deprecated ? "Deprecated. " : "") + (summary ?? ""),
122
+ }));
123
+ const brief = output.mode === "table" && output.fields === undefined;
124
+ printRecords(brief ? rows.map(({ name, effect, command, summary }) => ({ name, effect, command, summary })) : rows, output);
125
+ });
126
+ leafCommand(operations, "show", "read")
127
+ .description("Show one operation: route, effect, input schema and the command or tool that covers it.")
128
+ .argument("<operation>", "Name (tags.create), operationId or exact MCP tool name.")
129
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 operations show tags.create --json\n")
130
+ .action(async function (reference) {
131
+ const output = fixedColumns(OPERATION_KEYS, resolveFlags(rootProgram(this)));
132
+ const operation = await requireOperation(reference);
133
+ if (output.mode === "table" && output.fields === undefined) {
134
+ const { input, ...rest } = operation;
135
+ printObject(rest, output);
136
+ console.log(JSON.stringify(input, null, 2));
137
+ return;
138
+ }
139
+ printObject(operation, output);
140
+ });
141
+ leafCommand(operations, "call", "destructive")
142
+ .description("Call one operation. Input is checked against its schema before anything is sent.")
143
+ .argument("<operation>", "Name (tags.create), operationId or exact MCP tool name.")
144
+ .option("-p, --path <name=value>", "Path parameter (repeatable); workspaceId comes from the configuration.", collect, [])
145
+ .option("-q, --query <name=value>", "Query parameter (repeatable).", collect, [])
146
+ .option("--body <json|@file|->", "JSON body: inline, @file, or - for stdin.")
147
+ .option("--file <path>", "File to upload, for the operations that take one.")
148
+ .option("--output-file <path>", "Write the response to this new file instead of stdout.")
149
+ .option("--dry-run", "Print the request without sending it. Needs no credentials.", false)
150
+ .addHelpText("after", "\nExamples:\n" +
151
+ " $ clk115 operations call tags.list -q archived=false\n" +
152
+ " $ clk115 operations call tags.create --body '{\"name\":\"focus\"}' --dry-run\n" +
153
+ " $ clk115 operations call expenses.create --body @expense.json --file receipt.pdf\n" +
154
+ "\nAn operation that replaces a record resets the fields you leave out; `operations show` names the safe update.\n")
155
+ .action(async function (reference, opts) {
156
+ const operation = await requireOperation(reference);
157
+ const reads = operation.effect === "read";
158
+ declareMutation(this, !reads);
159
+ const { callOperation, operationInputProblems } = await import("clockify-sdk-ts-115/operations");
160
+ const root = rootProgram(this);
161
+ const output = resolveFlags(root);
162
+ const schema = operation.input.properties;
163
+ const text = await readTextInput(opts.body, "--body");
164
+ const body = withFile(operation, text === undefined ? undefined : parseJson(text, "--body"), opts.file);
165
+ const config = services.loadConfig(globalFlags(root));
166
+ const workspaceId = operation.path.includes("{workspaceId}") ? requireWorkspaceId(config) : undefined;
167
+ const input = {
168
+ workspaceId,
169
+ path: parameters(schema?.path, opts.path.map((pair) => parsePair(pair, "--path"))),
170
+ query: parameters(schema?.query, opts.query.map((pair) => parsePair(pair, "--query"))),
171
+ ...(body !== undefined && { body }),
172
+ };
173
+ const problems = operationInputProblems(operation, input);
174
+ if (problems.length > 0) {
175
+ throw new UsageError(`${operation.name}: ${problems.join("; ")}. Run \`clk115 operations show ${operation.name}\` for its input.`);
176
+ }
177
+ if (opts.dryRun) {
178
+ printObject({ ok: true, dryRun: true, ...resolvedRequest(operation, input) }, fixedColumns(REQUEST_KEYS, output));
179
+ return;
180
+ }
181
+ const { outputFile } = opts;
182
+ const shape = outputFile !== undefined && reads ? fixedColumns(WRITTEN_KEYS, output) : output;
183
+ const fileFitsStdout = !process.stdout.isTTY && output.mode === "table";
184
+ if (outputFile !== undefined)
185
+ requireNewFile(outputFile);
186
+ else if (answersWithFile(operation) && !fileFitsStdout)
187
+ throw new UsageError(IS_A_FILE);
188
+ const client = await services.buildClient(config, this);
189
+ const call = callOperation(client, operation.name, input);
190
+ const answer = reads ? await call : await dispatchedWrite(this, call);
191
+ const data = outputFile === undefined ? await responseData(operation, answer) : await written(outputFile, operation, answer);
192
+ if (Buffer.isBuffer(data)) {
193
+ if (!fileFitsStdout)
194
+ throw new Error(IS_A_FILE);
195
+ process.stdout.write(data);
196
+ }
197
+ else if (reads)
198
+ printData(data, shape);
199
+ else
200
+ printReceipt(operationReceipt(operation, input, data), output);
201
+ });
202
+ };
203
+ const IS_A_FILE = "The response is a file: pass --output-file, or redirect stdout without an output flag.";
204
+ export function answersWithFile({ responseMedia = [] }) {
205
+ return responseMedia.includes("application/octet-stream");
206
+ }
207
+ function isFileResponse(value) {
208
+ return value !== null && typeof value === "object" && "arrayBuffer" in value && typeof value.arrayBuffer === "function";
209
+ }
210
+ function withoutSigningToken({ returnsSigningToken }, data) {
211
+ if (!returnsSigningToken || data === undefined)
212
+ return data;
213
+ return JSON.parse(JSON.stringify(data, (key, value) => (key === "authToken" ? undefined : value)));
214
+ }
215
+ async function responseBytes(answer) {
216
+ return isFileResponse(answer) ? Buffer.from(await answer.arrayBuffer()) : answer;
217
+ }
218
+ export async function responseData(operation, answer) {
219
+ const { returnsSigningToken } = operation;
220
+ const raw = await responseBytes(answer);
221
+ const encoded = Buffer.isBuffer(raw) ? !answersWithFile(operation) : typeof raw === "string" && returnsSigningToken;
222
+ if (!encoded)
223
+ return withoutSigningToken(operation, raw);
224
+ try {
225
+ const text = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.from(raw));
226
+ return withoutSigningToken(operation, JSON.parse(text));
227
+ }
228
+ catch {
229
+ if (returnsSigningToken)
230
+ throw new Error("The response is not JSON and may contain a signing token, so it is not shown.");
231
+ return raw;
232
+ }
233
+ }
234
+ function requireNewFile(file) {
235
+ try {
236
+ closeSync(openSync(file, "wx"));
237
+ rmSync(file);
238
+ }
239
+ catch (err) {
240
+ throw new UsageError(`--output-file ${JSON.stringify(file)} could not be created: ${err.message}; provide a path that does not exist yet`);
241
+ }
242
+ }
243
+ async function written(file, operation, answer) {
244
+ const data = isFileResponse(answer) && !operation.returnsSigningToken ? await responseBytes(answer) : await responseData(operation, answer);
245
+ const bytes = Buffer.isBuffer(data) ? data : Buffer.from(`${JSON.stringify(data ?? null, null, 2)}\n`);
246
+ const descriptor = openSync(file, "wx");
247
+ try {
248
+ writeFileSync(descriptor, bytes);
249
+ return { written: file, bytes: bytes.length };
250
+ }
251
+ catch (err) {
252
+ rmSync(file, { force: true });
253
+ throw err;
254
+ }
255
+ finally {
256
+ closeSync(descriptor);
257
+ }
258
+ }
259
+ export function operationReceipt(operation, { path: params = {} }, data) {
260
+ const ids = Object.fromEntries(Object.entries(params).map(([name, value]) => [name, String(value)]));
261
+ const record = data !== null && typeof data === "object" && !Array.isArray(data)
262
+ ? data
263
+ : data === undefined || data === null ? {} : { result: data };
264
+ return {
265
+ ok: true,
266
+ action: operation.name,
267
+ entity: operation.name.split(".")[0],
268
+ ids: { ...ids, ...(typeof record.id === "string" && { id: record.id }) },
269
+ data: record,
270
+ };
271
+ }
@@ -1,16 +1,11 @@
1
1
  import { archiveThenDeleteProject } from "clockify-sdk-ts-115/ensure";
2
+ import { projectUpdate } from "clockify-sdk-ts-115/updates";
2
3
  import { PartialDeleteError, UsageError } from "../failure.js";
3
4
  import { printObject, printRecords } from "../output.js";
4
5
  import { printReceipt } from "../receipt.js";
5
6
  import { dispatchedWrite } from "../write-outcome.js";
6
7
  import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
7
8
  import { leafCommand } from "./leaf-command.js";
8
- function projectUpdateCarryFields(current) {
9
- if (typeof current.billable !== "boolean" || typeof current.public !== "boolean") {
10
- throw new Error("Cannot update project safely: the current project did not return boolean billable and public fields.");
11
- }
12
- return { billable: current.billable, isPublic: current.public };
13
- }
14
9
  export const registerProjectsCommand = (program, services) => {
15
10
  const projects = program.command("projects").description("Manage projects.");
16
11
  leafCommand(projects, "list", "read")
@@ -127,19 +122,14 @@ export const registerProjectsCommand = (program, services) => {
127
122
  }
128
123
  const { client, workspaceId, output } = await resolveContext(this, services);
129
124
  const current = await client.projects.get({ workspaceId, projectId: id });
130
- const body = projectUpdateCarryFields(current);
131
- if (opts.name)
132
- body.name = opts.name;
133
- if (opts.client)
134
- body.clientId = opts.client;
135
- if (opts.color)
136
- body.color = opts.color;
137
- if (opts.note !== undefined)
138
- body.note = opts.note;
139
- if (opts.billable !== undefined)
140
- body.billable = opts.billable;
141
- if (opts.archived !== undefined)
142
- body.archived = opts.archived;
125
+ const body = projectUpdate.body(current, {
126
+ name: opts.name || undefined,
127
+ clientId: opts.client || undefined,
128
+ color: opts.color || undefined,
129
+ note: opts.note,
130
+ billable: opts.billable,
131
+ archived: opts.archived,
132
+ });
143
133
  const req = { workspaceId, projectId: id, body };
144
134
  const updated = (await dispatchedWrite(this, client.projects.update(req)));
145
135
  const data = { id: updated.id ?? id, name: updated.name ?? "" };
@@ -171,13 +161,10 @@ export const registerProjectsCommand = (program, services) => {
171
161
  adapter: {
172
162
  getCurrent: ({ workspaceId: currentWorkspaceId, id: projectId }) => client.projects.get({ workspaceId: currentWorkspaceId, projectId }),
173
163
  archive: async ({ workspaceId: currentWorkspaceId, id: projectId, current, }) => {
174
- const preserved = projectUpdateCarryFields(current);
175
164
  await dispatchedWrite(this, client.projects.update({
176
165
  workspaceId: currentWorkspaceId,
177
166
  projectId,
178
- name: current.name,
179
- ...preserved,
180
- archived: true,
167
+ ...projectUpdate.body(current, { name: current.name, archived: true }),
181
168
  }));
182
169
  archivedByCall = true;
183
170
  },
@@ -1,10 +1,20 @@
1
1
  import { REPORT_PERIODS, isExactWeeklyRange, parseWeeklyDateTime, resolveInstant, resolvePeriod, } from "clockify-sdk-ts-115/dates";
2
2
  import { detailedFilter, summaryFilter, weeklyFilter } from "clockify-sdk-ts-115/reports";
3
3
  import { UsageError } from "../failure.js";
4
- import { printObject } from "../output.js";
4
+ import { printData, printObject, printWarning } from "../output.js";
5
5
  import { clampPageSize, parseIntArg, parseTimeViewMode, resolveContext, TIME_VIEW_MODE_HELP } from "./helpers.js";
6
6
  import { leafCommand } from "./leaf-command.js";
7
7
  import { resolveClientId, resolveProjectId } from "./resolve-refs.js";
8
+ function printReport(report, lists, output) {
9
+ const answer = (report ?? { totals: [] });
10
+ const isReport = ["totals", ...lists].some((list) => Array.isArray(answer[list]));
11
+ const rows = lists.map((list) => answer[list]).find((list) => Array.isArray(list) && list.length > 0);
12
+ if (output.mode === "csv" && isReport)
13
+ printData(rows ?? [], output);
14
+ else
15
+ printObject(report, output);
16
+ return rows ?? [];
17
+ }
8
18
  function resolveRange(opts) {
9
19
  const now = new Date();
10
20
  const periodInput = (opts.period ?? "this_month")
@@ -161,7 +171,7 @@ export const registerReportsCommand = (program, services) => {
161
171
  req.clients = idFilter(ids);
162
172
  }
163
173
  const data = await client.reports.summary(req);
164
- printObject(data, output);
174
+ printReport(data, ["groupOne"], output);
165
175
  });
166
176
  leafCommand(reports, "detailed", "read")
167
177
  .description("Detailed report listing individual time entries over a date range.")
@@ -176,18 +186,23 @@ export const registerReportsCommand = (program, services) => {
176
186
  const timeViewMode = optionalTimeViewMode(opts);
177
187
  const { client, workspaceId, output } = await resolveContext(this, services);
178
188
  const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
189
+ const { page } = opts;
190
+ const pageSize = clampPageSize(opts.pageSize, 1000);
179
191
  const req = {
180
192
  workspaceId,
181
193
  dateRangeStart,
182
194
  dateRangeEnd,
183
195
  detailedFilter: detailedFilter({
184
- page: opts.page,
185
- pageSize: clampPageSize(opts.pageSize, 1000),
196
+ page,
197
+ pageSize,
186
198
  }),
187
199
  ...(timeViewMode !== undefined ? { timeViewMode } : {}),
188
200
  };
189
201
  const data = await client.reports.detailed(req);
190
- printObject(data, output);
202
+ const entries = printReport(data, ["timeentries", "timeEntries"], output);
203
+ if (entries.length >= pageSize) {
204
+ printWarning(`Page ${page} is full (${entries.length} entries). Read on with --page ${page + 1}.`, output);
205
+ }
191
206
  });
192
207
  leafCommand(reports, "weekly", "read")
193
208
  .description("Weekly report for one exact seven-day interval.")
@@ -211,7 +226,7 @@ export const registerReportsCommand = (program, services) => {
211
226
  ...(timeViewMode !== undefined ? { timeViewMode } : {}),
212
227
  };
213
228
  const data = await client.reports.weekly(req);
214
- printObject(data, output);
229
+ printReport(data, ["groupOne"], output);
215
230
  });
216
231
  leafCommand(reports, "attendance", "read")
217
232
  .description("Attendance report of clock-in/out activity over a date range.")
@@ -232,6 +247,6 @@ export const registerReportsCommand = (program, services) => {
232
247
  ...(timeViewMode !== undefined ? { timeViewMode } : {}),
233
248
  };
234
249
  const data = await client.reports.attendance(req);
235
- printObject(data, output);
250
+ printReport(data, ["groupOne", "entities"], output);
236
251
  });
237
252
  };
@@ -1,6 +1,7 @@
1
+ import { defined, SHARED_REPORT_TYPES, } from "clockify-sdk-ts-115/requests";
1
2
  import { z } from "zod";
2
3
  import { UsageError } from "../failure.js";
3
- import { SHARED_REPORT_FILTER_EXPORT_TYPES, SHARED_REPORT_TYPES, SUMMARY_GROUPS, } from "./sharedReports.js";
4
+ import { SHARED_REPORT_FILTER_EXPORT_TYPES, SUMMARY_GROUPS } from "./sharedReports.js";
4
5
  const nonEmptyStringSchema = z
5
6
  .string()
6
7
  .refine((value) => value.trim() !== "", "must be a non-empty string.");
@@ -68,85 +69,6 @@ const sharedReportBodySchema = z
68
69
  type: sharedReportTypeSchema,
69
70
  })
70
71
  .strict();
71
- function toSharedUsersFilter(value) {
72
- return {
73
- ...(value.contains !== undefined ? { contains: value.contains } : {}),
74
- ...(value.ids !== undefined ? { ids: value.ids } : {}),
75
- ...(value.status !== undefined ? { status: value.status } : {}),
76
- };
77
- }
78
- function toSharedReportFilter(value) {
79
- return {
80
- dateRangeEnd: value.dateRangeEnd,
81
- dateRangeStart: value.dateRangeStart,
82
- exportType: value.exportType,
83
- ...(value.attendanceFilter !== undefined
84
- ? {
85
- attendanceFilter: {
86
- ...(value.attendanceFilter.page !== undefined
87
- ? { page: value.attendanceFilter.page }
88
- : {}),
89
- ...(value.attendanceFilter.pageSize !== undefined
90
- ? { pageSize: value.attendanceFilter.pageSize }
91
- : {}),
92
- ...(value.attendanceFilter.users !== undefined
93
- ? { users: toSharedUsersFilter(value.attendanceFilter.users) }
94
- : {}),
95
- },
96
- }
97
- : {}),
98
- ...(value.detailedFilter !== undefined
99
- ? {
100
- detailedFilter: {
101
- ...(value.detailedFilter.auditFilter !== undefined
102
- ? { auditFilter: value.detailedFilter.auditFilter }
103
- : {}),
104
- ...(value.detailedFilter.options !== undefined
105
- ? { options: value.detailedFilter.options }
106
- : {}),
107
- ...(value.detailedFilter.page !== undefined
108
- ? { page: value.detailedFilter.page }
109
- : {}),
110
- ...(value.detailedFilter.pageSize !== undefined
111
- ? { pageSize: value.detailedFilter.pageSize }
112
- : {}),
113
- ...(value.detailedFilter.sortColumn !== undefined
114
- ? { sortColumn: value.detailedFilter.sortColumn }
115
- : {}),
116
- ...(value.detailedFilter.sortOrder !== undefined
117
- ? { sortOrder: value.detailedFilter.sortOrder }
118
- : {}),
119
- },
120
- }
121
- : {}),
122
- ...(value.summaryFilter !== undefined
123
- ? {
124
- summaryFilter: {
125
- groups: value.summaryFilter.groups,
126
- ...(value.summaryFilter.sortColumn !== undefined
127
- ? { sortColumn: value.summaryFilter.sortColumn }
128
- : {}),
129
- },
130
- }
131
- : {}),
132
- ...(value.weeklyFilter !== undefined
133
- ? {
134
- weeklyFilter: {
135
- group: value.weeklyFilter.group,
136
- subgroup: value.weeklyFilter.subgroup,
137
- },
138
- }
139
- : {}),
140
- };
141
- }
142
- function toSharedReportBody(value) {
143
- return {
144
- filter: toSharedReportFilter(value.filter),
145
- name: value.name,
146
- type: value.type,
147
- ...(value.isPublic !== undefined ? { isPublic: value.isPublic } : {}),
148
- };
149
- }
150
72
  function parseFilterJson(raw) {
151
73
  if (typeof raw !== "string") {
152
74
  throw new UsageError("--filter must be a JSON object.");
@@ -201,5 +123,5 @@ export function parseSharedReportBody(opts, operation) {
201
123
  if (!result.success) {
202
124
  throw sharedReportValidationError(result.error, operation, opts.type);
203
125
  }
204
- return toSharedReportBody(result.data);
126
+ return defined(result.data);
205
127
  }
@@ -1,3 +1,4 @@
1
+ import { SHARED_REPORT_TYPES } from "clockify-sdk-ts-115/requests";
1
2
  import { UsageError } from "../failure.js";
2
3
  import { printObject, printRecords } from "../output.js";
3
4
  import { printReceipt } from "../receipt.js";
@@ -20,27 +21,6 @@ async function readReportBody(response) {
20
21
  return { body: text };
21
22
  }
22
23
  }
23
- export const SHARED_REPORT_TYPES = [
24
- "SUMMARY",
25
- "DETAILED",
26
- "WEEKLY",
27
- "EXPENSE_DETAILED",
28
- "INVOICE_TIME",
29
- "KIOSK_PIN_LIST",
30
- "ATTENDANCE_DETAILED",
31
- "ATTENDANCE_SUMMARY",
32
- "ASSIGNMENT_LIST",
33
- "ASSIGNMENT_SCHEDULE",
34
- "APPROVAL_DETAILED",
35
- "APPROVAL_SUMMARY",
36
- "BALANCE_LIST",
37
- "INVOICE_AMOUNT_LIST",
38
- "INVOICE_DETAILED",
39
- "TIMEOFF_DETAILED",
40
- "TIMEOFF_HOLIDAY",
41
- "TIMEOFF_BALANCE",
42
- "EXPENSE_SUMMARY",
43
- ];
44
24
  export const SHARED_REPORT_FILTER_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
45
25
  const SHARED_REPORT_VIEW_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV"];
46
26
  export const SUMMARY_GROUPS = [
@@ -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
+ };