@helm-ai/cli 0.28.0 → 0.29.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/dist/cli.js +164 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -25,7 +25,7 @@ function renderSplash(ctx) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// src/version.ts
|
|
28
|
-
var version = "0.
|
|
28
|
+
var version = "0.29.0";
|
|
29
29
|
|
|
30
30
|
// src/commands/auth.ts
|
|
31
31
|
import prompts from "prompts";
|
|
@@ -367,7 +367,17 @@ var HelmClient = class _HelmClient {
|
|
|
367
367
|
balance: async (filters = {}) => {
|
|
368
368
|
const data = await this.request("get_hour_balance", "GET", filters);
|
|
369
369
|
return { plans: data.plans ?? [], message: data.message };
|
|
370
|
-
}
|
|
370
|
+
},
|
|
371
|
+
/** The time that used a plan's hours: the current period, or a closed one by its start date. */
|
|
372
|
+
activity: async (filters) => this.request("list_hour_activity", "GET", filters),
|
|
373
|
+
/** A closed period's statement, as it was at close. */
|
|
374
|
+
statement: async (filters) => this.request("get_hour_statement", "GET", filters),
|
|
375
|
+
/** Add-on hours, or an adjustment (needs a note). */
|
|
376
|
+
add: async (input) => this.request("add_hour_block", "POST", input),
|
|
377
|
+
/** Without confirm, reports what voiding would do; with it, voids. */
|
|
378
|
+
void: async (blockId, confirm) => this.request("void_hour_block", "POST", { block_id: blockId, confirm }),
|
|
379
|
+
createPlan: async (input) => this.request("create_hour_plan", "POST", input),
|
|
380
|
+
updatePlan: async (input) => this.request("update_hour_plan", "POST", input)
|
|
371
381
|
};
|
|
372
382
|
timeEntries = {
|
|
373
383
|
list: async (filters = {}) => {
|
|
@@ -2230,6 +2240,7 @@ function registerTimeCommands(parent) {
|
|
|
2230
2240
|
}
|
|
2231
2241
|
|
|
2232
2242
|
// src/commands/hours.ts
|
|
2243
|
+
import prompts4 from "prompts";
|
|
2233
2244
|
var TYPE_LABELS = {
|
|
2234
2245
|
monthly: "Monthly",
|
|
2235
2246
|
quarterly: "Quarterly",
|
|
@@ -2267,6 +2278,157 @@ function registerHoursCommands(parent) {
|
|
|
2267
2278
|
process.exitCode = 1;
|
|
2268
2279
|
}
|
|
2269
2280
|
});
|
|
2281
|
+
cmd.command("activity").description("The time that used a plan's hours (the current period by default)").option("--plan <id>", "the plan").option("--project <id>", "the plan this project draws from, narrowed to it").option("--all-projects", "with --project, every project on the plan").option("--period <date>", "start date of a closed period (YYYY-MM-DD)").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2282
|
+
try {
|
|
2283
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2284
|
+
const data = await client.hours.activity({
|
|
2285
|
+
plan_id: opts.plan,
|
|
2286
|
+
project_id: opts.project,
|
|
2287
|
+
all_projects: opts.allProjects ? true : void 0,
|
|
2288
|
+
period_start: opts.period
|
|
2289
|
+
});
|
|
2290
|
+
const format = opts.output ?? defaultFormat();
|
|
2291
|
+
if (format !== "table") {
|
|
2292
|
+
console.log(render(data.entries, [
|
|
2293
|
+
{ header: "Date", get: (e) => e.date },
|
|
2294
|
+
{ header: "Project", get: (e) => e.project.name },
|
|
2295
|
+
{ header: "Task", get: (e) => e.task?.title ?? "" },
|
|
2296
|
+
{ header: "Description", get: (e) => e.description ?? "" },
|
|
2297
|
+
{ header: "Hours", get: (e) => String(e.hours_counted) },
|
|
2298
|
+
{ header: "Drew from", get: (e) => e.drew_from.map((d) => `${d.kind} ${d.hours}h`).join(", ") }
|
|
2299
|
+
], format));
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
console.log(`${data.plan} \xB7 ${data.period} \xB7 ${data.total_hours_counted}h counted`);
|
|
2303
|
+
if (data.entries.length === 0) {
|
|
2304
|
+
console.log("No time has used these hours yet.");
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
console.log(render(data.entries, [
|
|
2308
|
+
{ header: "Date", get: (e) => e.date },
|
|
2309
|
+
{ header: "Project", get: (e) => e.project.name, truncate: 24 },
|
|
2310
|
+
{ header: "Work", get: (e) => e.task?.title ?? e.description ?? "", truncate: 40 },
|
|
2311
|
+
{ header: "Hours", get: (e) => `${e.hours_counted}h` },
|
|
2312
|
+
{ header: "Drew from", get: (e) => e.drew_from.map((d) => `${d.kind} ${d.hours}h`).join(", ") }
|
|
2313
|
+
], format));
|
|
2314
|
+
} catch (err) {
|
|
2315
|
+
console.error(formatErrorForCli(err));
|
|
2316
|
+
process.exitCode = 1;
|
|
2317
|
+
}
|
|
2318
|
+
});
|
|
2319
|
+
cmd.command("statement").description("A closed period's hours statement (the most recent by default)").option("--plan <id>", "the plan").option("--project <id>", "the plan this project draws from").option("--period <date>", "start date of the closed period (YYYY-MM-DD)").option("-p, --profile <name>").action(async (opts) => {
|
|
2320
|
+
try {
|
|
2321
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2322
|
+
const data = await client.hours.statement({ plan_id: opts.plan, project_id: opts.project, period_start: opts.period });
|
|
2323
|
+
console.log(JSON.stringify(data, null, 2));
|
|
2324
|
+
} catch (err) {
|
|
2325
|
+
console.error(formatErrorForCli(err));
|
|
2326
|
+
process.exitCode = 1;
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2329
|
+
cmd.command("add").description("Add hours to a plan: an add-on the client bought, or an adjustment (needs --note)").requiredOption("--hours <n>", "hours, in quarter-hour steps (negative only for an adjustment)").option("--plan <id>", "the plan").option("--project <id>", "the plan this project draws from").option("--adjustment", "an adjustment rather than an add-on").option("--from <date>", "YYYY-MM-DD the hours count from (default today)").option("--note <text>", "why, for the team; never shown to the client").option("--invoice <id>", "the invoice these hours were bought on").option("-p, --profile <name>").action(async (opts) => {
|
|
2330
|
+
try {
|
|
2331
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2332
|
+
const data = await client.hours.add({
|
|
2333
|
+
plan_id: opts.plan,
|
|
2334
|
+
project_id: opts.project,
|
|
2335
|
+
hours: Number(opts.hours),
|
|
2336
|
+
kind: opts.adjustment ? "adjustment" : "add_on",
|
|
2337
|
+
valid_from: opts.from,
|
|
2338
|
+
note: opts.note,
|
|
2339
|
+
invoice_id: opts.invoice
|
|
2340
|
+
});
|
|
2341
|
+
console.log(`\u2713 ${data.hours > 0 ? "Added" : "Took away"} ${Math.abs(data.hours)}h ${data.hours > 0 ? "to" : "from"} ${data.plan} (${data.block_id})`);
|
|
2342
|
+
} catch (err) {
|
|
2343
|
+
console.error(formatErrorForCli(err));
|
|
2344
|
+
process.exitCode = 1;
|
|
2345
|
+
}
|
|
2346
|
+
});
|
|
2347
|
+
cmd.command("void <blockId>").description("Void a block of hours (block ids are in `hours balance -o json`)").option("-y, --yes", "skip confirmation").option("-p, --profile <name>").action(async (blockId, opts) => {
|
|
2348
|
+
try {
|
|
2349
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2350
|
+
const check = await client.hours.void(blockId, false);
|
|
2351
|
+
if (!opts.yes) {
|
|
2352
|
+
if (!process.stdin.isTTY) {
|
|
2353
|
+
console.error(`${check.impact}
|
|
2354
|
+
Refusing to void without confirmation in a non-interactive shell. Re-run with -y/--yes.`);
|
|
2355
|
+
process.exitCode = 1;
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
const { confirmed } = await prompts4({
|
|
2359
|
+
type: "confirm",
|
|
2360
|
+
name: "confirmed",
|
|
2361
|
+
message: `${check.impact} Void these hours?`,
|
|
2362
|
+
initial: false
|
|
2363
|
+
});
|
|
2364
|
+
if (!confirmed) {
|
|
2365
|
+
console.log("Aborted.");
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
await client.hours.void(blockId, true);
|
|
2370
|
+
console.log(`\u2713 Voided ${blockId}`);
|
|
2371
|
+
} catch (err) {
|
|
2372
|
+
console.error(formatErrorForCli(err));
|
|
2373
|
+
process.exitCode = 1;
|
|
2374
|
+
}
|
|
2375
|
+
});
|
|
2376
|
+
const plan = cmd.command("plan").description("Set up and change hour plans");
|
|
2377
|
+
const num = (v) => v === void 0 ? void 0 : Number(v);
|
|
2378
|
+
const settings = (opts) => ({
|
|
2379
|
+
hours_per_period: num(opts.hours),
|
|
2380
|
+
reset_day: num(opts.resetDay),
|
|
2381
|
+
rollover: opts.rollover,
|
|
2382
|
+
rollover_cap_hours: num(opts.rolloverCap),
|
|
2383
|
+
round_increment_minutes: num(opts.round),
|
|
2384
|
+
round_mode: opts.roundMode,
|
|
2385
|
+
minimum_entry_minutes: num(opts.minimum),
|
|
2386
|
+
low_balance_alert_pct: num(opts.lowAlert),
|
|
2387
|
+
extra_hours: opts.extraHours,
|
|
2388
|
+
extra_hours_rate: num(opts.extraRate),
|
|
2389
|
+
draft_invoice_each_period: opts.draftInvoice === void 0 ? void 0 : opts.draftInvoice !== "off",
|
|
2390
|
+
period_price: num(opts.price),
|
|
2391
|
+
period_product_id: opts.product
|
|
2392
|
+
});
|
|
2393
|
+
const withSettings = (c) => c.option("--hours <n>", "hours each month or quarter").option("--reset-day <n>", "day of the month the hours reset, 1 to 28").option("--rollover <policy>", "none | capped | unlimited").option("--rollover-cap <hours>", "with --rollover capped, the most hours that roll over").option("--round <minutes>", "round each entry: 6, 10, 15 or 30").option("--round-mode <mode>", "up | nearest").option("--minimum <minutes>", "each entry counts for at least this many minutes").option("--low-alert <pct>", "alert when this percent is left").option("--extra-hours <policy>", "track | review | bill").option("--extra-rate <rate>", "hourly rate for billed extra hours").option("--draft-invoice <on|off>", "draft an invoice for each period's hours").option("--price <amount>", "price of each period's hours, for the draft invoice").option("--product <id>", "product for the draft invoice line");
|
|
2394
|
+
withSettings(plan.command("create").description("Set up an hour plan for a client").requiredOption("--account <id>", "the client").requiredOption("--name <name>", 'e.g. "Dev & Maintenance retainer"').requiredOption("--type <type>", "monthly | quarterly | hours_as_needed").requiredOption("--projects <ids>", "comma-separated projects whose time uses these hours").option("--starts <date>", "YYYY-MM-DD (default today)").option("--timezone <tz>", "IANA time zone the plan keeps dates in").option("--starting-hours <n>", "hours the client already has (required for hours_as_needed)")).option("-p, --profile <name>").action(async (opts) => {
|
|
2395
|
+
try {
|
|
2396
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2397
|
+
const data = await client.hours.createPlan({
|
|
2398
|
+
account_id: opts.account,
|
|
2399
|
+
name: opts.name,
|
|
2400
|
+
type: opts.type,
|
|
2401
|
+
project_ids: String(opts.projects).split(",").map((s) => s.trim()).filter(Boolean),
|
|
2402
|
+
starts_on: opts.starts,
|
|
2403
|
+
timezone: opts.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
2404
|
+
starting_hours: num(opts.startingHours),
|
|
2405
|
+
...settings(opts)
|
|
2406
|
+
});
|
|
2407
|
+
console.log(`\u2713 ${data.message} (${data.plan_id})`);
|
|
2408
|
+
} catch (err) {
|
|
2409
|
+
console.error(formatErrorForCli(err));
|
|
2410
|
+
process.exitCode = 1;
|
|
2411
|
+
}
|
|
2412
|
+
});
|
|
2413
|
+
withSettings(plan.command("update <planId>").description("Change a plan's settings, pause or end it, or change its projects").option("--name <name>").option("--status <status>", "active | paused | ended").option("--ends <date>", "YYYY-MM-DD the plan ends after").option("--add-projects <ids>", "comma-separated projects to add").option("--remove-projects <ids>", "comma-separated projects to remove")).option("-p, --profile <name>").action(async (planId, opts) => {
|
|
2414
|
+
try {
|
|
2415
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2416
|
+
const list = (v) => v ? v.split(",").map((s) => s.trim()).filter(Boolean) : void 0;
|
|
2417
|
+
const data = await client.hours.updatePlan({
|
|
2418
|
+
plan_id: planId,
|
|
2419
|
+
name: opts.name,
|
|
2420
|
+
status: opts.status,
|
|
2421
|
+
ends_on: opts.ends,
|
|
2422
|
+
add_project_ids: list(opts.addProjects),
|
|
2423
|
+
remove_project_ids: list(opts.removeProjects),
|
|
2424
|
+
...settings(opts)
|
|
2425
|
+
});
|
|
2426
|
+
console.log(`\u2713 ${data.message}`);
|
|
2427
|
+
} catch (err) {
|
|
2428
|
+
console.error(formatErrorForCli(err));
|
|
2429
|
+
process.exitCode = 1;
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2270
2432
|
}
|
|
2271
2433
|
|
|
2272
2434
|
// src/lib/line-items.ts
|