Skip to content

✨ Add work command: journal.json-based session toggle with daily folder structure - #40

Open
amy-shinsen-openclaw wants to merge 5 commits into
mainfrom
feat/work-command
Open

✨ Add work command: journal.json-based session toggle with daily folder structure#40
amy-shinsen-openclaw wants to merge 5 commits into
mainfrom
feat/work-command

Conversation

@amy-shinsen-openclaw

@amy-shinsen-openclaw amy-shinsen-openclaw commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Closes #39

What this does

Adds a work command (alias: w) that replaces the split start-work/end-work workflow with a single toggle, using the folder-per-day file structure and journal.json for session state — not the legacy annotation system.

The legacy plugin (gdarquie_work) has been removed from main.rs — it is no longer wired to any command. The work command now lives entirely in the core src/commands/ module.

New / changed files

src/commands/work.rs

The command itself:

  1. Calls initialize_project() to ensure .nost/ exists.
  2. Calls create_note_file_with_folders("work") → creates <not_path>/year/month/week/day/YYYY-MM-DD.work.md if absent.
  3. Reads the last work event from journal.json via find_last_work_event().
  4. Delegates the start/stop decision to the pure determine_work_action() helper, then records START_WORK or STOP_WORK.

New exports:

  • WorkAction enum (Start / Stop)
  • determine_work_action(last_event: Option<&Event>) -> WorkAction — pure, easily testable

src/events/find.rs

Reads journal.json and returns the last START_WORK or STOP_WORK event.

src/main.rs

  • Routes work / w to the new command.
  • Plugin imports (gdarquie_work start-work / end-work / work-stats) removed.

Tests

commands::work — 4 unit tests for determine_work_action

  • no previous event → Start
  • last event is STOP_WORKStart
  • last event is START_WORKStop
  • non-work event (e.g. CreateNot) → Stop (defensive)

events::find — 6 unit tests for find_last_work_event

  • no journal file → None
  • empty journal → None
  • single START_WORK entry → returns it
  • START_WORK then STOP_WORK → returns STOP_WORK
  • CreateNot after START_WORKCreateNot is ignored, START_WORK returned
  • multiple sessions → returns the most recent work event

All 20 tests pass (cargo test).

Comment thread src/main.rs Outdated
Comment thread src/commands/work.rs
Comment thread src/events/find.rs
@gdarquie

Copy link
Copy Markdown
Contributor

The PR description is not correct anymore, for example "src/plugins/gdarquie_work/commands/work.rs" does not exists.

- Extract determine_work_action() pure function from work() for testability
- Add 4 unit tests for determine_work_action (no event, after stop, after start, non-work event)
- Add 6 unit tests for find_last_work_event (no journal, empty, start, stop, ignores CreateNot, multiple sessions)
Comment thread src/commands/work.rs
/// Outcome of the work-toggle decision.
#[derive(Debug, PartialEq)]
pub enum WorkAction {
Start,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you use here "StartWork" and "StopWork" EventName ?

Comment thread src/commands/work.rs Outdated
// A non-work event (e.g. CreateNot) is treated as "still open" → stop
// (shouldn't normally appear as last work event, but defensive check)
let event = make_event(EventName::CreateNot);
assert_eq!(determine_work_action(Some(&event)), WorkAction::Stop);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if only a non work event, it should add an event "START_WORK".

Comment thread src/events/find.rs
let dir = tempdir().unwrap();
env::set_var("NOT_PATH", dir.path().to_str().unwrap());
// CreateNot comes after StartWork — it must be ignored; StartWork wins.
let events = vec![

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a warning here saying something like "You should first end the last work session before to create a new note".

- Use EventName variants in determine_work_action() match arms
- Non-work event (e.g. CreateNot) as last event now starts a new session
- Add warning in new_legacy() when a work session is still open
- Update test for determine_work_action_after_create_not accordingly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Add work command: create work file with daily folder structure and toggle work session

2 participants