@silicaclaw/cli 1.0.0-beta.2 → 1.0.0-beta.20

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 (70) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/INSTALL.md +36 -0
  3. package/README.md +40 -0
  4. package/apps/local-console/public/index.html +81 -63
  5. package/package.json +6 -1
  6. package/packages/core/dist/crypto.d.ts +6 -0
  7. package/packages/core/dist/crypto.js +50 -0
  8. package/packages/core/dist/directory.d.ts +17 -0
  9. package/packages/core/dist/directory.js +145 -0
  10. package/packages/core/dist/identity.d.ts +2 -0
  11. package/packages/core/dist/identity.js +18 -0
  12. package/packages/core/dist/index.d.ts +11 -0
  13. package/packages/core/dist/index.js +27 -0
  14. package/packages/core/dist/indexing.d.ts +6 -0
  15. package/packages/core/dist/indexing.js +43 -0
  16. package/packages/core/dist/presence.d.ts +4 -0
  17. package/packages/core/dist/presence.js +23 -0
  18. package/packages/core/dist/profile.d.ts +4 -0
  19. package/packages/core/dist/profile.js +39 -0
  20. package/packages/core/dist/publicProfileSummary.d.ts +70 -0
  21. package/packages/core/dist/publicProfileSummary.js +103 -0
  22. package/packages/core/dist/socialConfig.d.ts +99 -0
  23. package/packages/core/dist/socialConfig.js +287 -0
  24. package/packages/core/dist/socialResolver.d.ts +46 -0
  25. package/packages/core/dist/socialResolver.js +237 -0
  26. package/packages/core/dist/socialTemplate.d.ts +2 -0
  27. package/packages/core/dist/socialTemplate.js +88 -0
  28. package/packages/core/dist/types.d.ts +37 -0
  29. package/packages/core/dist/types.js +2 -0
  30. package/packages/core/src/socialResolver.ts +17 -5
  31. package/packages/network/dist/abstractions/messageEnvelope.d.ts +28 -0
  32. package/packages/network/dist/abstractions/messageEnvelope.js +36 -0
  33. package/packages/network/dist/abstractions/peerDiscovery.d.ts +43 -0
  34. package/packages/network/dist/abstractions/peerDiscovery.js +2 -0
  35. package/packages/network/dist/abstractions/topicCodec.d.ts +4 -0
  36. package/packages/network/dist/abstractions/topicCodec.js +2 -0
  37. package/packages/network/dist/abstractions/transport.d.ts +36 -0
  38. package/packages/network/dist/abstractions/transport.js +2 -0
  39. package/packages/network/dist/codec/jsonMessageEnvelopeCodec.d.ts +5 -0
  40. package/packages/network/dist/codec/jsonMessageEnvelopeCodec.js +24 -0
  41. package/packages/network/dist/codec/jsonTopicCodec.d.ts +5 -0
  42. package/packages/network/dist/codec/jsonTopicCodec.js +12 -0
  43. package/packages/network/dist/discovery/heartbeatPeerDiscovery.d.ts +28 -0
  44. package/packages/network/dist/discovery/heartbeatPeerDiscovery.js +144 -0
  45. package/packages/network/dist/index.d.ts +13 -0
  46. package/packages/network/dist/index.js +29 -0
  47. package/packages/network/dist/localEventBus.d.ts +9 -0
  48. package/packages/network/dist/localEventBus.js +47 -0
  49. package/packages/network/dist/mock.d.ts +8 -0
  50. package/packages/network/dist/mock.js +24 -0
  51. package/packages/network/dist/realPreview.d.ts +105 -0
  52. package/packages/network/dist/realPreview.js +327 -0
  53. package/packages/network/dist/transport/udpLanBroadcastTransport.d.ts +23 -0
  54. package/packages/network/dist/transport/udpLanBroadcastTransport.js +153 -0
  55. package/packages/network/dist/types.d.ts +6 -0
  56. package/packages/network/dist/types.js +2 -0
  57. package/packages/network/dist/webrtcPreview.d.ts +163 -0
  58. package/packages/network/dist/webrtcPreview.js +844 -0
  59. package/packages/storage/dist/index.d.ts +3 -0
  60. package/packages/storage/dist/index.js +19 -0
  61. package/packages/storage/dist/jsonRepo.d.ts +7 -0
  62. package/packages/storage/dist/jsonRepo.js +29 -0
  63. package/packages/storage/dist/repos.d.ts +21 -0
  64. package/packages/storage/dist/repos.js +41 -0
  65. package/packages/storage/dist/socialRuntimeRepo.d.ts +5 -0
  66. package/packages/storage/dist/socialRuntimeRepo.js +52 -0
  67. package/packages/storage/tsconfig.json +6 -1
  68. package/scripts/quickstart.sh +280 -14
  69. package/scripts/silicaclaw-cli.mjs +271 -1
  70. package/scripts/silicaclaw-gateway.mjs +410 -0
package/CHANGELOG.md CHANGED
@@ -8,6 +8,14 @@
8
8
  - `INSTALL.md`
9
9
  - `DEMO_GUIDE.md`
10
10
  - `RELEASE_NOTES_v1.0.md`
11
+ - CLI onboarding install UX polish:
12
+ - added shell alias fallback (`silicaclaw -> npx @silicaclaw/cli@beta`) when global install is unavailable
13
+ - reduced reliance on manual PATH/env edits for first-run success
14
+ - `silicaclaw update` guidance polish:
15
+ - prioritize zero-setup `npx` flow
16
+ - clarify global install is optional
17
+ - hide global-install recommendation during `npx` runtime to avoid repeated `EACCES` loops
18
+ - add explicit `command not found` alias guidance for first-run shells
11
19
  - README first-screen and structure polish:
12
20
  - fixed v1.0 beta project positioning
13
21
  - added concise feature summary
package/INSTALL.md CHANGED
@@ -22,11 +22,47 @@ CLI-style onboarding command (recommended, zero-config):
22
22
  npx @silicaclaw/cli@beta onboard
23
23
  ```
24
24
 
25
+ Cross-network quick wizard (defaults to global-preview):
26
+
27
+ ```bash
28
+ npx @silicaclaw/cli@beta connect
29
+ ```
30
+
31
+ Check/update CLI version:
32
+
33
+ ```bash
34
+ npx @silicaclaw/cli@beta update
35
+ ```
36
+
37
+ Gateway background service commands:
38
+
39
+ ```bash
40
+ npx @silicaclaw/cli@beta gateway start --mode=local
41
+ npx @silicaclaw/cli@beta gateway status
42
+ npx @silicaclaw/cli@beta gateway restart --mode=lan
43
+ npx @silicaclaw/cli@beta gateway stop
44
+ ```
45
+
46
+ For most home users, just press Enter on defaults and use `local` mode first.
47
+
25
48
  Optional global install (advanced users only):
26
49
 
27
50
  ```bash
28
51
  npm i -g @silicaclaw/cli
29
52
  silicaclaw onboard
53
+ silicaclaw connect
54
+ silicaclaw update
55
+ silicaclaw gateway start --mode=local
56
+ silicaclaw gateway status
57
+ silicaclaw gateway stop
58
+ ```
59
+
60
+ If global install fails with `EACCES`, use alias mode (no PATH edits):
61
+
62
+ ```bash
63
+ alias silicaclaw='npx -y @silicaclaw/cli@beta'
64
+ silicaclaw onboard
65
+ silicaclaw update
30
66
  ```
31
67
 
32
68
  ## 3. Run
package/README.md CHANGED
@@ -28,6 +28,27 @@ Without servers, accounts, or central control.
28
28
  npx @silicaclaw/cli@beta onboard
29
29
  ```
30
30
 
31
+ Cross-network preview quick wizard:
32
+
33
+ ```bash
34
+ npx @silicaclaw/cli@beta connect
35
+ ```
36
+
37
+ Check and update CLI version:
38
+
39
+ ```bash
40
+ npx @silicaclaw/cli@beta update
41
+ ```
42
+
43
+ Background gateway service:
44
+
45
+ ```bash
46
+ npx @silicaclaw/cli@beta gateway start --mode=local
47
+ npx @silicaclaw/cli@beta gateway status
48
+ npx @silicaclaw/cli@beta gateway restart --mode=lan
49
+ npx @silicaclaw/cli@beta gateway stop
50
+ ```
51
+
31
52
  Or manual:
32
53
 
33
54
  ```bash
@@ -53,11 +74,30 @@ Zero-config (recommended, no global install / no PATH setup):
53
74
  npx @silicaclaw/cli@beta onboard
54
75
  ```
55
76
 
77
+ Cross-network preview (global-preview first):
78
+
79
+ ```bash
80
+ npx @silicaclaw/cli@beta connect
81
+ ```
82
+
56
83
  Optional global install:
57
84
 
58
85
  ```bash
59
86
  npm i -g @silicaclaw/cli
60
87
  silicaclaw onboard
88
+ silicaclaw connect
89
+ silicaclaw update
90
+ silicaclaw gateway start --mode=local
91
+ silicaclaw gateway status
92
+ silicaclaw gateway stop
93
+ ```
94
+
95
+ If global install is blocked by system permissions (`EACCES`), use alias mode:
96
+
97
+ ```bash
98
+ alias silicaclaw='npx -y @silicaclaw/cli@beta'
99
+ silicaclaw onboard
100
+ silicaclaw update
61
101
  ```
62
102
 
63
103
  ## Quick Start (OpenClaw-style)
@@ -427,6 +427,22 @@
427
427
  white-space: pre-wrap;
428
428
  word-break: break-word;
429
429
  }
430
+ .advanced-panel {
431
+ margin-top: 10px;
432
+ }
433
+ .advanced-panel summary {
434
+ cursor: pointer;
435
+ list-style: none;
436
+ user-select: none;
437
+ }
438
+ .advanced-panel summary::-webkit-details-marker { display: none; }
439
+ .advanced-panel summary::after {
440
+ content: "Show";
441
+ float: right;
442
+ color: var(--muted);
443
+ font-size: 12px;
444
+ }
445
+ .advanced-panel[open] summary::after { content: "Hide"; }
430
446
 
431
447
  .toast {
432
448
  position: fixed;
@@ -474,10 +490,7 @@
474
490
  <button class="tab active" data-tab="overview">Overview</button>
475
491
  <button class="tab" data-tab="profile">Profile</button>
476
492
  <button class="tab" data-tab="network">Network</button>
477
- <button class="tab" data-tab="peers">Peers</button>
478
- <button class="tab" data-tab="discovery">Discovery Events</button>
479
- <button class="tab" data-tab="social">Social Config</button>
480
- <button class="tab" data-tab="logs">Logs</button>
493
+ <button class="tab" data-tab="social">Social</button>
481
494
  </nav>
482
495
 
483
496
  <div class="sidebar-foot" id="sideMeta">adapter: -<br/>namespace: -</div>
@@ -602,15 +615,20 @@
602
615
  <div class="mono" id="networkComponents"></div>
603
616
  </div>
604
617
  <div class="card">
605
- <h3 class="title-sm">Actions</h3>
618
+ <h3 class="title-sm">Quick Actions</h3>
606
619
  <div class="actions">
607
620
  <button id="startBroadcastBtn">Start Broadcast</button>
608
621
  <button class="secondary" id="stopBroadcastBtn">Stop Broadcast</button>
609
622
  <button class="secondary" id="broadcastNowBtn">Broadcast Now</button>
623
+ </div>
624
+ <details class="advanced-panel">
625
+ <summary class="title-sm">Advanced Actions</summary>
626
+ <div class="actions" style="margin-top:10px;">
610
627
  <button class="secondary" id="refreshCacheBtn">Refresh Cache</button>
611
628
  <button class="secondary" id="clearCacheBtn">Clear Discovered Cache</button>
612
629
  <button class="secondary" id="quickGlobalPreviewBtn">Enable Cross-network Preview</button>
613
630
  </div>
631
+ </details>
614
632
  <div id="networkFeedback" class="feedback" style="margin-top:10px;">Ready.</div>
615
633
  </div>
616
634
  </div>
@@ -624,32 +642,47 @@
624
642
  <div class="mono mono-block" id="networkStatsSnapshot">-</div>
625
643
  </div>
626
644
  </div>
627
- </section>
628
-
629
- <section id="view-peers" class="view">
630
- <div class="grid" id="peerCards"></div>
631
- <div class="card" style="margin-top:10px;">
632
- <h3 class="title-sm">Peer Inventory</h3>
633
- <div id="peerTableWrap"></div>
634
- </div>
635
- <div class="card" style="margin-top:10px;">
636
- <h3 class="title-sm">Peer Discovery Stats</h3>
637
- <div class="mono mono-block" id="peerStatsWrap">-</div>
638
- </div>
639
- </section>
640
-
641
- <section id="view-discovery" class="view">
642
- <div class="grid" id="discoveryCards"></div>
643
- <div class="split">
645
+ <details class="advanced-panel card">
646
+ <summary class="title-sm">Diagnostics</summary>
647
+ <div class="grid" id="peerCards" style="margin-top:10px;"></div>
644
648
  <div class="card" style="margin-top:10px;">
645
- <h3 class="title-sm">Recent Discovery Events</h3>
646
- <div class="logs" id="discoveryEventList"></div>
649
+ <h3 class="title-sm">Peer Inventory</h3>
650
+ <div id="peerTableWrap"></div>
647
651
  </div>
648
652
  <div class="card" style="margin-top:10px;">
649
- <h3 class="title-sm">Discovery Snapshot</h3>
650
- <div class="mono mono-block" id="discoverySnapshot">-</div>
653
+ <h3 class="title-sm">Peer Discovery Stats</h3>
654
+ <div class="mono mono-block" id="peerStatsWrap">-</div>
651
655
  </div>
652
- </div>
656
+ <div class="grid" id="discoveryCards" style="margin-top:10px;"></div>
657
+ <div class="split">
658
+ <div class="card" style="margin-top:10px;">
659
+ <h3 class="title-sm">Recent Discovery Events</h3>
660
+ <div class="logs" id="discoveryEventList"></div>
661
+ </div>
662
+ <div class="card" style="margin-top:10px;">
663
+ <h3 class="title-sm">Discovery Snapshot</h3>
664
+ <div class="mono mono-block" id="discoverySnapshot">-</div>
665
+ </div>
666
+ </div>
667
+ <div class="card" style="margin-top:10px;">
668
+ <h3 class="title-sm">Logs</h3>
669
+ <div class="toolbar">
670
+ <div class="field">
671
+ <label for="logLevelFilter">Category</label>
672
+ <select id="logLevelFilter">
673
+ <option value="all">all</option>
674
+ <option value="info">info</option>
675
+ <option value="warn">warn</option>
676
+ <option value="error">error</option>
677
+ </select>
678
+ </div>
679
+ <div>
680
+ <button type="button" class="secondary" id="refreshLogsBtn">Refresh Logs</button>
681
+ </div>
682
+ </div>
683
+ <div class="logs" id="logList"></div>
684
+ </div>
685
+ </details>
653
686
  </section>
654
687
 
655
688
  <section id="view-social" class="view">
@@ -666,22 +699,25 @@
666
699
  <div class="grid" id="socialAdvancedCards" style="margin-top:10px;"></div>
667
700
  <div class="mono mono-block" id="socialAdvancedWrap" style="margin-top:10px;">-</div>
668
701
  </details>
669
- <div class="split">
670
- <div class="card" style="margin-top:10px;">
671
- <h3 class="title-sm">Source & Parsed Frontmatter</h3>
672
- <div class="mono mono-block" id="socialSourceWrap">-</div>
673
- <div style="height:10px;"></div>
674
- <div class="mono mono-block" id="socialRawWrap">-</div>
702
+ <details class="advanced-panel card">
703
+ <summary class="title-sm">Source / Runtime / Template</summary>
704
+ <div class="split">
705
+ <div class="card" style="margin-top:10px;">
706
+ <h3 class="title-sm">Source & Parsed Frontmatter</h3>
707
+ <div class="mono mono-block" id="socialSourceWrap">-</div>
708
+ <div style="height:10px;"></div>
709
+ <div class="mono mono-block" id="socialRawWrap">-</div>
710
+ </div>
711
+ <div class="card" style="margin-top:10px;">
712
+ <h3 class="title-sm">Runtime Summary</h3>
713
+ <div class="mono mono-block" id="socialRuntimeWrap">-</div>
714
+ </div>
675
715
  </div>
676
716
  <div class="card" style="margin-top:10px;">
677
- <h3 class="title-sm">Runtime Summary</h3>
678
- <div class="mono mono-block" id="socialRuntimeWrap">-</div>
717
+ <h3 class="title-sm">Export Template Preview</h3>
718
+ <div class="mono mono-block" id="socialTemplateWrap">-</div>
679
719
  </div>
680
- </div>
681
- <div class="card" style="margin-top:10px;">
682
- <h3 class="title-sm">Export Template Preview</h3>
683
- <div class="mono mono-block" id="socialTemplateWrap">-</div>
684
- </div>
720
+ </details>
685
721
  <div class="card" style="margin-top:10px;">
686
722
  <h3 class="title-sm">Actions</h3>
687
723
  <div class="toolbar">
@@ -707,27 +743,6 @@
707
743
  <div id="socialFeedback" class="feedback" style="margin-top:10px;">Ready.</div>
708
744
  </div>
709
745
  </section>
710
-
711
- <section id="view-logs" class="view">
712
- <div class="card">
713
- <h3 class="title-sm">Recent Logs</h3>
714
- <div class="toolbar">
715
- <div class="field">
716
- <label for="logLevelFilter">Category</label>
717
- <select id="logLevelFilter">
718
- <option value="all">all</option>
719
- <option value="info">info</option>
720
- <option value="warn">warn</option>
721
- <option value="error">error</option>
722
- </select>
723
- </div>
724
- <div>
725
- <button type="button" class="secondary" id="refreshLogsBtn">Refresh Logs</button>
726
- </div>
727
- </div>
728
- <div class="logs" id="logList"></div>
729
- </div>
730
- </section>
731
746
  </main>
732
747
  </div>
733
748
 
@@ -919,7 +934,7 @@
919
934
  }
920
935
  activeTab = tab;
921
936
  document.querySelectorAll('.tab').forEach((b) => b.classList.toggle('active', b.dataset.tab === tab));
922
- ['overview', 'profile', 'network', 'peers', 'discovery', 'social', 'logs'].forEach((k) => {
937
+ ['overview', 'profile', 'network', 'social'].forEach((k) => {
923
938
  document.getElementById(`view-${k}`).classList.toggle('active', k === tab);
924
939
  });
925
940
  if (tab === 'profile' && !profileDirty && !profileSaving) {
@@ -1320,7 +1335,10 @@
1320
1335
 
1321
1336
  async function refreshAll() {
1322
1337
  try {
1323
- const tasks = [refreshOverview(), refreshNetwork(), refreshPeers(), refreshDiscovery(), refreshSocial(), refreshLogs(), refreshPublicProfilePreview()];
1338
+ const tasks = [refreshOverview(), refreshNetwork(), refreshSocial(), refreshPublicProfilePreview()];
1339
+ if (activeTab === 'network') {
1340
+ tasks.push(refreshPeers(), refreshDiscovery(), refreshLogs());
1341
+ }
1324
1342
  const shouldRefreshProfile = !(activeTab === 'profile' && profileDirty);
1325
1343
  if (shouldRefreshProfile) {
1326
1344
  tasks.push(refreshProfile());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silicaclaw/cli",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.20",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,12 +15,15 @@
15
15
  "apps/public-explorer/src/**",
16
16
  "apps/public-explorer/tsconfig.json",
17
17
  "packages/core/package.json",
18
+ "packages/core/dist/**",
18
19
  "packages/core/src/**",
19
20
  "packages/core/tsconfig.json",
20
21
  "packages/network/package.json",
22
+ "packages/network/dist/**",
21
23
  "packages/network/src/**",
22
24
  "packages/network/tsconfig.json",
23
25
  "packages/storage/package.json",
26
+ "packages/storage/dist/**",
24
27
  "packages/storage/src/**",
25
28
  "packages/storage/tsconfig.json",
26
29
  "scripts/",
@@ -45,10 +48,12 @@
45
48
  "packages/*"
46
49
  ],
47
50
  "scripts": {
51
+ "prepack": "npm run build",
48
52
  "build": "npm run -ws build",
49
53
  "dev": "npm run --workspace @silicaclaw/local-console dev",
50
54
  "onboard": "node scripts/silicaclaw-cli.mjs onboard",
51
55
  "quickstart": "bash scripts/quickstart.sh",
56
+ "gateway": "node scripts/silicaclaw-gateway.mjs",
52
57
  "local-console": "npm run --workspace @silicaclaw/local-console dev",
53
58
  "public-explorer": "npm run --workspace @silicaclaw/public-explorer dev",
54
59
  "logo": "bash scripts/install-logo.sh",
@@ -0,0 +1,6 @@
1
+ export declare function toBase64(input: Uint8Array): string;
2
+ export declare function fromBase64(input: string): Uint8Array;
3
+ export declare function hashPublicKey(publicKey: Uint8Array): string;
4
+ export declare function stableStringify(input: unknown): string;
5
+ export declare function signPayload(payload: unknown, privateKeyBase64: string): string;
6
+ export declare function verifyPayload(payload: unknown, signatureBase64: string, publicKeyBase64: string): boolean;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.toBase64 = toBase64;
7
+ exports.fromBase64 = fromBase64;
8
+ exports.hashPublicKey = hashPublicKey;
9
+ exports.stableStringify = stableStringify;
10
+ exports.signPayload = signPayload;
11
+ exports.verifyPayload = verifyPayload;
12
+ const crypto_1 = require("crypto");
13
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
14
+ function toBase64(input) {
15
+ return Buffer.from(input).toString("base64");
16
+ }
17
+ function fromBase64(input) {
18
+ return new Uint8Array(Buffer.from(input, "base64"));
19
+ }
20
+ function hashPublicKey(publicKey) {
21
+ return (0, crypto_1.createHash)("sha256").update(publicKey).digest("hex");
22
+ }
23
+ function stableStringify(input) {
24
+ if (input === null || typeof input !== "object") {
25
+ return JSON.stringify(input);
26
+ }
27
+ if (Array.isArray(input)) {
28
+ return `[${input.map((item) => stableStringify(item)).join(",")}]`;
29
+ }
30
+ const entries = Object.entries(input)
31
+ .filter(([, value]) => value !== undefined)
32
+ .sort(([a], [b]) => a.localeCompare(b));
33
+ return `{${entries
34
+ .map(([key, value]) => `${JSON.stringify(key)}:${stableStringify(value)}`)
35
+ .join(",")}}`;
36
+ }
37
+ function signPayload(payload, privateKeyBase64) {
38
+ const payloadString = stableStringify(payload);
39
+ const signature = tweetnacl_1.default.sign.detached(Buffer.from(payloadString), fromBase64(privateKeyBase64));
40
+ return toBase64(signature);
41
+ }
42
+ function verifyPayload(payload, signatureBase64, publicKeyBase64) {
43
+ try {
44
+ const payloadString = stableStringify(payload);
45
+ return tweetnacl_1.default.sign.detached.verify(Buffer.from(payloadString), fromBase64(signatureBase64), fromBase64(publicKeyBase64));
46
+ }
47
+ catch {
48
+ return false;
49
+ }
50
+ }
@@ -0,0 +1,17 @@
1
+ import { DirectoryState, IndexRefRecord, PresenceRecord, PublicProfile, SignedProfileRecord } from "./types";
2
+ export declare const DEFAULT_PRESENCE_TTL_MS = 30000;
3
+ export declare function createEmptyDirectoryState(): DirectoryState;
4
+ export declare function ingestProfileRecord(state: DirectoryState, record: SignedProfileRecord): DirectoryState;
5
+ export declare function ingestPresenceRecord(state: DirectoryState, record: PresenceRecord): DirectoryState;
6
+ export declare function ingestIndexRecord(state: DirectoryState, record: IndexRefRecord): DirectoryState;
7
+ export declare function isAgentOnline(lastSeenAt: number | undefined, now?: number, ttlMs?: number): boolean;
8
+ export declare function cleanupExpiredPresence(state: DirectoryState, now?: number, ttlMs?: number): {
9
+ state: DirectoryState;
10
+ removed: number;
11
+ };
12
+ export declare function rebuildIndexForProfile(state: DirectoryState, profile: PublicProfile): DirectoryState;
13
+ export declare function dedupeIndex(state: DirectoryState): DirectoryState;
14
+ export declare function searchDirectory(state: DirectoryState, keyword: string, options?: {
15
+ now?: number;
16
+ presenceTTLms?: number;
17
+ }): PublicProfile[];
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_PRESENCE_TTL_MS = void 0;
4
+ exports.createEmptyDirectoryState = createEmptyDirectoryState;
5
+ exports.ingestProfileRecord = ingestProfileRecord;
6
+ exports.ingestPresenceRecord = ingestPresenceRecord;
7
+ exports.ingestIndexRecord = ingestIndexRecord;
8
+ exports.isAgentOnline = isAgentOnline;
9
+ exports.cleanupExpiredPresence = cleanupExpiredPresence;
10
+ exports.rebuildIndexForProfile = rebuildIndexForProfile;
11
+ exports.dedupeIndex = dedupeIndex;
12
+ exports.searchDirectory = searchDirectory;
13
+ const indexing_1 = require("./indexing");
14
+ exports.DEFAULT_PRESENCE_TTL_MS = 30_000;
15
+ function createEmptyDirectoryState() {
16
+ return {
17
+ profiles: {},
18
+ presence: {},
19
+ index: {},
20
+ };
21
+ }
22
+ function ingestProfileRecord(state, record) {
23
+ const next = {
24
+ profiles: { ...state.profiles },
25
+ presence: { ...state.presence },
26
+ index: { ...state.index },
27
+ };
28
+ next.profiles[record.profile.agent_id] = record.profile;
29
+ return rebuildIndexForProfile(next, record.profile);
30
+ }
31
+ function ingestPresenceRecord(state, record) {
32
+ return {
33
+ profiles: { ...state.profiles },
34
+ presence: {
35
+ ...state.presence,
36
+ [record.agent_id]: record.timestamp,
37
+ },
38
+ index: { ...state.index },
39
+ };
40
+ }
41
+ function ingestIndexRecord(state, record) {
42
+ const existing = new Set(state.index[record.key] ?? []);
43
+ if (existing.has(record.agent_id)) {
44
+ return state;
45
+ }
46
+ existing.add(record.agent_id);
47
+ return {
48
+ profiles: { ...state.profiles },
49
+ presence: { ...state.presence },
50
+ index: {
51
+ ...state.index,
52
+ [record.key]: Array.from(existing),
53
+ },
54
+ };
55
+ }
56
+ function isAgentOnline(lastSeenAt, now = Date.now(), ttlMs = exports.DEFAULT_PRESENCE_TTL_MS) {
57
+ if (!lastSeenAt) {
58
+ return false;
59
+ }
60
+ return now - lastSeenAt <= ttlMs;
61
+ }
62
+ function cleanupExpiredPresence(state, now = Date.now(), ttlMs = exports.DEFAULT_PRESENCE_TTL_MS) {
63
+ let removed = 0;
64
+ const presence = {};
65
+ for (const [agentId, timestamp] of Object.entries(state.presence)) {
66
+ if (isAgentOnline(timestamp, now, ttlMs)) {
67
+ presence[agentId] = timestamp;
68
+ }
69
+ else {
70
+ removed += 1;
71
+ }
72
+ }
73
+ if (removed === 0) {
74
+ return { state, removed: 0 };
75
+ }
76
+ return {
77
+ state: {
78
+ profiles: { ...state.profiles },
79
+ presence,
80
+ index: { ...state.index },
81
+ },
82
+ removed,
83
+ };
84
+ }
85
+ function rebuildIndexForProfile(state, profile) {
86
+ const keys = (0, indexing_1.buildIndexKeys)(profile);
87
+ const nextIndex = {};
88
+ for (const [key, ids] of Object.entries(state.index)) {
89
+ const filtered = ids.filter((id) => id !== profile.agent_id);
90
+ if (filtered.length > 0) {
91
+ nextIndex[key] = Array.from(new Set(filtered));
92
+ }
93
+ }
94
+ for (const key of keys) {
95
+ const existing = new Set(nextIndex[key] ?? []);
96
+ existing.add(profile.agent_id);
97
+ nextIndex[key] = Array.from(existing);
98
+ }
99
+ return {
100
+ profiles: { ...state.profiles },
101
+ presence: { ...state.presence },
102
+ index: nextIndex,
103
+ };
104
+ }
105
+ function dedupeIndex(state) {
106
+ const index = {};
107
+ for (const [key, ids] of Object.entries(state.index)) {
108
+ index[key] = Array.from(new Set(ids));
109
+ }
110
+ return {
111
+ profiles: { ...state.profiles },
112
+ presence: { ...state.presence },
113
+ index,
114
+ };
115
+ }
116
+ function searchDirectory(state, keyword, options) {
117
+ const now = options?.now ?? Date.now();
118
+ const presenceTTLms = options?.presenceTTLms ?? exports.DEFAULT_PRESENCE_TTL_MS;
119
+ const normalized = keyword.trim().toLowerCase();
120
+ const baseList = normalized.length === 0
121
+ ? Object.values(state.profiles)
122
+ : Array.from(new Set([
123
+ ...(state.index[`tag:${normalized}`] ?? []),
124
+ ...(state.index[`name:${normalized.replace(/[^a-z0-9]+/g, "")}`] ?? []),
125
+ ]))
126
+ .map((agentId) => state.profiles[agentId])
127
+ .filter((profile) => Boolean(profile));
128
+ return baseList
129
+ .slice()
130
+ .sort((a, b) => {
131
+ const aOnline = isAgentOnline(state.presence[a.agent_id], now, presenceTTLms) ? 1 : 0;
132
+ const bOnline = isAgentOnline(state.presence[b.agent_id], now, presenceTTLms) ? 1 : 0;
133
+ if (aOnline !== bOnline) {
134
+ return bOnline - aOnline;
135
+ }
136
+ if (a.updated_at !== b.updated_at) {
137
+ return b.updated_at - a.updated_at;
138
+ }
139
+ const byName = a.display_name.localeCompare(b.display_name);
140
+ if (byName !== 0) {
141
+ return byName;
142
+ }
143
+ return a.agent_id.localeCompare(b.agent_id);
144
+ });
145
+ }
@@ -0,0 +1,2 @@
1
+ import { AgentIdentity } from "./types";
2
+ export declare function createIdentity(now?: number): AgentIdentity;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createIdentity = createIdentity;
7
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
8
+ const crypto_1 = require("./crypto");
9
+ function createIdentity(now = Date.now()) {
10
+ const pair = tweetnacl_1.default.sign.keyPair();
11
+ const publicKey = (0, crypto_1.toBase64)(pair.publicKey);
12
+ return {
13
+ agent_id: (0, crypto_1.hashPublicKey)(pair.publicKey),
14
+ public_key: publicKey,
15
+ private_key: (0, crypto_1.toBase64)(pair.secretKey),
16
+ created_at: now,
17
+ };
18
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./types";
2
+ export * from "./crypto";
3
+ export * from "./identity";
4
+ export * from "./profile";
5
+ export * from "./presence";
6
+ export * from "./indexing";
7
+ export * from "./directory";
8
+ export * from "./publicProfileSummary";
9
+ export * from "./socialConfig";
10
+ export * from "./socialResolver";
11
+ export * from "./socialTemplate";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./crypto"), exports);
19
+ __exportStar(require("./identity"), exports);
20
+ __exportStar(require("./profile"), exports);
21
+ __exportStar(require("./presence"), exports);
22
+ __exportStar(require("./indexing"), exports);
23
+ __exportStar(require("./directory"), exports);
24
+ __exportStar(require("./publicProfileSummary"), exports);
25
+ __exportStar(require("./socialConfig"), exports);
26
+ __exportStar(require("./socialResolver"), exports);
27
+ __exportStar(require("./socialTemplate"), exports);
@@ -0,0 +1,6 @@
1
+ import { IndexRefRecord, PublicProfile } from "./types";
2
+ export declare function normalizeTag(tag: string): string;
3
+ export declare function buildTagIndexKeys(tags: string[]): string[];
4
+ export declare function buildNamePrefixKeys(displayName: string): string[];
5
+ export declare function buildIndexKeys(profile: PublicProfile): string[];
6
+ export declare function buildIndexRecords(profile: PublicProfile): IndexRefRecord[];