@hagicode/cli 0.1.0-dev.42.1.b13f8d2 → 0.1.0-dev.43.1.03d9a6a

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.
package/README.md CHANGED
@@ -117,9 +117,10 @@ hagi
117
117
  |-- chat list | create | archive | delete | send
118
118
  |-- hagitask list | schema | create | send | get | messages
119
119
  |-- plan list | get | create | update | enable | disable | delete | run
120
- `-- skills local list | enable | disable | uninstall
121
- gallery search | detail | install
122
- trusted list | upsert | delete | reset
120
+ |-- skills local list | enable | disable | uninstall
121
+ | gallery search | detail | install
122
+ | trusted list | upsert | delete | reset
123
+ `-- agent lock acquire | status | renew | heartbeat | release | requisition | list
123
124
  ```
124
125
 
125
126
  The `send` commands of `chat`, `proposal`, and `hagitask` also take `--steer` and `--no-steer`, and `HAGI_SEND_STEER` sets the default. See [Steer](#steer-send-option).
@@ -679,6 +680,39 @@ hagi skills trusted delete --provider-id example-provider
679
680
  hagi skills trusted reset
680
681
  ```
681
682
 
683
+ ## Agent Lock Commands
684
+
685
+ `hagi agent lock` lets several agents take turns on one shared resource, such as a game server that only one agent may use at a time. The backend keeps a fair queue per lock; the lock is cooperative and cannot stop an action already running on the remote resource. There is no top-level `hagi lock`. The agent-facing protocol is in [`skills/hagi/references/resource-lock.md`](skills/hagi/references/resource-lock.md).
686
+
687
+ ```bash
688
+ hagi agent lock acquire --lock-id eu-1/duckov --owner sess-7f2c
689
+ hagi agent lock acquire --server eu-1 --game duckov --owner sess-7f2c --wait --timeout 900
690
+ hagi agent lock status --lock-id eu-1/duckov --owner sess-7f2c --json
691
+ hagi agent lock heartbeat --lock-id eu-1/duckov --owner sess-7f2c --epoch 7
692
+ hagi agent lock release --lock-id eu-1/duckov --owner sess-7f2c --epoch 7
693
+ hagi agent lock requisition --lock-id eu-1/duckov --owner sess-7f2c --reason "User order: take the lock now"
694
+ hagi agent lock list --prefix eu-1/
695
+ ```
696
+
697
+ - Lock: `--lock-id <id>` (one to four `/`-separated segments) or `--server <name> --game <name>`, which means `<server>/<game>`. Giving both forms, or only one of `--server` and `--game`, exits `2` before any request.
698
+ - Owner: `--owner <id>`, then `HAGI_LOCK_OWNER`, then `HAGI_SESSION_ID`. An agent passes its own session ID. The CLI never invents or stores an owner ID; with none set it exits `2`.
699
+ - `acquire` takes the lock or joins the queue and exits `0` for `Holding` and `Queued`. `acquire --wait` long-polls until the owner holds the lock (exit `0`), the `--timeout` passes (default 900 seconds, exit `31`, the queue entry it created is released), or the entry is dropped (exit `32`). Ctrl-C releases the entry it created and never a lock held before. `acquire` has no force option.
700
+ - `status` reads one owner's state (`Holding`, `Queued`, `Expired`, `Requisitioned`, `None`) and exits `0` for all of them; `--wait-seconds` long-polls. `renew` sends one renewal. `release` exits `0` whether or not anything was released. `list` shows the busy locks; `--prefix` filters them.
701
+ - `heartbeat` renews at once and then every `--interval` seconds (default 120), is quiet on success (`--verbose` prints each beat), prints a line and exits `32` when the lock is lost, retries transport errors with backoff and never reports them as loss. SIGINT or SIGTERM ends it with exit `0` and does not release. Run it under a Monitor or another watcher.
702
+ - `requisition` requires `--reason` (1 to 200 characters), takes the lock at once, and displaces the holder, who is told by its next heartbeat. Use it only when a user explicitly ordered a forced take.
703
+ - Answers show the valid-until time, the 24-hour hard cap, the check-in window and, for a queued owner, the turn window.
704
+
705
+ | Timing | Default |
706
+ | --- | --- |
707
+ | Feedback timeout (no heartbeat releases the lock) | 10 minutes |
708
+ | Maximum hold | 24 hours |
709
+ | Heartbeat interval | 2 minutes |
710
+ | Claim window after a handoff | 30 seconds |
711
+ | Waiter TTL | 60 seconds |
712
+ | `acquire --wait` timeout | 900 seconds |
713
+
714
+ Agent loop: `acquire`, read the windows, start `heartbeat` under a watcher before any work (or, when queued, a continuous `acquire --wait` watcher), stop the heartbeat when done and then `release`, and stop using the resource as soon as a command exits `32`. After losing track, repeat `acquire` with the same owner; it is safe.
715
+
682
716
  ## Steer (send option)
683
717
 
684
718
  `hagi chat send`, `hagi proposal send`, and `hagi hagitask send` deliver a message in one of two ways:
@@ -748,7 +782,8 @@ Stable non-zero exits used by the CLI. The HTTP numbers are the equivalents of t
748
782
  | `24` | HTTP 404 |
749
783
  | `29` | HTTP 409 |
750
784
  | `30` | Operation failed: the backend returned a refusal, for example `skills local enable` or `disable` on a name that is not a built-in skill, an invalid MonoSpecs configuration from `project monospecs validate`, or a failed clone from `project monospecs clone` or `set --clone` |
751
- | `31` | Wait timed out: `--wait` on `proposal get` or `hagitask get` reached `--timeout` before the session settled. The last status is printed. Not a success, and not a backend error |
785
+ | `31` | Wait timed out: `--wait` on `proposal get`, `hagitask get` or `agent lock acquire` reached `--timeout` before the session settled. The last status is printed. Not a success, and not a backend error |
786
+ | `32` | Lock lost: a `hagi agent lock` command learned that the owner no longer holds the lock (expired, taken back at the 24-hour cap, stale epoch, requisitioned). Stop using the resource. Distinct from `31` |
752
787
  | `40` | Other HTTP 4xx |
753
788
  | `50` | HTTP 5xx |
754
789
  | `60` | Transport or connection failure |