@codetreker/daynight 0.21.13 → 0.24.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.
Files changed (102) hide show
  1. package/README.md +364 -287
  2. package/config.example.yml +69 -0
  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.d.ts +2 -1
  11. package/dist/commands/review/config.js +22 -39
  12. package/dist/commands/review/config.js.map +1 -1
  13. package/dist/commands/review/configuration-guide.js +7 -6
  14. package/dist/commands/review/configuration-guide.js.map +1 -1
  15. package/dist/commands/review/definition.js +1 -1
  16. package/dist/commands/review/definition.js.map +1 -1
  17. package/dist/commands/review/repositories.js +19 -19
  18. package/dist/commands/review/repositories.js.map +1 -1
  19. package/dist/commands/skill/skills/using-daynight/references/execute-task-in-managed.md +6 -5
  20. package/dist/commands/skill/skills/using-daynight/references/handbook.md +1 -1
  21. package/dist/commands/skill/skills/using-daynight/references/handoff.md +1 -1
  22. package/dist/commands/worker/attach.d.ts +3 -0
  23. package/dist/commands/worker/attach.js +53 -0
  24. package/dist/commands/worker/attach.js.map +1 -0
  25. package/dist/commands/worker/cleanup.d.ts +8 -2
  26. package/dist/commands/worker/cleanup.js +44 -160
  27. package/dist/commands/worker/cleanup.js.map +1 -1
  28. package/dist/commands/worker/config.d.ts +13 -3
  29. package/dist/commands/worker/config.js +35 -13
  30. package/dist/commands/worker/config.js.map +1 -1
  31. package/dist/commands/worker/configuration-guide.d.ts +19 -0
  32. package/dist/commands/worker/configuration-guide.js +86 -0
  33. package/dist/commands/worker/configuration-guide.js.map +1 -0
  34. package/dist/commands/worker/control.d.ts +11 -18
  35. package/dist/commands/worker/control.js +75 -132
  36. package/dist/commands/worker/control.js.map +1 -1
  37. package/dist/commands/worker/coordinator.d.ts +10 -8
  38. package/dist/commands/worker/coordinator.js +311 -473
  39. package/dist/commands/worker/coordinator.js.map +1 -1
  40. package/dist/commands/worker/definition.js +34 -18
  41. package/dist/commands/worker/definition.js.map +1 -1
  42. package/dist/commands/worker/diagnostics.js +2 -3
  43. package/dist/commands/worker/diagnostics.js.map +1 -1
  44. package/dist/commands/worker/execution.d.ts +35 -10
  45. package/dist/commands/worker/execution.js +92 -283
  46. package/dist/commands/worker/execution.js.map +1 -1
  47. package/dist/commands/worker/herdr/agents.d.ts +12 -91
  48. package/dist/commands/worker/herdr/agents.js +111 -358
  49. package/dist/commands/worker/herdr/agents.js.map +1 -1
  50. package/dist/commands/worker/herdr/instance.d.ts +1 -0
  51. package/dist/commands/worker/herdr/instance.js +30 -5
  52. package/dist/commands/worker/herdr/instance.js.map +1 -1
  53. package/dist/commands/worker/herdr/preflight.d.ts +21 -9
  54. package/dist/commands/worker/herdr/preflight.js +118 -124
  55. package/dist/commands/worker/herdr/preflight.js.map +1 -1
  56. package/dist/commands/worker/herdr.d.ts +7 -63
  57. package/dist/commands/worker/herdr.js.map +1 -1
  58. package/dist/commands/worker/identity.js +2 -2
  59. package/dist/commands/worker/identity.js.map +1 -1
  60. package/dist/commands/worker/index.d.ts +8 -0
  61. package/dist/commands/worker/index.js +21 -14
  62. package/dist/commands/worker/index.js.map +1 -1
  63. package/dist/commands/worker/prompts.d.ts +10 -3
  64. package/dist/commands/worker/prompts.js +21 -32
  65. package/dist/commands/worker/prompts.js.map +1 -1
  66. package/dist/commands/worker/remote.d.ts +2 -3
  67. package/dist/commands/worker/remote.js +1 -6
  68. package/dist/commands/worker/remote.js.map +1 -1
  69. package/dist/commands/worker/repositories.d.ts +40 -0
  70. package/dist/commands/worker/repositories.js +236 -0
  71. package/dist/commands/worker/repositories.js.map +1 -0
  72. package/dist/commands/worker/runtime.d.ts +1 -0
  73. package/dist/commands/worker/runtime.js +135 -212
  74. package/dist/commands/worker/runtime.js.map +1 -1
  75. package/dist/commands/worker/setup-environment.d.ts +31 -0
  76. package/dist/commands/worker/setup-environment.js +146 -0
  77. package/dist/commands/worker/setup-environment.js.map +1 -0
  78. package/dist/commands/worker/setup.d.ts +11 -0
  79. package/dist/commands/worker/setup.js +113 -0
  80. package/dist/commands/worker/setup.js.map +1 -0
  81. package/dist/commands/worker/store.d.ts +12 -114
  82. package/dist/commands/worker/store.js +92 -817
  83. package/dist/commands/worker/store.js.map +1 -1
  84. package/dist/commands/worker/types.d.ts +10 -114
  85. package/dist/commands/worker/worktrees.d.ts +9 -9
  86. package/dist/commands/worker/worktrees.js +77 -37
  87. package/dist/commands/worker/worktrees.js.map +1 -1
  88. package/dist/config/document.d.ts +0 -1
  89. package/dist/config/document.js +1 -22
  90. package/dist/config/document.js.map +1 -1
  91. package/dist/config/errors.d.ts +2 -2
  92. package/dist/config/errors.js.map +1 -1
  93. package/dist/config/files.d.ts +7 -1
  94. package/dist/config/files.js +4 -1
  95. package/dist/config/files.js.map +1 -1
  96. package/dist/config/ownership.d.ts +12 -0
  97. package/dist/config/ownership.js +39 -0
  98. package/dist/config/ownership.js.map +1 -0
  99. package/dist/repository/location.d.ts +7 -0
  100. package/dist/repository/location.js +51 -0
  101. package/dist/repository/location.js.map +1 -0
  102. package/package.json +4 -3
package/README.md CHANGED
@@ -98,11 +98,15 @@ 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
103
+ daynight worker attach # Open the worker Herdr session
104
+ daynight worker repo list [--json]
105
+ daynight worker repo add [--project <project-id>]
106
+ daynight worker repo remove [--project <project-id>]
102
107
  daynight worker retry <task-id> --claim-id <claim-id> [--project <project-id>]
103
108
  daynight worker release <task-id> --claim-id <claim-id> --if-version <version> [--project <project-id>]
104
109
  daynight worker resume <task-id> --claim-id <previous-claim-id> --if-version <version> [--project <project-id>]
105
- daynight worker transfer <task-id> --claim-id <claim-id> --if-version <version> [target options] [--project <project-id>]
106
110
  daynight review # Show review help
107
111
  daynight review run
108
112
  daynight review list # Also review ls
@@ -310,6 +314,32 @@ records startup-file ownership and installation limits.
310
314
 
311
315
  ## Configuration setup
312
316
 
317
+ The shared configuration file is `~/.daynight/config.yml`. The complete
318
+ [`config.example.yml`](config.example.yml) covers service access, review and worker
319
+ settings with their defaults and optional overrides. It is included at the root
320
+ of the npm package. For an npm global installation, locate it with:
321
+
322
+ ```bash
323
+ npm root --global
324
+ ```
325
+
326
+ Open `@codetreker/daynight/config.example.yml` beneath that directory. Select the
327
+ sections needed for your commands and replace the example repositories and local
328
+ paths. For a new configuration, save the selected settings to
329
+ `~/.daynight/config.yml`; for an existing file, merge them while preserving its
330
+ credential, generated `workerId` and unrelated settings. The example itself is
331
+ not loaded automatically. Repository paths resolve from the configuration
332
+ directory, with the rules in the [worker](#worker-configuration-and-startup) and
333
+ [review](#review-configuration-and-startup) guides.
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
+
313
343
  Project and task commands use `https://daynight.cc` when the configuration file or
314
344
  `serverUrl` is absent. A production connection needs no server configuration.
315
345
  Run `daynight login` to display an authorization code and open the verification
@@ -342,7 +372,8 @@ commands do not start login, follow redirects with credentials, or automatically
342
372
  repeat a write. Reconcile an unconfirmed business mutation before another one.
343
373
 
344
374
  The first `review run`, `review list` or `review ls` asks for a repository when
345
- the file or `repositories` field is absent. To configure one in advance, run:
375
+ the file, `review` section or `review.repositories` field is absent. To configure
376
+ one in advance, run:
346
377
 
347
378
  ```bash
348
379
  daynight review add-repo https://github.com/OWNER/REPO.git
@@ -759,27 +790,108 @@ records binary transport and output ownership.
759
790
 
760
791
  ## Worker configuration and startup
761
792
 
762
- `daynight worker run` is a foreground process that claims eligible ready tasks
763
- across configured repositories and runs Copilot or Codex in a dedicated Herdr
764
- instance. The agent owns task delivery, acceptance, evidence and final
765
- claim-bound completion. The worker owns concurrency, resources, recovery and
766
- 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.
767
830
 
768
831
  Install Git, Herdr 0.9.5 or newer with protocol 22 capabilities, and the selected
769
- native agent on PATH. Native/provider authentication and the current official
770
- Herdr SessionStart integration must be configured explicitly. Codex needs the
771
- hooks feature and `--no-daemon`; Unix hook scripts need bash and python3, while
772
- Windows hooks need PowerShell. The worker reports missing capabilities or
773
- integration/history instead of installing or changing global native settings.
774
- Git transport and tools used by the task, such as authenticated GitHub CLI for
775
- PR delivery, must also be ready.
776
-
777
- Run `daynight login` for Daynight authentication. Add the following mapping to
778
- the shared `~/.daynight/config.yml`, preserving existing connection and review
779
- settings:
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.
839
+
840
+ Manage individual Project registrations with:
841
+
842
+ ```bash
843
+ daynight worker repo add
844
+ daynight worker repo list
845
+ daynight worker repo remove
846
+ ```
847
+
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:
854
+
855
+ ```bash
856
+ daynight worker repo add --project PROJECT_UUID
857
+ daynight worker repo remove --project PROJECT_UUID
858
+ daynight worker repo list --json
859
+ ```
860
+
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:
780
891
 
781
892
  ```yaml
782
893
  worker:
894
+ repositoryRoot: ~/daynights
783
895
  maxConcurrent: 1
784
896
  pollIntervalMs: 5000
785
897
  recoveryLimit: 3
@@ -796,286 +908,245 @@ worker:
796
908
  args: []
797
909
  ```
798
910
 
799
- These are the defaults for all optional worker fields; `repositories` is
800
- required. Each entry requires `remote` and `path`, with optional `projectId`,
801
- `agent`, `model` and `args`. The service project must already exist and match the
802
- repository. Add `projectId` when more than one project matches. Missing local
803
- repositories are cloned; existing roots and origins are verified without
804
- resetting their files or branches. Use the native authentication configuration
805
- for credentials, keeping credentials out of repository URLs and argument lists.
806
-
807
- Paths are absolute or relative to the configuration file's directory, never
808
- the launch directory. Tilde expansion and drive-relative Windows paths are
809
- rejected. Repository identities, project IDs and paths cannot duplicate or
810
- overlap, including the fixed Daynight state directory. Unknown worker fields,
811
- wrong types, invalid arguments and unsupported path shapes fail visibly.
812
- `maxConcurrent` is a positive integer, `recoveryLimit` is nonnegative and
813
- `pollIntervalMs` is a positive safe integer within the timer range.
814
-
815
- Repository agent settings override fields independently when the type stays
816
- the same; explicit null model or an empty args list clears that field. Switching
817
- agent type clears inherited model and arguments unless the repository explicitly
818
- sets them. Args replace the list rather than append. The recovery limit is
819
- worker-wide. Configuration loads at startup, without hot reload; existing claims
820
- keep their original frozen configuration after a restart, while later claims
821
- use the newly loaded settings.
822
-
823
- New tasks have automatic execution disabled. Enable it explicitly with the
824
- normal task update workflow after reading the current task/version. The worker
825
- selects only ready, permitted tasks compatible with its actual platform; WSL
826
- counts as Linux. It never enables that permission itself. Released tasks wait
827
- for explicit management and do not immediately re-enter ordinary automatic
828
- 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.
829
944
 
830
945
  ```bash
831
946
  daynight worker run
832
947
  ```
833
948
 
834
- The command generates and atomically saves a stable root `workerId` on first
835
- use. One foreground instance owns fixed `~/.daynight/worker/` state: its SQLite,
836
- instance lock, logs, temporary resources and private Herdr data. There is no
837
- state-path override. Each task uses `daynight/<task-id>` and
838
- `<repository>/.worktrees/daynight/<task-id>`. The same valid claim retains dirty
839
- work, native history and configuration; a new claim has a fresh execution
840
- identity and conversation.
841
-
842
- The worker verifies the startup credential through the existing current-user
843
- API and pins successful response identity, including empty pages. Each local
844
- claim retains its original Daynight user ID. If another account is logged in on
845
- the same OS account, the stable workerId stays the same, but that account's empty
846
- inventory cannot terminate or resume the previous account's work. Scope-paused
847
- records need the original account/identity inspected; do not remove local state
848
- or regenerate workerId to make the mismatch disappear. The running process
849
- keeps its startup credential; restart after an intended account change.
850
-
851
- Changing serverUrl also separates local responsibility from remote work. The
852
- worker queries and acquires only on its current service. Previously committed
853
- cleanup deadlines and normal shutdown cover that worker's local records across
854
- all original services, without calling an old API or asking the new service
855
- about old records. A newly granted current-service claim freezes its new
856
- configuration and waits pending behind any active predecessor with the same task UUID for that
857
- worker, including another origin. Read-only Git ownership attributes
858
- an occupied canonical path; it does not adopt the old conversation or config.
859
-
860
- The foreground stderr output and JSONL logs identify project/task/claim, platform,
861
- waiting, pause and cleanup errors. The log path is printed at startup. An
862
- unconfirmed claim request, native launch or input is retained for observation;
863
- it is not replayed. A pause still reserves capacity. Recovering missing original
864
- configuration, history or stop evidence requires inspection, without creating a
865
- replacement conversation to conceal the loss.
866
-
867
- For human input, copy the safe `attach` descriptor printed after the running
868
- worker has completed inventory and private managed-instance readiness.
869
- Invoke its `executable` with its `arguments` (`herdr --session w` for the default
870
- executable), apply exactly its `environment` overrides and remove the names in
871
- `unsetEnvironment` **only for that attach client process**. The descriptor's
872
- private XDG values select the worker's exact Herdr instance; the existing task
873
- pane keeps its original native XDG and private HISTFILE. The descriptor contains
874
- routing and native-home paths, not a dump of authentication values. Continue in
875
- the original task pane so the worker can observe the same execution.
876
-
877
- Native startup can be waiting at a folder-trust or authorization screen even
878
- when Herdr reports idle/interactiveReady. The worker checks the current Codex
879
- input surface before automatic text and Enter, reports a blocking reason and
880
- keeps the first prompt unsent. It does not choose native trust or change global
881
- trust configuration. Configure that prerequisite normally in the native tool or
882
- use the original attached task pane to make the decision explicitly, then leave
883
- the business composer available for input. This check does not inspect arbitrary
884
- human draft meaning or prove that a model consumed previously submitted text.
885
-
886
- The checked Codex startup/restart layout is the standard/default business
887
- composer together with a loaded model/reasoning and current-directory footer
888
- (`model-with-reasoning · current-dir`). Ask text or a version header alone is
889
- insufficient because provisional startup can show them too. A custom footer,
890
- cropped footer or otherwise unrecognized visible layout remains unknown; the
891
- original Operation bounds observation and ends not-submitted if that supported
892
- surface never appears. In the original session, finish any blocking decision
893
- and restore the supported standard native layout before requesting public retry.
894
- The worker does not change the layout, infer arbitrary draft meaning or turn
895
- this screen check into a native consumption receipt.
896
-
897
- For started executions, a successful complete own-claim inventory from the
898
- original account makes the original claim's absence cause
899
- the same terminal cleanup for done, release and transfer: request attributable
900
- outside-worktree cleanup for at most the original ten-minute deadline, confirm
901
- the original agent stopped, close its workspace, delete its worktree and retain
902
- local history. Failures keep responsibility and resume cleanup after restart.
903
- A failed, incomplete or differently scoped inventory cannot authorize a new
904
- terminal-cleanup decision. Already persisted cleanup/control intents continue in
905
- the same foreground process through a lightweight discovery loop and one
906
- transient asynchronous job per full claim, before current-user/project network
907
- requests and even during server read failures. Only already authorized intents
908
- with known original account scope advance; unknown-scope terminal/control
909
- intents remain preserved. Each job waits at most one second or its nearer
910
- original deadline, independently of pollIntervalMs. One task's held RPC does not
911
- postpone another task's next cleanup advance; per-task serialization still
912
- prevents overlapping operations on the same execution. There is no persisted job
913
- queue.
914
-
915
- Ctrl+C stops acquisition and ordinary input, cancels and joins the ordinary
916
- cleanup discovery loop and all per-claim jobs, then runs original-task shutdown
917
- with a separate bounded cancellation scope and a shared exit deadline.
918
- Unfinished claims, worktrees and native history remain; the private instance
919
- stops only after original agents are confirmed stopped. Stop uncertainty is
920
- reported and retains the instance/resources for inspection. Restart the command
921
- to reconcile with the same worker identity and original state. After consuming
922
- interrupted shutdown, the worker refreshes Herdr resources before ordinary
923
- execution. If a native launch may have occurred but its exact original session
924
- ID is missing, shutdown preserves its old binding, launch and PID evidence and
925
- pauses; it does not turn that execution into a first launch. Proven
926
- never-started work and executions with a known original native ID retain their
927
- normal recovery path.
928
-
929
- A causal worker cancellation propagates into shutdown without adding a fault
930
- pause. Existing real pauses, recovery budget and unknown-action records keep
931
- their meaning; an unrelated error is not normal cancellation merely because the
932
- signal is already aborted. Read-only interruption followed by successful
933
- shutdown can resume the original session through the normal recovery path.
934
-
935
- Pending successors whose resources, workspace and native launch are proven
936
- never started stay pending on normal exit. A successful complete inventory from
937
- the same original account can complete an absent unstarted claim directly,
938
- without activating it or touching an older claim's fixed Git path. Other tasks'
939
- shutdown initialization is isolated so one bad record does not prevent known
940
- agents stopping. Untracked resources or unknown scope keep the private instance
941
- when its stop cannot be confirmed.
942
-
943
- Linux, Windows and macOS complete Goal acceptance is separate from the installed
944
- runtime and its component checks. The
945
- [worker requirements](../../docs/spec/daynight-worker.md) and
946
- [worker design](../../docs/design/daynight-worker.md) own the behavior and
947
- mechanisms, including native capability limits.
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.
948
954
 
949
- ## Worker manual management
955
+ The local database has exactly these business fields:
950
956
 
951
- Manual commands select one task and its exact original claim. They use the same
952
- fixed SQLite and singleton lock as `worker run`. With a foreground worker, that
953
- process remains the sole agent controller and consumes the persisted decision;
954
- without one, the command acquires the same lock and advances the same coordinator
955
- for that execution. There is no separate control service. Current configuration
956
- and Daynight authentication are required, and the original service origin must
957
- match. Release, transfer and retry require the unfinished original local record;
958
- resume can use an explicit project with its configured repository.
957
+ ```text
958
+ projects(project_id, repo_url, local_path)
959
+ tasks(project_id, task_id, claim_id, status, agent, session_id)
960
+ ```
959
961
 
960
- Read the current task before deciding a versioned operation:
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:
961
1031
 
962
1032
  ```bash
963
- daynight task show <task-id> --json
964
- daynight worker release <task-id> --claim-id <source-claim-id> --if-version <version>
1033
+ daynight worker attach
965
1034
  ```
966
1035
 
967
- Release and transfer first verify project access and source owner/admin
968
- permission, then persist the concrete source decision before cleanup. The
969
- controller requests the original agent's attributable temporary-resource cleanup,
970
- waits for its original deadline of at most 10 minutes, confirms that agent stopped,
971
- closes its task workspace and deletes its worktree. Only then can it submit the
972
- remote write at the exact supplied version. Other tasks keep their shared Herdr
973
- instance. Failed stopping or deletion retains the source responsibility and a
974
- visible error. Cleanup keeps its original deadline after restart; each HTTP
975
- request has an independent bounded scope, without a five-minute total command
976
- limit.
977
-
978
- Release returns the task to `todo` and clears its execution interval. The daemon
979
- skips released tasks until explicitly resumed. Resume starts a fresh execution
980
- on this worker:
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. Logs are
1080
+ diagnostic only; they do not supply a second recovery ledger. The
1081
+ [worker requirements](../../docs/spec/daynight-worker.md) and
1082
+ [design](../../docs/design/daynight-worker.md) own full behavior and validation.
1083
+
1084
+ ## Worker manual management
1085
+
1086
+ Stop `daynight worker run` before retry, release or resume. Each command
1087
+ acquires the same instance lock and synchronously handles one specified claim;
1088
+ an occupied lock returns an instruction to stop the runner. Management does not
1089
+ write a durable intent or coordinate through a background request queue.
1090
+
1091
+ Retry performs one attempt for an active claim still owned by this worker:
981
1092
 
982
1093
  ```bash
983
- daynight worker resume <task-id> --claim-id <released-claim-id> --if-version <version> \
984
- --project <project-id>
1094
+ daynight worker retry <task-id> --claim-id <claim-id> --project <project-id>
985
1095
  ```
986
1096
 
987
- The previous claim must still be released and the task ready. The original owner
988
- or a current project admin may resume it, retaining the explicit manual exception
989
- to automatic permission and platform filters. The new claim and worktree IDs are
990
- generated and persisted before submission. Its actual grant commits local
991
- `pending` with this repository's current effective agent/model/args; `worker run`
992
- then performs ordinary capacity checks and prepares a fresh native conversation.
993
- The deleted source worktree and native history are not required. Run
994
- `daynight worker run` if the foreground worker is stopped.
1097
+ It connects the live agent or resumes its recorded native session. NULL emits
1098
+ Warning and starts a fresh conversation in the same task worktree. The claim
1099
+ and agent type remain; pending rows are started through normal run scheduling.
1100
+ After the attempt, run connects to the actual surviving resource. Retry does not
1101
+ persist a permit or a cumulative cross-restart budget.
995
1102
 
996
- Transfer explicitly identifies the target's current user, stable worker and
997
- machine descriptor, actual platform and selected agent:
1103
+ Release validates current Project access, source owner/admin, original claim
1104
+ and exact supplied version. Its ordering is:
998
1105
 
999
- ```bash
1000
- daynight worker transfer <task-id> --claim-id <source-claim-id> --if-version <version> \
1001
- --target-user-id <user-id> --target-worker-id <worker-id> \
1002
- --target-machine-id <machine-id> --target-machine-name "target-machine" \
1003
- --target-platform linux --target-agent codex
1106
+ ```text
1107
+ notify and stop agent → close workspace → submit remote change
1108
+ → confirm source ownership ended → delete worktree → local done
1004
1109
  ```
1005
1110
 
1006
- Use the intended receiver's actual descriptor and the explicitly selected new
1007
- agent type. A trace-free new transfer grant honors that agent even when the
1008
- receiver's current repository defaults select the other type. It freezes
1009
- `model: null` and `args: []` for that type, with the current recovery limit; a
1010
- matching type uses the current effective model/args. Existing pending snapshots
1011
- are retained. The source operator's owner/admin permission is checked separately
1012
- from the target's
1013
- current membership. Transfer still requires automatic execution permission,
1014
- platform compatibility and completed dependencies. It preserves `in_progress`
1015
- and the task's execution interval, installing a fresh target claim/worktree ID
1016
- with empty runtime associations. The receiver discovers its actual grant through
1017
- normal claim inventory and starts a new execution; an old task path still in use
1018
- blocks preparation. No source files, SQLite snapshots or native history are
1019
- transported. Target and source agents may differ. Public commands provide no
1020
- claim/worktree-ID override or continuity confirmation option; the service and
1021
- typed client reject deprecated `continuityConfirmed` input.
1022
-
1023
- For a paused execution that still belongs to the original owner, authorize one
1024
- extra recovery attempt:
1111
+ The worktree is retained until remote confirmation. A refusal leaves it available
1112
+ for original execution recovery; success followed by local deletion failure is
1113
+ finished by the next run's ordinary absent-claim cleanup. Stopping failure cannot
1114
+ supply stoppedConfirmed. Explicit --if-version is never replaced during cleanup.
1025
1115
 
1026
1116
  ```bash
1027
- daynight worker retry <task-id> --claim-id <claim-id>
1117
+ daynight worker release <task-id> --claim-id <claim-id> --if-version <version> \
1118
+ --project <project-id>
1028
1119
  ```
1029
1120
 
1030
- Retry preserves the original claim, worktree/native identity and frozen
1031
- settings, retaining the cumulative recovery count rather than resetting it.
1032
- Concurrent or repeated requests do not accumulate extra authorization or launch
1033
- a second agent. The controller consumes the single permit for that original
1034
- execution; a further failure remains visible. Retry cannot replace terminal
1035
- cleanup or recreate an execution that has ended.
1036
-
1037
- A native launch acknowledged before a blocking startup screen has a specific
1038
- continuation path when its first prompt is durably known unsent. Keep the
1039
- original worker/native session running and use another terminal to attach to
1040
- that original pane. Inspect the reported folder-trust/authorization requirement
1041
- and make the native decision yourself. Once the business composer is available,
1042
- run:
1121
+ Release returns the task to todo and clears its execution interval. Ordinary
1122
+ automatic acquisition skips released tasks until explicitly resumed:
1043
1123
 
1044
1124
  ```bash
1045
- daynight worker retry <task-id> --claim-id <original-claim-id> --project <project-id>
1125
+ daynight worker resume <task-id> --claim-id <released-claim-id> --if-version <version> \
1126
+ --project <project-id>
1046
1127
  ```
1047
1128
 
1048
- The controller first checks the original worktree, full binding, frozen argv,
1049
- workspace/launch evidence, same shell and every saved native key PID. Ordinary
1050
- child-process changes do not replace the original proof. After that read-only
1051
- identity check, it consumes one authorized recovery attempt (the cumulative
1052
- count increases by one, without reset) and can deliver the first prompt once in
1053
- the original native process without another agent.start or conversation. Missing
1054
- an official native ID before the first turn does not by itself block this
1055
- proven-unsent continuation. This is not permission to resend an earlier
1056
- submitted/unknown prompt, infer loss from an empty-looking composer or restart
1057
- an unproven missing-ID conversation. Legacy records with unknown native-process
1058
- role remain fenced; migration does not construct identity from foreground PID
1059
- order. Automated cleanup text and /exit use the same screen boundary; a blocking
1060
- screen is not accepted with Enter merely to finish shutdown.
1061
-
1062
- Management diagnostics identify the original claim and report persisted waiting,
1063
- completion, rejection or unknown results. Interrupting the command retains its
1064
- intent so the foreground controller or a later management invocation can
1065
- continue. An unknown release/transfer write is reconciled by reading the actual
1066
- task and saved target claim; it is never resent or assigned replacement IDs,
1067
- even when a read still shows the old value. Reinvoking that same decision can
1068
- reconcile its result by targeted reads, including beside a running foreground
1069
- worker, without taking over resource control or resubmitting. An already-cleaned
1070
- source is not restarted. Only a definitely rejected submission can be replaced by a new explicit
1071
- decision, with the supplied `--if-version` matching a fresh task observation. The
1072
- numeric version may remain the same when the refusal did not change the task,
1073
- including a definite pre-dispatch failure or permission refusal. An unknown
1074
- submission cannot be reset or replayed; `--if-version` is never silently replaced.
1075
- Unknown resume requests likewise retain their original claim/worktree/config
1076
- until the actual grant can be confirmed. These targeted reads reconcile manual
1077
- writes; automatic cleanup still relies only on a complete successful inventory
1078
- for the original authenticated user and worker.
1129
+ Resume requires the previous released claim, ready task and original owner/admin.
1130
+ It preserves the explicit manual permission/platform exception, obtains fresh
1131
+ claim/worktree identities with current settings, and registers pending with a
1132
+ NULL native session ID. Start run to execute it.
1133
+
1134
+ Web task details show the current claiming user, machine, agent and phase. The
1135
+ original owner or a project admin can confirm **Force withdraw** for active or
1136
+ released ownership. This submits the reviewed claim ID and exact version,
1137
+ atomically clears worker ownership, returns the task to `todo`, clears both
1138
+ execution timestamps and sets `allowAgents=false`. Other task materials remain.
1139
+ It requires no stopped confirmation and does not guarantee that the remote agent
1140
+ stops immediately. On its next successful complete own-claim inventory, the
1141
+ original worker discovers its claim is absent and starts terminal cleanup.
1142
+ Automatic selection stays disabled until explicitly enabled again. There is no
1143
+ CLI withdrawal command or target-execution handoff.
1144
+
1145
+ Fresh IDs are generated and printed before remote submission. An unknown response
1146
+ is reconciled by GET without replaying the write. If the result remains unknown
1147
+ or the command is interrupted, inspect the remote task and claim before starting
1148
+ run again; management has no cross-process intent continuation. A definite refusal
1149
+ allows a new explicit decision with a freshly observed exact version.
1079
1150
 
1080
1151
  ## Review configuration and startup
1081
1152
 
@@ -1095,23 +1166,29 @@ cloning, authentication checks, GitHub calls, SQLite initialization and PR bound
1095
1166
  selection belong to review startup. An already running reviewer keeps its loaded
1096
1167
  configuration until its next startup.
1097
1168
 
1098
- The same YAML also accepts the server client's `serverUrl` and optional
1099
- `serverToken` fields. Review validates its own fields independently of server
1100
- business values. The server projection requires a valid HTTP(S) origin and
1101
- validates any configured token and its transport. The shared parser still rejects
1102
- invalid YAML, duplicate keys and unknown root fields. Registration can add the
1103
- first review repository to a server-only file while preserving its server
1104
- settings and comments.
1169
+ All review settings belong under the `review` mapping. The same YAML also
1170
+ accepts the server client's `serverUrl` and optional `serverToken` fields, the
1171
+ `worker` mapping and generated `workerId`. Review validates its own fields
1172
+ independently of server business values. The server projection requires a valid HTTP(S) origin and
1173
+ validates any configured token and its transport. The shared parser rejects invalid YAML, duplicate keys and a non-mapping root.
1174
+ Unknown fields at the root, inside `review` or `worker`, and in their repository
1175
+ entries are ignored by runtime projections and preserved by configuration edits.
1176
+ Known fields retain their type and value validation. Registration can add the
1177
+ first review repository to a server-only file while preserving its settings and
1178
+ comments. Flat review settings are ignored; move `repositoryRoot`, `repositories`,
1179
+ numeric options and Copilot options under `review` to use them. The CLI does not
1180
+ migrate these fields.
1105
1181
 
1106
1182
  A configuration with an explicit addition root is:
1107
1183
 
1108
1184
  ```yaml
1109
- repositoryRoot: ~/daynights
1110
- copilotModel: auto
1111
- copilotReasoningEffort: high
1112
- repositories:
1113
- - remote: https://github.com/OWNER/REPO.git
1114
- path: ../daynights/github.com/owner/repo
1185
+ review:
1186
+ repositoryRoot: ~/daynights
1187
+ copilotModel: auto
1188
+ copilotReasoningEffort: high
1189
+ repositories:
1190
+ - remote: https://github.com/OWNER/REPO.git
1191
+ path: ../daynights/github.com/owner/repo
1115
1192
  ```
1116
1193
 
1117
1194
  `copilotModel` and `copilotReasoningEffort` are independent optional fields for
@@ -1123,11 +1200,11 @@ effort levels and model/effort compatibility; Daynight maintains no static lists
1123
1200
  corresponding override and preserves Copilot's choice, so neither, either or both
1124
1201
  may be configured. Changes take effect on the next `review run` startup. Guided configuration
1125
1202
  and repository registration preserve both fields and YAML comments. The server
1126
- configuration projection recognizes these shared keys without validating their
1203
+ configuration projection recognizes the `review` section without validating its
1127
1204
  review-owned values.
1128
1205
 
1129
- `repositoryRoot` defaults to `~/daynights`. It is used only when `add-repo` has no
1130
- `--path`: the command derives filesystem-safe components from the normalized
1206
+ `review.repositoryRoot` defaults to `~/daynights`. It is used only when
1207
+ `add-repo` has no `--path`: the command derives filesystem-safe components from the normalized
1131
1208
  host/owner/name and saves the resulting absolute repository path. A configured
1132
1209
  root may be absolute, config-directory-relative, or begin with `~` for the current
1133
1210
  OS user's home. Other users' tilde forms are rejected. Changing the root affects
@@ -1152,7 +1229,7 @@ configuration containing `serverToken` uses POSIX mode `0600`; without a token,
1152
1229
  existing file-mode behavior is preserved.
1153
1230
 
1154
1231
  Numeric options use the documented [configuration defaults](../../docs/design/daynight-review.md#使用方式与配置)
1155
- when omitted. Explicit invalid values, unsupported fields, duplicate YAML keys and
1232
+ when omitted. Explicit invalid values for known fields, duplicate YAML keys and
1156
1233
  malformed documents produce nonzero exits with useful errors. Missing configuration
1157
1234
  triggers the [configuration setup](#configuration-setup) rules before review
1158
1235
  startup. Duplicate repository identities,