@codetreker/daynight 0.22.1 → 0.24.1

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 (84) hide show
  1. package/README.md +314 -334
  2. package/config.example.yml +8 -4
  3. package/dist/api/client.d.ts +2 -2
  4. package/dist/api/client.js +10 -7
  5. package/dist/api/client.js.map +1 -1
  6. package/dist/api/types.d.ts +1 -8
  7. package/dist/cli/prompts.d.ts +1 -0
  8. package/dist/commands/auth/credentials.js +1 -1
  9. package/dist/commands/auth/credentials.js.map +1 -1
  10. package/dist/commands/review/config.js +0 -9
  11. package/dist/commands/review/config.js.map +1 -1
  12. package/dist/commands/review/configuration-guide.js +3 -2
  13. package/dist/commands/review/configuration-guide.js.map +1 -1
  14. package/dist/commands/review/repositories.js +11 -4
  15. package/dist/commands/review/repositories.js.map +1 -1
  16. package/dist/commands/skill/skills/using-daynight/references/execute-task-in-managed.md +6 -5
  17. package/dist/commands/skill/skills/using-daynight/references/handbook.md +1 -1
  18. package/dist/commands/skill/skills/using-daynight/references/handoff.md +1 -1
  19. package/dist/commands/worker/cleanup.d.ts +8 -2
  20. package/dist/commands/worker/cleanup.js +44 -160
  21. package/dist/commands/worker/cleanup.js.map +1 -1
  22. package/dist/commands/worker/config.d.ts +3 -3
  23. package/dist/commands/worker/config.js +0 -6
  24. package/dist/commands/worker/config.js.map +1 -1
  25. package/dist/commands/worker/control.d.ts +11 -18
  26. package/dist/commands/worker/control.js +75 -132
  27. package/dist/commands/worker/control.js.map +1 -1
  28. package/dist/commands/worker/coordinator.d.ts +10 -8
  29. package/dist/commands/worker/coordinator.js +324 -472
  30. package/dist/commands/worker/coordinator.js.map +1 -1
  31. package/dist/commands/worker/definition.js +9 -17
  32. package/dist/commands/worker/definition.js.map +1 -1
  33. package/dist/commands/worker/diagnostics.js +2 -3
  34. package/dist/commands/worker/diagnostics.js.map +1 -1
  35. package/dist/commands/worker/execution.d.ts +35 -10
  36. package/dist/commands/worker/execution.js +109 -281
  37. package/dist/commands/worker/execution.js.map +1 -1
  38. package/dist/commands/worker/herdr/agents.d.ts +12 -91
  39. package/dist/commands/worker/herdr/agents.js +111 -358
  40. package/dist/commands/worker/herdr/agents.js.map +1 -1
  41. package/dist/commands/worker/herdr/preflight.d.ts +21 -9
  42. package/dist/commands/worker/herdr/preflight.js +118 -124
  43. package/dist/commands/worker/herdr/preflight.js.map +1 -1
  44. package/dist/commands/worker/herdr.d.ts +7 -63
  45. package/dist/commands/worker/herdr.js.map +1 -1
  46. package/dist/commands/worker/identity.js +2 -2
  47. package/dist/commands/worker/identity.js.map +1 -1
  48. package/dist/commands/worker/index.d.ts +1 -0
  49. package/dist/commands/worker/index.js +6 -13
  50. package/dist/commands/worker/index.js.map +1 -1
  51. package/dist/commands/worker/prompts.d.ts +10 -3
  52. package/dist/commands/worker/prompts.js +21 -32
  53. package/dist/commands/worker/prompts.js.map +1 -1
  54. package/dist/commands/worker/remote.d.ts +2 -3
  55. package/dist/commands/worker/remote.js +1 -6
  56. package/dist/commands/worker/remote.js.map +1 -1
  57. package/dist/commands/worker/repositories.d.ts +20 -3
  58. package/dist/commands/worker/repositories.js +100 -21
  59. package/dist/commands/worker/repositories.js.map +1 -1
  60. package/dist/commands/worker/runtime.js +112 -217
  61. package/dist/commands/worker/runtime.js.map +1 -1
  62. package/dist/commands/worker/setup-environment.d.ts +31 -0
  63. package/dist/commands/worker/setup-environment.js +146 -0
  64. package/dist/commands/worker/setup-environment.js.map +1 -0
  65. package/dist/commands/worker/setup.d.ts +11 -0
  66. package/dist/commands/worker/setup.js +113 -0
  67. package/dist/commands/worker/setup.js.map +1 -0
  68. package/dist/commands/worker/store.d.ts +12 -114
  69. package/dist/commands/worker/store.js +92 -817
  70. package/dist/commands/worker/store.js.map +1 -1
  71. package/dist/commands/worker/types.d.ts +10 -114
  72. package/dist/commands/worker/worktrees.d.ts +9 -9
  73. package/dist/commands/worker/worktrees.js +77 -37
  74. package/dist/commands/worker/worktrees.js.map +1 -1
  75. package/dist/config/document.d.ts +0 -1
  76. package/dist/config/document.js +1 -14
  77. package/dist/config/document.js.map +1 -1
  78. package/dist/config/files.d.ts +7 -1
  79. package/dist/config/files.js +4 -1
  80. package/dist/config/files.js.map +1 -1
  81. package/dist/config/ownership.d.ts +12 -0
  82. package/dist/config/ownership.js +39 -0
  83. package/dist/config/ownership.js.map +1 -0
  84. package/package.json +2 -2
package/README.md CHANGED
@@ -98,6 +98,7 @@ daynight update
98
98
  daynight login [--no-browser] # Authorize CLI access through the browser
99
99
  daynight logout # Revoke and remove the current CLI credential
100
100
  daynight worker # Show worker help
101
+ daynight worker setup # Check prerequisites and choose an agent and Projects
101
102
  daynight worker run # Run until interrupted
102
103
  daynight worker attach # Open the worker Herdr session
103
104
  daynight worker repo list [--json]
@@ -106,7 +107,6 @@ daynight worker repo remove [--project <project-id>]
106
107
  daynight worker retry <task-id> --claim-id <claim-id> [--project <project-id>]
107
108
  daynight worker release <task-id> --claim-id <claim-id> --if-version <version> [--project <project-id>]
108
109
  daynight worker resume <task-id> --claim-id <previous-claim-id> --if-version <version> [--project <project-id>]
109
- daynight worker transfer <task-id> --claim-id <claim-id> --if-version <version> [target options] [--project <project-id>]
110
110
  daynight review # Show review help
111
111
  daynight review run
112
112
  daynight review list # Also review ls
@@ -332,6 +332,14 @@ not loaded automatically. Repository paths resolve from the configuration
332
332
  directory, with the rules in the [worker](#worker-configuration-and-startup) and
333
333
  [review](#review-configuration-and-startup) guides.
334
334
 
335
+ Unknown fields at the root, in `review` or `worker`, and in their repository
336
+ entries are ignored at runtime and preserved by CLI configuration edits. Known
337
+ fields retain their type and value checks. Invalid YAML, duplicate keys and
338
+ invalid mapping structures remain errors. Every CLI configuration write, including
339
+ first-time `workerId` creation, preserves decoded values outside the fields it owns. If shared YAML aliases would change an unrelated value, the write fails
340
+ and retains the original file; separate those aliases before retrying. Unaffected
341
+ aliases remain valid.
342
+
335
343
  Project and task commands use `https://daynight.cc` when the configuration file or
336
344
  `serverUrl` is absent. A production connection needs no server configuration.
337
345
  Run `daynight login` to display an authorization code and open the verification
@@ -782,23 +790,54 @@ records binary transport and output ownership.
782
790
 
783
791
  ## Worker configuration and startup
784
792
 
785
- `daynight worker run` is a foreground process that claims eligible ready tasks
786
- across configured repositories and runs Copilot or Codex in a dedicated Herdr
787
- instance. The agent owns task delivery, acceptance, evidence and final
788
- claim-bound completion. The worker owns concurrency, resources, recovery and
789
- cleanup based on its current claim inventory.
793
+ `daynight worker run` is a foreground reconciler. It claims eligible ready tasks
794
+ across configured repositories, runs Copilot or Codex in private Herdr workspaces,
795
+ and cleans resources when the original claim leaves its complete inventory. The
796
+ agent owns delivery, acceptance, evidence and final claim-bound completion.
797
+
798
+ Start with interactive setup:
799
+
800
+ ```bash
801
+ daynight login
802
+ daynight worker setup
803
+ daynight worker run
804
+ ```
805
+
806
+ `setup` requires terminal input and stderr. It reports environment checks and
807
+ repair instructions, asks which native agent should execute tasks, then lists
808
+ existing accessible Projects with names, UUIDs and repository URLs. Select at
809
+ least one Project. Current Projects are preselected on repeat setup. The final
810
+ selection replaces the acquisition list, and the chosen agent applies to every
811
+ selected Project.
812
+
813
+ Matching registrations keep exact transport URLs and local paths. Compatible
814
+ models and arguments survive; switching agent clears incompatible global and
815
+ per-Project values. Setup previews Projects, paths, removed registrations and
816
+ native-setting resets before confirmation, then atomically saves agent settings
817
+ and the complete selection. Cancellation, invalid choices, inaccessible Project
818
+ inventory, related concurrent changes and write failures leave configuration
819
+ unchanged.
820
+
821
+ Local diagnostics inspect tools and integration settings without starting Herdr
822
+ or native agents. Missing prerequisites are reported together; selected-agent
823
+ checks use effective retained native arguments in the setup launch directory.
824
+ Missing native dependencies allow saving with a repair-needed result. Versions
825
+ and hook configuration do not prove provider authentication, future task-directory
826
+ trust, hook execution, live Herdr protocol, Git access or completed delivery.
827
+ Setup does not install tools, edit provider configuration, sign in, clone, open
828
+ worker state or acquire tasks. Unconfirmed probe-process cleanup is a failure,
829
+ including during cancellation.
790
830
 
791
831
  Install Git, Herdr 0.9.5 or newer with protocol 22 capabilities, and the selected
792
- native agent on PATH. Native/provider authentication and the current official
793
- Herdr SessionStart integration must be configured explicitly. Codex needs the
794
- hooks feature and `--no-daemon`; Unix hook scripts need bash and python3, while
795
- Windows hooks need PowerShell. The worker reports missing capabilities or
796
- integration/history instead of installing or changing global native settings.
797
- Git transport and tools used by the task, such as authenticated GitHub CLI for
798
- PR delivery, must also be ready.
832
+ native agent on PATH. Configure native/provider credentials and the current
833
+ official Herdr SessionStart integration explicitly. Codex needs hooks and
834
+ `--no-daemon`; Unix hooks need bash and python3, while Windows hooks need
835
+ PowerShell. Inspect official integration with `herdr integration status`. Missing
836
+ capabilities and native launch failures remain visible;
837
+ the worker does not install or change global native configuration. Git transport
838
+ and task tools, such as authenticated GitHub CLI for PR delivery, must be ready.
799
839
 
800
- Run `daynight login` for Daynight authentication, then select one or more
801
- existing accessible Projects:
840
+ Manage individual Project registrations with:
802
841
 
803
842
  ```bash
804
843
  daynight worker repo add
@@ -806,14 +845,12 @@ daynight worker repo list
806
845
  daynight worker repo remove
807
846
  ```
808
847
 
809
- Add and remove list remote Projects for multiselection. Each choice includes its
810
- name, UUID and repository URL. A new registration saves the selected Project ID,
811
- original server repository URL and an absolute local path. Matching existing
812
- registrations retain their configured transport URL, path and native settings;
813
- a remote-only registration gains only its Project ID. Remove changes configuration
814
- only: clones, claims, worktrees, native history and frozen execution settings
815
- remain. A running worker reads its next selection at startup, without hot reload.
816
- For scripts, identify one accessible existing Project explicitly:
848
+ Add and remove offer multiselection with each Project's name, complete UUID and
849
+ repoUrl. New entries save projectId, the original repository URL and an absolute
850
+ local path. Matching existing entries retain their transport URL, path and
851
+ agent settings; remote-only entries gain only projectId. Remove changes future
852
+ acquisition scope and preserves clones, claims, worktrees and native history.
853
+ For scripts, select one Project explicitly:
817
854
 
818
855
  ```bash
819
856
  daynight worker repo add --project PROJECT_UUID
@@ -821,41 +858,36 @@ daynight worker repo remove --project PROJECT_UUID
821
858
  daynight worker repo list --json
822
859
  ```
823
860
 
824
- `list` reads local registrations without remote discovery. Add and remove
825
- operate on existing accessible remote Projects, not raw Git URLs or new Project
826
- creation. Cancellation, empty choices, authentication or API failures, invalid
827
- selections and save failures leave the selection unchanged.
828
-
829
- An empty repository list makes interactive `worker run` offer the same Project
830
- selection. Fresh startup saves the selection before creating worker identity,
831
- SQLite, Git or Herdr resources. A restarted worker with retained state first
832
- establishes its cleanup controller, so committed cleanup deadlines continue
833
- while Project lookup or prompting waits. New task resources wait for successful
834
- selection. Startup checks the service and selected worker settings from one
835
- captured configuration source; changed service or credentials require restarting
836
- the worker. Without terminal input and stderr, configure a Project with
837
- `worker repo add --project PROJECT_UUID` before startup.
838
-
839
- New paths use `worker.repositoryRoot`, defaulting to `~/daynights`, independently
840
- of `review.repositoryRoot`. The worker root accepts the current home
841
- shortcut (`~` or `~/`), absolute paths and paths relative to `config.yml`; Windows
842
- also accepts `~\`. Registration resolves that root with the actual home and
843
- saves absolute paths. Ordinary repositories use `<root>/<host>/<owner>/<repo>`;
844
- generic transport, user, port or nested-path identities retain distinct encoded
845
- coordinates. Existing Project paths and agent overrides survive repeat add and
846
- root edits.
847
-
848
- Network and interaction hold no configuration lock. The atomic writer rereads
849
- current YAML, preserves comments and unrelated edits, and refuses changed
850
- worker root, repository selection or service credentials. Save also rejects
851
- shared YAML aliases that would alter unrelated effective settings; separate the
852
- worker data from those aliases before retrying. Unaffected aliases remain valid.
853
- Repository identities, Project IDs and logical or physical paths must remain
854
- distinct, including the Daynight state directory. These commands do not clone
855
- repositories, acquire tasks or start Herdr.
856
-
857
- For explicit repository paths and runtime overrides, retain the shared
858
- connection and review settings and configure `worker` directly:
861
+ List reads local registrations. Add and remove use existing remote Projects;
862
+ they do not create Projects, clone repositories, acquire tasks or start Herdr.
863
+ Cancellation, empty selection, failed remote reads and save errors leave the
864
+ selection unchanged.
865
+
866
+ With an empty repository list, interactive run guides the same selection before
867
+ starting tasks. Noninteractive startup requires a configured repository and
868
+ prints `worker repo add --project PROJECT_UUID` guidance. Service credentials
869
+ and selected worker settings come from one captured configuration source;
870
+ changed credentials require restarting the command. Startup resolves configured
871
+ Projects into the local projects table before reading claim inventory, including
872
+ when the state database is empty.
873
+
874
+ `worker.repositoryRoot` defaults to `~/daynights`, independently of review's
875
+ root. New registration expands the actual home shortcut or resolves a path
876
+ relative to config.yml; existing paths are retained when the root changes.
877
+ Ordinary repositories use `<root>/<host>/<owner>/<repo>`; generic transport,
878
+ user, port and nested-path identities use distinct encoded coordinates.
879
+
880
+ Network and prompts hold no configuration lock. The atomic writer rereads YAML,
881
+ preserves comments and unrelated edits, and refuses changed worker root,
882
+ repository selection or service credentials. Setup also protects observed global
883
+ agent/model/args values and saves those fields with the selected Projects. Repo
884
+ commands only own repositories; neither operation changes repositoryRoot. Shared aliases that would alter
885
+ unrelated effective settings are rejected; unaffected aliases remain valid.
886
+ Repository identities, Project IDs and physical paths must remain distinct,
887
+ including the Daynight state directory.
888
+
889
+ For explicit paths and runtime overrides, retain the shared service and review
890
+ settings and configure worker directly:
859
891
 
860
892
  ```yaml
861
893
  worker:
@@ -876,304 +908,252 @@ worker:
876
908
  args: []
877
909
  ```
878
910
 
879
- These are the defaults for the optional runtime fields. A missing configuration
880
- file, an omitted `worker` mapping, and `worker: {}` use the same defaults.
881
- Omitting `repositories` selects an empty acquisition list; worker repositories
882
- are never inferred from review settings. Configuration reads do not create or
883
- rewrite configuration files. Explicit `null` in non-nullable fields, malformed
884
- settings, filesystem errors and cancellation remain errors; `model: null` keeps
885
- its documented clearing semantics.
886
-
887
- Each explicit repository entry requires `remote` and `path`, with optional
888
- `projectId`, `agent`, `model` and `args`. The
889
- service project must already exist and match the repository. Add `projectId`
890
- when more than one project matches. Missing local repositories are cloned;
891
- existing roots and origins are verified without resetting their files or
892
- branches. Use the native authentication configuration for credentials, keeping
893
- credentials out of repository URLs and argument lists.
894
-
895
- Repository entry paths are absolute or relative to the configuration file's
896
- directory, never the launch directory. They do not expand tilde and reject
897
- drive-relative Windows paths. Repository identities, project IDs and paths cannot duplicate or
898
- overlap, including the fixed Daynight state directory. Unknown worker fields,
899
- wrong types, invalid arguments and unsupported path shapes fail visibly.
900
- `maxConcurrent` is a positive integer, `recoveryLimit` is nonnegative and
901
- `pollIntervalMs` is a positive safe integer within the timer range.
902
-
903
- Repository agent settings override fields independently when the type stays
904
- the same; explicit null model or an empty args list clears that field. Switching
905
- agent type clears inherited model and arguments unless the repository explicitly
906
- sets them. Args replace the list rather than append. The recovery limit is
907
- worker-wide. Configuration loads at startup, without hot reload; existing claims
908
- keep their original frozen configuration after a restart, while later claims
909
- use the newly loaded settings.
910
-
911
- New tasks have automatic execution disabled. Enable it explicitly with the
912
- normal task update workflow after reading the current task/version. The worker
913
- selects only ready, permitted tasks compatible with its actual platform; WSL
914
- counts as Linux. It never enables that permission itself. Released tasks wait
915
- for explicit management and do not immediately re-enter ordinary automatic
916
- acquisition. Run the worker with:
911
+ These are the defaults for optional runtime fields. A missing file, omitted
912
+ worker mapping and `worker: {}` use the same defaults; omitted repositories is
913
+ an empty list. Worker never infers repositories from review. Reads do not create
914
+ or rewrite configuration. Unknown root, worker and repository-entry fields are
915
+ ignored at runtime and preserved during configuration edits. Known non-nullable
916
+ fields still reject explicit null, invalid types or values; malformed YAML,
917
+ filesystem failures and cancellation remain errors. model:null clears the model
918
+ setting.
919
+
920
+ Each repository requires remote/path and may specify projectId or agent/model/args.
921
+ The service Project must already exist and match the repository; use projectId
922
+ when remote discovery is ambiguous. Missing local repositories are cloned;
923
+ existing roots and origins are verified without resetting files or branches.
924
+ Credentials belong in native authentication configuration, outside repository
925
+ URLs and argument lists.
926
+
927
+ Entry paths are absolute or relative to the configuration directory, never the
928
+ launch directory. They do not expand tilde or accept Windows drive-relative
929
+ paths. Duplicate repositories/Projects and overlapping repository/state paths
930
+ are errors. maxConcurrent is positive, recoveryLimit is nonnegative, and
931
+ pollIntervalMs is a positive safe integer within the timer range.
932
+
933
+ Repository agent settings override fields independently for the same type.
934
+ Explicit null model or [] args clears that field; switching type clears omitted
935
+ model/args, and args replaces the list. Worker owns cwd/session/model/mode
936
+ arguments. Configuration loads at startup without hot reload. Each claim retains
937
+ its recorded agent type and native session ID; a restarted agent uses the current
938
+ settings appropriate to that type. Settings for another type are not applied to it.
939
+
940
+ New tasks have automatic execution disabled. Enable it explicitly through the
941
+ normal task update workflow after reading the current task and version. Worker
942
+ only acquires ready, permitted tasks compatible with its actual platform; WSL is
943
+ Linux. It never enables permission itself. Released tasks wait for explicit resume.
917
944
 
918
945
  ```bash
919
946
  daynight worker run
920
947
  ```
921
948
 
922
- The command generates and atomically saves a stable root `workerId` on first
923
- use. One foreground instance owns fixed `~/.daynight/worker/` state: its SQLite,
924
- instance lock, logs, temporary resources and private Herdr data. There is no
925
- state-path override. Each task uses `daynight/<task-id>` and
926
- `<repository>/.worktrees/daynight/<task-id>`. The same valid claim retains dirty
927
- work, native history and configuration; a new claim has a fresh execution
928
- identity and conversation.
929
-
930
- The worker verifies the startup credential through the existing current-user
931
- API and pins successful response identity, including empty pages. Each local
932
- claim retains its original Daynight user ID. If another account is logged in on
933
- the same OS account, the stable workerId stays the same, but that account's empty
934
- inventory cannot terminate or resume the previous account's work. Scope-paused
935
- records need the original account/identity inspected; do not remove local state
936
- or regenerate workerId to make the mismatch disappear. The running process
937
- keeps its startup credential; restart after an intended account change.
938
-
939
- Changing serverUrl also separates local responsibility from remote work. The
940
- worker queries and acquires only on its current service. Previously committed
941
- cleanup deadlines and normal shutdown cover that worker's local records across
942
- all original services, without calling an old API or asking the new service
943
- about old records. A newly granted current-service claim freezes its new
944
- configuration and waits pending behind any active predecessor with the same task UUID for that
945
- worker, including another origin. Read-only Git ownership attributes
946
- an occupied canonical path; it does not adopt the old conversation or config.
947
-
948
- The foreground stderr output and JSONL logs identify project/task/claim, platform,
949
- waiting, pause and cleanup errors. The log path is printed at startup. An
950
- unconfirmed claim request, native launch or input is retained for observation;
951
- it is not replayed. A pause still reserves capacity. Recovering missing original
952
- configuration, history or stop evidence requires inspection, without creating a
953
- replacement conversation to conceal the loss.
954
-
955
- For human input, run this in another interactive terminal:
949
+ First use generates and atomically saves stable root workerId. One instance owns
950
+ fixed `~/.daynight/worker/` state, its SQLite, lock, logs, temporary resources and
951
+ private Herdr. Each task uses branch `daynight/<task-id>` and directory
952
+ `<repository>/.worktrees/daynight/<task-id>`. Valid claims retain their dirty
953
+ worktree; task branches and commits remain after terminal cleanup.
954
+
955
+ The local database has exactly these business fields:
956
+
957
+ ```text
958
+ projects(project_id, repo_url, local_path)
959
+ tasks(project_id, task_id, claim_id, status, agent, session_id)
960
+ ```
961
+
962
+ Status is pending, active or done. Pending is an actual acquired claim waiting
963
+ for startup; active owns startup, running, recovery or cleanup responsibility;
964
+ done means the ended claim's resources have been cleaned. Completed rows remain,
965
+ and at most one claim for the same Project/task can be active. A removed config
966
+ entry stops new acquisition but its saved Project mapping continues reconciliation.
967
+ Mappings with unfinished tasks or actual managed resources cannot be rebound.
968
+
969
+ The state directory belongs to the configured single service, Daynight account
970
+ and workerId. Finish old executions before changing those identities and
971
+ rebuilding local state. The running process pins its startup authenticated user;
972
+ the six-column database does not retain prior-service or prior-account recovery
973
+ scopes. Existing detailed worker databases are not migrated: stop the old worker,
974
+ remove its old SQLite database yourself, and let the next run create the new
975
+ schema. The CLI never deletes it automatically. Keep workerId and native history.
976
+
977
+ Each reconciliation obtains the complete own-claim inventory for configured and
978
+ saved Projects. Still-owned local active tasks are queued for fresh target
979
+ observation and recovery before global Git discovery, so a sibling checkout's
980
+ filesystem error does not block an already-reserved task. New pending startup
981
+ and new claims still require complete global resource discovery. Failed or
982
+ partial reads are errors, not an empty inventory. Resources from unqueried or
983
+ unmapped Projects are preserved with a diagnostic.
984
+
985
+ Capacity is the claim-deduplicated union of active rows, actual owned resources,
986
+ already selected cleanup responsibilities and adapter stop confirmations still
987
+ pending. An orphan keeps its slot and same-task barrier until all cleanup has
988
+ finished, even without a local row or after its pane has closed. Git
989
+ markers identify a claim rather than a worker. A Git-only resource must be tied
990
+ to a local row, the private Herdr instance or a current own claim before this
991
+ worker can clean it; otherwise it is reported and preserved.
992
+
993
+ An unknown claim response emits Warning and creates no resources. The worker
994
+ finds the actual grant in a later complete inventory instead of replaying the
995
+ request. A late grant can remain pending while local active slots are full.
996
+
997
+ Pending startup and new acquisition both rotate Projects after each successful
998
+ slot allocation. Pending rows have priority, with stable task-ID order inside
999
+ each Project; new candidates retain server ready order. A busy Project does not
1000
+ fill every free slot before another Project gets its turn.
1001
+
1002
+ Native recovery uses current resources and the recorded session ID:
1003
+
1004
+ | State | Action |
1005
+ |---|---|
1006
+ | Matching agent is alive | Reconnect and observe without resending the startup prompt. |
1007
+ | Agent needs starting, session_id is present | Resume that native session using the recorded agent type. |
1008
+ | Agent needs starting, session_id is NULL | Emit Warning, start a fresh native conversation, and save its ID in the same row. |
1009
+
1010
+ When a native process must restart, the worker stops/closes an existing
1011
+ inactive workspace and creates a new one with the current native environment
1012
+ and an empty pane-level session reference. Herdr restore can retain the old
1013
+ native reference while restoring the shell without its extra launch environment.
1014
+ The saved SQLite session_id still selects resume or fresh startup; an inactive
1015
+ pane's retained reference is not saved as a newly observed session ID. A live
1016
+ agent keeps its current connection.
1017
+
1018
+ A non-NULL saved session ID remains the recovery identity. A different native
1019
+ ID reported during startup, live reconnection or before deferred input is an
1020
+ error: the saved ID is retained and that input is not sent. A genuine live
1021
+ agent's ID may fill a NULL record; inactive pane references remain excluded.
1022
+
1023
+ The NULL rule also covers interruption before a newly started native ID was saved.
1024
+ It retains the task, claim and worktree and requires no history scan or approval
1025
+ gate. A failed resume of a known ID remains an error. Launch/input receipts,
1026
+ process observations, retries and cleanup progress exist only in the current
1027
+ call or process. Recovery counts reset on restart; reaching recoveryLimit keeps
1028
+ the task active with a visible error until explicit retry or another run.
1029
+
1030
+ For human input, use another interactive terminal:
956
1031
 
957
1032
  ```bash
958
1033
  daynight worker attach
959
1034
  ```
960
1035
 
961
- The command opens the existing private Herdr session with the correct directory
962
- and environment. Continue in the original task pane so the worker can observe
963
- the same execution. Detaching closes only the client connection; the worker,
964
- original agent and task keep running. This command needs no Daynight login or
965
- server request and does not take the worker lock. It connects only to an
966
- existing session; if it is unavailable, start `daynight worker run` first.
967
- Client startup and nonzero-exit errors remain visible.
968
-
969
- The worker prints the attach command after inventory and private
970
- managed-instance readiness. Its attachment descriptor remains the internal
971
- source of routing, native-home and history settings. Only the client process
972
- receives those settings and removal of inherited session identities; the
973
- existing task pane retains its original native XDG and private HISTFILE.
974
-
975
- Native startup can be waiting at a folder-trust or authorization screen even
976
- when Herdr reports idle/interactiveReady. The worker checks the current Codex
977
- input surface before automatic text and Enter, reports a blocking reason and
978
- keeps the first prompt unsent. It does not choose native trust or change global
979
- trust configuration. Configure that prerequisite normally in the native tool or
980
- use the original attached task pane to make the decision explicitly, then leave
981
- the business composer available for input. This check does not inspect arbitrary
982
- human draft meaning or prove that a model consumed previously submitted text.
983
-
984
- The checked Codex startup/restart layout is the standard/default business
985
- composer together with a loaded model/reasoning and current-directory footer
986
- (`model-with-reasoning · current-dir`). Ask text or a version header alone is
987
- insufficient because provisional startup can show them too. A custom footer,
988
- cropped footer or otherwise unrecognized visible layout remains unknown; the
989
- original Operation bounds observation and ends not-submitted if that supported
990
- surface never appears. In the original session, finish any blocking decision
991
- and restore the supported standard native layout before requesting public retry.
992
- The worker does not change the layout, infer arbitrary draft meaning or turn
993
- this screen check into a native consumption receipt.
994
-
995
- For started executions, a successful complete own-claim inventory from the
996
- original account makes the original claim's absence cause
997
- the same terminal cleanup for done, release and transfer: request attributable
998
- outside-worktree cleanup for at most the original ten-minute deadline, confirm
999
- the original agent stopped, close its workspace, delete its worktree and retain
1000
- local history. Failures keep responsibility and resume cleanup after restart.
1001
- A failed, incomplete or differently scoped inventory cannot authorize a new
1002
- terminal-cleanup decision. Already persisted cleanup/control intents continue in
1003
- the same foreground process through a lightweight discovery loop and one
1004
- transient asynchronous job per full claim, before current-user/project network
1005
- requests and even during server read failures. Only already authorized intents
1006
- with known original account scope advance; unknown-scope terminal/control
1007
- intents remain preserved. Each job waits at most one second or its nearer
1008
- original deadline, independently of pollIntervalMs. One task's held RPC does not
1009
- postpone another task's next cleanup advance; per-task serialization still
1010
- prevents overlapping operations on the same execution. There is no persisted job
1011
- queue.
1012
-
1013
- Ctrl+C stops acquisition and ordinary input, cancels and joins the ordinary
1014
- cleanup discovery loop and all per-claim jobs, then runs original-task shutdown
1015
- with a separate bounded cancellation scope and a shared exit deadline.
1016
- Unfinished claims, worktrees and native history remain; the private instance
1017
- stops only after original agents are confirmed stopped. Stop uncertainty is
1018
- reported and retains the instance/resources for inspection. Restart the command
1019
- to reconcile with the same worker identity and original state. After consuming
1020
- interrupted shutdown, the worker refreshes Herdr resources before ordinary
1021
- execution. If a native launch may have occurred but its exact original session
1022
- ID is missing, shutdown preserves its old binding, launch and PID evidence and
1023
- pauses; it does not turn that execution into a first launch. Proven
1024
- never-started work and executions with a known original native ID retain their
1025
- normal recovery path.
1026
-
1027
- A causal worker cancellation propagates into shutdown without adding a fault
1028
- pause. Existing real pauses, recovery budget and unknown-action records keep
1029
- their meaning; an unrelated error is not normal cancellation merely because the
1030
- signal is already aborted. Read-only interruption followed by successful
1031
- shutdown can resume the original session through the normal recovery path.
1032
-
1033
- Pending successors whose resources, workspace and native launch are proven
1034
- never started stay pending on normal exit. A successful complete inventory from
1035
- the same original account can complete an absent unstarted claim directly,
1036
- without activating it or touching an older claim's fixed Git path. Other tasks'
1037
- shutdown initialization is isolated so one bad record does not prevent known
1038
- agents stopping. Untracked resources or unknown scope keep the private instance
1039
- when its stop cannot be confirmed.
1040
-
1041
- Linux, Windows and macOS complete Goal acceptance is separate from the installed
1042
- runtime and its component checks. The
1036
+ Attach opens only the existing private Herdr session. It needs no Daynight
1037
+ credential or service request, does not open SQLite or take the worker lock,
1038
+ and does not start a replacement daemon. Detaching leaves worker and tasks
1039
+ running. Original task panes retain their native XDG and private HISTFILE;
1040
+ client routing comes from the existing attachment descriptor.
1041
+
1042
+ Folder trust or authorization must be handled explicitly in the native tool or
1043
+ attached task pane. Worker retains input-readiness and supported Codex composer
1044
+ checks and does not auto-accept trust or alter global settings. Unknown layouts
1045
+ or launch errors remain visible. Reconnecting an already alive agent does not
1046
+ promise to resend an input lost across a process interruption.
1047
+
1048
+ When the original claim is absent from a successful complete inventory, the
1049
+ worker asks its agent to release attributable temporary files, services and
1050
+ processes outside the worktree. It waits at most ten minutes for this cleanup
1051
+ attempt, stops the agent, closes its workspace, removes the matching worktree
1052
+ and marks the local row done. Done, release and force withdrawal have the same terminal
1053
+ resource rule. Failed stop or deletion retains responsibility and the error.
1054
+
1055
+ Known-target cleanup and shutdown observe that Herdr execution directly;
1056
+ worktree deletion validates only its target Git registration and directory.
1057
+ Unrelated repository or sibling-worktree registration errors are reported
1058
+ separately and do not prevent a healthy agent from stopping.
1059
+
1060
+ Early cleanup completion uses only the successful cleanup-prompt receipt's
1061
+ idle, interactive-ready observation with both sequence counters present; later
1062
+ observations must advance both counters. A prior polling snapshot cannot supply
1063
+ that baseline. Busy, unknown, rejected or unattributable notification results
1064
+ retain the current bounded wait instead of counting an old task turn as cleanup.
1065
+
1066
+ Cleanup timing and progress are in memory. Polls do not extend the current
1067
+ attempt's deadline; after a crash, the next successful reconciliation observes
1068
+ remaining resources and starts a new cleanup attempt and timer. Cleanup prompts
1069
+ may repeat. Separate tasks have independent bounded jobs, so one held RPC does
1070
+ not postpone another task's cleanup. A cleanup already selected in the current
1071
+ process can continue during later service-read failures.
1072
+
1073
+ Ctrl+C stops acquisition and ordinary scheduling, then gives agents bounded
1074
+ outside-worktree cleanup, stops them and closes their workspaces. Valid claims,
1075
+ worktrees, session IDs and active/pending rows remain for the next run. The
1076
+ private instance stops last; exit failures remain visible.
1077
+
1078
+ stderr and JSONL logs identify worker, platform, Project/task/claim, agent and
1079
+ known session ID. Startup prints the log location and attach guidance. Routine
1080
+ observations report the first connection and changes to a claim’s waiting or
1081
+ executing phase, terminal or native session. Unchanged polls stay quiet, including
1082
+ the first poll after a successful start. Claims are tracked independently.
1083
+ Resource-preservation warnings appear once while continuously observed and
1084
+ appear again if they clear and return. Actual starts, recoveries, cleanup, manual
1085
+ operations and failed attempts remain visible. This reporting state lasts for
1086
+ the current process. Logs are diagnostic only; they do not supply a second
1087
+ recovery ledger. The
1043
1088
  [worker requirements](../../docs/spec/daynight-worker.md) and
1044
- [worker design](../../docs/design/daynight-worker.md) own the behavior and
1045
- mechanisms, including native capability limits.
1089
+ [design](../../docs/design/daynight-worker.md) own full behavior and validation.
1046
1090
 
1047
1091
  ## Worker manual management
1048
1092
 
1049
- Manual commands select one task and its exact original claim. They use the same
1050
- fixed SQLite and singleton lock as `worker run`. With a foreground worker, that
1051
- process remains the sole agent controller and consumes the persisted decision;
1052
- without one, the command acquires the same lock and advances the same coordinator
1053
- for that execution. There is no separate control service. Current configuration
1054
- and Daynight authentication are required, and the original service origin must
1055
- match. Release, transfer and retry require the unfinished original local record;
1056
- resume can use an explicit project with its configured repository.
1093
+ Stop `daynight worker run` before retry, release or resume. Each command
1094
+ acquires the same instance lock and synchronously handles one specified claim;
1095
+ an occupied lock returns an instruction to stop the runner. Management does not
1096
+ write a durable intent or coordinate through a background request queue.
1057
1097
 
1058
- Read the current task before deciding a versioned operation:
1098
+ Retry performs one attempt for an active claim still owned by this worker:
1059
1099
 
1060
1100
  ```bash
1061
- daynight task show <task-id> --json
1062
- daynight worker release <task-id> --claim-id <source-claim-id> --if-version <version>
1101
+ daynight worker retry <task-id> --claim-id <claim-id> --project <project-id>
1063
1102
  ```
1064
1103
 
1065
- Release and transfer first verify project access and source owner/admin
1066
- permission, then persist the concrete source decision before cleanup. The
1067
- controller requests the original agent's attributable temporary-resource cleanup,
1068
- waits for its original deadline of at most 10 minutes, confirms that agent stopped,
1069
- closes its task workspace and deletes its worktree. Only then can it submit the
1070
- remote write at the exact supplied version. Other tasks keep their shared Herdr
1071
- instance. Failed stopping or deletion retains the source responsibility and a
1072
- visible error. Cleanup keeps its original deadline after restart; each HTTP
1073
- request has an independent bounded scope, without a five-minute total command
1074
- limit.
1075
-
1076
- Release returns the task to `todo` and clears its execution interval. The daemon
1077
- skips released tasks until explicitly resumed. Resume starts a fresh execution
1078
- on this worker:
1104
+ It connects the live agent or resumes its recorded native session. NULL emits
1105
+ Warning and starts a fresh conversation in the same task worktree. The claim
1106
+ and agent type remain; pending rows are started through normal run scheduling.
1107
+ After the attempt, run connects to the actual surviving resource. Retry does not
1108
+ persist a permit or a cumulative cross-restart budget.
1079
1109
 
1080
- ```bash
1081
- daynight worker resume <task-id> --claim-id <released-claim-id> --if-version <version> \
1082
- --project <project-id>
1083
- ```
1084
-
1085
- The previous claim must still be released and the task ready. The original owner
1086
- or a current project admin may resume it, retaining the explicit manual exception
1087
- to automatic permission and platform filters. The new claim and worktree IDs are
1088
- generated and persisted before submission. Its actual grant commits local
1089
- `pending` with this repository's current effective agent/model/args; `worker run`
1090
- then performs ordinary capacity checks and prepares a fresh native conversation.
1091
- The deleted source worktree and native history are not required. Run
1092
- `daynight worker run` if the foreground worker is stopped.
1093
-
1094
- Transfer explicitly identifies the target's current user, stable worker and
1095
- machine descriptor, actual platform and selected agent:
1110
+ Release validates current Project access, source owner/admin, original claim
1111
+ and exact supplied version. Its ordering is:
1096
1112
 
1097
- ```bash
1098
- daynight worker transfer <task-id> --claim-id <source-claim-id> --if-version <version> \
1099
- --target-user-id <user-id> --target-worker-id <worker-id> \
1100
- --target-machine-id <machine-id> --target-machine-name "target-machine" \
1101
- --target-platform linux --target-agent codex
1113
+ ```text
1114
+ notify and stop agent → close workspace → submit remote change
1115
+ → confirm source ownership ended → delete worktree → local done
1102
1116
  ```
1103
1117
 
1104
- Use the intended receiver's actual descriptor and the explicitly selected new
1105
- agent type. A trace-free new transfer grant honors that agent even when the
1106
- receiver's current repository defaults select the other type. It freezes
1107
- `model: null` and `args: []` for that type, with the current recovery limit; a
1108
- matching type uses the current effective model/args. Existing pending snapshots
1109
- are retained. The source operator's owner/admin permission is checked separately
1110
- from the target's
1111
- current membership. Transfer still requires automatic execution permission,
1112
- platform compatibility and completed dependencies. It preserves `in_progress`
1113
- and the task's execution interval, installing a fresh target claim/worktree ID
1114
- with empty runtime associations. The receiver discovers its actual grant through
1115
- normal claim inventory and starts a new execution; an old task path still in use
1116
- blocks preparation. No source files, SQLite snapshots or native history are
1117
- transported. Target and source agents may differ. Public commands provide no
1118
- claim/worktree-ID override or continuity confirmation option; the service and
1119
- typed client reject deprecated `continuityConfirmed` input.
1120
-
1121
- For a paused execution that still belongs to the original owner, authorize one
1122
- extra recovery attempt:
1118
+ The worktree is retained until remote confirmation. A refusal leaves it available
1119
+ for original execution recovery; success followed by local deletion failure is
1120
+ finished by the next run's ordinary absent-claim cleanup. Stopping failure cannot
1121
+ supply stoppedConfirmed. Explicit --if-version is never replaced during cleanup.
1123
1122
 
1124
1123
  ```bash
1125
- daynight worker retry <task-id> --claim-id <claim-id>
1124
+ daynight worker release <task-id> --claim-id <claim-id> --if-version <version> \
1125
+ --project <project-id>
1126
1126
  ```
1127
1127
 
1128
- Retry preserves the original claim, worktree/native identity and frozen
1129
- settings, retaining the cumulative recovery count rather than resetting it.
1130
- Concurrent or repeated requests do not accumulate extra authorization or launch
1131
- a second agent. The controller consumes the single permit for that original
1132
- execution; a further failure remains visible. Retry cannot replace terminal
1133
- cleanup or recreate an execution that has ended.
1134
-
1135
- A native launch acknowledged before a blocking startup screen has a specific
1136
- continuation path when its first prompt is durably known unsent. Keep the
1137
- original worker/native session running and use another terminal to attach to
1138
- that original pane. Inspect the reported folder-trust/authorization requirement
1139
- and make the native decision yourself. Once the business composer is available,
1140
- run:
1128
+ Release returns the task to todo and clears its execution interval. Ordinary
1129
+ automatic acquisition skips released tasks until explicitly resumed:
1141
1130
 
1142
1131
  ```bash
1143
- daynight worker retry <task-id> --claim-id <original-claim-id> --project <project-id>
1132
+ daynight worker resume <task-id> --claim-id <released-claim-id> --if-version <version> \
1133
+ --project <project-id>
1144
1134
  ```
1145
1135
 
1146
- The controller first checks the original worktree, full binding, frozen argv,
1147
- workspace/launch evidence, same shell and every saved native key PID. Ordinary
1148
- child-process changes do not replace the original proof. After that read-only
1149
- identity check, it consumes one authorized recovery attempt (the cumulative
1150
- count increases by one, without reset) and can deliver the first prompt once in
1151
- the original native process without another agent.start or conversation. Missing
1152
- an official native ID before the first turn does not by itself block this
1153
- proven-unsent continuation. This is not permission to resend an earlier
1154
- submitted/unknown prompt, infer loss from an empty-looking composer or restart
1155
- an unproven missing-ID conversation. Legacy records with unknown native-process
1156
- role remain fenced; migration does not construct identity from foreground PID
1157
- order. Automated cleanup text and /exit use the same screen boundary; a blocking
1158
- screen is not accepted with Enter merely to finish shutdown.
1159
-
1160
- Management diagnostics identify the original claim and report persisted waiting,
1161
- completion, rejection or unknown results. Interrupting the command retains its
1162
- intent so the foreground controller or a later management invocation can
1163
- continue. An unknown release/transfer write is reconciled by reading the actual
1164
- task and saved target claim; it is never resent or assigned replacement IDs,
1165
- even when a read still shows the old value. Reinvoking that same decision can
1166
- reconcile its result by targeted reads, including beside a running foreground
1167
- worker, without taking over resource control or resubmitting. An already-cleaned
1168
- source is not restarted. Only a definitely rejected submission can be replaced by a new explicit
1169
- decision, with the supplied `--if-version` matching a fresh task observation. The
1170
- numeric version may remain the same when the refusal did not change the task,
1171
- including a definite pre-dispatch failure or permission refusal. An unknown
1172
- submission cannot be reset or replayed; `--if-version` is never silently replaced.
1173
- Unknown resume requests likewise retain their original claim/worktree/config
1174
- until the actual grant can be confirmed. These targeted reads reconcile manual
1175
- writes; automatic cleanup still relies only on a complete successful inventory
1176
- for the original authenticated user and worker.
1136
+ Resume requires the previous released claim, ready task and original owner/admin.
1137
+ It preserves the explicit manual permission/platform exception, obtains fresh
1138
+ claim/worktree identities with current settings, and registers pending with a
1139
+ NULL native session ID. Start run to execute it.
1140
+
1141
+ Web task details show the current claiming user, machine, agent and phase. The
1142
+ original owner or a project admin can confirm **Force withdraw** for active or
1143
+ released ownership. This submits the reviewed claim ID and exact version,
1144
+ atomically clears worker ownership, returns the task to `todo`, clears both
1145
+ execution timestamps and sets `allowAgents=false`. Other task materials remain.
1146
+ It requires no stopped confirmation and does not guarantee that the remote agent
1147
+ stops immediately. On its next successful complete own-claim inventory, the
1148
+ original worker discovers its claim is absent and starts terminal cleanup.
1149
+ Automatic selection stays disabled until explicitly enabled again. There is no
1150
+ CLI withdrawal command or target-execution handoff.
1151
+
1152
+ Fresh IDs are generated and printed before remote submission. An unknown response
1153
+ is reconciled by GET without replaying the write. If the result remains unknown
1154
+ or the command is interrupted, inspect the remote task and claim before starting
1155
+ run again; management has no cross-process intent continuation. A definite refusal
1156
+ allows a new explicit decision with a freshly observed exact version.
1177
1157
 
1178
1158
  ## Review configuration and startup
1179
1159
 
@@ -1197,14 +1177,14 @@ All review settings belong under the `review` mapping. The same YAML also
1197
1177
  accepts the server client's `serverUrl` and optional `serverToken` fields, the
1198
1178
  `worker` mapping and generated `workerId`. Review validates its own fields
1199
1179
  independently of server business values. The server projection requires a valid HTTP(S) origin and
1200
- validates any configured token and its transport. The shared parser still rejects
1201
- invalid YAML, duplicate keys and unknown root fields. Registration can add the
1202
- first review repository to a server-only file while preserving its server
1203
- settings and comments. Unknown fields inside `review` are rejected by review
1204
- commands. Existing flat review settings must be moved together under `review`,
1205
- including `repositoryRoot`, `repositories`, numeric options and Copilot options;
1206
- remove their old root entries. The old root fields are rejected, with no automatic
1207
- migration.
1180
+ validates any configured token and its transport. The shared parser rejects invalid YAML, duplicate keys and a non-mapping root.
1181
+ Unknown fields at the root, inside `review` or `worker`, and in their repository
1182
+ entries are ignored by runtime projections and preserved by configuration edits.
1183
+ Known fields retain their type and value validation. Registration can add the
1184
+ first review repository to a server-only file while preserving its settings and
1185
+ comments. Flat review settings are ignored; move `repositoryRoot`, `repositories`,
1186
+ numeric options and Copilot options under `review` to use them. The CLI does not
1187
+ migrate these fields.
1208
1188
 
1209
1189
  A configuration with an explicit addition root is:
1210
1190
 
@@ -1256,7 +1236,7 @@ configuration containing `serverToken` uses POSIX mode `0600`; without a token,
1256
1236
  existing file-mode behavior is preserved.
1257
1237
 
1258
1238
  Numeric options use the documented [configuration defaults](../../docs/design/daynight-review.md#使用方式与配置)
1259
- when omitted. Explicit invalid values, unsupported fields, duplicate YAML keys and
1239
+ when omitted. Explicit invalid values for known fields, duplicate YAML keys and
1260
1240
  malformed documents produce nonzero exits with useful errors. Missing configuration
1261
1241
  triggers the [configuration setup](#configuration-setup) rules before review
1262
1242
  startup. Duplicate repository identities,