@hagicode/cli 0.1.0-dev.42.1.b13f8d2 → 0.1.0-dev.47.1.f8624d4
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 +81 -8
- package/dist/chunks/main-CAH7GrRu.js +251 -0
- package/dist/cli.js +1 -1
- package/dist/main.js +1 -1
- package/package.json +4 -3
- package/resources/saga/.gitignore +1 -0
- package/resources/saga/manifest.json +12 -0
- package/resources/saga/prompts/acceptance.md +15 -0
- package/resources/saga/prompts/amend.md +10 -0
- package/resources/saga/prompts/goal.md +23 -0
- package/resources/saga/prompts/plan.md +16 -0
- package/resources/saga/prompts/research.md +16 -0
- package/resources/saga/prompts/run.md +18 -0
- package/skills/README.md +1 -0
- package/skills/hagi/SKILL.md +23 -2
- package/skills/hagi/agents/openai.yaml +2 -2
- package/skills/hagi/references/cli-usage.md +63 -6
- package/skills/hagi/references/local-development.md +10 -0
- package/skills/hagi/references/resource-lock.md +135 -0
- package/skills/hagi/references/saga.md +189 -0
- package/skills/hagi/references/session-data.md +14 -0
- package/skills/hagi/references/validation.md +6 -2
- package/dist/chunks/main-CGAPe6tb.js +0 -179
package/README.md
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@hagicode/cli)
|
|
6
6
|
[](https://nodejs.org/)
|
|
7
7
|
|
|
8
|
-
`@hagicode/cli` provides the published `hagi` command, which lets you drive a HagiCode backend from a terminal, scripts, or an AI agent without opening the app. Manage projects, proposals (generate, execute, archive, and send), vaults and their files, chat sessions, HagiTasks, scheduled plans, and skills (local list, enable, disable and uninstall, gallery search and install, and trusted providers). Every command supports a shared `--json` output for scripting, and an embedded Hagi skill under [`skills/`](skills/) guides agent workflows.
|
|
8
|
+
`@hagicode/cli` provides the published `hagi` command, which lets you drive a HagiCode backend from a terminal, scripts, or an AI agent without opening the app. Manage projects, proposals (generate, execute, archive, and send), local Sagas, vaults and their files, chat sessions, HagiTasks, scheduled plans, and skills (local list, enable, disable and uninstall, gallery search and install, and trusted providers). Every command supports a shared `--json` output for scripting, and an embedded Hagi skill under [`skills/`](skills/) guides agent workflows.
|
|
9
9
|
|
|
10
10
|
## Requirements
|
|
11
11
|
|
|
12
12
|
- Node.js 24+
|
|
13
|
-
- Access to a HagiCode backend API
|
|
13
|
+
- Access to a HagiCode backend API for backend-selected commands; Saga commands with `--path` work locally without one
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -76,9 +76,44 @@ Example:
|
|
|
76
76
|
hagi --base-url https://api.example.com --token "$HAGI_TOKEN" project list --json
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
## Saga Commands
|
|
80
|
+
|
|
81
|
+
Each Saga command requires exactly one project selector: `--path <directory>` or `--project-id <id>`. Missing, empty,
|
|
82
|
+
or conflicting selectors exit with code `2`. `--path` is resolved on the CLI host, relative to the current directory,
|
|
83
|
+
and does not read backend configuration or contact the backend; backend flags do not change local behavior. Quote paths
|
|
84
|
+
that contain spaces.
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
hagi saga init --path "./My Project"
|
|
88
|
+
hagi saga new demo --path "./My Project" --json
|
|
89
|
+
hagi saga list --path "./My Project"
|
|
90
|
+
hagi saga status demo --project-id <project-id> --json
|
|
91
|
+
hagi saga items demo --path "./My Project" --json
|
|
92
|
+
hagi saga claim demo --path "./My Project" --session orchestrator-1 --json
|
|
93
|
+
hagi saga check demo --path "./My Project" --phase run --json
|
|
94
|
+
hagi saga tick demo T1 --path "./My Project" --token "$SAGA_EXECUTION_TOKEN" --json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Write and check commands (`claim`, `assert-owner`, `release`, `freeze`, `check`, `tick`, `block`, `set-status`, `amend`,
|
|
98
|
+
`archive`) run in the CLI itself; the CLI installs only the six method prompts and the ignore rule, and no standalone Saga tool. Mutating commands read the execution token
|
|
99
|
+
from `--token` or `SAGA_EXECUTION_TOKEN`; with `--project-id`, `--token` is rejected because it is the backend token, so use
|
|
100
|
+
`SAGA_EXECUTION_TOKEN` there. Exit code `0` means success, `1` a refusal or failed check, and `2` a usage error.
|
|
101
|
+
|
|
102
|
+
With `--project-id`, the CLI uses the normal base URL, token, and language settings to resolve the project through the
|
|
103
|
+
backend. The returned project path must exist on the machine running the CLI; it is not a remote filesystem path.
|
|
104
|
+
|
|
105
|
+
`saga init` installs managed resources without overwriting differing files by default: it preserves conflicts, installs
|
|
106
|
+
missing resources, and reports each file outcome. Conflicts exit with code `4`; `--force` replaces differing managed
|
|
107
|
+
resources, while `.gitignore` is always merged additively. Initialization refuses redirected or unsafe targets and
|
|
108
|
+
leaves identical resources untouched on repeat runs. See the [Saga command reference](skills/hagi/references/saga.md)
|
|
109
|
+
for outcomes, safety behavior, and JSON details.
|
|
110
|
+
|
|
111
|
+
For offline use, install the package or use a cached `npx` package. An uncached `npx @hagicode/cli` invocation may need
|
|
112
|
+
network access to download the package even though `saga ... --path` itself does not use a backend.
|
|
113
|
+
|
|
79
114
|
## Connection Setup
|
|
80
115
|
|
|
81
|
-
Every operation
|
|
116
|
+
Every backend operation resolves the base URL on each invocation, in this order:
|
|
82
117
|
|
|
83
118
|
1. `--base-url <url>` flag
|
|
84
119
|
2. `HAGI_API_BASE_URL` environment variable
|
|
@@ -91,7 +126,9 @@ Every operation command resolves the backend base URL on each invocation, in thi
|
|
|
91
126
|
}
|
|
92
127
|
```
|
|
93
128
|
|
|
94
|
-
If none of the three is set,
|
|
129
|
+
If none of the three is set, a backend operation exits with code `2` and sends no backend request. Saga commands using
|
|
130
|
+
`--path` bypass this resolution and do not read backend configuration. The `steer` key is the default for `hagi chat send`,
|
|
131
|
+
`hagi proposal send`, and `hagi hagitask send` (see [Steer](#steer-send-option)); it must be `true` or `false`.
|
|
95
132
|
|
|
96
133
|
Operation commands send requests without a credential by default. Pass `--token` (or set `HAGI_API_TOKEN`) only when your backend requires one.
|
|
97
134
|
|
|
@@ -112,14 +149,16 @@ hagi
|
|
|
112
149
|
|-- project list | repositories | create | update | delete
|
|
113
150
|
| `-- monospecs show | init | set | validate | reload | clone | remove-checkout
|
|
114
151
|
|-- proposal list | create | optimize-description | generate | annotate | execute | archive | status | complete | send | get | messages
|
|
152
|
+
|-- saga init | new | list | status | items | claim | assert-owner | release | freeze | check | tick | block | set-status | amend | archive
|
|
115
153
|
|-- vault list | create | update | delete
|
|
116
154
|
| `-- files list | preview
|
|
117
155
|
|-- chat list | create | archive | delete | send
|
|
118
156
|
|-- hagitask list | schema | create | send | get | messages
|
|
119
157
|
|-- plan list | get | create | update | enable | disable | delete | run
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
158
|
+
|-- skills local list | enable | disable | uninstall
|
|
159
|
+
| gallery search | detail | install
|
|
160
|
+
| trusted list | upsert | delete | reset
|
|
161
|
+
`-- agent lock acquire | status | renew | heartbeat | release | requisition | list
|
|
123
162
|
```
|
|
124
163
|
|
|
125
164
|
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 +718,39 @@ hagi skills trusted delete --provider-id example-provider
|
|
|
679
718
|
hagi skills trusted reset
|
|
680
719
|
```
|
|
681
720
|
|
|
721
|
+
## Agent Lock Commands
|
|
722
|
+
|
|
723
|
+
`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).
|
|
724
|
+
|
|
725
|
+
```bash
|
|
726
|
+
hagi agent lock acquire --lock-id eu-1/duckov --owner sess-7f2c
|
|
727
|
+
hagi agent lock acquire --server eu-1 --game duckov --owner sess-7f2c --wait --timeout 900
|
|
728
|
+
hagi agent lock status --lock-id eu-1/duckov --owner sess-7f2c --json
|
|
729
|
+
hagi agent lock heartbeat --lock-id eu-1/duckov --owner sess-7f2c --epoch 7
|
|
730
|
+
hagi agent lock release --lock-id eu-1/duckov --owner sess-7f2c --epoch 7
|
|
731
|
+
hagi agent lock requisition --lock-id eu-1/duckov --owner sess-7f2c --reason "User order: take the lock now"
|
|
732
|
+
hagi agent lock list --prefix eu-1/
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
- 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.
|
|
736
|
+
- 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`.
|
|
737
|
+
- `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.
|
|
738
|
+
- `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.
|
|
739
|
+
- `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.
|
|
740
|
+
- `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.
|
|
741
|
+
- Answers show the valid-until time, the 24-hour hard cap, the check-in window and, for a queued owner, the turn window.
|
|
742
|
+
|
|
743
|
+
| Timing | Default |
|
|
744
|
+
| --- | --- |
|
|
745
|
+
| Feedback timeout (no heartbeat releases the lock) | 10 minutes |
|
|
746
|
+
| Maximum hold | 24 hours |
|
|
747
|
+
| Heartbeat interval | 2 minutes |
|
|
748
|
+
| Claim window after a handoff | 30 seconds |
|
|
749
|
+
| Waiter TTL | 60 seconds |
|
|
750
|
+
| `acquire --wait` timeout | 900 seconds |
|
|
751
|
+
|
|
752
|
+
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.
|
|
753
|
+
|
|
682
754
|
## Steer (send option)
|
|
683
755
|
|
|
684
756
|
`hagi chat send`, `hagi proposal send`, and `hagi hagitask send` deliver a message in one of two ways:
|
|
@@ -748,7 +820,8 @@ Stable non-zero exits used by the CLI. The HTTP numbers are the equivalents of t
|
|
|
748
820
|
| `24` | HTTP 404 |
|
|
749
821
|
| `29` | HTTP 409 |
|
|
750
822
|
| `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 `
|
|
823
|
+
| `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 |
|
|
824
|
+
| `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
825
|
| `40` | Other HTTP 4xx |
|
|
753
826
|
| `50` | HTTP 5xx |
|
|
754
827
|
| `60` | Transport or connection failure |
|