ptimelog 0.10.0 → 0.13.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a7ad17dbf09bc8d7694f9261ffcc8216af2f1ec04be03e62ccabadf9732e8b0
4
- data.tar.gz: 4ee34a775b9300e50971421adedee472fbfa5f5c0ec226b93e299d17474df411
3
+ metadata.gz: 0c9d0fcc6e0b89b70b4be7765118af54a493aa561dc6336fb03e070999dbdf95
4
+ data.tar.gz: 3306a2c87d164e509cbc102d7173fb7480d00165a2c8fd56c0c5b1d05e0e4715
5
5
  SHA512:
6
- metadata.gz: 198b9c6aefbab6f64b617a6b2ad125f9e9921c829e1740ca08faa41c69c797fda1cca1181665adec6b68b51560b3a5bed88ad3b23a8bceba6382dd4b222bb129
7
- data.tar.gz: d37ed829daa68c7527caafe929874c6523986609661f9a9155463f0307ac2fb9d14d3237878d6c6659f799ca59c9536e8cae46770f21cdb13916753277beaf2c
6
+ metadata.gz: 5017e8bd76814d2119faf4a9bd77924d034f7cacfd7496e92a6d8a6d882e124f079ba47cf5319579a252c5c9505ab329c93a97b543d2593c437311e166540429
7
+ data.tar.gz: 44c779a4aeafce366b344231591a0c53bc9101e76116e25866656ffc8c31b0d936b2a545db0ff6b7a11f5c53d757e3c7779880bbaad9e9c69b97a91d5d47605a
data/AGENTS.md ADDED
@@ -0,0 +1,43 @@
1
+ ## Technical
2
+
3
+ - written in Ruby
4
+ - Tests with RSpec, execute `rspec` to run them
5
+ - Code-Style is checked with RuboCop, run `rubocop` to check
6
+ - the default rake-task (`rake`) runs both rspec and rubocop in an row
7
+
8
+ ## Ideas
9
+
10
+ The project is a CLI that collects time-tracking information into entries and allows to show them.
11
+ The data-backend is either the data of gtimelog or of a dialy note in Obsidian.md
12
+
13
+ ### gtimelog
14
+
15
+ gtimelog is a GTK GUI app, that uses a single file to store when a task has ended.
16
+
17
+ This allows to infer the duration of tasks by reading mulitple lines.
18
+
19
+ ### Obsidian.md
20
+
21
+ Obsidian.md (mostly called obsidian) is a note-taking application allows to have daily notes in markdown-format.
22
+
23
+ The plugin 'dayplanner' adds a special section to daily notes that are time-tracking entries. They are grouped under a headline and formatted like this
24
+
25
+ ```markdown
26
+ - 10:00 - 11:00 Task 17: Hard work, Analysis, Feedback -- work client mail
27
+ ```
28
+
29
+ This describes a time-entry from 10:00 to 11:00 o'clock. The entry's ticket is "Task 17" and its description is "Hard work, Analysis, Feedback". The entry is tagged with "work", "client" and "mail"
30
+
31
+ ## Development-Workflow
32
+
33
+ - Always write a spec first
34
+ - The spec should define the desired state
35
+ - The spec should be failing at first
36
+ - Then add the implementation
37
+ - The spec should now be successful
38
+ - The whole spec-suite should also still be without errors
39
+ - run `rspec` to ensure that
40
+ - if any spec fails, fix the new implementation until all specs pass
41
+ - Lastly, run `rubocop` to ensure the code-style is good.
42
+ - verify completeness by running `rake` (runs `rubocop` and `rspec` together).
43
+ - Propose a commit-message, summarizing the need for the change
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # pTimeLog
2
2
 
3
- small tooling to transfer timelog-entries from gtimelog's timelog.txt to the PuzzleTime Timetracking Website.
4
-
5
- [![Build Status](https://travis-ci.org/kronn/ptimelog.svg?branch=master)](https://travis-ci.org/kronn/ptimelog)
3
+ small tooling to transfer timelog-entries from gtimelog's timelog.txt or the tasks of an Obsidian vault to the PuzzleTime time-tracking web-application.
6
4
 
7
5
  ## Approach
8
6
 
@@ -20,6 +18,7 @@ small tooling to transfer timelog-entries from gtimelog's timelog.txt to the Puz
20
18
  - [x] support user-supplied ticket-parsers
21
19
  - [x] get ticket-parser from tags
22
20
  - [x] merge equal adjacent entries into one
21
+ - [x] caculate, show and upload durations
23
22
  - [ ] complete login/entry automation
24
23
  - [ ] handle authentication
25
24
  - [ ] login and store cookie (https://stackoverflow.com/questions/12399087/curl-to-access-a-page-that-requires-a-login-from-a-different-page#12399176)
@@ -29,7 +28,7 @@ small tooling to transfer timelog-entries from gtimelog's timelog.txt to the Puz
29
28
  - [x] avoid duplicate entries
30
29
  - [x] start/end time as indicator?
31
30
  - [x] offer rounding times to the next 5, 10 or 15 minutes
32
- - [x] allow to add entries from the command-line
31
+ - [-] allow to add entries from the command-line (removed in 0.13.0)
33
32
  - [ ] handle time-account and billable better
34
33
  - [ ] import time-accounts from ptime (https://time.puzzle.ch/work_items/search.json?q=search%20terms)
35
34
  - [ ] with a dedicated cli?
@@ -40,8 +39,17 @@ small tooling to transfer timelog-entries from gtimelog's timelog.txt to the Puz
40
39
  - [ ] allow to have a list of "favourite" time-accounts
41
40
  - [ ] select best-matching time-account according to tags, possibly limited to the favourites
42
41
  - [x] combine billable and account-lookup into one script
43
- - [ ] add cli-help
44
- - [ ] use commander for CLI?
42
+ - [x] add cli-help
43
+ - [x] use ~~commander~~ _cmd_parse_ for CLI
44
+ - [x] support Obsidian as datasource
45
+ - [x] with explicit config
46
+ - [x] with reading the config from the Obsidian Vault
47
+ - [x] time-entries from the sessions Operon tracked on its tasks
48
+ - [ ] time-account/billable/metadata lookup from a note
49
+ - [x] support show-command: output the entries of a day
50
+ - [x] support upload-command: send the entries of a day to ptime
51
+ - [ ] support "last"-day for obsidian
52
+ - [x] filter the entries by tag
45
53
 
46
54
  ## Installation
47
55
 
@@ -53,29 +61,94 @@ Install it with:
53
61
 
54
62
  $ ptimelog ACTION DATE
55
63
 
64
+ Maybe it's best to explore the commands with `ptimelog help` and going from
65
+ there.
66
+
56
67
  ### Actions
57
68
 
58
69
  Currently supported actions are
59
70
 
60
71
  - show
72
+ - summarize
61
73
  - upload
74
+ - confirm
62
75
  - edit
63
- - add
64
76
  - version
77
+ - help
78
+ - info
65
79
 
66
80
  ### Date-Identifier
67
81
 
68
82
  To handle a specific date, the format YYYY-MM-DD is expected, e.g. 2017-12-25.
69
- Please note that you should not work on that day, unless you bring presents.
83
+ Please note that you should not work on that day, unless you bring presents or
84
+ release a new version of Ruby.
70
85
 
71
86
  For reusability in a shell-history the following keywords are supported:
72
87
 
73
88
  - today
74
89
  - yesterday
75
- - last
76
90
  - all
91
+ - a weekday, full or shortened: monday, mon, tue, ...
92
+
93
+ Currently, you need to pass a day. The previously exisiting "last" worked fine
94
+ to timelog.txt, but not for Obsidian.
95
+
96
+ #### Whole months
97
+
98
+ A month-name selects every day of that month, `month` the current one:
99
+
100
+ $ ptimelog show october
101
+ $ ptimelog show oct
102
+ $ ptimelog show month
103
+
104
+ Like a weekday, a month looks backwards: in November 2026, `december` is the
105
+ one of 2025. The current month counts, unfinished as it is. If you want the
106
+ current month, the keyword "month" is there. This nicely highlight that at
107
+ least germanic languages do not have the monthly equivalent of today. "tomonth"
108
+ would have a candidate, but... yeah, fixing that is outside of the scope of
109
+ this project (for now, at least).
110
+
111
+ The output stays grouped by day, and so does `-d`, which also summarizes per
112
+ ticket within a day, not across the month. `upload october` opens a browser-tab
113
+ per entry of the whole month; `confirm october` asks per day and is therefore
114
+ both more annoying and potentially gentler on your RAM. I know, boring...
115
+
116
+ :warn: Only the Obsidian-Datasource supports this. The timelog.txt-Datasource
117
+ refuses with an error instead of silently showing every day it knows. Use "all"
118
+ for now.
119
+
120
+ ### Summarizing a range
77
121
 
78
- If nothing is specified, the action is applied to entries of the last day.
122
+ `show` answers "what did I do, and when". For reporting and invoicing, the
123
+ question is "how much time went into what", and a day is no useful group for
124
+ that. That is what `summarize` is for:
125
+
126
+ $ ptimelog summarize october
127
+ October 2026
128
+ ----------
129
+ 03:00 | HIT-4711: Release | hit client
130
+ 02:00 | HIT-2342: Zeug machen | hit client topic
131
+ 01:00 | Rechnung prüfen
132
+ ----------
133
+ Total work done: 06:00 hours
134
+ ----------------------------
135
+
136
+ There is one title, which is the requested range spelled out, and one total to
137
+ cross-check against. No times of day are listed, they say nothing about an
138
+ amount of work. Durations are implied, so there is no `-d`; `-t` filters as
139
+ everywhere else.
140
+
141
+ Two entries are merged when their ticket **and** their tags are the same, no
142
+ matter which day they were tracked on. The tags decide the time-account, so
143
+ entries which differ in them have to stay apart. An entry without a ticket
144
+ carries nothing to merge it by and therefore stays on its own — if you want it
145
+ joined, add the metadata to the task.
146
+
147
+ This also means `summarize` can split lines differently than `show -d`, which
148
+ merges an untagged entry into a tagged one of the same ticket. `show` is
149
+ unchanged.
150
+
151
+ A single day works as well, it is simply its own title.
79
152
 
80
153
  ### Edit-Identifier
81
154
 
@@ -83,39 +156,67 @@ When the action is "edit", the next argument is treated as script that should
83
156
  be edited.
84
157
 
85
158
  If nothing is passed, the main timelog.txt is loaded.
159
+ :warn: The Obsidian-Datasource has no single file, because an entry can
160
+ come from any note of the vault. Without an argument, this command only
161
+ edits an inferer-script, which is the thing that can still be edited.
86
162
 
87
163
  Otherwise, a script to determine the time-account is loaded.
88
164
 
89
- ### Adding entries
165
+ ### Filtering by Tag
166
+
167
+ All actions that list entries (currently: show, summarize, upload and confirm)
168
+ take a `-t`/`--tag` parameter to limit the entries to those tagged with it.
169
+
170
+ $ ptimelog show today -t hit
171
+
172
+ It can be repeated to filter more intensely. All mentioned tags must apply.
173
+
174
+ $ ptimelog show today -t hit -t mail
90
175
 
91
- In order to add entries with the ptimelog-cli, the complete entry needs to be
92
- quoted on the command-line to count as one argument.
176
+ A day without a single matching entry is skipped instead of being printed as
177
+ empty, which keeps `ptimelog show all -t hit` readable.
178
+
179
+
180
+ ### Adding entries (removed)
181
+
182
+ Up to 0.12.0 there was an add-action that appended an entry to the
183
+ timelog.txt:
93
184
 
94
185
  $ ptimelog add 'ticket 1337: Implement requirements -- client coding'
95
186
 
96
- While this requires some knowledge of the file-format, it is no different than
97
- entering the same string in gTimelog. For now, the entry is added to the
98
- timelog.txt as it is passed. By default, the date/time added to the entry is
99
- the one when the command is executed.
187
+ It is gone since 0.13.0. It had been broken for a while: no datasource
188
+ implemented the write it called, so every invocation ended in a
189
+ `NoMethodError`. With Obsidian as datasource it cannot come back in that
190
+ shape at all — tracked time belongs to a task in Operon, and only Operon may
191
+ write it. This is a self-imposed limitation, of course.
100
192
 
101
- You can prefix a positive or negative signed number to slightly skew the entry
102
- (think: '-5 meeting' or '+5 lunch \*\*') or even set a precise time ('10:30
103
- meeting').
193
+ Patches are welcome, but be warned that this is not a small job. See
194
+ [docs/add-command.md](docs/add-command.md): section 9 describes what a rebuild
195
+ for the timelog.txt backend needs, sections 1 to 8 why the Obsidian side is
196
+ hard. Tracking time in Operon needs a task with correct tracking attributes.
197
+ Adding those is not impossible, but to cumbersome for now, for me.
104
198
 
105
- $ ptimelog add '-5 meeting: Discuss requirements -- client planning'
199
+ It might come back to support automating events like closing or opening the
200
+ laptop (via a lidswitch-script) and locking or unlocking the screen (via a hook
201
+ in your screen-locker). But this requires some thought and careful planning.
202
+ Currently, I am happy enough using drag&drop in Operon.
106
203
 
107
204
  ### Showing the Version
108
205
 
109
206
  I got tired of asking rubygems which version I installed, so I took on the
110
- herculean task of letting ptimelog show its own version.
207
+ herculean task of letting ptimelog show its own version. With the switch to a
208
+ cmd_parse-based CLI, this has been partially offloaded to cmd_parse. You can
209
+ imagine the weight that has been lifted off my shoulders.
111
210
 
112
211
  ### Formatting the Output
113
212
 
114
213
  In order to format the output of the show-action into a table, a hopefully
115
- convienient field-marker has been chosen. I think it is unlikely, that ∴ is
116
- being used in a time-entry. Therefore, you can pipe the output into `column`:
214
+ convienient field-marker has been chosen. After 0.10.0, I switched from '∴' to
215
+ '|', which is much more widely used, but also much easier to find on keyboard.
216
+ This removes one need to copy an unusual separator, maybe even using the mouse...
217
+ Anyway, you can pipe the output into `column`:
117
218
 
118
- ptimelog show today | column -t -s ∴
219
+ ptimelog show today | column -t -s'|'
119
220
 
120
221
  ## Helper-Scripts
121
222
 
@@ -126,6 +227,9 @@ These scripts should be located in `~/.config/ptimelog/inferers/` and be named
126
227
  like the first tag used. The script gets the ticket, the description and all
127
228
  remaining tags passed as arguments.
128
229
 
230
+ Only the first tag picks the script. `--tag` does not care about that order
231
+ and matches a tag at any position.
232
+
129
233
  The output of the script should be the ID of the time-account and the
130
234
  billable-state as "true" or "false". Both items need to be separated by
131
235
  whitespace, so you can output those two on the same line or on different lines.
@@ -134,6 +238,42 @@ Since these scripts are called a lot, it is better to write them in a compiled
134
238
  language. If you only like ruby, take a look at crystal. For such simple
135
239
  scripts, the code is almost identical and "just" needs to be compiled.
136
240
 
241
+ ## Operon
242
+
243
+ With `obsidian: true`, entries are read from the time-sessions
244
+ [Operon](https://github.com/hasanyilmaz/operon) tracked on the tasks of your
245
+ vault. Operon stores them on the task itself, so one entry comes from one
246
+ session, not from one task:
247
+
248
+ {{trackers:: 2026-10-07T11:00:00/2026-10-07T12:00:00; 2026-10-07T14:00:00/2026-10-07T15:00:00}}
249
+
250
+ Only tracked time is read. A running timer and a planned block
251
+ (`datetimeStart`/`datetimeEnd`) are no time yet, so they are skipped. A
252
+ session counts on the day it started on. Notes below `archive/` and Operons
253
+ own documentation are skipped.
254
+
255
+ Ticket and account-tags come from two custom keys, which you can create in
256
+ **Settings → Operon → Core → Custom Keys**:
257
+
258
+ - [ ] HIT-12345: Zeug machen {{operonId:: …}} {{ticket:: HIT-12345}} {{ptimelog:: hit sac mv}}
259
+
260
+ `ticket` is the text puzzletime is asked for. `ptimelog` is a single,
261
+ space-separated string of tags, identical to what the dayplanner-entries used
262
+ to carry after their `--`. The first tag selects the inferer-script, the rest
263
+ are passed to it. A task without that key is still listed, but has no account.
264
+
265
+ Both keys are inherited: a subtask which carries none of them takes them
266
+ from its parent task, up the whole chain. So the ticket can sit once in the
267
+ frontmatter of a file task, while the time is tracked on its subtasks. A key
268
+ on the subtask itself always wins.
269
+
270
+ If your vault already uses other names for these keys, map them with
271
+ `operon_custom_keys`. A key you leave out keeps its default:
272
+
273
+ operon_custom_keys:
274
+ ticket: issue
275
+ inferer: account
276
+
137
277
  ## Configuration
138
278
 
139
279
  A config-file is read from `$HOME/.config/ptimelog/config`. It is expected
@@ -141,6 +281,18 @@ to be a YAML-file. Currently, it supports the following keys:
141
281
 
142
282
  - rounding: [integer or false, default 15]
143
283
  - base_url: [url to your puzzletime-installation, default https://time.puzzle.ch]
284
+ - obsidian: [boolean, default false, read from an Obsidian vault instead of timelog.txt]
285
+ - obsidian_vault: [path to that vault, default ~/path/to/obsidian-vault]
286
+ - operon_custom_keys: [hash, default { ticket: ticket, inferer: ptimelog }, names of the keys Operon stores ticket and tags in]
287
+
288
+ If the default path of `obsidian_vault` works for you, I really want to talk to
289
+ you :-)
290
+
291
+ Operons tracked time is stored to the second, so set `rounding: false` to keep
292
+ it exact.
293
+
294
+ It might still work with the timelog.txt-config. I do not use it anymore, but
295
+ I do not want to break things needlessly. So I left it in.
144
296
 
145
297
  ## Development
146
298
 
@@ -159,7 +311,6 @@ git commits and tags, and push the `.gem` file to
159
311
 
160
312
  Bug reports and pull requests are welcome on GitHub at https://github.com/kronn/ptimelog.
161
313
 
162
-
163
314
  ## License
164
315
 
165
316
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,239 @@
1
+ # Plan: `add`-command with Obsidian/Operon as datasource
2
+
3
+ Collected ideas and findings for a later planning session. Nothing here is
4
+ implemented yet.
5
+
6
+ ## 1. Current state
7
+
8
+ - **Decision:** `add` is removed. It crashed with both backends — `Command::Add`
9
+ called `backend.add(entry)`, which neither `Ptimelog::Operon` nor
10
+ `Ptimelog::Timelog` implemented — so no working behaviour was lost. The
11
+ command, its spec and the commented-out write-methods in `Timelog` are gone
12
+ since 0.13.0.
13
+ - **The timelog.txt side is a separate, much smaller job.** See section 9.
14
+ - **Already built and kept:** `Operon#previous_entry`
15
+ (`lib/ptimelog/operon.rb:51`). It returns the running timer's start, else the
16
+ end of the day's last session, else `operon_start_time` (default `08:00`).
17
+ The entry is hidden (`start **`) and has specs. `Timelog.previous_entry` is
18
+ kept as well. Both are the hook a reimplementation starts from.
19
+
20
+ ## 2. Hard limits from the Operon docs
21
+
22
+ 1. **`trackers`, `duration` and `activeTracker` belong to Operon.** They can be
23
+ read, but should not be edited by hand (`DOCS-012:92-117`). `add` cannot
24
+ write tracked time.
25
+ 2. **`datetimeStart` and `datetimeEnd` are user-settable fields**
26
+ (`DOCS-012:70-71`). They describe a *planned* block — the only safe thing
27
+ `add` could write.
28
+ 3. **ptimelog only reads tracked time** (deliberate decision). A planned block
29
+ written by `add` does not show up in `ptimelog show` until **Log as
30
+ tracked** is pressed in Operon. The flow is always two steps.
31
+ 4. **`{{operonId}}` resolves on its own.** A probe showed Operon replaces a
32
+ literal `{{operonId:: {{operonId}}}}` shortly after the line appears,
33
+ without a restart. ptimelog never has to mint ids. Should it ever be needed:
34
+ ids are 7 characters of `[a-z0-9]` (`DOCS-015`), e.g.
35
+ `SecureRandom.random_number(36**7).to_s(36).rjust(7, '0')`.
36
+ 5. **Other template variables are unproven** on a line ptimelog writes
37
+ (`{{date}}`, `{{status}}`, `{{priority}}`, see `DOCS-061`). Write literal
38
+ values for those.
39
+
40
+ ## 3. Shape of a written line
41
+
42
+ ```markdown
43
+ - [ ] <description> {{operonId:: {{operonId}}}} {{ticket:: …}} {{ptimelog:: …}} {{datetimeStart:: YYYY-MM-DDTHH:MM:00}} {{datetimeEnd:: …}} {{dateScheduled:: YYYY-MM-DD}}
44
+ ```
45
+
46
+ - **Start:** `previous_entry.finish_time`. **End:** the parsed time or offset;
47
+ `parse_task` in `add.rb` already handles `-5`, `+5` and `HH:MM`.
48
+ - **`dateScheduled`:** matches the Operon setting
49
+ `inlineTaskDailyNoteAddScheduledDate: true` and makes the task show under
50
+ `## Heute geplant`.
51
+ - **Appending:** add the line as plain text so nothing else in the note moves.
52
+ Do not rewrite the note through a markdown parser; the old dayplanner adapter
53
+ had escaping trouble with `[`, `]`, `#`, `_` and `-`.
54
+
55
+ ## 4. Where the line goes
56
+
57
+ Operon's Task Router (`DOCS-136:26-38`) offers five destinations: Daily Notes,
58
+ Weekly Notes, Specific File, Active File, Ask Every Time. A CLI can only serve
59
+ **Daily Notes** and **Specific File**. Operon has no "inbox" concept; Specific
60
+ File *is* the inbox.
61
+
62
+ Current local setup:
63
+
64
+ - **Operon** (`.obsidian/plugins/operon/data.json → ui.taskCreationProfile`,
65
+ version 3): `specific-file`, pointing at `Operon/Tasks/Operon Inbox.md`, with
66
+ heading keyword `Heute neu`.
67
+ - **Obsidian Core daily notes** (`.obsidian/daily-notes.json`): folder `daily`,
68
+ format `YYYY-MM-DD`, template `intern/Templates/Daily Note.md`. The template
69
+ has no tokens, so creating a missing note is a plain copy.
70
+
71
+ Placement depends on the destination:
72
+
73
+ | Destination | Line lands |
74
+ |---------------|----------------------------------------------------------------------------|
75
+ | Daily Notes | under the first heading containing `Heute neu`; `##` created if missing |
76
+ | Specific File | under a date heading like `## [[2026-10-08]]`; the Inbox already uses them |
77
+
78
+ Missing daily notes (`DOCS-137:56-64`): Operon creates them from the template;
79
+ with `createDailyNotesAsOperonTask` on, the note becomes the task's parent. That
80
+ setting is currently off.
81
+
82
+ ## 5. Design options
83
+
84
+ Proposed config: `operon_task_add_location` with the values `"daily"`, an
85
+ absolute path, or `false` (default, disables `add`).
86
+
87
+ Three ways to determine the destination:
88
+
89
+ - **A. Read Operon's own settings** (`data.json` plus `daily-notes.json`)
90
+ - Pro: never drifts from what Operon's Task Creator does.
91
+ - Con: depends on Operon's private plugin data. It is versioned, its mode
92
+ values are undocumented, and it is not a published contract
93
+ (`DOCS-044`, `DOCS-046`).
94
+ - **B. Own ptimelog key**, reading only Core's `daily-notes.json` for the daily
95
+ folder and format (earlier recommendation)
96
+ - Pro: small, explicit, owned by ptimelog.
97
+ - Con: repeats a setting Operon already has, so the two can disagree.
98
+ - **C. Delegate to `operon-cli`** (`operon task create`, `DOCS-127`)
99
+ - Pro: the supported route, with preview, verified writes and parent linking.
100
+ - Con: not installed here, needs Obsidian running plus the official Obsidian
101
+ CLI, native Linux is "public beta", and the local Obsidian is a flatpak.
102
+ A dead end for now.
103
+
104
+ ## 6. Open questions
105
+
106
+ 1. **Is `add` worth it at all,** given its output is invisible to `show` until
107
+ tracked in Operon? The alternative is capturing directly in Operon.
108
+ 2. **Destination:** A, B or C. Should `"daily"` follow Core's
109
+ `daily-notes.json` or a ptimelog-owned folder?
110
+ 3. **Missing note:** create it (from the template for daily notes, empty for a
111
+ specific file) or refuse with a hint?
112
+ 4. **Dry run:** add `add --dry-run` that prints the line without writing
113
+ (about 3 lines; `confirm` already has `-n`)?
114
+ 5. **Concurrent writes:** if Obsidian has the note open, its next save can
115
+ overwrite ptimelog's line. Accept the risk, or document "close Obsidian
116
+ first"?
117
+
118
+ ## 7. Verification procedure
119
+
120
+ 1. **Specs first:** exactly one line appended; the rest of the note stays
121
+ byte-identical; the line reads back with the same fields; start equals
122
+ `previous_entry`; `show` does **not** list it.
123
+ 2. **Dry run:** prints the exact line and writes nothing.
124
+ 3. **Real write with Obsidian closed:** back up the note, run `add`. `show`
125
+ must be unchanged. In Obsidian the task gets a real id and appears on the
126
+ Calendar. After **Log as tracked**, `show` has exactly one new entry with
127
+ matching times. Restore the note.
128
+ 4. **Regression check:** the session-parity check against
129
+ `~/Obsidian/Things/export-operon-time` still matches (37/37 sessions over
130
+ 11 days at the time of writing).
131
+
132
+ ## 8. Possible small step before the full design
133
+
134
+ Today "disabled" means `ptimelog add` is an unknown command. Once `add` comes
135
+ back for timelog.txt (section 9), Obsidian needs an explicit refusal: a
136
+ one-method `Operon#add` raising a `Ptimelog::Error` ("adding entries is not
137
+ supported for the Obsidian datasource") — same pattern as
138
+ `Operon::VaultNotFound`, with one spec.
139
+
140
+ ## 9. Rebuilding `add` for the timelog.txt backend
141
+
142
+ The Obsidian/Operon side above is the hard problem. The timelog.txt side is
143
+ not: it is one appended line. `Command::Add` and
144
+ `spec/ptimelog/command/add_spec.rb` were deleted in 0.13.0, together with the
145
+ commented-out write-methods in `lib/ptimelog/timelog.rb`. What follows is what
146
+ a patch has to restore.
147
+
148
+ ### The old code
149
+
150
+ The last version that actually wrote to timelog.txt:
151
+
152
+ git show fe45a2a^:lib/ptimelog/command/add.rb
153
+
154
+ `fe45a2a` ("Switch to cmdparse for CLI and add Obsidian as datasource") turned
155
+ that into the `Entry`-based `Command::Add`, which never worked because no
156
+ backend implemented `add`. `9adbc86` ("Store the copied parts from the
157
+ add-command for later") copied the five write-methods into `Timelog` as
158
+ comments; the deletion commit removed them. Both are still readable in git.
159
+
160
+ ### The CLI contract to restore
161
+
162
+ $ ptimelog add 'ticket 1337: Implement requirements -- client coding'
163
+ $ ptimelog add '-5 meeting: Discuss requirements -- client planning'
164
+ $ ptimelog add '10:30 meeting: Discuss requirements -- client planning'
165
+
166
+ The whole entry is one quoted argument, in gTimelog's own format. A signed
167
+ prefix shifts by minutes, `HH:MM` or `H:MM` sets the time outright. Prefixing
168
+ an offset *before* a time does not work and never did (`-3 9:42 foo` parses
169
+ `9:42 foo` as the description) — the old spec pinned that as expected
170
+ behaviour.
171
+
172
+ The resulting line, appended to `timelog_txt`:
173
+
174
+ YYYY-MM-DD HH:MM: ticket: description -- tags
175
+
176
+ timelog.txt records when a task *ended*, so only the finish time is written.
177
+ The start is implicit from the preceding line.
178
+
179
+ ### Still in place
180
+
181
+ - `Timelog.timelog_txt` — the configured path, expanded
182
+ - `Timelog.previous_entry` — last non-empty, non-`**` line as an `Entry`
183
+ - `Timelog#tokenize` / `#parse` — the read side, unchanged
184
+ - `Operon#previous_entry` — the Operon equivalent, spec'd
185
+ - `DataSource#backend` — picks `Timelog.instance` or `Operon`
186
+
187
+ ### What has to be built
188
+
189
+ 1. **`Timelog#add`** — append the line, preceded by an empty line when the day
190
+ changed. Five short methods in the old code; `timelog_txt.open('a')` is the
191
+ whole write.
192
+ 2. **A refusal for Operon.** `Command::Add` resolved its backend through
193
+ `DataSource`, and with `obsidian: true` that is an `Operon` instance. Either
194
+ guard on `DataSource#type == :timelog` or give `Operon#add` a raising stub
195
+ (section 8). Without one of the two, `add` fails with `NoMethodError`
196
+ again — which is how it died.
197
+ 3. **Re-registration** — `autoload :Add` in `lib/ptimelog.rb` and
198
+ `parser.add_command` in `exe/ptimelog`.
199
+
200
+ ### Traps
201
+
202
+ 1. **Do not route the write through `Entry`.** `Entry#finish_time=` rounds via
203
+ `round_time` and `rounding` defaults to 15 (`lib/ptimelog/entry.rb`). An
204
+ `add` at 10:37 would be written as `10:30` — permanent loss in the raw file,
205
+ which is the one file that should stay exact. The old code passed a string
206
+ for this reason. There is no `Entry#to_timelog`, only `from_timelog`; if you
207
+ add one, keep it off the rounding writers.
208
+ 2. **The empty-line check is narrow.** The old condition was
209
+ `previous_entry.date == NamedDate.new.named_date('yesterday')`. After a week
210
+ off, the previous entry is not from yesterday and the day separator is
211
+ skipped. Compare against "not today" instead.
212
+ 3. **`previous_entry` is day-only.** Since `show october`, `NamedDate` can
213
+ return a range of days, and `DataSource` hands it straight to
214
+ `Operon.new`. `Operon#previous_entry` has no caller in `lib/` today, so it
215
+ never sees one; `add` would be the first. Guard it there (or in
216
+ `Operon#previous_entry` itself) — unguarded, it writes the whole range into
217
+ `entry.date` and the appended line is garbage.
218
+ 4. **`previous_entry` skips `**`-lines,** so the start it reports after a lunch
219
+ break is the pre-lunch finish. Harmless for timelog.txt, where no start is
220
+ written; it matters for anything that displays or uploads the entry.
221
+ 5. **A missing or empty timelog.txt** raises `Errno::ENOENT` or trips
222
+ `tokenize(nil)` in `previous_entry`. The old spec had a "does not need
223
+ existing entries" case; it was never implemented.
224
+ 6. **`timelog` defaults to `true`** (`lib/ptimelog/configuration.rb`), and
225
+ `DataSource#type` checks it before `obsidian`. A vault user who never set
226
+ `timelog: false` gets the timelog backend.
227
+
228
+ ### Acceptance
229
+
230
+ The old spec file listed these as pending; they are a good checklist:
231
+
232
+ 1. appends exactly one line, the rest of the file byte-identical
233
+ 2. appends an empty line when the day changed
234
+ 3. `-5`, `+5`, `HH:MM`, `H:MM`, and `H:MM -3` combined, all under Timecop
235
+ 4. offset-before-time parses as description, not as a time
236
+ 5. the written time survives a read-back through `tokenize`
237
+
238
+ Roughly 15 lines of implementation plus specs, half an hour, for the
239
+ timelog.txt backend alone. Operon stays out — see sections 1 through 8.
data/exe/ptimelog CHANGED
@@ -1,6 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../lib/ptimelog'
4
+ require 'cmdparse'
5
+ require 'ptimelog'
5
6
 
6
- Ptimelog::App.new(ARGV).run
7
+ parser = CmdParse::CommandParser.new(handle_exceptions: true)
8
+ parser.main_options.version = Ptimelog::VERSION
9
+ parser.main_options.program_name = 'ptimelog'
10
+ parser.main_options.banner = Ptimelog::BANNER
11
+
12
+ parser.add_command(CmdParse::VersionCommand.new)
13
+ parser.add_command(CmdParse::HelpCommand.new, default: true)
14
+ parser.add_command(Ptimelog::Command::Info.new)
15
+
16
+ parser.add_command(Ptimelog::Command::Edit.new)
17
+ parser.add_command(Ptimelog::Command::Show.new)
18
+ parser.add_command(Ptimelog::Command::Summarize.new)
19
+ parser.add_command(Ptimelog::Command::Upload.new)
20
+ parser.add_command(Ptimelog::Command::Confirm.new)
21
+
22
+ begin
23
+ parser.parse
24
+ rescue Ptimelog::Error => e
25
+ warn <<~MSG
26
+ An Error occured: #{e.class}
27
+
28
+ #{e.message}
29
+ MSG
30
+ end