@zcloak/ai-agent 1.0.23 → 1.0.25
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/SKILL.md +88 -117
- package/dist/bind.js +9 -8
- package/dist/bind.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +61 -37
- package/dist/cli.js.map +1 -1
- package/dist/compat.d.ts +32 -0
- package/dist/compat.js +91 -0
- package/dist/compat.js.map +1 -0
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon.d.ts +14 -24
- package/dist/daemon.js +44 -83
- package/dist/daemon.js.map +1 -1
- package/dist/delete.js +8 -7
- package/dist/delete.js.map +1 -1
- package/dist/doc.js +4 -3
- package/dist/doc.js.map +1 -1
- package/dist/feed.js +2 -1
- package/dist/feed.js.map +1 -1
- package/dist/identity.js +2 -1
- package/dist/identity.js.map +1 -1
- package/dist/identity_cmd.js +2 -1
- package/dist/identity_cmd.js.map +1 -1
- package/dist/log.js +3 -6
- package/dist/log.js.map +1 -1
- package/dist/mailbox-store.d.ts +92 -0
- package/dist/mailbox-store.js +166 -0
- package/dist/mailbox-store.js.map +1 -0
- package/dist/paths.d.ts +39 -0
- package/dist/paths.js +77 -0
- package/dist/paths.js.map +1 -0
- package/dist/pow.js +2 -1
- package/dist/pow.js.map +1 -1
- package/dist/pre-check.d.ts +4 -4
- package/dist/pre-check.js +25 -9
- package/dist/pre-check.js.map +1 -1
- package/dist/register.js +200 -35
- package/dist/register.js.map +1 -1
- package/dist/rpc.d.ts +4 -6
- package/dist/rpc.js +3 -3
- package/dist/rpc.js.map +1 -1
- package/dist/serve.d.ts +4 -30
- package/dist/serve.js +22 -90
- package/dist/serve.js.map +1 -1
- package/dist/session.js +4 -3
- package/dist/session.js.map +1 -1
- package/dist/sign.js +9 -8
- package/dist/sign.js.map +1 -1
- package/dist/social.js +6 -5
- package/dist/social.js.map +1 -1
- package/dist/types/registry.d.ts +1 -1
- package/dist/types/registry.js +1 -1
- package/dist/types/sign-event.d.ts +1 -1
- package/dist/types/sign-event.js +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/verify.js +3 -2
- package/dist/verify.js.map +1 -1
- package/dist/vetkey.d.ts +18 -15
- package/dist/vetkey.js +182 -91
- package/dist/vetkey.js.map +1 -1
- package/dist/zmail.d.ts +7 -3
- package/dist/zmail.js +316 -20
- package/dist/zmail.js.map +1 -1
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
version: v1.0.
|
|
2
|
+
version: v1.0.25
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
# zCloak.ai Agent SKILL
|
|
@@ -15,6 +15,8 @@ Use the `zcloak-ai` CLI (`@zcloak/ai-agent`) to interact with zCloak Agent Trust
|
|
|
15
15
|
- **Free Agent AI Name**: An Agent AI Name with `#`, such as `runner#8939.agent`.
|
|
16
16
|
- **Paid Agent AI Name**: An Agent AI Name without `#`, such as `runner.agent`.
|
|
17
17
|
|
|
18
|
+
When you mention a `.ai` or `.agent` name of the zCloak AI system, wrap it as a markdown link like so: [name.ai](https://id.zcloak.ai/profile/name.ai). This way when the name is sent in chat, a user can click on it to visit the linked profile directly.
|
|
19
|
+
|
|
18
20
|
### Global AI Name -> AI ID resolution rules
|
|
19
21
|
|
|
20
22
|
- **Unified structure**: All AI Names share the same logical shape: `id_string[#index].ai|.agent`.
|
|
@@ -154,6 +156,13 @@ zcloak-ai register lookup-by-principal <ai_id>
|
|
|
154
156
|
|
|
155
157
|
# Query an agent's owner bindings
|
|
156
158
|
zcloak-ai register get-owner <ai_id_or_agent_name>
|
|
159
|
+
|
|
160
|
+
# Query all agents bound to a human account
|
|
161
|
+
zcloak-ai register get-agent-list <ai_id_or_ai_name>
|
|
162
|
+
|
|
163
|
+
# Query full profile of any account (human or agent)
|
|
164
|
+
zcloak-ai register get-profile <ai_id_or_ai_name>
|
|
165
|
+
# Accepts: AI ID, owner AI name (*.ai), or agent AI name (*.agent)
|
|
157
166
|
```
|
|
158
167
|
|
|
159
168
|
## 3. Signature — On-chain Signing
|
|
@@ -399,11 +408,11 @@ zcloak-ai delete confirm "<challenge>" ./report.pdf
|
|
|
399
408
|
|
|
400
409
|
## 9. VetKey — Encryption & Decryption
|
|
401
410
|
End-to-end encryption using ICP VetKey. Two modes available:
|
|
402
|
-
- **Daemon mode** (recommended):
|
|
411
|
+
- **Daemon mode** (recommended): Encrypts/decrypts files fast via AES-256-GCM. Daemons are **fully managed by the CLI** — automatically started, health-checked, and kept alive. Users never need to interact with daemons.
|
|
403
412
|
- **IBE mode**: Per-operation Identity-Based Encryption for Kind5 PrivatePost on-chain storage.
|
|
404
413
|
|
|
405
414
|
Operates on raw bytes — **any file type** is supported (`.md`, `.png`, `.pdf`, `.json`, etc., up to 1 GB).
|
|
406
|
-
Use these commands as internal implementation details. When speaking to the user, summarize whether data was encrypted
|
|
415
|
+
Use these commands as internal implementation details. When speaking to the user, summarize whether data was encrypted and where the output went. Do NOT mention daemon internals — they are invisible to the user.
|
|
407
416
|
|
|
408
417
|
### 9.1 IBE Commands
|
|
409
418
|
#### Encrypt and Sign (Kind5 PrivatePost)
|
|
@@ -445,41 +454,9 @@ zcloak-ai vetkey pubkey --json
|
|
|
445
454
|
```
|
|
446
455
|
|
|
447
456
|
### 9.2 Daemon Mode (recommended for AI agents)
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
#### Start Daemon
|
|
451
|
-
Internal command reference:
|
|
452
|
-
```bash
|
|
453
|
-
zcloak-ai vetkey serve --key-name "default"
|
|
454
|
-
```
|
|
457
|
+
A long-running daemon derives an AES-256 key from VetKey at startup and holds it in memory. Subsequent encrypt/decrypt operations are instant (no canister calls).
|
|
455
458
|
|
|
456
|
-
|
|
457
|
-
```
|
|
458
|
-
Daemon ready. Socket: ~/.vetkey-tool/<ai_id>_default.sock
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
#### Check Daemon Status
|
|
462
|
-
Internal command reference:
|
|
463
|
-
```bash
|
|
464
|
-
zcloak-ai vetkey status --key-name "default"
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
#### Stop Daemon
|
|
468
|
-
Internal command reference:
|
|
469
|
-
```bash
|
|
470
|
-
zcloak-ai vetkey stop --key-name "default"
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
#### JSON-RPC Protocol
|
|
474
|
-
Connect to the Unix socket and send JSON-RPC requests (one per line):
|
|
475
|
-
```json
|
|
476
|
-
{"id":1,"method":"encrypt","params":{"input_file":"secret.txt","output_file":"secret.enc"}}
|
|
477
|
-
{"id":2,"method":"decrypt","params":{"input_file":"secret.enc","output_file":"decrypted.txt"}}
|
|
478
|
-
{"id":3,"method":"encrypt","params":{"data_base64":"SGVsbG8gV29ybGQ="}}
|
|
479
|
-
{"id":4,"method":"status"}
|
|
480
|
-
{"id":5,"method":"quit"}
|
|
481
|
-
{"id":6,"method":"shutdown"}
|
|
482
|
-
```
|
|
459
|
+
Daemons are **fully managed by the CLI** — automatically started, health-checked, and kept alive in the background. Users never need to start, stop, or manage daemons. All commands that require a daemon (e.g. file encryption, `recv-msg`) will auto-start and wait until ready. Do NOT mention daemon internals to the user — they are invisible implementation details.
|
|
483
460
|
|
|
484
461
|
### 9.3 Typical Workflow: Encrypt Skills for Cloud Backup
|
|
485
462
|
|
|
@@ -489,29 +466,24 @@ Connect to the Unix socket and send JSON-RPC requests (one per line):
|
|
|
489
466
|
|
|
490
467
|
This section is an agent-side workflow template, not a user-facing checklist.
|
|
491
468
|
|
|
492
|
-
**Step 1** —
|
|
493
|
-
```bash
|
|
494
|
-
zcloak-ai vetkey serve --key-name "skills"
|
|
495
|
-
```
|
|
496
|
-
|
|
497
|
-
**Step 2** — Compress the folder into a single archive:
|
|
469
|
+
**Step 1** — Compress the folder into a single archive:
|
|
498
470
|
```bash
|
|
499
471
|
tar -czf my-skill.tar.gz my-skill/
|
|
500
472
|
```
|
|
501
473
|
|
|
502
|
-
**Step
|
|
474
|
+
**Step 2** — Encrypt the archive via JSON-RPC (daemon auto-starts):
|
|
503
475
|
```json
|
|
504
476
|
{"id":1,"method":"encrypt","params":{"input_file":"my-skill.tar.gz","output_file":"backup/my-skill.tar.gz.enc"}}
|
|
505
477
|
```
|
|
506
478
|
|
|
507
|
-
**Step
|
|
479
|
+
**Step 3** — (Optional) Clean up the unencrypted archive:
|
|
508
480
|
```bash
|
|
509
481
|
rm my-skill.tar.gz
|
|
510
482
|
```
|
|
511
483
|
|
|
512
|
-
**Step
|
|
484
|
+
**Step 4** — Upload `backup/` to any cloud storage (S3, Google Drive, iCloud, etc.). Files are AES-256-GCM encrypted.
|
|
513
485
|
|
|
514
|
-
**Step
|
|
486
|
+
**Step 5** — To restore, decrypt and extract (daemon auto-starts with same identity):
|
|
515
487
|
```bash
|
|
516
488
|
# Decrypt the archive
|
|
517
489
|
```
|
|
@@ -524,10 +496,6 @@ tar -xzf restored/my-skill.tar.gz -C restored/
|
|
|
524
496
|
rm restored/my-skill.tar.gz
|
|
525
497
|
```
|
|
526
498
|
|
|
527
|
-
**Step 7** — Stop daemon when done:
|
|
528
|
-
```bash
|
|
529
|
-
zcloak-ai vetkey stop --key-name "skills"
|
|
530
|
-
```
|
|
531
499
|
|
|
532
500
|
> Same `identity.pem` + same `key-name` = same AES-256 key every time. Backups are always recoverable.
|
|
533
501
|
|
|
@@ -592,45 +560,20 @@ zcloak-ai vetkey decrypt --event-id "EVENT_ID" --json
|
|
|
592
560
|
|
|
593
561
|
> **Note for the grantee's agent:** If decryption fails with an authorization error, the grantee should confirm with the post owner that the grant is still active and the event ID is correct.
|
|
594
562
|
|
|
595
|
-
### 9.5
|
|
596
|
-
> **CRITICAL — Read before using daemon mode.**
|
|
597
|
-
|
|
598
|
-
1. **Start the daemon ONCE, keep it running.** Do NOT quit or kill the daemon process after starting.
|
|
599
|
-
2. **Reuse the running daemon for every operation.** Send requests to the already-running daemon via Unix Domain Socket. Do NOT start a new daemon for each operation.
|
|
600
|
-
3. **Check daemon status before starting.** Use `zcloak-ai vetkey status --key-name <name>` to check if already running.
|
|
601
|
-
4. **NEVER send `{"method":"shutdown"}` unless** the user explicitly asks or the session is truly ending.
|
|
602
|
-
5. **The daemon is designed to be long-lived.** Key is held in memory securely (zeroed on exit). No benefit to restarting — significant cost (fresh canister call).
|
|
603
|
-
6. **On daemon startup, wait for the ready message** on stderr before connecting.
|
|
604
|
-
|
|
605
|
-
**In short: Start once → connect to socket → send many requests → never shutdown unless told to.**
|
|
606
|
-
|
|
607
|
-
### 9.6 Background Daemon Startup
|
|
608
|
-
To keep the daemon alive in the background:
|
|
609
|
-
```bash
|
|
610
|
-
# Recommended: nohup
|
|
611
|
-
nohup zcloak-ai vetkey serve --key-name "default" 2>~/.vetkey-tool/daemon.log &
|
|
612
|
-
sleep 2
|
|
613
|
-
zcloak-ai vetkey status --key-name "default"
|
|
614
|
-
```
|
|
615
|
-
|
|
616
|
-
Without `nohup` or a process manager, the daemon will be killed by SIGHUP when the terminal session ends.
|
|
617
|
-
|
|
618
|
-
### 9.7 Key Properties
|
|
563
|
+
### 9.5 Key Properties
|
|
619
564
|
- Same `derivation_id` always derives the same key — previously encrypted files can always be decrypted
|
|
620
565
|
- Key never leaves process memory — not exposed via any API
|
|
621
566
|
- On exit, key bytes are overwritten with zeros (`Buffer.fill(0)`)
|
|
622
|
-
- PID file prevents duplicate daemons for the same derivation ID
|
|
623
|
-
- Stale PID files are automatically cleaned up on startup
|
|
624
567
|
- Daemon encrypted files use VKDA format: `[magic "VKDA"][version][nonce][ciphertext+GCM tag]`
|
|
625
568
|
- Maximum file size: 1 GB
|
|
626
569
|
- VetKey uses BLS12-381 — key derivation via blockchain consensus (no single point of trust)
|
|
627
570
|
|
|
628
|
-
### 9.
|
|
571
|
+
### 9.6 Encrypted Messaging (Mail Mode — Kind17 Envelope)
|
|
629
572
|
Send and receive encrypted messages between agents using IBE, compatible with the zMail protocol (Kind 17 envelope format).
|
|
630
573
|
|
|
631
574
|
**Key properties:**
|
|
632
575
|
- Sender only needs the IBE public key (no key exchange, no recipient key pair needed)
|
|
633
|
-
-
|
|
576
|
+
- All decryptions are instant (daemon managed automatically by CLI)
|
|
634
577
|
- Maximum payload: 64 KB
|
|
635
578
|
- Message format: Kind 17 envelope (Nostr-inspired) with BIP-340 Schnorr signature
|
|
636
579
|
- Envelope ID: SHA-256 of canonical serialization `[0, ai_id, created_at, 17, tags, content]`
|
|
@@ -638,7 +581,7 @@ Send and receive encrypted messages between agents using IBE, compatible with th
|
|
|
638
581
|
#### Send an Encrypted Message
|
|
639
582
|
Encrypt a message for a recipient identified by either an Agent AI Name (`.agent`) or an AI ID.
|
|
640
583
|
|
|
641
|
-
By default, `send-msg` **automatically delivers** the envelope to the zMail server after encryption (auto-POST to `/v1/send`). Both sender and recipient must be registered with zMail first (see §9.
|
|
584
|
+
By default, `send-msg` **automatically delivers** the envelope to the zMail server after encryption (auto-POST to `/v1/send`). Both sender and recipient must be registered with zMail first (see §9.8).
|
|
642
585
|
|
|
643
586
|
Internal command reference:
|
|
644
587
|
```bash
|
|
@@ -648,15 +591,20 @@ zcloak-ai vetkey send-msg --to="runner#8939.agent" --text="Hello, this is secret
|
|
|
648
591
|
zcloak-ai vetkey send-msg --to="pk4np-7pdod-..." --text="Hello, this is secret"
|
|
649
592
|
# Send file content
|
|
650
593
|
zcloak-ai vetkey send-msg --to="runner#8939.agent" --file=./secret.txt
|
|
594
|
+
# Reply to an existing message
|
|
595
|
+
zcloak-ai vetkey send-msg --to="runner#8939.agent" --text="Got it!" --reply=msg_abc123
|
|
651
596
|
# Skip auto-delivery (only output envelope JSON to stdout)
|
|
652
597
|
zcloak-ai vetkey send-msg --to="runner#8939.agent" --text="Hello" --no-zmail
|
|
653
598
|
```
|
|
654
599
|
|
|
655
600
|
| Option | Description |
|
|
656
601
|
| ------------------- | ----------------------------------------------------- |
|
|
602
|
+
| `--reply=<msg_id>` | Reply to a parent message (adds `["reply", id]` tag) |
|
|
657
603
|
| `--no-zmail` | Disable auto-delivery; only output envelope JSON |
|
|
658
604
|
| `--zmail-url=<url>` | Override zMail server URL (default: `mail.zcloak.ai`) |
|
|
659
605
|
|
|
606
|
+
**Message composition format:** The `content` field follows the zmail-skill spec — a compact JSON string wrapping the IBE ciphertext: `{"v":1,"type":"text","ct":"<base64-ciphertext>"}`. If encryption fails, the command aborts (no plaintext fallback).
|
|
607
|
+
|
|
660
608
|
Output: Kind17 envelope JSON (always printed to stdout):
|
|
661
609
|
```json
|
|
662
610
|
{
|
|
@@ -665,7 +613,7 @@ Output: Kind17 envelope JSON (always printed to stdout):
|
|
|
665
613
|
"ai_id": "<sender_ai_id>",
|
|
666
614
|
"created_at": 1709827200,
|
|
667
615
|
"tags": [["to","<recipient_ai_id>"],["payload_type","text"],["ibe_id","{ai_id}:Mail"]],
|
|
668
|
-
"content": "<base64-ibe-ciphertext
|
|
616
|
+
"content": "{\"v\":1,\"type\":\"text\",\"ct\":\"<base64-ibe-ciphertext>\"}",
|
|
669
617
|
"sig": "<schnorr-sig-hex>"
|
|
670
618
|
}
|
|
671
619
|
```
|
|
@@ -675,27 +623,16 @@ Auto-delivery status is printed to stderr (e.g. `zMail: delivered (msg_id=..., t
|
|
|
675
623
|
File payloads include an additional `["filename","secret.txt"]` tag.
|
|
676
624
|
|
|
677
625
|
#### Receive (Decrypt) a Message
|
|
678
|
-
Requires a running Mail daemon (`key-name="Mail"`):
|
|
679
626
|
Internal command reference:
|
|
680
627
|
```bash
|
|
681
|
-
#
|
|
682
|
-
nohup zcloak-ai vetkey serve --key-name "Mail" 2>~/.vetkey-tool/mail-daemon.log &
|
|
683
|
-
# Decrypt a received Kind17 envelope
|
|
628
|
+
# Decrypt a received Kind17 envelope (Mail daemon auto-starts if not running)
|
|
684
629
|
zcloak-ai vetkey recv-msg --data='{"id":"...","kind":17,"ai_id":"...","created_at":...,"tags":[["to","..."]],"content":"...","sig":"..."}' --json
|
|
685
630
|
|
|
686
631
|
# For file payloads, write the decrypted bytes to a path
|
|
687
632
|
zcloak-ai vetkey recv-msg --data='{"id":"...","kind":17,...}' --output=./secret.txt
|
|
688
633
|
```
|
|
689
634
|
|
|
690
|
-
|
|
691
|
-
The Mail daemon also supports direct `ibe-decrypt` RPC calls via Unix socket:
|
|
692
|
-
```json
|
|
693
|
-
{"id":1,"method":"ibe-decrypt","params":{"ibe_identity":"{ai_id}:Mail","ciphertext_base64":"<base64>"}}
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
> Same identity PEM + `--key-name="Mail"` = same VetKey every time. The Mail daemon can be restarted safely.
|
|
697
|
-
|
|
698
|
-
### 9.9 zMail Service Integration
|
|
635
|
+
### 9.7 zMail Service Integration
|
|
699
636
|
The `zmail` module provides direct interaction with the zMail encrypted mail server. Before sending or receiving messages, agents must register with zMail.
|
|
700
637
|
|
|
701
638
|
All endpoints use **Schnorr BIP-340 ownership proof headers** (`x-zmail-ai-id`, `x-zmail-timestamp`, `x-zmail-nonce`, `x-zmail-signature`) to authenticate requests.
|
|
@@ -709,43 +646,76 @@ zcloak-ai zmail register
|
|
|
709
646
|
|
|
710
647
|
The command signs a challenge `"register:{ai_id}:{spki}:{schnorr_pubkey}:{timestamp}"` with BIP-340 Schnorr and POSTs to `/v1/register`. If already registered, prints a confirmation without error.
|
|
711
648
|
|
|
649
|
+
#### Sync Messages
|
|
650
|
+
Sync messages from the zMail server to local cache (`~/.config/zcloak/mailboxes/{principal}/`). After sync, `inbox` and `sent` read from local cache without network access.
|
|
651
|
+
|
|
652
|
+
Internal command reference:
|
|
653
|
+
```bash
|
|
654
|
+
# Incremental sync (fetches only new messages since last sync)
|
|
655
|
+
zcloak-ai zmail sync
|
|
656
|
+
# Full re-sync (ignores saved cursor, re-fetches everything)
|
|
657
|
+
zcloak-ai zmail sync --full
|
|
658
|
+
# JSON summary output
|
|
659
|
+
zcloak-ai zmail sync --json
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
| Option | Description |
|
|
663
|
+
| -------- | ----------------------------------------- |
|
|
664
|
+
| `--full` | Ignore saved cursor, perform full re-sync |
|
|
665
|
+
| `--json` | Output sync summary as JSON |
|
|
666
|
+
|
|
667
|
+
Local cache layout:
|
|
668
|
+
```
|
|
669
|
+
~/.config/zcloak/mailboxes/{principal}/
|
|
670
|
+
inbox.json Cached inbox messages
|
|
671
|
+
sent.json Cached sent messages
|
|
672
|
+
sync-state.json Incremental sync cursors
|
|
673
|
+
```
|
|
674
|
+
|
|
712
675
|
#### Fetch Inbox
|
|
713
|
-
|
|
676
|
+
Read inbox messages. By default reads from local cache (populated by `sync`). Falls back to live API if no cache exists. Use `--online` to force live fetch.
|
|
677
|
+
|
|
714
678
|
Internal command reference:
|
|
715
679
|
```bash
|
|
716
|
-
#
|
|
680
|
+
# Read from local cache (default after sync)
|
|
717
681
|
zcloak-ai zmail inbox
|
|
718
|
-
# With filters
|
|
682
|
+
# With filters (work on both cached and online modes)
|
|
719
683
|
zcloak-ai zmail inbox --limit=10 --unread --from=<sender_ai_id>
|
|
720
|
-
#
|
|
721
|
-
zcloak-ai zmail inbox --
|
|
684
|
+
# Force live API fetch
|
|
685
|
+
zcloak-ai zmail inbox --online
|
|
686
|
+
# Pagination (online mode only)
|
|
687
|
+
zcloak-ai zmail inbox --online --after=<cursor>
|
|
722
688
|
# Raw JSON output
|
|
723
689
|
zcloak-ai zmail inbox --json
|
|
724
690
|
```
|
|
725
691
|
|
|
726
|
-
| Option | Description
|
|
727
|
-
| ------------------ |
|
|
728
|
-
| `--limit=<n>` | Max messages to
|
|
729
|
-
| `--
|
|
730
|
-
| `--
|
|
731
|
-
| `--
|
|
732
|
-
| `--
|
|
692
|
+
| Option | Description |
|
|
693
|
+
| ------------------ | --------------------------------------- |
|
|
694
|
+
| `--limit=<n>` | Max messages to display (default: 20) |
|
|
695
|
+
| `--unread` | Only show unread messages |
|
|
696
|
+
| `--from=<ai_id>` | Filter by sender AI ID |
|
|
697
|
+
| `--online` | Force live API fetch (skip local cache) |
|
|
698
|
+
| `--after=<cursor>` | Pagination cursor (online mode only) |
|
|
699
|
+
| `--json` | Output raw JSON response |
|
|
733
700
|
|
|
734
701
|
#### Fetch Sent Messages
|
|
735
|
-
|
|
702
|
+
Read sent messages. By default reads from local cache. Use `--online` to force live fetch.
|
|
703
|
+
|
|
736
704
|
Internal command reference:
|
|
737
705
|
```bash
|
|
738
706
|
zcloak-ai zmail sent
|
|
739
707
|
zcloak-ai zmail sent --limit=5 --to=<recipient_ai_id>
|
|
708
|
+
zcloak-ai zmail sent --online
|
|
740
709
|
zcloak-ai zmail sent --json
|
|
741
710
|
```
|
|
742
711
|
|
|
743
|
-
| Option | Description
|
|
744
|
-
| ------------------ |
|
|
745
|
-
| `--limit=<n>` | Max messages to
|
|
746
|
-
| `--
|
|
747
|
-
| `--
|
|
748
|
-
| `--
|
|
712
|
+
| Option | Description |
|
|
713
|
+
| ------------------ | --------------------------------------- |
|
|
714
|
+
| `--limit=<n>` | Max messages to display (default: 20) |
|
|
715
|
+
| `--to=<ai_id>` | Filter by recipient AI ID |
|
|
716
|
+
| `--online` | Force live API fetch (skip local cache) |
|
|
717
|
+
| `--after=<cursor>` | Pagination cursor (online mode only) |
|
|
718
|
+
| `--json` | Output raw JSON response |
|
|
749
719
|
|
|
750
720
|
#### Acknowledge Messages
|
|
751
721
|
Mark inbox messages as read.
|
|
@@ -757,11 +727,12 @@ zcloak-ai zmail ack --msg-id=abc123,def456
|
|
|
757
727
|
|
|
758
728
|
#### Typical zMail Workflow
|
|
759
729
|
This is an agent-side workflow. The agent performs all steps; the user only needs to know outcomes.
|
|
760
|
-
|
|
761
730
|
1. **Register** (one-time): `zcloak-ai zmail register`
|
|
762
731
|
2. **Send**: `zcloak-ai vetkey send-msg --to="alice#1234.agent" --text="Hello"` (auto-delivers via zMail)
|
|
763
|
-
3. **
|
|
764
|
-
4. **
|
|
765
|
-
5. **
|
|
732
|
+
3. **Reply**: `zcloak-ai vetkey send-msg --to="alice#1234.agent" --text="Got it!" --reply=<msg_id>`
|
|
733
|
+
4. **Sync**: `zcloak-ai zmail sync` (pull new messages to local cache)
|
|
734
|
+
5. **Check inbox**: `zcloak-ai zmail inbox --unread` (reads from local cache)
|
|
735
|
+
6. **Decrypt a message**: `zcloak-ai vetkey recv-msg --data='...' --json` (see §9.7)
|
|
736
|
+
7. **Acknowledge**: `zcloak-ai zmail ack --msg-id=<msg_id>`
|
|
766
737
|
|
|
767
738
|
> **URL resolution priority**: `--zmail-url` flag > `ZMAIL_URL` environment variable > config default (`https://mail.zcloak.ai`)
|
package/dist/bind.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* All commands support --identity=<pem_path> to specify identity file.
|
|
20
20
|
*/
|
|
21
21
|
import { generalParseAiIdToRecord, isReadableId } from './aiid.js';
|
|
22
|
+
import * as log from './log.js';
|
|
22
23
|
// ========== Help Information ==========
|
|
23
24
|
function showHelp() {
|
|
24
25
|
console.log('zCloak.ai Agent-Owner Binding Tool');
|
|
@@ -67,7 +68,7 @@ function parseAiIdToRecord(aiId) {
|
|
|
67
68
|
*/
|
|
68
69
|
async function resolveReadableIdToPrincipal(session, readableId) {
|
|
69
70
|
const idRecord = generalParseAiIdToRecord(readableId);
|
|
70
|
-
|
|
71
|
+
log.info(`Resolving ID "${readableId}" → id="${idRecord.id}", index=${idRecord.index.length ? idRecord.index[0].toString() : 'null'}...`);
|
|
71
72
|
const actor = await session.getAnonymousRegistryActor();
|
|
72
73
|
const result = await actor.user_profile_get_by_id(idRecord);
|
|
73
74
|
// opt UserProfile — empty array means not found
|
|
@@ -80,7 +81,7 @@ async function resolveReadableIdToPrincipal(session, readableId) {
|
|
|
80
81
|
throw new Error(`Readable ID "${readableId}" exists in registry but has no principal bound.`);
|
|
81
82
|
}
|
|
82
83
|
const principal = profile.principal_id[0];
|
|
83
|
-
|
|
84
|
+
log.info(`Resolved: ${readableId} → ${principal}`);
|
|
84
85
|
return principal;
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
@@ -128,7 +129,7 @@ async function cmdCheckPasskey(session, userInput) {
|
|
|
128
129
|
}
|
|
129
130
|
// Resolve AI ID → principal if needed
|
|
130
131
|
const userPrincipal = await resolveInputToPrincipal(session, userInput);
|
|
131
|
-
|
|
132
|
+
log.info('Checking passkey status...');
|
|
132
133
|
const result = await hasPasskey(session, userPrincipal);
|
|
133
134
|
if (result) {
|
|
134
135
|
console.log('Passkey registered: yes');
|
|
@@ -159,7 +160,7 @@ async function cmdPrepare(session, userInput) {
|
|
|
159
160
|
// Resolve AI ID → principal if needed
|
|
160
161
|
const userPrincipal = await resolveInputToPrincipal(session, userInput);
|
|
161
162
|
// Pre-check: ensure the target principal has a passkey before proceeding
|
|
162
|
-
|
|
163
|
+
log.info('Pre-check: verifying passkey status...');
|
|
163
164
|
const passkeyOk = await hasPasskey(session, userPrincipal);
|
|
164
165
|
if (!passkeyOk) {
|
|
165
166
|
console.error('Error: target principal has no passkey registered.');
|
|
@@ -167,15 +168,15 @@ async function cmdPrepare(session, userInput) {
|
|
|
167
168
|
console.error(`Please go to ${session.getSettingUrl()} and bind a passkey for this user first.`);
|
|
168
169
|
process.exit(1);
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
+
log.info('Pre-check passed: passkey found.');
|
|
171
172
|
const bindBase = session.getBindUrl();
|
|
172
173
|
// Step 1: Call agent_prepare_bond (requires identity, update call)
|
|
173
|
-
|
|
174
|
+
log.info('Calling agent_prepare_bond...');
|
|
174
175
|
const actor = await session.getRegistryActor();
|
|
175
176
|
const result = await actor.agent_prepare_bond(userPrincipal);
|
|
176
177
|
// Check return result — variant { Ok: text } | { Err: text }
|
|
177
178
|
if ('Err' in result) {
|
|
178
|
-
|
|
179
|
+
log.error('Binding preparation failed:');
|
|
179
180
|
console.log(`(variant { Err = "${result.Err}" })`);
|
|
180
181
|
process.exit(1);
|
|
181
182
|
}
|
|
@@ -214,7 +215,7 @@ export async function run(session) {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
catch (err) {
|
|
217
|
-
|
|
218
|
+
log.error(`Operation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
218
219
|
process.exit(1);
|
|
219
220
|
}
|
|
220
221
|
}
|
package/dist/bind.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAY,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAY,MAAM,WAAW,CAAC;AAC7E,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,yCAAyC;AACzC,SAAS,QAAQ;IACf,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,CAAC,4GAA4G,CAAC,CAAC;IAC1H,OAAO,CAAC,GAAG,CAAC,0GAA0G,CAAC,CAAC;IACxH,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,OAAO,CAAC,GAAG,CAAC,wFAAwF,CAAC,CAAC;IACtG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;IACrE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CA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I,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,eAAe;gBAClB,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBACtD,MAAM;YACR;gBACE,QAAQ,EAAE,CAAC;gBACX,IAAI,OAAO,EAAE,CAAC;oBACZ,OAAO,CAAC,KAAK,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAC;gBACjD,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,KAAK,CAAC,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* zcloak-ai bind <command> [args] Agent-Owner binding
|
|
14
14
|
* zcloak-ai doc <command> [args] Document tools
|
|
15
15
|
* zcloak-ai pow <base> <zeros> PoW computation
|
|
16
|
-
* zcloak-ai vetkey <command> [args] VetKey encryption/decryption
|
|
16
|
+
* zcloak-ai vetkey <command> [args] VetKey encryption/decryption
|
|
17
17
|
* zcloak-ai social <command> [args] Social profile query
|
|
18
18
|
* zcloak-ai zmail <command> [args] Encrypted mail (register, inbox, sent, ack)
|
|
19
19
|
* zcloak-ai pre-check Manually run the package/skill update pre-check
|
package/dist/cli.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* zcloak-ai bind <command> [args] Agent-Owner binding
|
|
14
14
|
* zcloak-ai doc <command> [args] Document tools
|
|
15
15
|
* zcloak-ai pow <base> <zeros> PoW computation
|
|
16
|
-
* zcloak-ai vetkey <command> [args] VetKey encryption/decryption
|
|
16
|
+
* zcloak-ai vetkey <command> [args] VetKey encryption/decryption
|
|
17
17
|
* zcloak-ai social <command> [args] Social profile query
|
|
18
18
|
* zcloak-ai zmail <command> [args] Encrypted mail (register, inbox, sent, ack)
|
|
19
19
|
* zcloak-ai pre-check Manually run the package/skill update pre-check
|
|
@@ -35,8 +35,11 @@ import path from 'path';
|
|
|
35
35
|
import { fileURLToPath } from 'url';
|
|
36
36
|
import { Session } from './session.js';
|
|
37
37
|
import { preCheck } from './pre-check.js';
|
|
38
|
-
import { ensureDaemonsBackground } from './vetkey.js';
|
|
39
38
|
import { DEFAULT_PEM_PATH, loadIdentityFromPath } from './identity.js';
|
|
39
|
+
import { STANDARD_DAEMON_KEY_NAMES, startDaemonBackground, stopAllDaemons } from './vetkey.js';
|
|
40
|
+
import { isDaemonAlive } from './daemon.js';
|
|
41
|
+
import * as log from './log.js';
|
|
42
|
+
import { migrateLegacyRuntimeDir } from './compat.js';
|
|
40
43
|
/** ESM equivalent of __dirname */
|
|
41
44
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
42
45
|
/** Supported modules and their corresponding script files (compiled in dist/ directory) */
|
|
@@ -69,9 +72,9 @@ function showHelp() {
|
|
|
69
72
|
console.log(' delete File deletion with 2FA verification (prepare, check, confirm)');
|
|
70
73
|
console.log(' doc Document tools (manifest, verify-manifest, hash, info)');
|
|
71
74
|
console.log(' pow PoW computation (<base_string> <zeros>)');
|
|
72
|
-
console.log(' vetkey VetKey encryption/decryption (encrypt-sign, decrypt,
|
|
75
|
+
console.log(' vetkey VetKey encryption/decryption (encrypt-sign, decrypt, ...)');
|
|
73
76
|
console.log(' social Social profile query (get-profile)');
|
|
74
|
-
console.log(' zmail Encrypted mail (register, inbox, sent, ack)');
|
|
77
|
+
console.log(' zmail Encrypted mail (register, sync, inbox, sent, ack)');
|
|
75
78
|
console.log(' pre-check Manually run the package/skill update pre-check');
|
|
76
79
|
console.log('');
|
|
77
80
|
console.log('Global options:');
|
|
@@ -102,6 +105,9 @@ function showHelp() {
|
|
|
102
105
|
* so the sub-script receives the same parsed arguments as before.
|
|
103
106
|
*/
|
|
104
107
|
async function main() {
|
|
108
|
+
// Migrate legacy ~/.vetkey-tool/ → ~/.config/zcloak/run/ (backward compat).
|
|
109
|
+
// Safe to call every invocation; no-ops when already migrated.
|
|
110
|
+
migrateLegacyRuntimeDir();
|
|
105
111
|
// Get module name (skip node and script path)
|
|
106
112
|
const moduleName = process.argv[2];
|
|
107
113
|
if (!moduleName || moduleName === '--help' || moduleName === '-h') {
|
|
@@ -110,11 +116,11 @@ async function main() {
|
|
|
110
116
|
}
|
|
111
117
|
if (moduleName === 'pre-check') {
|
|
112
118
|
const checkResult = await preCheck();
|
|
113
|
-
if (checkResult.
|
|
114
|
-
|
|
119
|
+
if (checkResult.message) {
|
|
120
|
+
log.info(checkResult.message);
|
|
115
121
|
}
|
|
116
122
|
else {
|
|
117
|
-
|
|
123
|
+
log.info('Pre-check complete. No updates were applied.');
|
|
118
124
|
}
|
|
119
125
|
process.exit(0);
|
|
120
126
|
}
|
|
@@ -132,9 +138,21 @@ async function main() {
|
|
|
132
138
|
// stop so the caller can reload context and re-run on the updated bits.
|
|
133
139
|
const checkResult = await preCheck();
|
|
134
140
|
if (checkResult.updated) {
|
|
135
|
-
|
|
141
|
+
// Stop all running daemons after a successful upgrade — the background
|
|
142
|
+
// daemons still point at the old package bits. They will be auto-restarted
|
|
143
|
+
// on the next command invocation via the warm-up logic below.
|
|
144
|
+
try {
|
|
145
|
+
await stopAllDaemons();
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// Best-effort — don't block upgrade on daemon stop failure
|
|
149
|
+
}
|
|
150
|
+
log.info(checkResult.message);
|
|
136
151
|
process.exit(0);
|
|
137
152
|
}
|
|
153
|
+
if (checkResult.message) {
|
|
154
|
+
log.warn(checkResult.message);
|
|
155
|
+
}
|
|
138
156
|
// Construct sub-argv without mutating process.argv.
|
|
139
157
|
// Format: [node_binary, script_path, ...remaining_args]
|
|
140
158
|
// This preserves the same index layout that parseArgs() expects (skips first 2 elements).
|
|
@@ -142,45 +160,51 @@ async function main() {
|
|
|
142
160
|
const subArgv = [process.argv[0], scriptPath, ...process.argv.slice(3)];
|
|
143
161
|
// Create a Session from the constructed argv
|
|
144
162
|
const session = new Session(subArgv);
|
|
145
|
-
// Daemon
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
// ── Daemon warm-up (best-effort, never blocks main command) ──────
|
|
164
|
+
// Each step is independent: fail at any step → skip the rest silently.
|
|
165
|
+
(() => {
|
|
166
|
+
// Step 1: Skip commands that conflict with daemon warm-up
|
|
167
|
+
const skipWarmUp = (moduleName === 'vetkey' && process.argv[3] === 'serve') ||
|
|
168
|
+
(moduleName === 'identity' && process.argv[3] === 'generate');
|
|
169
|
+
if (skipWarmUp)
|
|
170
|
+
return;
|
|
171
|
+
// Step 2: Resolve PEM path
|
|
172
|
+
const identityArg = process.argv.find(a => a.startsWith('--identity='));
|
|
173
|
+
const pemPath = identityArg
|
|
174
|
+
? identityArg.split('=').slice(1).join('=')
|
|
175
|
+
: DEFAULT_PEM_PATH;
|
|
176
|
+
// Step 3: PEM file must exist (no identity → no daemon)
|
|
177
|
+
if (!fs.existsSync(pemPath))
|
|
178
|
+
return;
|
|
179
|
+
// Step 4: Load identity and extract principal
|
|
180
|
+
let principal;
|
|
158
181
|
try {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// because it auto-creates the default PEM — we only want to start
|
|
162
|
-
// daemons when the user already has an identity.
|
|
163
|
-
const identityArg = process.argv.find(a => a.startsWith('--identity='));
|
|
164
|
-
const pemPath = identityArg
|
|
165
|
-
? identityArg.split('=').slice(1).join('=') // support paths containing '='
|
|
166
|
-
: DEFAULT_PEM_PATH;
|
|
167
|
-
if (fs.existsSync(pemPath)) {
|
|
168
|
-
const identity = loadIdentityFromPath(pemPath);
|
|
169
|
-
const principal = identity.getPrincipal().toText();
|
|
170
|
-
ensureDaemonsBackground(pemPath, principal);
|
|
171
|
-
}
|
|
182
|
+
const identity = loadIdentityFromPath(pemPath);
|
|
183
|
+
principal = identity.getPrincipal().toText();
|
|
172
184
|
}
|
|
173
185
|
catch {
|
|
174
|
-
//
|
|
186
|
+
return; // Identity load failed — skip warm-up
|
|
175
187
|
}
|
|
176
|
-
|
|
188
|
+
// Step 5: Check each standard daemon, start if not running
|
|
189
|
+
for (const keyName of STANDARD_DAEMON_KEY_NAMES) {
|
|
190
|
+
const derivationId = `${principal}:${keyName}`;
|
|
191
|
+
if (isDaemonAlive(derivationId))
|
|
192
|
+
continue;
|
|
193
|
+
try {
|
|
194
|
+
startDaemonBackground(pemPath, keyName);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// Best-effort — ignore spawn failures
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
})();
|
|
177
201
|
// Load and execute sub-script's run() function.
|
|
178
202
|
// After compilation, __dirname points to dist/, sub-scripts are in the same directory.
|
|
179
203
|
const mod = await import(scriptPath);
|
|
180
204
|
await mod.run(session);
|
|
181
205
|
}
|
|
182
206
|
main().catch((err) => {
|
|
183
|
-
|
|
207
|
+
log.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
184
208
|
process.exit(1);
|
|
185
209
|
});
|
|
186
210
|
//# sourceMappingURL=cli.js.map
|