@dayzehq/cli 0.0.0-stage → 0.2.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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +305 -2
  3. package/dist/add.d.ts +6 -0
  4. package/dist/add.js +72 -0
  5. package/dist/admin.d.ts +110 -0
  6. package/dist/admin.js +408 -0
  7. package/dist/agent-bridge.d.ts +50 -0
  8. package/dist/agent-bridge.js +146 -0
  9. package/dist/agent-mcp.d.ts +4 -0
  10. package/dist/agent-mcp.js +36 -0
  11. package/dist/ai-consent.d.ts +18 -0
  12. package/dist/ai-consent.js +93 -0
  13. package/dist/args.d.ts +5 -0
  14. package/dist/args.js +127 -0
  15. package/dist/auth.d.ts +20 -0
  16. package/dist/auth.js +198 -0
  17. package/dist/channel.d.ts +55 -0
  18. package/dist/channel.js +250 -0
  19. package/dist/chat.d.ts +67 -0
  20. package/dist/chat.js +170 -0
  21. package/dist/cli-errors.d.ts +13 -0
  22. package/dist/cli-errors.js +30 -0
  23. package/dist/coding-context.d.ts +12 -0
  24. package/dist/coding-context.js +130 -0
  25. package/dist/coding.d.ts +35 -0
  26. package/dist/coding.js +283 -0
  27. package/dist/config.d.ts +36 -0
  28. package/dist/config.js +149 -0
  29. package/dist/day.d.ts +22 -0
  30. package/dist/day.js +54 -0
  31. package/dist/dayze-cli-runtime +0 -0
  32. package/dist/dayze-days.d.ts +56 -0
  33. package/dist/dayze-days.js +276 -0
  34. package/dist/doctor.d.ts +32 -0
  35. package/dist/doctor.js +225 -0
  36. package/dist/focus.d.ts +9 -0
  37. package/dist/focus.js +163 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +675 -0
  40. package/dist/inventory.d.ts +73 -0
  41. package/dist/inventory.js +1272 -0
  42. package/dist/life.d.ts +48 -0
  43. package/dist/life.js +146 -0
  44. package/dist/me.d.ts +94 -0
  45. package/dist/me.js +789 -0
  46. package/dist/people.d.ts +232 -0
  47. package/dist/people.js +2034 -0
  48. package/dist/projects.d.ts +21 -0
  49. package/dist/projects.js +132 -0
  50. package/dist/request-deadline.d.ts +11 -0
  51. package/dist/request-deadline.js +34 -0
  52. package/dist/runtime-build.json +1 -0
  53. package/dist/ui.d.ts +37 -0
  54. package/dist/ui.js +219 -0
  55. package/dist/version.d.ts +4 -0
  56. package/dist/version.js +16 -0
  57. package/package.json +54 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Phi Digital LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,306 @@
1
- # Temporary Holding Version
1
+ # Dayze CLI
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `dayze code` opens a project coding session. `dayze runtimes` discovers installed
4
+ provider connections. Existing Dayze data commands and the cloud Agent remain available.
5
+
6
+ ```sh
7
+ dayze code --runtime codex --project ./my-app
8
+ dayze code --runtime claude --project ./my-app --context profile,projects
9
+ ```
10
+
11
+ Use `/model` to list models advertised by the connected provider, then
12
+ `/model 2` or `/model <id>` to choose one. `/runtime codex` and `/runtime claude`
13
+ start fresh provider sessions. `/new` clears the current session; `/exit` leaves it.
14
+ Ctrl+C stops the session. Inspect any interrupted action before repeating it.
15
+
16
+ Coding sessions use the pinned Dayze Desktop runtime engine, with its ordinary
17
+ provider-owned sign-in, project tools, streamed replies and one-time approvals.
18
+ The chosen project is the working folder, not a security boundary for every
19
+ provider read. Runtime safeguards and permission requests still apply. Cursor and
20
+ other discovered CLIs are listed honestly as lacking a coding adapter in this version.
21
+
22
+ Life context is **off by default**. Choose `--context profile,people,calendar,projects`
23
+ or any subset. Sharing requires your existing Dayze AI-sharing consent plus an
24
+ explicit terminal confirmation for that provider. Only selected read tools are
25
+ exposed; they re-check account identity and consent for every call, return bounded
26
+ results, and cannot change Dayze records. Calendar context depends on the separately
27
+ deployed `/api/cli/events` route. API-key consent checks require the read-only
28
+ `/api/cli/ai-sharing-consent` route in that same server update. The CLI cannot grant
29
+ consent. Profile context excludes network/session details.
30
+ Change selections by starting a new session. Previously shared information cannot
31
+ be withdrawn from a provider's history by changing a local setting.
32
+
33
+ Release maintainers run `npm ci`, `npm run build:all` in `cli`. This builds and bundles
34
+ the native helper for the current platform/architecture; end users of that package
35
+ do not need Rust or the Desktop source. The build needs Rust and Git access to the
36
+ exact Desktop revision pinned in `runtime/Cargo.toml`. Provider adapters must already
37
+ be installed through Dayze Desktop, PATH, or the supported existing Buzz install.
38
+ No adapter, credential or model is silently downloaded or substituted. Packages
39
+ must be built and validated separately for each supported platform.
40
+
41
+ Terminal agent for your life OS — Cursor-style session, same tools as web Dayze Agent.
42
+
43
+ ```text
44
+ ◆ Dayze agent v0.2.0
45
+ ────────────────────────────────────────────────────
46
+ api https://dayze.com
47
+ auth api key dayze_k_…
48
+ ────────────────────────────────────────────────────
49
+ Enter to chat · /help for commands · Ctrl+C to exit
50
+
51
+ ❯ what's on my calendar this week?
52
+ ⋮ Understanding your request...
53
+ ⚡ …
54
+ ● Dayze
55
+ …
56
+ ```
57
+
58
+ ## Install
59
+
60
+ `dayze` is not on the public npm registry yet (`npm view dayze` → 404). The package is publish-ready (PHI-2091); until Luke publishes, install from this monorepo with `npm link`:
61
+
62
+ ```bash
63
+ cd cli
64
+ npm install
65
+ npm run build
66
+ npm link # `dayze` on PATH
67
+ ```
68
+
69
+ After publish:
70
+
71
+ ```bash
72
+ npm i -g dayze
73
+ ```
74
+
75
+ ## Login
76
+
77
+ **API key** (recommended) — [Settings → Agent access](https://dayze.com/settings/agent-access), enable **Actions**:
78
+
79
+ ```bash
80
+ dayze login --key 'dayze_k_…'
81
+ # local Next:
82
+ dayze login --api http://127.0.0.1:3000 --key 'dayze_k_…'
83
+ ```
84
+
85
+ **Email** / password also supported (`dayze login --email` / `--password`).
86
+
87
+ ## Commands
88
+
89
+ Matches `dayze help` (`printHelp` in `cli/src/ui.ts`):
90
+
91
+ | | |
92
+ |--|--|
93
+ | `dayze` | Interactive agent (default) |
94
+ | `dayze agent` | Same as default |
95
+ | `dayze ask "…"` | One-shot question |
96
+ | `dayze people` | Address book (all contacts · type to filter) |
97
+ | `dayze people list` | Print full directory |
98
+ | `dayze people add NAME` | Create contact (non-interactive) |
99
+ | `dayze people show NAME` | Contact details |
100
+ | `dayze people paid-for NAME` | What they paid for you |
101
+ | `dayze people log NAME` | Log interaction |
102
+ | `dayze people alias …` | Add nickname |
103
+ | `dayze people merge …` | Merge duplicates |
104
+ | `dayze inventory` | Life Inventory (↑↓ Enter · Ctrl+S sort · d delete) |
105
+ | `dayze inventory list` | Print items `[--sort=price\|name\|updated]` |
106
+ | `dayze inventory add NAME` | Create item (non-interactive) |
107
+ | `dayze inventory show NAME` | Item detail |
108
+ | `dayze inventory delete NAME` | Remove item |
109
+ | `dayze life show --kind=… --id=…` | Life Schema entity envelope |
110
+ | `dayze channel list` | IRC-style channels (PHI-2102 stub) |
111
+ | `dayze channel join NAME` | Join a channel (stub) |
112
+ | `dayze channel leave NAME` | Leave a channel (stub) |
113
+ | `dayze channel send NAME "…"` | Send a channel message (stub) |
114
+ | `dayze channel read NAME` | Read channel messages `[--limit=N]` (stub) |
115
+ | `dayze admin users [q]` | Admin users list/search (superuser session) |
116
+ | `dayze admin cost` | Admin AI cost summary `[--days=7\|30\|90]` |
117
+ | `dayze admin flags` | Admin config readiness (bot-config) |
118
+ | `dayze admin health` | Admin dependency health checks |
119
+ | `dayze admin support` | Support / feedback queue summary |
120
+ | `dayze admin audit` | Operational audit list (bot_logs) |
121
+ | `dayze me` | Your dossier (`a` agent · `e` edit) |
122
+ | `dayze me --public-ip` | Same, plus opt-in third-party public-IP lookup |
123
+ | `dayze projects` | List portfolio (no LLM) |
124
+ | `dayze projects list` | List portfolio (no LLM) |
125
+ | `dayze projects show SLUG` | Project details and KPIs |
126
+ | `dayze projects create "Name"` | Create project (see `dayze projects help`) |
127
+ | `dayze day` | Your Day Age (local math · no LLM) |
128
+ | `dayze day --agent` | Same via Agent (uses quota / consent) |
129
+ | `dayze focus` | Today's 1–3 platform priorities |
130
+ | `dayze focus add "…"` | Add priority `[--bet=1\|2\|3]` |
131
+ | `dayze login [--key …]` | Sign in |
132
+ | `dayze logout` | Sign out |
133
+ | `dayze whoami` | Auth / credentials only |
134
+ | `dayze consent status` | AI sharing consent (Settings → Privacy) |
135
+ | `dayze doctor` | First-run checklist (auth / host / consent) |
136
+ | `dayze status` | Banner + whoami |
137
+ | `dayze help` | This help |
138
+
139
+ ### Flags
140
+
141
+ | | |
142
+ |--|--|
143
+ | `--key dayze_k_…` | API key (Actions scope) |
144
+ | `--email` / `--password` | Session login |
145
+ | `--api https://dayze.com` | API host (default; use localhost:3000 only for local Next) |
146
+ | `--quiet` | Hide thinking / tool traces |
147
+ | `--json` | Machine-readable JSON (ask · day · people add/list/show/paid-for · life show · admin · projects list/show/create · focus list · channel · me · inventory add/list) |
148
+ | `--agent` | For `dayze day`: ask the Agent instead of local math |
149
+ | `--public-ip` | Opt in to api.ipify.org for live egress IP on `dayze me` (off by default) |
150
+
151
+ ### In session
152
+
153
+ `/help` · `/new` · `/clear` · `/people` · `/inventory` · `/me` · `/status` · `/api <url>` · `/exit`
154
+
155
+ Shortcuts work without slash: `people` · `inventory` · `me` · `focus`
156
+
157
+ ### Address book
158
+
159
+ | | |
160
+ |--|--|
161
+ | `dayze people` | Interactive (↑↓ Enter · type to filter) |
162
+ | `dayze people list` | All contacts (pipe: `\| less`) |
163
+ | `dayze people show "Leah"` | One contact |
164
+ | `dayze people paid-for "Leah"` | What they paid for on your behalf |
165
+ | `dayze people help` | Keyboard + subcommands |
166
+
167
+ Detail keys: `a` agent · `e` edit · `n` note
168
+
169
+ ### Add contacts and inventory without prompts
170
+
171
+ These commands use the Actions scope and the web create validators. They do not call the Agent.
172
+ Pass a quoted name (or `--name`), followed by `--flag=value` or `--flag value`:
173
+
174
+ ```bash
175
+ dayze people add "Maya Chen" --email maya@example.com --phone "+65 8123 4567" --birthday 1990-05-17
176
+ dayze inventory add "Travel bag" --category bags --purchase-price 80 --currency SGD --tags "travel,weekend"
177
+ dayze inventory add --name "Desk lamp" --category electronics --json
178
+ ```
179
+
180
+ People options: `--name`, `--relationship`, `--email`, `--phone`, `--birthday`,
181
+ `--birth-time`, `--tier`, `--occupation`, `--company`, `--address`, `--first-met`,
182
+ `--first-met-location`, `--instagram`, `--twitter`, `--linkedin`, `--website`, `--notes`.
183
+ Birthday accepts `YYYY`, `YYYY-MM`, `YYYY-MM-DD`, or `MM-DD` (year unknown);
184
+ birth time uses `HH:mm` or `HH:mm:ss`, first met uses `YYYY-MM-DD`.
185
+ Tier is `vip`, `normal` (default), or `low`.
186
+
187
+ Inventory options: `--name`, `--category`, `--item-type`, `--brand`, `--color`,
188
+ `--size`, `--condition`, `--status`, `--purchase-price`, `--current-value`, `--currency`,
189
+ `--purchase-date`, `--location`, `--notes`, `--tags`, `--occasions`, `--seasons`, `--resale-url`.
190
+ Prices must be nonnegative numbers, currency a three-letter code, purchase date `YYYY-MM-DD`;
191
+ tags, occasions and seasons are comma-separated. Web defaults apply: category `other`,
192
+ condition `good`, status `owned`, currency `USD`. Category, condition and status must
193
+ be valid web values. Structured storage locations are managed through the web app.
194
+
195
+ Both commands print the created name and ID, or the created record alone with `--json`.
196
+ Missing names, unknown/duplicate flags, missing flag values and invalid fields fail with a
197
+ clear error and a nonzero exit code. No prompts appear. On a timeout, check the list before
198
+ retrying because the create may have completed.
199
+
200
+ ### Life Schema
201
+
202
+ | | |
203
+ |--|--|
204
+ | `dayze life show --kind=person --id=<uuid>` | Life Schema entity envelope |
205
+ | `dayze life help` | Kinds and usage |
206
+
207
+ Kinds: `person` · `event` · `moment` · `place` · `inventory_item`
208
+
209
+ ### Admin (superuser session)
210
+
211
+ Read-only wrappers around existing `/api/admin/*` GET routes. Requires `dayze login --email …`
212
+ as a `profiles.is_superuser` account — Actions API keys (`dayze_k_…`) cannot call admin routes.
213
+ `--json` is supported on every subcommand; token-like fields are redacted.
214
+
215
+ | | |
216
+ |--|--|
217
+ | `dayze admin users [q]` | `GET /api/admin/users` list/search `[--q=…] [--page=1] [--limit=50]` |
218
+ | `dayze admin cost` | `GET /api/admin/analytics/ai-cost` `[--days=7\|30\|90] [--includeInternal]` |
219
+ | `dayze admin flags` | `GET /api/admin/bot-config` (config readiness; no feature-flag catalog API yet) |
220
+ | `dayze admin health` | `GET /api/admin/health` |
221
+ | `dayze admin support` | `GET /api/admin/feedback` queue summary |
222
+ | `dayze admin audit` | `GET /api/admin/bot-logs` operational audit list |
223
+ | `dayze admin help` | Usage |
224
+
225
+ ### Inventory
226
+
227
+ | | |
228
+ |--|--|
229
+ | `dayze inventory` | Interactive (↑↓ Enter · type to filter · Ctrl+S sort) |
230
+ | `dayze inventory list` | Table `[--sort=price\|name\|updated\|bought]` |
231
+ | `dayze inventory show "…"` | One item |
232
+ | `dayze inventory delete "…"` | Remove item (confirm on TTY) |
233
+ | `dayze inventory help` | Keyboard + subcommands |
234
+
235
+ Detail keys: `a` agent · `e` edit · `n` note · `d` delete
236
+
237
+ Or: `dayze ask "check my inventory"`
238
+
239
+ ### Projects
240
+
241
+ ```bash
242
+ dayze projects
243
+ dayze projects list --json
244
+ dayze projects show my-project --json
245
+ dayze projects create "My project" --kind side_project --status idea --json
246
+ dayze projects create --name="Client launch" --slug=client-launch --description="Launch plan" --website=https://example.com --notes="First milestone"
247
+ dayze projects help
248
+ ```
249
+
250
+ Create accepts `--name` (instead of a positional name), `--slug`, `--kind`,
251
+ `--status`, `--description`, `--website`, and `--notes`, using either `--flag value`
252
+ or `--flag=value`. Quote names and text containing spaces. Kinds: `own_venture`
253
+ (default), `client_work`, `side_project`, `other`. Statuses: `active` (default),
254
+ `paused`, `archived`, `idea`. Slugs are generated from the name unless supplied.
255
+
256
+ These commands use `/api/cli/projects` and `/api/cli/projects/<slug>` with the
257
+ existing project store and scorecards. List excludes archived projects; show can
258
+ read an archived project by slug and does not sync connectors. Creation requires
259
+ an Actions-scoped API key or a signed-in session; reads also accept Context scope.
260
+ `--json` prints the API response as one JSON object: `{ projects, isSuperuser }`
261
+ for list, `{ project, kpis, weakestKpi, syncedAt, isSuperuser }` for show, and
262
+ `{ project, scorecard }` for create. Failures print `{ error }` and exit with code
263
+ 1; success exits with code 0. If creation times out, check the list before retrying
264
+ because the server may have completed the write.
265
+
266
+ ### Public IP on `dayze me`
267
+
268
+ By default, `dayze me` does **not** call third-party IP services. Session / network fields come from Dayze’s server-inferred request IP.
269
+
270
+ To report your live egress IP (useful when talking to a local Next server that only sees `127.0.0.1`), opt in:
271
+
272
+ ```bash
273
+ dayze me --public-ip
274
+ # or
275
+ DAYZE_PUBLIC_IP=1 dayze me
276
+ ```
277
+
278
+ That path alone may call `https://api.ipify.org`.
279
+
280
+ ## API host
281
+
282
+ Default is `https://dayze.com` (no local server needed once `/api/cli` is deployed).
283
+
284
+ ```bash
285
+ # Local Next:
286
+ dayze login --api http://127.0.0.1:3000 --key 'dayze_k_…'
287
+ ```
288
+
289
+ If localhost is down, CLI auto-switches back to `https://dayze.com`.
290
+
291
+ ## Env
292
+
293
+ | | |
294
+ |--|--|
295
+ | `DAYZE_API_BASE` | Default API host |
296
+ | `DAYZE_API_KEY` | Override key |
297
+ | `NO_COLOR=1` | Disable ANSI |
298
+ | `DAYZE_PUBLIC_IP=1` | Opt in to third-party public-IP lookup on `dayze me` (same as `--public-ip`) |
299
+
300
+ ## Note
301
+
302
+ API-key auth on the Agent stream requires the server build that accepts `dayze_k_…` with the **actions** scope. Use local `npm run dev` or deploy before expecting full tools against production.
303
+
304
+ ## Let another agent talk to Dayze
305
+
306
+ The new `dayze mcp-agent --client codex` command exposes Dayze Agent conversations to a local MCP host. It requires an explicit, dedicated Actions key, preserves follow-ups, and protects against replay after interrupted requests. It does not use the saved CLI login or replace the public Dayze life-context MCP catalog. See [the setup and permission guide](../docs/integrations/agent-conversation/README.md). This feature must be built from this checkout until a package release is approved.
package/dist/add.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { type DayzeCredentials } from './config.js';
2
+ export declare const INVENTORY_ADD_FIELDS: readonly ["name", "category", "item-type", "brand", "color", "size", "condition", "status", "purchase-price", "current-value", "currency", "purchase-date", "location", "notes", "tags", "occasions", "seasons", "resale-url"];
3
+ export declare const PEOPLE_ADD_FIELDS: readonly ["name", "relationship", "email", "phone", "birthday", "birth-time", "tier", "occupation", "company", "address", "first-met", "first-met-location", "instagram", "twitter", "linkedin", "website", "notes"];
4
+ /** Strict create syntax: never silently turn a misspelled flag into part of a name. */
5
+ export declare function parseAddArgs(args: string[], fields: readonly string[]): Record<string, string>;
6
+ export declare function postAdd<T>(creds: DayzeCredentials, directory: 'inventory' | 'people', body: Record<string, unknown>): Promise<T>;
package/dist/add.js ADDED
@@ -0,0 +1,72 @@
1
+ import { CliError } from './cli-errors.js';
2
+ import { authHeader } from './config.js';
3
+ import { fetchJsonWithDeadline } from './request-deadline.js';
4
+ import { CLI_USER_AGENT } from './version.js';
5
+ export const INVENTORY_ADD_FIELDS = [
6
+ 'name', 'category', 'item-type', 'brand', 'color', 'size', 'condition', 'status',
7
+ 'purchase-price', 'current-value', 'currency', 'purchase-date', 'location', 'notes',
8
+ 'tags', 'occasions', 'seasons', 'resale-url',
9
+ ];
10
+ export const PEOPLE_ADD_FIELDS = [
11
+ 'name', 'relationship', 'email', 'phone', 'birthday', 'birth-time', 'tier',
12
+ 'occupation', 'company', 'address', 'first-met', 'first-met-location',
13
+ 'instagram', 'twitter', 'linkedin', 'website', 'notes',
14
+ ];
15
+ /** Strict create syntax: never silently turn a misspelled flag into part of a name. */
16
+ export function parseAddArgs(args, fields) {
17
+ const values = {};
18
+ const name = [];
19
+ for (let i = 0; i < args.length; i++) {
20
+ const arg = args[i];
21
+ if (!arg.startsWith('-')) {
22
+ name.push(arg);
23
+ continue;
24
+ }
25
+ const match = /^--([^=]+)(?:=(.*))?$/s.exec(arg);
26
+ if (!match || !fields.includes(match[1])) {
27
+ throw new CliError(`Unknown add option: ${arg}`, { code: 'INVALID_INPUT' });
28
+ }
29
+ const flag = match[1];
30
+ const value = match[2] ?? args[++i];
31
+ if (value === undefined || value.startsWith('--')) {
32
+ throw new CliError(`--${flag} requires a value`, { code: 'INVALID_INPUT' });
33
+ }
34
+ const key = flag.replaceAll('-', '_');
35
+ if (Object.hasOwn(values, key)) {
36
+ throw new CliError(`--${flag} was provided more than once`, { code: 'INVALID_INPUT' });
37
+ }
38
+ values[key] = value;
39
+ }
40
+ if (name.length && values.name !== undefined) {
41
+ throw new CliError('Use either a positional name or --name', { code: 'INVALID_INPUT' });
42
+ }
43
+ values.name = (values.name ?? name.join(' ')).trim();
44
+ if (!values.name)
45
+ throw new CliError('Name is required', { code: 'INVALID_INPUT' });
46
+ return values;
47
+ }
48
+ export async function postAdd(creds, directory, body) {
49
+ const authorization = authHeader(creds);
50
+ if (!authorization)
51
+ throw new CliError('Not logged in');
52
+ return fetchJsonWithDeadline(`${creds.apiBase}/api/cli/${directory}`, {
53
+ method: 'POST',
54
+ headers: {
55
+ Authorization: authorization, Accept: 'application/json',
56
+ 'Content-Type': 'application/json', 'User-Agent': CLI_USER_AGENT,
57
+ },
58
+ body: JSON.stringify(body),
59
+ }, {
60
+ timeoutMessage: `Adding to ${directory} timed out. The create may have completed; check dayze ${directory} list before retrying.`,
61
+ httpErrorMessage: (status, preview) => {
62
+ let message = preview;
63
+ try {
64
+ const parsed = JSON.parse(preview);
65
+ if (typeof parsed.error === 'string')
66
+ message = parsed.error;
67
+ }
68
+ catch { /* Keep a bounded non-JSON server error. */ }
69
+ return `Failed to add to ${directory} (${status}): ${message}`;
70
+ },
71
+ });
72
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * CLI: dayze admin — read-only superuser ops (PHI-2103).
3
+ * Wraps existing /api/admin/* GET surfaces. Does not invent new privileged APIs.
4
+ *
5
+ * Auth: /api/admin/* requires a Supabase session JWT for a profiles.is_superuser
6
+ * account. Actions API keys (dayze_k_…) are rejected by verifyAdmin.
7
+ */
8
+ import { type DayzeCredentials } from './config.js';
9
+ export type AdminCommandOptions = {
10
+ json?: boolean;
11
+ };
12
+ export type AdminCommand = {
13
+ kind: 'help';
14
+ } | {
15
+ kind: 'users';
16
+ q?: string;
17
+ page?: number;
18
+ limit?: number;
19
+ } | {
20
+ kind: 'cost';
21
+ days: 7 | 30 | 90;
22
+ includeInternal: boolean;
23
+ } | {
24
+ kind: 'flags';
25
+ } | {
26
+ kind: 'health';
27
+ } | {
28
+ kind: 'support';
29
+ limit?: number;
30
+ } | {
31
+ kind: 'audit';
32
+ limit?: number;
33
+ };
34
+ /** Deep-clone JSON and replace secret-looking keys so --json never dumps tokens. */
35
+ export declare function redactSecrets<T>(value: T): T;
36
+ /** Prefer session JWT; API keys cannot pass verifyAdmin. */
37
+ export declare function adminAuthHeader(creds: DayzeCredentials): string;
38
+ export declare function parseAdminArgs(positional: string[]): AdminCommand;
39
+ export type AdminUsersResponse = {
40
+ users?: Array<Record<string, unknown>>;
41
+ total?: number;
42
+ page?: number;
43
+ totalPages?: number;
44
+ stats?: Record<string, unknown>;
45
+ };
46
+ export declare function fetchAdminUsers(creds: DayzeCredentials, opts?: {
47
+ q?: string;
48
+ page?: number;
49
+ limit?: number;
50
+ }): Promise<AdminUsersResponse>;
51
+ export type AdminCostResponse = {
52
+ days?: number;
53
+ summary?: Record<string, unknown>;
54
+ channels?: Array<Record<string, unknown>>;
55
+ [key: string]: unknown;
56
+ };
57
+ export declare function fetchAdminCost(creds: DayzeCredentials, opts: {
58
+ days: 7 | 30 | 90;
59
+ includeInternal: boolean;
60
+ }): Promise<AdminCostResponse>;
61
+ /** Closest existing admin "flags/config" read: GET /api/admin/bot-config (no feature-flag catalog API). */
62
+ export type AdminFlagsResponse = {
63
+ status?: string;
64
+ isConfigured?: boolean;
65
+ missingVars?: string[];
66
+ message?: string;
67
+ [key: string]: unknown;
68
+ };
69
+ export declare function fetchAdminFlags(creds: DayzeCredentials): Promise<AdminFlagsResponse>;
70
+ export type AdminHealthResponse = {
71
+ checks?: Array<{
72
+ id?: string;
73
+ label?: string;
74
+ status?: string;
75
+ latencyMs?: number;
76
+ detail?: string;
77
+ }>;
78
+ healthy?: boolean;
79
+ checkedAt?: string;
80
+ };
81
+ export declare function fetchAdminHealth(creds: DayzeCredentials): Promise<AdminHealthResponse>;
82
+ export type AdminSupportResponse = {
83
+ stats?: {
84
+ total?: number;
85
+ newCount?: number;
86
+ avgRating?: number | null;
87
+ byCategory?: Record<string, number>;
88
+ byStatus?: Record<string, number>;
89
+ };
90
+ total?: number;
91
+ feedback?: unknown[];
92
+ [key: string]: unknown;
93
+ };
94
+ export declare function fetchAdminSupport(creds: DayzeCredentials, opts?: {
95
+ limit?: number;
96
+ }): Promise<AdminSupportResponse>;
97
+ export type AdminAuditResponse = {
98
+ logs?: Array<Record<string, unknown>>;
99
+ [key: string]: unknown;
100
+ };
101
+ /** Operational audit list via existing bot_logs readout (no dedicated admin audit-log API). */
102
+ export declare function fetchAdminAudit(creds: DayzeCredentials): Promise<AdminAuditResponse>;
103
+ export declare function printAdminUsers(data: AdminUsersResponse): void;
104
+ export declare function printAdminCost(data: AdminCostResponse): void;
105
+ export declare function printAdminFlags(data: AdminFlagsResponse): void;
106
+ export declare function printAdminHealth(data: AdminHealthResponse): void;
107
+ export declare function printAdminSupport(data: AdminSupportResponse): void;
108
+ export declare function printAdminAudit(data: AdminAuditResponse, limit?: number): void;
109
+ export declare function printAdminHelp(): void;
110
+ export declare function runAdminCommand(creds: DayzeCredentials, positional: string[], options?: AdminCommandOptions): Promise<void>;