feat(cli): add authored data sync commands#76
Conversation
|
Warning Review limit reached
More reviews will be available in 51 minutes and 34 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (9)
WalkthroughThis PR splits the CLI into relay and node command modules, adds an interactive node REPL runner, configures file-based and environment-driven logging, exposes authored-data-sync epochDuration and store types, and extends peer-session with a Peer type, a connect(alias) method, and optional module registration when starting a node. Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
2e1ee8e to
7f297aa
Compare
7f297aa to
b904aaa
Compare
0b26fc6 to
6c9234f
Compare
cebbeb7 to
9483c21
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/cli/src/relay.ts (2)
59-62: ⚡ Quick winAdd error handling in the SIGINT handler.
If
relaySession.shutdown()throws, the error will be uncaught and might prevent the process from exiting cleanly. Wrap the call in try-catch to ensure a graceful shutdown even if cleanup fails.♻️ Proposed error handling
process.on("SIGINT", async () => { - await relaySession.shutdown(); - process.exit(0); + try { + await relaySession.shutdown(); + } catch (error) { + console.error(`Error during shutdown: ${error instanceof Error ? error.message : String(error)}`); + } + process.exit(0); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/cli/src/relay.ts` around lines 59 - 62, In the SIGINT handler registered with process.on("SIGINT"), wrap the await relaySession.shutdown() call in a try-catch so any thrown error is caught; inside try await relaySession.shutdown(), and in catch log the error (use existing logger if available, otherwise console.error) and then ensure the process still exits (process.exit(0) on success, process.exit(1) on failure) so the process terminates cleanly even if relaySession.shutdown() fails.
42-44: ⚡ Quick winConsider wrapping
buildRelayAnnounceAddrin a try-catch for better error UX.
buildRelayAnnounceAddrthrows if the IP is invalid or if the port is 0. While the error messages are clear, an uncaught exception will display a stack trace. Wrapping in try-catch would allow you to format the error more cleanly and exit gracefully.♻️ Proposed error handling
const listenAddr = addr ?? localDevRelayListenAddr; let announceAddr: string | undefined; if (opts.publicIp) { - announceAddr = buildRelayAnnounceAddr(listenAddr, opts.publicIp); + try { + announceAddr = buildRelayAnnounceAddr(listenAddr, opts.publicIp); + } catch (error) { + console.error(`Failed to build relay announce address: ${error instanceof Error ? error.message : String(error)}`); + process.exit(1); + } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/cli/src/relay.ts` around lines 42 - 44, Wrap the call to buildRelayAnnounceAddr(listenAddr, opts.publicIp) in a try-catch inside the branch that checks opts.publicIp; on error, catch the thrown exception, log a clean user-facing message (including the error.message) instead of letting a stack trace print, and exit the process with a non-zero code so announceAddr isn't used when invalid. Ensure you reference announceAddr, listenAddr and opts.publicIp in the handler so the log gives context about which input failed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/src/logging.ts`:
- Around line 3-5: Wrap the parseLogLevel(process.env.PEERKIT_LOG) call in a
try-catch: if PEERKIT_LOG is set, attempt to parse it inside try and assign to
logLevel; on catch, write a clear user-friendly error to stderr (including the
invalid value and the parse error message) and exit non-zero (process.exit(1))
so the CLI fails fast with a helpful message; if PEERKIT_LOG is not set then
keep the existing default "warning". Use the existing symbol names logLevel,
parseLogLevel and PEERKIT_LOG in this change.
In `@packages/cli/src/relay.ts`:
- Around line 45-57: Wrap the call to startRelay in a try-catch to handle
startup failures: catch errors thrown by startRelay (e.g., transport/port
failures), log a clear message including the error (use console.error or
processLogger if available) and exit with a non-zero status; ensure you still
reference relaySession.dialAddr only after successful startRelay so the code
that logs Relay address runs inside the try block and any cleanup or graceful
shutdown logic can run in the catch/finally as needed.
---
Nitpick comments:
In `@packages/cli/src/relay.ts`:
- Around line 59-62: In the SIGINT handler registered with process.on("SIGINT"),
wrap the await relaySession.shutdown() call in a try-catch so any thrown error
is caught; inside try await relaySession.shutdown(), and in catch log the error
(use existing logger if available, otherwise console.error) and then ensure the
process still exits (process.exit(0) on success, process.exit(1) on failure) so
the process terminates cleanly even if relaySession.shutdown() fails.
- Around line 42-44: Wrap the call to buildRelayAnnounceAddr(listenAddr,
opts.publicIp) in a try-catch inside the branch that checks opts.publicIp; on
error, catch the thrown exception, log a clean user-facing message (including
the error.message) instead of letting a stack trace print, and exit the process
with a non-zero code so announceAddr isn't used when invalid. Ensure you
reference announceAddr, listenAddr and opts.publicIp in the handler so the log
gives context about which input failed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4c207ba0-bc6d-4ead-8cac-62957e6c24bc
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (8)
packages/authored-data-sync/src/authored-data-sync.tspackages/cli/package.jsonpackages/cli/src/commands.tspackages/cli/src/logging.tspackages/cli/src/main.tspackages/cli/src/node.tspackages/cli/src/relay.tspackages/peer-session/src/node.ts
9483c21 to
78b9f25
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/package.json`:
- Around line 32-33: The package.json uses exact versions for `@peerkit/api` and
`@peerkit/authored-data-sync` but other workspace `@peerkit` deps use caret ranges;
update the dependency entries for "`@peerkit/api`" and
"`@peerkit/authored-data-sync`" to use caret-prefixed versions (e.g.
^0.1.0-alpha.12) so they match the existing pattern for "`@peerkit/peer-session`"
and "`@peerkit/transport-libp2p-nodejs`" and then regenerate your lockfile
(npm/yarn/pnpm) if needed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 51362865-8a86-417f-b8e9-c81a95d58bb4
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (9)
packages/authored-data-sync/src/authored-data-sync.tspackages/authored-data-sync/src/index.tspackages/cli/package.jsonpackages/cli/src/commands.tspackages/cli/src/logging.tspackages/cli/src/main.tspackages/cli/src/node.tspackages/cli/src/relay.tspackages/peer-session/src/node.ts
✅ Files skipped from review due to trivial changes (2)
- packages/cli/src/logging.ts
- packages/authored-data-sync/src/authored-data-sync.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- packages/cli/src/relay.ts
- packages/peer-session/src/node.ts
- packages/cli/src/commands.ts
- packages/cli/src/main.ts
- packages/cli/src/node.ts
78b9f25 to
6bed28b
Compare
|
✔️ 6bed28b - Conventional commits check succeeded. |
Add commands to create data blobs in the in-memory store, inspect the store and pull them from other peers.