@zibby/cli 0.3.0 → 0.4.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.
- package/README.md +117 -16
- package/dist/bin/zibby.js +3 -3
- package/dist/commands/init.js +173 -83
- package/dist/commands/memory.js +41 -23
- package/dist/commands/template.js +4 -4
- package/dist/commands/uninstall.js +15 -14
- package/dist/commands/workflows/agent-helpers.js +7 -7
- package/dist/commands/workflows/generate.js +54 -32
- package/dist/commands/workflows/run-local.js +10 -10
- package/dist/commands/workflows/run.js +5 -5
- package/dist/commands/workflows/start.js +6 -6
- package/dist/package.json +1 -1
- package/dist/templates/zibby-workflow-claude/agents-md-block.md +65 -5
- package/dist/templates/zibby-workflow-claude/claude/agents/zibby-test-author.md +16 -1
- package/dist/templates/zibby-workflow-claude/claude/agents/zibby-workflow-builder.md +22 -2
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-add-node.md +1 -1
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-debug.md +1 -1
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-delete.md +1 -1
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-deploy.md +24 -14
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-list.md +2 -2
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-cost.md +39 -0
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-pull.md +47 -0
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-remote-use-hosted.md +61 -0
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-stats.md +38 -0
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-static-ip.md +8 -6
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-tail.md +1 -1
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-debug.md +2 -2
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-generate.md +1 -1
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-run.md +3 -2
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-write.md +1 -1
- package/dist/templates/zibby-workflow-claude/claude/commands/zibby-trigger.md +10 -6
- package/dist/templates/zibby-workflow-claude/cursor/rules/zibby-workflows.mdc +76 -13
- package/dist/templates/zibby-workflow-claude/manifest.json +5 -1
- package/dist/utils/apply-memory-sync-config.js +1 -0
- package/dist/utils/hosted-memory-sync.js +1 -0
- package/package.json +1 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
<!-- zibby-template-version:
|
|
1
|
+
<!-- zibby-template-version: 4 -->
|
|
2
2
|
# /zibby-static-ip — set up dedicated outbound static IP for a workflow
|
|
3
3
|
|
|
4
4
|
You are helping the user route a workflow's outbound traffic through a static IP address — needed when the workflow calls APIs that require IP allowlisting (corporate GitLab/GitHub Enterprise, internal SaaS, firewalls).
|
|
5
5
|
|
|
6
6
|
Canonical docs: **https://docs.zibby.app/workflows/egress**
|
|
7
7
|
|
|
8
|
+
> Note: the `--dedicated-ip` flag lives on the legacy alias `zibby deploy <name>`, NOT on `zibby workflow deploy <name>`. The two share a handler, but only `zibby deploy` exposes this flag in `--help`.
|
|
9
|
+
|
|
8
10
|
## What "static IP" means here
|
|
9
11
|
|
|
10
12
|
By default, workflow tasks run on Fargate and their outbound traffic exits via AWS-managed IPs that rotate. With the **dedicated egress** addon enabled, the workflow's outbound traffic is routed through a Zibby-managed proxy whose IP is pinned and customer-allowlistable.
|
|
@@ -23,19 +25,19 @@ Two pieces:
|
|
|
23
25
|
|
|
24
26
|
2. **Check current state:**
|
|
25
27
|
```
|
|
26
|
-
Bash(zibby
|
|
28
|
+
Bash(zibby deploy <name> --dedicated-ip status)
|
|
27
29
|
```
|
|
28
30
|
Output tells you: addon active or inactive, this workflow currently using it or not, and the assigned IPs to publish to customers.
|
|
29
31
|
|
|
30
32
|
3. **If addon is inactive — enable it** (only after explicit user confirmation):
|
|
31
33
|
```
|
|
32
|
-
Bash(zibby
|
|
34
|
+
Bash(zibby deploy <name> --dedicated-ip enable)
|
|
33
35
|
```
|
|
34
36
|
This is one-time per account. After this, the addon is active for ALL workflows in the account that opt in.
|
|
35
37
|
|
|
36
38
|
4. **Opt this workflow in:**
|
|
37
39
|
```
|
|
38
|
-
Bash(zibby
|
|
40
|
+
Bash(zibby deploy <name> --dedicated-ip use)
|
|
39
41
|
```
|
|
40
42
|
From now on, every deploy of this workflow + every triggered execution routes outbound through the static IP.
|
|
41
43
|
|
|
@@ -52,8 +54,8 @@ Two pieces:
|
|
|
52
54
|
|
|
53
55
|
## Reverting
|
|
54
56
|
|
|
55
|
-
- `Bash(zibby
|
|
56
|
-
- `Bash(zibby
|
|
57
|
+
- `Bash(zibby deploy <name> --dedicated-ip unuse)` — stop routing this workflow's egress through the static IP. Other opted-in workflows are unaffected.
|
|
58
|
+
- `Bash(zibby deploy <name> --dedicated-ip disable)` — disable the addon entirely (also stops billing).
|
|
57
59
|
|
|
58
60
|
## Tell the user the IPs
|
|
59
61
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- zibby-template-version:
|
|
1
|
+
<!-- zibby-template-version: 4 -->
|
|
2
2
|
# /zibby-test-debug — diagnose a failing Zibby test
|
|
3
3
|
|
|
4
4
|
You are helping the user figure out why a test failed.
|
|
@@ -34,7 +34,7 @@ Spec ambiguity is the most common cause. If the spec says "click the button" and
|
|
|
34
34
|
```
|
|
35
35
|
Bash(zibby test test-specs/<name>.txt --verbose) # info-level logs
|
|
36
36
|
Bash(zibby test test-specs/<name>.txt --debug) # all logs, lots
|
|
37
|
-
Bash(zibby test test-specs/<name>.txt
|
|
37
|
+
Bash(zibby test test-specs/<name>.txt) # default is headed — drop --headless to watch the browser
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### 5. Re-execute one node from a prior session
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- zibby-template-version:
|
|
1
|
+
<!-- zibby-template-version: 4 -->
|
|
2
2
|
# /zibby-test-generate — generate test specs from a Jira ticket / requirements
|
|
3
3
|
|
|
4
4
|
You are helping the user auto-generate test specs from a ticket description (Jira) or a free-text requirements doc. Zibby's `generate` command runs the configured AI agent against the codebase + ticket and produces `.txt` specs in `test-specs/`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- zibby-template-version:
|
|
1
|
+
<!-- zibby-template-version: 4 -->
|
|
2
2
|
# /zibby-test-run — execute a Zibby test spec
|
|
3
3
|
|
|
4
4
|
You are helping the user run an existing test spec through Zibby. A spec is a `.txt` file describing what to test in plain language; Zibby's runner turns it into a Playwright execution and produces a video + JSON results.
|
|
@@ -40,9 +40,10 @@ Canonical docs: **https://docs.zibby.app/tests/running**
|
|
|
40
40
|
- `--verbose` / `--debug` — escalate log levels
|
|
41
41
|
- `-m, --mem` — enable test memory (Dolt-backed knowledge from prior runs)
|
|
42
42
|
- `--sync` / `--no-sync` — force / skip cloud upload regardless of config
|
|
43
|
+
- `--sources <ids> --execution <id>` — run cloud-stored test cases from a specific execution (comma-separated IDs)
|
|
43
44
|
|
|
44
45
|
## Common failure modes
|
|
45
46
|
|
|
46
47
|
- **"No spec found"** — path is relative to project root, not cwd. Check `paths.specs` in `.zibby.config.mjs`.
|
|
47
|
-
- **"Browser crashed"** — usually the playwright browser cache is stale.
|
|
48
|
+
- **"Browser crashed"** — usually the playwright browser cache is stale. Drop `--headless` once (default is headed) so you can see what's happening, then re-add `--headless` once it's healthy.
|
|
48
49
|
- **MCP errors during `execute_live`** — the agent's MCP tool config may need refreshing. See `/zibby-test-debug`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- zibby-template-version:
|
|
1
|
+
<!-- zibby-template-version: 4 -->
|
|
2
2
|
# /zibby-test-write — author a new Zibby test spec
|
|
3
3
|
|
|
4
4
|
You are helping the user write a new test spec. Specs are plain-language `.txt` files in `test-specs/` (configurable via `.zibby.config.mjs` `paths.specs`). Zibby's runner converts them to Playwright at execution time.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<!-- zibby-template-version:
|
|
1
|
+
<!-- zibby-template-version: 4 -->
|
|
2
2
|
# /zibby-trigger — run a deployed Zibby workflow
|
|
3
3
|
|
|
4
4
|
You are helping the user trigger a deployed workflow execution.
|
|
5
5
|
|
|
6
6
|
A trigger creates a new ECS Fargate task that loads the workflow's bundle, runs the graph, and writes status + logs as it goes.
|
|
7
7
|
|
|
8
|
-
Canonical docs: **https://docs.zibby.app/
|
|
8
|
+
Canonical docs: **https://docs.zibby.app/cloud/triggering**
|
|
9
9
|
|
|
10
10
|
## Steps
|
|
11
11
|
|
|
@@ -13,15 +13,19 @@ Canonical docs: **https://docs.zibby.app/workflows/triggering**
|
|
|
13
13
|
|
|
14
14
|
2. **Construct the input.** Workflows take a JSON input that nodes can read via `ctx.input`. Ask the user what input the workflow expects (or read `workflow.json`'s `inputSchema` if present).
|
|
15
15
|
|
|
16
|
-
3. **Run the trigger
|
|
16
|
+
3. **Run the trigger.** Three ways to pass input — they merge with this **precedence (highest → lowest)**:
|
|
17
|
+
1. `-p key=value` (repeatable) — wins over everything; great for shell-friendly tweaks on top of a base payload
|
|
18
|
+
2. `--input '<json>'` — full JSON payload as a string
|
|
19
|
+
3. `--input-file path.json` — full JSON/YAML payload from a file (lowest precedence; `-p` and `--input` override individual keys)
|
|
20
|
+
|
|
17
21
|
```
|
|
18
22
|
zibby workflow trigger <uuid> --input '{"key":"value"}'
|
|
19
|
-
```
|
|
20
|
-
Or use `-p key=value` for individual params (more shell-friendly than embedded JSON):
|
|
21
|
-
```
|
|
22
23
|
zibby workflow trigger <uuid> -p ticket=ENG-1234 -p priority=high
|
|
24
|
+
zibby workflow trigger <uuid> --input-file payload.json -p priority=urgent # mix
|
|
23
25
|
```
|
|
24
26
|
|
|
27
|
+
Same flag surface as `zibby workflow run` (local) — flip the verb and the same call shape goes from local to remote.
|
|
28
|
+
|
|
25
29
|
4. **Tail the logs immediately:**
|
|
26
30
|
```
|
|
27
31
|
zibby workflow logs <uuid> -t
|
|
@@ -1,46 +1,106 @@
|
|
|
1
|
-
<!-- zibby-template-version:
|
|
1
|
+
<!-- zibby-template-version: 4 -->
|
|
2
2
|
---
|
|
3
|
-
description: Help the user build, test, and deploy Zibby agent workflows
|
|
3
|
+
description: Help the user build, test, and deploy Zibby agent workflows + browser tests
|
|
4
4
|
globs:
|
|
5
5
|
- "**/.zibby/workflows/**"
|
|
6
6
|
- ".zibby.config.mjs"
|
|
7
7
|
- "**/workflow.json"
|
|
8
8
|
- "**/graph.mjs"
|
|
9
|
+
- "test-specs/**"
|
|
10
|
+
- ".zibby/memory/**"
|
|
9
11
|
alwaysApply: false
|
|
10
12
|
---
|
|
11
13
|
|
|
12
|
-
# Zibby
|
|
14
|
+
# Zibby — workflows + tests
|
|
13
15
|
|
|
14
|
-
This project
|
|
16
|
+
This project uses **Zibby**. Two surfaces share `.zibby.config.mjs` at the project root.
|
|
15
17
|
|
|
16
|
-
##
|
|
18
|
+
## Workflows
|
|
19
|
+
|
|
20
|
+
A graph of AI-agent-driven steps that runs inside an ECS Fargate sandbox.
|
|
17
21
|
|
|
18
22
|
```
|
|
19
23
|
<workflowsBasePath>/<workflow-name>/
|
|
20
|
-
├── workflow.json # name, entryClass, triggers, schemas
|
|
24
|
+
├── workflow.json # name, entryClass, triggers, schemas (manifest)
|
|
21
25
|
├── graph.mjs # exports the graph (nodes + edges)
|
|
22
|
-
├── nodes/ # one .mjs file per node
|
|
26
|
+
├── nodes/ # one .mjs file per node, plus index.mjs barrel
|
|
23
27
|
└── package.json # deps bundled at deploy time
|
|
24
28
|
```
|
|
25
29
|
|
|
26
30
|
Each node exports `{ id, description, async run(ctx) }`. `ctx` provides `input`, `agent({prompt, schema})`, `shell(cmd)`, `log(...)`.
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
### Common dev loop
|
|
29
33
|
|
|
30
34
|
```
|
|
31
|
-
zibby workflow
|
|
32
|
-
zibby workflow
|
|
33
|
-
zibby workflow
|
|
34
|
-
zibby workflow
|
|
35
|
+
zibby workflow new <name> # scaffold
|
|
36
|
+
zibby workflow run <name> # one-shot local run (preferred for the dev loop)
|
|
37
|
+
zibby workflow deploy <name> # build + push to cloud
|
|
38
|
+
zibby workflow trigger <uuid> # invoke the cloud workflow
|
|
39
|
+
zibby workflow logs <uuid> -t # tail live logs (docker-compose-style for concurrent runs)
|
|
40
|
+
zibby workflow list # local + cloud
|
|
41
|
+
zibby workflow download <uuid> # pull cloud source back to .zibby/workflows/
|
|
42
|
+
zibby workflow delete <uuid> # remove a deployed workflow
|
|
35
43
|
```
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
`run` (one-shot) vs `start` (long-lived dev server, port 3848 — Studio integration). For plain CLI iteration always use `run`.
|
|
46
|
+
|
|
47
|
+
`run` and `trigger` accept the same input flags: `-p key=value` (highest precedence, repeatable), `--input '<json>'`, `--input-file path.json` (lowest precedence).
|
|
48
|
+
|
|
49
|
+
### Adding a new node
|
|
38
50
|
|
|
39
51
|
1. Create `<workflow>/nodes/<name>.mjs` (mirror existing `example.mjs` pattern)
|
|
40
52
|
2. Register in `<workflow>/nodes/index.mjs`
|
|
41
53
|
3. Wire into `<workflow>/graph.mjs` (add to `nodes` array and connect via edges)
|
|
42
54
|
4. `zibby workflow run <name>` to test locally; `zibby workflow deploy` to push
|
|
43
55
|
|
|
56
|
+
### Per-workflow env vars
|
|
57
|
+
|
|
58
|
+
Each deployed workflow has its own encrypted env-var bag (KMS-backed); workflow env wins over project secrets on conflict.
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
zibby workflow env list <uuid> # show key names (values never returned)
|
|
62
|
+
zibby workflow env set <uuid> ANTHROPIC_API_KEY=sk-… # add or rotate one
|
|
63
|
+
zibby workflow env unset <uuid> OLD_KEY # remove one
|
|
64
|
+
zibby workflow env push <uuid> --file .env [--file .env.prod] # bulk replace
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Fast path on first deploy: `zibby workflow deploy my-pipeline --env .env` deploys, then auto-pushes the .env into the new UUID.
|
|
68
|
+
|
|
69
|
+
## Tests (`zibby test`)
|
|
70
|
+
|
|
71
|
+
Plain-language `.txt` specs at `test-specs/`. The runner drives a real browser via MCP, generates Playwright, produces a video.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
zibby test test-specs/<name>.txt # run a spec
|
|
75
|
+
zibby test "go to example.com and ..." # inline, no file
|
|
76
|
+
zibby test <spec> --agent claude # override agent (claude|cursor|codex|gemini)
|
|
77
|
+
zibby test --sources <ids> --execution <id> # cloud test cases
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
When debugging, `test-results/<spec>/video.webm` usually tells you what went wrong faster than logs.
|
|
81
|
+
|
|
82
|
+
### Test memory (`.zibby/memory/.dolt/`)
|
|
83
|
+
|
|
84
|
+
Local-first Dolt SQL DB that learns selectors, page model, navigation, history from every run. Keyed **per-domain** (cross-spec). Auto-pulls before runs, auto-pushes after passing runs.
|
|
85
|
+
|
|
86
|
+
When `zibby test` runs and `.dolt/` exists, the agent gets 5 MCP tools auto-exposed:
|
|
87
|
+
- `memory_get_test_history` — recent runs (filter by spec-path substring)
|
|
88
|
+
- `memory_get_selectors` — known selectors per page with stability metrics
|
|
89
|
+
- `memory_get_page_model` — page elements, roles, accessible names
|
|
90
|
+
- `memory_get_navigation` — page-to-page transitions
|
|
91
|
+
- `memory_save_insight` — save observations (`selector_tip | timing | navigation | workaround | flaky | general`)
|
|
92
|
+
|
|
93
|
+
**After completing a test, the agent MUST call `memory_save_insight` at least once** — record reliable selectors, timing quirks, workarounds.
|
|
94
|
+
|
|
95
|
+
Local CLI: `zibby memory stats | cost | compact | reset`.
|
|
96
|
+
|
|
97
|
+
Team sync (BYO or hosted):
|
|
98
|
+
```
|
|
99
|
+
zibby memory remote add aws://my-bucket/team/proj/main # BYO (S3 / GCS / DoltHub / file:///)
|
|
100
|
+
zibby memory remote use --hosted # OR: Zibby-managed S3 (signed-in only)
|
|
101
|
+
```
|
|
102
|
+
Set `memorySync.remote` in `.zibby.config.mjs` (`'hosted'` or `'aws://...'`) so teammates running `zibby init` plug into the same memory automatically.
|
|
103
|
+
|
|
44
104
|
## Reference
|
|
45
105
|
|
|
46
106
|
Canonical, evolving docs: **https://docs.zibby.app/workflows**
|
|
@@ -49,8 +109,11 @@ Topics:
|
|
|
49
109
|
- Node SDK (ctx.agent / ctx.shell / ctx.log): https://docs.zibby.app/workflows/sdk
|
|
50
110
|
- Deploying & bundling: https://docs.zibby.app/workflows/deploying
|
|
51
111
|
- Triggering & inputs: https://docs.zibby.app/workflows/triggers
|
|
112
|
+
- Per-workflow env vars: https://docs.zibby.app/cloud/env-vars
|
|
52
113
|
- Live log streaming: https://docs.zibby.app/workflows/logs
|
|
53
114
|
- Egress proxy / static IPs: https://docs.zibby.app/workflows/egress
|
|
54
115
|
- Security & secrets: https://docs.zibby.app/workflows/security
|
|
116
|
+
- Test memory: https://docs.zibby.app/tests/memory
|
|
117
|
+
- Tests — running: https://docs.zibby.app/tests/running
|
|
55
118
|
|
|
56
119
|
Prefer the docs URL for anything you're unsure about — they're updated more frequently than these rules.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"templateVersion":
|
|
2
|
+
"templateVersion": 4,
|
|
3
3
|
"description": "Canonical agent helpers for Zibby workflows. Each shipped file carries '<!-- zibby-template-version: N -->' for idempotent upgrades. Bumped on breaking content changes.",
|
|
4
4
|
"agents": {
|
|
5
5
|
"claude": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
".claude/commands/zibby-test-write.md",
|
|
17
17
|
".claude/commands/zibby-test-generate.md",
|
|
18
18
|
".claude/commands/zibby-test-debug.md",
|
|
19
|
+
".claude/commands/zibby-memory-stats.md",
|
|
20
|
+
".claude/commands/zibby-memory-cost.md",
|
|
21
|
+
".claude/commands/zibby-memory-pull.md",
|
|
22
|
+
".claude/commands/zibby-memory-remote-use-hosted.md",
|
|
19
23
|
".claude/agents/zibby-workflow-builder.md",
|
|
20
24
|
".claude/agents/zibby-test-author.md"
|
|
21
25
|
],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=[null,void 0,"","none","off",!1],f="hosted",d=["aws://","gs://","https://","http://","file://"];function y(r){if(!r||typeof r!="object")return{ok:!0,kind:"noop"};let e=r.remote;return m.includes(e)?{ok:!0,kind:"noop"}:typeof e!="string"?{ok:!1,error:`memorySync.remote must be null or a string, got ${typeof e}`}:e===f?{ok:!0,kind:"hosted"}:d.some(n=>e.startsWith(n))?{ok:!0,kind:"byo",remote:e}:{ok:!1,error:`memorySync.remote = ${JSON.stringify(e)} is not recognized. Use null, 'hosted', or a URL beginning with one of: ${d.join(" / ")}.`}}async function c({cwd:r,projectId:e,block:n,memoryApi:t,hostedSetup:i,getSessionToken:s,logger:u=console}){let o=y(n);if(!o.ok)return u.warn?.(`[memory-sync] config invalid: ${o.error}`),{action:"error",reason:o.error};if(o.kind==="noop")return{action:"skipped",reason:"memorySync.remote not set"};if(o.kind==="byo")return t?.memoryRemoteAdd?t.memoryRemoteAdd(r,o.remote)?{action:"byo",remote:o.remote}:{action:"error",reason:"memoryRemoteAdd returned false (memory DB not initialized?)"}:{action:"error",reason:"@zibby/ui-memory not loaded"};if(o.kind==="hosted"){if(typeof s=="function"&&!s())return{action:"pending-login",reason:'memorySync.remote = "hosted" but the user is not logged in. Run `zibby login` then `zibby memory remote use --hosted`.'};if(typeof i!="function")return{action:"error",reason:"hostedSetup function not provided"};try{return await i({cwd:r,projectId:e}),{action:"hosted"}}catch(a){return{action:"error",reason:`hosted setup failed: ${a.message}`}}}return{action:"error",reason:`unhandled kind: ${o.kind}`}}export{c as applyMemorySyncConfig,y as validateMemorySyncConfig};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFileSync as y,writeFileSync as f,existsSync as d,mkdirSync as S,chmodSync as w}from"fs";import{join as u}from"path";var x="memory-sync.json",C="memory-sync-creds.json",h=120*1e3;function c(r){let e=u(r,".zibby");return{dir:e,config:u(e,x),creds:u(e,C)}}function p(r){let{config:e}=c(r);if(!d(e))return null;try{let t=JSON.parse(y(e,"utf-8"));return t.mode!=="hosted"?null:t}catch{return null}}function K(r){return!!p(r)}function T(r,e){let{dir:t,config:n}=c(r);S(t,{recursive:!0}),f(n,JSON.stringify({mode:"hosted",projectId:e.projectId,bucket:e.bucket,prefix:e.prefix,doltUrl:e.doltUrl,configuredAt:new Date().toISOString()},null,2),"utf-8")}function b(r){let{config:e,creds:t}=c(r);for(let n of[e,t])if(d(n))try{f(n,"")}catch{}}function l(r){let{creds:e}=c(r);if(!d(e))return null;try{let t=JSON.parse(y(e,"utf-8"));return!t?.accessKeyId||!t?.secretAccessKey||!t?.sessionToken?null:t}catch{return null}}function m(r,e){let{dir:t,creds:n}=c(r);S(t,{recursive:!0}),f(n,JSON.stringify(e,null,2),"utf-8");try{w(n,384)}catch{}}function E(r){return r?.expiration?new Date(r.expiration).getTime()-Date.now()<h:!0}async function I({cwd:r,projectId:e,apiUrl:t,sessionToken:n,fetch:s=globalThis.fetch}){if(!e)throw new Error("refreshCredentials: projectId required");if(!t)throw new Error("refreshCredentials: apiUrl required");if(!n)throw new Error("refreshCredentials: sessionToken required (run `zibby login`)");let i=`${String(t).replace(/\/+$/,"")}/memory/sync-credentials`,a=await s(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({projectId:e})});if(!a.ok){let g=await a.text().catch(()=>"");throw new Error(`memory-sync credentials request failed (${a.status}): ${g||"no body"}`)}let o=await a.json();if(!o?.accessKeyId||!o?.secretAccessKey||!o?.sessionToken)throw new Error("memory-sync credentials response missing required fields");return m(r,{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,sessionToken:o.sessionToken,expiration:o.expiration||null,refreshedAt:new Date().toISOString()}),l(r)}async function A({cwd:r,apiUrl:e,sessionToken:t,fetch:n}){let s=p(r);if(!s)return null;let i=l(r);return(!i||E(i))&&(i=await I({cwd:r,projectId:s.projectId,apiUrl:e,sessionToken:t,fetch:n})),i}async function N({cwd:r,apiUrl:e,sessionToken:t,fetch:n}){let s=await A({cwd:r,apiUrl:e,sessionToken:t,fetch:n});return s?{AWS_ACCESS_KEY_ID:s.accessKeyId,AWS_SECRET_ACCESS_KEY:s.secretAccessKey,AWS_SESSION_TOKEN:s.sessionToken,AWS_REGION:process.env.AWS_REGION||"ap-southeast-2"}:null}var j={paths:c,readCreds:l,writeCreds:m,isExpiringSoon:E,REFRESH_HEADROOM_MS:h};export{j as __testing,N as buildDoltEnv,b as clearConfig,A as getActiveCredentials,K as isHosted,p as readConfig,I as refreshCredentials,T as writeConfig};
|