onenote-cli 0.2.0 → 0.2.1-darwin-arm64
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/bin/onenote-cli +0 -0
- package/package.json +12 -44
- package/.env.example +0 -10
- package/.github/workflows/release.yml +0 -43
- package/.husky/pre-commit +0 -1
- package/.releaserc.json +0 -13
- package/.secretlintrc.json +0 -3
- package/CLAUDE.md +0 -42
- package/README.md +0 -254
- package/SKILL.md +0 -77
- package/bun.lock +0 -1427
- package/docs/azure-app-registration.md +0 -80
- package/docs/development-notes.md +0 -84
- package/docs/graph-api-endpoints.md +0 -131
- package/docs/local-search-architecture.md +0 -132
- package/docs/onen0te-cli-analysis.md +0 -130
- package/docs/setup.md +0 -141
- package/docs/zhihu-intro.md +0 -92
- package/src/auth.ts +0 -359
- package/src/cache.ts +0 -1709
- package/src/debug-tags.ts +0 -207
- package/src/export.ts +0 -367
- package/src/graph.ts +0 -1480
- package/src/index.ts +0 -1176
- package/src/markdown.ts +0 -134
- package/src/read-render.ts +0 -621
- package/src/sync-ui.tsx +0 -220
- package/tsconfig.json +0 -16
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Azure AD App Registration for OneNote CLI
|
|
2
|
-
|
|
3
|
-
This document describes how to register an Azure AD application for use with `onenote-cli`, which uses the Microsoft Graph OneNote API with delegated (device code flow) authentication.
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
- A Microsoft account (personal or organizational)
|
|
8
|
-
- Access to [Microsoft Entra admin center](https://entra.microsoft.com)
|
|
9
|
-
|
|
10
|
-
## Step 1: Create the App Registration
|
|
11
|
-
|
|
12
|
-
1. Go to [Microsoft Entra admin center](https://entra.microsoft.com)
|
|
13
|
-
2. Navigate to **Entra ID** > **App registrations** > **New registration**
|
|
14
|
-
3. Fill in:
|
|
15
|
-
- **Name**: `onenote-cli`
|
|
16
|
-
- **Supported account types**: "Accounts in any organizational directory and personal Microsoft accounts"
|
|
17
|
-
- **Redirect URI**: Leave blank (configured in the next step)
|
|
18
|
-
4. Click **Register**
|
|
19
|
-
5. Copy the **Application (client) ID** from the Overview page
|
|
20
|
-
|
|
21
|
-
## Step 2: Configure Authentication Platform
|
|
22
|
-
|
|
23
|
-
1. Go to **Authentication** tab in your app registration
|
|
24
|
-
2. Click **Add a platform** > **Mobile and desktop applications**
|
|
25
|
-
3. Check these redirect URIs:
|
|
26
|
-
- `https://login.microsoftonline.com/common/oauth2/nativeclient`
|
|
27
|
-
- `msal{client-id}://auth` (MSAL-specific URI)
|
|
28
|
-
4. Click **Configure**
|
|
29
|
-
|
|
30
|
-
## Step 3: Enable Public Client Flows
|
|
31
|
-
|
|
32
|
-
1. In the **Authentication** tab, go to the **Settings** sub-tab
|
|
33
|
-
2. Find **Allow public client flows** and set it to **Enabled**
|
|
34
|
-
3. Click **Save**
|
|
35
|
-
|
|
36
|
-
This is required for device code flow authentication. Without it, you will get error `AADSTS7000218`.
|
|
37
|
-
|
|
38
|
-
## Step 4: Add API Permissions
|
|
39
|
-
|
|
40
|
-
1. Go to **API permissions** > **Add a permission**
|
|
41
|
-
2. Select **Microsoft Graph** > **Delegated permissions**
|
|
42
|
-
3. Search for "Notes" and expand the **Notes** group
|
|
43
|
-
4. Select:
|
|
44
|
-
- `Notes.Read` — Read user OneNote notebooks
|
|
45
|
-
- `Notes.ReadWrite` — Read and write user OneNote notebooks
|
|
46
|
-
- `Notes.ReadWrite.All` — Read and write all notebooks the user can access
|
|
47
|
-
5. Click **Add permissions**
|
|
48
|
-
|
|
49
|
-
The default `User.Read` permission is already included.
|
|
50
|
-
|
|
51
|
-
## Step 5: Configure the CLI
|
|
52
|
-
|
|
53
|
-
Set the client ID via environment variable or config file:
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
# Option A: .env.local
|
|
57
|
-
ONENOTE_CLIENT_ID=your-client-id-here
|
|
58
|
-
ONENOTE_AUTHORITY=https://login.microsoftonline.com/common
|
|
59
|
-
|
|
60
|
-
# Option B: ~/.onenote-cli/config.json
|
|
61
|
-
{
|
|
62
|
-
"clientId": "your-client-id-here",
|
|
63
|
-
"authority": "https://login.microsoftonline.com/common"
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Environment variables take priority over the config file.
|
|
68
|
-
|
|
69
|
-
## Step 6: Login and Verify
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
bun run src/index.ts login
|
|
73
|
-
bun run src/index.ts notebooks list
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Notes
|
|
77
|
-
|
|
78
|
-
- The Microsoft Graph OneNote API **does not support app-only authentication** as of March 2025. Only delegated (user) authentication is supported.
|
|
79
|
-
- The authority URL `https://login.microsoftonline.com/common` supports both organizational and personal Microsoft accounts.
|
|
80
|
-
- Tokens are cached at `~/.onenote-cli/msal-cache.json` and automatically refreshed.
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# Development Notes
|
|
2
|
-
|
|
3
|
-
Lessons learned and implementation notes from building `onenote-cli`.
|
|
4
|
-
|
|
5
|
-
## Architecture Decisions
|
|
6
|
-
|
|
7
|
-
### Bun + Yargs
|
|
8
|
-
|
|
9
|
-
- Bun is used as the runtime, allowing direct execution of TypeScript without a build step
|
|
10
|
-
- Yargs provides a natural command/subcommand CLI structure
|
|
11
|
-
- The `bin` field in package.json points directly to `src/index.ts` — no compilation needed
|
|
12
|
-
|
|
13
|
-
### MSAL Node for Authentication
|
|
14
|
-
|
|
15
|
-
- `@azure/msal-node` provides the `PublicClientApplication` class for device code flow
|
|
16
|
-
- Token caching is implemented via MSAL's `cachePlugin` interface, persisting to `~/.onenote-cli/msal-cache.json`
|
|
17
|
-
- Silent token acquisition is attempted first (using cached refresh tokens), falling back to device code flow
|
|
18
|
-
|
|
19
|
-
### Configuration Priority
|
|
20
|
-
|
|
21
|
-
Configuration is resolved in this order:
|
|
22
|
-
1. Environment variables (`ONENOTE_CLIENT_ID`, `ONENOTE_AUTHORITY`)
|
|
23
|
-
2. Config file (`~/.onenote-cli/config.json`)
|
|
24
|
-
3. Default values (which prompt the user to configure)
|
|
25
|
-
|
|
26
|
-
This allows both `.env.local` for development and the config file for installed usage.
|
|
27
|
-
|
|
28
|
-
## Implementation Details
|
|
29
|
-
|
|
30
|
-
### Device Code Flow
|
|
31
|
-
|
|
32
|
-
The device code flow is ideal for CLI applications because:
|
|
33
|
-
- No web server or redirect handler is needed
|
|
34
|
-
- Works in headless/SSH environments
|
|
35
|
-
- User authenticates in any browser, even on a different device
|
|
36
|
-
|
|
37
|
-
Flow:
|
|
38
|
-
1. CLI requests a device code from Azure AD
|
|
39
|
-
2. Azure AD returns a code and a URL
|
|
40
|
-
3. User opens the URL in a browser and enters the code
|
|
41
|
-
4. User authenticates and consents to permissions
|
|
42
|
-
5. CLI polls Azure AD and receives tokens once authentication completes
|
|
43
|
-
|
|
44
|
-
### Page Creation
|
|
45
|
-
|
|
46
|
-
OneNote pages are created by POSTing raw HTML (Content-Type: `text/html`), not JSON. The HTML must include a `<title>` in the `<head>` and content in the `<body>`. This is different from most Graph API endpoints which use JSON.
|
|
47
|
-
|
|
48
|
-
### App-Only Auth Not Supported
|
|
49
|
-
|
|
50
|
-
As of March 2025, Microsoft Graph OneNote API no longer supports app-only (client credentials) authentication. All access must use delegated permissions with a signed-in user. This means the CLI must always go through the device code flow for initial authentication.
|
|
51
|
-
|
|
52
|
-
## Azure Portal Navigation Tips
|
|
53
|
-
|
|
54
|
-
### Entra Admin Center vs Azure Portal
|
|
55
|
-
|
|
56
|
-
- App registrations are managed in the [Microsoft Entra admin center](https://entra.microsoft.com), not the classic Azure portal
|
|
57
|
-
- The path is: **Entra ID** > **App registrations**
|
|
58
|
-
- Direct URL: `https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade`
|
|
59
|
-
|
|
60
|
-
### Common Setup Mistakes
|
|
61
|
-
|
|
62
|
-
1. **Forgetting to enable public client flows** — Device code flow requires "Allow public client flows" to be set to Yes in Authentication > Settings. Without this, authentication fails with `AADSTS7000218`.
|
|
63
|
-
|
|
64
|
-
2. **Wrong account type selection** — For a CLI that should work with both personal and work accounts, select "Accounts in any organizational directory and personal Microsoft accounts".
|
|
65
|
-
|
|
66
|
-
3. **Missing redirect URI** — While device code flow doesn't strictly require a redirect URI, adding `https://login.microsoftonline.com/common/oauth2/nativeclient` ensures compatibility with the MSAL library.
|
|
67
|
-
|
|
68
|
-
4. **Not adding API permissions** — The default `User.Read` permission is not enough. You must explicitly add `Notes.Read` / `Notes.ReadWrite` delegated permissions under Microsoft Graph.
|
|
69
|
-
|
|
70
|
-
## Troubleshooting
|
|
71
|
-
|
|
72
|
-
### Token Refresh Failures
|
|
73
|
-
|
|
74
|
-
If silent token acquisition fails after a long period, the refresh token may have expired. Run `onenote login` again to re-authenticate.
|
|
75
|
-
|
|
76
|
-
### Graph API 403 Errors
|
|
77
|
-
|
|
78
|
-
Usually means the required permission was not consented. Check that:
|
|
79
|
-
- The permission is added in the app registration
|
|
80
|
-
- The user consented during login (or admin consent was granted)
|
|
81
|
-
|
|
82
|
-
### Graph API 404 Errors
|
|
83
|
-
|
|
84
|
-
OneNote resources use opaque IDs. If a notebook/section/page was deleted or moved, its ID becomes invalid.
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# Microsoft Graph OneNote API Endpoints
|
|
2
|
-
|
|
3
|
-
Reference for the OneNote REST API endpoints used by `onenote-cli`.
|
|
4
|
-
|
|
5
|
-
## Base URL
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
https://graph.microsoft.com/v1.0/me/onenote/
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Notebooks
|
|
12
|
-
|
|
13
|
-
| Method | Endpoint | Description |
|
|
14
|
-
|--------|----------|-------------|
|
|
15
|
-
| GET | `/me/onenote/notebooks` | List all notebooks |
|
|
16
|
-
| GET | `/me/onenote/notebooks/{id}` | Get a notebook by ID |
|
|
17
|
-
| POST | `/me/onenote/notebooks` | Create a notebook (`{ "displayName": "..." }`) |
|
|
18
|
-
|
|
19
|
-
## Sections
|
|
20
|
-
|
|
21
|
-
| Method | Endpoint | Description |
|
|
22
|
-
|--------|----------|-------------|
|
|
23
|
-
| GET | `/me/onenote/sections` | List all sections |
|
|
24
|
-
| GET | `/me/onenote/notebooks/{id}/sections` | List sections in a notebook |
|
|
25
|
-
| GET | `/me/onenote/sections/{id}` | Get a section by ID |
|
|
26
|
-
| POST | `/me/onenote/notebooks/{id}/sections` | Create a section (`{ "displayName": "..." }`) |
|
|
27
|
-
|
|
28
|
-
`onenote-cli` also resolves SharePoint notebook URLs to the site-scoped equivalent:
|
|
29
|
-
|
|
30
|
-
```http
|
|
31
|
-
GET /sites/{site-id}/onenote/notebooks/{id}/sections
|
|
32
|
-
POST /sites/{site-id}/onenote/notebooks/{id}/sections
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Section Groups
|
|
36
|
-
|
|
37
|
-
| Method | Endpoint | Description |
|
|
38
|
-
|--------|----------|-------------|
|
|
39
|
-
| GET | `/me/onenote/sectionGroups` | List all section groups |
|
|
40
|
-
| GET | `/me/onenote/notebooks/{id}/sectionGroups` | List section groups in a notebook |
|
|
41
|
-
|
|
42
|
-
## Pages
|
|
43
|
-
|
|
44
|
-
| Method | Endpoint | Description |
|
|
45
|
-
|--------|----------|-------------|
|
|
46
|
-
| GET | `/me/onenote/pages` | List all pages |
|
|
47
|
-
| GET | `/me/onenote/sections/{id}/pages` | List pages in a section |
|
|
48
|
-
| GET | `/me/onenote/pages/{id}` | Get page metadata |
|
|
49
|
-
| GET | `/me/onenote/pages/{id}/content` | Get page HTML content |
|
|
50
|
-
| POST | `/me/onenote/sections/{id}/pages` | Create a page (Content-Type: text/html) |
|
|
51
|
-
| PATCH | `/me/onenote/pages/{id}/content` | Update page content with OneNote PATCH commands |
|
|
52
|
-
| DELETE | `/me/onenote/pages/{id}` | Delete a page |
|
|
53
|
-
|
|
54
|
-
For SharePoint page or section URLs, the CLI resolves the corresponding site-scoped endpoints automatically:
|
|
55
|
-
|
|
56
|
-
```http
|
|
57
|
-
GET /sites/{site-id}/onenote/sections/{id}/pages
|
|
58
|
-
GET /sites/{site-id}/onenote/pages/{id}
|
|
59
|
-
GET /sites/{site-id}/onenote/pages/{id}/content
|
|
60
|
-
POST /sites/{site-id}/onenote/sections/{id}/pages
|
|
61
|
-
PATCH /sites/{site-id}/onenote/pages/{id}/content
|
|
62
|
-
DELETE /sites/{site-id}/onenote/pages/{id}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Search
|
|
66
|
-
|
|
67
|
-
| Method | Endpoint | Description |
|
|
68
|
-
|--------|----------|-------------|
|
|
69
|
-
| GET | `/me/onenote/pages?$search={query}` | Search pages by content |
|
|
70
|
-
|
|
71
|
-
## Creating Pages
|
|
72
|
-
|
|
73
|
-
Pages are created by POSTing HTML to a section:
|
|
74
|
-
|
|
75
|
-
```http
|
|
76
|
-
POST /me/onenote/sections/{section-id}/pages
|
|
77
|
-
Content-Type: text/html
|
|
78
|
-
|
|
79
|
-
<!DOCTYPE html>
|
|
80
|
-
<html>
|
|
81
|
-
<head>
|
|
82
|
-
<title>Page Title</title>
|
|
83
|
-
</head>
|
|
84
|
-
<body>
|
|
85
|
-
<p>Page content here</p>
|
|
86
|
-
</body>
|
|
87
|
-
</html>
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Updating Pages
|
|
91
|
-
|
|
92
|
-
Page updates are sent as JSON PATCH commands to `/pages/{id}/content`:
|
|
93
|
-
|
|
94
|
-
```http
|
|
95
|
-
PATCH /me/onenote/pages/{page-id}/content
|
|
96
|
-
Content-Type: application/json
|
|
97
|
-
|
|
98
|
-
[
|
|
99
|
-
{
|
|
100
|
-
"target": "#element-id",
|
|
101
|
-
"action": "replace",
|
|
102
|
-
"content": "<p>Updated content</p>"
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Required Permissions (Delegated)
|
|
108
|
-
|
|
109
|
-
| Permission | Description |
|
|
110
|
-
|------------|-------------|
|
|
111
|
-
| `Notes.Read` | Read notebooks |
|
|
112
|
-
| `Notes.ReadWrite` | Read and write notebooks |
|
|
113
|
-
| `Notes.Read.All` | Read all accessible notebooks |
|
|
114
|
-
| `Notes.ReadWrite.All` | Read and write all accessible notebooks |
|
|
115
|
-
|
|
116
|
-
## Additional Scopes
|
|
117
|
-
|
|
118
|
-
Notebooks can also be accessed via group or SharePoint site contexts:
|
|
119
|
-
|
|
120
|
-
```
|
|
121
|
-
/groups/{id}/onenote/{notebooks|sections|pages}
|
|
122
|
-
/sites/{id}/onenote/{notebooks|sections|pages}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
These require corresponding group/site read permissions.
|
|
126
|
-
|
|
127
|
-
## References
|
|
128
|
-
|
|
129
|
-
- [OneNote API overview](https://learn.microsoft.com/en-us/graph/integrate-with-onenote)
|
|
130
|
-
- [OneNote REST API reference](https://learn.microsoft.com/en-us/graph/api/resources/onenote-api-overview)
|
|
131
|
-
- [Graph Explorer](https://developer.microsoft.com/graph/graph-explorer)
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
# Local Page-Level Search Architecture
|
|
2
|
-
|
|
3
|
-
## Problem
|
|
4
|
-
|
|
5
|
-
The Microsoft Graph OneNote API has a hard limit: when a OneDrive for Business document library contains more than 5,000 OneNote items, the API returns error 10008 and blocks all section/page listing endpoints. This affects accounts with many notebooks.
|
|
6
|
-
|
|
7
|
-
The Graph Search API (`/search/query`) only returns section-level (.one file) results — it cannot identify individual pages within a section.
|
|
8
|
-
|
|
9
|
-
## Solution: Local Cache + Binary Text Extraction
|
|
10
|
-
|
|
11
|
-
### How it works
|
|
12
|
-
|
|
13
|
-
1. **Sync** (`onenote sync`): Downloads all `.one` section files from OneDrive to a local cache directory (`.onenote/cache/`)
|
|
14
|
-
2. **Extract**: Parses the MS-ONESTORE binary format to extract readable text blocks, then segments them into pages based on binary gaps
|
|
15
|
-
3. **Search** (`onenote search <query>`): Searches the local cache for matching text at the page level
|
|
16
|
-
|
|
17
|
-
### Cache Structure
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
.onenote/
|
|
21
|
-
cache/
|
|
22
|
-
{Notebook Name}/
|
|
23
|
-
{Section Name}.json # Extracted pages with text
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Each `.json` file contains:
|
|
27
|
-
```json
|
|
28
|
-
{
|
|
29
|
-
"section": "Section Name",
|
|
30
|
-
"notebook": "Notebook Name",
|
|
31
|
-
"webUrl": "https://...Doc.aspx?sourcedoc={GUID}&...",
|
|
32
|
-
"pages": [
|
|
33
|
-
{ "title": "Page Title", "body": "Full text content..." },
|
|
34
|
-
...
|
|
35
|
-
],
|
|
36
|
-
"cachedAt": "2025-01-01T00:00:00.000Z"
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Binary-Based Position Search
|
|
41
|
-
|
|
42
|
-
For accurate page attribution, the cache stores the original `.one` binary alongside extracted metadata. Search works by:
|
|
43
|
-
|
|
44
|
-
1. Searching the binary directly for the query string (both UTF-8 and UTF-16LE encodings)
|
|
45
|
-
2. For each match position, finding the nearest preceding page GUID anchor
|
|
46
|
-
3. Returning that page as the result
|
|
47
|
-
|
|
48
|
-
This bypasses the imperfect text-block-to-page heuristics and gives accurate page attribution because the binary positions are ground truth — the matched text is physically located near the page anchor it belongs to.
|
|
49
|
-
|
|
50
|
-
### .one Binary Text Extraction
|
|
51
|
-
|
|
52
|
-
The MS-ONESTORE format (`.one` files) stores text as UTF-8 and UTF-16LE encoded strings interspersed with binary data. The extraction algorithm:
|
|
53
|
-
|
|
54
|
-
1. Read the file twice — once as UTF-8 (ASCII content) and once as UTF-16LE (CJK and other Unicode)
|
|
55
|
-
2. Find contiguous runs of printable characters
|
|
56
|
-
3. Filter runs that don't contain enough "common" characters (ratio threshold)
|
|
57
|
-
4. Use the page GUID anchors (see below) to assign each text block to the correct page
|
|
58
|
-
|
|
59
|
-
### Page GUID Extraction
|
|
60
|
-
|
|
61
|
-
Page-level URLs require knowing each page's UUID. We extract these from the binary using a pattern observed in MS-ONESTORE files:
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
[UTF-16LE title text] 00 00 [10 00 00 00] [16-byte page GUID]
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
The `10 00 00 00` is a uint32-LE size marker meaning "16 bytes follow", and the next 16 bytes are a UUIDv4 (version=4, variant=8-B). The text immediately preceding (UTF-16LE encoded) is the page title.
|
|
68
|
-
|
|
69
|
-
For each page GUID found, all text blocks at later offsets up to the next anchor are assigned to that page. This anchor-based grouping correctly maps content (including text in non-Latin scripts) to the right page even when the file structure is fragmented.
|
|
70
|
-
|
|
71
|
-
### Page-Level URL Format
|
|
72
|
-
|
|
73
|
-
OneNote Online supports deep linking to specific pages via:
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
{sectionUrl}&wd=target({pageTitle}|{pageGuid}/)
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Where:
|
|
80
|
-
- `{sectionUrl}` is the SharePoint Doc.aspx URL with the section's `sourcedoc` GUID
|
|
81
|
-
- `{pageTitle}` is the page title with `)` and `|` characters escaped as `\)` and `\|`
|
|
82
|
-
- `{pageGuid}` is the page's UUIDv4
|
|
83
|
-
- Trailing `/` is required
|
|
84
|
-
|
|
85
|
-
The full `wd=` parameter is then URL-encoded with strict encoding (parens encoded as `%28`/`%29`).
|
|
86
|
-
|
|
87
|
-
### Search Output
|
|
88
|
-
|
|
89
|
-
Each result shows:
|
|
90
|
-
- **Page title** — extracted from the page anchor
|
|
91
|
-
- **Section and notebook** — which section/notebook contains the match
|
|
92
|
-
- **Context snippet** — text surrounding the match with keyword highlighted in `**bold**`
|
|
93
|
-
- **URL** — page-level OneNote Online deep link
|
|
94
|
-
|
|
95
|
-
### Page-Level URL Resolution (Official URLs)
|
|
96
|
-
|
|
97
|
-
We use the OneNote Graph API endpoint `GET /me/onenote/sections/0-{guid}/pages` to fetch the official `links.oneNoteWebUrl.href` for each page. This endpoint works even when the 5,000-item document library limit blocks `/me/onenote/pages` and `/me/onenote/sections` listing — because the `0-{guid}` ID prefix targets the section directly via its sourcedoc GUID (extracted from the OneDrive driveItem webUrl).
|
|
98
|
-
|
|
99
|
-
Official OneNote URLs use the format:
|
|
100
|
-
```
|
|
101
|
-
{driveRootPath}/{notebook}?wd=target({sectionFile}|{sectionGroupGuid}/{pageTitle}|{pageGuid}/)
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Unlike the simpler `Doc.aspx?sourcedoc=...&wd=target(...)` format, this URL **bypasses OneNote Online's session caching** and navigates directly to the specified page on first load. Verified working via browser automation testing.
|
|
105
|
-
|
|
106
|
-
The page navigation GUID (used in `wd=target`) is extracted from the `oneNoteWebUrl` URL itself (the last UUID in the URL), since the API's page `id` field uses a different identifier format (`1-{32hexchars}!{counter}-{sectionGuid}`) that doesn't match the navigation GUID.
|
|
107
|
-
|
|
108
|
-
### Limitations
|
|
109
|
-
|
|
110
|
-
- **Page coverage**: Our binary parser detects ~50% of pages in some sections (those whose GUID-title binary pattern matches our heuristic). The other pages exist in the cache but without a precise GUID, so search results for them fall back to section-level URLs.
|
|
111
|
-
- **Cache freshness**: Cache is valid for 1 hour by default. Run `onenote sync` to refresh.
|
|
112
|
-
- **Binary parsing heuristic**: The UTF-8 text extraction may miss some content or include some binary noise. Page boundary detection is approximate.
|
|
113
|
-
- **Large sections**: Sections with thousands of pages (e.g., 5000+ extracted "pages") may have over-segmented results due to the binary gap heuristic.
|
|
114
|
-
|
|
115
|
-
### Alternative Approaches Investigated
|
|
116
|
-
|
|
117
|
-
| Approach | Result |
|
|
118
|
-
|---|---|
|
|
119
|
-
| OneNote API `/me/onenote/pages` | Blocked by 5000 item limit (error 10008) |
|
|
120
|
-
| Graph Search API `driveItem` | Section-level only, no page granularity |
|
|
121
|
-
| Graph Search API `listItem` | Section-level only (pages not individually indexed) |
|
|
122
|
-
| OneDrive HTML conversion (`?format=html`) | Not supported for .one files (406) |
|
|
123
|
-
| SharePoint REST search | Requires separate OAuth scope, returns section-level |
|
|
124
|
-
| Site-specific OneNote API | Same 5000 limit applies |
|
|
125
|
-
| Beta Graph API endpoints | Same limitations |
|
|
126
|
-
|
|
127
|
-
### Future Improvements
|
|
128
|
-
|
|
129
|
-
- Implement proper MS-ONESTORE parser for accurate page extraction with page GUIDs
|
|
130
|
-
- Use page GUIDs to construct page-level deep links: `Doc.aspx?sourcedoc={guid}&wd=target(section|/pageTitle)`
|
|
131
|
-
- Incremental sync (only download changed sections based on `lastModifiedDateTime`)
|
|
132
|
-
- SQLite or full-text search index for faster queries on large caches
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
# onen0te-cli UX Analysis
|
|
2
|
-
|
|
3
|
-
Analysis of [fatihdumanli/onen0te-cli](https://github.com/fatihdumanli/onen0te-cli) — a Go-based OneNote CLI tool. Key takeaways for informing our `onenote-cli` design.
|
|
4
|
-
|
|
5
|
-
## Command Structure
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
nnote new [-i "text" | -f file] [-a alias] [-t title] Create a note
|
|
9
|
-
nnote browse Interactive notebook/section/page navigation
|
|
10
|
-
nnote search <phrase> Search across all notebooks
|
|
11
|
-
nnote alias new [name] Create a section alias
|
|
12
|
-
nnote alias list List all aliases
|
|
13
|
-
nnote alias remove <name> Delete an alias
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Auth Flow
|
|
17
|
-
|
|
18
|
-
- Uses **OAuth 2.0 Authorization Code Flow** (not device code)
|
|
19
|
-
- Starts a local HTTP server on `localhost:5992` for the redirect callback
|
|
20
|
-
- Opens system browser for login
|
|
21
|
-
- Tokens stored in Bitcask DB at `/tmp/nnote`
|
|
22
|
-
- Auto-refreshes expired tokens silently before each API call
|
|
23
|
-
- On first run, prompts: "You haven't setup a Onenote account yet, would you like to setup one now?"
|
|
24
|
-
|
|
25
|
-
Comparison with our approach:
|
|
26
|
-
- We use **device code flow** which works better in SSH/headless environments
|
|
27
|
-
- They use browser redirect which is more seamless on desktop
|
|
28
|
-
- Both auto-refresh tokens
|
|
29
|
-
|
|
30
|
-
## Key UX Patterns Worth Adopting
|
|
31
|
-
|
|
32
|
-
### 1. Interactive Selection Prompts
|
|
33
|
-
|
|
34
|
-
When creating a note without an alias, the user is prompted to select a notebook, then a section via interactive dropdown (uses `survey` library). This is much better than requiring users to copy-paste IDs.
|
|
35
|
-
|
|
36
|
-
### 2. Alias System
|
|
37
|
-
|
|
38
|
-
Maps a short name to a notebook+section pair. Avoids repeated interactive selection for frequently-used sections. Example:
|
|
39
|
-
```
|
|
40
|
-
nnote new -a work -i "Meeting notes"
|
|
41
|
-
```
|
|
42
|
-
After saving, if no alias exists for the section, suggests creating one.
|
|
43
|
-
|
|
44
|
-
### 3. Browse Mode (Interactive Navigation Loop)
|
|
45
|
-
|
|
46
|
-
`nnote browse` creates an interactive loop:
|
|
47
|
-
1. Select notebook
|
|
48
|
-
2. Select section
|
|
49
|
-
3. Select page
|
|
50
|
-
4. View content (HTML rendered to text)
|
|
51
|
-
5. Menu: back to sections / notebooks / open in browser / open in OneNote client / exit
|
|
52
|
-
|
|
53
|
-
Uses emoji indicators in menus for visual scanning.
|
|
54
|
-
|
|
55
|
-
### 4. Multiple Note Input Methods
|
|
56
|
-
|
|
57
|
-
- `-i "text"` — Inline text
|
|
58
|
-
- `-f /path/to/file` — Import from file
|
|
59
|
-
- No flags — Opens `$EDITOR` for composing
|
|
60
|
-
|
|
61
|
-
### 5. Spinner Animations
|
|
62
|
-
|
|
63
|
-
Shows spinners during API calls (GetNotebooks, GetSections, SaveNote, etc.) with success/fail status on completion.
|
|
64
|
-
|
|
65
|
-
### 6. Styled Output
|
|
66
|
-
|
|
67
|
-
- Color-coded messages: green=success, red=error, yellow=warning
|
|
68
|
-
- Table rendering for structured data (aliases, notebooks)
|
|
69
|
-
- Breadcrumb display with metadata when viewing pages
|
|
70
|
-
|
|
71
|
-
## Architecture Decisions
|
|
72
|
-
|
|
73
|
-
### Storage
|
|
74
|
-
|
|
75
|
-
- Uses **Bitcask** (embedded key-value store) at `/tmp/nnote`
|
|
76
|
-
- Stores both OAuth tokens and aliases in the same DB
|
|
77
|
-
- No config files — minimal setup burden
|
|
78
|
-
- Concern: `/tmp` is volatile on some systems; better to use `~/.config/` or `~/.local/`
|
|
79
|
-
|
|
80
|
-
### API Layer
|
|
81
|
-
|
|
82
|
-
- Custom REST client wrapper over `net/http`
|
|
83
|
-
- Endpoints used:
|
|
84
|
-
- `GET /me/onenote/notebooks` — list notebooks
|
|
85
|
-
- `GET /me/onenote/notebooks/{id}/sections` — list sections
|
|
86
|
-
- `GET /me/onenote/sections/{id}/pages` — list pages
|
|
87
|
-
- `GET /me/onenote/pages/{id}/content` — get page HTML
|
|
88
|
-
- `POST /me/onenote/sections/{id}/pages` — create page
|
|
89
|
-
- `GET /me/onenote/pages?search=...` — search (undocumented/deprecated?)
|
|
90
|
-
- Uses `html2text` library to convert page HTML to terminal-readable text
|
|
91
|
-
|
|
92
|
-
### Error Handling
|
|
93
|
-
|
|
94
|
-
- All errors wrapped with context via `pkg/errors`
|
|
95
|
-
- Exit codes for different failure modes (0-7)
|
|
96
|
-
- Styled error messages (not raw stack traces)
|
|
97
|
-
|
|
98
|
-
### Dependencies (Go)
|
|
99
|
-
|
|
100
|
-
| Library | Purpose |
|
|
101
|
-
|---------|---------|
|
|
102
|
-
| spf13/cobra | CLI framework |
|
|
103
|
-
| AlecAivazis/survey | Interactive prompts |
|
|
104
|
-
| pterm/pterm | Tables, spinners, styled output |
|
|
105
|
-
| k3a/html2text | HTML to text rendering |
|
|
106
|
-
| prologic/bitcask | Key-value storage |
|
|
107
|
-
| pkg/errors | Error wrapping |
|
|
108
|
-
|
|
109
|
-
## Notable Gaps
|
|
110
|
-
|
|
111
|
-
- No pagination for large result sets
|
|
112
|
-
- No retry logic for HTTP 503/504 (marked as TODO)
|
|
113
|
-
- No handling of the 5000-item SharePoint limit (would fail silently)
|
|
114
|
-
- Search uses an older/undocumented Graph API pattern
|
|
115
|
-
- Hardcoded OAuth client ID — not configurable
|
|
116
|
-
- Storage path `/tmp/nnote` is volatile
|
|
117
|
-
- No `--json` output option for scripting
|
|
118
|
-
|
|
119
|
-
## Ideas for onenote-cli
|
|
120
|
-
|
|
121
|
-
Based on this analysis, features worth considering for our CLI:
|
|
122
|
-
|
|
123
|
-
1. **Interactive prompts** — Use `@inquirer/prompts` or similar for notebook/section selection instead of requiring raw IDs
|
|
124
|
-
2. **Alias system** — Map short names to notebook+section pairs for quick note creation
|
|
125
|
-
3. **Browse mode** — Interactive navigation loop through notebooks → sections → pages
|
|
126
|
-
4. **HTML to text rendering** — Use `html-to-text` or `turndown` for terminal display of page content
|
|
127
|
-
5. **Spinner/progress indicators** — Show progress during API calls
|
|
128
|
-
6. **Open in browser/client** — Use the `links.oneNoteWebUrl` and `oneNoteClientUrl` from notebook metadata
|
|
129
|
-
7. **$EDITOR integration** — Launch editor for composing notes
|
|
130
|
-
8. **--json flag** — Output JSON for scripting/piping (improvement over onen0te-cli)
|