Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 76 additions & 63 deletions .claude/skills/timesheet/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,119 @@
name: timesheet
description: Use when someone asks for their monthly hours, a timesheet, a work
report for a month, "таблица часов", "отчёт за месяц", "табель", or a
Jira/git activity table to import into Google Sheets.
table of tracked time and git activity to import into Google Sheets.
---

# timesheet

Builds one person's month as a table — date, day, ticket, link, description,
hours — from Jira and the git clones, as a CSV that Google Sheets imports.
Builds one person's month as a table — date, day, task, link, description,
hours — from solidtime, Plane and the git clones, as a CSV that Google Sheets
imports.

Two scripts do the mechanical part. Deciding the hours and wording each row is
yours: Jira holds no worklogs, so every number is an estimate from evidence.
Two scripts do the mechanical part. The hours are the ones solidtime tracked;
wording each row is yours.

Hours exist in solidtime from 2026-11-30. Earlier months were estimated from
Jira, which this skill no longer reads, so they cannot be rebuilt here.

The delivery cycle in `CLAUDE.md` is for changes to the repo. This report makes
none, so it takes no Jira ticket, no branch and no commit.
none, so it takes no task, no branch, no commit and no time entry.

## 1 · Collect

```bash
node .claude/skills/timesheet/scripts/collect.mjs --month 2026-09
node .claude/skills/timesheet/scripts/collect.mjs --month 2026-12
```

Without `--month` it takes the current month from the 15th on, the previous
one before that. It scans this clone plus the `runtime` and `bridle` clones
beside it (`--repos a,b` to override, `--out file.json` to choose where the
data lands).
data lands). It reads `TIME_API_KEY` and `TASKS_API_KEY` from `.env.project`
and only reads: nothing is written to solidtime or Plane.

It prints a short header and two paths. Read the `digest` file in full: it is
the month day by day, each ticket with its Jira events and commits. `data` is
the same as JSON.
the month day by day, each task with its time entries, its Plane events and
its commits. `data` is the same as JSON.

Everything in the digest is the person's own: time they tracked, commits they
authored, tasks they created, status changes and comments they made. Work
before 05:00 is already filed under the evening before and marked `+1d`; a
time entry belongs, whole, to the working day it started on.

Everything in the digest is the person's own: commits they authored, tickets
they created, status changes and comments they made. Work before 05:00 is
already filed under the evening before and marked `+1d`.
A time entry counts for ranch when its description, or its solidtime task,
names a `RANCH-<n>` id, or when it sits in a solidtime project called ranch.
The rest of the person's entries (other projects, no id) stay out, and the
header counts them.

## 2 · Read the identity line first

The first line of the header says whose month this is.
The first line of the header says whose month this is. It is always the owner
of the two keys in `.env.project`: solidtime answers with nobody else's time.

| First line | What to do |
|---|---|
| `identity: … (verified)` | `git config user.email` was found in Jira. Carry on. |
| `WARNING identity: …` | The git address is unset or unknown to Jira, and the data is the **default person's**. Build the table all the same, and open your reply with the warning, naming both addresses, before anything else. |
| `identity: … (verified)` | `git config user.email` is the key owner's address. Carry on. |
| `WARNING identity: …` | The git address is unset or is somebody else's, and the data is the **key owner's**. Build the table all the same, and open your reply with the warning, naming both addresses, before anything else. |
| `timesheet: …` and exit 1 | Nothing was collected. Report the message and stop. |

The person is never chosen by name, by guess, or from the conversation. To
report for someone else, that person runs it from their own clone.
report for someone else, that person runs it from their own clone, with their
own keys.

## 3 · Turn evidence into rows
## 3 · Turn the digest into rows

One row per ticket per day. Take the first line of this table that fits:
One row per task per day. Take the first line of this table that fits:

| The ticket that day | Row |
| The task that day | Row |
|---|---|
| is `absent in Jira` | no |
| is marked `assignee: …` (someone else, or nobody) and has no commit | no |
| has a commit | yes |
| has a comment | yes |
| was `created`, and is a `subtask of` a ticket with a row that day | no, it is part of the parent's row |
| was `created` | yes, 1 hour, as the write-up of the task |
| only changed status | no |

`(no ticket)` commits join a ticket when the subject names the same feature as
that ticket's title or its other commits; they count as that ticket's commits,
and may give it a row on a day it has nothing else. The rest stay out. List
both kinds under assumptions.
| has `tracked H:MM -> N` | yes, with `N` hours |
| is `(no task)` with tracked time | joins a task when the entry's description names the same work as that task's title or commits; otherwise no |
| shows `no time tracked` | no |

`(no task)` commits join a task when the subject names the same feature as
that task's title or its other commits; they help word its row and never add
hours.

**Hours**

- Whole numbers, 1 at the least.
- Each row is weighed on its own evidence: the number of commits, the span
between the first and last event, spec/plan/tasks commits, a release bump.
A ticket opened and sent to testing within minutes on one commit is 1. A
ticket with a spec and a dozen commits is 3 or more. A lone `(#NN)` merge
days after the work is 1: review and merge.
- Tickets worked side by side in the same hour share that hour. Commits that
carry one timestamp were rebased together; count them, ignore their span.
- A commit naming two tickets counts for both, and its weight is shared, not
doubled.
- A day is the sum of its rows. A full weekday usually comes to 6–8; that is
what to expect, not a number to reach.
- Above 10 hours `build-csv.mjs` names the day. Take hours off its largest
rows, unless the 1-hour minimums alone make the day that long.
- The number after the arrow, as it is: tracked time to the nearest quarter of
an hour, a quarter at the least. Never estimate, never round up to a whole
hour, never move time to another task or day.
- `(running)` means the entry had no end yet and was counted up to the moment
of the run. Say so.
- `days with work that has no time tracked` — those tasks get no row. List the
days and their tasks, and ask. Hours the person then names for them go in as
rows and under assumptions, as their word.
- `days where entries overlap` — two entries ran at once, so the day's rows add
up to more than the clock. Rows keep each task's own time; name the day with
both numbers.
- Above 10 hours `build-csv.mjs` names the day. Look for an overlap or a timer
left running and report what you find. Do not trim it yourself.
- A `CLEAN-<n>` id is from Jira, the tracker before Plane. Tracked time under
one still gets its row, without a link and worded from its commits.

**Days**

- `weekdays still ahead` — leave them out and say so.
- `today` — today gets what it shows so far. Say the day was not over.
- `weekdays without any activity` — leave them out, list them, and ask what
was done on them.
- When the person has said they worked every weekday in full, and only then:
a weekday under 6 is raised to 6 on its largest row, and a weekday without
activity gets the nearest large ticket at 6. List every such day under
assumptions.
- `weekdays without any activity` — leave them out and list them.
- A weekend day gets what it shows.
- `solidtime holds hours from …` — the days before that date have no rows.
Say so, with the date.

**Descriptions** — Russian, one line, up to about 100 characters, no full stop.
Say what landed that day, from the commit subjects. When a ticket spans
several days, each day names its own part. A row without commits is worded
from the ticket title: `Постановка: …` when the ticket was created that day,
Say what landed that day, from the commit subjects. When a task spans several
days, each day names its own part. A row without commits is worded from the
task title: `Постановка: …` when the task was created that day,
`Проверка и обсуждение: …` otherwise.

## 4 · Build the CSV

Write the rows to a file in the scratchpad or temp directory:

```json
{ "month": "2026-09", "rows": [
{ "date": "2026-09-01", "key": "CLEAN-55", "text": "Статус «unreachable», когда рантайм не подключён к хабу", "hours": 2 }
{ "month": "2026-12", "rows": [
{ "date": "2026-12-01", "key": "RANCH-4", "text": "Табель читает часы из solidtime и задачи из Plane", "hours": 1.25 }
] }
```

Expand All @@ -122,20 +128,27 @@ Exit 1 lists rows to fix; fix them and run it again. A `days above 10h` line
comes with exit 0 and a written file: see Hours. Do not write the CSV by hand.
`рабочих дней` in the last row counts every day worked, weekends too.

Hours are written with a decimal comma (`1,25`), which a sheet with a Russian
or Ukrainian locale reads as a number. For a sheet with an English locale add
`--decimal dot`.

## 5 · Report

In the language the person wrote in, in this order:

1. Whose month it is: the Jira name and the address. With the identity
warning, if there was one, in front of it.
1. Whose month it is: the name and the address. With the identity warning, if
there was one, in front of it.
2. The path of the CSV, the number of rows and days, the total hours.
3. Hours per day.
4. Assumptions: days filled on the person's word, commits without a ticket,
tickets of other people, weekend rows, days left out, today if unfinished.
5. That the hours are estimates, to be looked over before the table is sent.
4. What is not in the table: days and tasks with work and no time tracked,
entries that name no task, entries of other projects, days before solidtime
held hours, days left out.
5. Assumptions: hours taken on the person's word, overlapping entries, an entry
still running, today if unfinished, weekend rows.

## Never

- Print or paste values from `.env.project`.
- Invent a ticket, a day or a commit the digest does not show.
- Invent a task, a day, a commit or an hour the digest does not show.
- Write to solidtime or Plane: this skill only reads.
- Leave the CSV inside the repo.
27 changes: 17 additions & 10 deletions .claude/skills/timesheet/scripts/build-csv.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
// Turns the agreed rows into the CSV that Google Sheets imports.
//
// node .claude/skills/timesheet/scripts/build-csv.mjs --rows rows.json [--out file.csv]
// node .claude/skills/timesheet/scripts/build-csv.mjs --rows rows.json [--out file.csv] [--decimal dot]
//
// rows.json: { "month": "2026-09", "rows": [{ "date": "2026-09-01", "key": "CLEAN-55", "text": "…", "hours": 2 }] }
// rows.json: { "month": "2026-12", "rows": [{ "date": "2026-12-01", "key": "RANCH-4", "text": "…", "hours": 1.25 }] }
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { homedir, tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { DAY_NAMES, jiraBase, loadEnv, monthBounds, parseArgs, repoRoot } from './env.mjs';
import { DAY_NAMES, QUARTER, monthBounds, parseArgs, taskUrl } from './env.mjs';

const HEADER = ['Дата', 'День', 'Задача', 'Ссылка', 'Описание', 'Часы'];
const LONG_DAY_HOURS = 10;

const args = parseArgs(process.argv.slice(2));
if (typeof args.rows !== 'string') throw new Error('--rows <file.json> is required.');
const decimal = args.decimal ?? 'comma';
if (decimal !== 'comma' && decimal !== 'dot') throw new Error(`--decimal expects comma or dot, got "${decimal}".`);

const { month, rows } = JSON.parse(readFileSync(resolve(args.rows), 'utf8'));
monthBounds(month);
if (!Array.isArray(rows) || rows.length === 0) throw new Error('rows.json has no rows.');

const base = jiraBase(loadEnv(repoRoot()));
const problems = [];
rows.forEach((row, index) => {
const where = `row ${index + 1} (${row.date} ${row.key})`;
if (!/^\d{4}-\d{2}-\d{2}$/.test(row.date ?? '') || !row.date.startsWith(`${month}-`)) {
problems.push(`${where}: date is outside ${month}`);
}
if (!/^[A-Z][A-Z0-9]+-\d+$/.test(row.key ?? '')) problems.push(`${where}: key is not a ticket id`);
if (!Number.isInteger(row.hours) || row.hours < 1) problems.push(`${where}: hours must be a whole number, 1 or more`);
if (!/^[A-Z][A-Z0-9]+-\d+$/.test(row.key ?? '')) problems.push(`${where}: key is not a task id`);
if (typeof row.hours !== 'number' || row.hours < QUARTER || !Number.isInteger(row.hours / QUARTER)) {
problems.push(`${where}: hours must be a number of quarter hours, ${QUARTER} or more`);
}
if (typeof row.text !== 'string' || !row.text.trim()) problems.push(`${where}: description is empty`);
});
const pairs = rows.map((row) => `${row.date} ${row.key}`);
for (const pair of new Set(pairs.filter((value, index) => pairs.indexOf(value) !== index))) {
problems.push(`${pair}: the same ticket appears twice on one day, merge the rows`);
problems.push(`${pair}: the same task appears twice on one day, merge the rows`);
}
if (problems.length) {
console.error(problems.join('\n'));
Expand All @@ -47,16 +50,20 @@ const cell = (value) => {
return /[",\r\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
};

// A sheet in a Russian or Ukrainian locale reads "1.5" as the first of May, and one in an
// English locale reads "1,5" as text. The headers are Russian, so comma is the default.
const hoursCell = (hours) => (decimal === 'comma' ? String(hours).replace('.', ',') : String(hours));

const perDay = new Map();
const lines = [HEADER];
for (const row of sorted) {
const [year, monthNumber, day] = row.date.split('-');
const name = DAY_NAMES[new Date(`${row.date}T12:00:00`).getDay()];
lines.push([`${day}.${monthNumber}.${year}`, name, row.key, `${base}/browse/${row.key}`, row.text.trim(), row.hours]);
lines.push([`${day}.${monthNumber}.${year}`, name, row.key, taskUrl(row.key), row.text.trim(), hoursCell(row.hours)]);
perDay.set(row.date, (perDay.get(row.date) ?? 0) + row.hours);
}
const total = [...perDay.values()].reduce((sum, hours) => sum + hours, 0);
lines.push(['ИТОГО', '', '', '', `${perDay.size} рабочих дней`, total]);
lines.push(['ИТОГО', '', '', '', `${perDay.size} рабочих дней`, hoursCell(total)]);

const downloads = join(homedir(), 'Downloads');
const folder = existsSync(downloads) ? downloads : tmpdir();
Expand All @@ -67,4 +74,4 @@ console.log(`csv ${out}`);
console.log(`rows ${rows.length} · days ${perDay.size} · hours ${total}`);
console.log([...perDay].map(([date, hours]) => `${date.slice(8)}:${hours}`).join(' '));
const long = [...perDay].filter(([, hours]) => hours > LONG_DAY_HOURS).map(([date, hours]) => `${date} (${hours}h)`);
if (long.length) console.log(`days above ${LONG_DAY_HOURS}h, bring them down: ${long.join(', ')}`);
if (long.length) console.log(`days above ${LONG_DAY_HOURS}h, check them for overlap: ${long.join(', ')}`);
Loading
Loading