@andrzejchm/notion-cli 0.1.2 → 0.3.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.
@@ -0,0 +1,81 @@
1
+ # notion-cli for OpenCode
2
+
3
+ Complete guide for using notion-cli with [OpenCode](https://opencode.ai).
4
+
5
+ ## Quick Install
6
+
7
+ Tell OpenCode:
8
+
9
+ ```
10
+ Fetch and follow instructions from https://raw.githubusercontent.com/andrzejchm/notion-cli/main/docs/README.agents.md
11
+ ```
12
+
13
+ ## Installation
14
+
15
+ ### 1. Install the CLI
16
+
17
+ ```bash
18
+ # Homebrew (recommended)
19
+ brew tap andrzejchm/notion-cli
20
+ brew install notion-cli
21
+
22
+ # npm (alternative)
23
+ npm install -g @andrzejchm/notion-cli
24
+ ```
25
+
26
+ Homebrew bundles Node.js automatically. npm requires Node.js ≥ 22.
27
+
28
+ ### 2. Install the skill file
29
+
30
+ ```bash
31
+ mkdir -p ~/.config/opencode/skills/using-notion-cli
32
+ curl -fsSL https://raw.githubusercontent.com/andrzejchm/notion-cli/main/docs/skills/using-notion-cli/SKILL.md \
33
+ -o ~/.config/opencode/skills/using-notion-cli/SKILL.md
34
+ ```
35
+
36
+ ### 3. Authenticate
37
+
38
+ **Interactive setup** (choose OAuth or integration token):
39
+ ```bash
40
+ notion auth login
41
+ ```
42
+
43
+ **Integration token only** (CI/agents — no TTY needed):
44
+ ```bash
45
+ export NOTION_API_TOKEN=ntn_your_token_here
46
+ ```
47
+
48
+ Get a token: https://www.notion.so/profile/integrations/internal
49
+
50
+ **OAuth** (recommended for write operations — attributes comments/pages to your user):
51
+ ```bash
52
+ notion auth login # select "OAuth user login" in the prompt
53
+ notion auth login --manual # headless: prints URL, paste redirect back
54
+ ```
55
+
56
+ ### 4. Share pages with your integration
57
+
58
+ Open any Notion page → `⋯` → **Add connections** → select your integration.
59
+
60
+ ### 5. Verify
61
+
62
+ ```bash
63
+ notion --version # CLI installed
64
+ notion ls # auth works
65
+ ```
66
+
67
+ Restart OpenCode after installing. The skill is now discoverable via the `skill` tool.
68
+
69
+ ## Updating
70
+
71
+ ```bash
72
+ # Homebrew
73
+ brew upgrade notion-cli
74
+
75
+ # npm
76
+ npm install -g @andrzejchm/notion-cli
77
+
78
+ # Update skill file (either install method)
79
+ curl -fsSL https://raw.githubusercontent.com/andrzejchm/notion-cli/main/docs/skills/using-notion-cli/SKILL.md \
80
+ -o ~/.config/opencode/skills/using-notion-cli/SKILL.md
81
+ ```
package/docs/demo.gif ADDED
Binary file
package/docs/demo.tape ADDED
@@ -0,0 +1,26 @@
1
+ Output demo.gif
2
+
3
+ Set FontSize 14
4
+ Set Width 800
5
+ Set Height 400
6
+ Set Theme "Dracula"
7
+ Set Padding 20
8
+ Set TypingSpeed 40ms
9
+ Env PATH "/Users/andrzejchm/.nvm/versions/node/v24.13.0/bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin"
10
+
11
+ Sleep 500ms
12
+
13
+ Type "notion search demo"
14
+ Sleep 500ms
15
+ Enter
16
+ Sleep 3s
17
+
18
+ Type "notion read 314e707e00688087b2eef0af1de30033"
19
+ Sleep 500ms
20
+ Enter
21
+ Sleep 4s
22
+
23
+ Type "notion db schema 314e707e-0068-8035-8e42-000b2f2ded85"
24
+ Sleep 500ms
25
+ Enter
26
+ Sleep 3s
Binary file
@@ -0,0 +1,176 @@
1
+ ---
2
+ name: using-notion-cli
3
+ description: Reads and writes Notion pages using the `notion` CLI tool. Use when accessing Notion content, searching workspace pages, querying database entries, reading page markdown, appending content, creating pages, or adding comments from the terminal or within automated workflows.
4
+ license: MIT
5
+ compatibility: opencode
6
+ ---
7
+
8
+ ## Setup
9
+
10
+ Install once:
11
+ ```bash
12
+ npm install -g @andrzejchm/notion-cli
13
+ notion auth login # interactive setup — choose OAuth or integration token
14
+ ```
15
+
16
+ Or set env var (preferred for CI/agents):
17
+ ```bash
18
+ export NOTION_API_TOKEN=ntn_your_token_here
19
+ ```
20
+
21
+ Get token: https://www.notion.so/profile/integrations/internal
22
+
23
+ Pages must be shared with your integration: open page → `⋯` → **Add connections**.
24
+
25
+ **Integration capabilities** (set at notion.so/profile/integrations/internal → your integration → Capabilities):
26
+ - Read-only commands: **Read content** only
27
+ - `notion append`, `notion create-page`: also need **Insert content**
28
+ - `notion comment`: also need **Read comments** + **Insert comments**
29
+
30
+ ---
31
+
32
+ ## Authentication
33
+
34
+ Two auth methods are available. If both are configured, **OAuth takes precedence**.
35
+
36
+ | Method | Command | Attribution | Notes |
37
+ |--------|---------|-------------|-------|
38
+ | Interactive setup | `notion auth login` | — | Guides you to choose; TTY required |
39
+ | OAuth user login | select "OAuth user login" in `notion auth login` | Your Notion account | Browser required; `--manual` for headless |
40
+ | Integration token | select "Integration token" in `notion auth login` | Integration bot | Works in CI/headless; must connect integration to pages |
41
+
42
+ ```bash
43
+ notion auth login # interactive selector — OAuth or integration token
44
+ notion auth login --manual # headless OAuth (prints URL, paste redirect back)
45
+ notion auth status # show current auth state
46
+ notion auth logout # remove a profile (interactive selector)
47
+ notion auth logout --profile <name> # remove specific profile directly
48
+ notion auth list # list all saved profiles
49
+ notion auth use <name> # switch active profile
50
+ ```
51
+
52
+ **Headless/CI agents:** Use `NOTION_API_TOKEN=<token>` env var — overrides all config, no TTY needed.
53
+
54
+ ---
55
+
56
+ ## Output Modes
57
+
58
+ | Context | Default | Override |
59
+ |---------|---------|----------|
60
+ | Terminal (TTY) | Formatted tables | `--json` |
61
+ | Piped / agent | Plain text tables | `--json` |
62
+
63
+ `notion read` always outputs **markdown** — in terminal and when piped.
64
+
65
+ Pipe any command to get JSON:
66
+ ```bash
67
+ notion search "query" | jq '.[0].id'
68
+ notion ls | jq '.[] | select(.type == "database")'
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Commands
74
+
75
+ ### Search & Discovery
76
+
77
+ ```bash
78
+ notion search "query" # search all pages/databases by title
79
+ notion search "query" --type page # pages only
80
+ notion search "query" --type database # databases only
81
+ notion ls # list everything accessible to integration
82
+ notion users # list workspace members
83
+ notion comments <id|url> # list page comments
84
+ notion open <id|url> # open in browser
85
+ ```
86
+
87
+ ### Reading Pages
88
+
89
+ ```bash
90
+ notion read <id|url> # markdown (always, even when piped)
91
+ notion read <id|url> --json # raw Notion JSON block tree
92
+ ```
93
+
94
+ ### Database Operations
95
+
96
+ ```bash
97
+ notion db schema <id|url> # inspect properties + valid values
98
+ notion db query <id|url> # all rows
99
+ notion db query <id|url> --filter "Status=Done" # filter (repeatable)
100
+ notion db query <id|url> --sort "Created:desc" # sort (repeatable)
101
+ notion db query <id|url> --columns "Title,Status" # limit columns
102
+ notion db query <id|url> --json | jq '.[] | .properties'
103
+ ```
104
+
105
+ ### Write Operations
106
+
107
+ ```bash
108
+ notion append <id|url> -m "## Heading\nParagraph text" # append markdown blocks to a page
109
+ notion append <id|url> -m "$(cat notes.md)" # append file contents
110
+
111
+ notion create-page --parent <id|url> --title "Title" # title-only page
112
+ notion create-page --parent <id|url> --title "Title" -m "# Hello" # with markdown body
113
+ echo "# Content" | notion create-page --parent <id|url> --title "Title" # from stdin
114
+ URL=$(notion create-page --parent <id|url> --title "Summary" -m "...") # capture URL
115
+
116
+ notion comment <id|url> -m "Reviewed and approved." # add comment to a page
117
+ ```
118
+
119
+ ---
120
+
121
+ ## ID Formats
122
+
123
+ All commands accept any of:
124
+ - `abc123def456789012345678901234ab` (32-char hex)
125
+ - `abc123de-f456-7890-1234-5678901234ab` (UUID)
126
+ - `https://www.notion.so/workspace/Page-Title-abc123` (full URL)
127
+
128
+ ---
129
+
130
+ ## Agent Patterns
131
+
132
+ ```bash
133
+ # Find page by title, read it
134
+ PAGE_ID=$(notion search "Meeting Notes" --type page | jq -r '.[0].id')
135
+ notion read "$PAGE_ID"
136
+
137
+ # Get database ID, then query with filter
138
+ DB_ID=$(notion search "Project Tracker" --type database | jq -r '.[0].id')
139
+ notion db query "$DB_ID" --filter "Status=In Progress" | jq '.[] | .properties'
140
+
141
+ # Always check schema before filtering (see valid property names/values)
142
+ notion db schema "$DB_ID"
143
+ notion db query "$DB_ID" --filter "Status=Done"
144
+
145
+ # Extract page section
146
+ notion read "$PAGE_ID" | grep -A 10 "## Action Items"
147
+
148
+ # Summarize a page and append the summary back
149
+ SUMMARY=$(notion read "$PAGE_ID" | your-summarize-command)
150
+ notion append "$PAGE_ID" -m "## AI Summary\n$SUMMARY"
151
+
152
+ # Create a page and capture its URL for further use
153
+ URL=$(notion create-page --parent "$PAGE_ID" --title "Report $(date +%Y-%m-%d)" -m "# Report\n...")
154
+ echo "Created: $URL"
155
+
156
+ # Pipe command output into a new page
157
+ my-report-command | notion create-page --parent "$PAGE_ID" --title "Auto Report"
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Troubleshooting
163
+
164
+ **404 / page not found** — Share the page with your integration: page → `⋯` → **Add connections**.
165
+
166
+ **401 / unauthorized** — Run `notion auth login` or set `NOTION_API_TOKEN`.
167
+
168
+ **Search returns nothing** — Search is title-only. Page must be shared with integration.
169
+
170
+ **Empty db query** — Run `notion db schema <id>` to see valid property names and values.
171
+
172
+ **`notion auth login` requires TTY** — Use `NOTION_API_TOKEN` env var in agents, or use `notion auth login --manual` for headless OAuth.
173
+
174
+ **`notion comment` returns "Insufficient permissions"** — Enable **Read comments** + **Insert comments** in integration capabilities: notion.so/profile/integrations/internal → your integration → Capabilities.
175
+
176
+ **`notion append` / `notion create-page` returns "Insufficient permissions"** — Enable **Insert content** in integration capabilities.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrzejchm/notion-cli",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "Read Notion pages and databases from the terminal. Built for AI agents and developers.",
5
5
  "keywords": [
6
6
  "notion",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "files": [
27
27
  "dist/",
28
- "docs/agent-skill.md",
28
+ "docs/",
29
29
  "README.md"
30
30
  ],
31
31
  "type": "module",
@@ -36,7 +36,14 @@
36
36
  "build": "tsup",
37
37
  "dev": "tsup --watch",
38
38
  "test": "vitest run",
39
- "test:watch": "vitest"
39
+ "test:watch": "vitest",
40
+ "typecheck": "tsc --noEmit",
41
+ "lint": "biome lint .",
42
+ "format": "biome format .",
43
+ "format:write": "biome format --write .",
44
+ "check": "biome check .",
45
+ "check:write": "biome check --write .",
46
+ "ci": "npm run typecheck && npm run check"
40
47
  },
41
48
  "dependencies": {
42
49
  "@inquirer/prompts": "^8.3.0",
@@ -46,6 +53,7 @@
46
53
  "yaml": "^2.8.0"
47
54
  },
48
55
  "devDependencies": {
56
+ "@biomejs/biome": "^2.4.4",
49
57
  "@commander-js/extra-typings": "^14.0.0",
50
58
  "@types/node": "^22",
51
59
  "tsup": "^8.5.0",