Skip to content

feat: add iris init / config check / config path (v0.1.16)#22

Merged
t2tx merged 3 commits into
mainfrom
feature/iris-init
Jun 22, 2026
Merged

feat: add iris init / config check / config path (v0.1.16)#22
t2tx merged 3 commits into
mainfrom
feature/iris-init

Conversation

@t2tx

@t2tx t2tx commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a config experience so users can generate, validate, and locate their config from the CLI instead of hand-writing ~/.iris-slack/config.toml.

  • iris init — writes a commented starter config (embedded as a string so it works from the SEA binary, which doesn't bundle the example file). Never overwrites an existing file; created 0600 since it holds Slack tokens.
  • iris config check — runs loadConfig() on the resolved path without starting the bridge; prints a per-project summary (name / mode / workDir / channel & user counts; no tokens). ConfigError is reported with the file path and a non-zero exit.
  • iris config path — prints which config file would be used (or reports none and suggests iris init).

Both inspect commands honor --config; otherwise they use the same resolveConfigPath() search the bridge uses.

Implementation

  • main()'s switch is now a dispatch table to keep complexity flat as commands are added.
  • README (en + ja) setup sections updated to lead with iris init → fill tokens → iris config check.
  • Ported from upstream (GitLab) v0.1.17. OSS-specific hardening is preserved: the execFileSync (no-shell) calls from the CodeQL fix and the resolveConfigPath(cwd/home) test seam are untouched — cli.ts changes are additive only, config.ts is unchanged.

Checks

  • pnpm verify — 99 tests pass
  • Verified live: init (0600 generate / no-overwrite), config check (OK summary + ConfigError cases), config path, help listing.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added iris init to generate a commented starter config template (created with secure permissions and without overwriting existing files)
    • Added iris config check to validate the effective configuration and display a summary
    • Added iris config path to show where the config is resolved from
  • Documentation
    • Updated the configuration setup instructions and “Configuration (TOML)” quick-start workflow with the new commands
  • Chores
    • Bumped the package version to 0.1.16

Config experience: generate, validate, and locate the config from the CLI,
instead of hand-writing ~/.iris-slack/config.toml.

- `iris init` — write a commented starter config (embedded string so it works
  from the SEA binary too); never overwrites; created 0600 (holds tokens)
- `iris config check` — validate via loadConfig() without starting; prints a
  per-project summary; ConfigError reported with path + non-zero exit
- `iris config path` — print which config file would be used

main()'s switch is now a dispatch table to keep complexity flat. README (en/ja)
setup updated. Ported from upstream (GitLab) v0.1.17; the OSS-specific
execFileSync hardening and resolveConfigPath(cwd/home) test seam are preserved
(cli.ts changes are additive only).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c837733c-e1c0-462a-a604-515032046a17

📥 Commits

Reviewing files that changed from the base of the PR and between 68b3c13 and cb11ef2.

📒 Files selected for processing (1)
  • src/cli.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli.ts

Walkthrough

Three new CLI subcommands (iris init, iris config path, iris config check) are added to src/cli.ts. The command dispatch is refactored from a switch to a COMMANDS lookup table. An embedded CONFIG_TEMPLATE drives iris init. Both READMEs are updated with quick-start instructions, and the package version is bumped to 0.1.16.

Changes

iris init & config subcommands

Layer / File(s) Summary
CLI imports and command dispatch refactor
src/cli.ts
Expands the ./config.js import to include resolveConfigPath, loadConfig, and ConfigError; replaces the main() switch with a COMMANDS dispatch map (with --help/-h and --version/-v aliases); and updates the help text and header comment to list the new subcommands.
CONFIG_TEMPLATE and init() command
src/cli.ts
Adds the embedded CONFIG_TEMPLATE constant (a commented starter TOML) and implements init(), which errors if the target file already exists, creates parent directories, and writes the template with mode 0600.
config path and config check subcommands
src/cli.ts
Implements resolveConfigForInspect() (honoring --config), configCmd() dispatcher, configPath() (prints path or search targets), and configCheck() (loads and validates config via loadConfig, prints per-project summary, handles ConfigError).
README updates and version bump
README.md, README.ja.md, package.json
Adds iris init / iris config check / iris config path quick-start blocks to both READMEs and bumps the version to 0.1.16.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add iris init / config check / config path (v0.1.16)' clearly summarizes the main changes: three new CLI commands (iris init, config check, config path) and a version bump.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/iris-init

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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 `@src/cli.ts`:
- Around line 210-214: The logic in the config path resolution needs to
explicitly reject the --config flag when it lacks a value argument instead of
silently falling back to auto-resolution. Modify the condition to check if
--config is present but either is the last argument or the next element is
undefined or another flag, and in that case throw or return an error with a
usage message. Only proceed with resolveConfigPath() as a fallback when --config
is not present at all.
- Around line 186-196: The code has a race condition where a file could be
created between the existsSync check and the writeFileSync call, causing the
non-overwrite guarantee to be broken. Replace the current check-then-write
pattern with an atomic file creation operation. Use the writeFileSync call with
a flag option set to 'wx' (write exclusive) instead of the default behavior,
which will throw an error if the file already exists, eliminating the race
condition. Remove the existsSync check since the exclusive write flag will
handle the collision detection atomically. Ensure the mkdirSync call is still
executed before attempting the atomic write to create the necessary directory
structure.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 496debbb-2939-4f57-bfb3-43179c2d5582

📥 Commits

Reviewing files that changed from the base of the PR and between 45f5391 and 68b3c13.

📒 Files selected for processing (4)
  • README.ja.md
  • README.md
  • package.json
  • src/cli.ts

Comment thread src/cli.ts Outdated
Comment thread src/cli.ts
Addresses CodeRabbit review on PR #22.

- init: replace the existsSync-then-write (TOCTOU) with an exclusive create
  (writeFileSync flag 'wx'), so the never-overwrite guarantee holds even
  against a concurrent creator. EEXIST → the same friendly notice.
- resolveConfigForInspect: when --config is present but has no value (or the
  next token is a flag), fail fast with a usage error instead of silently
  auto-resolving.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@t2tx

t2tx commented Jun 22, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai Addressed both:

  1. init now creates the file with writeFileSync(..., {flag: 'wx'}) (exclusive create) and removes the existsSync pre-check, so there's no TOCTOU gap — EEXIST yields the same 'already exists' notice.
  2. resolveConfigForInspect now fails fast with '--config requires a path argument.' when --config is present without a value (or followed by another flag), instead of silently auto-resolving.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@t2tx Both fixes look exactly right:

  1. wx flag — atomic exclusive create is the correct approach here; the kernel enforces uniqueness without any window for a race, and mapping EEXIST to the same user-facing notice keeps the UX identical to before.
  2. --config guard — failing fast with a clear message rather than silently falling back to auto-resolution prevents a confusing class of "why is it reading the wrong file?" bugs.

Thanks for the thorough follow-through on both points!

🐇✨

@t2tx t2tx closed this Jun 22, 2026
@t2tx t2tx reopened this Jun 22, 2026
@t2tx t2tx merged commit 6a2e32f into main Jun 22, 2026
5 checks passed
@t2tx t2tx deleted the feature/iris-init branch June 22, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant